Repository navigation
Expand file tree
/
Copy pathdataGuide.ts
More file actions
220 lines (213 loc) · 5.86 KB
/
Copy pathdataGuide.ts
File metadata and controls
220 lines (213 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import type {
ComponentVariant,
ComponentVariantMode,
} from '@purestack/ts-components'
import {
getThemePaletteVar,
SEMANTIC_TONES,
type SemanticTone,
} from '@purestack/ts-style'
import {
defineComponent,
html,
type Ref,
type RefOrValue,
ref,
unref,
} from 'regor'
const variants: ComponentVariant[] = [
'solid',
'surface',
'surfaceAlt',
'spotlight',
'glass',
'flat',
'flatAlt',
'flatSolid',
'outlineFill',
'outline',
'subtle',
'subtleBtn',
'link',
'sheen',
'underline',
'rail',
'bracket',
'none',
]
export interface ChartAppearanceState {
chartTone: Ref<SemanticTone>
chartVariant: Ref<ComponentVariant>
chartVariantMode: Ref<ComponentVariantMode>
chartWidth: Ref<number | string>
resetAppearance: () => void
}
export function createChartAppearanceState(): ChartAppearanceState {
const tone = ref<SemanticTone>('neutral')
const variant = ref<ComponentVariant>('none')
const variantMode = ref<ComponentVariantMode>('stateless')
const width = ref<number | string>('')
return {
chartTone: tone,
chartVariant: variant,
chartVariantMode: variantMode,
chartWidth: width,
resetAppearance: () => {
tone('neutral')
variant('none')
variantMode('stateless')
width('')
},
}
}
export interface ChartAppearanceControls {
tone: Ref<SemanticTone>
variant: Ref<ComponentVariant>
variantMode: Ref<ComponentVariantMode>
width: Ref<number | string>
showWidth?: RefOrValue<boolean>
prefix: RefOrValue<string>
}
export function defineChartAppearanceControls() {
return defineComponent<ChartAppearanceControls>(
html`<Grid columns="1" columnsMd="3">
<FormSelectField
:id="prefix + '-tone'"
label="Chart tone"
:model="tone"
:options="tones"/>
<FormSelectField
:id="prefix + '-variant'"
label="Chart variant"
:model="variant"
:options="variants"/>
<FormSelectField
:id="prefix + '-mode'"
label="Variant mode"
:model="variantMode"
:options="modes"/>
<FormInputField
r-if="showWidth"
:id="prefix + '-width'"
label="SVG width (px; blank is responsive)"
type="number"
min="240"
:model="width"/>
</Grid>`,
{
props: ['tone', 'variant', 'variantMode', 'width', 'showWidth', 'prefix'],
context: (head) => ({
...head.props,
tones: SEMANTIC_TONES.map((value) => ({ label: value, value })),
variants: variants.map((value) => ({ label: value, value })),
modes: [
{ label: 'Stateless · resting appearance', value: 'stateless' },
{ label: 'Stateful · hover and active', value: 'stateful' },
],
}),
},
)
}
export interface ChartAppearanceGallery {
component: RefOrValue<string>
axis: RefOrValue<'tone' | 'variant' | 'mode'>
}
export function defineChartAppearanceGallery() {
return defineComponent<ChartAppearanceGallery>(
html`<div class="component-appearance-grid data-chart-gallery">
<div class="component-appearance-cell" r-for="sample in samples">
<code>{{ sample.label }}</code>
<BarChart
r-if="component === 'BarChart'"
:items="sample.items"
:tone="sample.tone"
:variant="sample.variant"
:variantMode="sample.mode"
width="100%"
height="160"
:animated="false"
:ariaLabel="sample.label + ': Monday 24, Tuesday 38, Wednesday -12'"/>
<LineChart
r-if="component === 'LineChart'"
:series="sample.series"
:tone="sample.tone"
:variant="sample.variant"
:variantMode="sample.mode"
width="100%"
height="160"
:showArea="true"
:showPoints="true"
:animated="false"
:ariaLabel="sample.label + ': requests 18, 32, 25, 48'"/>
<DoughnutChart
r-if="component === 'DoughnutChart'"
:segments="sample.segments"
:tone="sample.tone"
:variant="sample.variant"
:variantMode="sample.mode"
size="160"
centerLabel="Tasks"
centerValue="30"
:animated="false"
:ariaLabel="sample.label + ': complete 18, review 7, planned 5'"/>
</div>
</div>`,
{
props: ['component', 'axis'],
context: (head) => {
const axis = unref(head.props.axis)
const values =
axis === 'tone'
? SEMANTIC_TONES
: axis === 'variant'
? variants
: ['stateless', 'stateful']
return {
...head.props,
samples: values.map((label) => {
const tone = axis === 'tone' ? label : 'accent'
const variant =
axis === 'variant'
? label
: axis === 'mode'
? 'outlineFill'
: 'surface'
const color = getThemePaletteVar(
['solid', 'flatSolid'].includes(variant)
? `semanticTone.${tone}.button.rest.text`
: ['neutral', 'ghost'].includes(tone)
? `semanticTone.${tone}.text.default`
: `semanticTone.${tone}.button.rest.bgcolor`,
)
return {
label,
tone,
variant,
mode: axis === 'mode' ? label : 'stateless',
items: [
{ label: 'Mon', value: 24, color },
{ label: 'Tue', value: 38, color },
{ label: 'Wed', value: -12, color },
],
series: [
{
label: 'Requests',
color,
points: [18, 32, 25, 48].map((value, index) => ({
label: ['Mon', 'Tue', 'Wed', 'Thu'][index],
value,
})),
},
],
segments: [
{ label: 'Complete', value: 18, color },
{ label: 'Review', value: 7 },
{ label: 'Planned', value: 5 },
],
}
}),
}
},
},
)
}