@bjj/nuxt-layer-shadcn-ui 0.12.1 → 0.12.3
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.
- package/app/components/ui/DatePicker/index.vue +1 -2
- package/app/components/ui/Input/index.stories.ts +4 -0
- package/app/components/ui/Input/index.vue +13 -0
- package/app/components/ui/Input/types.ts +4 -0
- package/app/components/ui/Textarea/index.stories.ts +4 -0
- package/app/components/ui/Textarea/index.vue +36 -11
- package/app/components/ui/Textarea/types.ts +4 -0
- package/package.json +2 -2
|
@@ -93,8 +93,7 @@ const timeConfig = computed(() => {
|
|
|
93
93
|
:disabled="disabled"
|
|
94
94
|
:readonly="readonly"
|
|
95
95
|
@update:modelValue="(v: string | undefined) => onInput(v ?? '')"
|
|
96
|
-
@keydown
|
|
97
|
-
@keydown.tab="onTab"
|
|
96
|
+
@keydown="(e: KeyboardEvent) => { if (e.key === 'Enter') onEnter(e); else if (e.key === 'Tab') onTab(e) }"
|
|
98
97
|
@change="(v: string | undefined) => { if (!v) onClear() }"
|
|
99
98
|
@blur="onBlur"
|
|
100
99
|
@focus="() => { onFocus(); openMenu() }"
|
|
@@ -10,6 +10,8 @@ const meta = {
|
|
|
10
10
|
argTypes: {
|
|
11
11
|
modelValue: { control: 'text' },
|
|
12
12
|
autocomplete: { control: 'text' },
|
|
13
|
+
maxlength: { control: 'number' },
|
|
14
|
+
showCount: { control: 'boolean' },
|
|
13
15
|
disabled: { control: 'boolean' },
|
|
14
16
|
readonly: { control: 'boolean' },
|
|
15
17
|
invalid: { control: 'boolean' },
|
|
@@ -18,6 +20,8 @@ const meta = {
|
|
|
18
20
|
args: {
|
|
19
21
|
modelValue: '',
|
|
20
22
|
autocomplete: 'off',
|
|
23
|
+
maxlength: undefined,
|
|
24
|
+
showCount: false,
|
|
21
25
|
disabled: false,
|
|
22
26
|
readonly: false,
|
|
23
27
|
invalid: false,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
InputGroupAddon,
|
|
5
5
|
InputGroupButton,
|
|
6
6
|
InputGroupInput,
|
|
7
|
+
InputGroupText,
|
|
7
8
|
} from '../../shadcn/input-group'
|
|
8
9
|
import type { InputProps } from './types'
|
|
9
10
|
|
|
@@ -33,6 +34,11 @@ watch(() => props.modelValue, value => {
|
|
|
33
34
|
|
|
34
35
|
const showClearButton = computed(() => !!internalValue.value && !props.readonly && !props.disabled)
|
|
35
36
|
|
|
37
|
+
const countText = computed(() => {
|
|
38
|
+
const length = internalValue.value?.length ?? 0
|
|
39
|
+
return props.maxlength === undefined ? `${length}` : `${length} / ${props.maxlength}`
|
|
40
|
+
})
|
|
41
|
+
|
|
36
42
|
function handleChange (event: Event) {
|
|
37
43
|
const target = event.target as HTMLInputElement
|
|
38
44
|
emit('change', target.value)
|
|
@@ -67,6 +73,7 @@ function clearInput () {
|
|
|
67
73
|
v-bind="$attrs"
|
|
68
74
|
:readonly="readonly"
|
|
69
75
|
:disabled="disabled"
|
|
76
|
+
:maxlength="maxlength"
|
|
70
77
|
:aria-invalid="isInvalid || undefined"
|
|
71
78
|
:data-1p-ignore="autocomplete === 'off' || !autocomplete ? true : undefined"
|
|
72
79
|
:autocomplete="autocomplete || 'off'"
|
|
@@ -85,6 +92,12 @@ function clearInput () {
|
|
|
85
92
|
<Icon name="x" />
|
|
86
93
|
</InputGroupButton>
|
|
87
94
|
</InputGroupAddon>
|
|
95
|
+
<InputGroupAddon
|
|
96
|
+
v-if="showCount"
|
|
97
|
+
align="inline-end"
|
|
98
|
+
>
|
|
99
|
+
<InputGroupText>{{ countText }}</InputGroupText>
|
|
100
|
+
</InputGroupAddon>
|
|
88
101
|
<InputGroupAddon
|
|
89
102
|
v-if="slots.suffix"
|
|
90
103
|
align="inline-end"
|
|
@@ -2,6 +2,10 @@ export interface InputProps {
|
|
|
2
2
|
modelValue?: string
|
|
3
3
|
/** Set to enable browser/password-manager autofill (e.g. 'email', 'current-password'). Defaults to 'off'. */
|
|
4
4
|
autocomplete?: string
|
|
5
|
+
/** Maximum number of characters allowed */
|
|
6
|
+
maxlength?: number
|
|
7
|
+
/** Show character count (rendered as `count / maxlength` when maxlength is set) */
|
|
8
|
+
showCount?: boolean
|
|
5
9
|
readonly?: boolean
|
|
6
10
|
disabled?: boolean
|
|
7
11
|
invalid?: boolean
|
|
@@ -10,6 +10,8 @@ const meta = {
|
|
|
10
10
|
modelValue: { control: 'text' },
|
|
11
11
|
autocomplete: { control: 'text' },
|
|
12
12
|
rows: { control: 'number' },
|
|
13
|
+
maxlength: { control: 'number' },
|
|
14
|
+
showCount: { control: 'boolean' },
|
|
13
15
|
invalid: { control: 'boolean' },
|
|
14
16
|
class: { control: 'text' },
|
|
15
17
|
},
|
|
@@ -17,6 +19,8 @@ const meta = {
|
|
|
17
19
|
modelValue: '',
|
|
18
20
|
autocomplete: '',
|
|
19
21
|
rows: undefined,
|
|
22
|
+
maxlength: undefined,
|
|
23
|
+
showCount: false,
|
|
20
24
|
invalid: false,
|
|
21
25
|
class: '',
|
|
22
26
|
},
|
|
@@ -8,6 +8,8 @@ const props = withDefaults(defineProps<TextareaProps>(), {
|
|
|
8
8
|
modelValue: undefined,
|
|
9
9
|
autocomplete: undefined,
|
|
10
10
|
rows: undefined,
|
|
11
|
+
maxlength: undefined,
|
|
12
|
+
showCount: false,
|
|
11
13
|
invalid: false,
|
|
12
14
|
class: undefined,
|
|
13
15
|
})
|
|
@@ -19,8 +21,22 @@ const emit = defineEmits<{
|
|
|
19
21
|
|
|
20
22
|
const isInvalid = useFormItemInvalid(() => props.invalid)
|
|
21
23
|
|
|
24
|
+
// Internal value tracks the actual textarea content, independent of parent's modelValue
|
|
25
|
+
const internalValue = ref(props.modelValue)
|
|
26
|
+
|
|
27
|
+
// Sync internal value when parent updates modelValue
|
|
28
|
+
watch(() => props.modelValue, value => {
|
|
29
|
+
internalValue.value = value
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const countText = computed(() => {
|
|
33
|
+
const length = internalValue.value?.length ?? 0
|
|
34
|
+
return props.maxlength === undefined ? `${length}` : `${length} / ${props.maxlength}`
|
|
35
|
+
})
|
|
36
|
+
|
|
22
37
|
function handleInput (event: Event) {
|
|
23
38
|
const target = event.target as HTMLTextAreaElement
|
|
39
|
+
internalValue.value = target.value
|
|
24
40
|
emit('update:modelValue', target.value)
|
|
25
41
|
}
|
|
26
42
|
|
|
@@ -38,15 +54,24 @@ const mergedClass = computed(() =>
|
|
|
38
54
|
</script>
|
|
39
55
|
|
|
40
56
|
<template>
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
<div>
|
|
58
|
+
<ShadcnTextarea
|
|
59
|
+
:modelValue="modelValue"
|
|
60
|
+
:rows="rows"
|
|
61
|
+
:maxlength="maxlength"
|
|
62
|
+
:class="mergedClass"
|
|
63
|
+
:aria-invalid="isInvalid || undefined"
|
|
64
|
+
:data-1p-ignore="autocomplete === 'off' || !autocomplete ? true : undefined"
|
|
65
|
+
:autocomplete="autocomplete || 'off'"
|
|
66
|
+
v-bind="$attrs"
|
|
67
|
+
@input="handleInput"
|
|
68
|
+
@change="handleChange"
|
|
69
|
+
/>
|
|
70
|
+
<div
|
|
71
|
+
v-if="showCount"
|
|
72
|
+
class="mt-1 text-sm text-muted-foreground text-right"
|
|
73
|
+
>
|
|
74
|
+
{{ countText }}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
52
77
|
</template>
|
|
@@ -3,6 +3,10 @@ export interface TextareaProps {
|
|
|
3
3
|
/** Set to enable browser/password-manager autofill. Defaults to 'off'. */
|
|
4
4
|
autocomplete?: string
|
|
5
5
|
rows?: number
|
|
6
|
+
/** Maximum number of characters allowed */
|
|
7
|
+
maxlength?: number
|
|
8
|
+
/** Show character count below the textarea (rendered as `count / maxlength` when maxlength is set) */
|
|
9
|
+
showCount?: boolean
|
|
6
10
|
invalid?: boolean
|
|
7
11
|
class?: ClassValue
|
|
8
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
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": "
|
|
45
|
+
"gitHead": "ee465b34aeb8fb45b58b7145d940f4c9bf19a6d2"
|
|
46
46
|
}
|