-
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
Cover: Add custom unit support for height controls #20888
Merged
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5ff8a7e
Add unit-control component
52bc8e5
Add G2 color values to color utils. Apply to UnitControl
b1676f5
Add numeric inputmode for UnitControl
c608b21
Add TODO note for NumberControl
cfb2f5a
Add NumberControl for better increment/decrement handling
8ba87a1
Refactor UnitControl and NumberControl. Add README files for components
c8641ea
Adjust UnitSelectControl rendering
9fd0b31
Improve integration of UnitControl with Cover Block
0c1b6b5
Adjust default minHeightUnit
2210d42
Fix default height for Cover block
125405f
Add add_theme_support for custom units
c411186
Adjust styles for UnitLabel
fc8e56d
Add unit tests for NumberControl. Update snapshot for UnitControl.
34a4bab
Abstract UnitControl to block-editor component
1dcc082
Refactor to remove getComputedSize. Set unitized height directly with…
50ed451
Improve reset values for UnitControl
8b43e60
Enable support for secondary parameters for `add_theme_support( 'disa…
7691e30
Add comments for unit filtering
a3998f3
Rename disable-custom-units to experimental-custom-units
2b6ea59
Provide return description for filterUnitsWithSettings util
34bafa0
Improve logic clarity of Cover minHeight style
23e79b7
Add dev notes for G2 color map
1b3a583
Default minHeightUnit of Cover to `px`
0a65b6d
Adjust colors to deep merge without mutation
8eaf5a6
Adjust label of Cover height control
455cb04
Remove unnecessary test comments from number-control test
94b3a85
Add tests for UnitControl
52882de
Update Storybook snapshots
95a7024
Remove default px value for minHeightUnit in Cover
fab4f91
Update PHP comments for line height and unit filters
0d8f031
Fix PHP lint issues
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
Add add_theme_support for custom units
- Loading branch information
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -35,7 +35,7 @@ import { | |
__experimentalPanelColorGradientSettings as PanelColorGradientSettings, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { withDispatch } from '@wordpress/data'; | ||
import { useSelect, withDispatch } from '@wordpress/data'; | ||
import { cover as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
|
@@ -73,6 +73,15 @@ function retrieveFastAverageColor() { | |
return retrieveFastAverageColor.fastAverageColor; | ||
} | ||
|
||
export function useIsCustomUnitsDisabled() { | ||
const isDisabled = useSelect( ( select ) => { | ||
const { getSettings } = select( 'core/block-editor' ); | ||
return !! getSettings().__experimentalDisableCustomUnits; | ||
}, [] ); | ||
|
||
return isDisabled; | ||
} | ||
|
||
const { __getComputedSize: getComputedUnitSize } = UnitControl; | ||
|
||
function CoverHeightInput( { | ||
|
@@ -85,6 +94,7 @@ function CoverHeightInput( { | |
const instanceId = useInstanceId( UnitControl ); | ||
const inputId = `block-cover-height-input-${ instanceId }`; | ||
const isPx = unit === 'px'; | ||
const isCustomUnitsDisabled = useIsCustomUnitsDisabled(); | ||
|
||
const handleOnChange = ( unprocessedValue ) => { | ||
const inputValue = | ||
|
@@ -108,6 +118,7 @@ function CoverHeightInput( { | |
|
||
const inputValue = temporaryInput !== null ? temporaryInput : value; | ||
const min = isPx ? COVER_MIN_HEIGHT : 0; | ||
const units = isCustomUnitsDisabled ? false : CSS_UNITS; | ||
|
||
return ( | ||
<BaseControl label={ __( 'Minimum height in pixels' ) } id={ inputId }> | ||
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. This label is no longer entirely accurate. |
||
|
@@ -120,7 +131,7 @@ function CoverHeightInput( { | |
step="1" | ||
style={ { maxWidth: 80 } } | ||
unit={ unit } | ||
units={ CSS_UNITS } | ||
units={ units } | ||
value={ inputValue } | ||
/> | ||
</BaseControl> | ||
|
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
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
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.
Should this support a second argument where the theme can say which should be the unit shown / used? Like
get_theme_support( 'disable-custom-units', 'rem' )
would force rem to be used in all unit-based selectors.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.
Good suggestion! Let me make that adjustment ✨