Skip to content
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

Pass active state to HeadingLevelIcon in order to native start working #17747

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/block-library/src/heading/heading-level-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/
import { Path, SVG } from '@wordpress/components';

export default function HeadingLevelIcon( { level } ) {
export default function HeadingLevelIcon( { level, active } ) {

const levelToPath = {
1: 'M9 5h2v10H9v-4H5v4H3V5h2v4h4V5zm6.6 0c-.6.9-1.5 1.7-2.6 2v1h2v7h2V5h-1.4z',
2: 'M7 5h2v10H7v-4H3v4H1V5h2v4h4V5zm8 8c.5-.4.6-.6 1.1-1.1.4-.4.8-.8 1.2-1.3.3-.4.6-.8.9-1.3.2-.4.3-.8.3-1.3 0-.4-.1-.9-.3-1.3-.2-.4-.4-.7-.8-1-.3-.3-.7-.5-1.2-.6-.5-.2-1-.2-1.5-.2-.4 0-.7 0-1.1.1-.3.1-.7.2-1 .3-.3.1-.6.3-.9.5-.3.2-.6.4-.8.7l1.2 1.2c.3-.3.6-.5 1-.7.4-.2.7-.3 1.2-.3s.9.1 1.3.4c.3.3.5.7.5 1.1 0 .4-.1.8-.4 1.1-.3.5-.6.9-1 1.2-.4.4-1 .9-1.6 1.4-.6.5-1.4 1.1-2.2 1.6V15h8v-2H15z',
Expand All @@ -17,7 +18,7 @@ export default function HeadingLevelIcon( { level } ) {
}

return (
<SVG width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<SVG width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" active={ active } >
Copy link
Contributor

@youknowriad youknowriad Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why the "SVG" component should have an "active" prop. it would make sense for a "button" to be active but not the SVG component in my opinion (for both web and mobile)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @youknowriad @gziolo as I remember gutenberg is using some css magic which allows you to define heading text color in higher-level CSS which will be passed to SVG but native doesn't support that magic. Probably we can find some better solution? But this issue is blocking our release process so we can do it after the release? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with CSS you can use the class names applied to parents to change how it looks. With RN it isn't possible, that's why you need to pass it down as prop.

<Path d={ levelToPath[ level ] } />
</SVG>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/heading/heading-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import HeadingLevelIcon from './heading-level-icon';

class HeadingToolbar extends Component {
createLevelControl( targetLevel, selectedLevel, onChange ) {
const isActive = targetLevel === selectedLevel;
return {
icon: <HeadingLevelIcon level={ targetLevel } />,
icon: <HeadingLevelIcon level={ targetLevel } active={ isActive }/>,
// translators: %s: heading level e.g: "1", "2", "3"
title: sprintf( __( 'Heading %d' ), targetLevel ),
isActive: targetLevel === selectedLevel,
isActive,
onClick: () => onChange( targetLevel ),
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/primitives/svg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export const SVG = ( props ) => {

// Disable reason: We need to have a way to render HTML tag for web.
// eslint-disable-next-line react/forbid-elements
return <svg { ...appliedProps } />;
return <svg { ...omit( appliedProps, 'active' ) } />;
};
4 changes: 2 additions & 2 deletions packages/components/src/primitives/svg/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export {

export const SVG = ( props ) => {
const stylesFromClasses = ( props.className || '' ).split( ' ' ).map( ( element ) => styles[ element ] ).filter( Boolean );
const stylesFromAriaPressed = props.ariaPressed ? styles[ 'is-active' ] : styles[ 'components-toolbar__control' ];
const styleValues = Object.assign( {}, props.style, stylesFromAriaPressed, ...stylesFromClasses );
const defaultStyle = props.active ? styles[ 'is-active' ] : styles[ 'components-toolbar__control' ];
const styleValues = Object.assign( {}, props.style, defaultStyle, ...stylesFromClasses );

const safeProps = { ...props, style: styleValues };

Expand Down