@poveste/controls 0.6.1 → 0.8.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/package.json +16 -3
- package/postcss.config.cjs +0 -7
- package/src/components/HstCopyIcon.story.vue +0 -26
- package/src/components/HstCopyIcon.vue +0 -38
- package/src/components/HstWrapper.vue +0 -41
- package/src/components/button/HstButton.story.vue +0 -30
- package/src/components/button/HstButton.vue +0 -26
- package/src/components/button/HstButtonGroup.story.vue +0 -79
- package/src/components/button/HstButtonGroup.vue +0 -71
- package/src/components/checkbox/HstCheckbox.spec.ts +0 -28
- package/src/components/checkbox/HstCheckbox.story.vue +0 -47
- package/src/components/checkbox/HstCheckbox.vue +0 -56
- package/src/components/checkbox/HstCheckboxList.story.vue +0 -49
- package/src/components/checkbox/HstCheckboxList.vue +0 -82
- package/src/components/checkbox/HstSimpleCheckbox.story.vue +0 -28
- package/src/components/checkbox/HstSimpleCheckbox.vue +0 -82
- package/src/components/checkbox/__snapshots__/HstCheckbox.spec.ts.snap +0 -5
- package/src/components/colorselect/HstColorSelect.story.vue +0 -28
- package/src/components/colorselect/HstColorSelect.vue +0 -89
- package/src/components/design-tokens/HstColorShades.story.vue +0 -392
- package/src/components/design-tokens/HstColorShades.vue +0 -101
- package/src/components/design-tokens/HstTokenGrid.story.vue +0 -36
- package/src/components/design-tokens/HstTokenGrid.vue +0 -88
- package/src/components/design-tokens/HstTokenList.story.vue +0 -81
- package/src/components/design-tokens/HstTokenList.vue +0 -62
- package/src/components/json/HstJson.story.vue +0 -41
- package/src/components/json/HstJson.vue +0 -167
- package/src/components/json/serialize.spec.ts +0 -85
- package/src/components/json/serialize.ts +0 -54
- package/src/components/number/HstNumber.story.vue +0 -42
- package/src/components/number/HstNumber.vue +0 -95
- package/src/components/radio/HstRadio.story.vue +0 -51
- package/src/components/radio/HstRadio.vue +0 -109
- package/src/components/select/CustomSelect.vue +0 -126
- package/src/components/select/HstSelect.story.vue +0 -161
- package/src/components/select/HstSelect.vue +0 -40
- package/src/components/slider/HstSlider.story.vue +0 -37
- package/src/components/slider/HstSlider.vue +0 -106
- package/src/components/text/HstText.story.vue +0 -63
- package/src/components/text/HstText.vue +0 -44
- package/src/components/textarea/HstTextarea.story.vue +0 -35
- package/src/components/textarea/HstTextarea.vue +0 -44
- package/src/end.d.ts +0 -8
- package/src/index.ts +0 -54
- package/src/style/main.css +0 -65
- package/src/types.ts +0 -4
- package/src/utils.ts +0 -12
- package/tsconfig.json +0 -53
- package/vite.config.ts +0 -46
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poveste/controls",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Prebuilt controls components",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"homepage": "https://poveste.dev",
|
|
10
11
|
"repository": {
|
|
11
12
|
"url": "https://github.com/poveste-dev/poveste.git",
|
|
12
13
|
"type": "git",
|
|
13
14
|
"directory": "packages/poveste-controls"
|
|
14
15
|
},
|
|
16
|
+
"bugs": "https://github.com/poveste-dev/poveste/issues",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"poveste",
|
|
19
|
+
"controls",
|
|
20
|
+
"props"
|
|
21
|
+
],
|
|
15
22
|
"publishConfig": {
|
|
16
23
|
"access": "public"
|
|
17
24
|
},
|
|
@@ -30,6 +37,12 @@
|
|
|
30
37
|
"main": "./dist/index.es.js",
|
|
31
38
|
"module": "./dist/index.es.js",
|
|
32
39
|
"types": "./dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
45
|
+
},
|
|
33
46
|
"dependencies": {
|
|
34
47
|
"@codemirror/commands": "^6.7.1",
|
|
35
48
|
"@codemirror/lang-json": "^6.0.1",
|
|
@@ -38,8 +51,8 @@
|
|
|
38
51
|
"@codemirror/state": "^6.4.1",
|
|
39
52
|
"@codemirror/theme-one-dark": "^6.1.2",
|
|
40
53
|
"@codemirror/view": "^6.35.0",
|
|
41
|
-
"@poveste/shared": "^0.
|
|
42
|
-
"@poveste/vendors": "^0.
|
|
54
|
+
"@poveste/shared": "^0.8.0",
|
|
55
|
+
"@poveste/vendors": "^0.8.0"
|
|
43
56
|
},
|
|
44
57
|
"devDependencies": {
|
|
45
58
|
"@tailwindcss/cli": "^4.3.3",
|
package/postcss.config.cjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import HstCopyIcon from './HstCopyIcon.vue'
|
|
3
|
-
|
|
4
|
-
function initState() {
|
|
5
|
-
return {
|
|
6
|
-
content: 'Text fo copy',
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<Story
|
|
13
|
-
title="internals/HstCopyIcon"
|
|
14
|
-
>
|
|
15
|
-
<Variant
|
|
16
|
-
title="default"
|
|
17
|
-
:init-state="initState"
|
|
18
|
-
>
|
|
19
|
-
<template #default="{ state }">
|
|
20
|
-
<HstCopyIcon
|
|
21
|
-
:content="state.content"
|
|
22
|
-
/>
|
|
23
|
-
</template>
|
|
24
|
-
</Variant>
|
|
25
|
-
</Story>
|
|
26
|
-
</template>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstCopyIcon',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import type { Awaitable } from '@poveste/shared'
|
|
9
|
-
import { Icon } from '@iconify/vue'
|
|
10
|
-
import { useClipboard } from '@vueuse/core'
|
|
11
|
-
import { VTooltip as vTooltip } from 'floating-vue'
|
|
12
|
-
|
|
13
|
-
const props = defineProps<{
|
|
14
|
-
content: string | (() => Awaitable<string>)
|
|
15
|
-
}>()
|
|
16
|
-
|
|
17
|
-
const { copy, copied } = useClipboard()
|
|
18
|
-
|
|
19
|
-
async function action() {
|
|
20
|
-
const content = typeof props.content === 'function' ? await props.content() : props.content
|
|
21
|
-
copy(content)
|
|
22
|
-
}
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<template>
|
|
26
|
-
<Icon
|
|
27
|
-
v-tooltip="{
|
|
28
|
-
content: 'Copied!',
|
|
29
|
-
triggers: [],
|
|
30
|
-
shown: copied,
|
|
31
|
-
distance: 12,
|
|
32
|
-
delay: 0,
|
|
33
|
-
}"
|
|
34
|
-
icon="carbon:copy-file"
|
|
35
|
-
class="w-4 h-4 opacity-50 hover:opacity-100 hover:text-primary-500 cursor-pointer"
|
|
36
|
-
@click="action()"
|
|
37
|
-
/>
|
|
38
|
-
</template>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstWrapper',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import { VTooltip as vTooltip } from 'floating-vue'
|
|
9
|
-
|
|
10
|
-
withDefaults(defineProps<{
|
|
11
|
-
title?: string
|
|
12
|
-
tag?: string
|
|
13
|
-
}>(), {
|
|
14
|
-
title: undefined,
|
|
15
|
-
tag: 'label',
|
|
16
|
-
})
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<template>
|
|
20
|
-
<component
|
|
21
|
-
:is="tag"
|
|
22
|
-
class="poveste-wrapper histoire-wrapper p-2 hover:bg-primary-100 dark:hover:bg-primary-800 flex gap-2 flex-wrap"
|
|
23
|
-
>
|
|
24
|
-
<span
|
|
25
|
-
v-tooltip="{
|
|
26
|
-
content: title,
|
|
27
|
-
placement: 'left',
|
|
28
|
-
distance: 12,
|
|
29
|
-
}"
|
|
30
|
-
class="w-28 whitespace-nowrap text-ellipsis overflow-hidden shrink-0"
|
|
31
|
-
>
|
|
32
|
-
{{ title }}
|
|
33
|
-
</span>
|
|
34
|
-
<span class="grow max-w-full flex items-center gap-1">
|
|
35
|
-
<span class="block grow max-w-full">
|
|
36
|
-
<slot />
|
|
37
|
-
</span>
|
|
38
|
-
<slot name="actions" />
|
|
39
|
-
</span>
|
|
40
|
-
</component>
|
|
41
|
-
</template>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import HstButton from './HstButton.vue'
|
|
3
|
-
|
|
4
|
-
const variants: Array<{ name: string, bind?: unknown }> = [
|
|
5
|
-
{ name: 'Default' },
|
|
6
|
-
{ name: 'Primary', bind: { color: 'primary' } },
|
|
7
|
-
{ name: 'Flat', bind: { color: 'flat' } },
|
|
8
|
-
]
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<Story
|
|
13
|
-
title="HstButton"
|
|
14
|
-
group="controls"
|
|
15
|
-
:layout="{ type: 'grid', width: '200px', iframe: false }"
|
|
16
|
-
>
|
|
17
|
-
<Variant
|
|
18
|
-
v-for="(variant, key) of variants"
|
|
19
|
-
:key="key"
|
|
20
|
-
:title="variant.name"
|
|
21
|
-
>
|
|
22
|
-
<HstButton
|
|
23
|
-
v-bind="variant.bind as {}"
|
|
24
|
-
class="p-2"
|
|
25
|
-
>
|
|
26
|
-
Click me!
|
|
27
|
-
</HstButton>
|
|
28
|
-
</Variant>
|
|
29
|
-
</Story>
|
|
30
|
-
</template>
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstButton',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script setup lang="ts">
|
|
8
|
-
defineProps<{
|
|
9
|
-
color?: keyof typeof colors
|
|
10
|
-
}>()
|
|
11
|
-
|
|
12
|
-
const colors = {
|
|
13
|
-
default: 'bg-gray-200 dark:bg-gray-750 text-gray-900 dark:text-gray-100 hover:bg-primary-200 dark:hover:bg-primary-900',
|
|
14
|
-
primary: 'bg-primary-500 hover:bg-primary-600 text-white dark:text-black',
|
|
15
|
-
flat: 'bg-transparent hover:bg-gray-500/20 text-gray-900 dark:text-gray-100',
|
|
16
|
-
}
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<template>
|
|
20
|
-
<button
|
|
21
|
-
class="poveste-button cursor-pointer rounded-sm border-none"
|
|
22
|
-
:class="colors[color ?? 'default']"
|
|
23
|
-
>
|
|
24
|
-
<slot />
|
|
25
|
-
</button>
|
|
26
|
-
</template>
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { ref } from 'vue'
|
|
3
|
-
import HstButtonGroup from './HstButtonGroup.vue'
|
|
4
|
-
|
|
5
|
-
const options = {
|
|
6
|
-
slow: 'Slow',
|
|
7
|
-
fast: 'Fast',
|
|
8
|
-
max: 'Max',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const flatOptions = Object.keys(options)
|
|
12
|
-
|
|
13
|
-
const objectOptions = Object.keys(options).map(key => ({
|
|
14
|
-
label: options[key],
|
|
15
|
-
value: key,
|
|
16
|
-
}))
|
|
17
|
-
|
|
18
|
-
function initState() {
|
|
19
|
-
return {
|
|
20
|
-
speed: flatOptions[0],
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const count = ref('0')
|
|
25
|
-
</script>
|
|
26
|
-
|
|
27
|
-
<template>
|
|
28
|
-
<Story
|
|
29
|
-
title="HstButtonGroup"
|
|
30
|
-
group="controls"
|
|
31
|
-
:layout="{ type: 'single', iframe: false }"
|
|
32
|
-
>
|
|
33
|
-
<Variant
|
|
34
|
-
title="playground"
|
|
35
|
-
:init-state="initState"
|
|
36
|
-
>
|
|
37
|
-
<template #default="{ state }">
|
|
38
|
-
<pre>{{ { speed: state.speed } }}</pre>
|
|
39
|
-
<HstButtonGroup
|
|
40
|
-
v-model="state.speed"
|
|
41
|
-
title="Label"
|
|
42
|
-
:options="objectOptions"
|
|
43
|
-
/>
|
|
44
|
-
</template>
|
|
45
|
-
|
|
46
|
-
<template #controls="{ state }">
|
|
47
|
-
<HstButtonGroup
|
|
48
|
-
v-model="state.speed"
|
|
49
|
-
title="Label"
|
|
50
|
-
:options="objectOptions"
|
|
51
|
-
/>
|
|
52
|
-
</template>
|
|
53
|
-
</Variant>
|
|
54
|
-
|
|
55
|
-
<Variant
|
|
56
|
-
title="Object options"
|
|
57
|
-
:init-state="initState"
|
|
58
|
-
>
|
|
59
|
-
<template #default="{ state }">
|
|
60
|
-
<pre>{{ { speed: state.speed } }}</pre>
|
|
61
|
-
<HstButtonGroup
|
|
62
|
-
v-model="state.speed"
|
|
63
|
-
title="Label"
|
|
64
|
-
:options="options"
|
|
65
|
-
/>
|
|
66
|
-
</template>
|
|
67
|
-
</Variant>
|
|
68
|
-
|
|
69
|
-
<Variant
|
|
70
|
-
title="Should retain order"
|
|
71
|
-
>
|
|
72
|
-
<pre>{{ { count } }}</pre>
|
|
73
|
-
<HstButtonGroup
|
|
74
|
-
v-model="count"
|
|
75
|
-
:options="[{ label: 'Low', value: '-25' }, { label: 'Regular', value: '0' }, { label: 'High', value: '200' }]"
|
|
76
|
-
/>
|
|
77
|
-
</Variant>
|
|
78
|
-
</Story>
|
|
79
|
-
</template>
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstButtonGroup',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script setup lang="ts">
|
|
8
|
-
import type { ComputedRef } from 'vue'
|
|
9
|
-
import type { HstControlOption } from '../../types'
|
|
10
|
-
import { computed } from 'vue'
|
|
11
|
-
import HstWrapper from '../HstWrapper.vue'
|
|
12
|
-
import HstButton from './HstButton.vue'
|
|
13
|
-
|
|
14
|
-
const props = defineProps<{
|
|
15
|
-
title?: string
|
|
16
|
-
modelValue?: string
|
|
17
|
-
options: string[] | number[] | HstControlOption[] | Record<string, string | number>
|
|
18
|
-
}>()
|
|
19
|
-
|
|
20
|
-
const emit = defineEmits<{
|
|
21
|
-
(e: 'update:modelValue', value: string): void
|
|
22
|
-
}>()
|
|
23
|
-
|
|
24
|
-
const formattedOptions: ComputedRef<HstControlOption[]> = computed(() => {
|
|
25
|
-
if (Array.isArray(props.options)) {
|
|
26
|
-
return props.options.map((value: string | number | HstControlOption) => {
|
|
27
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
28
|
-
return { value, label: String(value) }
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return value
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return Object.keys(props.options).map((value: string) => ({
|
|
37
|
-
value,
|
|
38
|
-
label: props.options[value],
|
|
39
|
-
}))
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
function selectOption(value: string) {
|
|
44
|
-
emit('update:modelValue', value)
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<template>
|
|
49
|
-
<HstWrapper
|
|
50
|
-
tag="div"
|
|
51
|
-
role="group"
|
|
52
|
-
:title="title"
|
|
53
|
-
class="poveste-button-group flex-nowrap items-center"
|
|
54
|
-
>
|
|
55
|
-
<div class="flex gap-px border border-solid border-black/25 dark:border-white/25 rounded-sm p-px">
|
|
56
|
-
<HstButton
|
|
57
|
-
v-for="{ label, value } of formattedOptions"
|
|
58
|
-
:key="value"
|
|
59
|
-
class="px-1 h-[22px] flex-1 rounded-[3px]!"
|
|
60
|
-
:color="value === modelValue ? 'primary' : 'flat'"
|
|
61
|
-
:rounded="false"
|
|
62
|
-
@click="selectOption(value)"
|
|
63
|
-
>
|
|
64
|
-
{{ label }}
|
|
65
|
-
</HstButton>
|
|
66
|
-
</div>
|
|
67
|
-
<template #actions>
|
|
68
|
-
<slot name="actions" />
|
|
69
|
-
</template>
|
|
70
|
-
</HstWrapper>
|
|
71
|
-
</template>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { mount } from '@vue/test-utils'
|
|
2
|
-
import HstCheckbox from './HstCheckbox.vue'
|
|
3
|
-
|
|
4
|
-
describe('hstCheckbox', () => {
|
|
5
|
-
it('toggle to checked', async () => {
|
|
6
|
-
const wrapper = mount(HstCheckbox, {
|
|
7
|
-
props: {
|
|
8
|
-
modelValue: false,
|
|
9
|
-
title: 'Label',
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
await wrapper.trigger('click')
|
|
13
|
-
expect(wrapper.emitted('update:modelValue')[0]).toEqual([true])
|
|
14
|
-
expect(wrapper.html()).toMatchSnapshot()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('toggle to unchecked', async () => {
|
|
18
|
-
const wrapper = mount(HstCheckbox, {
|
|
19
|
-
props: {
|
|
20
|
-
modelValue: true,
|
|
21
|
-
title: 'Label',
|
|
22
|
-
},
|
|
23
|
-
})
|
|
24
|
-
await wrapper.trigger('click')
|
|
25
|
-
expect(wrapper.emitted('update:modelValue')[0]).toEqual([false])
|
|
26
|
-
expect(wrapper.html()).toMatchSnapshot()
|
|
27
|
-
})
|
|
28
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import HstCheckbox from './HstCheckbox.vue'
|
|
3
|
-
|
|
4
|
-
function initState() {
|
|
5
|
-
return {
|
|
6
|
-
booleanChecked: false,
|
|
7
|
-
stringChecked: 'false',
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
</script>
|
|
11
|
-
|
|
12
|
-
<template>
|
|
13
|
-
<Story
|
|
14
|
-
title="HstCheckbox"
|
|
15
|
-
group="controls"
|
|
16
|
-
:layout="{ type: 'single', iframe: false }"
|
|
17
|
-
>
|
|
18
|
-
<Variant
|
|
19
|
-
title="playground"
|
|
20
|
-
:init-state="initState"
|
|
21
|
-
>
|
|
22
|
-
<template #default="{ state }">
|
|
23
|
-
<HstCheckbox
|
|
24
|
-
v-model="state.booleanChecked"
|
|
25
|
-
title="Boolean"
|
|
26
|
-
/>
|
|
27
|
-
{{ { value: state.booleanChecked } }}
|
|
28
|
-
<HstCheckbox
|
|
29
|
-
v-model="state.stringChecked"
|
|
30
|
-
title="String"
|
|
31
|
-
/>
|
|
32
|
-
{{ { value: state.stringChecked } }}
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<template #controls="{ state }">
|
|
36
|
-
<HstCheckbox
|
|
37
|
-
v-model="state.booleanChecked"
|
|
38
|
-
title="Boolean"
|
|
39
|
-
/>
|
|
40
|
-
<HstCheckbox
|
|
41
|
-
v-model="state.stringChecked"
|
|
42
|
-
title="String"
|
|
43
|
-
/>
|
|
44
|
-
</template>
|
|
45
|
-
</Variant>
|
|
46
|
-
</Story>
|
|
47
|
-
</template>
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstCheckbox',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import { computed } from 'vue'
|
|
9
|
-
import HstWrapper from '../HstWrapper.vue'
|
|
10
|
-
import HstSimpleCheckbox from './HstSimpleCheckbox.vue'
|
|
11
|
-
|
|
12
|
-
type Booleanish = boolean | 'true' | 'false'
|
|
13
|
-
|
|
14
|
-
const props = defineProps<{
|
|
15
|
-
modelValue?: Booleanish | null
|
|
16
|
-
title?: string
|
|
17
|
-
}>()
|
|
18
|
-
|
|
19
|
-
const emit = defineEmits({
|
|
20
|
-
'update:modelValue': (newValue: Booleanish) => true,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
function toggle() {
|
|
24
|
-
if (typeof props.modelValue === 'string') {
|
|
25
|
-
emit('update:modelValue', props.modelValue === 'false' ? 'true' : 'false')
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
emit('update:modelValue', !props.modelValue)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const isTrue = computed(() => {
|
|
33
|
-
if (typeof props.modelValue === 'string') {
|
|
34
|
-
return props.modelValue !== 'false'
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return props.modelValue
|
|
38
|
-
})
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<template>
|
|
42
|
-
<HstWrapper
|
|
43
|
-
role="checkbox"
|
|
44
|
-
tabindex="0"
|
|
45
|
-
class="poveste-checkbox cursor-pointer items-center"
|
|
46
|
-
:title="title"
|
|
47
|
-
@click="toggle()"
|
|
48
|
-
@keydown.enter.prevent="toggle()"
|
|
49
|
-
@keydown.space.prevent="toggle()"
|
|
50
|
-
>
|
|
51
|
-
<HstSimpleCheckbox :model-value="isTrue" />
|
|
52
|
-
<template #actions>
|
|
53
|
-
<slot name="actions" />
|
|
54
|
-
</template>
|
|
55
|
-
</HstWrapper>
|
|
56
|
-
</template>
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import HstCheckboxList from './HstCheckboxList.vue'
|
|
3
|
-
|
|
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 objectOptions = Object.keys(options).map(key => ({
|
|
11
|
-
label: options[key],
|
|
12
|
-
value: key,
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
function initState() {
|
|
16
|
-
return {
|
|
17
|
-
characters: [],
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
</script>
|
|
21
|
-
|
|
22
|
-
<template>
|
|
23
|
-
<Story
|
|
24
|
-
title="HstCheckboxList"
|
|
25
|
-
group="controls"
|
|
26
|
-
:layout="{ type: 'single', iframe: false }"
|
|
27
|
-
>
|
|
28
|
-
<Variant
|
|
29
|
-
title="playground"
|
|
30
|
-
:init-state="initState"
|
|
31
|
-
>
|
|
32
|
-
<template #default="{ state }">
|
|
33
|
-
<HstCheckboxList
|
|
34
|
-
v-model="state.characters"
|
|
35
|
-
title="Label"
|
|
36
|
-
:options="objectOptions"
|
|
37
|
-
/>
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
<template #controls="{ state }">
|
|
41
|
-
<HstCheckboxList
|
|
42
|
-
v-model="state.characters"
|
|
43
|
-
title="Label"
|
|
44
|
-
:options="objectOptions"
|
|
45
|
-
/>
|
|
46
|
-
</template>
|
|
47
|
-
</Variant>
|
|
48
|
-
</Story>
|
|
49
|
-
</template>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
export default {
|
|
3
|
-
name: 'HstCheckboxList',
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import type { ComputedRef } from 'vue'
|
|
9
|
-
import type { HstControlOption } from '../../types'
|
|
10
|
-
import { computed } from 'vue'
|
|
11
|
-
import HstWrapper from '../HstWrapper.vue'
|
|
12
|
-
import HstSimpleCheckbox from './HstSimpleCheckbox.vue'
|
|
13
|
-
|
|
14
|
-
const props = defineProps<{
|
|
15
|
-
title?: string
|
|
16
|
-
modelValue: Array<string>
|
|
17
|
-
options: string[] | HstControlOption[]
|
|
18
|
-
}>()
|
|
19
|
-
|
|
20
|
-
const emit = defineEmits<{
|
|
21
|
-
(e: 'update:modelValue', value: Array<string>): void
|
|
22
|
-
}>()
|
|
23
|
-
|
|
24
|
-
const formattedOptions: ComputedRef<Record<string, string>> = computed(() => {
|
|
25
|
-
if (Array.isArray(props.options)) {
|
|
26
|
-
return Object.fromEntries(props.options.map((value: string | HstControlOption) => {
|
|
27
|
-
if (typeof value === 'string') {
|
|
28
|
-
return [value, value]
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return [value.value, value.label]
|
|
32
|
-
}
|
|
33
|
-
}))
|
|
34
|
-
}
|
|
35
|
-
return props.options
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
function toggleOption(value: string) {
|
|
39
|
-
if (props.modelValue.includes(value)) {
|
|
40
|
-
emit('update:modelValue', props.modelValue.filter(element => element !== value))
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
emit('update:modelValue', [...props.modelValue, value])
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<template>
|
|
49
|
-
<HstWrapper
|
|
50
|
-
role="group"
|
|
51
|
-
:title="title"
|
|
52
|
-
class="poveste-checkbox-list cursor-text"
|
|
53
|
-
:class="$attrs.class"
|
|
54
|
-
:style="$attrs.style"
|
|
55
|
-
>
|
|
56
|
-
<div class="-my-1">
|
|
57
|
-
<template
|
|
58
|
-
v-for="(label, value) in formattedOptions"
|
|
59
|
-
:key="value"
|
|
60
|
-
>
|
|
61
|
-
<label
|
|
62
|
-
tabindex="0"
|
|
63
|
-
:for="`${value}-radio`"
|
|
64
|
-
class="cursor-pointer flex items-center relative py-1 group"
|
|
65
|
-
@keydown.enter.prevent="toggleOption(value)"
|
|
66
|
-
@keydown.space.prevent="toggleOption(value)"
|
|
67
|
-
@click="toggleOption(value)"
|
|
68
|
-
>
|
|
69
|
-
<HstSimpleCheckbox
|
|
70
|
-
:model-value="modelValue.includes(value)"
|
|
71
|
-
class="mr-2"
|
|
72
|
-
/>
|
|
73
|
-
{{ label }}
|
|
74
|
-
</label>
|
|
75
|
-
</template>
|
|
76
|
-
</div>
|
|
77
|
-
|
|
78
|
-
<template #actions>
|
|
79
|
-
<slot name="actions" />
|
|
80
|
-
</template>
|
|
81
|
-
</HstWrapper>
|
|
82
|
-
</template>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import HstSimpleCheckbox from './HstSimpleCheckbox.vue'
|
|
3
|
-
|
|
4
|
-
function initState() {
|
|
5
|
-
return {
|
|
6
|
-
checked: true,
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<Story
|
|
13
|
-
title="internals/HstSimpleCheckbox"
|
|
14
|
-
:layout="{ type: 'single', iframe: false }"
|
|
15
|
-
>
|
|
16
|
-
<Variant
|
|
17
|
-
title="playground"
|
|
18
|
-
:init-state="initState"
|
|
19
|
-
>
|
|
20
|
-
<template #default="{ state }">
|
|
21
|
-
<HstSimpleCheckbox
|
|
22
|
-
v-model="state.checked"
|
|
23
|
-
with-toggle
|
|
24
|
-
/>
|
|
25
|
-
</template>
|
|
26
|
-
</Variant>
|
|
27
|
-
</Story>
|
|
28
|
-
</template>
|