-
-
-
- {{ field.label }}
+
+
+
+
+ {{ field.label }}
+
+
+
+
-
-
-
-
-
+
+
-
-
-
+
+
+
+
+
diff --git a/resources/components/sidebar.vue b/resources/components/sidebar.vue
index c6fadc6..c3365c0 100644
--- a/resources/components/sidebar.vue
+++ b/resources/components/sidebar.vue
@@ -1,21 +1,14 @@
@@ -26,29 +19,6 @@ const items: Ref = ref(props.menu)
-
+
diff --git a/resources/components/ui/menu/category.vue b/resources/components/ui/menu/category.vue
new file mode 100644
index 0000000..10e0742
--- /dev/null
+++ b/resources/components/ui/menu/category.vue
@@ -0,0 +1,18 @@
+
+
+
+
+ - {{ item.label }}
+ -
+
+
+
+
diff --git a/resources/components/ui/menu/index.vue b/resources/components/ui/menu/index.vue
new file mode 100644
index 0000000..f329576
--- /dev/null
+++ b/resources/components/ui/menu/index.vue
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/resources/components/ui/menu/item.vue b/resources/components/ui/menu/item.vue
new file mode 100644
index 0000000..ce3f70b
--- /dev/null
+++ b/resources/components/ui/menu/item.vue
@@ -0,0 +1,33 @@
+
+
+
+
+
+ {{ item.label }}
+
+
diff --git a/src/menu/menu_category.ts b/src/menu/menu_category.ts
index 18f746e..a362afc 100644
--- a/src/menu/menu_category.ts
+++ b/src/menu/menu_category.ts
@@ -20,16 +20,19 @@ export class MenuCategory implements Serializable {
return item
}
+ /**
+ * Adds an item from a resource.
+ */
resource(resource: (new () => BaseResource) | BaseResource): MenuItem {
const instance = resource instanceof BaseResource ? resource : new resource()
const item = this.item(instance.labelPlural())
+ .prefixMatch()
+ .route(`cockpit.resources.index`, { slug: instance.name() })
if (instance.icon) {
item.icon(instance.icon())
}
- item.route(`cockpit.resources.index`, { slug: instance.name() })
-
return item
}
diff --git a/src/menu/menu_item.ts b/src/menu/menu_item.ts
index 685ebb5..ded6fe8 100644
--- a/src/menu/menu_item.ts
+++ b/src/menu/menu_item.ts
@@ -6,6 +6,7 @@ export class MenuItem {
#href?: string
#target?: string
#icon?: string
+ #prefixMatch = false
constructor(label: string) {
this.#label = label
@@ -36,16 +37,21 @@ export class MenuItem {
return this
}
- // public static resource(Resource: Type
): MenuItem {
- // const resource = new Resource()
- // const item = this.make().label(resource.labelPlural()).href(resource.route('index'))
- //
- // if (resource.icon) {
- // item.icon(resource.icon())
- // }
- //
- // return item
- // }
+ /**
+ * Make the item active using prefix matching.
+ */
+ prefixMatch(): this {
+ this.#prefixMatch = true
+ return this
+ }
+
+ /**
+ * Make the item active using exact matching.
+ */
+ exactMatch(): this {
+ this.#prefixMatch = false
+ return this
+ }
toJSON(): PrimeMenuItem {
return {
@@ -53,6 +59,7 @@ export class MenuItem {
url: this.#href,
target: this.#target,
icon: this.#icon,
+ prefixMatch: this.#prefixMatch,
}
}
}