Skip to content

Commit 4846b90

Browse files
authored
Merge pull request #592 from components-ai/theme-gen
Fix regen for theme values
2 parents 62953c9 + 98b7d34 commit 4846b90

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.changeset/nasty-meals-fold.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+
Fix regen for theme values

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useTheme } from '../providers/ThemeContext'
2-
import { get, range } from 'lodash-es'
2+
import { get, range, sample } from 'lodash-es'
33
import { ThemeNamedValue, ThemeValue } from '../../types/css'
44
import { SelectInput } from '../inputs/SelectInput'
55
import { DataTypeSchema } from './types'
66
import { joinPath } from '../providers/util'
7+
import { randomInt } from '../../lib/random'
78

89
export function themeScale(path: string): DataTypeSchema<ThemeValue> {
910
return {
@@ -19,6 +20,13 @@ export function themeScale(path: string): DataTypeSchema<ThemeValue> {
1920
stringify(value, theme) {
2021
return get(theme, joinPath(value.path, value.index))
2122
},
23+
regenerate(options) {
24+
const scale = get(options.theme, options.previousValue.path)
25+
return {
26+
...options.previousValue,
27+
index: randomInt(0, scale.length),
28+
}
29+
},
2230
inlineInput(props) {
2331
const theme = useTheme()
2432
const numOptions = get(theme, path)?.length || 0
@@ -64,6 +72,15 @@ export function themeRecord(path: string): DataTypeSchema<ThemeNamedValue> {
6472
stringify(value, theme) {
6573
return get(theme, `${value.path}.${value.key}`)
6674
},
75+
regenerate(options) {
76+
const records = get(options.theme, options.previousValue.path)
77+
const paths = Object.keys(records || {})
78+
79+
return {
80+
...options.previousValue,
81+
key: sample(paths) ?? '',
82+
}
83+
},
6784
inlineInput(props) {
6885
const theme = useTheme()
6986
const options = Object.keys(get(theme, path))

0 commit comments

Comments
 (0)