Skip to content
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

Global Styles: Add button to reset color palette #26975

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/components/src/color-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default function ColorEdit( {
onChange,
emptyUI,
immutableColorSlugs,
canReset = true,
} ) {
const [ isInsertingColor, setIsInsertingColor ] = useState( false );
return (
Expand Down Expand Up @@ -311,6 +312,16 @@ export default function ColorEdit( {
) }
{ ! isInsertingColor && isEmpty( colors ) && emptyUI }
</div>
{ !! canReset && (
<Button
isSmall
isSecondary
className="components-color-edit__reset-button"
onClick={ () => onChange() }
>
{ __( 'Reset' ) }
</Button>
) }
</fieldset>
</BaseControl>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/color-edit/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
.components-color-edit__slug-input {
margin-left: $grid-unit-10;
}

.components-color-edit__reset-button {
float: right;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ import { useEditorFeature, GLOBAL_CONTEXT } from '../editor/utils';
*/
const EMPTY_ARRAY = [];

export default function ColorPalettePanel( { contextName, setSetting } ) {
export default function ColorPalettePanel( {
contextName,
getSetting,
setSetting,
} ) {
const colors = useEditorFeature( 'color.palette', contextName );
const userColors = getSetting( contextName, 'color.palette' );
const immutableColorSlugs = useSelect(
( select ) => {
const baseStyles = select( 'core/edit-site' ).getSettings()
Expand Down Expand Up @@ -62,6 +67,7 @@ export default function ColorPalettePanel( { contextName, setSetting } ) {
emptyUI={ __(
'Colors are empty! Add some colors to create your own color palette.'
) }
canReset={ colors === userColors }
/>
);
}