@histoire/controls 0.2.3 → 0.3.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.
@@ -0,0 +1,35 @@
1
+ <script lang="ts" setup>
2
+ import HstTokenGrid from './HstTokenGrid.vue'
3
+
4
+ const tokens = {
5
+ sm: 'filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.05))',
6
+ DEFAULT: 'filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1)) drop-shadow(0 1px 1px rgb(0 0 0 / 0.06))',
7
+ md: 'filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06))',
8
+ lg: 'filter: drop-shadow(0 10px 8px rgb(0 0 0 / 0.04)) drop-shadow(0 4px 3px rgb(0 0 0 / 0.1))',
9
+ xl: 'filter: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08))',
10
+ '2xl': 'filter: drop-shadow(0 25px 25px rgb(0 0 0 / 0.15))',
11
+ none: 'filter: drop-shadow(0 0 #0000)',
12
+ }
13
+ </script>
14
+
15
+ <template>
16
+ <Story
17
+ title="design-tokens/HstTokenGrid"
18
+ responsive-disabled
19
+ >
20
+ <Variant title="default">
21
+ <HstTokenGrid
22
+ :tokens="tokens"
23
+ :get-name="key => key === 'DEFAULT' ? 'drop-shadow' : `drop-shadow-${key}`"
24
+ :col-size="160"
25
+ >
26
+ <template #default="{ token }">
27
+ <div
28
+ class="htw-w-32 htw-h-32 htw-bg-white dark:htw-bg-black htw-rounded htw-mb-2"
29
+ :style="token.value"
30
+ />
31
+ </template>
32
+ </HstTokenGrid>
33
+ </Variant>
34
+ </Story>
35
+ </template>
@@ -0,0 +1,88 @@
1
+ <script lang="ts">
2
+ export default {
3
+ name: 'HstTokenGrid',
4
+ }
5
+ </script>
6
+
7
+ <script lang="ts" setup>
8
+ import { computed, ref, withDefaults } from 'vue'
9
+ import { VTooltip as vTooltip } from 'floating-vue'
10
+ import HstCopyIcon from '../HstCopyIcon.vue'
11
+
12
+ const props = withDefaults(defineProps<{
13
+ tokens: Record<string, string | number | any[] | Record<string, any>>
14
+ colSize?: number
15
+ getName?: (key: string, value: string | number | any[] | Record<string, any>) => string
16
+ }>(), {
17
+ colSize: 180,
18
+ getName: null,
19
+ })
20
+
21
+ const processedTokens = computed(() => {
22
+ const list = props.tokens
23
+ const getName = props.getName
24
+ return Object.entries(list).map(([key, value]) => {
25
+ const name = getName ? getName(key, value) : key
26
+ return {
27
+ key,
28
+ name,
29
+ value: typeof value === 'number' ? value.toString() : value,
30
+ }
31
+ })
32
+ })
33
+
34
+ const colSizePx = computed(() => `${props.colSize}px`)
35
+
36
+ const hover = ref<string>(null)
37
+ </script>
38
+
39
+ <template>
40
+ <div
41
+ class="htw-bind-col-size htw-grid htw-gap-4 htw-m-4"
42
+ :style="{
43
+ '--histoire-col-size': colSizePx,
44
+ }"
45
+ >
46
+ <div
47
+ v-for="token of processedTokens"
48
+ :key="token.key"
49
+ class="htw-flex htw-flex-col htw-gap-2"
50
+ @mouseenter="hover = token.key"
51
+ @mouseleave="hover = null"
52
+ >
53
+ <slot
54
+ :token="token"
55
+ />
56
+ <div>
57
+ <div class="htw-flex htw-gap-1">
58
+ <pre
59
+ v-tooltip="token.name.length > colSize / 8 ? token.name : ''"
60
+ class="htw-my-0 htw-truncate htw-shrink"
61
+ >{{ token.name }}</pre>
62
+ <HstCopyIcon
63
+ v-if="hover === token.key"
64
+ :content="token.name"
65
+ class="htw-flex-none"
66
+ />
67
+ </div>
68
+ <div class="htw-flex htw-gap-1">
69
+ <pre
70
+ v-tooltip="token.value.length > colSize / 8 ? token.value : ''"
71
+ class="htw-my-0 htw-opacity-50 htw-truncate htw-shrink"
72
+ >{{ token.value }}</pre>
73
+ <HstCopyIcon
74
+ v-if="hover === token.key"
75
+ :content="typeof token.value === 'string' ? token.value : JSON.stringify(token.value)"
76
+ class="htw-flex-none"
77
+ />
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </template>
83
+
84
+ <style>
85
+ .htw-bind-col-size {
86
+ grid-template-columns: repeat(auto-fill, minmax(var(--histoire-col-size), 1fr));
87
+ }
88
+ </style>
@@ -0,0 +1,79 @@
1
+ <script lang="ts" setup>
2
+ import HstTokenList from './HstTokenList.vue'
3
+
4
+ const tokens = {
5
+ 0: 0,
6
+ 1: '0.25rem',
7
+ 2: '0.5rem',
8
+ 3: '0.75rem',
9
+ 4: '1rem',
10
+ 5: '1.25rem',
11
+ 6: '1.5rem',
12
+ 8: '2rem',
13
+ 10: '2.5rem',
14
+ 12: '3rem',
15
+ 16: '4rem',
16
+ 20: '5rem',
17
+ 24: '6rem',
18
+ 32: '8rem',
19
+ 40: '10rem',
20
+ 48: '12rem',
21
+ 56: '14rem',
22
+ 64: '16rem',
23
+ auto: 'auto',
24
+ px: '1px',
25
+ screen: '100vw',
26
+ '1/2': '50%',
27
+ '1/3': '33.333333%',
28
+ '2/3': '66.666667%',
29
+ '1/4': '25%',
30
+ '2/4': '50%',
31
+ '3/4': '75%',
32
+ '1/5': '20%',
33
+ '2/5': '40%',
34
+ '3/5': '60%',
35
+ '4/5': '80%',
36
+ '1/6': '16.666667%',
37
+ '2/6': '33.333333%',
38
+ '3/6': '50%',
39
+ '4/6': '66.666667%',
40
+ '5/6': '83.333333%',
41
+ '1/12': '8.333333%',
42
+ '2/12': '16.666667%',
43
+ '3/12': '25%',
44
+ '4/12': '33.333333%',
45
+ '5/12': '41.666667%',
46
+ '6/12': '50%',
47
+ '7/12': '58.333333%',
48
+ '8/12': '66.666667%',
49
+ '9/12': '75%',
50
+ '10/12': '83.333333%',
51
+ '11/12': '91.666667%',
52
+ full: '100%',
53
+ }
54
+ </script>
55
+
56
+ <template>
57
+ <Story
58
+ title="design-tokens/HstTokenList"
59
+ responsive-disabled
60
+ >
61
+ <Variant title="default">
62
+ <HstTokenList
63
+ :tokens="tokens"
64
+ :get-name="key => `w-${key}`"
65
+ >
66
+ <template #default="{ token }">
67
+ <div class="htw-bg-gray-500/10">
68
+ <div
69
+ class="htw-h-20 htw-bg-gray-500/50"
70
+ :style="{
71
+ width: token.value,
72
+ }"
73
+ />
74
+ </div>
75
+ </template>
76
+ </HstTokenList>
77
+ </Variant>
78
+ </Story>
79
+ </template>
@@ -0,0 +1,62 @@
1
+ <script lang="ts">
2
+ export default {
3
+ name: 'HstTokenList',
4
+ }
5
+ </script>
6
+
7
+ <script lang="ts" setup>
8
+ import { computed, ref } from 'vue'
9
+ import HstCopyIcon from '../HstCopyIcon.vue'
10
+
11
+ const props = defineProps<{
12
+ tokens: Record<string, string | number | any[] | Record<string, any>>
13
+ getName?: (key: string, value: string | number | any[] | Record<string, any>) => string
14
+ }>()
15
+
16
+ const processedTokens = computed(() => {
17
+ const list = props.tokens
18
+ const getName = props.getName
19
+ return Object.entries(list).map(([key, value]) => {
20
+ const name = getName ? getName(key, value) : key
21
+ return {
22
+ key,
23
+ name,
24
+ value: typeof value === 'number' ? value.toString() : value,
25
+ }
26
+ })
27
+ })
28
+
29
+ const hover = ref<string>(null)
30
+ </script>
31
+
32
+ <template>
33
+ <div
34
+ v-for="token of processedTokens"
35
+ :key="token.key"
36
+ class="htw-flex htw-flex-col htw-gap-2 htw-my-8"
37
+ @mouseenter="hover = token.key"
38
+ @mouseleave="hover = null"
39
+ >
40
+ <slot
41
+ :token="token"
42
+ />
43
+ <div class="htw-mx-4">
44
+ <div class="htw-flex htw-gap-1">
45
+ <pre class="htw-my-0 htw-truncate htw-shrink">{{ token.name }}</pre>
46
+ <HstCopyIcon
47
+ v-if="hover === token.key"
48
+ :content="token.name"
49
+ class="htw-flex-none"
50
+ />
51
+ </div>
52
+ <div class="htw-flex htw-gap-1">
53
+ <pre class="htw-my-0 htw-opacity-50 htw-truncate htw-shrink">{{ token.value }}</pre>
54
+ <HstCopyIcon
55
+ v-if="hover === token.key"
56
+ :content="typeof token.value === 'string' ? token.value : JSON.stringify(token.value)"
57
+ class="htw-flex-none"
58
+ />
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </template>
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ import HstTextVue from './components/text/HstText.vue'
4
4
  import HstNumberVue from './components/number/HstNumber.vue'
5
5
  import HstTextareaVue from './components/textarea/HstTextarea.vue'
6
6
  import HstColorShadesVue from './components/design-tokens/HstColorShades.vue'
7
+ import HstTokenListVue from './components/design-tokens/HstTokenList.vue'
8
+ import HstTokenGridVue from './components/design-tokens/HstTokenGrid.vue'
7
9
  import HstCopyIconVue from './components/HstCopyIcon.vue'
8
10
 
9
11
  export const HstCheckbox = HstCheckboxVue
@@ -11,6 +13,8 @@ export const HstText = HstTextVue
11
13
  export const HstNumber = HstNumberVue
12
14
  export const HstTextarea = HstTextareaVue
13
15
  export const HstColorShades = HstColorShadesVue
16
+ export const HstTokenList = HstTokenListVue
17
+ export const HstTokenGrid = HstTokenGridVue
14
18
  export const HstCopyIcon = HstCopyIconVue
15
19
 
16
20
  export function registerVueComponents (app: App) {
@@ -18,4 +22,7 @@ export function registerVueComponents (app: App) {
18
22
  app.component('HstText', HstTextVue)
19
23
  app.component('HstNumber', HstNumberVue)
20
24
  app.component('HstTextarea', HstTextareaVue)
25
+ app.component('HstColorShades', HstColorShadesVue)
26
+ app.component('HstTokenList', HstTokenListVue)
27
+ app.component('HstTokenGrid', HstTokenGridVue)
21
28
  }
package/tsconfig.json CHANGED
@@ -27,6 +27,8 @@
27
27
  "alwaysStrict": true,
28
28
  "strictBindCallApply": true,
29
29
  "strictFunctionTypes": true,
30
+ // Volar
31
+ "jsx": "preserve",
30
32
  },
31
33
  "include": [
32
34
  "src"