Skip to content

Commit 810c5dd

Browse files
authored
Merge pull request #550 from components-ai/scale-select-labels
Display theme value for scales
2 parents 0c15586 + 58c2c3f commit 810c5dd

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.changeset/orange-terms-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compai/css-gui': patch
3+
---
4+
5+
Display theme value for scales

packages/gui/src/components/inputs/SelectInput.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ interface Props<T extends string> {
99
options: readonly T[]
1010
ruleset?: any
1111
property?: string
12+
decorateText?(text: T): string
1213
}
1314
// A select input with a label
14-
export function SelectInput<T extends string>(props: Props<T>) {
15+
export function SelectInput<T extends string>({
16+
decorateText,
17+
...props
18+
}: Props<T>) {
1519
const { value, onChange, options = [] } = props
1620

1721
return (
@@ -34,7 +38,9 @@ export function SelectInput<T extends string>(props: Props<T>) {
3438
return (
3539
<Select.Item key={v} value={v}>
3640
<Select.ItemIndicator />
37-
<Select.ItemText>{v}</Select.ItemText>
41+
<Select.ItemText>
42+
{decorateText ? decorateText(v) : v}
43+
</Select.ItemText>
3844
</Select.Item>
3945
)
4046
})}

packages/gui/src/components/schemas/theme.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { get, range } from 'lodash-es'
33
import { ThemeNamedValue, ThemeValue } from '../../types/css'
44
import { SelectInput } from '../inputs/SelectInput'
55
import { DataTypeSchema } from './types'
6+
import { joinPath } from '../providers/util'
67

78
export function themeScale(path: string): DataTypeSchema<ThemeValue> {
89
return {
@@ -16,11 +17,15 @@ export function themeScale(path: string): DataTypeSchema<ThemeValue> {
1617
)
1718
}) as any,
1819
stringify(value, theme) {
19-
return get(theme, `${value.path}.${value.index}`)
20+
return get(theme, joinPath(value.path, value.index))
2021
},
2122
inlineInput(props) {
2223
const theme = useTheme()
2324
const numOptions = get(theme, path)?.length || 0
25+
const decorateText = (step: string) => {
26+
const value = get(theme, joinPath(path, step))
27+
return `${step} - ${value}`
28+
}
2429
return (
2530
<SelectInput
2631
label=""
@@ -32,6 +37,7 @@ export function themeScale(path: string): DataTypeSchema<ThemeValue> {
3237
})
3338
}
3439
options={range(0, numOptions).map((x) => x.toString())}
40+
decorateText={decorateText}
3541
/>
3642
)
3743
},

0 commit comments

Comments
 (0)