-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Simplify CustomCSS UI #49721
Merged
Merged
Simplify CustomCSS UI #49721
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
packages/block-editor/src/components/global-styles/advanced-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
TextareaControl, | ||
Tooltip, | ||
__experimentalVStack as VStack, | ||
} from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Icon, info } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { default as transformStyles } from '../../utils/transform-styles'; | ||
|
||
export default function AdvancedPanel( { | ||
value, | ||
onChange, | ||
inheritedValue = value, | ||
} ) { | ||
// Custom CSS | ||
const [ cssError, setCSSError ] = useState( null ); | ||
const customCSS = inheritedValue?.css; | ||
function handleOnChange( newValue ) { | ||
onChange( { | ||
...value, | ||
css: newValue, | ||
} ); | ||
if ( cssError ) { | ||
const [ transformed ] = transformStyles( | ||
[ { css: value } ], | ||
'.editor-styles-wrapper' | ||
); | ||
if ( transformed ) { | ||
setCSSError( null ); | ||
} | ||
} | ||
} | ||
function handleOnBlur( event ) { | ||
if ( ! event?.target?.value ) { | ||
setCSSError( null ); | ||
return; | ||
} | ||
|
||
const [ transformed ] = transformStyles( | ||
[ { css: event.target.value } ], | ||
'.editor-styles-wrapper' | ||
); | ||
|
||
setCSSError( | ||
transformed === null | ||
? __( 'There is an error with your CSS structure.' ) | ||
: null | ||
); | ||
} | ||
|
||
return ( | ||
<VStack spacing={ 3 }> | ||
<TextareaControl | ||
label={ __( 'Additional CSS' ) } | ||
__nextHasNoMarginBottom | ||
value={ customCSS } | ||
onChange={ ( newValue ) => handleOnChange( newValue ) } | ||
onBlur={ handleOnBlur } | ||
className="block-editor-global-styles-advanced-panel__custom-css-input" | ||
spellCheck={ false } | ||
/> | ||
{ cssError && ( | ||
<Tooltip text={ cssError }> | ||
<div className="block-editor-global-styles-advanced-panel__custom-css-validation-wrapper"> | ||
<Icon | ||
icon={ info } | ||
className="block-editor-global-styles-advanced-panel__custom-css-validation-icon" | ||
/> | ||
</div> | ||
</Tooltip> | ||
) } | ||
</VStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 16 additions & 115 deletions
131
packages/edit-site/src/components/global-styles/custom-css.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the intention that this component will be expanded with more functionality later? Otherwise it would be clearer to call it something like "CustomCSSPanel".
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.
The idea is the component is equivalent to the "Advanced" section of the block inspector panel. It can contain things like custom class, anchor, ... and any "common" advanced setting.
The issue here is kind of similar to the "filters" panel where we only have duotone and the "effects" panel where we only have "box shadow" so far.
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.
Got it. So this panel would replace the block inspector Advanced section, once it's expanded to handle custom classes etc.?
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.
That's my hope but I'm not entirely sure. Visually at least, it helps creates a relation between the two panels (local and global ones)
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.
I'm not sure I understand. Visually the custom CSS panel in this branch looks the same as in trunk; they both use similar fonts and spacing as the block inspector panels.
Is the idea to potentially add custom CSS to the block inspector so it can be set on individual blocks? Right now the logic in this AdvancedPanel is pretty specific to custom CSS.
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.
My logic is the following. Within "inspector controls" we have "panels" and each panel has "controls".
Does that make sense?
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.
If that's the case then it makes sense to have this here. Though if we ever add more global styles controls here, it might be better to change the name of the site editor component from
CustomCSSControl
to something more generic too.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.
I actually agree with this, It should be AdvancedPanel too there too. It's just that I got confused, I thought you were discussing the ones in the block editor package. I'll make the update.
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.
Ok, so I just took a look again. I think the issue right now with the naming is that we access the panel by clicking "Additional CSS" button and going into an "Custom CSS screen" which contains this component.
So if I update
CustomCSSControl
toAdvancedPanel
, I'll be just moving the issue to another place because the CustomCSSScreen will include AdvancedPanel. (so same issue).I think this is just a temporary issue though that will be solved when we unify the whole block sidebar in #49428 since we'll just be rendering all the panels inline exactly like the block inspector. So I think we shouldn't be doing anything here for now until the other PR.
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.
That makes sense! Another thing that would be good to look at in a follow up would be adding a "reset" button that wipes any user-added CSS and restores the theme CSS if there is any.