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
React Native - Heading toolbar #9570
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb7c413
Update use of content size change event.
SergioEstevao 29dc1c1
Show toolbar heading specific buttons.
SergioEstevao 379d16f
Implement subscript in button.
SergioEstevao 060c659
Merge branch 'master' into rnmobile/heading_toolbar
SergioEstevao 225307a
Make viewport implementation empty in native.
SergioEstevao 2208534
Add entry point for React Native in api-fetch package
SergioEstevao 9b81b29
Share createLevelControl between React Web and React Native
SergioEstevao c9fb74a
Allow headings to have styles (strong, em, del).
SergioEstevao ba04e50
Implement heading toolbar.
SergioEstevao File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,13 +2,15 @@ | |
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
import { range } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { RichText } from '@wordpress/editor'; | ||
import { Toolbar } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -18,6 +20,26 @@ import './editor.scss'; | |
const minHeight = 50; | ||
|
||
class HeadingEdit extends Component { | ||
createLevelControl( targetLevel ) { | ||
const { | ||
attributes, | ||
setAttributes, | ||
} = this.props; | ||
|
||
const { | ||
level, | ||
} = attributes; | ||
|
||
return { | ||
icon: 'heading', | ||
// translators: %s: heading level e.g: "1", "2", "3" | ||
title: sprintf( __( 'Heading %d' ), targetLevel ), | ||
isActive: targetLevel === level, | ||
onClick: () => setAttributes( { level: targetLevel } ), | ||
subscript: String( targetLevel ), | ||
}; | ||
} | ||
|
||
render() { | ||
const { | ||
attributes, | ||
|
@@ -33,6 +55,7 @@ class HeadingEdit extends Component { | |
|
||
return ( | ||
<View> | ||
<Toolbar controls={ range( 2, 5 ).map( this.createLevelControl.bind( this ) ) } /> | ||
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. Similar to https://github.com/WordPress/gutenberg/pull/9570/files#r214705073, it would be nice if we could avoid re-defining the toolbar buttons. |
||
<RichText | ||
tagName={ tagName } | ||
content={ { contentTree: attributes.content, eventCount: attributes.eventCount } } | ||
|
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TouchableOpacity } from 'react-native'; | ||
import { TouchableOpacity, Text, View } from 'react-native'; | ||
|
||
export default function Button( props ) { | ||
const { children, onClick, 'aria-label': ariaLabel, 'aria-pressed': ariaPressed } = props; | ||
const { children, onClick, 'aria-label': ariaLabel, 'aria-pressed': ariaPressed, 'data-subscript': subscript } = props; | ||
return ( | ||
<TouchableOpacity | ||
accessible={ true } | ||
accessibilityLabel={ ariaLabel } | ||
onPress={ onClick } | ||
style={ { borderColor: ariaPressed ? 'black' : 'white', borderWidth: 1, borderRadius: 2 } } | ||
> | ||
{ children } | ||
<View style={ { flex: 1, flexDirection: 'row' } }> | ||
{ children } | ||
{ subscript && ( <Text style={ { fontVariant: [ 'small-caps' ], textAlignVertical: 'bottom' } }>{ subscript }</Text> ) } | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
} |
Empty file.
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.
Can we extract the implementation of
createLevelControl
into its own module file and re-use it both for the web and the native mobile? I think we should try that to avoid replicating code that is not specific to native mobile.