@bjj/nuxt-layer-shadcn-ui 0.15.7 → 0.15.9

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.
@@ -22,6 +22,7 @@ import {
22
22
  SidebarMenuSub,
23
23
  SidebarMenuSubButton,
24
24
  SidebarMenuSubItem,
25
+ useSidebar,
25
26
  } from '../../shadcn/sidebar'
26
27
 
27
28
  const props = defineProps<{
@@ -37,6 +38,12 @@ const emit = defineEmits<{
37
38
 
38
39
  const route = useRoute()
39
40
 
41
+ // In page mode this is the real provider's live state; the embedded fallback
42
+ // context pins it to 'expanded'. On mobile the sidebar renders as a full-width
43
+ // sheet, so the inline sub-menu stays regardless of the collapsed state.
44
+ const { state, isMobile } = useSidebar()
45
+ const iconCollapsed = computed(() => state.value === 'collapsed' && !isMobile.value)
46
+
40
47
  const isExternal = (href: string) => /^https?:\/\//.test(href)
41
48
 
42
49
  const navGroups = computed(() => {
@@ -74,6 +81,21 @@ function hasActiveChild (item: SidebarLayoutMenuItem): boolean {
74
81
  function handleSelect (item: SidebarLayoutMenuItem) {
75
82
  emit('select', item)
76
83
  }
84
+
85
+ // Fly-out items for an icon-collapsed parent: the leading label stands in for
86
+ // the parent's text, which only shows its icon in that state.
87
+ function toDropdownItems (item: SidebarLayoutMenuItem): DropdownItem[] {
88
+ return [
89
+ { type: 'label', label: item.label },
90
+ ...(item.children ?? []).map(child => ({
91
+ label: child.label,
92
+ icon: child.icon,
93
+ href: child.href,
94
+ active: isActive(child),
95
+ command: () => handleSelect(child),
96
+ })),
97
+ ]
98
+ }
77
99
  </script>
78
100
 
79
101
  <template>
@@ -81,7 +103,13 @@ function handleSelect (item: SidebarLayoutMenuItem) {
81
103
  v-for="(group, groupIndex) in navGroups"
82
104
  :key="groupIndex"
83
105
  >
84
- <SidebarGroupLabel v-if="group.label">
106
+ <!-- While icon-collapsed the vendored label hides via `opacity-0`, which
107
+ creates a stacking context that keeps hit-testing above the menu row
108
+ it overlaps, so clicks must fall through it. -->
109
+ <SidebarGroupLabel
110
+ v-if="group.label"
111
+ class="group-data-[collapsible=icon]:pointer-events-none"
112
+ >
85
113
  {{ group.label }}
86
114
  </SidebarGroupLabel>
87
115
  <SidebarMenu>
@@ -89,9 +117,31 @@ function handleSelect (item: SidebarLayoutMenuItem) {
89
117
  v-for="item in group.items"
90
118
  :key="sidebarMenuItemKey(item)"
91
119
  >
120
+ <!-- Icon-collapsed parent: the inline sub-menu is hidden in that
121
+ state, so the children fly out as a dropdown at the side. -->
122
+ <SidebarMenuItem v-if="item.children?.length && iconCollapsed">
123
+ <Dropdown
124
+ :menus="toDropdownItems(item)"
125
+ side="right"
126
+ align="start"
127
+ class="min-w-48 rounded-lg"
128
+ >
129
+ <SidebarMenuButton
130
+ :isActive="hasActiveChild(item)"
131
+ class="cursor-pointer"
132
+ >
133
+ <Icon
134
+ v-if="item.icon"
135
+ :name="item.icon"
136
+ />
137
+ <span>{{ item.label }}</span>
138
+ </SidebarMenuButton>
139
+ </Dropdown>
140
+ </SidebarMenuItem>
141
+
92
142
  <!-- Collapsible item with children -->
93
143
  <Collapsible
94
- v-if="item.children?.length"
144
+ v-else-if="item.children?.length"
95
145
  asChild
96
146
  :defaultOpen="item.expanded ?? hasActiveChild(item)"
97
147
  class="group/collapsible"
@@ -199,6 +199,52 @@ export const NestedMenus: Story = {
199
199
  },
200
200
  }
201
201
 
202
+ // Page mode starting icon-collapsed (`defaultOpen` falls through to the
203
+ // provider): parents with children show them in a fly-out dropdown at the side.
204
+ export const CollapsedNestedMenus: Story = {
205
+ parameters: {
206
+ ...noControls,
207
+ docs: {
208
+ source: {
209
+ code: `
210
+ <template>
211
+ <SidebarLayout
212
+ v-model:active="active"
213
+ :menus="menus"
214
+ :defaultOpen="false"
215
+ contentClass="p-6"
216
+ >
217
+ <template #header>
218
+ <div class="truncate px-2 py-1 text-base font-semibold group-data-[collapsible=icon]:hidden">Acme Inc.</div>
219
+ </template>
220
+
221
+ <div class="text-sm text-muted-foreground">Pane for {{ active }}</div>
222
+ </SidebarLayout>
223
+ </template>
224
+ `.trim(),
225
+ },
226
+ },
227
+ },
228
+ render: () => ({
229
+ components: { SidebarLayout },
230
+ setup () {
231
+ const active = ref('intro')
232
+ return { active, nestedMenus }
233
+ },
234
+ template: `
235
+ <SidebarLayout
236
+ v-model:active="active"
237
+ :menus="nestedMenus"
238
+ :defaultOpen="false"
239
+ contentClass="p-6"
240
+ >
241
+ ${brandTemplate}
242
+ <div class="text-sm text-muted-foreground">Pane for {{ active }}</div>
243
+ </SidebarLayout>
244
+ `,
245
+ }),
246
+ }
247
+
202
248
  export const EmptyText: Story = {
203
249
  parameters: noControls,
204
250
  args: {
@@ -0,0 +1,3 @@
1
+ {
2
+ "lines": "{count} lines"
3
+ }
@@ -11,6 +11,7 @@ const meta = {
11
11
  autocomplete: { control: 'text' },
12
12
  rows: { control: 'number' },
13
13
  maxlength: { control: 'number' },
14
+ maxLines: { control: 'number' },
14
15
  showCount: { control: 'boolean' },
15
16
  readonly: { control: 'boolean' },
16
17
  disabled: { control: 'boolean' },
@@ -22,6 +23,7 @@ const meta = {
22
23
  autocomplete: '',
23
24
  rows: undefined,
24
25
  maxlength: undefined,
26
+ maxLines: undefined,
25
27
  showCount: false,
26
28
  readonly: false,
27
29
  disabled: false,
@@ -72,6 +74,23 @@ export const WithRows: Story = {
72
74
  }),
73
75
  }
74
76
 
77
+ export const WithCount: Story = {
78
+ parameters: noControls,
79
+ args: {
80
+ showCount: true,
81
+ maxlength: 200,
82
+ },
83
+ }
84
+
85
+ export const WithMaxLines: Story = {
86
+ parameters: noControls,
87
+ args: {
88
+ showCount: true,
89
+ maxLines: 3,
90
+ modelValue: 'Line 1\nLine 2',
91
+ },
92
+ }
93
+
75
94
  export const Invalid: Story = {
76
95
  parameters: noControls,
77
96
  args: {
@@ -9,6 +9,7 @@ const props = withDefaults(defineProps<TextareaProps>(), {
9
9
  autocomplete: undefined,
10
10
  rows: undefined,
11
11
  maxlength: undefined,
12
+ maxLines: undefined,
12
13
  showCount: false,
13
14
  readonly: false,
14
15
  disabled: false,
@@ -21,6 +22,8 @@ const emit = defineEmits<{
21
22
  'change': [value: string]
22
23
  }>()
23
24
 
25
+ const { t } = useI18n()
26
+
24
27
  const isInvalid = useFormItemInvalid(() => props.invalid)
25
28
 
26
29
  // Internal value tracks the actual textarea content, independent of parent's modelValue
@@ -31,15 +34,53 @@ watch(() => props.modelValue, value => {
31
34
  internalValue.value = value
32
35
  })
33
36
 
37
+ // A limit below one line would leave no room for content at all
38
+ const lineLimit = computed(() =>
39
+ props.maxLines !== undefined && props.maxLines >= 1 ? props.maxLines : undefined,
40
+ )
41
+
42
+ function countLines (value: string) {
43
+ return value === '' ? 0 : value.split('\n').length
44
+ }
45
+
46
+ /** Keep the leading lines and drop everything past the line limit */
47
+ function clampLines (value: string) {
48
+ const limit = lineLimit.value
49
+ if (limit === undefined || countLines(value) <= limit) return value
50
+ return value.split('\n').slice(0, limit).join('\n')
51
+ }
52
+
34
53
  const countText = computed(() => {
35
- const length = internalValue.value?.length ?? 0
36
- return props.maxlength === undefined ? `${length}` : `${length} / ${props.maxlength}`
54
+ const value = internalValue.value ?? ''
55
+ const lines = countLines(value)
56
+ const linesPart = lineLimit.value === undefined ? `${lines}` : `${lines} / ${lineLimit.value}`
57
+ const charsPart = props.maxlength === undefined ? `${value.length}` : `${value.length} / ${props.maxlength}`
58
+ return `${t('components.ui.Textarea.lines', { count: linesPart })} · ${charsPart}`
37
59
  })
38
60
 
39
61
  function handleInput (event: Event) {
40
62
  const target = event.target as HTMLTextAreaElement
41
- internalValue.value = target.value
42
- emit('update:modelValue', target.value)
63
+ const value = clampLines(target.value)
64
+ if (value !== target.value) {
65
+ const caret = Math.min(target.selectionStart, value.length)
66
+ target.value = value
67
+ target.setSelectionRange(caret, caret)
68
+ // Re-dispatch so the inner textarea's own v-model state follows the trimmed value
69
+ target.dispatchEvent(new Event('input', { bubbles: true }))
70
+ return
71
+ }
72
+ internalValue.value = value
73
+ emit('update:modelValue', value)
74
+ }
75
+
76
+ // Reject line breaks beyond the line limit; overflow from pasting is trimmed in handleInput
77
+ function handleKeydown (event: KeyboardEvent) {
78
+ const limit = lineLimit.value
79
+ // While composing, Enter commits the IME candidate instead of inserting a line break
80
+ if (limit === undefined || event.key !== 'Enter' || event.isComposing) return
81
+ const { value, selectionStart, selectionEnd } = event.target as HTMLTextAreaElement
82
+ const next = `${value.slice(0, selectionStart)}\n${value.slice(selectionEnd)}`
83
+ if (countLines(next) > limit) event.preventDefault()
43
84
  }
44
85
 
45
86
  function handleChange (event: Event) {
@@ -69,6 +110,7 @@ const mergedClass = computed(() =>
69
110
  :autocomplete="autocomplete || 'off'"
70
111
  v-bind="$attrs"
71
112
  @input="handleInput"
113
+ @keydown="handleKeydown"
72
114
  @change="handleChange"
73
115
  />
74
116
  <div
@@ -5,7 +5,12 @@ export interface TextareaProps {
5
5
  rows?: number
6
6
  /** Maximum number of characters allowed */
7
7
  maxlength?: number
8
- /** Show character count below the textarea (rendered as `count / maxlength` when maxlength is set) */
8
+ /** Maximum number of lines allowed: extra line breaks are blocked and pasted overflow is trimmed */
9
+ maxLines?: number
10
+ /**
11
+ * Show line and character count below the textarea, rendered as `lines · count`.
12
+ * Each part gains a ` / limit` suffix when `maxLines` / `maxlength` is set.
13
+ */
9
14
  showCount?: boolean
10
15
  readonly?: boolean
11
16
  disabled?: boolean
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "الإجراءات"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} أسطر"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "انقر أو اسحب الملف إلى هذه المنطقة للتحميل",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Aktionen"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} Zeilen"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Klicken oder ziehen Sie eine Datei in diesen Bereich, um sie hochzuladen",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Actions"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} lines"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Click or drag file to this area to upload",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Acciones"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} líneas"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Haz clic o arrastra un archivo a esta área para subir",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Actions"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} lignes"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Cliquez ou glissez un fichier dans cette zone pour télécharger",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "क्रियाएं"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} पंक्तियाँ"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "इस क्षेत्र में फ़ाइल को क्लिक करें या खींचें और अपलोड करें",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Tindakan"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} baris"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Klik atau seret file ke area ini untuk mengunggah",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Azioni"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} righe"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Fai clic o trascina il file in quest'area per caricarlo",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "アクション"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} 行"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "ファイルをクリックまたはドラッグしてこのエリアにアップロード",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "작업"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count}줄"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "이 영역에 파일을 클릭하거나 드래그하여 업로드하세요",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Acties"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} regels"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Klik of sleep bestand naar dit gebied om te uploaden",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Akcje"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} wierszy"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Kliknij lub przeciągnij plik do tego obszaru, aby przesłać",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Ações"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} linhas"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Clique ou arraste um arquivo para esta área para fazer upload",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Действия"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} строк"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Нажмите или перетащите файл в эту область для загрузки",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "การกระทำ"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} บรรทัด"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "คลิกหรือลากไฟล์ไปยังพื้นที่นี้เพื่ออัปโหลด",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "İşlemler"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} satır"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Bu alana dosya gömmek veya sürüklemek için tıklayın",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Hành động"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} dòng"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "Nhấp hoặc kéo tệp vào khu vực này để tải lên",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "操作"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} 行"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "点击或拖动文件到此区域上传",
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "操作"
91
91
  },
92
+ "Textarea": {
93
+ "lines": "{count} 行"
94
+ },
92
95
  "Upload": {
93
96
  "drag": {
94
97
  "title": "在此點擊或拖曳檔案以上傳",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.15.7",
3
+ "version": "0.15.9",
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": "f9c5a4ca3f0fa3ab4cdfb8f950487d3142031058"
45
+ "gitHead": "7f4cf572fa25bd362436144ff826ae2ebf352317"
46
46
  }