@bjj/nuxt-layer-shadcn-ui 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3'
2
2
  import type { SidebarLayoutMenuItem } from '../SidebarLayout/types'
3
+ import type { SidebarModalFilter } from './types'
3
4
  import EventLog from '#storybook/EventLog.vue'
4
5
  import { useArgsModel } from '#storybook/argsModel'
5
6
  import Button from '../Button/index.vue'
@@ -43,6 +44,31 @@ const scrollingMenus: SidebarLayoutMenuItem[] = [
43
44
  })),
44
45
  ]
45
46
 
47
+ // The rows each pane renders, doubling as the index a business search would hit.
48
+ const paneContent: Record<string, string[]> = {
49
+ general: [ 'full name', 'email', 'notifications' ],
50
+ account: [ 'password', 'two-factor', 'sessions' ],
51
+ usage: [ 'quota', 'billing period' ],
52
+ capabilities: [ 'beta features' ],
53
+ appearance: [ 'theme', 'dark mode', 'font size' ],
54
+ extensions: [ 'browser extension' ],
55
+ developer: [ 'api key', 'webhooks' ],
56
+ skills: [ 'custom instructions' ],
57
+ connectors: [ 'google drive', 'slack' ],
58
+ }
59
+
60
+ const searchByContent: SidebarModalFilter = (items, keyword) => {
61
+ if (!keyword) return items
62
+ const needle = keyword.toLowerCase()
63
+ return items.filter(item => {
64
+ const key = item.key ?? item.label
65
+ return [ item.label, item.group, ...(paneContent[key] ?? []) ]
66
+ .join(' ')
67
+ .toLowerCase()
68
+ .includes(needle)
69
+ })
70
+ }
71
+
46
72
  const generalPane = `
47
73
  <template #general>
48
74
  <div class="space-y-4">
@@ -110,6 +136,7 @@ const meta = {
110
136
  visible: { control: 'boolean' },
111
137
  active: { control: 'text' },
112
138
  searchable: { control: 'boolean' },
139
+ search: { control: 'text' },
113
140
  searchPlaceholder: { control: 'text' },
114
141
  title: { control: 'text' },
115
142
  modal: { control: 'boolean' },
@@ -123,6 +150,7 @@ const meta = {
123
150
  visible: false,
124
151
  active: 'general',
125
152
  searchable: true,
153
+ search: '',
126
154
  searchPlaceholder: '',
127
155
  title: 'Settings',
128
156
  modal: true,
@@ -134,9 +162,10 @@ const meta = {
134
162
  render: args => {
135
163
  const onUpdateVisible = useArgsModel('visible')
136
164
  const onUpdateActive = useArgsModel('active')
165
+ const onUpdateSearch = useArgsModel('search')
137
166
  return {
138
167
  components: { SidebarModal, Button, Input, Switch },
139
- setup: () => ({ args, onUpdateVisible, onUpdateActive }),
168
+ setup: () => ({ args, onUpdateVisible, onUpdateActive, onUpdateSearch }),
140
169
  // Opening through `#trigger` keeps the demo alive on the Docs page, where
141
170
  // only the primary story's args round-trip; the emits still sync Controls.
142
171
  template: `
@@ -144,6 +173,7 @@ const meta = {
144
173
  v-bind="args"
145
174
  @update:visible="onUpdateVisible"
146
175
  @update:active="onUpdateActive"
176
+ @update:search="onUpdateSearch"
147
177
  >
148
178
  <template #trigger>
149
179
  <Button>Open Settings</Button>
@@ -180,6 +210,85 @@ export const SearchPlaceholder: Story = {
180
210
  }
181
211
 
182
212
  // A search flattens matched children so none stays hidden behind a closed parent.
213
+ // A `searchable` function owns the listing, so the keyword can be matched against
214
+ // pane content: "dark" surfaces Appearance even though no label contains it.
215
+ export const CustomSearch: Story = {
216
+ parameters: {
217
+ ...noControls,
218
+ docs: {
219
+ source: {
220
+ code: `
221
+ <template>
222
+ <SidebarModal
223
+ :menus="menus"
224
+ :searchable="searchByContent"
225
+ title="Settings"
226
+ >
227
+ <template #trigger>
228
+ <Button>Open Settings</Button>
229
+ </template>
230
+
231
+ <template #default="{ active, item }">
232
+ <h2 class="text-lg font-semibold">{{ item?.label }}</h2>
233
+ <div
234
+ v-for="row in paneContent[active]"
235
+ :key="row"
236
+ class="py-3 text-sm"
237
+ >
238
+ {{ row }}
239
+ </div>
240
+ </template>
241
+ </SidebarModal>
242
+ </template>
243
+
244
+ <script setup lang="ts">
245
+ // One source of truth: the rows a pane renders are the rows search matches.
246
+ const searchByContent: SidebarModalFilter = (items, keyword) => {
247
+ if (!keyword) return items
248
+ const needle = keyword.toLowerCase()
249
+ return items.filter(item => [ item.label, item.group, ...paneContent[item.key] ?? [] ]
250
+ .join(' ')
251
+ .toLowerCase()
252
+ .includes(needle))
253
+ }
254
+ </script>
255
+ `.trim(),
256
+ },
257
+ },
258
+ },
259
+ render: () => ({
260
+ components: { SidebarModal, Button },
261
+ setup: () => ({ menus, searchByContent, paneContent }),
262
+ template: `
263
+ <SidebarModal
264
+ :menus="menus"
265
+ :searchable="searchByContent"
266
+ title="Settings"
267
+ searchPlaceholder="Search settings or content"
268
+ >
269
+ <template #trigger>
270
+ <Button>Open Settings</Button>
271
+ </template>
272
+
273
+ <template #default="{ active, item }">
274
+ <div class="space-y-4">
275
+ <h2 class="text-lg font-semibold">{{ item?.label }}</h2>
276
+ <div class="divide-y divide-border">
277
+ <div
278
+ v-for="row in paneContent[active] || []"
279
+ :key="row"
280
+ class="py-3 text-sm capitalize"
281
+ >
282
+ {{ row }}
283
+ </div>
284
+ </div>
285
+ </div>
286
+ </template>
287
+ </SidebarModal>
288
+ `,
289
+ }),
290
+ }
291
+
183
292
  export const NestedMenus: Story = {
184
293
  parameters: noControls,
185
294
  args: {
@@ -267,6 +376,7 @@ export const NonModal: Story = {
267
376
  },
268
377
  }
269
378
 
379
+ // The `#header` slot sits above the built-in search field rather than replacing it.
270
380
  export const CustomHeader: Story = {
271
381
  parameters: {
272
382
  ...noControls,
@@ -278,6 +388,7 @@ export const CustomHeader: Story = {
278
388
  v-model:visible="visible"
279
389
  :menus="menus"
280
390
  title="Settings"
391
+ searchable
281
392
  >
282
393
  <template #header>
283
394
  <div class="flex items-center gap-2 px-2 py-1">
@@ -314,7 +425,7 @@ export const CustomHeader: Story = {
314
425
  template: `
315
426
  <div>
316
427
  <Button @click="visible = true">Open Settings</Button>
317
- <SidebarModal v-model:visible="visible" :menus="menus" title="Settings">
428
+ <SidebarModal v-model:visible="visible" :menus="menus" title="Settings" searchable>
318
429
  <template #header>
319
430
  <div class="flex items-center gap-2 px-2 py-1">
320
431
  <Icon name="building-2" />
@@ -16,6 +16,7 @@ defineOptions({ inheritAttrs: false })
16
16
  const props = withDefaults(defineProps<SidebarModalProps>(), {
17
17
  visible: undefined,
18
18
  active: undefined,
19
+ search: undefined,
19
20
  searchPlaceholder: undefined,
20
21
  title: undefined,
21
22
  modal: true,
@@ -29,6 +30,7 @@ const props = withDefaults(defineProps<SidebarModalProps>(), {
29
30
  const emit = defineEmits<{
30
31
  'update:visible': [value: boolean]
31
32
  'update:active': [key: string]
33
+ 'update:search': [keyword: string]
32
34
  'select': [item: SidebarLayoutMenuItem]
33
35
  'open': []
34
36
  'close': []
@@ -49,7 +51,7 @@ const T = useTranslations('components.ui.SidebarModal')
49
51
 
50
52
  const dialogOpen = ref(props.visible ?? false)
51
53
  const activeKey = ref(props.active ?? '')
52
- const searchQuery = ref<string>()
54
+ const searchQuery = ref(props.search)
53
55
 
54
56
  const activeItem = computed(() => findSidebarMenuItem(props.menus, activeKey.value))
55
57
 
@@ -58,11 +60,17 @@ const paneSlotProps = computed<SidebarModalPaneSlotProps>(() => ({
58
60
  item: activeItem.value,
59
61
  }))
60
62
 
61
- const searchKeyword = computed(() => searchQuery.value?.trim().toLowerCase() ?? '')
63
+ const searchKeyword = computed(() => searchQuery.value?.trim() ?? '')
62
64
 
63
- const filteredMenus = computed(() =>
64
- searchKeyword.value ? filterMenus(props.menus, searchKeyword.value) : props.menus,
65
- )
65
+ const filteredMenus = computed(() => {
66
+ // A custom filter runs for every keyword, empty included, so it fully owns the
67
+ // listing; reading its own reactive state in there also covers async results.
68
+ if (typeof props.searchable === 'function') {
69
+ return props.searchable(props.menus, searchKeyword.value)
70
+ }
71
+ if (!searchKeyword.value) return props.menus
72
+ return filterMenus(props.menus, searchKeyword.value.toLowerCase())
73
+ })
66
74
 
67
75
  const dialogClass = computed(() =>
68
76
  cn(
@@ -92,6 +100,12 @@ watch(dialogOpen, value => {
92
100
  searchQuery.value = undefined
93
101
  })
94
102
 
103
+ watch(() => props.search, keyword => {
104
+ if (keyword !== undefined) searchQuery.value = keyword
105
+ })
106
+
107
+ watch(searchQuery, keyword => emit('update:search', keyword ?? ''))
108
+
95
109
  watch(() => props.active, key => {
96
110
  if (key !== undefined) activeKey.value = key
97
111
  })
@@ -171,16 +185,17 @@ function onPointerDownOutside (event: Event) {
171
185
  v-if="searchable || $slots.header"
172
186
  #header
173
187
  >
174
- <slot name="header">
175
- <Input
176
- v-model="searchQuery"
177
- :placeholder="searchPlaceholder || T('searchPlaceholder')"
178
- >
179
- <template #prefix>
180
- <Icon name="search" />
181
- </template>
182
- </Input>
183
- </slot>
188
+ <slot name="header" />
189
+
190
+ <Input
191
+ v-if="searchable"
192
+ v-model="searchQuery"
193
+ :placeholder="searchPlaceholder || T('searchPlaceholder')"
194
+ >
195
+ <template #prefix>
196
+ <Icon name="search" />
197
+ </template>
198
+ </Input>
184
199
  </template>
185
200
 
186
201
  <template
@@ -6,13 +6,28 @@ export interface SidebarModalPaneSlotProps {
6
6
  item?: SidebarLayoutMenuItem
7
7
  }
8
8
 
9
+ /**
10
+ * Menus to list for the current keyword. Receives the keyword as typed (trimmed),
11
+ * so a business search can look beyond labels — pane content, a remote index —
12
+ * and return whatever entries should show.
13
+ */
14
+ export type SidebarModalFilter = (
15
+ menus: SidebarLayoutMenuItem[],
16
+ keyword: string,
17
+ ) => SidebarLayoutMenuItem[]
18
+
9
19
  export interface SidebarModalProps {
10
20
  menus: SidebarLayoutMenuItem[]
11
21
  visible?: boolean
12
22
  /** Key of the selected menu item. Omitted → the first selectable item. */
13
23
  active?: string
14
- /** Render a search field above the menu, filtering items by label and group. */
15
- searchable?: boolean
24
+ /**
25
+ * Render a search field between `#header` and the menu. `true`: filter menus by
26
+ * label and group; function: custom filter (replaces the built-in one).
27
+ */
28
+ searchable?: boolean | SidebarModalFilter
29
+ /** Search keyword. Use `v-model:search` to read or drive it from the outside. */
30
+ search?: string
16
31
  searchPlaceholder?: string
17
32
  /** Accessible name of the dialog, rendered for screen readers only. */
18
33
  title?: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Nuxt layer providing shadcn-vue based UI components",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -42,5 +42,5 @@
42
42
  "vue-i18n": "^11",
43
43
  "vue-router": "^4 || ^5"
44
44
  },
45
- "gitHead": "8b94a7bdf44027021baccd353801079740f84b3e"
45
+ "gitHead": "fcb519f4b49b1057560758810895da335df8366c"
46
46
  }