@pequity/squirrel 6.1.0 → 7.0.0
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/cjs/chunks/p-alert.js +52 -0
- package/dist/cjs/chunks/p-avatar.js +65 -0
- package/dist/cjs/chunks/p-btn.js +4 -4
- package/dist/cjs/chunks/p-date-picker.js +2 -2
- package/dist/cjs/chunks/p-input-number.js +161 -0
- package/dist/cjs/chunks/p-input-percent.js +2 -2
- package/dist/cjs/chunks/p-input.js +111 -0
- package/dist/cjs/chunks/p-progress-bar.js +38 -0
- package/dist/cjs/chunks/p-select-btn.js +3 -4
- package/dist/cjs/chunks/p-textarea.js +89 -0
- package/dist/cjs/index.js +69 -76
- package/dist/cjs/inputClasses.js +8 -2
- package/dist/cjs/p-alert.js +2 -64
- package/dist/cjs/p-avatar.js +2 -70
- package/dist/cjs/p-drawer.js +2 -2
- package/dist/cjs/p-input-number.js +2 -145
- package/dist/cjs/p-input-search.js +2 -2
- package/dist/cjs/p-input.js +2 -92
- package/dist/cjs/p-modal.js +2 -2
- package/dist/cjs/p-progress-bar.js +2 -40
- package/dist/cjs/p-table-filter-icon.js +14 -9
- package/dist/cjs/p-textarea.js +2 -72
- package/dist/cjs/p-toggle.js +76 -64
- package/dist/cjs/useInputClasses.js +13 -18
- package/dist/es/chunks/p-alert.js +53 -0
- package/dist/es/chunks/p-avatar.js +66 -0
- package/dist/es/chunks/p-btn.js +4 -4
- package/dist/es/chunks/p-date-picker.js +2 -2
- package/dist/es/chunks/p-input-number.js +162 -0
- package/dist/es/chunks/p-input-percent.js +2 -2
- package/dist/es/chunks/p-input.js +112 -0
- package/dist/es/chunks/p-progress-bar.js +39 -0
- package/dist/es/chunks/p-select-btn.js +4 -5
- package/dist/es/chunks/p-textarea.js +90 -0
- package/dist/es/index.js +119 -126
- package/dist/es/inputClasses.js +8 -2
- package/dist/es/p-alert.js +2 -64
- package/dist/es/p-avatar.js +2 -70
- package/dist/es/p-drawer.js +2 -2
- package/dist/es/p-input-number.js +2 -145
- package/dist/es/p-input-search.js +2 -2
- package/dist/es/p-input.js +2 -92
- package/dist/es/p-modal.js +2 -2
- package/dist/es/p-progress-bar.js +2 -40
- package/dist/es/p-table-filter-icon.js +14 -9
- package/dist/es/p-textarea.js +2 -72
- package/dist/es/p-toggle.js +77 -65
- package/dist/es/useInputClasses.js +14 -19
- package/dist/squirrel/components/p-alert/p-alert.vue.d.ts +27 -10
- package/dist/squirrel/components/p-avatar/p-avatar.vue.d.ts +9 -10
- package/dist/squirrel/components/p-btn/p-btn.vue.d.ts +28 -28
- package/dist/squirrel/components/p-date-picker/p-date-picker.vue.d.ts +2 -2
- package/dist/squirrel/components/p-drawer/p-drawer.vue.d.ts +37 -13
- package/dist/squirrel/components/p-inline-date-picker/p-inline-date-picker.vue.d.ts +2 -2
- package/dist/squirrel/components/p-input/p-input.vue.d.ts +30 -61
- package/dist/squirrel/components/p-input-number/p-input-number.vue.d.ts +101 -65
- package/dist/squirrel/components/p-input-search/p-input-search.vue.d.ts +113 -83
- package/dist/squirrel/components/p-modal/p-modal.vue.d.ts +2 -2
- package/dist/squirrel/components/p-progress-bar/p-progress-bar.vue.d.ts +5 -20
- package/dist/squirrel/components/p-table-header-cell/p-table-header-cell.vue.d.ts +1 -1
- package/dist/squirrel/components/p-table-loader/p-table-loader.vue.d.ts +1 -1
- package/dist/squirrel/components/p-table-sort/p-table-sort.vue.d.ts +3 -7
- package/dist/squirrel/components/p-textarea/p-textarea.vue.d.ts +79 -42
- package/dist/squirrel/components/p-toggle/p-toggle.vue.d.ts +25 -62
- package/dist/squirrel/composables/useInputClasses.d.ts +2 -1
- package/dist/squirrel/utils/index.d.ts +1 -3
- package/dist/squirrel/utils/inputClasses.d.ts +12 -0
- package/dist/squirrel.css +5 -5
- package/package.json +19 -19
- package/squirrel/components/p-alert/p-alert.spec.js +9 -8
- package/squirrel/components/p-alert/p-alert.vue +19 -31
- package/squirrel/components/p-avatar/p-avatar.spec.ts +10 -3
- package/squirrel/components/p-avatar/p-avatar.vue +40 -42
- package/squirrel/components/p-btn/p-btn.spec.js +7 -7
- package/squirrel/components/p-btn/p-btn.vue +4 -4
- package/squirrel/components/p-input/p-input.vue +63 -40
- package/squirrel/components/p-input-number/p-input-number.vue +101 -86
- package/squirrel/components/p-progress-bar/p-progress-bar.vue +9 -14
- package/squirrel/components/p-select-btn/p-select-btn.spec.js +24 -5
- package/squirrel/components/p-select-btn/p-select-btn.vue +1 -1
- package/squirrel/components/p-table-header-cell/p-table-filter-icon.vue +8 -9
- package/squirrel/components/p-table-sort/p-table-sort.vue +13 -16
- package/squirrel/components/p-textarea/p-textarea.vue +55 -37
- package/squirrel/components/p-toggle/p-toggle.vue +59 -43
- package/squirrel/composables/useInputClasses.spec.js +50 -13
- package/squirrel/composables/useInputClasses.ts +18 -24
- package/squirrel/utils/index.ts +0 -7
- package/squirrel/utils/inputClasses.ts +8 -2
- package/dist/cjs/inputClassesMixin.js +0 -58
- package/dist/cjs/tailwind.js +0 -25
- package/dist/es/inputClassesMixin.js +0 -59
- package/dist/es/tailwind.js +0 -25
- package/dist/squirrel/utils/inputClassesMixin.d.ts +0 -56
- package/dist/squirrel/utils/tailwind.d.ts +0 -8
- package/squirrel/utils/inputClassesMixin.spec.js +0 -241
- package/squirrel/utils/inputClassesMixin.ts +0 -60
- package/squirrel/utils/tailwind.spec.js +0 -27
- package/squirrel/utils/tailwind.ts +0 -28
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
</div>
|
|
19
19
|
</template>
|
|
20
20
|
|
|
21
|
-
<script lang="ts">
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { type Size, SIZES } from '@squirrel/components/p-btn/p-btn.types';
|
|
22
23
|
import PInfoIcon from '@squirrel/components/p-info-icon/p-info-icon.vue';
|
|
23
|
-
import
|
|
24
|
+
import { useInputClasses } from '@squirrel/composables/useInputClasses';
|
|
24
25
|
import { toNumberOrNull } from '@squirrel/utils/number';
|
|
25
26
|
import { kebabCase } from 'lodash-es';
|
|
26
|
-
import { computed,
|
|
27
|
+
import { computed, type PropType, type StyleValue, useAttrs, useSlots, watch } from 'vue';
|
|
27
28
|
import { type CurrencyDisplay, type CurrencyInputOptions, useCurrencyInput } from 'vue-currency-input';
|
|
28
29
|
|
|
29
30
|
const ALL_OPTIONS = [
|
|
@@ -40,93 +41,107 @@ const ALL_OPTIONS = [
|
|
|
40
41
|
'valueScaling',
|
|
41
42
|
];
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
defineOptions({
|
|
44
45
|
name: 'PInputNumber',
|
|
45
|
-
components: {
|
|
46
|
-
PInfoIcon,
|
|
47
|
-
},
|
|
48
|
-
mixins: [inputClassesMixin],
|
|
49
46
|
inheritAttrs: false,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const emit = defineEmits(['update:modelValue', 'change']);
|
|
50
|
+
|
|
51
|
+
const props = defineProps({
|
|
52
|
+
modelValue: {
|
|
53
|
+
type: [Number, String] as PropType<number | string | null | undefined>,
|
|
54
|
+
default: null,
|
|
55
|
+
},
|
|
56
|
+
label: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: '',
|
|
59
|
+
},
|
|
60
|
+
errorMsg: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: '',
|
|
63
|
+
},
|
|
64
|
+
required: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: false,
|
|
67
|
+
},
|
|
68
|
+
size: {
|
|
69
|
+
type: String as PropType<Size>,
|
|
70
|
+
default: 'md',
|
|
71
|
+
validator(value: Size) {
|
|
72
|
+
return SIZES.includes(value);
|
|
74
73
|
},
|
|
75
74
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const inputCurrencyOptions = computed(() => {
|
|
86
|
-
ALL_OPTIONS.forEach((key) => {
|
|
87
|
-
const attr = attrs[kebabCase(key)];
|
|
88
|
-
|
|
89
|
-
if (attr && typeof attr !== 'undefined') {
|
|
90
|
-
DEFAULTS[key] = attr;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return DEFAULTS;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const { inputRef, numberValue, setValue } = useCurrencyInput(
|
|
98
|
-
inputCurrencyOptions.value as unknown as CurrencyInputOptions,
|
|
99
|
-
false
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
watch(numberValue, (value) => {
|
|
103
|
-
emit('update:modelValue', toNumberOrNull(value));
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
watch(
|
|
107
|
-
() => props.modelValue,
|
|
108
|
-
(value) => {
|
|
109
|
-
setValue(toNumberOrNull(value));
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const computedAttrs = computed(() => {
|
|
114
|
-
const { class: classes, style, ...rest } = attrs;
|
|
115
|
-
|
|
116
|
-
return rest;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const style = computed(() => {
|
|
120
|
-
return attrs.style as StyleValue;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const focus = () => {
|
|
124
|
-
props.selectOnClick && inputRef.value.select();
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
expose({ setValue });
|
|
128
|
-
|
|
129
|
-
return { inputRef, computedAttrs, style, focus };
|
|
75
|
+
selectOnClick: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: true,
|
|
78
|
+
},
|
|
79
|
+
tooltipText: {
|
|
80
|
+
type: String,
|
|
81
|
+
default: '',
|
|
130
82
|
},
|
|
131
83
|
});
|
|
84
|
+
|
|
85
|
+
const slots = useSlots();
|
|
86
|
+
|
|
87
|
+
const { labelClasses, inputClasses, errorMsgClasses } = useInputClasses(
|
|
88
|
+
computed(() => ({
|
|
89
|
+
...props,
|
|
90
|
+
prefix: !!slots.prefix,
|
|
91
|
+
suffix: !!slots.suffix,
|
|
92
|
+
}))
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const attrs = useAttrs();
|
|
96
|
+
|
|
97
|
+
const DEFAULTS: CurrencyInputOptions & Record<string, unknown> = {
|
|
98
|
+
locale: 'en-US',
|
|
99
|
+
currency: 'USD',
|
|
100
|
+
precision: 0,
|
|
101
|
+
currencyDisplay: 'hidden' as CurrencyDisplay,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const inputCurrencyOptions = computed(() => {
|
|
105
|
+
ALL_OPTIONS.forEach((key) => {
|
|
106
|
+
const attr = attrs[kebabCase(key)];
|
|
107
|
+
|
|
108
|
+
if (attr && typeof attr !== 'undefined') {
|
|
109
|
+
DEFAULTS[key] = attr;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return DEFAULTS;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const { inputRef, numberValue, setValue } = useCurrencyInput(
|
|
117
|
+
inputCurrencyOptions.value as unknown as CurrencyInputOptions,
|
|
118
|
+
false
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
watch(numberValue, (value) => {
|
|
122
|
+
emit('update:modelValue', toNumberOrNull(value));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
watch(
|
|
126
|
+
() => props.modelValue,
|
|
127
|
+
(value) => {
|
|
128
|
+
setValue(toNumberOrNull(value));
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const computedAttrs = computed(() => {
|
|
133
|
+
const { class: classes, style, ...rest } = attrs;
|
|
134
|
+
|
|
135
|
+
return rest;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const style = computed(() => {
|
|
139
|
+
return attrs.style as StyleValue;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const focus = () => {
|
|
143
|
+
props.selectOnClick && inputRef.value.select();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
defineExpose({ setValue });
|
|
132
147
|
</script>
|
|
@@ -10,26 +10,21 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import { defineComponent, type PropType } from 'vue';
|
|
15
|
-
|
|
13
|
+
<script setup lang="ts">
|
|
16
14
|
export type ProgressItem = {
|
|
17
15
|
value: number;
|
|
18
16
|
color: string;
|
|
19
17
|
label?: string;
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
type Props = {
|
|
21
|
+
total: number;
|
|
22
|
+
items: ProgressItem[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
defineOptions({
|
|
23
26
|
name: 'PProgressBar',
|
|
24
|
-
props: {
|
|
25
|
-
total: {
|
|
26
|
-
type: Number as PropType<number>,
|
|
27
|
-
required: true,
|
|
28
|
-
},
|
|
29
|
-
items: {
|
|
30
|
-
type: Array as PropType<ProgressItem[]>,
|
|
31
|
-
required: true,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
27
|
});
|
|
28
|
+
|
|
29
|
+
defineProps<Props>();
|
|
35
30
|
</script>
|
|
@@ -134,7 +134,7 @@ describe('PSelectBtn.vue', () => {
|
|
|
134
134
|
},
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
const buttonDivs =
|
|
137
|
+
const buttonDivs = wrapper.findAll('div.inline-flex');
|
|
138
138
|
|
|
139
139
|
buttonDivs.forEach((buttonDiv, i) => {
|
|
140
140
|
expect(buttonDiv.attributes()['data-tooltip']).toBe(items[i].textCustom);
|
|
@@ -213,6 +213,25 @@ describe('PSelectBtn.vue', () => {
|
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
+
it('renders auto-width buttons', async () => {
|
|
217
|
+
const wrapper = createWrapperFor(PSelectBtn, {
|
|
218
|
+
props: {
|
|
219
|
+
items,
|
|
220
|
+
itemValue: 'valueCustom',
|
|
221
|
+
itemText: 'textCustom',
|
|
222
|
+
modelValue: 2,
|
|
223
|
+
grow: false,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const buttons = await wrapper.findAll('button');
|
|
228
|
+
|
|
229
|
+
expect(wrapper.classes()).toContain('flex');
|
|
230
|
+
buttons.forEach((button) => {
|
|
231
|
+
expect(button.classes()).not.toContain('flex-1');
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
216
235
|
it('removes padding from buttons', async () => {
|
|
217
236
|
const wrapper = createWrapperFor(PSelectBtn, {
|
|
218
237
|
props: {
|
|
@@ -224,11 +243,11 @@ describe('PSelectBtn.vue', () => {
|
|
|
224
243
|
},
|
|
225
244
|
});
|
|
226
245
|
|
|
227
|
-
const
|
|
246
|
+
const buttonDivs = wrapper.findAll('div.inline-flex');
|
|
228
247
|
|
|
229
|
-
|
|
230
|
-
expect(
|
|
231
|
-
expect(
|
|
248
|
+
buttonDivs.forEach((buttonDiv) => {
|
|
249
|
+
expect(buttonDiv.classes()).toContain('*:px-0');
|
|
250
|
+
expect(buttonDiv.classes()).toContain('*:py-0');
|
|
232
251
|
});
|
|
233
252
|
});
|
|
234
253
|
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
<div :class="['h-5 w-5 shrink-0 cursor-pointer filter', { active: active }]" v-bind="$attrs"></div>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
-
<script lang="ts">
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default defineComponent({
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
defineOptions({
|
|
9
7
|
name: 'PTableFilterIcon',
|
|
10
8
|
inheritAttrs: false,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
defineProps({
|
|
12
|
+
active: {
|
|
13
|
+
type: Boolean,
|
|
14
|
+
default: false,
|
|
16
15
|
},
|
|
17
16
|
});
|
|
18
17
|
</script>
|
|
@@ -55,26 +55,23 @@
|
|
|
55
55
|
</div>
|
|
56
56
|
</template>
|
|
57
57
|
|
|
58
|
-
<script lang="ts">
|
|
58
|
+
<script setup lang="ts">
|
|
59
59
|
import { SORTING_TYPES, type SortingType } from '@squirrel/components/p-table-sort/p-table-sort.config';
|
|
60
|
-
import {
|
|
60
|
+
import { type PropType } from 'vue';
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
defineOptions({
|
|
63
63
|
name: 'PTableSort',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
defineEmits(['update:modelValue']);
|
|
67
|
+
|
|
68
|
+
defineProps({
|
|
69
|
+
modelValue: {
|
|
70
|
+
type: String as PropType<SortingType>,
|
|
71
|
+
default: SORTING_TYPES.NO_SORTING,
|
|
72
|
+
validator(value: SortingType) {
|
|
73
|
+
return Object.values(SORTING_TYPES).includes(value);
|
|
71
74
|
},
|
|
72
75
|
},
|
|
73
|
-
emits: ['update:modelValue'],
|
|
74
|
-
data() {
|
|
75
|
-
return {
|
|
76
|
-
SORTING_TYPES,
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
76
|
});
|
|
80
77
|
</script>
|
|
@@ -10,49 +10,67 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { type Size, SIZES } from '@squirrel/components/p-btn/p-btn.types';
|
|
15
|
+
import { useInputClasses } from '@squirrel/composables/useInputClasses';
|
|
16
|
+
import { computed, type PropType, type StyleValue, useAttrs } from 'vue';
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
defineOptions({
|
|
18
19
|
name: 'PTextarea',
|
|
19
|
-
mixins: [inputClassesMixin],
|
|
20
20
|
inheritAttrs: false,
|
|
21
|
-
|
|
22
|
-
modelValue: {
|
|
23
|
-
type: [String, Number],
|
|
24
|
-
default: '',
|
|
25
|
-
},
|
|
26
|
-
label: {
|
|
27
|
-
type: String,
|
|
28
|
-
default: '',
|
|
29
|
-
},
|
|
30
|
-
errorMsg: {
|
|
31
|
-
type: String,
|
|
32
|
-
default: '',
|
|
33
|
-
},
|
|
34
|
-
required: {
|
|
35
|
-
type: Boolean,
|
|
36
|
-
default: false,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
emits: ['update:modelValue'],
|
|
40
|
-
computed: {
|
|
41
|
-
attrs() {
|
|
42
|
-
const { class: classes, style, ...rest } = this.$attrs;
|
|
21
|
+
});
|
|
43
22
|
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
style() {
|
|
47
|
-
return this.$attrs.style as StyleValue;
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
methods: {
|
|
51
|
-
updateValue(e: Event): void {
|
|
52
|
-
const target = e.target as HTMLInputElement;
|
|
23
|
+
const emit = defineEmits(['update:modelValue']);
|
|
53
24
|
|
|
54
|
-
|
|
25
|
+
const props = defineProps({
|
|
26
|
+
modelValue: {
|
|
27
|
+
type: [String, Number, null] as PropType<string | number | null>,
|
|
28
|
+
default: '',
|
|
29
|
+
},
|
|
30
|
+
label: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: '',
|
|
33
|
+
},
|
|
34
|
+
errorMsg: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: '',
|
|
37
|
+
},
|
|
38
|
+
required: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
type: String as PropType<Size>,
|
|
44
|
+
default: 'md',
|
|
45
|
+
validator(value: Size) {
|
|
46
|
+
return SIZES.includes(value);
|
|
55
47
|
},
|
|
56
48
|
},
|
|
57
49
|
});
|
|
50
|
+
|
|
51
|
+
const { labelClasses, textareaClasses, errorMsgClasses } = useInputClasses(
|
|
52
|
+
computed(() => ({
|
|
53
|
+
required: props.required,
|
|
54
|
+
errorMsg: props.errorMsg,
|
|
55
|
+
size: props.size,
|
|
56
|
+
}))
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const allAttrs = useAttrs();
|
|
60
|
+
|
|
61
|
+
const attrs = computed(() => {
|
|
62
|
+
const { class: classes, style, ...rest } = allAttrs;
|
|
63
|
+
|
|
64
|
+
return rest;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const style = computed(() => {
|
|
68
|
+
return allAttrs.style as StyleValue;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const updateValue = (e: Event) => {
|
|
72
|
+
const target = e.target as HTMLInputElement;
|
|
73
|
+
|
|
74
|
+
emit('update:modelValue', target.value);
|
|
75
|
+
};
|
|
58
76
|
</script>
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
27
|
<script lang="ts">
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
28
|
+
import { type Size, SIZES } from '@squirrel/components/p-btn/p-btn.types';
|
|
29
|
+
import { useInputClasses } from '@squirrel/composables/useInputClasses';
|
|
30
|
+
import { computed, type PropType, type StyleValue, useAttrs } from 'vue';
|
|
30
31
|
|
|
31
32
|
const TOGGLE_SIZES = {
|
|
32
33
|
sm: `w-7 h-4 after:top-[2px] after:left-[2px] after:h-3 after:w-3`,
|
|
@@ -52,56 +53,71 @@ const TOGGLE_CLASSES = [
|
|
|
52
53
|
'peer-disabled:bg-p-blue-10',
|
|
53
54
|
'peer-disabled:after:border-p-blue-10',
|
|
54
55
|
].join(' ');
|
|
56
|
+
</script>
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
defineOptions({
|
|
57
60
|
name: 'PToggle',
|
|
58
|
-
mixins: [inputClassesMixin],
|
|
59
61
|
inheritAttrs: false,
|
|
60
|
-
|
|
61
|
-
modelValue: {
|
|
62
|
-
type: Boolean,
|
|
63
|
-
default: false,
|
|
64
|
-
},
|
|
65
|
-
label: {
|
|
66
|
-
type: String,
|
|
67
|
-
default: '',
|
|
68
|
-
},
|
|
69
|
-
errorMsg: {
|
|
70
|
-
type: String,
|
|
71
|
-
default: '',
|
|
72
|
-
},
|
|
73
|
-
required: {
|
|
74
|
-
type: Boolean,
|
|
75
|
-
default: false,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
emits: ['update:modelValue'],
|
|
79
|
-
computed: {
|
|
80
|
-
toggleClasses() {
|
|
81
|
-
const base = `${TOGGLE_CLASSES} ${TOGGLE_SIZES[this.size]}`;
|
|
82
|
-
const res = this.errorMsg ? `${base} border border-on-error` : base;
|
|
62
|
+
});
|
|
83
63
|
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
toggleLabelClasses() {
|
|
87
|
-
return `${this.labelClasses.replace('mb-1', '')} ml-2`;
|
|
88
|
-
},
|
|
89
|
-
attrs() {
|
|
90
|
-
const { style, class: classes, 'data-testid': dataTestId, ...rest } = this.$attrs;
|
|
64
|
+
const emit = defineEmits(['update:modelValue']);
|
|
91
65
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
66
|
+
const props = defineProps({
|
|
67
|
+
modelValue: {
|
|
68
|
+
type: Boolean,
|
|
69
|
+
default: false,
|
|
70
|
+
},
|
|
71
|
+
label: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: '',
|
|
74
|
+
},
|
|
75
|
+
errorMsg: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: '',
|
|
78
|
+
},
|
|
79
|
+
required: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false,
|
|
97
82
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
size: {
|
|
84
|
+
type: String as PropType<Size>,
|
|
85
|
+
default: 'md',
|
|
86
|
+
validator(value: Size) {
|
|
87
|
+
return SIZES.includes(value);
|
|
102
88
|
},
|
|
103
89
|
},
|
|
104
90
|
});
|
|
91
|
+
|
|
92
|
+
const allAttrs = useAttrs();
|
|
93
|
+
const { labelClasses, errorMsgClasses } = useInputClasses(props);
|
|
94
|
+
|
|
95
|
+
const toggleClasses = computed(() => {
|
|
96
|
+
const base = `${TOGGLE_CLASSES} ${TOGGLE_SIZES[props.size]}`;
|
|
97
|
+
const res = props.errorMsg ? `${base} border border-on-error` : base;
|
|
98
|
+
|
|
99
|
+
return res;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const toggleLabelClasses = computed(() => {
|
|
103
|
+
return `${labelClasses.value.replace('mb-1', '')} ml-2`;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const attrs = computed(() => {
|
|
107
|
+
const { style, class: classes, 'data-testid': dataTestId, ...rest } = allAttrs;
|
|
108
|
+
|
|
109
|
+
return rest;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const style = computed(() => {
|
|
113
|
+
return allAttrs.style as StyleValue;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const change = (e: Event) => {
|
|
117
|
+
const target = e.target as HTMLInputElement;
|
|
118
|
+
|
|
119
|
+
emit('update:modelValue', target.checked);
|
|
120
|
+
};
|
|
105
121
|
</script>
|
|
106
122
|
|
|
107
123
|
<style scoped>
|