-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Rnmobile/add/typography controls #33605
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fa8cc98
Allow for a non units to show without the unit picker.
enejb 079fafd
Add Line Height Controls
enejb ccf43f4
Make variable more clear
enejb de9c703
Revert Typography web
enejb e7e0f14
Add support for font sizes
enejb 212cd52
Add bottom Cell sheet subLabel
enejb 83c359c
Update the colour of the subheading
enejb 5204319
Update colours again for subheading
enejb c811a7f
Make the Typography UI only available in dev build
enejb f805c7c
Do not show items that we can't parse as numbers
enejb 6e4f99c
Add comment
enejb 19f1470
Move the FontSizePicker export
enejb 97eb2bd
Remove the not needed platform check
enejb 438c3db
Update comment to be more font size specific.
enejb 0934c87
Fix unit test for customLineHeight
enejb 3984a50
Revert the units logic to hide the Unit picker
enejb 7be1cdd
Remove the added borderRightWidth for picker that doesn't have childern
enejb 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
8 changes: 7 additions & 1 deletion
8
packages/block-editor/src/components/font-sizes/index.native.js
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 |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| export { getFontSize, getFontSizeClass } from './utils'; | ||
| export { | ||
| getFontSize, | ||
| getFontSizeClass, | ||
| getFontSizeObjectByValue, | ||
| } from './utils'; | ||
| export { default as FontSizePicker } from './font-size-picker'; | ||
| export { default as withFontSizes } from './with-font-sizes'; |
25 changes: 25 additions & 0 deletions
25
packages/block-editor/src/components/line-height-control/index.native.js
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,25 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { UnitControl } from '@wordpress/components'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { BASE_DEFAULT_VALUE, STEP, isLineHeightDefined } from './utils'; | ||
|
|
||
| export default function LineHeightControl( { value: lineHeight, onChange } ) { | ||
| const isDefined = isLineHeightDefined( lineHeight ); | ||
| const value = isDefined ? lineHeight : BASE_DEFAULT_VALUE; | ||
| return ( | ||
| <UnitControl | ||
| label={ __( 'Line Height' ) } | ||
| min={ 0 } | ||
| max={ 5 } | ||
| step={ STEP } | ||
| value={ value } | ||
| onChange={ onChange } | ||
| units={ false } | ||
| /> | ||
| ); | ||
| } |
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,64 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { hasBlockSupport } from '@wordpress/blocks'; | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { PanelBody } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import InspectorControls from '../components/inspector-controls'; | ||
|
|
||
| import { | ||
| LINE_HEIGHT_SUPPORT_KEY, | ||
| LineHeightEdit, | ||
| useIsLineHeightDisabled, | ||
| } from './line-height'; | ||
| import { | ||
| FONT_SIZE_SUPPORT_KEY, | ||
| FontSizeEdit, | ||
| useIsFontSizeDisabled, | ||
| } from './font-size'; | ||
|
|
||
| export const TYPOGRAPHY_SUPPORT_KEY = 'typography'; | ||
| export const TYPOGRAPHY_SUPPORT_KEYS = [ | ||
| LINE_HEIGHT_SUPPORT_KEY, | ||
| FONT_SIZE_SUPPORT_KEY, | ||
| ]; | ||
|
|
||
| export function TypographyPanel( props ) { | ||
| const isDisabled = useIsTypographyDisabled( props ); | ||
| const isSupported = hasTypographySupport( props.name ); | ||
|
|
||
| // only enable TypographyPanel for development | ||
| // eslint-disable-next-line no-undef | ||
| if ( isDisabled || ! isSupported || ! __DEV__ ) return null; | ||
|
|
||
| return ( | ||
| <InspectorControls> | ||
| <PanelBody title={ __( 'Typography' ) }> | ||
| <FontSizeEdit { ...props } /> | ||
| <LineHeightEdit { ...props } /> | ||
| </PanelBody> | ||
| </InspectorControls> | ||
| ); | ||
| } | ||
|
|
||
| const hasTypographySupport = ( blockName ) => { | ||
| return TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) => | ||
| hasBlockSupport( blockName, key ) | ||
| ); | ||
| }; | ||
|
|
||
| function useIsTypographyDisabled( props = {} ) { | ||
| const configs = [ | ||
| useIsFontSizeDisabled( props ), | ||
| useIsLineHeightDisabled( props ), | ||
| ]; | ||
|
|
||
| return configs.filter( Boolean ).length === configs.length; | ||
| } | ||
173 changes: 173 additions & 0 deletions
173
packages/components/src/font-size-picker/index.native.js
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,173 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { View } from 'react-native'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useNavigation } from '@react-navigation/native'; | ||
| import { useState } from '@wordpress/element'; | ||
| import { Icon, chevronRight, check } from '@wordpress/icons'; | ||
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { BottomSheet } from '@wordpress/components'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { default as UnitControl, useCustomUnits } from '../unit-control'; | ||
| import styles from './style.scss'; | ||
|
|
||
| function FontSizePicker( { | ||
| fontSizes = [], | ||
| disableCustomFontSizes = false, | ||
| onChange, | ||
| value: selectedValue, | ||
| } ) { | ||
| const [ showSubSheet, setShowSubSheet ] = useState( false ); | ||
| const navigation = useNavigation(); | ||
|
|
||
| const onChangeValue = ( value ) => { | ||
| return () => { | ||
| goBack(); | ||
| onChange( value ); | ||
| }; | ||
| }; | ||
|
|
||
| const selectedOption = fontSizes.find( | ||
| ( option ) => option.size === selectedValue | ||
| ) ?? { name: 'Custom' }; | ||
|
|
||
| const goBack = () => { | ||
| setShowSubSheet( false ); | ||
| navigation.goBack(); | ||
| }; | ||
|
|
||
| const openSubSheet = () => { | ||
| navigation.navigate( BottomSheet.SubSheet.screenName ); | ||
| setShowSubSheet( true ); | ||
| }; | ||
| const label = __( 'Font Size' ); | ||
|
|
||
| const units = useCustomUnits( { | ||
| availableUnits: [ 'px', 'em', 'rem' ], | ||
| } ); | ||
|
|
||
| return ( | ||
| <BottomSheet.SubSheet | ||
| navigationButton={ | ||
| <BottomSheet.Cell | ||
| label={ label } | ||
| separatorType="none" | ||
| value={ | ||
| selectedValue | ||
| ? sprintf( | ||
| // translators: %1$s: Select control font size name e.g. Small, %2$s: Select control font size e.g. 12px | ||
| __( '%1$s (%2$s)' ), | ||
| selectedOption.name, | ||
| selectedValue | ||
| ) | ||
| : __( 'Default' ) | ||
| } | ||
| onPress={ openSubSheet } | ||
| accessibilityRole={ 'button' } | ||
| accessibilityLabel={ selectedOption.name } | ||
| accessibilityHint={ sprintf( | ||
| // translators: %s: Select control button label e.g. Small | ||
| __( 'Navigates to select %s' ), | ||
| selectedOption.name | ||
| ) } | ||
| > | ||
| <Icon icon={ chevronRight }></Icon> | ||
| </BottomSheet.Cell> | ||
| } | ||
| showSheet={ showSubSheet } | ||
| > | ||
| <> | ||
| <BottomSheet.NavigationHeader | ||
| screen={ label } | ||
| leftButtonOnPress={ goBack } | ||
| /> | ||
| <View style={ styles[ 'components-font-size-picker' ] }> | ||
| <BottomSheet.Cell | ||
| customActionButton | ||
| separatorType="none" | ||
| label={ __( 'Default' ) } | ||
| onPress={ onChangeValue( undefined ) } | ||
| leftAlign={ true } | ||
| key={ 'default' } | ||
| accessibilityRole={ 'button' } | ||
| accessibilityLabel={ __( 'Selected: Default' ) } | ||
| accessibilityHint={ __( | ||
| 'Double tap to select default font size' | ||
| ) } | ||
| > | ||
| <View> | ||
| { selectedValue === undefined && ( | ||
| <Icon icon={ check }></Icon> | ||
| ) } | ||
| </View> | ||
| </BottomSheet.Cell> | ||
| { fontSizes.map( ( item, index ) => { | ||
| // Only display a choice that we can currenly select. | ||
| if ( ! parseFloat( item.size ) ) { | ||
| return null; | ||
| } | ||
geriux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ( | ||
| <BottomSheet.Cell | ||
| customActionButton | ||
| separatorType="none" | ||
| label={ item.name } | ||
| subLabel={ item.size } | ||
| onPress={ onChangeValue( item.size ) } | ||
| leftAlign={ true } | ||
| key={ index } | ||
| accessibilityRole={ 'button' } | ||
| accessibilityLabel={ | ||
| item.size === selectedValue | ||
| ? sprintf( | ||
| // translators: %s: Select font size option value e.g: "Selected: Large". | ||
| __( 'Selected: %s' ), | ||
| item.name | ||
| ) | ||
| : item.name | ||
| } | ||
| accessibilityHint={ __( | ||
| 'Double tap to select font size' | ||
| ) } | ||
| > | ||
| <View> | ||
| { item.size === selectedValue && ( | ||
| <Icon icon={ check }></Icon> | ||
| ) } | ||
| </View> | ||
| </BottomSheet.Cell> | ||
| ); | ||
| } ) } | ||
| { ! disableCustomFontSizes && ( | ||
| <UnitControl | ||
| label={ __( 'Custom' ) } | ||
| min={ 0 } | ||
| max={ 200 } | ||
| step={ 1 } | ||
| value={ selectedValue } | ||
| onChange={ ( nextSize ) => { | ||
| if ( | ||
| 0 === parseFloat( nextSize ) || | ||
| ! nextSize | ||
| ) { | ||
| onChange( undefined ); | ||
| } else { | ||
| onChange( nextSize ); | ||
| } | ||
| } } | ||
| units={ units } | ||
| /> | ||
| ) } | ||
| </View> | ||
| </> | ||
| </BottomSheet.SubSheet> | ||
| ); | ||
| } | ||
|
|
||
| export default FontSizePicker; | ||
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,6 @@ | ||
| .components-font-size-picker { | ||
| padding: 0 $block-edge-to-content; | ||
| } | ||
| .components-font-size-picker__font-size { | ||
| font-size: 11px; | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.