@histoire/controls 0.4.4 → 0.5.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/components/select/CustomSelect.vue.d.ts +25 -0
- package/dist/components/select/HstSelect.vue.d.ts +23 -41
- package/dist/index.es.js +227 -170
- package/dist/style-standalone.css +62 -5
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/components/HstWrapper.vue +5 -2
- package/src/components/checkbox/HstCheckbox.vue +4 -0
- package/src/components/checkbox/__snapshots__/HstCheckbox.test.ts.snap +42 -38
- package/src/components/number/HstNumber.vue +4 -0
- package/src/components/select/CustomSelect.vue +119 -0
- package/src/components/select/HstSelect.story.vue +33 -7
- package/src/components/select/HstSelect.vue +21 -44
- package/src/components/text/HstText.vue +4 -0
- package/src/components/textarea/HstTextarea.vue +4 -0
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
.v-popper__popper{
|
|
29
29
|
z-index:10000;
|
|
30
30
|
top:0;
|
|
31
|
-
left:0
|
|
31
|
+
left:0;
|
|
32
|
+
outline:none
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
.v-popper__popper.v-popper__popper--hidden{
|
|
@@ -294,6 +295,10 @@
|
|
|
294
295
|
margin-bottom:0.5rem
|
|
295
296
|
}
|
|
296
297
|
|
|
298
|
+
.htw-ml-auto{
|
|
299
|
+
margin-left:auto
|
|
300
|
+
}
|
|
301
|
+
|
|
297
302
|
.htw-box-border{
|
|
298
303
|
box-sizing:border-box
|
|
299
304
|
}
|
|
@@ -334,6 +339,10 @@
|
|
|
334
339
|
height:5rem
|
|
335
340
|
}
|
|
336
341
|
|
|
342
|
+
.htw-h-\[27px\]{
|
|
343
|
+
height:27px
|
|
344
|
+
}
|
|
345
|
+
|
|
337
346
|
.htw-min-h-\[26px\]{
|
|
338
347
|
min-height:26px
|
|
339
348
|
}
|
|
@@ -366,6 +375,10 @@
|
|
|
366
375
|
flex:none
|
|
367
376
|
}
|
|
368
377
|
|
|
378
|
+
.htw-flex-1{
|
|
379
|
+
flex:1 1 0%
|
|
380
|
+
}
|
|
381
|
+
|
|
369
382
|
.htw-shrink-0{
|
|
370
383
|
flex-shrink:0
|
|
371
384
|
}
|
|
@@ -425,14 +438,14 @@
|
|
|
425
438
|
gap:0.5rem
|
|
426
439
|
}
|
|
427
440
|
|
|
428
|
-
.htw-gap-4{
|
|
429
|
-
gap:1rem
|
|
430
|
-
}
|
|
431
|
-
|
|
432
441
|
.htw-gap-1{
|
|
433
442
|
gap:0.25rem
|
|
434
443
|
}
|
|
435
444
|
|
|
445
|
+
.htw-gap-4{
|
|
446
|
+
gap:1rem
|
|
447
|
+
}
|
|
448
|
+
|
|
436
449
|
.htw-overflow-hidden{
|
|
437
450
|
overflow:hidden
|
|
438
451
|
}
|
|
@@ -488,6 +501,11 @@
|
|
|
488
501
|
border-color:rgb(0 0 0 / 0.25)
|
|
489
502
|
}
|
|
490
503
|
|
|
504
|
+
.htw-border-gray-850{
|
|
505
|
+
--tw-border-opacity:1;
|
|
506
|
+
border-color:rgb(31 31 33 / var(--tw-border-opacity))
|
|
507
|
+
}
|
|
508
|
+
|
|
491
509
|
.htw-bg-white{
|
|
492
510
|
--tw-bg-opacity:1;
|
|
493
511
|
background-color:rgb(255 255 255 / var(--tw-bg-opacity))
|
|
@@ -510,6 +528,16 @@
|
|
|
510
528
|
background-color:rgb(250 250 250 / var(--tw-bg-opacity))
|
|
511
529
|
}
|
|
512
530
|
|
|
531
|
+
.htw-bg-primary-200{
|
|
532
|
+
--tw-bg-opacity:1;
|
|
533
|
+
background-color:rgb(167 243 208 / var(--tw-bg-opacity))
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
.htw-bg-gray-700{
|
|
537
|
+
--tw-bg-opacity:1;
|
|
538
|
+
background-color:rgb(63 63 70 / var(--tw-bg-opacity))
|
|
539
|
+
}
|
|
540
|
+
|
|
513
541
|
.htw-stroke-white{
|
|
514
542
|
stroke:#fff
|
|
515
543
|
}
|
|
@@ -550,6 +578,10 @@
|
|
|
550
578
|
line-height:1rem
|
|
551
579
|
}
|
|
552
580
|
|
|
581
|
+
.htw-leading-normal{
|
|
582
|
+
line-height:1.5
|
|
583
|
+
}
|
|
584
|
+
|
|
553
585
|
.htw-text-white{
|
|
554
586
|
--tw-text-opacity:1;
|
|
555
587
|
color:rgb(255 255 255 / var(--tw-text-opacity))
|
|
@@ -619,6 +651,11 @@ body {
|
|
|
619
651
|
}
|
|
620
652
|
}
|
|
621
653
|
|
|
654
|
+
.hover\:htw-border-primary-500:hover{
|
|
655
|
+
--tw-border-opacity:1;
|
|
656
|
+
border-color:rgb(16 185 129 / var(--tw-border-opacity))
|
|
657
|
+
}
|
|
658
|
+
|
|
622
659
|
.hover\:htw-bg-primary-100:hover{
|
|
623
660
|
--tw-bg-opacity:1;
|
|
624
661
|
background-color:rgb(209 250 229 / var(--tw-bg-opacity))
|
|
@@ -651,16 +688,36 @@ body {
|
|
|
651
688
|
background-color:rgb(0 0 0 / var(--tw-bg-opacity))
|
|
652
689
|
}
|
|
653
690
|
|
|
691
|
+
.htw-dark .dark\:htw-bg-gray-700{
|
|
692
|
+
--tw-bg-opacity:1;
|
|
693
|
+
background-color:rgb(63 63 70 / var(--tw-bg-opacity))
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
.htw-dark .dark\:htw-bg-primary-800{
|
|
697
|
+
--tw-bg-opacity:1;
|
|
698
|
+
background-color:rgb(6 95 70 / var(--tw-bg-opacity))
|
|
699
|
+
}
|
|
700
|
+
|
|
654
701
|
.htw-dark .dark\:htw-bg-gray-600{
|
|
655
702
|
--tw-bg-opacity:1;
|
|
656
703
|
background-color:rgb(82 82 91 / var(--tw-bg-opacity))
|
|
657
704
|
}
|
|
658
705
|
|
|
706
|
+
.htw-dark .dark\:hover\:htw-border-primary-500:hover{
|
|
707
|
+
--tw-border-opacity:1;
|
|
708
|
+
border-color:rgb(16 185 129 / var(--tw-border-opacity))
|
|
709
|
+
}
|
|
710
|
+
|
|
659
711
|
.htw-dark .dark\:hover\:htw-bg-primary-800:hover{
|
|
660
712
|
--tw-bg-opacity:1;
|
|
661
713
|
background-color:rgb(6 95 70 / var(--tw-bg-opacity))
|
|
662
714
|
}
|
|
663
715
|
|
|
716
|
+
.htw-dark .dark\:hover\:htw-bg-primary-700:hover{
|
|
717
|
+
--tw-bg-opacity:1;
|
|
718
|
+
background-color:rgb(4 120 87 / var(--tw-bg-opacity))
|
|
719
|
+
}
|
|
720
|
+
|
|
664
721
|
.htw-dark .dark\:focus\:htw-border-primary-500:focus{
|
|
665
722
|
--tw-border-opacity:1;
|
|
666
723
|
border-color:rgb(16 185 129 / var(--tw-border-opacity))
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.htw-bind-col-size{grid-template-columns:repeat(auto-fill,minmax(var(--histoire-col-size),1fr))}
|
|
1
|
+
.v-popper{line-height:0}.htw-dark .v-popper--theme-dropdown .v-popper__inner{--tw-border-opacity: 1;border-color:rgb(31 31 33 / var(--tw-border-opacity));--tw-bg-opacity: 1;background-color:rgb(63 63 70 / var(--tw-bg-opacity));--tw-text-opacity: 1;color:rgb(244 244 245 / var(--tw-text-opacity))}.htw-dark .v-popper--theme-dropdown .v-popper__arrow-inner{--tw-border-opacity: 1;border-color:rgb(63 63 70 / var(--tw-border-opacity))}.htw-dark .v-popper--theme-dropdown .v-popper__arrow-outer{--tw-border-opacity: 1;border-color:rgb(31 31 33 / var(--tw-border-opacity))}.v-popper--theme-dropdown.v-popper__popper--show-from .v-popper__wrapper{transform:scale(.75)}.v-popper--theme-dropdown.v-popper__popper--show-to .v-popper__wrapper{transform:none;transition:transform .15s cubic-bezier(0,1,.5,1)}.v-popper__popper:focus-visible{outline:none}.htw-bind-col-size{grid-template-columns:repeat(auto-fill,minmax(var(--histoire-col-size),1fr))}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/controls",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Prebuilt controls components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@peeky/test": "^0.13.5",
|
|
40
|
-
"@types/node": "^17.0.
|
|
40
|
+
"@types/node": "^17.0.32",
|
|
41
41
|
"@vitejs/plugin-vue": "^2.3.1",
|
|
42
42
|
"@vue/test-utils": "^2.0.0-rc.19",
|
|
43
43
|
"@vueuse/core": "^8.2.5",
|
|
44
44
|
"autoprefixer": "^10.4.4",
|
|
45
45
|
"concurrently": "^7.1.0",
|
|
46
46
|
"floating-vue": "^2.0.0-beta.16",
|
|
47
|
-
"histoire": "0.
|
|
47
|
+
"histoire": "0.5.0",
|
|
48
48
|
"postcss": "^8.4.12",
|
|
49
49
|
"postcss-import": "^14.1.0",
|
|
50
50
|
"tailwindcss": "^3.0.23",
|
|
@@ -24,8 +24,11 @@ const props = defineProps<{
|
|
|
24
24
|
>
|
|
25
25
|
{{ title }}
|
|
26
26
|
</span>
|
|
27
|
-
<span class="htw-
|
|
28
|
-
<
|
|
27
|
+
<span class="htw-grow htw-flex htw-items-center htw-gap-1">
|
|
28
|
+
<span class="htw-block htw-grow">
|
|
29
|
+
<slot />
|
|
30
|
+
</span>
|
|
31
|
+
<slot name="actions" />
|
|
29
32
|
</span>
|
|
30
33
|
</label>
|
|
31
34
|
</template>
|
|
@@ -9,26 +9,28 @@ exports[`HstCheckbox toggle to checked 1`] = `
|
|
|
9
9
|
<span class="htw-w-28 htw-whitespace-nowrap htw-text-ellipsis htw-overflow-hidden htw-shrink-0 v-popper--has-tooltip">
|
|
10
10
|
Label
|
|
11
11
|
</span>
|
|
12
|
-
<span class="htw-
|
|
13
|
-
<
|
|
14
|
-
<div class="htw-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<path
|
|
23
|
-
d="m 4 12 l 5 5 l 10 -10"
|
|
24
|
-
fill="none"
|
|
25
|
-
class="htw-stroke-white htw-stroke-2 htw-duration-200 htw-ease-in-out htw-transition-all"
|
|
26
|
-
stroke-dasharray="21.21"
|
|
27
|
-
stroke-dashoffset="21.21"
|
|
12
|
+
<span class="htw-grow htw-flex htw-items-center htw-gap-1">
|
|
13
|
+
<span class="htw-block htw-grow">
|
|
14
|
+
<div class="htw-text-white htw-w-[16px] htw-h-[16px] htw-relative">
|
|
15
|
+
<div class="htw-border htw-border-solid group-active:htw-bg-gray-500/20 htw-rounded-sm htw-box-border htw-absolute htw-inset-0 htw-transition-border htw-duration-150 htw-ease-out htw-border-black/25 dark:htw-border-white/25 htw-delay-150">
|
|
16
|
+
</div>
|
|
17
|
+
<svg
|
|
18
|
+
width="16"
|
|
19
|
+
height="16"
|
|
20
|
+
viewbox="0 0 24 24"
|
|
21
|
+
class="htw-relative htw-z-10"
|
|
28
22
|
>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
<path
|
|
24
|
+
d="m 4 12 l 5 5 l 10 -10"
|
|
25
|
+
fill="none"
|
|
26
|
+
class="htw-stroke-white htw-stroke-2 htw-duration-200 htw-ease-in-out htw-transition-all"
|
|
27
|
+
stroke-dasharray="21.21"
|
|
28
|
+
stroke-dashoffset="21.21"
|
|
29
|
+
>
|
|
30
|
+
</path>
|
|
31
|
+
</svg>
|
|
32
|
+
</div>
|
|
33
|
+
</span>
|
|
32
34
|
</span>
|
|
33
35
|
</label>
|
|
34
36
|
`;
|
|
@@ -42,26 +44,28 @@ exports[`HstCheckbox toggle to unchecked 1`] = `
|
|
|
42
44
|
<span class="htw-w-28 htw-whitespace-nowrap htw-text-ellipsis htw-overflow-hidden htw-shrink-0 v-popper--has-tooltip">
|
|
43
45
|
Label
|
|
44
46
|
</span>
|
|
45
|
-
<span class="htw-
|
|
46
|
-
<
|
|
47
|
-
<div class="htw-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<path
|
|
56
|
-
d="m 4 12 l 5 5 l 10 -10"
|
|
57
|
-
fill="none"
|
|
58
|
-
class="htw-stroke-white htw-stroke-2 htw-duration-200 htw-ease-in-out htw-transition-all htw-delay-150"
|
|
59
|
-
stroke-dasharray="21.21"
|
|
60
|
-
stroke-dashoffset="0"
|
|
47
|
+
<span class="htw-grow htw-flex htw-items-center htw-gap-1">
|
|
48
|
+
<span class="htw-block htw-grow">
|
|
49
|
+
<div class="htw-text-white htw-w-[16px] htw-h-[16px] htw-relative">
|
|
50
|
+
<div class="htw-border htw-border-solid group-active:htw-bg-gray-500/20 htw-rounded-sm htw-box-border htw-absolute htw-inset-0 htw-transition-border htw-duration-150 htw-ease-out htw-border-primary-500 htw-border-8">
|
|
51
|
+
</div>
|
|
52
|
+
<svg
|
|
53
|
+
width="16"
|
|
54
|
+
height="16"
|
|
55
|
+
viewbox="0 0 24 24"
|
|
56
|
+
class="htw-relative htw-z-10"
|
|
61
57
|
>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
<path
|
|
59
|
+
d="m 4 12 l 5 5 l 10 -10"
|
|
60
|
+
fill="none"
|
|
61
|
+
class="htw-stroke-white htw-stroke-2 htw-duration-200 htw-ease-in-out htw-transition-all htw-delay-150"
|
|
62
|
+
stroke-dasharray="21.21"
|
|
63
|
+
stroke-dashoffset="0"
|
|
64
|
+
>
|
|
65
|
+
</path>
|
|
66
|
+
</svg>
|
|
67
|
+
</div>
|
|
68
|
+
</span>
|
|
65
69
|
</span>
|
|
66
70
|
</label>
|
|
67
71
|
`;
|
|
@@ -88,5 +88,9 @@ onUnmounted(() => {
|
|
|
88
88
|
}"
|
|
89
89
|
class="htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-pl-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm htw-cursor-ew-resize"
|
|
90
90
|
>
|
|
91
|
+
|
|
92
|
+
<template #actions>
|
|
93
|
+
<slot name="actions" />
|
|
94
|
+
</template>
|
|
91
95
|
</HstWrapper>
|
|
92
96
|
</template>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export default {
|
|
3
|
+
name: 'CustomSelect',
|
|
4
|
+
}
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { Dropdown as VDropdown } from 'floating-vue'
|
|
9
|
+
import { computed, ComputedRef } from 'vue'
|
|
10
|
+
import { Icon } from '@iconify/vue'
|
|
11
|
+
|
|
12
|
+
export interface SelectOption {
|
|
13
|
+
label: string
|
|
14
|
+
value: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
modelValue: string
|
|
19
|
+
options: Record<string, string> | string[] | SelectOption[]
|
|
20
|
+
}>()
|
|
21
|
+
|
|
22
|
+
const emits = defineEmits<{
|
|
23
|
+
(e: 'update:modelValue', value: string): void
|
|
24
|
+
}>()
|
|
25
|
+
|
|
26
|
+
const formattedOptions: ComputedRef<Record<string, string>> = computed(() => {
|
|
27
|
+
if (Array.isArray(props.options)) {
|
|
28
|
+
return Object.fromEntries(props.options.map((value: string | SelectOption) => {
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
return [value, value]
|
|
31
|
+
} else {
|
|
32
|
+
return [value.value, value.label]
|
|
33
|
+
}
|
|
34
|
+
}))
|
|
35
|
+
}
|
|
36
|
+
return props.options
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const selectedLabel = computed(() => formattedOptions.value[props.modelValue])
|
|
40
|
+
|
|
41
|
+
function selectValue (value: string, hide: () => void) {
|
|
42
|
+
emits('update:modelValue', value)
|
|
43
|
+
hide()
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<VDropdown
|
|
49
|
+
auto-size
|
|
50
|
+
>
|
|
51
|
+
<div
|
|
52
|
+
class="htw-cursor-pointer htw-w-full htw-outline-none htw-px-2 htw-h-[27px] -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 hover:htw-border-primary-500 dark:hover:htw-border-primary-500 htw-rounded-sm htw-flex htw-gap-2 htw-items-center htw-leading-normal"
|
|
53
|
+
>
|
|
54
|
+
<div class="htw-flex-1 htw-truncate">
|
|
55
|
+
<slot :label="selectedLabel">
|
|
56
|
+
{{ selectedLabel }}
|
|
57
|
+
</slot>
|
|
58
|
+
</div>
|
|
59
|
+
<Icon
|
|
60
|
+
icon="carbon:chevron-sort"
|
|
61
|
+
class="htw-w-4 htw-h-4 htw-flex-none htw-ml-auto"
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
<template #popper="{ hide }">
|
|
65
|
+
<div class="htw-flex htw-flex-col htw-bg-gray-50 dark:htw-bg-gray-700">
|
|
66
|
+
<div
|
|
67
|
+
v-for="( label, value ) in formattedOptions"
|
|
68
|
+
v-bind="{ ...$attrs, class: null, style: null }"
|
|
69
|
+
:key="label"
|
|
70
|
+
class="htw-px-2 htw-py-1 htw-cursor-pointer hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700"
|
|
71
|
+
:class="{
|
|
72
|
+
'htw-bg-primary-200 dark:htw-bg-primary-800': props.modelValue === value,
|
|
73
|
+
}"
|
|
74
|
+
@click="selectValue(value, hide)"
|
|
75
|
+
>
|
|
76
|
+
{{ label }}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</template>
|
|
80
|
+
</VDropdown>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<style lang="postcss">
|
|
84
|
+
/* @TODO custom themes */
|
|
85
|
+
|
|
86
|
+
.v-popper {
|
|
87
|
+
line-height: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.v-popper--theme-dropdown {
|
|
91
|
+
.htw-dark & {
|
|
92
|
+
.v-popper__inner {
|
|
93
|
+
@apply htw-bg-gray-700 htw-border-gray-850 htw-text-gray-100;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.v-popper__arrow-inner {
|
|
97
|
+
@apply htw-border-gray-700;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.v-popper__arrow-outer {
|
|
101
|
+
@apply htw-border-gray-850;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.v-popper__popper--show-from .v-popper__wrapper {
|
|
106
|
+
transform: scale(.75);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&.v-popper__popper--show-to .v-popper__wrapper {
|
|
110
|
+
transform: none;
|
|
111
|
+
transition: transform .15s cubic-bezier(0, 1, .5, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.v-popper__popper:focus-visible {
|
|
116
|
+
outline: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
</style>
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import HstSelect from './HstSelect.vue'
|
|
3
3
|
|
|
4
|
-
const options =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const options = {
|
|
5
|
+
'crash-bandicoot': 'Crash Bandicoot',
|
|
6
|
+
'the-last-of-us': 'The Last of Us',
|
|
7
|
+
'ghost-of-tsushima': 'Ghost of Tsushima',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const flatOptions = Object.keys(options)
|
|
9
11
|
|
|
10
|
-
const
|
|
12
|
+
const objectOptions = Object.keys(options).map(key => ({
|
|
13
|
+
label: options[key],
|
|
14
|
+
value: key,
|
|
15
|
+
}))
|
|
11
16
|
|
|
12
17
|
function initState () {
|
|
13
18
|
return {
|
|
@@ -66,7 +71,7 @@ function initState () {
|
|
|
66
71
|
</Variant>
|
|
67
72
|
|
|
68
73
|
<Variant
|
|
69
|
-
title="options-as-
|
|
74
|
+
title="options-as-object"
|
|
70
75
|
:init-state="initState"
|
|
71
76
|
>
|
|
72
77
|
<template #default="{ state }">
|
|
@@ -86,6 +91,27 @@ function initState () {
|
|
|
86
91
|
</template>
|
|
87
92
|
</Variant>
|
|
88
93
|
|
|
94
|
+
<Variant
|
|
95
|
+
title="options-as-array-of-objects"
|
|
96
|
+
:init-state="initState"
|
|
97
|
+
>
|
|
98
|
+
<template #default="{ state }">
|
|
99
|
+
<pre class="htw-text-xs htw-bg-gray-50 dark:htw-bg-gray-600 htw-rounded htw-p-4">{{ objectOptions }}</pre>
|
|
100
|
+
<HstSelect
|
|
101
|
+
v-model="state.select"
|
|
102
|
+
title="Games"
|
|
103
|
+
:options="objectOptions"
|
|
104
|
+
/>
|
|
105
|
+
</template>
|
|
106
|
+
<template #controls="{ state }">
|
|
107
|
+
<HstSelect
|
|
108
|
+
v-model="state.select"
|
|
109
|
+
title="Games"
|
|
110
|
+
:options="objectOptions"
|
|
111
|
+
/>
|
|
112
|
+
</template>
|
|
113
|
+
</Variant>
|
|
114
|
+
|
|
89
115
|
<Variant
|
|
90
116
|
title="options-as-array-of-strings"
|
|
91
117
|
:init-state="initState"
|
|
@@ -2,39 +2,24 @@
|
|
|
2
2
|
export default {
|
|
3
3
|
name: 'HstSelect',
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
export type { SelectOption as HstSelectOption } from './CustomSelect.vue'
|
|
5
7
|
</script>
|
|
6
8
|
|
|
7
9
|
<script lang="ts" setup>
|
|
8
|
-
import { ref
|
|
10
|
+
import { ref } from 'vue'
|
|
9
11
|
import HstWrapper from '../HstWrapper.vue'
|
|
12
|
+
import CustomSelect, { SelectOption } from './CustomSelect.vue'
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const props = defineProps({
|
|
17
|
-
title: {
|
|
18
|
-
type: String,
|
|
19
|
-
default: '',
|
|
20
|
-
},
|
|
21
|
-
modelValue: {
|
|
22
|
-
type: String,
|
|
23
|
-
default: null,
|
|
24
|
-
},
|
|
25
|
-
options: {
|
|
26
|
-
type: Array as PropType<HstSelectOptions[] | string[]>,
|
|
27
|
-
required: true,
|
|
28
|
-
default: () => [],
|
|
29
|
-
},
|
|
30
|
-
})
|
|
14
|
+
const props = defineProps<{
|
|
15
|
+
title?: string
|
|
16
|
+
modelValue: string
|
|
17
|
+
options: Record<string, string> | string[] | SelectOption[]
|
|
18
|
+
}>()
|
|
31
19
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const emit = defineEmits({
|
|
36
|
-
'update:modelValue': (newValue: string) => true,
|
|
37
|
-
})
|
|
20
|
+
const emits = defineEmits<{
|
|
21
|
+
(e: 'update:modelValue', value: string): void
|
|
22
|
+
}>()
|
|
38
23
|
|
|
39
24
|
const select = ref<HTMLInputElement>()
|
|
40
25
|
</script>
|
|
@@ -45,23 +30,15 @@ const select = ref<HTMLInputElement>()
|
|
|
45
30
|
class="htw-cursor-text htw-items-center"
|
|
46
31
|
:class="$attrs.class"
|
|
47
32
|
:style="$attrs.style"
|
|
48
|
-
@click="select.focus()"
|
|
49
33
|
>
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
:value="modelValue"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
:key="label"
|
|
60
|
-
class="dark:htw-bg-gray-600"
|
|
61
|
-
:value="value"
|
|
62
|
-
>
|
|
63
|
-
{{ label }}
|
|
64
|
-
</option>
|
|
65
|
-
</select>
|
|
34
|
+
<CustomSelect
|
|
35
|
+
:options="options"
|
|
36
|
+
:model-value="modelValue"
|
|
37
|
+
@update:model-value="emits('update:modelValue', $event)"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<template #actions>
|
|
41
|
+
<slot name="actions" />
|
|
42
|
+
</template>
|
|
66
43
|
</HstWrapper>
|
|
67
44
|
</template>
|
|
@@ -36,5 +36,9 @@ const input = ref<HTMLInputElement>()
|
|
|
36
36
|
class="htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm"
|
|
37
37
|
@input="emit('update:modelValue', ($event.target as HTMLInputElement).value)"
|
|
38
38
|
>
|
|
39
|
+
|
|
40
|
+
<template #actions>
|
|
41
|
+
<slot name="actions" />
|
|
42
|
+
</template>
|
|
39
43
|
</HstWrapper>
|
|
40
44
|
</template>
|
|
@@ -36,5 +36,9 @@ const input = ref<HTMLInputElement>()
|
|
|
36
36
|
class="htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm htw-box-border htw-resize-y htw-min-h-[26px]"
|
|
37
37
|
@input="emit('update:modelValue', ($event.target as HTMLInputElement).value)"
|
|
38
38
|
/>
|
|
39
|
+
|
|
40
|
+
<template #actions>
|
|
41
|
+
<slot name="actions" />
|
|
42
|
+
</template>
|
|
39
43
|
</HstWrapper>
|
|
40
44
|
</template>
|