-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9091d91
commit 78052d1
Showing
3 changed files
with
99 additions
and
115 deletions.
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="edit-site-global-styles__custom-css-input" | ||
spellCheck={ false } | ||
/> | ||
{ cssError && ( | ||
<Tooltip text={ cssError }> | ||
<div className="edit-site-global-styles__custom-css-validation-wrapper"> | ||
<Icon | ||
icon={ info } | ||
className="edit-site-global-styles__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
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