Repository navigation
Responsive styles: Use viewport dropdown to control states for in-editor global styles sidebar #80339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Responsive styles: Use viewport dropdown to control states for in-editor global styles sidebar #80339
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,9 +97,16 @@ const { | |
| interface ScreenBlockProps { | ||
| name: string; | ||
| variation?: string; | ||
| selectedViewport?: string; | ||
| showResponsiveStateControls?: boolean; | ||
| } | ||
|
|
||
| function ScreenBlock( { name, variation }: ScreenBlockProps ) { | ||
| function ScreenBlock( { | ||
| name, | ||
| variation, | ||
| selectedViewport: controlledSelectedViewport, | ||
| showResponsiveStateControls = true, | ||
| }: ScreenBlockProps ) { | ||
| const { | ||
| user: userConfig, | ||
| merged: mergedConfig, | ||
|
|
@@ -113,10 +120,12 @@ function ScreenBlock( { name, variation }: ScreenBlockProps ) { | |
| const prefix = prefixParts.join( '.' ); | ||
|
|
||
| // State selector state | ||
| const [ selectedViewport, setSelectedViewport ] = | ||
| const [ localSelectedViewport, setSelectedViewport ] = | ||
| useState< string >( 'default' ); | ||
| const [ selectedPseudoState, setSelectedPseudoState ] = | ||
| useState< string >( 'default' ); | ||
| const selectedViewport = | ||
| controlledSelectedViewport ?? localSelectedViewport; | ||
| const viewportSettings = mergedConfig.settings?.viewport; | ||
| const validViewportStates = useMemo( | ||
| () => getValidViewportStates( viewportSettings ), | ||
|
|
@@ -361,8 +370,13 @@ function ScreenBlock( { name, variation }: ScreenBlockProps ) { | |
| pseudoStates={ validPseudoStates } | ||
| selectedViewport={ effectiveSelectedViewport } | ||
| selectedPseudoState={ selectedPseudoState } | ||
| onChangeViewport={ setSelectedViewport } | ||
| onChangeViewport={ | ||
| showResponsiveStateControls | ||
| ? setSelectedViewport | ||
| : undefined | ||
| } | ||
|
Comment on lines
+373
to
+377
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non blocking question: is this even required since screenheader passes an empty array to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems not, but I don't mind it. At least with this, |
||
| onChangePseudoState={ setSelectedPseudoState } | ||
| showResponsiveStateControls={ showResponsiveStateControls } | ||
| /> | ||
| <BlockPreviewPanel | ||
| name={ name } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think one day a global-style-ui context with this type of stuff would be useful to avoid prop drilling?
Just curious!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is a lot of prop drilling. A context provider could help. 👍