1
1
import { useTheme } from '../providers/ThemeContext'
2
- import { get , range } from 'lodash-es'
2
+ import { get , range , sample } from 'lodash-es'
3
3
import { ThemeNamedValue , ThemeValue } from '../../types/css'
4
4
import { SelectInput } from '../inputs/SelectInput'
5
5
import { DataTypeSchema } from './types'
6
6
import { joinPath } from '../providers/util'
7
+ import { randomInt } from '../../lib/random'
7
8
8
9
export function themeScale ( path : string ) : DataTypeSchema < ThemeValue > {
9
10
return {
@@ -19,6 +20,13 @@ export function themeScale(path: string): DataTypeSchema<ThemeValue> {
19
20
stringify ( value , theme ) {
20
21
return get ( theme , joinPath ( value . path , value . index ) )
21
22
} ,
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
+ } ,
22
30
inlineInput ( props ) {
23
31
const theme = useTheme ( )
24
32
const numOptions = get ( theme , path ) ?. length || 0
@@ -64,6 +72,15 @@ export function themeRecord(path: string): DataTypeSchema<ThemeNamedValue> {
64
72
stringify ( value , theme ) {
65
73
return get ( theme , `${ value . path } .${ value . key } ` )
66
74
} ,
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
+ } ,
67
84
inlineInput ( props ) {
68
85
const theme = useTheme ( )
69
86
const options = Object . keys ( get ( theme , path ) )
0 commit comments