vueless 0.0.535 → 0.0.537
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/package.json +1 -1
- package/types.ts +7 -0
- package/ui.button/UButton.vue +1 -1
- package/ui.button/types.ts +1 -1
- package/ui.button-link/ULink.vue +1 -1
- package/ui.button-link/types.ts +1 -1
- package/ui.button-toggle/UToggle.vue +1 -1
- package/ui.button-toggle/types.ts +1 -1
- package/ui.button-toggle-item/UToggleItem.vue +1 -1
- package/ui.button-toggle-item/types.ts +1 -1
- package/ui.container-accordion/UAccordion.vue +1 -1
- package/ui.container-accordion/types.ts +1 -1
- package/ui.container-card/UCard.vue +1 -1
- package/ui.container-card/types.ts +1 -1
- package/ui.container-col/UCol.vue +1 -1
- package/ui.container-col/types.ts +1 -1
- package/ui.container-divider/UDivider.vue +1 -1
- package/ui.container-divider/types.ts +1 -1
- package/ui.container-group/UGroup.vue +1 -1
- package/ui.container-group/types.ts +1 -1
- package/ui.container-modal/UModal.vue +1 -1
- package/ui.container-modal/types.ts +1 -1
- package/ui.container-modal-confirm/UModalConfirm.vue +1 -1
- package/ui.container-modal-confirm/types.ts +1 -1
- package/ui.container-page/UPage.vue +1 -1
- package/ui.container-page/types.ts +1 -1
- package/ui.container-row/URow.vue +1 -1
- package/ui.container-row/types.ts +1 -1
- package/ui.data-table/UTable.vue +6 -6
- package/ui.data-table/config.ts +5 -4
- package/ui.data-table/useAttrs.ts +3 -2
- package/ui.form-checkbox/UCheckbox.vue +82 -187
- package/ui.form-checkbox/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox/storybook/{stories.js → stories.ts} +14 -6
- package/ui.form-checkbox/types.ts +106 -0
- package/ui.form-checkbox/useAttrs.ts +35 -0
- package/ui.form-checkbox-group/UCheckboxGroup.vue +63 -137
- package/ui.form-checkbox-group/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox-group/storybook/{stories.js → stories.ts} +19 -6
- package/ui.form-checkbox-group/types.ts +83 -0
- package/ui.form-checkbox-group/useAttrs.ts +18 -0
- package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +34 -97
- package/ui.form-checkbox-multi-state/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox-multi-state/storybook/{stories.js → stories.ts} +16 -5
- package/ui.form-checkbox-multi-state/types.ts +71 -0
- package/ui.form-checkbox-multi-state/useAttrs.ts +41 -0
- package/ui.form-select/config.js +3 -3
- package/ui.image-avatar/UAvatar.vue +1 -1
- package/ui.image-avatar/types.ts +1 -1
- package/ui.image-icon/UIcon.vue +1 -1
- package/ui.image-icon/types.ts +1 -1
- package/ui.loader/ULoader.vue +1 -1
- package/ui.loader/types.ts +1 -1
- package/ui.loader-overlay/ULoaderOverlay.vue +1 -1
- package/ui.loader-overlay/types.ts +1 -1
- package/ui.loader-progress/ULoaderProgress.vue +1 -1
- package/ui.loader-progress/types.ts +1 -1
- package/ui.navigation-pagination/UPagination.vue +1 -1
- package/ui.navigation-pagination/types.ts +1 -1
- package/ui.navigation-progress/StepperProgress.vue +1 -1
- package/ui.navigation-progress/UProgress.vue +1 -1
- package/ui.navigation-progress/types.ts +2 -2
- package/ui.navigation-tab/UTab.vue +1 -1
- package/ui.navigation-tab/types.ts +1 -1
- package/ui.navigation-tabs/UTabs.vue +1 -1
- package/ui.navigation-tabs/types.ts +1 -1
- package/ui.other-dot/UDot.vue +1 -1
- package/ui.other-dot/types.ts +1 -1
- package/ui.text-alert/UAlert.vue +1 -1
- package/ui.text-alert/types.ts +1 -1
- package/ui.text-badge/UBadge.vue +1 -1
- package/ui.text-badge/types.ts +1 -1
- package/ui.text-block/UText.vue +1 -1
- package/ui.text-block/types.ts +1 -1
- package/ui.text-empty/UEmpty.vue +1 -1
- package/ui.text-empty/types.ts +1 -1
- package/ui.text-file/UFile.vue +1 -1
- package/ui.text-file/types.ts +1 -1
- package/ui.text-files/UFiles.vue +1 -1
- package/ui.text-files/types.ts +1 -1
- package/ui.text-header/UHeader.vue +1 -1
- package/ui.text-header/types.ts +1 -1
- package/ui.text-money/UMoney.vue +1 -1
- package/ui.text-money/types.ts +1 -1
- package/ui.text-notify/UNotify.vue +1 -1
- package/ui.text-notify/types.ts +1 -1
- package/web-types.json +147 -184
- package/ui.form-checkbox/useAttrs.js +0 -23
- package/ui.form-checkbox-group/useAttrs.js +0 -15
- package/ui.form-checkbox-multi-state/useAttrs.js +0 -28
- /package/ui.form-checkbox/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox/{constants.js → constants.ts} +0 -0
- /package/ui.form-checkbox-group/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox-group/{constants.js → constants.ts} +0 -0
- /package/ui.form-checkbox-multi-state/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox-multi-state/{constants.js → constants.ts} +0 -0
|
@@ -1,47 +1,4 @@
|
|
|
1
|
-
<
|
|
2
|
-
<ULabel
|
|
3
|
-
:for="elementId"
|
|
4
|
-
:label="label"
|
|
5
|
-
:error="error"
|
|
6
|
-
:size="checkboxSize"
|
|
7
|
-
:align="labelAlign"
|
|
8
|
-
:disabled="disabled"
|
|
9
|
-
:description="description"
|
|
10
|
-
v-bind="checkboxLabelAttrs"
|
|
11
|
-
:data-test="`${dataTest}-label`"
|
|
12
|
-
>
|
|
13
|
-
<input
|
|
14
|
-
:id="elementId"
|
|
15
|
-
type="checkbox"
|
|
16
|
-
:value="checkboxValue"
|
|
17
|
-
:true-value="trueValue"
|
|
18
|
-
:false-value="falseValue"
|
|
19
|
-
:name="checkboxName"
|
|
20
|
-
:checked="isChecked"
|
|
21
|
-
:disabled="disabled"
|
|
22
|
-
v-bind="checkboxAttrs"
|
|
23
|
-
:data-test="dataTest"
|
|
24
|
-
@change="onChange"
|
|
25
|
-
/>
|
|
26
|
-
|
|
27
|
-
<label v-if="isChecked" v-bind="iconWrapperAttrs" :for="elementId">
|
|
28
|
-
<UIcon
|
|
29
|
-
internal
|
|
30
|
-
:name="partial ? config.defaults.partiallyCheckedIcon : config.defaults.checkedIcon"
|
|
31
|
-
:size="iconSize"
|
|
32
|
-
color="white"
|
|
33
|
-
v-bind="checkedIconAttrs"
|
|
34
|
-
/>
|
|
35
|
-
</label>
|
|
36
|
-
|
|
37
|
-
<template #bottom>
|
|
38
|
-
<!-- @slot Use it to add something below the checkbox. -->
|
|
39
|
-
<slot name="bottom" />
|
|
40
|
-
</template>
|
|
41
|
-
</ULabel>
|
|
42
|
-
</template>
|
|
43
|
-
|
|
44
|
-
<script setup>
|
|
1
|
+
<script setup lang="ts">
|
|
45
2
|
import { inject, ref, onMounted, computed, watchEffect, toValue, useId } from "vue";
|
|
46
3
|
import { isEqual } from "lodash-es";
|
|
47
4
|
|
|
@@ -50,149 +7,35 @@ import ULabel from "../ui.form-label/ULabel.vue";
|
|
|
50
7
|
|
|
51
8
|
import { getDefault } from "../utils/ui.ts";
|
|
52
9
|
|
|
53
|
-
import defaultConfig from "./config.
|
|
54
|
-
import { UCheckbox } from "./constants.
|
|
55
|
-
import useAttrs from "./useAttrs.
|
|
10
|
+
import defaultConfig from "./config.ts";
|
|
11
|
+
import { UCheckbox } from "./constants.ts";
|
|
12
|
+
import useAttrs from "./useAttrs.ts";
|
|
13
|
+
|
|
14
|
+
import type { UnknownObject } from "../types.ts";
|
|
15
|
+
import type { UCheckboxProps } from "./types.ts";
|
|
56
16
|
|
|
57
17
|
defineOptions({ inheritAttrs: false });
|
|
58
18
|
|
|
59
19
|
const getCheckboxGroupName = inject("getCheckboxGroupName", null);
|
|
60
20
|
const getCheckboxGroupCheckedItems = inject("getCheckboxGroupCheckedItems", null);
|
|
61
|
-
const setCheckboxGroupCheckedItems = inject(
|
|
21
|
+
const setCheckboxGroupCheckedItems = inject<((value: UnknownObject[]) => void) | null>(
|
|
22
|
+
"setCheckboxGroupCheckedItems",
|
|
23
|
+
null,
|
|
24
|
+
);
|
|
62
25
|
const getCheckboxGroupColor = inject("getCheckboxGroupColor", null);
|
|
63
26
|
const getCheckboxSize = inject("getCheckboxSize", null);
|
|
64
27
|
|
|
65
|
-
const props = defineProps({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
value: {
|
|
78
|
-
type: [Boolean, String, Number, Array, Object],
|
|
79
|
-
default: "",
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Own value for checkbox checked state.
|
|
84
|
-
*/
|
|
85
|
-
trueValue: {
|
|
86
|
-
type: [Boolean, String, Number, Array, Object],
|
|
87
|
-
default: true,
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Own value for checkbox unchecked state.
|
|
92
|
-
*/
|
|
93
|
-
falseValue: {
|
|
94
|
-
type: [Boolean, String, Number, Array, Object],
|
|
95
|
-
default: false,
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Checkbox name.
|
|
100
|
-
*/
|
|
101
|
-
name: {
|
|
102
|
-
type: String,
|
|
103
|
-
default: "",
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Checkbox label.
|
|
108
|
-
*/
|
|
109
|
-
label: {
|
|
110
|
-
type: String,
|
|
111
|
-
default: "",
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Checkbox label description.
|
|
116
|
-
*/
|
|
117
|
-
description: {
|
|
118
|
-
type: String,
|
|
119
|
-
default: "",
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Error message.
|
|
124
|
-
*/
|
|
125
|
-
error: {
|
|
126
|
-
type: String,
|
|
127
|
-
default: "",
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Label placement.
|
|
132
|
-
* @values left, right
|
|
133
|
-
*/
|
|
134
|
-
labelAlign: {
|
|
135
|
-
type: String,
|
|
136
|
-
default: getDefault(defaultConfig, UCheckbox).labelAlign,
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Checkbox color.
|
|
141
|
-
* @values brand, grayscale, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose
|
|
142
|
-
*/
|
|
143
|
-
color: {
|
|
144
|
-
type: String,
|
|
145
|
-
default: getDefault(defaultConfig, UCheckbox).color,
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Checkbox size.
|
|
150
|
-
* @values sm, md, lg
|
|
151
|
-
*/
|
|
152
|
-
size: {
|
|
153
|
-
type: String,
|
|
154
|
-
default: getDefault(defaultConfig, UCheckbox).size,
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Make checkbox disabled.
|
|
159
|
-
*/
|
|
160
|
-
disabled: {
|
|
161
|
-
type: Boolean,
|
|
162
|
-
default: getDefault(defaultConfig, UCheckbox).disabled,
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Make checkbox partially checked (change the checked tick to a minus).
|
|
167
|
-
*/
|
|
168
|
-
partial: {
|
|
169
|
-
type: Boolean,
|
|
170
|
-
default: getDefault(defaultConfig, UCheckbox).partial,
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Unique element id.
|
|
175
|
-
*/
|
|
176
|
-
id: {
|
|
177
|
-
type: String,
|
|
178
|
-
default: "",
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Component config object.
|
|
183
|
-
*/
|
|
184
|
-
config: {
|
|
185
|
-
type: Object,
|
|
186
|
-
default: () => ({}),
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Data-test attribute for automated testing.
|
|
191
|
-
*/
|
|
192
|
-
dataTest: {
|
|
193
|
-
type: String,
|
|
194
|
-
default: "",
|
|
195
|
-
},
|
|
28
|
+
const props = withDefaults(defineProps<UCheckboxProps>(), {
|
|
29
|
+
labelAlign: getDefault<UCheckboxProps>(defaultConfig, UCheckbox).labelAlign,
|
|
30
|
+
color: getDefault<UCheckboxProps>(defaultConfig, UCheckbox).color,
|
|
31
|
+
size: getDefault<UCheckboxProps>(defaultConfig, UCheckbox).size,
|
|
32
|
+
disabled: getDefault<UCheckboxProps>(defaultConfig, UCheckbox).disabled,
|
|
33
|
+
partial: getDefault<UCheckboxProps>(defaultConfig, UCheckbox).partial,
|
|
34
|
+
name: "",
|
|
35
|
+
value: "",
|
|
36
|
+
trueValue: true,
|
|
37
|
+
falseValue: false,
|
|
38
|
+
dataTest: "",
|
|
196
39
|
});
|
|
197
40
|
|
|
198
41
|
const emit = defineEmits([
|
|
@@ -237,9 +80,13 @@ const isBinary = computed(() => !Array.isArray(props.modelValue));
|
|
|
237
80
|
const isCheckboxInGroup = computed(() => Boolean(toValue(getCheckboxGroupName)));
|
|
238
81
|
|
|
239
82
|
const isChecked = computed(() => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
83
|
+
if (isBinary.value && !isCheckboxInGroup.value) {
|
|
84
|
+
return isEqual(props.modelValue, props.trueValue);
|
|
85
|
+
} else if (Array.isArray(currentValue.value)) {
|
|
86
|
+
return currentValue.value.findIndex((item) => isEqual(item, checkboxValue.value)) !== -1;
|
|
87
|
+
} else {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
243
90
|
});
|
|
244
91
|
|
|
245
92
|
const checkboxValue = computed(() => {
|
|
@@ -251,7 +98,8 @@ const currentValue = computed(() => {
|
|
|
251
98
|
});
|
|
252
99
|
|
|
253
100
|
onMounted(() => {
|
|
254
|
-
checkboxName.value =
|
|
101
|
+
checkboxName.value =
|
|
102
|
+
isCheckboxInGroup.value && getCheckboxGroupName ? toValue(getCheckboxGroupName) : props.name;
|
|
255
103
|
});
|
|
256
104
|
|
|
257
105
|
watchEffect(() => (checkboxColor.value = toValue(getCheckboxGroupColor) || props.color));
|
|
@@ -265,16 +113,63 @@ function onChange() {
|
|
|
265
113
|
}
|
|
266
114
|
|
|
267
115
|
if (!isBinary.value || isCheckboxInGroup.value) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
116
|
+
if (Array.isArray(currentValue.value)) {
|
|
117
|
+
newModelValue = !isChecked.value
|
|
118
|
+
? [...currentValue.value, checkboxValue.value]
|
|
119
|
+
: currentValue.value.filter((item) => !isEqual(checkboxValue.value, item));
|
|
120
|
+
} else {
|
|
121
|
+
newModelValue = isChecked.value ? [checkboxValue.value] : [];
|
|
122
|
+
}
|
|
271
123
|
}
|
|
272
124
|
|
|
273
125
|
if (isCheckboxInGroup.value && setCheckboxGroupCheckedItems) {
|
|
274
|
-
setCheckboxGroupCheckedItems(newModelValue);
|
|
126
|
+
setCheckboxGroupCheckedItems(newModelValue as UnknownObject[]);
|
|
275
127
|
}
|
|
276
128
|
|
|
277
129
|
emit("update:modelValue", newModelValue);
|
|
278
130
|
emit("input", newModelValue);
|
|
279
131
|
}
|
|
280
132
|
</script>
|
|
133
|
+
|
|
134
|
+
<template>
|
|
135
|
+
<ULabel
|
|
136
|
+
:for="elementId"
|
|
137
|
+
:label="label"
|
|
138
|
+
:error="error"
|
|
139
|
+
:size="checkboxSize"
|
|
140
|
+
:align="labelAlign"
|
|
141
|
+
:disabled="disabled"
|
|
142
|
+
:description="description"
|
|
143
|
+
v-bind="checkboxLabelAttrs"
|
|
144
|
+
:data-test="`${dataTest}-label`"
|
|
145
|
+
>
|
|
146
|
+
<input
|
|
147
|
+
:id="elementId"
|
|
148
|
+
type="checkbox"
|
|
149
|
+
:value="checkboxValue"
|
|
150
|
+
:true-value="trueValue"
|
|
151
|
+
:false-value="falseValue"
|
|
152
|
+
:name="checkboxName"
|
|
153
|
+
:checked="isChecked"
|
|
154
|
+
:disabled="disabled"
|
|
155
|
+
v-bind="checkboxAttrs"
|
|
156
|
+
:data-test="dataTest"
|
|
157
|
+
@change="onChange"
|
|
158
|
+
/>
|
|
159
|
+
|
|
160
|
+
<label v-if="isChecked" v-bind="iconWrapperAttrs" :for="elementId">
|
|
161
|
+
<UIcon
|
|
162
|
+
internal
|
|
163
|
+
:name="partial ? config?.defaults?.partiallyCheckedIcon : config?.defaults?.checkedIcon"
|
|
164
|
+
:size="iconSize"
|
|
165
|
+
color="white"
|
|
166
|
+
v-bind="checkedIconAttrs"
|
|
167
|
+
/>
|
|
168
|
+
</label>
|
|
169
|
+
|
|
170
|
+
<template #bottom>
|
|
171
|
+
<!-- @slot Use it to add something below the checkbox. -->
|
|
172
|
+
<slot name="bottom" />
|
|
173
|
+
</template>
|
|
174
|
+
</ULabel>
|
|
175
|
+
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
|
|
2
2
|
import { getSource } from "../../utils/storybook.ts";
|
|
3
3
|
|
|
4
|
-
import * as stories from "./stories.
|
|
5
|
-
import defaultConfig from "../config.
|
|
4
|
+
import * as stories from "./stories.ts";
|
|
5
|
+
import defaultConfig from "../config.ts?raw"
|
|
6
6
|
|
|
7
7
|
<Meta of={stories} />
|
|
8
8
|
<Title of={stories} />
|
|
@@ -5,6 +5,14 @@ import UCheckboxGroup from "../../ui.form-checkbox-group/UCheckboxGroup.vue";
|
|
|
5
5
|
import UBadge from "../../ui.text-badge/UBadge.vue";
|
|
6
6
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
7
7
|
|
|
8
|
+
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
9
|
+
import type { UCheckboxProps } from "../types.ts";
|
|
10
|
+
|
|
11
|
+
interface UCheckboxArgs extends UCheckboxProps {
|
|
12
|
+
slotTemplate?: string;
|
|
13
|
+
enum: "size";
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* The `UCheckbox` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.form-checkbox)
|
|
10
18
|
*/
|
|
@@ -19,9 +27,9 @@ export default {
|
|
|
19
27
|
...getArgTypes(UCheckbox.__name),
|
|
20
28
|
modelValue: { control: { type: "boolean" } },
|
|
21
29
|
},
|
|
22
|
-
};
|
|
30
|
+
} as Meta;
|
|
23
31
|
|
|
24
|
-
const DefaultTemplate = (args) => ({
|
|
32
|
+
const DefaultTemplate: StoryFn<UCheckboxArgs> = (args: UCheckboxArgs) => ({
|
|
25
33
|
components: { UCheckbox, UBadge },
|
|
26
34
|
setup() {
|
|
27
35
|
const slots = getSlotNames(UCheckbox.__name);
|
|
@@ -30,12 +38,12 @@ const DefaultTemplate = (args) => ({
|
|
|
30
38
|
},
|
|
31
39
|
template: `
|
|
32
40
|
<UCheckbox v-bind="args" v-model="args.modelValue">
|
|
33
|
-
${args.slotTemplate || getSlotsFragment()}
|
|
41
|
+
${args.slotTemplate || getSlotsFragment("")}
|
|
34
42
|
</UCheckbox>
|
|
35
43
|
`,
|
|
36
44
|
});
|
|
37
45
|
|
|
38
|
-
const ValueTypesTemplate = (args) => ({
|
|
46
|
+
const ValueTypesTemplate: StoryFn<UCheckboxArgs> = (args: UCheckboxArgs) => ({
|
|
39
47
|
components: { UCheckbox, UCheckboxGroup, UCol },
|
|
40
48
|
setup() {
|
|
41
49
|
return { args };
|
|
@@ -89,12 +97,12 @@ const ValueTypesTemplate = (args) => ({
|
|
|
89
97
|
`,
|
|
90
98
|
});
|
|
91
99
|
|
|
92
|
-
const EnumVariantTemplate = (args, { argTypes }) => ({
|
|
100
|
+
const EnumVariantTemplate: StoryFn<UCheckboxArgs> = (args: UCheckboxArgs, { argTypes }) => ({
|
|
93
101
|
components: { UCheckbox, UCol },
|
|
94
102
|
setup() {
|
|
95
103
|
return {
|
|
96
104
|
args,
|
|
97
|
-
options: argTypes[args.enum]
|
|
105
|
+
options: argTypes?.[args.enum]?.options,
|
|
98
106
|
};
|
|
99
107
|
},
|
|
100
108
|
template: `
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
import type { UnknownObject, UnknownArray } from "../types.ts";
|
|
4
|
+
|
|
5
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
6
|
+
|
|
7
|
+
export interface UCheckboxProps {
|
|
8
|
+
/**
|
|
9
|
+
* Checkbox value.
|
|
10
|
+
*/
|
|
11
|
+
modelValue?: boolean | string | number | UnknownArray | UnknownObject;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Native value attribute.
|
|
15
|
+
*/
|
|
16
|
+
value?: boolean | string | number | UnknownArray | UnknownObject;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Own value for checkbox checked state.
|
|
20
|
+
*/
|
|
21
|
+
trueValue?: boolean | string | number | UnknownArray | UnknownObject;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Own value for checkbox unchecked state.
|
|
25
|
+
*/
|
|
26
|
+
falseValue?: boolean | string | number | UnknownArray | UnknownObject;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checkbox name.
|
|
30
|
+
*/
|
|
31
|
+
name?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checkbox label.
|
|
35
|
+
*/
|
|
36
|
+
label?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checkbox label description.
|
|
40
|
+
*/
|
|
41
|
+
description?: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Error message.
|
|
45
|
+
*/
|
|
46
|
+
error?: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Label placement.
|
|
50
|
+
*/
|
|
51
|
+
labelAlign?: "left" | "right";
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checkbox color.
|
|
55
|
+
*/
|
|
56
|
+
color?:
|
|
57
|
+
| "brand"
|
|
58
|
+
| "grayscale"
|
|
59
|
+
| "red"
|
|
60
|
+
| "orange"
|
|
61
|
+
| "amber"
|
|
62
|
+
| "yellow"
|
|
63
|
+
| "lime"
|
|
64
|
+
| "green"
|
|
65
|
+
| "emerald"
|
|
66
|
+
| "teal"
|
|
67
|
+
| "cyan"
|
|
68
|
+
| "sky"
|
|
69
|
+
| "blue"
|
|
70
|
+
| "indigo"
|
|
71
|
+
| "violet"
|
|
72
|
+
| "purple"
|
|
73
|
+
| "fuchsia"
|
|
74
|
+
| "pink"
|
|
75
|
+
| "rose";
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Checkbox size.
|
|
79
|
+
*/
|
|
80
|
+
size?: "sm" | "md" | "lg";
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Make checkbox disabled.
|
|
84
|
+
*/
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Make checkbox partially checked (change the checked tick to a minus).
|
|
89
|
+
*/
|
|
90
|
+
partial?: boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Unique element id.
|
|
94
|
+
*/
|
|
95
|
+
id?: string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Component config object.
|
|
99
|
+
*/
|
|
100
|
+
config?: Config;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Data-test attribute for automated testing.
|
|
104
|
+
*/
|
|
105
|
+
dataTest?: string;
|
|
106
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import useUI from "../composables/useUI.ts";
|
|
3
|
+
|
|
4
|
+
import defaultConfig from "./config.ts";
|
|
5
|
+
|
|
6
|
+
import type { Ref } from "vue";
|
|
7
|
+
import type { UseAttrs } from "../types.ts";
|
|
8
|
+
import type { UCheckboxProps, Config } from "./types.ts";
|
|
9
|
+
|
|
10
|
+
type ComponentState = {
|
|
11
|
+
checkboxColor: Ref<string>;
|
|
12
|
+
checkboxSize: Ref<string>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function useAttrs(
|
|
16
|
+
props: UCheckboxProps,
|
|
17
|
+
{ checkboxColor, checkboxSize }: ComponentState,
|
|
18
|
+
): UseAttrs<Config> {
|
|
19
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
|
|
20
|
+
|
|
21
|
+
const mutatedProps = computed(() => ({
|
|
22
|
+
color: checkboxColor.value,
|
|
23
|
+
size: checkboxSize.value,
|
|
24
|
+
label: Boolean(props.label),
|
|
25
|
+
error: Boolean(props.error),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const keysAttrs = getKeysAttrs(mutatedProps);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
config,
|
|
32
|
+
...keysAttrs,
|
|
33
|
+
hasSlotContent,
|
|
34
|
+
};
|
|
35
|
+
}
|