@bitrix24/b24ui-nuxt 0.5.10 → 0.5.11
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/dist/meta.cjs +72112 -0
- package/dist/meta.d.cts +72110 -0
- package/dist/meta.d.mts +5060 -5060
- package/dist/meta.d.ts +72110 -0
- package/dist/meta.mjs +5060 -5060
- package/dist/module.cjs +63 -0
- package/dist/module.d.cts +15 -0
- package/dist/module.d.ts +15 -0
- package/dist/module.json +3 -3
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/Advice.vue +54 -47
- package/dist/runtime/components/Alert.vue +96 -71
- package/dist/runtime/components/App.vue +34 -37
- package/dist/runtime/components/Avatar.vue +81 -69
- package/dist/runtime/components/AvatarGroup.vue +76 -53
- package/dist/runtime/components/Badge.vue +83 -83
- package/dist/runtime/components/Button.vue +157 -220
- package/dist/runtime/components/ButtonGroup.vue +51 -35
- package/dist/runtime/components/Calendar.vue +152 -186
- package/dist/runtime/components/Checkbox.vue +73 -84
- package/dist/runtime/components/Chip.vue +74 -59
- package/dist/runtime/components/Collapsible.vue +41 -44
- package/dist/runtime/components/Container.vue +27 -18
- package/dist/runtime/components/Countdown.vue +378 -198
- package/dist/runtime/components/DescriptionList.vue +149 -102
- package/dist/runtime/components/DropdownMenu.vue +139 -83
- package/dist/runtime/components/DropdownMenuContent.vue +84 -137
- package/dist/runtime/components/Form.vue +216 -162
- package/dist/runtime/components/FormField.vue +80 -76
- package/dist/runtime/components/Input.vue +179 -160
- package/dist/runtime/components/InputMenu.vue +380 -300
- package/dist/runtime/components/InputNumber.vue +175 -178
- package/dist/runtime/components/Kbd.vue +45 -33
- package/dist/runtime/components/Link.vue +173 -179
- package/dist/runtime/components/LinkBase.vue +42 -64
- package/dist/runtime/components/Modal.vue +127 -105
- package/dist/runtime/components/ModalDialogClose.vue +8 -4
- package/dist/runtime/components/Navbar.vue +33 -24
- package/dist/runtime/components/NavbarDivider.vue +33 -24
- package/dist/runtime/components/NavbarSection.vue +33 -24
- package/dist/runtime/components/NavbarSpacer.vue +33 -24
- package/dist/runtime/components/NavigationMenu.vue +210 -144
- package/dist/runtime/components/OverlayProvider.vue +17 -13
- package/dist/runtime/components/Popover.vue +81 -81
- package/dist/runtime/components/Progress.vue +136 -109
- package/dist/runtime/components/RadioGroup.vue +134 -120
- package/dist/runtime/components/Range.vue +85 -94
- package/dist/runtime/components/Select.vue +260 -212
- package/dist/runtime/components/SelectMenu.vue +365 -272
- package/dist/runtime/components/Separator.vue +71 -61
- package/dist/runtime/components/Sidebar.vue +33 -24
- package/dist/runtime/components/SidebarBody.vue +38 -30
- package/dist/runtime/components/SidebarFooter.vue +33 -24
- package/dist/runtime/components/SidebarHeader.vue +33 -24
- package/dist/runtime/components/SidebarHeading.vue +33 -24
- package/dist/runtime/components/SidebarLayout.vue +70 -40
- package/dist/runtime/components/SidebarSection.vue +33 -24
- package/dist/runtime/components/SidebarSpacer.vue +33 -24
- package/dist/runtime/components/Skeleton.vue +22 -17
- package/dist/runtime/components/Slideover.vue +131 -108
- package/dist/runtime/components/StackedLayout.vue +73 -40
- package/dist/runtime/components/Switch.vue +95 -100
- package/dist/runtime/components/Tabs.vue +107 -81
- package/dist/runtime/components/Textarea.vue +201 -177
- package/dist/runtime/components/Toast.vue +105 -94
- package/dist/runtime/components/Toaster.vue +116 -94
- package/dist/runtime/components/Tooltip.vue +64 -78
- package/dist/runtime/components/content/TableWrapper.vue +70 -58
- package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
- package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
- package/dist/runtime/composables/useComponentIcons.d.ts +3 -3
- package/dist/runtime/composables/useFormField.d.ts +1 -1
- package/dist/runtime/prose/A.vue +23 -18
- package/dist/runtime/prose/Blockquote.vue +23 -18
- package/dist/runtime/prose/Code.vue +31 -23
- package/dist/runtime/prose/Em.vue +23 -18
- package/dist/runtime/prose/H1.vue +23 -18
- package/dist/runtime/prose/H2.vue +23 -18
- package/dist/runtime/prose/H3.vue +23 -18
- package/dist/runtime/prose/H4.vue +23 -18
- package/dist/runtime/prose/H5.vue +23 -18
- package/dist/runtime/prose/H6.vue +23 -18
- package/dist/runtime/prose/Hr.vue +19 -18
- package/dist/runtime/prose/Img.vue +23 -18
- package/dist/runtime/prose/Li.vue +23 -18
- package/dist/runtime/prose/Ol.vue +23 -18
- package/dist/runtime/prose/P.vue +23 -18
- package/dist/runtime/prose/Pre.vue +33 -28
- package/dist/runtime/prose/Strong.vue +23 -18
- package/dist/runtime/prose/Table.vue +54 -44
- package/dist/runtime/prose/Tbody.vue +23 -18
- package/dist/runtime/prose/Td.vue +23 -18
- package/dist/runtime/prose/Th.vue +23 -18
- package/dist/runtime/prose/Thead.vue +23 -18
- package/dist/runtime/prose/Tr.vue +23 -18
- package/dist/runtime/prose/Ul.vue +23 -18
- package/dist/runtime/vue/components/Link.vue +202 -201
- package/dist/shared/b24ui-nuxt.DrKwIWoc.cjs +7721 -0
- package/dist/types.d.mts +5 -3
- package/dist/types.d.ts +7 -0
- package/dist/unplugin.cjs +236 -0
- package/dist/unplugin.d.cts +33 -0
- package/dist/unplugin.d.ts +33 -0
- package/dist/vite.cjs +21 -0
- package/dist/vite.d.cts +14 -0
- package/dist/vite.d.ts +14 -0
- package/package.json +25 -13
- package/dist/runtime/components/Advice.vue.d.ts +0 -170
- package/dist/runtime/components/Alert.vue.d.ts +0 -464
- package/dist/runtime/components/App.vue.d.ts +0 -23
- package/dist/runtime/components/Avatar.vue.d.ts +0 -281
- package/dist/runtime/components/AvatarGroup.vue.d.ts +0 -204
- package/dist/runtime/components/Badge.vue.d.ts +0 -517
- package/dist/runtime/components/Button.vue.d.ts +0 -640
- package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -116
- package/dist/runtime/components/Calendar.vue.d.ts +0 -437
- package/dist/runtime/components/Checkbox.vue.d.ts +0 -354
- package/dist/runtime/components/Chip.vue.d.ts +0 -271
- package/dist/runtime/components/Collapsible.vue.d.ts +0 -118
- package/dist/runtime/components/Container.vue.d.ts +0 -27
- package/dist/runtime/components/Countdown.vue.d.ts +0 -356
- package/dist/runtime/components/DescriptionList.vue.d.ts +0 -379
- package/dist/runtime/components/DropdownMenu.vue.d.ts +0 -533
- package/dist/runtime/components/DropdownMenuContent.vue.d.ts +0 -228
- package/dist/runtime/components/Form.vue.d.ts +0 -55
- package/dist/runtime/components/FormField.vue.d.ts +0 -282
- package/dist/runtime/components/Input.vue.d.ts +0 -755
- package/dist/runtime/components/InputMenu.vue.d.ts +0 -1504
- package/dist/runtime/components/InputNumber.vue.d.ts +0 -658
- package/dist/runtime/components/Kbd.vue.d.ts +0 -109
- package/dist/runtime/components/Link.vue.d.ts +0 -129
- package/dist/runtime/components/LinkBase.vue.d.ts +0 -48
- package/dist/runtime/components/Modal.vue.d.ts +0 -327
- package/dist/runtime/components/ModalDialogClose.vue.d.ts +0 -10
- package/dist/runtime/components/Navbar.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarDivider.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSection.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/NavigationMenu.vue.d.ts +0 -824
- package/dist/runtime/components/OverlayProvider.vue.d.ts +0 -2
- package/dist/runtime/components/Popover.vue.d.ts +0 -147
- package/dist/runtime/components/Progress.vue.d.ts +0 -592
- package/dist/runtime/components/RadioGroup.vue.d.ts +0 -723
- package/dist/runtime/components/Range.vue.d.ts +0 -417
- package/dist/runtime/components/Select.vue.d.ts +0 -1200
- package/dist/runtime/components/SelectMenu.vue.d.ts +0 -1298
- package/dist/runtime/components/Separator.vue.d.ts +0 -400
- package/dist/runtime/components/Sidebar.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarBody.vue.d.ts +0 -90
- package/dist/runtime/components/SidebarFooter.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeader.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeading.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarLayout.vue.d.ts +0 -222
- package/dist/runtime/components/SidebarSection.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/Skeleton.vue.d.ts +0 -26
- package/dist/runtime/components/Slideover.vue.d.ts +0 -360
- package/dist/runtime/components/StackedLayout.vue.d.ts +0 -192
- package/dist/runtime/components/Switch.vue.d.ts +0 -587
- package/dist/runtime/components/Tabs.vue.d.ts +0 -453
- package/dist/runtime/components/Textarea.vue.d.ts +0 -601
- package/dist/runtime/components/Toast.vue.d.ts +0 -438
- package/dist/runtime/components/Toaster.vue.d.ts +0 -219
- package/dist/runtime/components/Tooltip.vue.d.ts +0 -186
- package/dist/runtime/components/content/TableWrapper.vue.d.ts +0 -237
- package/dist/runtime/prose/A.vue.d.ts +0 -84
- package/dist/runtime/prose/Blockquote.vue.d.ts +0 -84
- package/dist/runtime/prose/Code.vue.d.ts +0 -97
- package/dist/runtime/prose/Em.vue.d.ts +0 -84
- package/dist/runtime/prose/H1.vue.d.ts +0 -97
- package/dist/runtime/prose/H2.vue.d.ts +0 -123
- package/dist/runtime/prose/H3.vue.d.ts +0 -123
- package/dist/runtime/prose/H4.vue.d.ts +0 -123
- package/dist/runtime/prose/H5.vue.d.ts +0 -123
- package/dist/runtime/prose/H6.vue.d.ts +0 -123
- package/dist/runtime/prose/Hr.vue.d.ts +0 -74
- package/dist/runtime/prose/Img.vue.d.ts +0 -77
- package/dist/runtime/prose/Li.vue.d.ts +0 -84
- package/dist/runtime/prose/Ol.vue.d.ts +0 -84
- package/dist/runtime/prose/P.vue.d.ts +0 -84
- package/dist/runtime/prose/Pre.vue.d.ts +0 -117
- package/dist/runtime/prose/Strong.vue.d.ts +0 -84
- package/dist/runtime/prose/Table.vue.d.ts +0 -144
- package/dist/runtime/prose/Tbody.vue.d.ts +0 -84
- package/dist/runtime/prose/Td.vue.d.ts +0 -84
- package/dist/runtime/prose/Th.vue.d.ts +0 -84
- package/dist/runtime/prose/Thead.vue.d.ts +0 -84
- package/dist/runtime/prose/Tr.vue.d.ts +0 -84
- package/dist/runtime/prose/Ul.vue.d.ts +0 -84
- package/dist/runtime/vue/components/Link.vue.d.ts +0 -129
|
@@ -1,151 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<!-- eslint-disable vue/block-tag-newline -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import type { VariantProps } from 'tailwind-variants'
|
|
4
|
+
import type { ProgressRootProps, ProgressRootEmits } from 'reka-ui'
|
|
5
|
+
import type { AppConfig } from '@nuxt/schema'
|
|
6
|
+
import _appConfig from '#build/app.config'
|
|
7
|
+
import theme from '#build/b24ui/progress'
|
|
8
|
+
import { tv } from '../utils/tv'
|
|
9
|
+
|
|
10
|
+
const appConfigProgress = _appConfig as AppConfig & { b24ui: { progress: Partial<typeof theme> } }
|
|
11
|
+
|
|
12
|
+
const progress = tv({ extend: tv(theme), ...(appConfigProgress.b24ui?.progress || {}) })
|
|
13
|
+
|
|
14
|
+
type ProgressVariants = VariantProps<typeof progress>
|
|
15
|
+
|
|
16
|
+
export interface ProgressProps extends Pick<ProgressRootProps, 'getValueLabel' | 'modelValue'> {
|
|
17
|
+
/**
|
|
18
|
+
* The element or component this component should render as.
|
|
19
|
+
* @defaultValue 'div'
|
|
20
|
+
*/
|
|
21
|
+
as?: any
|
|
22
|
+
/**
|
|
23
|
+
* The maximum progress value
|
|
24
|
+
*/
|
|
25
|
+
max?: number | Array<any>
|
|
26
|
+
/**
|
|
27
|
+
* Display the current progress value
|
|
28
|
+
*/
|
|
29
|
+
status?: boolean
|
|
30
|
+
/**
|
|
31
|
+
* Whether the progress is visually inverted
|
|
32
|
+
* @defaultValue false
|
|
33
|
+
*/
|
|
34
|
+
inverted?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* @defaultValue 'md'
|
|
37
|
+
*/
|
|
38
|
+
size?: ProgressVariants['size']
|
|
39
|
+
/**
|
|
40
|
+
* @defaultValue 'primary'
|
|
41
|
+
*/
|
|
42
|
+
color?: ProgressVariants['color']
|
|
43
|
+
/**
|
|
44
|
+
* The orientation of the progress bar.
|
|
45
|
+
* @defaultValue 'horizontal'
|
|
46
|
+
*/
|
|
47
|
+
orientation?: ProgressVariants['orientation']
|
|
48
|
+
/**
|
|
49
|
+
* @defaultValue 'loading'
|
|
50
|
+
*/
|
|
51
|
+
animation?: ProgressVariants['animation']
|
|
52
|
+
class?: any
|
|
53
|
+
b24ui?: Partial<typeof progress.slots>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ProgressEmits extends ProgressRootEmits {}
|
|
57
|
+
|
|
58
|
+
export type ProgressSlots = {
|
|
59
|
+
status(props: { percent?: number }): any
|
|
60
|
+
} & {
|
|
61
|
+
[key: string]: (props: { step: number }) => any
|
|
62
|
+
}
|
|
63
|
+
|
|
7
64
|
</script>
|
|
8
65
|
|
|
9
|
-
<script setup>
|
|
10
|
-
import { computed } from
|
|
11
|
-
import { useForwardPropsEmits } from
|
|
12
|
-
import { reactivePick } from
|
|
13
|
-
import { useLocale } from
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
default: false
|
|
31
|
-
},
|
|
32
|
-
size: {
|
|
33
|
-
type: null,
|
|
34
|
-
required: false
|
|
35
|
-
},
|
|
36
|
-
color: {
|
|
37
|
-
type: null,
|
|
38
|
-
required: false
|
|
39
|
-
},
|
|
40
|
-
orientation: {
|
|
41
|
-
type: null,
|
|
42
|
-
required: false,
|
|
43
|
-
default: "horizontal"
|
|
44
|
-
},
|
|
45
|
-
animation: {
|
|
46
|
-
type: null,
|
|
47
|
-
required: false
|
|
48
|
-
},
|
|
49
|
-
class: {
|
|
50
|
-
type: null,
|
|
51
|
-
required: false
|
|
52
|
-
},
|
|
53
|
-
b24ui: {
|
|
54
|
-
type: Object,
|
|
55
|
-
required: false
|
|
56
|
-
},
|
|
57
|
-
getValueLabel: {
|
|
58
|
-
type: Function,
|
|
59
|
-
required: false
|
|
60
|
-
},
|
|
61
|
-
modelValue: {
|
|
62
|
-
type: [Number, null],
|
|
63
|
-
required: false,
|
|
64
|
-
default: null
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const emits = defineEmits(["update:modelValue", "update:max"]);
|
|
68
|
-
const slots = defineSlots();
|
|
69
|
-
const { dir } = useLocale();
|
|
70
|
-
const rootProps = useForwardPropsEmits(reactivePick(props, "getValueLabel", "modelValue"), emits);
|
|
71
|
-
const isIndeterminate = computed(() => rootProps.value.modelValue === null);
|
|
72
|
-
const hasSteps = computed(() => Array.isArray(props.max));
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { computed } from 'vue'
|
|
68
|
+
import { Primitive, ProgressRoot, ProgressIndicator, useForwardPropsEmits } from 'reka-ui'
|
|
69
|
+
import { reactivePick } from '@vueuse/core'
|
|
70
|
+
import { useLocale } from '../composables/useLocale'
|
|
71
|
+
|
|
72
|
+
const props = withDefaults(defineProps<ProgressProps>(), {
|
|
73
|
+
inverted: false,
|
|
74
|
+
modelValue: null,
|
|
75
|
+
orientation: 'horizontal'
|
|
76
|
+
})
|
|
77
|
+
const emits = defineEmits<ProgressEmits>()
|
|
78
|
+
const slots = defineSlots<ProgressSlots>()
|
|
79
|
+
|
|
80
|
+
const { dir } = useLocale()
|
|
81
|
+
|
|
82
|
+
const rootProps = useForwardPropsEmits(reactivePick(props, 'getValueLabel', 'modelValue'), emits)
|
|
83
|
+
|
|
84
|
+
const isIndeterminate = computed(() => rootProps.value.modelValue === null)
|
|
85
|
+
const hasSteps = computed(() => Array.isArray(props.max))
|
|
86
|
+
|
|
73
87
|
const realMax = computed(() => {
|
|
74
88
|
if (isIndeterminate.value || !props.max) {
|
|
75
|
-
return
|
|
89
|
+
return undefined
|
|
76
90
|
}
|
|
91
|
+
|
|
77
92
|
if (Array.isArray(props.max)) {
|
|
78
|
-
return props.max.length - 1
|
|
93
|
+
return props.max.length - 1
|
|
79
94
|
}
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
|
|
96
|
+
return Number(props.max)
|
|
97
|
+
})
|
|
98
|
+
|
|
82
99
|
const percent = computed(() => {
|
|
83
100
|
if (isIndeterminate.value) {
|
|
84
|
-
return
|
|
101
|
+
return undefined
|
|
85
102
|
}
|
|
103
|
+
|
|
86
104
|
switch (true) {
|
|
87
|
-
case rootProps.value.modelValue < 0:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return 100;
|
|
91
|
-
default:
|
|
92
|
-
return Math.round(rootProps.value.modelValue / (realMax.value ?? 100) * 100);
|
|
105
|
+
case rootProps.value.modelValue! < 0: return 0
|
|
106
|
+
case rootProps.value.modelValue! > (realMax.value ?? 100): return 100
|
|
107
|
+
default: return Math.round((rootProps.value.modelValue! / (realMax.value ?? 100)) * 100)
|
|
93
108
|
}
|
|
94
|
-
})
|
|
109
|
+
})
|
|
110
|
+
|
|
95
111
|
const indicatorStyle = computed(() => {
|
|
96
|
-
if (percent.value ===
|
|
97
|
-
return
|
|
112
|
+
if (percent.value === undefined) {
|
|
113
|
+
return
|
|
98
114
|
}
|
|
99
|
-
|
|
115
|
+
|
|
116
|
+
if (props.orientation === 'vertical') {
|
|
100
117
|
return {
|
|
101
|
-
transform: `translateY(${props.inverted ?
|
|
102
|
-
}
|
|
118
|
+
transform: `translateY(${props.inverted ? '' : '-'}${100 - percent.value}%)`
|
|
119
|
+
}
|
|
103
120
|
} else {
|
|
104
|
-
if (dir.value ===
|
|
121
|
+
if (dir.value === 'rtl') {
|
|
105
122
|
return {
|
|
106
|
-
transform: `translateX(${props.inverted ?
|
|
107
|
-
}
|
|
123
|
+
transform: `translateX(${props.inverted ? '-' : ''}${100 - percent.value}%)`
|
|
124
|
+
}
|
|
108
125
|
} else {
|
|
109
126
|
return {
|
|
110
|
-
transform: `translateX(${props.inverted ?
|
|
111
|
-
}
|
|
127
|
+
transform: `translateX(${props.inverted ? '' : '-'}${100 - percent.value}%)`
|
|
128
|
+
}
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
|
-
})
|
|
131
|
+
})
|
|
132
|
+
|
|
115
133
|
const statusStyle = computed(() => {
|
|
116
134
|
return {
|
|
117
|
-
[props.orientation ===
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
[props.orientation === 'vertical' ? 'height' : 'width']: percent.value ? `${percent.value}%` : 'fit-content'
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
function isActive(index: number) {
|
|
140
|
+
return index === Number(props.modelValue)
|
|
122
141
|
}
|
|
123
|
-
|
|
124
|
-
|
|
142
|
+
|
|
143
|
+
function isFirst(index: number) {
|
|
144
|
+
return index === 0
|
|
125
145
|
}
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
|
|
147
|
+
function isLast(index: number) {
|
|
148
|
+
return index === realMax.value
|
|
128
149
|
}
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
|
|
151
|
+
function stepVariant(index: number | string) {
|
|
152
|
+
index = Number(index)
|
|
153
|
+
|
|
131
154
|
if (isActive(index) && !isFirst(index)) {
|
|
132
|
-
return
|
|
155
|
+
return 'active'
|
|
133
156
|
}
|
|
157
|
+
|
|
134
158
|
if (isFirst(index) && isActive(index)) {
|
|
135
|
-
return
|
|
159
|
+
return 'first'
|
|
136
160
|
}
|
|
161
|
+
|
|
137
162
|
if (isLast(index) && isActive(index)) {
|
|
138
|
-
return
|
|
163
|
+
return 'last'
|
|
139
164
|
}
|
|
140
|
-
|
|
165
|
+
|
|
166
|
+
return 'other'
|
|
141
167
|
}
|
|
168
|
+
|
|
142
169
|
const b24ui = computed(() => progress({
|
|
143
170
|
animation: props.animation,
|
|
144
171
|
size: props.size,
|
|
145
172
|
color: props.color,
|
|
146
173
|
orientation: props.orientation,
|
|
147
174
|
inverted: props.inverted
|
|
148
|
-
}))
|
|
175
|
+
}))
|
|
149
176
|
</script>
|
|
150
177
|
|
|
151
178
|
<template>
|
|
@@ -1,104 +1,110 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { VariantProps } from 'tailwind-variants'
|
|
3
|
+
import type { RadioGroupRootProps, RadioGroupRootEmits } from 'reka-ui'
|
|
4
|
+
import type { AppConfig } from '@nuxt/schema'
|
|
5
|
+
import _appConfig from '#build/app.config'
|
|
6
|
+
import theme from '#build/b24ui/radio-group'
|
|
7
|
+
import { tv } from '../utils/tv'
|
|
8
|
+
import type { AcceptableValue } from '../types/utils'
|
|
9
|
+
|
|
10
|
+
const appConfigRadioGroup = _appConfig as AppConfig & { b24ui: { radioGroup: Partial<typeof theme> } }
|
|
11
|
+
|
|
12
|
+
const radioGroup = tv({ extend: tv(theme), ...(appConfigRadioGroup.b24ui?.radioGroup || {}) })
|
|
13
|
+
|
|
14
|
+
type RadioGroupVariants = VariantProps<typeof radioGroup>
|
|
15
|
+
|
|
16
|
+
export type RadioGroupValue = AcceptableValue
|
|
17
|
+
export type RadioGroupItem = {
|
|
18
|
+
label?: string
|
|
19
|
+
description?: string
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
value?: string
|
|
22
|
+
[key: string]: any
|
|
23
|
+
} | RadioGroupValue
|
|
24
|
+
|
|
25
|
+
export interface RadioGroupProps<T extends RadioGroupItem = RadioGroupItem> extends Pick<RadioGroupRootProps, 'defaultValue' | 'disabled' | 'loop' | 'modelValue' | 'name' | 'required'> {
|
|
26
|
+
/**
|
|
27
|
+
* The element or component this component should render as.
|
|
28
|
+
* @defaultValue 'div'
|
|
29
|
+
*/
|
|
30
|
+
as?: any
|
|
31
|
+
legend?: string
|
|
32
|
+
/**
|
|
33
|
+
* When `items` is an array of objects, select the field to use as the value.
|
|
34
|
+
* @defaultValue 'value'
|
|
35
|
+
*/
|
|
36
|
+
valueKey?: string
|
|
37
|
+
/**
|
|
38
|
+
* When `items` is an array of objects, select the field to use as the label.
|
|
39
|
+
* @defaultValue 'label'
|
|
40
|
+
*/
|
|
41
|
+
labelKey?: string
|
|
42
|
+
/**
|
|
43
|
+
* When `items` is an array of objects, select the field to use as the description.
|
|
44
|
+
* @defaultValue 'description'
|
|
45
|
+
*/
|
|
46
|
+
descriptionKey?: string
|
|
47
|
+
items?: T[]
|
|
48
|
+
/**
|
|
49
|
+
* @defaultValue 'md'
|
|
50
|
+
*/
|
|
51
|
+
size?: RadioGroupVariants['size']
|
|
52
|
+
/**
|
|
53
|
+
* @defaultValue 'list'
|
|
54
|
+
*/
|
|
55
|
+
variant?: RadioGroupVariants['variant']
|
|
56
|
+
/**
|
|
57
|
+
* @defaultValue 'primary'
|
|
58
|
+
*/
|
|
59
|
+
color?: RadioGroupVariants['color']
|
|
60
|
+
/**
|
|
61
|
+
* The orientation the radio buttons are laid out.
|
|
62
|
+
* @defaultValue 'vertical'
|
|
63
|
+
*/
|
|
64
|
+
orientation?: RadioGroupRootProps['orientation']
|
|
65
|
+
/**
|
|
66
|
+
* Position of the indicator.
|
|
67
|
+
* @defaultValue 'start'
|
|
68
|
+
*/
|
|
69
|
+
indicator?: RadioGroupVariants['indicator']
|
|
70
|
+
class?: any
|
|
71
|
+
b24ui?: Partial<typeof radioGroup.slots>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type RadioGroupEmits = RadioGroupRootEmits & {
|
|
75
|
+
change: [payload: Event]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type SlotProps<T extends RadioGroupItem> = (props: { item: T & { id: string }, modelValue?: RadioGroupValue }) => any
|
|
79
|
+
|
|
80
|
+
export interface RadioGroupSlots<T extends RadioGroupItem = RadioGroupItem> {
|
|
81
|
+
legend(props?: {}): any
|
|
82
|
+
label: SlotProps<T>
|
|
83
|
+
description: SlotProps<T>
|
|
84
|
+
}
|
|
7
85
|
</script>
|
|
8
86
|
|
|
9
|
-
<script setup>
|
|
10
|
-
import { computed, useId } from
|
|
11
|
-
import { useForwardPropsEmits } from
|
|
12
|
-
import { reactivePick } from
|
|
13
|
-
import { useFormField } from
|
|
14
|
-
import { get } from
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: String,
|
|
31
|
-
required: false,
|
|
32
|
-
default: "label"
|
|
33
|
-
},
|
|
34
|
-
descriptionKey: {
|
|
35
|
-
type: String,
|
|
36
|
-
required: false,
|
|
37
|
-
default: "description"
|
|
38
|
-
},
|
|
39
|
-
items: {
|
|
40
|
-
type: Array,
|
|
41
|
-
required: false
|
|
42
|
-
},
|
|
43
|
-
size: {
|
|
44
|
-
type: null,
|
|
45
|
-
required: false
|
|
46
|
-
},
|
|
47
|
-
variant: {
|
|
48
|
-
type: null,
|
|
49
|
-
required: false
|
|
50
|
-
},
|
|
51
|
-
color: {
|
|
52
|
-
type: null,
|
|
53
|
-
required: false
|
|
54
|
-
},
|
|
55
|
-
orientation: {
|
|
56
|
-
type: null,
|
|
57
|
-
required: false,
|
|
58
|
-
default: "vertical"
|
|
59
|
-
},
|
|
60
|
-
indicator: {
|
|
61
|
-
type: null,
|
|
62
|
-
required: false
|
|
63
|
-
},
|
|
64
|
-
class: {
|
|
65
|
-
type: null,
|
|
66
|
-
required: false
|
|
67
|
-
},
|
|
68
|
-
b24ui: {
|
|
69
|
-
type: Object,
|
|
70
|
-
required: false
|
|
71
|
-
},
|
|
72
|
-
defaultValue: {
|
|
73
|
-
type: [String, Number, Object, null],
|
|
74
|
-
required: false
|
|
75
|
-
},
|
|
76
|
-
disabled: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
required: false
|
|
79
|
-
},
|
|
80
|
-
loop: {
|
|
81
|
-
type: Boolean,
|
|
82
|
-
required: false
|
|
83
|
-
},
|
|
84
|
-
modelValue: {
|
|
85
|
-
type: [String, Number, Object, null],
|
|
86
|
-
required: false
|
|
87
|
-
},
|
|
88
|
-
name: {
|
|
89
|
-
type: String,
|
|
90
|
-
required: false
|
|
91
|
-
},
|
|
92
|
-
required: {
|
|
93
|
-
type: Boolean,
|
|
94
|
-
required: false
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
const emits = defineEmits(["update:modelValue", "change"]);
|
|
98
|
-
const slots = defineSlots();
|
|
99
|
-
const rootProps = useForwardPropsEmits(reactivePick(props, "as", "modelValue", "defaultValue", "orientation", "loop", "required"), emits);
|
|
100
|
-
const { emitFormChange, emitFormInput, color, name, size, id: _id, disabled, ariaAttrs } = useFormField(props, { bind: false });
|
|
101
|
-
const id = _id.value ?? useId();
|
|
87
|
+
<script setup lang="ts" generic="T extends RadioGroupItem">
|
|
88
|
+
import { computed, useId } from 'vue'
|
|
89
|
+
import { RadioGroupRoot, RadioGroupItem, RadioGroupIndicator, Label, useForwardPropsEmits } from 'reka-ui'
|
|
90
|
+
import { reactivePick } from '@vueuse/core'
|
|
91
|
+
import { useFormField } from '../composables/useFormField'
|
|
92
|
+
import { get } from '../utils'
|
|
93
|
+
|
|
94
|
+
const props = withDefaults(defineProps<RadioGroupProps<T>>(), {
|
|
95
|
+
valueKey: 'value',
|
|
96
|
+
labelKey: 'label',
|
|
97
|
+
descriptionKey: 'description',
|
|
98
|
+
orientation: 'vertical'
|
|
99
|
+
})
|
|
100
|
+
const emits = defineEmits<RadioGroupEmits>()
|
|
101
|
+
const slots = defineSlots<RadioGroupSlots<T>>()
|
|
102
|
+
|
|
103
|
+
const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'modelValue', 'defaultValue', 'orientation', 'loop', 'required'), emits)
|
|
104
|
+
|
|
105
|
+
const { emitFormChange, emitFormInput, color, name, size, id: _id, disabled, ariaAttrs } = useFormField<RadioGroupProps<T>>(props, { bind: false })
|
|
106
|
+
const id = _id.value ?? useId()
|
|
107
|
+
|
|
102
108
|
const b24ui = computed(() => radioGroup({
|
|
103
109
|
size: size.value,
|
|
104
110
|
color: color.value,
|
|
@@ -107,44 +113,52 @@ const b24ui = computed(() => radioGroup({
|
|
|
107
113
|
orientation: props.orientation,
|
|
108
114
|
variant: props.variant,
|
|
109
115
|
indicator: props.indicator
|
|
110
|
-
}))
|
|
111
|
-
|
|
116
|
+
}))
|
|
117
|
+
|
|
118
|
+
function normalizeItem(item: any) {
|
|
112
119
|
if (item === null) {
|
|
113
120
|
return {
|
|
114
121
|
id: `${id}:null`,
|
|
115
|
-
value:
|
|
116
|
-
label:
|
|
117
|
-
}
|
|
122
|
+
value: undefined,
|
|
123
|
+
label: undefined
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
|
-
|
|
126
|
+
|
|
127
|
+
if (typeof item === 'string' || typeof item === 'number') {
|
|
120
128
|
return {
|
|
121
129
|
id: `${id}:${item}`,
|
|
122
130
|
value: String(item),
|
|
123
131
|
label: String(item)
|
|
124
|
-
}
|
|
132
|
+
}
|
|
125
133
|
}
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const
|
|
134
|
+
|
|
135
|
+
const value = get(item, props.valueKey as string)
|
|
136
|
+
const label = get(item, props.labelKey as string)
|
|
137
|
+
const description = get(item, props.descriptionKey as string)
|
|
138
|
+
|
|
129
139
|
return {
|
|
130
140
|
...item,
|
|
131
141
|
value,
|
|
132
142
|
label,
|
|
133
143
|
description,
|
|
134
144
|
id: `${id}:${value}`
|
|
135
|
-
}
|
|
145
|
+
}
|
|
136
146
|
}
|
|
147
|
+
|
|
137
148
|
const normalizedItems = computed(() => {
|
|
138
149
|
if (!props.items) {
|
|
139
|
-
return []
|
|
150
|
+
return []
|
|
140
151
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
|
|
153
|
+
return props.items.map(normalizeItem)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
function onUpdate(value: any) {
|
|
157
|
+
// @ts-expect-error - 'target' does not exist in type 'EventInit'
|
|
158
|
+
const event = new Event('change', { target: { value } })
|
|
159
|
+
emits('change', event)
|
|
160
|
+
emitFormChange()
|
|
161
|
+
emitFormInput()
|
|
148
162
|
}
|
|
149
163
|
</script>
|
|
150
164
|
|
|
@@ -178,12 +192,12 @@ function onUpdate(value) {
|
|
|
178
192
|
|
|
179
193
|
<div :class="b24ui.wrapper({ class: props.b24ui?.wrapper })">
|
|
180
194
|
<component :is="variant === 'list' ? Label : 'p'" :class="b24ui.label({ class: props.b24ui?.label })" :for="item.id">
|
|
181
|
-
<slot name="label" :item="item" :model-value="modelValue">
|
|
195
|
+
<slot name="label" :item="item" :model-value="(modelValue as RadioGroupValue)">
|
|
182
196
|
{{ item.label }}
|
|
183
197
|
</slot>
|
|
184
198
|
</component>
|
|
185
199
|
<p v-if="item.description || !!slots.description" :class="b24ui.description({ class: props.b24ui?.description })">
|
|
186
|
-
<slot name="description" :item="item" :model-value="modelValue">
|
|
200
|
+
<slot name="description" :item="item" :model-value="(modelValue as RadioGroupValue)">
|
|
187
201
|
{{ item.description }}
|
|
188
202
|
</slot>
|
|
189
203
|
</p>
|