-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Duotone: add block controls on the inspector #49838
Changes from all commits
8da1330
cf970bc
af984c0
057be54
f96d202
799269e
b8f60bc
aabd119
6e7e6ec
3b5bb9a
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ const StylesTab = ( { blockName, clientId, hasBlockStyles } ) => { | |
label={ __( 'Color' ) } | ||
className="color-block-support-panel__inner-wrapper" | ||
/> | ||
<InspectorControls.Slot group="filter" /> | ||
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. @jasmussen is this a proper order for the filters? I put it after color because it's what made sense to me |
||
<InspectorControls.Slot | ||
group="typography" | ||
label={ __( 'Typography' ) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import { useSelect } from '@wordpress/data'; | |
*/ | ||
import { | ||
BlockControls, | ||
InspectorControls, | ||
__experimentalDuotoneControl as DuotoneControl, | ||
useSetting, | ||
} from '../components'; | ||
|
@@ -34,7 +35,9 @@ import { | |
} from '../components/duotone'; | ||
import { getBlockCSSSelector } from '../components/global-styles/get-block-css-selector'; | ||
import { scopeSelector } from '../components/global-styles/utils'; | ||
import { useBlockSettings } from './utils'; | ||
import { store as blockEditorStore } from '../store'; | ||
import { default as StylesFiltersPanel } from '../components/global-styles/filters-panel'; | ||
|
||
const EMPTY_ARRAY = []; | ||
|
||
|
@@ -106,9 +109,10 @@ export function getDuotonePresetFromColors( colors, duotonePalette ) { | |
return preset ? `var:preset|duotone|${ preset.slug }` : undefined; | ||
} | ||
|
||
function DuotonePanel( { attributes, setAttributes } ) { | ||
function DuotonePanel( { attributes, setAttributes, name } ) { | ||
const style = attributes?.style; | ||
const duotoneStyle = style?.color?.duotone; | ||
const settings = useBlockSettings( name ); | ||
|
||
const duotonePalette = useMultiOriginPresets( { | ||
presetSetting: 'color.duotone', | ||
|
@@ -132,30 +136,47 @@ function DuotonePanel( { attributes, setAttributes } ) { | |
: duotoneStyle; | ||
|
||
return ( | ||
<BlockControls group="block" __experimentalShareWithChildBlocks> | ||
<DuotoneControl | ||
duotonePalette={ duotonePalette } | ||
colorPalette={ colorPalette } | ||
disableCustomDuotone={ disableCustomDuotone } | ||
disableCustomColors={ disableCustomColors } | ||
value={ duotonePresetOrColors } | ||
onChange={ ( newDuotone ) => { | ||
const maybePreset = getDuotonePresetFromColors( | ||
newDuotone, | ||
duotonePalette | ||
); | ||
|
||
const newStyle = { | ||
...style, | ||
color: { | ||
...style?.color, | ||
duotone: maybePreset ?? newDuotone, // use preset or fallback to custom colors. | ||
}, | ||
}; | ||
setAttributes( { style: newStyle } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<> | ||
<InspectorControls group="filter"> | ||
<StylesFiltersPanel | ||
value={ { filter: { duotone: duotonePresetOrColors } } } | ||
onChange={ ( newDuotone ) => { | ||
const newStyle = { | ||
color: { | ||
...newDuotone?.filter, | ||
}, | ||
}; | ||
setAttributes( { style: newStyle } ); | ||
} } | ||
settings={ settings } | ||
/> | ||
</InspectorControls> | ||
<BlockControls group="block" __experimentalShareWithChildBlocks> | ||
<DuotoneControl | ||
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. @youknowriad we tried to use the 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. yes, this is a new use case (block toolbar). Maybe there's a way to make these controllers agnostic here too by providing a specific Wrapper prop, did we try that? 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. yes, we did that, and the 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. /cc @ajlende 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. I guess it's because of a missing |
||
duotonePalette={ duotonePalette } | ||
colorPalette={ colorPalette } | ||
disableCustomDuotone={ disableCustomDuotone } | ||
disableCustomColors={ disableCustomColors } | ||
value={ duotonePresetOrColors } | ||
onChange={ ( newDuotone ) => { | ||
const maybePreset = getDuotonePresetFromColors( | ||
newDuotone, | ||
duotonePalette | ||
); | ||
|
||
const newStyle = { | ||
...style, | ||
color: { | ||
...style?.color, | ||
duotone: maybePreset ?? newDuotone, // use preset or fallback to custom colors. | ||
}, | ||
}; | ||
setAttributes( { style: newStyle } ); | ||
} } | ||
settings={ settings } | ||
/> | ||
</BlockControls> | ||
</> | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,13 @@ export default function FiltersPanel( { name } ) { | |
inheritedValue={ inheritedStyle } | ||
value={ style } | ||
onChange={ setStyle } | ||
settings={ settings } | ||
settings={ { | ||
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. I wonder if we should memoize this object (depends on how it's used internally) |
||
...settings, | ||
color: { | ||
...settings.color, | ||
customDuotone: false, //TO FIX: Custom duotone only works on the block level right now | ||
}, | ||
} } | ||
/> | ||
); | ||
} |
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.
It's not great when we use "classnames" as reusable components. In the ideal scenario, the styles should be defined in the same place where the classname is used.
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.
yes! this I think can be refactored when we work on using the filter panel for the toolbar controls, I will make a note to do just that