@indielayer/ui 1.0.0-alpha.8 → 1.0.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.
- package/README.md +6 -3
- package/lib/common/icons.d.ts +15 -0
- package/lib/common/utils.d.ts +32 -0
- package/lib/components/alert/Alert.theme.d.ts +8 -0
- package/lib/components/alert/Alert.vue.d.ts +1 -12
- package/lib/components/alert/__tests__/Alert.spec.d.ts +1 -0
- package/lib/components/avatar/Avatar.theme.d.ts +8 -0
- package/lib/components/avatar/Avatar.vue.d.ts +5 -8
- package/lib/components/avatar/__tests__/Avatar.spec.d.ts +1 -0
- package/lib/components/badge/Badge.theme.d.ts +8 -0
- package/lib/components/badge/Badge.vue.d.ts +5 -6
- package/lib/components/badge/__tests__/Badge.spec.d.ts +1 -0
- package/lib/components/breadcrumbs/Breadcrumbs.theme.d.ts +8 -0
- package/lib/components/breadcrumbs/Breadcrumbs.vue.d.ts +19 -8
- package/lib/components/breadcrumbs/__tests__/Breadcrumbs.spec.d.ts +1 -0
- package/lib/components/button/Button.theme.d.ts +10 -0
- package/lib/components/button/Button.vue.d.ts +10 -16
- package/lib/components/button/ButtonGroup.theme.d.ts +6 -0
- package/lib/components/button/ButtonGroup.vue.d.ts +5 -2
- package/lib/components/button/__tests__/ Button.spec.d.ts +1 -0
- package/lib/components/button/__tests__/ ButtonGroup.spec.d.ts +1 -0
- package/lib/components/card/Card.theme.d.ts +7 -0
- package/lib/components/card/Card.vue.d.ts +2 -2
- package/lib/components/card/__tests__/Card.spec.d.ts +1 -0
- package/lib/components/checkbox/Checkbox.theme.d.ts +11 -0
- package/lib/components/checkbox/Checkbox.vue.d.ts +10 -14
- package/lib/components/checkbox/__tests__/Checkbox.spec.d.ts +1 -0
- package/lib/components/collapse/Collapse.theme.d.ts +9 -0
- package/lib/components/collapse/Collapse.vue.d.ts +12 -19
- package/lib/components/collapse/__tests__/Collapse.spec.d.ts +1 -0
- package/lib/components/container/Container.theme.d.ts +6 -0
- package/lib/components/container/Container.vue.d.ts +1 -1
- package/lib/components/container/__tests__/Container.spec.d.ts +1 -0
- package/lib/components/divider/Divider.theme.d.ts +9 -0
- package/lib/components/divider/Divider.vue.d.ts +1 -1
- package/lib/components/divider/__tests__/Divider.spec.d.ts +1 -0
- package/lib/components/drawer/Drawer.theme.d.ts +7 -0
- package/lib/components/drawer/Drawer.vue.d.ts +3 -15
- package/lib/components/drawer/__tests__/Drawer.spec.d.ts +1 -0
- package/lib/components/form/Form.theme.d.ts +6 -0
- package/lib/components/form/Form.vue.d.ts +9 -7
- package/lib/components/form/__tests__/Form.spec.d.ts +1 -0
- package/lib/components/helpers/InputError.d.ts +8 -0
- package/lib/components/icon/Icon.theme.d.ts +7 -0
- package/lib/components/icon/Icon.vue.d.ts +4 -8
- package/lib/components/icon/__tests__/Icon.spec.d.ts +1 -0
- package/lib/components/image/Image.theme.d.ts +6 -0
- package/lib/components/image/Image.vue.d.ts +1 -3
- package/lib/components/image/__tests__/Image.spec.d.ts +1 -0
- package/lib/components/index.d.ts +3 -3
- package/lib/components/input/Input.theme.d.ts +11 -0
- package/lib/components/input/Input.vue.d.ts +27 -25
- package/lib/components/input/__tests__/Input.spec.d.ts +1 -0
- package/lib/components/link/Link.theme.d.ts +8 -0
- package/lib/components/link/Link.vue.d.ts +3 -5
- package/lib/components/link/__tests__/Link.spec.d.ts +1 -0
- package/lib/components/menu/Menu.theme.d.ts +6 -0
- package/lib/components/menu/Menu.vue.d.ts +6 -3
- package/lib/components/menu/MenuItem.theme.d.ts +8 -0
- package/lib/components/menu/MenuItem.vue.d.ts +5 -30
- package/lib/components/menu/__tests__/Menu.spec.d.ts +1 -0
- package/lib/components/menu/__tests__/MenuItem.spec.d.ts +1 -0
- package/lib/components/modal/Modal.theme.d.ts +13 -0
- package/lib/components/modal/Modal.vue.d.ts +1 -6
- package/lib/components/modal/__tests__/Modal.spec.d.ts +1 -0
- package/lib/components/notifications/Notifications.theme.d.ts +8 -0
- package/lib/components/notifications/Notifications.vue.d.ts +11 -24
- package/lib/components/notifications/__tests__/Notifications.spec.d.ts +1 -0
- package/lib/components/pagination/Pagination.theme.d.ts +9 -0
- package/lib/components/pagination/Pagination.vue.d.ts +7 -16
- package/lib/components/pagination/PaginationItem.theme.d.ts +7 -0
- package/lib/components/pagination/PaginationItem.vue.d.ts +4 -3
- package/lib/components/pagination/__tests__/Pagination.spec.d.ts +1 -0
- package/lib/components/pagination/__tests__/PaginationItem.spec.d.ts +1 -0
- package/lib/components/popover/Popover.theme.d.ts +7 -0
- package/lib/components/popover/Popover.vue.d.ts +13 -13
- package/lib/components/popover/PopoverContainer.theme.d.ts +6 -0
- package/lib/components/popover/PopoverContainer.vue.d.ts +1 -1
- package/lib/components/popover/__tests__/Popover.spec.d.ts +1 -0
- package/lib/components/popover/__tests__/PopoverContainer.spec.d.ts +1 -0
- package/lib/components/progress/Progress.theme.d.ts +10 -0
- package/lib/components/progress/Progress.vue.d.ts +1 -3
- package/lib/components/progress/__tests__/Progress.spec.d.ts +1 -0
- package/lib/components/radio/Radio.theme.d.ts +12 -0
- package/lib/components/radio/Radio.vue.d.ts +12 -13
- package/lib/components/radio/__tests__/Radio.spec.d.ts +1 -0
- package/lib/components/scroll/Scroll.theme.d.ts +6 -0
- package/lib/components/scroll/Scroll.vue.d.ts +1 -7
- package/lib/components/scroll/__tests__/Scroll.spec.d.ts +1 -0
- package/lib/components/select/Select.theme.d.ts +13 -0
- package/lib/components/select/Select.vue.d.ts +8 -28
- package/lib/components/select/__tests__/Select.spec.d.ts +1 -0
- package/lib/components/skeleton/Skeleton.theme.d.ts +6 -0
- package/lib/components/skeleton/Skeleton.vue.d.ts +1 -1
- package/lib/components/skeleton/__tests__/Skeleton.spec.d.ts +1 -0
- package/lib/components/slider/Slider.theme.d.ts +10 -0
- package/lib/components/slider/Slider.vue.d.ts +8 -17
- package/lib/components/slider/__tests__/Slider.spec.d.ts +1 -0
- package/lib/components/spacer/Spacer.d.ts +2 -0
- package/lib/components/spacer/__tests__/Spacer.spec.d.ts +1 -0
- package/lib/components/spinner/Spinner.vue.d.ts +15 -6
- package/lib/components/spinner/__tests__/Spinner.spec.d.ts +1 -0
- package/lib/components/tab/Tab.theme.d.ts +9 -0
- package/lib/components/tab/Tab.vue.d.ts +4 -13
- package/lib/components/tab/TabGroup.theme.d.ts +10 -0
- package/lib/components/tab/TabGroup.vue.d.ts +4 -8
- package/lib/components/tab/__tests__/Tab.spec.d.ts +1 -0
- package/lib/components/tab/__tests__/TabGroup.spec.d.ts +1 -0
- package/lib/components/table/Table.theme.d.ts +8 -0
- package/lib/components/table/Table.vue.d.ts +6 -10
- package/lib/components/table/TableBody.d.ts +2 -0
- package/lib/components/table/TableCell.theme.d.ts +7 -0
- package/lib/components/table/TableCell.vue.d.ts +1 -1
- package/lib/components/table/TableHead.d.ts +2 -0
- package/lib/components/table/TableHeader.vue.d.ts +2 -2
- package/lib/components/table/TableRow.vue.d.ts +1 -1
- package/lib/components/table/__tests__/Table.spec.d.ts +1 -0
- package/lib/components/tag/Tag.theme.d.ts +9 -0
- package/lib/components/tag/Tag.vue.d.ts +5 -5
- package/lib/components/tag/__tests__/Tag.spec.d.ts +1 -0
- package/lib/components/textarea/Textarea.theme.d.ts +10 -0
- package/lib/components/textarea/Textarea.vue.d.ts +18 -24
- package/lib/components/textarea/__tests__/Textarea.spec.d.ts +1 -0
- package/lib/components/toggle/Toggle.theme.d.ts +11 -0
- package/lib/components/toggle/Toggle.vue.d.ts +10 -11
- package/lib/components/toggle/__tests__/Toggle.spec.d.ts +1 -0
- package/lib/components/tooltip/Tooltip.theme.d.ts +11 -0
- package/lib/components/tooltip/__tests__/Tooltip.spec.d.ts +1 -0
- package/lib/composables/colors-utils.d.ts +0 -1
- package/lib/composables/colors.d.ts +8 -4
- package/lib/composables/common.d.ts +1 -0
- package/lib/composables/css.d.ts +6 -5
- package/lib/composables/index.d.ts +1 -1
- package/lib/composables/inputtable.d.ts +1 -1
- package/lib/composables/interactive.d.ts +7 -2
- package/lib/composables/keys.d.ts +1 -0
- package/lib/composables/notifications.d.ts +1 -0
- package/lib/composables/theme.d.ts +20 -0
- package/lib/create.d.ts +3 -2
- package/lib/index.cjs.js +1 -15
- package/lib/index.es.js +4451 -3649
- package/lib/nuxt.js +2 -1
- package/lib/version.d.ts +1 -1
- package/package.json +16 -6
- package/src/common/icons.ts +15 -0
- package/src/common/utils.ts +68 -0
- package/src/components/alert/Alert.theme.ts +57 -0
- package/src/components/alert/Alert.vue +51 -127
- package/src/components/alert/__tests__/Alert.spec.ts +14 -0
- package/src/components/avatar/Avatar.theme.ts +39 -0
- package/src/components/avatar/Avatar.vue +58 -96
- package/src/components/avatar/__tests__/Avatar.spec.ts +11 -0
- package/src/components/badge/Badge.theme.ts +13 -0
- package/src/components/badge/Badge.vue +58 -65
- package/src/components/badge/__tests__/Badge.spec.ts +11 -0
- package/src/components/breadcrumbs/Breadcrumbs.theme.ts +9 -0
- package/src/components/breadcrumbs/Breadcrumbs.vue +34 -24
- package/src/components/breadcrumbs/__tests__/Breadcrumbs.spec.ts +11 -0
- package/src/components/button/Button.theme.ts +234 -0
- package/src/components/button/Button.vue +94 -356
- package/src/components/button/ButtonGroup.theme.ts +5 -0
- package/src/components/button/ButtonGroup.vue +30 -29
- package/src/components/button/__tests__/ Button.spec.ts +11 -0
- package/src/components/button/__tests__/ ButtonGroup.spec.ts +11 -0
- package/src/components/card/Card.theme.ts +7 -0
- package/src/components/card/Card.vue +18 -11
- package/src/components/card/__tests__/Card.spec.ts +11 -0
- package/src/components/checkbox/Checkbox.theme.ts +92 -0
- package/src/components/checkbox/Checkbox.vue +69 -156
- package/src/components/checkbox/__tests__/Checkbox.spec.ts +11 -0
- package/src/components/collapse/Collapse.theme.ts +11 -0
- package/src/components/collapse/Collapse.vue +99 -118
- package/src/components/collapse/__tests__/Collapse.spec.ts +11 -0
- package/src/components/container/Container.theme.ts +7 -0
- package/src/components/container/Container.vue +17 -9
- package/src/components/container/__tests__/Container.spec.ts +11 -0
- package/src/components/divider/Divider.theme.ts +11 -0
- package/src/components/divider/Divider.vue +22 -18
- package/src/components/divider/__tests__/Divider.spec.ts +11 -0
- package/src/components/drawer/Drawer.theme.ts +9 -0
- package/src/components/drawer/Drawer.vue +160 -177
- package/src/components/drawer/__tests__/Drawer.spec.ts +11 -0
- package/src/components/form/Form.theme.ts +7 -0
- package/src/components/form/Form.vue +90 -73
- package/src/components/form/__tests__/Form.spec.ts +11 -0
- package/src/components/helpers/InputError.tsx +14 -0
- package/src/components/icon/Icon.theme.ts +16 -0
- package/src/components/icon/Icon.vue +72 -88
- package/src/components/icon/__tests__/Icon.spec.ts +11 -0
- package/src/components/image/Image.theme.ts +7 -0
- package/src/components/image/Image.vue +22 -23
- package/src/components/image/__tests__/Image.spec.ts +11 -0
- package/src/components/index.ts +3 -3
- package/src/components/input/Input.theme.ts +44 -0
- package/src/components/input/Input.vue +97 -130
- package/src/components/input/__tests__/Input.spec.ts +11 -0
- package/src/components/link/Link.theme.ts +26 -0
- package/src/components/link/Link.vue +41 -66
- package/src/components/link/__tests__/Link.spec.ts +11 -0
- package/src/components/menu/Menu.theme.ts +7 -0
- package/src/components/menu/Menu.vue +54 -45
- package/src/components/menu/MenuItem.theme.ts +107 -0
- package/src/components/menu/MenuItem.vue +97 -199
- package/src/components/menu/__tests__/Menu.spec.ts +11 -0
- package/src/components/menu/__tests__/MenuItem.spec.ts +11 -0
- package/src/components/modal/Modal.theme.ts +29 -0
- package/src/components/modal/Modal.vue +78 -101
- package/src/components/modal/__tests__/Modal.spec.ts +11 -0
- package/src/components/notifications/Notifications.theme.ts +11 -0
- package/src/components/notifications/Notifications.vue +233 -247
- package/src/components/notifications/__tests__/Notifications.spec.ts +11 -0
- package/src/components/pagination/Pagination.theme.ts +27 -0
- package/src/components/pagination/Pagination.vue +142 -164
- package/src/components/pagination/PaginationItem.theme.ts +14 -0
- package/src/components/pagination/PaginationItem.vue +26 -33
- package/src/components/pagination/__tests__/Pagination.spec.ts +11 -0
- package/src/components/pagination/__tests__/PaginationItem.spec.ts +11 -0
- package/src/components/popover/Popover.theme.ts +9 -0
- package/src/components/popover/Popover.vue +153 -101
- package/src/components/popover/PopoverContainer.theme.ts +7 -0
- package/src/components/popover/PopoverContainer.vue +17 -9
- package/src/components/popover/__tests__/Popover.spec.ts +11 -0
- package/src/components/popover/__tests__/PopoverContainer.spec.ts +11 -0
- package/src/components/progress/Progress.theme.ts +26 -0
- package/src/components/progress/Progress.vue +29 -53
- package/src/components/progress/__tests__/Progress.spec.ts +11 -0
- package/src/components/radio/Radio.theme.ts +121 -0
- package/src/components/radio/Radio.vue +81 -158
- package/src/components/radio/__tests__/Radio.spec.ts +11 -0
- package/src/components/scroll/Scroll.theme.ts +7 -0
- package/src/components/scroll/Scroll.vue +34 -36
- package/src/components/scroll/__tests__/Scroll.spec.ts +11 -0
- package/src/components/select/Select.theme.ts +54 -0
- package/src/components/select/Select.vue +219 -273
- package/src/components/select/__tests__/Select.spec.ts +11 -0
- package/src/components/skeleton/Skeleton.theme.ts +7 -0
- package/src/components/skeleton/Skeleton.vue +17 -9
- package/src/components/skeleton/__tests__/Skeleton.spec.ts +11 -0
- package/src/components/slider/Slider.theme.ts +30 -0
- package/src/components/slider/Slider.vue +135 -168
- package/src/components/slider/__tests__/Slider.spec.ts +11 -0
- package/src/components/spacer/{Spacer.vue → Spacer.tsx} +3 -6
- package/src/components/spacer/__tests__/Spacer.spec.ts +11 -0
- package/src/components/spinner/Spinner.vue +10 -34
- package/src/components/spinner/__tests__/Spinner.spec.ts +11 -0
- package/src/components/tab/Tab.theme.ts +22 -0
- package/src/components/tab/Tab.vue +89 -93
- package/src/components/tab/TabGroup.theme.ts +43 -0
- package/src/components/tab/TabGroup.vue +94 -127
- package/src/components/tab/__tests__/Tab.spec.ts +11 -0
- package/src/components/tab/__tests__/TabGroup.spec.ts +11 -0
- package/src/components/table/Table.theme.ts +19 -0
- package/src/components/table/Table.vue +136 -147
- package/src/components/table/{TableBody.vue → TableBody.tsx} +3 -8
- package/src/components/table/TableCell.theme.ts +27 -0
- package/src/components/table/TableCell.vue +30 -58
- package/src/components/table/TableHead.tsx +14 -0
- package/src/components/table/TableHeader.vue +18 -20
- package/src/components/table/TableRow.vue +23 -20
- package/src/components/table/__tests__/Table.spec.ts +11 -0
- package/src/components/tag/Tag.theme.ts +32 -0
- package/src/components/tag/Tag.vue +40 -68
- package/src/components/tag/__tests__/Tag.spec.ts +11 -0
- package/src/components/textarea/Textarea.theme.ts +62 -0
- package/src/components/textarea/Textarea.vue +100 -115
- package/src/components/textarea/__tests__/Textarea.spec.ts +11 -0
- package/src/components/toggle/Toggle.theme.ts +51 -0
- package/src/components/toggle/Toggle.vue +51 -81
- package/src/components/toggle/__tests__/Toggle.spec.ts +11 -0
- package/src/components/tooltip/Tooltip.theme.ts +51 -0
- package/src/components/tooltip/Tooltip.vue +9 -14
- package/src/components/tooltip/__tests__/Tooltip.spec.ts +11 -0
- package/src/composables/colors-utils.ts +68 -68
- package/src/composables/colors.ts +18 -6
- package/src/composables/common.ts +1 -0
- package/src/composables/css.ts +7 -2
- package/src/composables/index.ts +1 -1
- package/src/composables/inputtable.ts +1 -1
- package/src/composables/interactive.ts +8 -4
- package/src/composables/keys.ts +1 -0
- package/src/composables/notifications.ts +10 -0
- package/src/composables/theme.ts +88 -0
- package/src/create.ts +8 -3
- package/src/exports/nuxt.js +2 -1
- package/src/version.ts +1 -1
- package/volar.d.ts +1 -0
- package/lib/components/spacer/Spacer.vue.d.ts +0 -2
- package/lib/components/table/TableBody.vue.d.ts +0 -2
- package/lib/components/table/TableHead.vue.d.ts +0 -2
- package/lib/composables/notification.d.ts +0 -1
- package/lib/style.css +0 -1
- package/src/components/table/TableHead.vue +0 -15
- package/src/composables/notification.ts +0 -10
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
export default {
|
|
3
|
+
name: 'XForm',
|
|
4
|
+
inheritAttrs: false,
|
|
5
|
+
}
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { provide, onMounted, watch, nextTick, type PropType } from 'vue'
|
|
3
10
|
import { injectFormKey } from '../../composables/keys'
|
|
11
|
+
import { useTheme } from '../../composables/theme'
|
|
12
|
+
|
|
13
|
+
import theme from './Form.theme'
|
|
14
|
+
|
|
15
|
+
export type FormError = {
|
|
16
|
+
field: string
|
|
17
|
+
msg: string
|
|
18
|
+
}
|
|
4
19
|
|
|
5
20
|
export type Form = {
|
|
6
21
|
name: string,
|
|
@@ -9,101 +24,103 @@ export type Form = {
|
|
|
9
24
|
setError: (val: string)=> void,
|
|
10
25
|
}
|
|
11
26
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
props: {
|
|
18
|
-
autoValidate: {
|
|
19
|
-
type: Boolean,
|
|
20
|
-
default: true,
|
|
21
|
-
},
|
|
22
|
-
autoFocus: {
|
|
23
|
-
type: Boolean,
|
|
24
|
-
default: true,
|
|
25
|
-
},
|
|
26
|
-
disabled: Boolean,
|
|
27
|
-
errors: {
|
|
28
|
-
type: Array,
|
|
29
|
-
default: () => [],
|
|
30
|
-
},
|
|
27
|
+
const props = defineProps({
|
|
28
|
+
autoValidate: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: true,
|
|
31
31
|
},
|
|
32
|
+
autoFocus: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true,
|
|
35
|
+
},
|
|
36
|
+
disabled: Boolean,
|
|
37
|
+
errors: {
|
|
38
|
+
type: [Array, Object] as PropType<[FormError[], FormError]>,
|
|
39
|
+
default: () => ([]),
|
|
40
|
+
},
|
|
41
|
+
})
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
const emit = defineEmits(['submit'])
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
const inputs: Form[] = []
|
|
45
|
+
const inputs: Form[] = []
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
provide(injectFormKey, {
|
|
48
|
+
registerInput: (name: string, focus: ()=> void, validate: ()=> boolean, setError: (val: string)=> void) => {
|
|
49
|
+
const exists = inputs.find((i) => i.name === name)
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
if (exists) {
|
|
52
|
+
exists.focus = focus
|
|
53
|
+
exists.validate = validate
|
|
54
|
+
exists.setError = setError
|
|
55
|
+
}
|
|
56
|
+
else inputs.push({ name, focus, validate, setError })
|
|
57
|
+
},
|
|
58
|
+
unregisterInput: (name: string) => {
|
|
59
|
+
const index = inputs.findIndex((i) => i.name === name)
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
inputs.splice(index, 1)
|
|
62
|
+
},
|
|
63
|
+
isInsideForm: true,
|
|
64
|
+
})
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
onMounted(() => {
|
|
67
|
+
if (props.autoFocus && inputs && inputs.length > 0) inputs[0].focus()
|
|
68
|
+
})
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
watch(() => props.errors, (errors) => {
|
|
71
|
+
if (errors) nextTick(() => {
|
|
72
|
+
if (Array.isArray(errors)) errors.forEach((error: any) => {
|
|
73
|
+
const input = inputs.find((i) => i.name === error.field)
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
})
|
|
75
|
+
if (input) input.setError(error.msg)
|
|
69
76
|
})
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
else {
|
|
79
|
+
const input = inputs.find((i) => i.name === (errors as FormError).field)
|
|
80
|
+
|
|
81
|
+
if (input) input.setError((errors as FormError).msg)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
})
|
|
73
85
|
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
const validate = () => {
|
|
87
|
+
let isFormValid = true
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
inputs.forEach((input) => {
|
|
90
|
+
const isInputValid = input.validate()
|
|
79
91
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
})
|
|
92
|
+
if (!isInputValid && isFormValid) {
|
|
93
|
+
isFormValid = false
|
|
84
94
|
|
|
85
|
-
|
|
95
|
+
// focus on input error
|
|
96
|
+
if (input.focus) input.focus()
|
|
86
97
|
}
|
|
98
|
+
})
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
e.stopPropagation()
|
|
100
|
+
return isFormValid
|
|
101
|
+
}
|
|
91
102
|
|
|
92
|
-
|
|
103
|
+
const submit = (e: Event) => {
|
|
104
|
+
e.preventDefault()
|
|
105
|
+
e.stopPropagation()
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
}
|
|
107
|
+
const isFormValid = props.autoValidate ? validate() : true
|
|
96
108
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
})
|
|
109
|
+
emit('submit', isFormValid)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const { styles, classes, className } = useTheme('form', theme, props)
|
|
103
113
|
</script>
|
|
104
114
|
|
|
105
115
|
<template>
|
|
106
|
-
<form
|
|
116
|
+
<form
|
|
117
|
+
:style="styles"
|
|
118
|
+
:class="[
|
|
119
|
+
className,
|
|
120
|
+
classes.wrapper
|
|
121
|
+
]"
|
|
122
|
+
@submit="submit"
|
|
123
|
+
>
|
|
107
124
|
<fieldset :disabled="disabled">
|
|
108
125
|
<slot></slot>
|
|
109
126
|
</fieldset>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import Form from '../Form.vue'
|
|
4
|
+
|
|
5
|
+
describe('Form', () => {
|
|
6
|
+
it('renders without errors', () => {
|
|
7
|
+
const wrapper = mount(Form)
|
|
8
|
+
|
|
9
|
+
expect(wrapper.vm).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: 'InputError',
|
|
5
|
+
props: {
|
|
6
|
+
error: String,
|
|
7
|
+
helper: String,
|
|
8
|
+
},
|
|
9
|
+
setup(props) {
|
|
10
|
+
return () => props.error
|
|
11
|
+
? <p class="text-sm text-red-500 dark:text-red-400 mt-1">{props.error}</p>
|
|
12
|
+
: props.helper ? <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">{props.helper}</p> : ''
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ThemeParams } from '../../composables/theme'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
classes: {
|
|
5
|
+
wrapper: ({ props }: ThemeParams) => {
|
|
6
|
+
const classes = 'inline'
|
|
7
|
+
|
|
8
|
+
if (props.size === 'xs') return classes + ' h-3 w-3'
|
|
9
|
+
else if (props.size === 'sm') return classes + ' h-4 w-4'
|
|
10
|
+
else if (props.size === 'lg') return classes + ' h-6 w-6'
|
|
11
|
+
else if (props.size === 'xl') return classes + ' h-9 w-9'
|
|
12
|
+
|
|
13
|
+
return classes + ' h-5 w-5'
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}
|
|
@@ -1,118 +1,102 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
export default { name: 'XIcon' }
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { inject, ref, watchEffect, normalizeStyle, unref, computed } from 'vue'
|
|
3
7
|
import { useCommon } from '../../composables/common'
|
|
4
8
|
import { injectIconsKey } from '../../composables/keys'
|
|
9
|
+
import { useTheme } from '../../composables/theme'
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
name: 'XIcon',
|
|
11
|
+
import theme from './Icon.theme'
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
const props = defineProps({
|
|
14
|
+
...useCommon.props(),
|
|
15
|
+
icon: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true,
|
|
11
18
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: String,
|
|
17
|
-
required: true,
|
|
18
|
-
},
|
|
19
|
-
filled: Boolean,
|
|
20
|
-
viewBox: {
|
|
21
|
-
type: String,
|
|
22
|
-
default: '0 0 24 24',
|
|
23
|
-
},
|
|
19
|
+
filled: Boolean,
|
|
20
|
+
viewBox: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: '0 0 24 24',
|
|
24
23
|
},
|
|
24
|
+
})
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
const icons: any = inject(injectIconsKey, () => {}, false)
|
|
28
|
-
const sizeClasses = computed(() => {
|
|
29
|
-
if (props.size === 'xs') return 'h-3 w-3'
|
|
30
|
-
else if (props.size === 'sm') return 'h-4 w-4'
|
|
31
|
-
else if (props.size === 'lg') return 'h-6 w-6'
|
|
32
|
-
else if (props.size === 'xl') return 'h-9 w-9'
|
|
33
|
-
|
|
34
|
-
return 'h-5 w-5'
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const isWrapSVG = ref(false)
|
|
38
|
-
const computedIcon = ref('')
|
|
39
|
-
const computedFilled = ref(props.filled)
|
|
40
|
-
const computedViewBox = ref(props.viewBox)
|
|
41
|
-
const attrs = ref({})
|
|
42
|
-
|
|
43
|
-
watchEffect(() => {
|
|
44
|
-
const injectedIcon = icons && icons[props.icon]
|
|
45
|
-
|
|
46
|
-
isWrapSVG.value = false
|
|
47
|
-
computedIcon.value = injectedIcon
|
|
48
|
-
|
|
49
|
-
if (injectedIcon) {
|
|
50
|
-
if (typeof injectedIcon === 'string') {
|
|
51
|
-
if (injectedIcon.startsWith('<svg')) {
|
|
52
|
-
isWrapSVG.value = true
|
|
53
|
-
|
|
54
|
-
const { content, attributes } = getSVG(injectedIcon)
|
|
55
|
-
|
|
56
|
-
attrs.value = attributes
|
|
57
|
-
computedIcon.value = content
|
|
58
|
-
} else {
|
|
59
|
-
isWrapSVG.value = false
|
|
60
|
-
computedIcon.value = injectedIcon
|
|
61
|
-
}
|
|
62
|
-
} else if (typeof injectedIcon === 'object') {
|
|
63
|
-
computedIcon.value = injectedIcon.icon
|
|
64
|
-
computedFilled.value = injectedIcon.filled || props.filled
|
|
65
|
-
computedViewBox.value = injectedIcon.viewBox || injectedIcon.viewbox || props.viewBox
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
computedIcon.value = props.icon
|
|
69
|
-
}
|
|
70
|
-
})
|
|
26
|
+
const icons: any = inject(injectIconsKey, () => ({}))
|
|
71
27
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
28
|
+
const isWrapSVG = ref(false)
|
|
29
|
+
const computedIcon = ref('')
|
|
30
|
+
const computedFilled = ref(props.filled)
|
|
31
|
+
const computedViewBox = ref(props.viewBox)
|
|
32
|
+
const attrs = ref({})
|
|
76
33
|
|
|
77
|
-
|
|
34
|
+
watchEffect(() => {
|
|
35
|
+
const injectedIcon = icons && icons[props.icon]
|
|
78
36
|
|
|
79
|
-
|
|
80
|
-
|
|
37
|
+
isWrapSVG.value = false
|
|
38
|
+
computedIcon.value = injectedIcon
|
|
81
39
|
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
if (injectedIcon) {
|
|
41
|
+
if (typeof injectedIcon === 'string') {
|
|
42
|
+
if (injectedIcon.startsWith('<svg')) {
|
|
43
|
+
isWrapSVG.value = true
|
|
84
44
|
|
|
85
|
-
|
|
86
|
-
attributes,
|
|
87
|
-
content,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
45
|
+
const { content, attributes } = getSVG(injectedIcon)
|
|
90
46
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
47
|
+
attrs.value = attributes
|
|
48
|
+
computedIcon.value = content
|
|
49
|
+
} else {
|
|
50
|
+
isWrapSVG.value = false
|
|
51
|
+
computedIcon.value = injectedIcon
|
|
52
|
+
}
|
|
53
|
+
} else if (typeof injectedIcon === 'object') {
|
|
54
|
+
computedIcon.value = injectedIcon.icon
|
|
55
|
+
computedFilled.value = injectedIcon.filled || props.filled
|
|
56
|
+
computedViewBox.value = injectedIcon.viewBox || injectedIcon.viewbox || props.viewBox
|
|
98
57
|
}
|
|
99
|
-
}
|
|
58
|
+
} else {
|
|
59
|
+
computedIcon.value = props.icon
|
|
60
|
+
}
|
|
100
61
|
})
|
|
62
|
+
|
|
63
|
+
function getSVG(svgString: string) {
|
|
64
|
+
svgString = svgString.trim()
|
|
65
|
+
const content = svgString.substring(svgString.indexOf('>') + 1, svgString.lastIndexOf('</svg>'))
|
|
66
|
+
const attrsRaw = svgString.substring(svgString.indexOf('<svg') + 4, svgString.indexOf('>')).trim().match(/[\w-]+="[^"]*"/g)
|
|
67
|
+
|
|
68
|
+
const attributes: Record<string, string | null> = {}
|
|
69
|
+
|
|
70
|
+
attrsRaw?.forEach((a) => {
|
|
71
|
+
const [attribute, value] = a.split('=')
|
|
72
|
+
|
|
73
|
+
if (!['height', 'width', 'class'].includes(attribute)) attributes[attribute] = value.replace(/(^"|"$)/g, '')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
attributes,
|
|
78
|
+
content,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { styles, classes, className } = useTheme('icon', theme, props)
|
|
83
|
+
|
|
84
|
+
const normalizedStyle = computed(() => normalizeStyle(unref(styles)))
|
|
101
85
|
</script>
|
|
102
86
|
|
|
103
87
|
<template>
|
|
104
88
|
<svg
|
|
105
89
|
v-if="isWrapSVG"
|
|
106
|
-
|
|
107
|
-
:class="
|
|
90
|
+
:style="normalizedStyle"
|
|
91
|
+
:class="['shrink-0', className, classes.wrapper]"
|
|
108
92
|
v-bind="attrs"
|
|
109
93
|
v-html="computedIcon"
|
|
110
94
|
/>
|
|
111
95
|
<svg
|
|
112
96
|
v-else
|
|
97
|
+
:style="normalizedStyle"
|
|
113
98
|
xmlns="http://www.w3.org/2000/svg"
|
|
114
|
-
class="
|
|
115
|
-
:class="[sizeClasses, { 'stroke-2': !computedFilled}]"
|
|
99
|
+
:class="['shrink-0', className, classes.wrapper, { 'stroke-2': !computedFilled}]"
|
|
116
100
|
:stroke-linejoin="computedFilled ? undefined : 'round'"
|
|
117
101
|
:stroke-linecap="computedFilled ? undefined : 'round'"
|
|
118
102
|
:stroke="computedFilled ? undefined : 'currentColor'"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import Icon from '../Icon.vue'
|
|
4
|
+
|
|
5
|
+
describe('Icon', () => {
|
|
6
|
+
it('renders without errors', () => {
|
|
7
|
+
const wrapper = mount(Icon)
|
|
8
|
+
|
|
9
|
+
expect(wrapper.vm).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
export default { name: 'XImage' }
|
|
3
|
+
</script>
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { watch, ref } from 'vue'
|
|
7
|
+
import { useTheme } from '../../composables/theme'
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
name: 'XImage',
|
|
9
|
+
import theme from './Image.theme'
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
src: String,
|
|
11
|
-
},
|
|
11
|
+
const fallback = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const props = defineProps({
|
|
14
|
+
src: String,
|
|
15
|
+
})
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
if (!src) return
|
|
18
|
-
const img = new Image()
|
|
17
|
+
const source = ref<string | undefined>(fallback)
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, {
|
|
24
|
-
immediate: true,
|
|
25
|
-
})
|
|
19
|
+
watch(() => props.src, (src) => {
|
|
20
|
+
if (!src) return
|
|
21
|
+
const img = new Image()
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
img.onload = () => { source.value = props.src }
|
|
24
|
+
img.onerror = () => { }
|
|
25
|
+
img.src = src
|
|
26
|
+
}, {
|
|
27
|
+
immediate: true,
|
|
31
28
|
})
|
|
29
|
+
|
|
30
|
+
const { styles, classes, className } = useTheme('image', theme, props)
|
|
32
31
|
</script>
|
|
33
32
|
|
|
34
33
|
<template>
|
|
35
|
-
<img :src="source" />
|
|
34
|
+
<img :class="[className, classes.wrapper]" :style="styles" :src="source" />
|
|
36
35
|
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import Image from '../Image.vue'
|
|
4
|
+
|
|
5
|
+
describe('Image', () => {
|
|
6
|
+
it('renders without errors', () => {
|
|
7
|
+
const wrapper = mount(Image)
|
|
8
|
+
|
|
9
|
+
expect(wrapper.vm).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
package/src/components/index.ts
CHANGED
|
@@ -29,12 +29,12 @@ export { default as XScroll } from './scroll/Scroll.vue'
|
|
|
29
29
|
export { default as XSelect } from './select/Select.vue'
|
|
30
30
|
export { default as XSkeleton } from './skeleton/Skeleton.vue'
|
|
31
31
|
export { default as XSlider } from './slider/Slider.vue'
|
|
32
|
-
export { default as XSpacer } from './spacer/Spacer
|
|
32
|
+
export { default as XSpacer } from './spacer/Spacer'
|
|
33
33
|
export { default as XSpinner } from './spinner/Spinner.vue'
|
|
34
34
|
export { default as XTable } from './table/Table.vue'
|
|
35
|
-
export { default as XTableBody } from './table/TableBody
|
|
35
|
+
export { default as XTableBody } from './table/TableBody'
|
|
36
36
|
export { default as XTableCell } from './table/TableCell.vue'
|
|
37
|
-
export { default as XTableHead } from './table/TableHead
|
|
37
|
+
export { default as XTableHead } from './table/TableHead'
|
|
38
38
|
export { default as XTableHeader } from './table/TableHeader.vue'
|
|
39
39
|
export { default as XTableRow } from './table/TableRow.vue'
|
|
40
40
|
export { default as XTab } from './tab/Tab.vue'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ThemeParams } from '../../composables/theme'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
classes: {
|
|
5
|
+
wrapper: 'inline-block align-bottom text-left',
|
|
6
|
+
|
|
7
|
+
label: ({ props }: ThemeParams) => {
|
|
8
|
+
const classes = 'font-medium text-gray-800 dark:text-gray-200 mb-1'
|
|
9
|
+
|
|
10
|
+
if (props.size === 'xs') return classes + ' text-xs'
|
|
11
|
+
else if (props.size === 'sm') return classes + ' text-sm'
|
|
12
|
+
else if (props.size === 'lg') return classes + ' text-lg'
|
|
13
|
+
else if (props.size === 'xl') return classes + ' text-xl'
|
|
14
|
+
|
|
15
|
+
return classes // + ' text-sm'
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
input: ({ props, data }: ThemeParams) => {
|
|
19
|
+
const classes = ['appearance-none block w-full placeholder-gray-400 dark:placeholder-gray-500 outline-transparent outline outline-2 outline-offset-[-1px] transition-all duration-150 ease-in-out border-gray-300 dark:border-gray-700 border shadow-sm rounded-md']
|
|
20
|
+
|
|
21
|
+
if (!data.errorInternal && !props.disabled) classes.push('hover:border-gray-400 dark:hover:border-gray-500')
|
|
22
|
+
|
|
23
|
+
if (props.size === 'xs') classes.push('px-2 py-1 text-xs')
|
|
24
|
+
else if (props.size === 'sm') classes.push('px-2 py-2 text-sm')
|
|
25
|
+
else if (props.size === 'lg') classes.push('px-4 py-3 text-lg')
|
|
26
|
+
else if (props.size === 'xl') classes.push('px-5 py-4 text-xl')
|
|
27
|
+
else classes.push('px-3 py-2')
|
|
28
|
+
|
|
29
|
+
classes.push(props.disabled
|
|
30
|
+
? 'bg-gray-100 dark:bg-gray-900 text-gray-500 cursor-not-allowed'
|
|
31
|
+
: 'bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200')
|
|
32
|
+
|
|
33
|
+
return classes
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
icon: 'text-gray-600 dark:text-gray-300 absolute my-auto inset-y-0',
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
styles: ({ colors, props, css }: ThemeParams) => {
|
|
40
|
+
const color = colors.getPalette(props.color)
|
|
41
|
+
|
|
42
|
+
return css.get('border', color[400])
|
|
43
|
+
},
|
|
44
|
+
}
|