1 | import { defineComponent } from 'vue';
|
2 | import { uid } from '../../helpers/index.mjs';
|
3 | import { colorVariantClass, sizePropValidator, FormComponentMixin, defaultPropValue } from '../../mixins/index.mjs';
|
4 | /**
|
5 | * Slot for default checkbox label
|
6 | * @name default
|
7 | * @kind slot
|
8 | */
|
9 | const componentName = 'ICheckbox';
|
10 | export default defineComponent({
|
11 | name: componentName,
|
12 | mixins: [
|
13 | FormComponentMixin
|
14 | ],
|
15 | props: {
|
16 | /**
|
17 | * The color variant of the checkbox
|
18 | * @type light | dark
|
19 | * @default light
|
20 | * @name color
|
21 | */
|
22 | color: {
|
23 | type: String,
|
24 | default: defaultPropValue(componentName, 'color')
|
25 | },
|
26 | /**
|
27 | * The disabled state of the checkbox
|
28 | * @type Boolean
|
29 | * @default false
|
30 | * @name disabled
|
31 | */
|
32 | disabled: {
|
33 | type: Boolean,
|
34 | default: false
|
35 | },
|
36 | /**
|
37 | * The indeterminate state of the checkbox
|
38 | * @type Boolean
|
39 | * @default false
|
40 | * @name indeterminate
|
41 | */
|
42 | indeterminate: {
|
43 | type: Boolean,
|
44 | default: false
|
45 | },
|
46 | /**
|
47 | * Used to set the checkbox value when used inside a checkbox group
|
48 | * @default false
|
49 | * @name value
|
50 | */
|
51 | value: {
|
52 | default: false
|
53 | },
|
54 | /**
|
55 | * Used to set the checkbox value when used by itself
|
56 | * @default false
|
57 | * @name modelValue
|
58 | */
|
59 | modelValue: {
|
60 | default: false
|
61 | },
|
62 | /**
|
63 | * The unique identifier of the checkbox
|
64 | * @type String
|
65 | * @default uid()
|
66 | * @name name
|
67 | */
|
68 | name: {
|
69 | type: [String, Number],
|
70 | default() {
|
71 | return uid('checkbox');
|
72 | }
|
73 | },
|
74 | /**
|
75 | * Displays the native browser checkbox input indicator
|
76 | * @type Boolean
|
77 | * @default false
|
78 | * @name native
|
79 | */
|
80 | native: {
|
81 | type: Boolean,
|
82 | default: false
|
83 | },
|
84 | /**
|
85 | * The readonly state of the checkbox
|
86 | * @type Boolean
|
87 | * @default false
|
88 | * @name readonly
|
89 | */
|
90 | readonly: {
|
91 | type: Boolean,
|
92 | default: false
|
93 | },
|
94 | /**
|
95 | * The size variant of the checkbox
|
96 | * @type sm | md | lg
|
97 | * @default md
|
98 | * @name size
|
99 | */
|
100 | size: {
|
101 | type: String,
|
102 | default: defaultPropValue(componentName, 'size'),
|
103 | validator: sizePropValidator
|
104 | },
|
105 | /**
|
106 | * The tabindex of the checkbox
|
107 | * @type Number | String
|
108 | * @default 0
|
109 | * @name tabindex
|
110 | */
|
111 | tabindex: {
|
112 | type: [Number, String],
|
113 | default: 0
|
114 | }
|
115 | },
|
116 | emits: [
|
117 | /**
|
118 | * Event emitted for setting the modelValue
|
119 | * @event update:modelValue
|
120 | */
|
121 | 'update:modelValue'
|
122 | ],
|
123 | computed: {
|
124 | classes() {
|
125 | return {
|
126 | ...colorVariantClass(this),
|
127 | [`-${this.size}`]: Boolean(this.size),
|
128 | '-disabled': this.isDisabled,
|
129 | '-readonly': this.isReadonly,
|
130 | '-native': this.native
|
131 | };
|
132 | },
|
133 | checked() {
|
134 | // When inside a Checkbox Group
|
135 | if (this.formGroup.checked) {
|
136 | return this.formGroup.checked.includes(this.value);
|
137 | }
|
138 | if (this.schema) {
|
139 | return this.schema.value;
|
140 | }
|
141 | return this.modelValue;
|
142 | },
|
143 | tabIndex() {
|
144 | return this.isDisabled ? -1 : this.tabindex;
|
145 | }
|
146 | },
|
147 | methods: {
|
148 | clickInputRef() {
|
149 | if (this.isReadonly) {
|
150 | return;
|
151 | }
|
152 | this.$refs.input.click();
|
153 | },
|
154 | onChange(event) {
|
155 | this.parent.onInput?.(this.name, event.target.checked);
|
156 | // When inside a Checkbox Group
|
157 | this.formGroup.onChange?.(this.value);
|
158 | this.$emit('update:modelValue', event.target.checked);
|
159 | },
|
160 | onBlur(event) {
|
161 | this.parent.onBlur?.(this.name, event);
|
162 | }
|
163 | }
|
164 | });
|
165 | //# sourceMappingURL=script.mjs.map |
\ | No newline at end of file |