-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Use Duotone presets in block duotone attributes #48318
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
Merged
+194
−18
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aa1e759
Naive implementation
getdave 13f8b75
Refactor to named functions
getdave ef853d6
Fix order of hooks
getdave 53a4173
Utilise existing duotone presets on front of site
getdave 89f1634
Improve self documenting code
getdave b3831a1
Refactor away redundant color prop of filter_preset
getdave 3db9ff8
Satisfy master yoda…
getdave 07d9df5
More commenting
getdave a457af9
Remove count() check for duotone color array
jeryj 8e9c0ee
Improve comments and linting
getdave d7ef38c
Allow Duotone to be cleared using UI
getdave 55f7dfe
Add initial tests for getColorsFromDuotonePreset
getdave 5915bbd
Be explicit about handling presets vs colors
getdave 73bf149
Complete tests for getColorsFromDuotonePreset
getdave 1ad0761
Add tests and fix implementation of getDuotonePresetFromColors
getdave a7f89db
Fix bug with selecting custom colors introduced during test refactor
getdave a5c64eb
Fix custom colors Duotone on front end rendering
getdave 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
This file contains hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { | ||
| getColorsFromDuotonePreset, | ||
| getDuotonePresetFromColors, | ||
| } from '../duotone'; | ||
|
|
||
| describe( 'Duotone utilities', () => { | ||
| const duotonePalette = [ | ||
| { | ||
| name: 'Dark grayscale', | ||
| colors: [ '#000000', '#7f7f7f' ], | ||
| slug: 'dark-grayscale', | ||
| }, | ||
| { | ||
| name: 'Grayscale', | ||
| colors: [ '#000000', '#ffffff' ], | ||
| slug: 'grayscale', | ||
| }, | ||
| { | ||
| name: 'Purple and yellow', | ||
| colors: [ '#8c00b7', '#fcff41' ], | ||
| slug: 'purple-yellow', | ||
| }, | ||
| ]; | ||
| describe( 'getColorsFromDuotonePreset', () => { | ||
| it( 'should return undefined if no arguments are provided', () => { | ||
| expect( getColorsFromDuotonePreset() ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if no duotone preset is provided', () => { | ||
| expect( | ||
| getColorsFromDuotonePreset( undefined, duotonePalette ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if a non-existent preset is provided', () => { | ||
| expect( | ||
| getColorsFromDuotonePreset( 'does-not-exist', duotonePalette ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return the colors from the preset if found', () => { | ||
| expect( | ||
| getColorsFromDuotonePreset( | ||
| duotonePalette[ 2 ].slug, | ||
| duotonePalette | ||
| ) | ||
| ).toEqual( duotonePalette[ 2 ].colors ); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'getDuotonePresetFromColors', () => { | ||
| it( 'should return undefined if no arguments are provided', () => { | ||
| expect( getDuotonePresetFromColors() ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if no colors are provided', () => { | ||
| expect( | ||
| getDuotonePresetFromColors( undefined, duotonePalette ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if provided colors is not of valid type', () => { | ||
| const notAnArrayOfColorStrings = 'purple-yellow'; | ||
| expect( | ||
| getDuotonePresetFromColors( | ||
| notAnArrayOfColorStrings, | ||
| duotonePalette | ||
| ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if no duotone palette is provided', () => { | ||
| expect( | ||
| getDuotonePresetFromColors( [ '#8c00b7', '#fcff41' ] ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return undefined if the provided colors do not match any preset', () => { | ||
| expect( | ||
| getDuotonePresetFromColors( | ||
| [ '#000000', '#000000' ], | ||
| duotonePalette | ||
| ) | ||
| ).toBeUndefined(); | ||
| } ); | ||
|
|
||
| it( 'should return the slug of the preset if found', () => { | ||
| expect( | ||
| getDuotonePresetFromColors( | ||
| duotonePalette[ 2 ].colors, | ||
| duotonePalette | ||
| ) | ||
| ).toEqual( duotonePalette[ 2 ].slug ); | ||
| } ); | ||
| } ); | ||
| } ); |
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.
I wish I would have used
'none'as the string instead of'unset'so that string values could just be treated as CSS like the rest of the block supports. But for maintaining backwards compatibility, I don't think that's really an option anymore.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.
Just so you know this return value is preserved but I moved it outside of this function so it doesn't need
colorsin the "preset".