@bjj/nuxt-layer-shadcn-ui 0.12.8 → 0.12.10
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/Checkbox/index.stories.ts +2 -0
- package/app/components/ui/Checkbox/index.vue +11 -0
- package/app/components/ui/Checkbox/types.ts +2 -0
- package/app/components/ui/InputCurrency/index.stories.ts +4 -0
- package/app/components/ui/InputCurrency/types.ts +1 -1
- package/app/components/ui/InputNumber/index.stories.ts +2 -0
- package/app/components/ui/InputNumber/index.vue +2 -0
- package/app/components/ui/InputNumber/types.ts +1 -0
- package/app/components/ui/InputOtp/index.stories.ts +2 -0
- package/app/components/ui/InputOtp/index.vue +12 -0
- package/app/components/ui/InputOtp/types.ts +1 -0
- package/app/components/ui/InputPercent/index.stories.ts +4 -0
- package/app/components/ui/InputPercent/types.ts +1 -1
- package/app/components/ui/InputRange/index.stories.ts +2 -0
- package/app/components/ui/RadioCardGroup/index.stories.ts +2 -0
- package/app/components/ui/RadioCardGroup/index.vue +39 -9
- package/app/components/ui/RadioCardGroup/types.ts +2 -0
- package/app/components/ui/RadioGroup/index.stories.ts +2 -0
- package/app/components/ui/RadioGroup/index.vue +27 -4
- package/app/components/ui/RadioGroup/types.ts +2 -0
- package/app/components/ui/SearchSelect/index.stories.ts +2 -0
- package/app/components/ui/SearchSelect/index.vue +2 -0
- package/app/components/ui/SearchSelect/types.ts +2 -0
- package/app/components/ui/Select/index.stories.ts +4 -0
- package/app/components/ui/Select/index.vue +29 -12
- package/app/components/ui/Select/types.ts +4 -0
- package/app/components/ui/Slider/index.stories.ts +2 -0
- package/app/components/ui/Slider/index.vue +24 -1
- package/app/components/ui/Slider/types.ts +2 -0
- package/app/components/ui/Switch/index.stories.ts +2 -0
- package/app/components/ui/Switch/index.vue +22 -2
- package/app/components/ui/Switch/types.ts +4 -1
- package/app/components/ui/Textarea/index.stories.ts +4 -0
- package/app/components/ui/Textarea/index.vue +4 -0
- package/app/components/ui/Textarea/types.ts +2 -0
- package/app/components/ui/WebLink/index.vue +2 -2
- package/package.json +2 -2
|
@@ -8,6 +8,7 @@ const meta = {
|
|
|
8
8
|
argTypes: {
|
|
9
9
|
modelValue: { control: 'select', options: [ true, false, 'indeterminate' ]},
|
|
10
10
|
defaultValue: { control: 'select', options: [ true, false, 'indeterminate' ]},
|
|
11
|
+
readonly: { control: 'boolean' },
|
|
11
12
|
disabled: { control: 'boolean' },
|
|
12
13
|
required: { control: 'boolean' },
|
|
13
14
|
invalid: { control: 'boolean' },
|
|
@@ -17,6 +18,7 @@ const meta = {
|
|
|
17
18
|
args: {
|
|
18
19
|
modelValue: false,
|
|
19
20
|
defaultValue: false,
|
|
21
|
+
readonly: false,
|
|
20
22
|
disabled: false,
|
|
21
23
|
required: false,
|
|
22
24
|
invalid: false,
|
|
@@ -5,17 +5,28 @@ import type { CheckboxProps } from './types'
|
|
|
5
5
|
const props = defineProps<CheckboxProps>()
|
|
6
6
|
|
|
7
7
|
const isInvalid = useFormItemInvalid(() => props.invalid)
|
|
8
|
+
|
|
9
|
+
// Reka's toggle runs on click; both keyboard and pointer activation emit a
|
|
10
|
+
// click event, so a capture-phase guard blocks every toggle path when readonly
|
|
11
|
+
function handleClickCapture (event: Event) {
|
|
12
|
+
if (props.readonly) {
|
|
13
|
+
event.preventDefault()
|
|
14
|
+
event.stopPropagation()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
8
17
|
</script>
|
|
9
18
|
|
|
10
19
|
<template>
|
|
11
20
|
<ShadcnCheckbox
|
|
12
21
|
v-slot="{ state }"
|
|
13
22
|
:aria-invalid="isInvalid || undefined"
|
|
23
|
+
:aria-readonly="readonly || undefined"
|
|
14
24
|
class="
|
|
15
25
|
data-[state=indeterminate]:border-primary
|
|
16
26
|
data-[state=indeterminate]:bg-primary
|
|
17
27
|
data-[state=indeterminate]:text-primary-foreground
|
|
18
28
|
"
|
|
29
|
+
@click.capture="handleClickCapture"
|
|
19
30
|
>
|
|
20
31
|
<Icon
|
|
21
32
|
v-if="state === 'indeterminate'"
|
|
@@ -11,12 +11,16 @@ const meta = {
|
|
|
11
11
|
modelValue: { control: 'number' },
|
|
12
12
|
currency: { control: 'text' },
|
|
13
13
|
currencyDisplay: { control: 'select', options: currencyDisplays },
|
|
14
|
+
readonly: { control: 'boolean' },
|
|
15
|
+
disabled: { control: 'boolean' },
|
|
14
16
|
invalid: { control: 'boolean' },
|
|
15
17
|
},
|
|
16
18
|
args: {
|
|
17
19
|
modelValue: 1000,
|
|
18
20
|
currency: 'JPY',
|
|
19
21
|
currencyDisplay: 'symbol',
|
|
22
|
+
readonly: false,
|
|
23
|
+
disabled: false,
|
|
20
24
|
invalid: false,
|
|
21
25
|
},
|
|
22
26
|
render: args => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InputNumberProps } from '../InputNumber/types'
|
|
2
2
|
|
|
3
|
-
export interface InputCurrencyProps extends /* @vue-ignore */ Pick<InputNumberProps, 'invalid'> {
|
|
3
|
+
export interface InputCurrencyProps extends /* @vue-ignore */ Pick<InputNumberProps, 'readonly' | 'disabled' | 'invalid'> {
|
|
4
4
|
currency?: string
|
|
5
5
|
currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'
|
|
6
6
|
}
|
|
@@ -13,6 +13,7 @@ const meta = {
|
|
|
13
13
|
step: { control: 'number' },
|
|
14
14
|
placeholder: { control: 'text' },
|
|
15
15
|
showButtons: { control: 'boolean' },
|
|
16
|
+
readonly: { control: 'boolean' },
|
|
16
17
|
disabled: { control: 'boolean' },
|
|
17
18
|
invalid: { control: 'boolean' },
|
|
18
19
|
},
|
|
@@ -23,6 +24,7 @@ const meta = {
|
|
|
23
24
|
step: 1,
|
|
24
25
|
placeholder: '',
|
|
25
26
|
showButtons: true,
|
|
27
|
+
readonly: false,
|
|
26
28
|
disabled: false,
|
|
27
29
|
invalid: false,
|
|
28
30
|
},
|
|
@@ -13,6 +13,7 @@ const props = withDefaults(defineProps<InputNumberProps>(), {
|
|
|
13
13
|
min: undefined,
|
|
14
14
|
max: undefined,
|
|
15
15
|
step: 1,
|
|
16
|
+
readonly: false,
|
|
16
17
|
disabled: false,
|
|
17
18
|
showButtons: true,
|
|
18
19
|
placeholder: undefined,
|
|
@@ -62,6 +63,7 @@ const inputClass = 'flex-1 min-w-0 border-0 shadow-none focus-visible:ring-0 rou
|
|
|
62
63
|
:min="min"
|
|
63
64
|
:max="max"
|
|
64
65
|
:step="step"
|
|
66
|
+
:readonly="readonly"
|
|
65
67
|
:disabled="disabled"
|
|
66
68
|
>
|
|
67
69
|
<NumberFieldContent :class="contentClass">
|
|
@@ -9,12 +9,14 @@ const meta = {
|
|
|
9
9
|
argTypes: {
|
|
10
10
|
modelValue: { control: 'text' },
|
|
11
11
|
length: { control: 'number' },
|
|
12
|
+
readonly: { control: 'boolean' },
|
|
12
13
|
disabled: { control: 'boolean' },
|
|
13
14
|
invalid: { control: 'boolean' },
|
|
14
15
|
},
|
|
15
16
|
args: {
|
|
16
17
|
modelValue: '',
|
|
17
18
|
length: 6,
|
|
19
|
+
readonly: false,
|
|
18
20
|
disabled: false,
|
|
19
21
|
invalid: false,
|
|
20
22
|
},
|
|
@@ -9,6 +9,7 @@ import type { InputOtpProps } from './types'
|
|
|
9
9
|
const props = withDefaults(defineProps<InputOtpProps>(), {
|
|
10
10
|
modelValue: '',
|
|
11
11
|
length: 6,
|
|
12
|
+
readonly: false,
|
|
12
13
|
disabled: false,
|
|
13
14
|
invalid: false,
|
|
14
15
|
})
|
|
@@ -24,6 +25,15 @@ function handleComplete (values: string[]) {
|
|
|
24
25
|
emit('complete', values.join(''))
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
// The native readonly attribute blocks typing and pasting, but PinInput
|
|
29
|
+
// mutates the model directly on Backspace/Delete, so intercept them here
|
|
30
|
+
function handleKeydownCapture (event: KeyboardEvent) {
|
|
31
|
+
if (props.readonly && (event.key === 'Backspace' || event.key === 'Delete')) {
|
|
32
|
+
event.preventDefault()
|
|
33
|
+
event.stopPropagation()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
function handleUpdate (value: string[]) {
|
|
28
38
|
emit('update:modelValue', value.join(''))
|
|
29
39
|
}
|
|
@@ -36,12 +46,14 @@ function handleUpdate (value: string[]) {
|
|
|
36
46
|
:disabled="disabled"
|
|
37
47
|
@update:modelValue="handleUpdate"
|
|
38
48
|
@complete="handleComplete"
|
|
49
|
+
@keydown.capture="handleKeydownCapture"
|
|
39
50
|
>
|
|
40
51
|
<PinInputGroup>
|
|
41
52
|
<PinInputSlot
|
|
42
53
|
v-for="(_, index) in length"
|
|
43
54
|
:key="index"
|
|
44
55
|
:index="index"
|
|
56
|
+
:readonly="readonly || undefined"
|
|
45
57
|
:aria-invalid="isInvalid || undefined"
|
|
46
58
|
/>
|
|
47
59
|
</PinInputGroup>
|
|
@@ -7,10 +7,14 @@ const meta = {
|
|
|
7
7
|
component: InputPercent as any,
|
|
8
8
|
argTypes: {
|
|
9
9
|
modelValue: { control: 'number' },
|
|
10
|
+
readonly: { control: 'boolean' },
|
|
11
|
+
disabled: { control: 'boolean' },
|
|
10
12
|
invalid: { control: 'boolean' },
|
|
11
13
|
},
|
|
12
14
|
args: {
|
|
13
15
|
modelValue: 0.5,
|
|
16
|
+
readonly: false,
|
|
17
|
+
disabled: false,
|
|
14
18
|
invalid: false,
|
|
15
19
|
},
|
|
16
20
|
render: args => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { InputNumberProps } from '../InputNumber/types'
|
|
2
2
|
|
|
3
|
-
export interface InputPercentProps extends /* @vue-ignore */ Pick<InputNumberProps, 'invalid'> {}
|
|
3
|
+
export interface InputPercentProps extends /* @vue-ignore */ Pick<InputNumberProps, 'readonly' | 'disabled' | 'invalid'> {}
|
|
@@ -14,6 +14,7 @@ const meta = {
|
|
|
14
14
|
max: { control: 'number' },
|
|
15
15
|
startPlaceholder: { control: 'text' },
|
|
16
16
|
endPlaceholder: { control: 'text' },
|
|
17
|
+
readonly: { control: 'boolean' },
|
|
17
18
|
disabled: { control: 'boolean' },
|
|
18
19
|
invalid: { control: 'boolean' },
|
|
19
20
|
as: { control: false },
|
|
@@ -25,6 +26,7 @@ const meta = {
|
|
|
25
26
|
max: 100,
|
|
26
27
|
startPlaceholder: '',
|
|
27
28
|
endPlaceholder: '',
|
|
29
|
+
readonly: false,
|
|
28
30
|
disabled: false,
|
|
29
31
|
invalid: false,
|
|
30
32
|
as: undefined,
|
|
@@ -42,12 +42,14 @@ const meta = {
|
|
|
42
42
|
argTypes: {
|
|
43
43
|
modelValue: { control: 'text' },
|
|
44
44
|
options: { control: 'object' },
|
|
45
|
+
readonly: { control: 'boolean' },
|
|
45
46
|
disabled: { control: 'boolean' },
|
|
46
47
|
invalid: { control: 'boolean' },
|
|
47
48
|
},
|
|
48
49
|
args: {
|
|
49
50
|
modelValue: 'current',
|
|
50
51
|
options,
|
|
52
|
+
readonly: false,
|
|
51
53
|
disabled: false,
|
|
52
54
|
invalid: false,
|
|
53
55
|
},
|
|
@@ -7,6 +7,7 @@ import type { RadioCardGroupProps } from './types'
|
|
|
7
7
|
|
|
8
8
|
const props = withDefaults(defineProps<RadioCardGroupProps>(), {
|
|
9
9
|
modelValue: undefined,
|
|
10
|
+
readonly: false,
|
|
10
11
|
disabled: false,
|
|
11
12
|
invalid: false,
|
|
12
13
|
class: undefined,
|
|
@@ -25,7 +26,41 @@ const model = computed({
|
|
|
25
26
|
},
|
|
26
27
|
})
|
|
27
28
|
|
|
29
|
+
// Cards select on click (labels forward clicks to the radio items) and arrow
|
|
30
|
+
// keys move the roving selection, so guard both at the group root when readonly
|
|
31
|
+
function handleClickCapture (event: Event) {
|
|
32
|
+
if (props.readonly) {
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
event.stopPropagation()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function handleKeydownCapture (event: KeyboardEvent) {
|
|
39
|
+
if (props.readonly && event.key.startsWith('Arrow')) {
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
event.stopPropagation()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
const mergedClass = computed(() => cn('gap-3', props.class))
|
|
46
|
+
|
|
47
|
+
const cardClass = (optionDisabled?: boolean) =>
|
|
48
|
+
cn(
|
|
49
|
+
`
|
|
50
|
+
gap-3 rounded-lg border-border px-4 py-3
|
|
51
|
+
has-data-[state=checked]:border-primary
|
|
52
|
+
flex items-center border transition-colors
|
|
53
|
+
has-data-disabled:cursor-not-allowed has-data-disabled:opacity-50
|
|
54
|
+
`,
|
|
55
|
+
props.readonly ? 'cursor-default' : 'cursor-pointer',
|
|
56
|
+
optionDisabled
|
|
57
|
+
? 'cursor-not-allowed opacity-50'
|
|
58
|
+
: !props.readonly && 'hover:bg-accent/50',
|
|
59
|
+
isInvalid.value && `
|
|
60
|
+
border-destructive
|
|
61
|
+
has-data-[state=checked]:border-destructive
|
|
62
|
+
`,
|
|
63
|
+
)
|
|
29
64
|
</script>
|
|
30
65
|
|
|
31
66
|
<template>
|
|
@@ -33,19 +68,14 @@ const mergedClass = computed(() => cn('gap-3', props.class))
|
|
|
33
68
|
v-model="model"
|
|
34
69
|
:disabled="disabled"
|
|
35
70
|
:class="mergedClass"
|
|
71
|
+
:aria-readonly="readonly || undefined"
|
|
72
|
+
@click.capture="handleClickCapture"
|
|
73
|
+
@keydown.capture="handleKeydownCapture"
|
|
36
74
|
>
|
|
37
75
|
<label
|
|
38
76
|
v-for="option in options"
|
|
39
77
|
:key="option.value"
|
|
40
|
-
class="
|
|
41
|
-
gap-3 rounded-lg border-border px-4 py-3
|
|
42
|
-
has-data-[state=checked]:border-primary
|
|
43
|
-
flex cursor-pointer items-center border transition-colors
|
|
44
|
-
has-data-disabled:cursor-not-allowed has-data-disabled:opacity-50
|
|
45
|
-
"
|
|
46
|
-
:class="[
|
|
47
|
-
option.disabled ? 'cursor-not-allowed opacity-50' : 'hover:bg-accent/50',
|
|
48
|
-
]"
|
|
78
|
+
:class="cardClass(option.disabled)"
|
|
49
79
|
>
|
|
50
80
|
<ShadcnRadioGroupItem
|
|
51
81
|
:value="option.value"
|
|
@@ -8,6 +8,8 @@ export interface RadioCardGroupOption {
|
|
|
8
8
|
export interface RadioCardGroupProps {
|
|
9
9
|
modelValue?: string
|
|
10
10
|
options: RadioCardGroupOption[]
|
|
11
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
12
|
+
readonly?: boolean
|
|
11
13
|
disabled?: boolean
|
|
12
14
|
invalid?: boolean
|
|
13
15
|
class?: ClassValue
|
|
@@ -22,6 +22,7 @@ const meta = {
|
|
|
22
22
|
argTypes: {
|
|
23
23
|
items: { control: 'object' },
|
|
24
24
|
modelValue: { control: 'text' },
|
|
25
|
+
readonly: { control: 'boolean' },
|
|
25
26
|
disabled: { control: 'boolean' },
|
|
26
27
|
invalid: { control: 'boolean' },
|
|
27
28
|
orientation: { control: 'inline-radio', options: [ 'vertical', 'horizontal' ]},
|
|
@@ -29,6 +30,7 @@ const meta = {
|
|
|
29
30
|
args: {
|
|
30
31
|
items: options,
|
|
31
32
|
modelValue: 'option1',
|
|
33
|
+
readonly: false,
|
|
32
34
|
disabled: false,
|
|
33
35
|
invalid: false,
|
|
34
36
|
orientation: 'vertical',
|
|
@@ -8,6 +8,7 @@ import type { RadioGroupItem, RadioGroupProps } from './types'
|
|
|
8
8
|
const props = withDefaults(defineProps<RadioGroupProps>(), {
|
|
9
9
|
items: () => [],
|
|
10
10
|
modelValue: undefined,
|
|
11
|
+
readonly: false,
|
|
11
12
|
disabled: false,
|
|
12
13
|
invalid: false,
|
|
13
14
|
orientation: 'vertical',
|
|
@@ -31,6 +32,22 @@ const model = computed({
|
|
|
31
32
|
},
|
|
32
33
|
})
|
|
33
34
|
|
|
35
|
+
// Items select on click (labels forward clicks to them) and arrow keys move
|
|
36
|
+
// the roving selection, so guard both at the group root when readonly
|
|
37
|
+
function handleClickCapture (event: Event) {
|
|
38
|
+
if (props.readonly) {
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
event.stopPropagation()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handleKeydownCapture (event: KeyboardEvent) {
|
|
45
|
+
if (props.readonly && event.key.startsWith('Arrow')) {
|
|
46
|
+
event.preventDefault()
|
|
47
|
+
event.stopPropagation()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
34
51
|
const orientationClass = {
|
|
35
52
|
horizontal: 'flex-row flex-wrap items-center',
|
|
36
53
|
vertical: 'flex-col',
|
|
@@ -49,14 +66,20 @@ const mergedClass = computed(() => cn(
|
|
|
49
66
|
:disabled="disabled"
|
|
50
67
|
:orientation="orientation"
|
|
51
68
|
:class="mergedClass"
|
|
69
|
+
:aria-readonly="readonly || undefined"
|
|
70
|
+
@click.capture="handleClickCapture"
|
|
71
|
+
@keydown.capture="handleKeydownCapture"
|
|
52
72
|
>
|
|
53
73
|
<label
|
|
54
74
|
v-for="item in items"
|
|
55
75
|
:key="item.value"
|
|
56
|
-
class="
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
:class="cn(
|
|
77
|
+
`
|
|
78
|
+
gap-2 flex items-center
|
|
79
|
+
has-data-disabled:cursor-not-allowed has-data-disabled:opacity-50
|
|
80
|
+
`,
|
|
81
|
+
readonly ? 'cursor-default' : 'cursor-pointer',
|
|
82
|
+
)"
|
|
60
83
|
>
|
|
61
84
|
<ShadcnRadioGroupItem
|
|
62
85
|
:value="item.value"
|
|
@@ -7,6 +7,8 @@ export interface RadioGroupItem {
|
|
|
7
7
|
export interface RadioGroupProps {
|
|
8
8
|
modelValue?: string
|
|
9
9
|
items?: RadioGroupItem[]
|
|
10
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
11
|
+
readonly?: boolean
|
|
10
12
|
disabled?: boolean
|
|
11
13
|
invalid?: boolean
|
|
12
14
|
orientation?: 'vertical' | 'horizontal'
|
|
@@ -51,6 +51,7 @@ const meta = {
|
|
|
51
51
|
createNewText: { control: 'text' },
|
|
52
52
|
loadLimit: { control: 'number' },
|
|
53
53
|
autoLoad: { control: 'boolean' },
|
|
54
|
+
readonly: { control: 'boolean' },
|
|
54
55
|
disabled: { control: 'boolean' },
|
|
55
56
|
invalid: { control: 'boolean' },
|
|
56
57
|
},
|
|
@@ -64,6 +65,7 @@ const meta = {
|
|
|
64
65
|
createNewText: '',
|
|
65
66
|
loadLimit: 20,
|
|
66
67
|
autoLoad: false,
|
|
68
|
+
readonly: false,
|
|
67
69
|
disabled: false,
|
|
68
70
|
invalid: false,
|
|
69
71
|
},
|
|
@@ -15,6 +15,7 @@ const props = withDefaults(defineProps<SearchSelectProps<TValue, TMeta>>(), {
|
|
|
15
15
|
loadValueOptionMethod: undefined,
|
|
16
16
|
loadLimit: 20,
|
|
17
17
|
placeholder: undefined,
|
|
18
|
+
readonly: false,
|
|
18
19
|
disabled: false,
|
|
19
20
|
invalid: false,
|
|
20
21
|
searchPlaceholder: undefined,
|
|
@@ -197,6 +198,7 @@ defineExpose({ refresh: resetAndLoad })
|
|
|
197
198
|
:placeholder="placeholder"
|
|
198
199
|
:searchPlaceholder="searchPlaceholder"
|
|
199
200
|
:emptyText="computedEmptyText"
|
|
201
|
+
:readonly="readonly"
|
|
200
202
|
:disabled="disabled"
|
|
201
203
|
:invalid="invalid"
|
|
202
204
|
:loading="isLoading"
|
|
@@ -26,6 +26,8 @@ export interface SearchSelectProps<V extends string | number = string, M = unkno
|
|
|
26
26
|
/** Items per request (default: 20) */
|
|
27
27
|
loadLimit?: number
|
|
28
28
|
placeholder?: string
|
|
29
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
30
|
+
readonly?: boolean
|
|
29
31
|
disabled?: boolean
|
|
30
32
|
invalid?: boolean
|
|
31
33
|
searchPlaceholder?: string
|
|
@@ -37,9 +37,11 @@ const meta = {
|
|
|
37
37
|
argTypes: {
|
|
38
38
|
modelValue: { control: 'text' },
|
|
39
39
|
placeholder: { control: 'text' },
|
|
40
|
+
readonly: { control: 'boolean' },
|
|
40
41
|
disabled: { control: 'boolean' },
|
|
41
42
|
invalid: { control: 'boolean' },
|
|
42
43
|
loading: { control: 'boolean' },
|
|
44
|
+
clearable: { control: 'boolean' },
|
|
43
45
|
filter: { control: 'boolean' },
|
|
44
46
|
multiple: { control: 'boolean' },
|
|
45
47
|
searchPlaceholder: { control: 'text' },
|
|
@@ -48,9 +50,11 @@ const meta = {
|
|
|
48
50
|
args: {
|
|
49
51
|
modelValue: undefined,
|
|
50
52
|
placeholder: 'Select an option',
|
|
53
|
+
readonly: false,
|
|
51
54
|
disabled: false,
|
|
52
55
|
invalid: false,
|
|
53
56
|
loading: false,
|
|
57
|
+
clearable: true,
|
|
54
58
|
filter: false,
|
|
55
59
|
multiple: false,
|
|
56
60
|
searchPlaceholder: '',
|
|
@@ -28,9 +28,11 @@ const props = withDefaults(defineProps<SelectProps<TValue, TMeta>>(), {
|
|
|
28
28
|
options: () => [],
|
|
29
29
|
modelValue: undefined,
|
|
30
30
|
placeholder: undefined,
|
|
31
|
+
readonly: false,
|
|
31
32
|
disabled: false,
|
|
32
33
|
invalid: false,
|
|
33
34
|
loading: false,
|
|
35
|
+
clearable: true,
|
|
34
36
|
filter: false,
|
|
35
37
|
searchPlaceholder: undefined,
|
|
36
38
|
emptyText: undefined,
|
|
@@ -39,6 +41,10 @@ const props = withDefaults(defineProps<SelectProps<TValue, TMeta>>(), {
|
|
|
39
41
|
|
|
40
42
|
const isInvalid = useFormItemInvalid(() => props.invalid)
|
|
41
43
|
|
|
44
|
+
// Alias the readonly prop: in this generic component vue-tsc resolves a bare
|
|
45
|
+
// `readonly` in the template to Vue's auto-imported readonly() instead
|
|
46
|
+
const readonlyActive = computed(() => props.readonly)
|
|
47
|
+
|
|
42
48
|
const emit = defineEmits<{
|
|
43
49
|
'update:modelValue': [value: TValue | TValue[]]
|
|
44
50
|
'search': [value: string]
|
|
@@ -56,13 +62,20 @@ defineSlots<{
|
|
|
56
62
|
const open = ref(false)
|
|
57
63
|
|
|
58
64
|
watch(open, value => {
|
|
59
|
-
if (value && props.disabled) {
|
|
65
|
+
if (value && (props.disabled || readonlyActive.value)) {
|
|
60
66
|
open.value = false
|
|
61
67
|
return
|
|
62
68
|
}
|
|
63
69
|
value ? emit('open') : emit('close')
|
|
64
70
|
})
|
|
65
71
|
|
|
72
|
+
function handleTriggerClickCapture (event: Event) {
|
|
73
|
+
if (readonlyActive.value) {
|
|
74
|
+
event.preventDefault()
|
|
75
|
+
event.stopPropagation()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
66
79
|
// -- Filter --
|
|
67
80
|
|
|
68
81
|
const commandFilterFunction = computed(() => {
|
|
@@ -145,7 +158,7 @@ const hasValue = computed(() => {
|
|
|
145
158
|
return props.modelValue !== undefined && props.modelValue !== null
|
|
146
159
|
})
|
|
147
160
|
|
|
148
|
-
const showClearButton = computed(() => hasValue.value && !props.disabled)
|
|
161
|
+
const showClearButton = computed(() => props.clearable && hasValue.value && !readonlyActive.value && !props.disabled)
|
|
149
162
|
|
|
150
163
|
function handleClear (event: MouseEvent) {
|
|
151
164
|
event.stopPropagation()
|
|
@@ -165,18 +178,22 @@ function handleClear (event: MouseEvent) {
|
|
|
165
178
|
tabindex="0"
|
|
166
179
|
:aria-expanded="open"
|
|
167
180
|
:aria-invalid="isInvalid || undefined"
|
|
181
|
+
:aria-readonly="readonlyActive || undefined"
|
|
168
182
|
:data-disabled="disabled || undefined"
|
|
169
183
|
:data-state="open ? 'open' : 'closed'"
|
|
170
|
-
class="
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
:class="cn(
|
|
185
|
+
`
|
|
186
|
+
data-[state=open]:border-ring data-[state=open]:ring-ring/50
|
|
187
|
+
aria-invalid:ring-destructive/20 aria-invalid:border-destructive
|
|
188
|
+
dark:aria-invalid:ring-destructive/40
|
|
189
|
+
aria-invalid:data-[state=open]:border-destructive
|
|
190
|
+
aria-invalid:data-[state=open]:ring-destructive/20
|
|
191
|
+
dark:aria-invalid:data-[state=open]:ring-destructive/40
|
|
192
|
+
data-[state=open]:ring-[3px]
|
|
193
|
+
`,
|
|
194
|
+
readonlyActive ? 'cursor-default' : 'cursor-pointer',
|
|
195
|
+
)"
|
|
196
|
+
@click.capture="handleTriggerClickCapture"
|
|
180
197
|
>
|
|
181
198
|
<span
|
|
182
199
|
class="
|
|
@@ -12,10 +12,14 @@ export type SelectFilterFunction = (items: string[], keyword: string) => string[
|
|
|
12
12
|
export type SelectBaseProps<V extends string | number = string, M = unknown> = {
|
|
13
13
|
options?: SelectOption<V, M>[]
|
|
14
14
|
placeholder?: string
|
|
15
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
16
|
+
readonly?: boolean
|
|
15
17
|
disabled?: boolean
|
|
16
18
|
invalid?: boolean
|
|
17
19
|
/** Show a spinner in place of the chevron */
|
|
18
20
|
loading?: boolean
|
|
21
|
+
/** Show a clear button when a value is selected */
|
|
22
|
+
clearable?: boolean
|
|
19
23
|
/** true: enable client-side label filter; function: custom filter (disables internal filter) */
|
|
20
24
|
filter?: boolean | SelectFilterFunction
|
|
21
25
|
/** Search input placeholder */
|
|
@@ -11,6 +11,7 @@ const meta = {
|
|
|
11
11
|
min: { control: 'number' },
|
|
12
12
|
max: { control: 'number' },
|
|
13
13
|
step: { control: 'number' },
|
|
14
|
+
readonly: { control: 'boolean' },
|
|
14
15
|
disabled: { control: 'boolean' },
|
|
15
16
|
orientation: { control: 'select', options: [ 'horizontal', 'vertical' ]},
|
|
16
17
|
},
|
|
@@ -19,6 +20,7 @@ const meta = {
|
|
|
19
20
|
min: 0,
|
|
20
21
|
max: 100,
|
|
21
22
|
step: 1,
|
|
23
|
+
readonly: false,
|
|
22
24
|
disabled: false,
|
|
23
25
|
orientation: 'horizontal',
|
|
24
26
|
},
|
|
@@ -20,8 +20,31 @@ const internalModel = computed({
|
|
|
20
20
|
emit('update:modelValue', isSingleValue.value ? (value[0] ?? 0) : value)
|
|
21
21
|
},
|
|
22
22
|
})
|
|
23
|
+
|
|
24
|
+
// Reka changes the value on pointer drag/track click and on thumb key
|
|
25
|
+
// presses, so guard both event types in the capture phase when readonly
|
|
26
|
+
function handlePointerdownCapture (event: Event) {
|
|
27
|
+
if (props.readonly) {
|
|
28
|
+
event.preventDefault()
|
|
29
|
+
event.stopPropagation()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const valueChangeKeys = [ 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown' ]
|
|
34
|
+
|
|
35
|
+
function handleKeydownCapture (event: KeyboardEvent) {
|
|
36
|
+
if (props.readonly && valueChangeKeys.includes(event.key)) {
|
|
37
|
+
event.preventDefault()
|
|
38
|
+
event.stopPropagation()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
23
41
|
</script>
|
|
24
42
|
|
|
25
43
|
<template>
|
|
26
|
-
<ShadcnSlider
|
|
44
|
+
<ShadcnSlider
|
|
45
|
+
v-model="internalModel"
|
|
46
|
+
:data-readonly="readonly ? '' : undefined"
|
|
47
|
+
@pointerdown.capture="handlePointerdownCapture"
|
|
48
|
+
@keydown.capture="handleKeydownCapture"
|
|
49
|
+
/>
|
|
27
50
|
</template>
|
|
@@ -2,4 +2,6 @@ import type { SliderRootProps } from 'reka-ui'
|
|
|
2
2
|
|
|
3
3
|
export interface SliderProps extends /* @vue-ignore */ Omit<SliderRootProps, 'modelValue' | 'defaultValue'> {
|
|
4
4
|
modelValue?: number | number[]
|
|
5
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
6
|
+
readonly?: boolean
|
|
5
7
|
}
|
|
@@ -8,10 +8,12 @@ const meta = {
|
|
|
8
8
|
component: Switch,
|
|
9
9
|
argTypes: {
|
|
10
10
|
modelValue: { control: 'boolean' },
|
|
11
|
+
readonly: { control: 'boolean' },
|
|
11
12
|
disabled: { control: 'boolean' },
|
|
12
13
|
},
|
|
13
14
|
args: {
|
|
14
15
|
modelValue: true,
|
|
16
|
+
readonly: false,
|
|
15
17
|
disabled: false,
|
|
16
18
|
},
|
|
17
19
|
render: args => {
|
|
@@ -2,9 +2,29 @@
|
|
|
2
2
|
import { Switch as ShadcnSwitch } from '../../shadcn/switch'
|
|
3
3
|
import type { SwitchProps } from './types'
|
|
4
4
|
|
|
5
|
-
defineProps<SwitchProps>()
|
|
5
|
+
const props = defineProps<SwitchProps>()
|
|
6
|
+
|
|
7
|
+
// Reka toggles on click (pointer and Space) and on Enter via its own keydown
|
|
8
|
+
// handler, so both events need a capture-phase guard when readonly
|
|
9
|
+
function handleClickCapture (event: Event) {
|
|
10
|
+
if (props.readonly) {
|
|
11
|
+
event.preventDefault()
|
|
12
|
+
event.stopPropagation()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function handleKeydownCapture (event: KeyboardEvent) {
|
|
17
|
+
if (props.readonly && (event.key === 'Enter' || event.key === ' ')) {
|
|
18
|
+
event.preventDefault()
|
|
19
|
+
event.stopPropagation()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
</script>
|
|
7
23
|
|
|
8
24
|
<template>
|
|
9
|
-
<ShadcnSwitch
|
|
25
|
+
<ShadcnSwitch
|
|
26
|
+
:aria-readonly="readonly || undefined"
|
|
27
|
+
@click.capture="handleClickCapture"
|
|
28
|
+
@keydown.capture="handleKeydownCapture"
|
|
29
|
+
/>
|
|
10
30
|
</template>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { SwitchRootProps } from 'reka-ui'
|
|
2
2
|
|
|
3
|
-
export interface SwitchProps extends /* @vue-ignore */ SwitchRootProps {
|
|
3
|
+
export interface SwitchProps extends /* @vue-ignore */ SwitchRootProps {
|
|
4
|
+
/** Keep the value visible and focusable but prevent changing it */
|
|
5
|
+
readonly?: boolean
|
|
6
|
+
}
|
|
@@ -12,6 +12,8 @@ const meta = {
|
|
|
12
12
|
rows: { control: 'number' },
|
|
13
13
|
maxlength: { control: 'number' },
|
|
14
14
|
showCount: { control: 'boolean' },
|
|
15
|
+
readonly: { control: 'boolean' },
|
|
16
|
+
disabled: { control: 'boolean' },
|
|
15
17
|
invalid: { control: 'boolean' },
|
|
16
18
|
class: { control: 'text' },
|
|
17
19
|
},
|
|
@@ -21,6 +23,8 @@ const meta = {
|
|
|
21
23
|
rows: undefined,
|
|
22
24
|
maxlength: undefined,
|
|
23
25
|
showCount: false,
|
|
26
|
+
readonly: false,
|
|
27
|
+
disabled: false,
|
|
24
28
|
invalid: false,
|
|
25
29
|
class: '',
|
|
26
30
|
},
|
|
@@ -10,6 +10,8 @@ const props = withDefaults(defineProps<TextareaProps>(), {
|
|
|
10
10
|
rows: undefined,
|
|
11
11
|
maxlength: undefined,
|
|
12
12
|
showCount: false,
|
|
13
|
+
readonly: false,
|
|
14
|
+
disabled: false,
|
|
13
15
|
invalid: false,
|
|
14
16
|
class: undefined,
|
|
15
17
|
})
|
|
@@ -59,6 +61,8 @@ const mergedClass = computed(() =>
|
|
|
59
61
|
:modelValue="modelValue"
|
|
60
62
|
:rows="rows"
|
|
61
63
|
:maxlength="maxlength"
|
|
64
|
+
:readonly="readonly"
|
|
65
|
+
:disabled="disabled"
|
|
62
66
|
:class="mergedClass"
|
|
63
67
|
:aria-invalid="isInvalid || undefined"
|
|
64
68
|
:data-1p-ignore="autocomplete === 'off' || !autocomplete ? true : undefined"
|
|
@@ -7,6 +7,8 @@ export interface TextareaProps {
|
|
|
7
7
|
maxlength?: number
|
|
8
8
|
/** Show character count below the textarea (rendered as `count / maxlength` when maxlength is set) */
|
|
9
9
|
showCount?: boolean
|
|
10
|
+
readonly?: boolean
|
|
11
|
+
disabled?: boolean
|
|
10
12
|
invalid?: boolean
|
|
11
13
|
class?: ClassValue
|
|
12
14
|
}
|
|
@@ -18,8 +18,6 @@ const localePath = useLocalePath()
|
|
|
18
18
|
|
|
19
19
|
const isExternal = computed(() => props.href ? isUrl(props.href) : false)
|
|
20
20
|
|
|
21
|
-
const showExternalIcon = computed(() => props.externalIcon && isExternal.value)
|
|
22
|
-
|
|
23
21
|
// Compute the final destination (supports both href string and to route object)
|
|
24
22
|
const finalTo = computed<RouteLocationRaw | undefined>(() => {
|
|
25
23
|
if (props.to) return props.to
|
|
@@ -39,6 +37,8 @@ const finalRel = computed(() => {
|
|
|
39
37
|
return finalTarget.value === '_blank' ? 'noopener noreferrer' : undefined
|
|
40
38
|
})
|
|
41
39
|
|
|
40
|
+
const showExternalIcon = computed(() => props.externalIcon && finalTarget.value === '_blank')
|
|
41
|
+
|
|
42
42
|
// Merge default class with external class
|
|
43
43
|
const mergedClass = computed(() => {
|
|
44
44
|
if (props.unstyled) {
|
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.10",
|
|
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": "acf837f913649d6fc7abc4688ddcdee097e45ab9"
|
|
46
46
|
}
|