@histoire/controls 0.12.3 → 0.13.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.
Files changed (26) hide show
  1. package/dist/components/HstWrapper.vue.d.ts +9 -1
  2. package/dist/components/button/HstButton.vue.d.ts +11 -4
  3. package/dist/components/button/HstButtonGroup.vue.d.ts +11 -4
  4. package/dist/components/checkbox/HstCheckbox.vue.d.ts +9 -2
  5. package/dist/components/checkbox/HstCheckboxList.vue.d.ts +9 -2
  6. package/dist/components/design-tokens/HstColorShades.vue.d.ts +11 -2
  7. package/dist/components/design-tokens/HstTokenGrid.vue.d.ts +14 -1
  8. package/dist/components/design-tokens/HstTokenList.vue.d.ts +15 -2
  9. package/dist/components/json/HstJson.vue.d.ts +9 -2
  10. package/dist/components/number/HstNumber.vue.d.ts +9 -2
  11. package/dist/components/radio/HstRadio.vue.d.ts +9 -2
  12. package/dist/components/select/CustomSelect.vue.d.ts +13 -4
  13. package/dist/components/select/HstSelect.vue.d.ts +9 -2
  14. package/dist/components/text/HstText.vue.d.ts +9 -2
  15. package/dist/components/textarea/HstTextarea.vue.d.ts +9 -2
  16. package/dist/index.d.ts +2221 -337
  17. package/dist/index.es.js +3811 -1814
  18. package/package.json +7 -7
  19. package/src/components/button/HstButtonGroup.story.vue +28 -0
  20. package/src/components/button/HstButtonGroup.vue +12 -8
  21. package/src/components/checkbox/{HstCheckbox.test.ts → HstCheckbox.spec.ts} +0 -0
  22. package/src/components/checkbox/__snapshots__/{HstCheckbox.test.ts.snap → HstCheckbox.spec.ts.snap} +0 -0
  23. package/src/components/design-tokens/HstTokenList.story.vue +1 -1
  24. package/src/components/select/CustomSelect.vue +3 -3
  25. package/src/components/select/HstSelect.story.vue +24 -0
  26. package/dist/components/checkbox/HstCheckbox.test.d.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/controls",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
4
4
  "description": "Prebuilt controls components",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -38,14 +38,14 @@
38
38
  "@codemirror/state": "^6.1.2",
39
39
  "@codemirror/theme-one-dark": "^6.1.0",
40
40
  "@codemirror/view": "^6.3.0",
41
- "@histoire/vendors": "^0.12.3"
41
+ "@histoire/vendors": "^0.13.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@peeky/server": "^0.14.0",
45
45
  "@peeky/test": "^0.14.1",
46
46
  "@types/node": "^17.0.32",
47
47
  "@vitejs/plugin-vue": "^4.0.0",
48
- "@vue/test-utils": "^2.0.0-rc.19",
48
+ "@vue/test-utils": "^2.2.10",
49
49
  "@vueuse/core": "^8.2.5",
50
50
  "autoprefixer": "^10.4.4",
51
51
  "concurrently": "^7.1.0",
@@ -53,10 +53,10 @@
53
53
  "postcss": "^8.4.12",
54
54
  "postcss-import": "^14.1.0",
55
55
  "tailwindcss": "^3.0.23",
56
- "typescript": "^4.7.4",
57
- "vite": "^4.0.0",
58
- "vue": "^3.2.31",
59
- "vue-tsc": "^0.35.2"
56
+ "typescript": "^4.9.5",
57
+ "vite": "^4.1.0",
58
+ "vue": "^3.2.47",
59
+ "vue-tsc": "^1.0.24"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "rimraf dist && pnpm run build:css && vite build && pnpm run build:types",
@@ -1,4 +1,5 @@
1
1
  <script lang="ts" setup>
2
+ import { ref } from 'vue'
2
3
  import HstButtonGroup from './HstButtonGroup.vue'
3
4
 
4
5
  const options = {
@@ -19,6 +20,8 @@ function initState () {
19
20
  speed: flatOptions[0],
20
21
  }
21
22
  }
23
+
24
+ const count = ref('0')
22
25
  </script>
23
26
 
24
27
  <template>
@@ -32,6 +35,7 @@ function initState () {
32
35
  :init-state="initState"
33
36
  >
34
37
  <template #default="{ state }">
38
+ <pre>{{ { speed: state.speed } }}</pre>
35
39
  <HstButtonGroup
36
40
  v-model="state.speed"
37
41
  title="Label"
@@ -47,5 +51,29 @@ function initState () {
47
51
  />
48
52
  </template>
49
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>
50
78
  </Story>
51
79
  </template>
@@ -13,20 +13,24 @@ import HstButton from './HstButton.vue'
13
13
  const props = defineProps<{
14
14
  title?: string
15
15
  modelValue: string
16
- options: string[] | HstControlOption[]
16
+ options: string[] | number[] | HstControlOption[] | Record<string, string | number>
17
17
  }>()
18
18
 
19
- const formattedOptions: ComputedRef<Record<string, string>> = computed(() => {
19
+ const formattedOptions: ComputedRef<HstControlOption[]> = computed(() => {
20
20
  if (Array.isArray(props.options)) {
21
- return Object.fromEntries(props.options.map((value: string | HstControlOption) => {
22
- if (typeof value === 'string') {
23
- return [value, value]
21
+ return props.options.map((value: string | number | HstControlOption) => {
22
+ if (typeof value === 'string' || typeof value === 'number') {
23
+ return { value, label: String(value) }
24
24
  } else {
25
- return [value.value, value.label]
25
+ return value
26
26
  }
27
+ })
28
+ } else {
29
+ return Object.keys(props.options).map((value: string) => ({
30
+ value,
31
+ label: props.options[value],
27
32
  }))
28
33
  }
29
- return props.options
30
34
  })
31
35
 
32
36
  const emit = defineEmits<{
@@ -47,7 +51,7 @@ function selectOption (value: string) {
47
51
  >
48
52
  <div class="htw-flex htw-gap-px htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 htw-rounded-sm htw-p-px">
49
53
  <HstButton
50
- v-for="( label, value ) in formattedOptions"
54
+ v-for="{ label, value } of formattedOptions"
51
55
  :key="value"
52
56
  class="htw-px-1 htw-h-[22px] htw-flex-1 !htw-rounded-[3px]"
53
57
  :color="value === modelValue ? 'primary' : 'flat'"
@@ -69,7 +69,7 @@ const tokens = {
69
69
  <div
70
70
  class="htw-h-20 htw-bg-gray-500/50"
71
71
  :style="{
72
- width: token.value,
72
+ width: token.value as string,
73
73
  }"
74
74
  />
75
75
  </div>
@@ -12,7 +12,7 @@ import { HstControlOption } from '../../types'
12
12
 
13
13
  const props = defineProps<{
14
14
  modelValue: string
15
- options: Record<string, any> | string[] | HstControlOption[]
15
+ options: Record<string, any> | string[] | number[] | HstControlOption[]
16
16
  }>()
17
17
 
18
18
  const emits = defineEmits<{
@@ -22,8 +22,8 @@ const emits = defineEmits<{
22
22
  const formattedOptions: ComputedRef<[any, string][]> = computed(() => {
23
23
  if (Array.isArray(props.options)) {
24
24
  return props.options.map(option => {
25
- if (typeof option === 'string') {
26
- return [option, option] as [string, string]
25
+ if (typeof option === 'string' || typeof option === 'number') {
26
+ return [option, String(option)] as [any, string]
27
27
  } else {
28
28
  return [option.value, option.label] as [any, string]
29
29
  }
@@ -14,10 +14,13 @@ const objectOptions = Object.keys(options).map(key => ({
14
14
  value: key,
15
15
  }))
16
16
 
17
+ const numberOptions = [0, 1, 2, 3, 4, 5]
18
+
17
19
  function initState () {
18
20
  return {
19
21
  label: 'My really long label',
20
22
  select: 'crash-bandicoot',
23
+ count: 0,
21
24
  }
22
25
  }
23
26
  </script>
@@ -133,5 +136,26 @@ function initState () {
133
136
  />
134
137
  </template>
135
138
  </Variant>
139
+
140
+ <Variant
141
+ title="options-as-array-of-numbers"
142
+ :init-state="initState"
143
+ >
144
+ <template #default="{ state }">
145
+ <pre class="htw-text-xs htw-bg-gray-50 dark:htw-bg-gray-600 htw-rounded htw-p-4">{{ numberOptions }}</pre>
146
+ <HstSelect
147
+ v-model="state.count"
148
+ title="Select"
149
+ :options="numberOptions"
150
+ />
151
+ </template>
152
+ <template #controls="{ state }">
153
+ <HstSelect
154
+ v-model="state.count"
155
+ title="Select"
156
+ :options="numberOptions"
157
+ />
158
+ </template>
159
+ </Variant>
136
160
  </Story>
137
161
  </template>
@@ -1 +0,0 @@
1
- export {};