-
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
Refactor heading block to share more code with web version. #20745
Changes from 1 commit
a17a5c6
b4e84f9
28350f5
d8fb1e8
bebc055
2f21f8b
733f4f6
d6aedfa
3ec775c
2d57fe2
0988634
5050d3d
3d7e007
507f972
bc3ca73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const TextColor = ( props ) => <>{ props.children }</>; | ||
|
||
const InspectorControlsColorPanel = () => null; | ||
|
||
export default function __experimentalUseColors() { | ||
return { | ||
TextColor, | ||
InspectorControlsColorPanel, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import HeadingToolbar from './heading-toolbar'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { PanelBody } from '@wordpress/components'; | ||
import { PanelBody, __experimentalText as Text } from '@wordpress/components'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { | ||
AlignmentToolbar, | ||
|
@@ -22,7 +22,7 @@ import { | |
__experimentalUseColors, | ||
__experimentalBlock as Block, | ||
} from '@wordpress/block-editor'; | ||
import { useRef } from '@wordpress/element'; | ||
import { useRef, Platform } from '@wordpress/element'; | ||
|
||
function HeadingEdit( { | ||
attributes, | ||
|
@@ -54,17 +54,19 @@ function HeadingEdit( { | |
onChange={ ( newLevel ) => | ||
setAttributes( { level: newLevel } ) | ||
} | ||
isCollapsed={ Platform.OS === 'web' } | ||
/> | ||
<AlignmentToolbar | ||
value={ align } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { align: nextAlign } ); | ||
} } | ||
isCollapsed={ Platform.OS === 'web' } | ||
/> | ||
</BlockControls> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Heading settings' ) }> | ||
<p>{ __( 'Level' ) }</p> | ||
<Text variant="label">{ __( 'Level' ) }</Text> | ||
<HeadingToolbar | ||
isCollapsed={ false } | ||
minLevel={ 1 } | ||
|
@@ -81,7 +83,9 @@ function HeadingEdit( { | |
<RichText | ||
ref={ ref } | ||
identifier="content" | ||
tagName={ Block[ tagName ] } | ||
tagName={ | ||
Platform.OS === 'web' ? Block[ tagName ] : tagName | ||
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. I think 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. Yes, ideally native has a 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. I'm working on to have an equivalent ( more a mock at this stage) on this PR: #20772 Will update this PR when the above is merged in. |
||
} | ||
value={ content } | ||
onChange={ ( value ) => | ||
setAttributes( { content: value } ) | ||
|
@@ -103,6 +107,7 @@ function HeadingEdit( { | |
[ `has-text-align-${ align }` ]: align, | ||
} ) } | ||
placeholder={ placeholder || __( 'Write heading…' ) } | ||
textAlign={ align } | ||
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 is the only thing that's bothering me, in this PR. It's redundunt with the style prop in the web and it can easily get removed since it's not used at all in the web version. 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 is a recurrent issue we have on the mobile implementations. We don't have access to CSS so we end up recurring to extra props or container classes to do the work that CSS does. I'm all open to suggestions on how can we avoid these issues. |
||
/> | ||
</TextColor> | ||
</> | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import css from '@emotion/css'; | ||
|
||
export default css; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { css } from '@emotion/native'; | ||
|
||
export default css; |
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.
Do mobile toolbars support isCollapsed prop? Wht happens if we keep it true for mobile too?
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.
They don't show., it looks collapsed is equivalent to hidden in mobile.
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.
Do you think we should update the toolbar implementation to just ignore that prop instead?
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 can update the code for the native ToolbarGroupCollapsed to simple do the same as the non-collapsed version, until we get a proper implementation of a collapsed toolbar for mobile.