66 isValidElement ,
77 ReactNode ,
88 useMemo ,
9+ useState ,
910} from 'react'
1011import { camelCase , isNil , mapValues , uniq } from 'lodash-es'
1112import { RefreshCw } from 'react-feather'
@@ -37,7 +38,14 @@ import { SchemaInput } from '../inputs/SchemaInput'
3738import { EditorDropdown } from '../ui/dropdowns/EditorDropdown'
3839import { FieldsetDropdown } from '../ui/dropdowns/FieldsetDropdown'
3940import { tokenize } from '../../lib/parse'
40- import { addPseudoSyntax } from '../../lib/pseudos'
41+ import {
42+ addPseudoSyntax ,
43+ getSelectorFunctionArgument ,
44+ getSelectorFunctionName ,
45+ isSelectorFunction ,
46+ removePseudoSyntax ,
47+ stringifySelectorFunction ,
48+ } from '../../lib/pseudos'
4149
4250export const getPropertyFromField = ( field : KeyArg ) => {
4351 if ( Array . isArray ( field ) ) {
@@ -219,7 +227,7 @@ export const Editor = ({
219227 < div sx = { { ml : 'auto' , display : 'flex' } } >
220228 < IconButton
221229 onClick = { ( ) => onChange ( regenerateAll ( ) ) }
222- sx = { { ml : 'auto' , } }
230+ sx = { { ml : 'auto' } }
223231 >
224232 < RefreshCw size = { 15 } />
225233 </ IconButton >
@@ -320,10 +328,13 @@ type FieldsetControlProps = {
320328 field : string
321329}
322330const FieldsetControl = ( { field } : FieldsetControlProps ) => {
323- const { getField, removeField } = useEditor ( )
331+ const { getField, removeField, setFields } = useEditor ( )
332+ const [ argument , setArgument ] = useState ( getSelectorFunctionArgument ( field ) )
333+
324334 const styles = getField ( field )
325335 const properties = Object . keys ( styles )
326336 const label = addPseudoSyntax ( field )
337+ const rawFieldsetName = getSelectorFunctionName ( field )
327338
328339 return (
329340 < section
@@ -350,12 +361,45 @@ const FieldsetControl = ({ field }: FieldsetControlProps) => {
350361 mb : 0 ,
351362 } }
352363 >
353- { removeInternalCSSClassSyntax ( label ) }
364+ { rawFieldsetName }
365+ { isSelectorFunction ( rawFieldsetName ) ? (
366+ < >
367+ { '(' }
368+ < input
369+ value = { argument }
370+ sx = { {
371+ width : 64 ,
372+ } }
373+ onChange = { ( e ) => {
374+ setArgument ( e . target . value )
375+ } }
376+ onBlur = { ( ) => {
377+ setFields (
378+ {
379+ [ stringifySelectorFunction ( rawFieldsetName , argument ) ] :
380+ styles ,
381+ } ,
382+ [ field ]
383+ )
384+ } }
385+ />
386+ { ')' }
387+ </ >
388+ ) : null }
354389 </ h3 >
355390 < FieldsetDropdown onRemove = { ( ) => removeField ( field ) } />
356391 </ div >
357392 < GenericFieldset field = { field } >
358- < div sx = { { mb : 3 , p : 3 , borderWidth : '1px' , borderStyle : 'solid' , borderColor : 'border' , borderRadius : '6px' , } } >
393+ < div
394+ sx = { {
395+ mb : 3 ,
396+ p : 3 ,
397+ borderWidth : '1px' ,
398+ borderStyle : 'solid' ,
399+ borderColor : 'border' ,
400+ borderRadius : '6px' ,
401+ } }
402+ >
359403 < AddPropertyControl
360404 field = { field }
361405 styles = { styles }
0 commit comments