diff --git a/packages/edit-site/src/components/global-styles/screen-shadows.js b/packages/edit-site/src/components/global-styles/screen-shadows.js index 82edff6481de7b..3645787f9a77f6 100644 --- a/packages/edit-site/src/components/global-styles/screen-shadows.js +++ b/packages/edit-site/src/components/global-styles/screen-shadows.js @@ -1,35 +1,13 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; - /** * Internal dependencies */ -import ScreenHeader from './header'; import ShadowsPanel from './shadows-panel'; -import { unlock } from '../../lock-unlock'; +import ShadowsEditPanel from './shadows-edit-panel'; -const { useGlobalSetting, useSettingsForBlockElement } = - unlock( blockEditorPrivateApis ); - -function ScreenShadows() { - // const [ rawSettings ] = useGlobalSetting( '' ); - // const settings = useSettingsForBlockElement( rawSettings ); - return ( - <> - -
- -
- - ); +export function ScreenShadows() { + return ; } -export default ScreenShadows; +export function ScreenShadowsEdit() { + return ; +} diff --git a/packages/edit-site/src/components/global-styles/shadows-edit-panel.js b/packages/edit-site/src/components/global-styles/shadows-edit-panel.js new file mode 100644 index 00000000000000..780b5684f62030 --- /dev/null +++ b/packages/edit-site/src/components/global-styles/shadows-edit-panel.js @@ -0,0 +1,364 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { + __experimentalHStack as HStack, + __experimentalVStack as VStack, + __experimentalSpacer as Spacer, + __experimentalItemGroup as ItemGroup, + __experimentalHeading as Heading, + __experimentalUnitControl as UnitControl, + __experimentalGrid as Grid, + __experimentalDropdownContentWrapper as DropdownContentWrapper, + __experimentalUseNavigator as useNavigator, + Dropdown, + RangeControl, + Button, + FlexItem, + ColorPicker, +} from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; +import { + Icon, + plus, + shadow as shadowIcon, + lineSolid, + settings, +} from '@wordpress/icons'; +import { useState, useMemo } from '@wordpress/element'; +import { debounce } from '@wordpress/compose'; + +/** + * Internal dependencies + */ +import { unlock } from '../../lock-unlock'; +import Subtitle from './subtitle'; +import ScreenHeader from './header'; +import { defaultShadow } from './shadows-panel'; +import { + getShadowParts, + shadowStringToObject, + shadowObjectToString, +} from './utils'; + +const { useGlobalSetting } = unlock( blockEditorPrivateApis ); + +export default function ShadowsEditPanel() { + const { + params: { category, slug }, + } = useNavigator(); + const [ shadows, setShadows ] = useGlobalSetting( + `shadow.presets.${ category }` + ); + const selectedShadow = useMemo( + () => ( shadows || [] ).find( ( shadow ) => shadow.slug === slug ), + [ shadows, slug ] + ); + const onShadowChange = debounce( ( shadow ) => { + const updatedShadow = { ...( selectedShadow || {} ), shadow }; + setShadows( + shadows.map( ( s ) => ( s.slug === slug ? updatedShadow : s ) ) + ); + }, 100 ); + + return ( + <> + +
+ + +
+ + ); +} + +function ShadowsPreview( { shadow } ) { + const shadowStyle = { + boxShadow: shadow, + }; + + return ( + + +
+ + + ); +} + +function ShadowEditor( { shadow, onChange } ) { + const shadowParts = getShadowParts( shadow ); + + const onChangeShadowPart = ( index, part ) => { + shadowParts[ index ] = part; + onChange( shadowParts.join( ', ' ) ); + }; + + const onAddShadowPart = () => { + shadowParts.push( defaultShadow ); + onChange( shadowParts.join( ', ' ) ); + }; + + const onRemoveShadowPart = ( index ) => { + shadowParts.splice( index, 1 ); + onChange( shadowParts.join( ', ' ) ); + }; + + return ( + <> + + + + { 'Shadows' } + + + + ); + } } + renderContent={ () => ( + +
+ +
+
+ ) } + /> + ); +} + +function ShadowPopover( { shadow: savedShadow, onChange } ) { + const shadowObj = shadowStringToObject( savedShadow ); + const [ shadow, setShadow ] = useState( { + x: shadowObj.x, + y: shadowObj.y, + blur: shadowObj.blur, + spread: shadowObj.spread, + color: shadowObj.color, + inset: shadowObj.inset, + } ); + + const onShadowChange = ( key, value ) => { + onChange( shadowObjectToString( shadow ) ); + setShadow( { + ...shadow, + [ key ]: value, + } ); + }; + + return ( +
+ + { __( 'Drop shadow' ) } + + onShadowChange( 'color', value ) } + /> + + + onShadowChange( 'x', value ) } + /> + onShadowChange( 'y', value ) } + /> + + onShadowChange( 'blur', value ) + } + /> + + onShadowChange( 'spread', value ) + } + /> + + +
+ ); +} + +function ShadowColorPicker( { color, onChange } ) { + const popoverProps = { + placement: 'left-start', + offset: 36, + shift: true, + }; + + return ( + { + const toggleProps = { + onClick: onToggle, + className: classnames( + 'block-editor-panel-color-gradient-settings__dropdown', + { 'is-open': isOpen } + ), + }; + + return ( + - ) } - {isCustom && - - ) } - - } -
- - - - { isEditing ? : } - - -} - -function ShadowsReadOnlyView({label, shadows, placeholder}) { - - const { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } = - unlock( componentsPrivateApis ); - const compositeStore = useCompositeStore(); + const onCreateShadow = ( shadow ) => { + setCustomShadows( [ ...( customShadows || [] ), shadow ] ); + }; - return -{ !shadows.length ? {placeholder} : shadows.map( ( { name, slug, shadow } ) => ( - -) ) } - -} - -function ShadowIndicator( { label, isActive, onSelect, shadow } ) { return ( - - ); -} - -function ShadowsEditorView({label, shadows, isCustom, onChange}) { - return - - { - shadows.map( ( { name, slug, shadow }, index ) => ( - onChange(index, ({ - name, slug, - shadow: updated, - }))} /> - ) ) - } - - -} - -function ShadowEditableItem({label, shadow, onChange, isCustom}) { - const [isEditing, setIsEditing] = useState(false); - const [ popoverAnchor, setPopoverAnchor ] = useState( null ); - const popoverProps = useMemo( - () => ( { - placement: 'left-start', - offset: 36, - shift: true, - anchor: popoverAnchor, - } ), - [ popoverAnchor ] + <> + +
+ + + + + +
+ ); - - return
-
-
- -
-
- { - isCustom ? - {} } - onFocus={ () => {setIsEditing(true)} } - /> :
{setIsEditing(true)}}>{label}
- } -
-
- -
-
- { - isEditing && setIsEditing( false ) } onChange={onChange} /> - } -
} -function ShadowPopover({shadow: savedShadow, popoverProps, onClose, onChange}) { - const shadowParts = shadowStringToObject(savedShadow || ''); - const [ shadow, setShadow ] = useState( { - x: shadowParts.x, - y: shadowParts.y, - blur: shadowParts.blur, - spread: shadowParts.spread, - color: shadowParts.color, - } ); - - const shadowString = `${shadow.x}px ${shadow.y}px ${shadow.blur}px ${shadow.spread}px ${shadow.color}`; +function ShadowList( { label, placeholder, shadows, category, onCreate } ) { + const handleAddShadow = () => { + onCreate( { + name: `Shadow ${ shadows.length + 1 }`, + shadow: defaultShadow, + slug: `shadow-${ shadows.length + 1 }`, + } ); + }; - const handleChange = ( key, value ) => { - onChange(shadowString); - setShadow( { - ...shadow, - [ key ]: value, - } ); - }; - - return -
- -
- { __( 'Drop shadow' ) } -
-
-
-
-
-
- handleChange( 'x', value ) } - withInputField={ false } - min={ 0 } - max={ 10 } - /> -
-
- handleChange( 'y', value ) } - withInputField={ false } - min={ 0 } - max={ 10 } - /> -
-
- handleChange( 'blur', value ) } - withInputField={ false } - min={ 0 } - max={ 10 } - /> -
-
- handleChange( 'spread', value ) } - withInputField={ false } - min={ 0 } - max={ 10 } - /> -
- {/*
Color
*/} -
-
-
-
+ return ( + + + + { label } + + + { category === 'custom' && ( +