Skip to content

Commit

Permalink
Mobile - Global styles: Block-specific styles (#30997)
Browse files Browse the repository at this point in the history
* Mobile - Read global styles and set color palette and gradients

* Mobile - Enable colors for blocks that support it

* Parse all color variables

* Mobile - Set background, title, text and link colors

* Fix gradients

* Add placeholder color

* Add support to block styles

* Add reset button in color picker

* Fix placeholder colors

* Fix paddings and remove Columns placeholder solid background

* Don't reset paddings for inner blocks that have paddings already

* Mobile - Block styles support

* Add fallback text color to blocks

* Adds new Prop for Global Styles Settings

* Rename updateTheme to be more generic for update settings include GSS (#31566)

* Fix wrong naming of subscribeUpdateEditorSettings

* Update Gutenberg demo

* Updates new props to rawStyles and rawFeatures

* Update iOS Bridge for new values

* Mobile - Global styles: Pass settings and set color palette and gradients (#30684)

* Mobile - Read global styles and set color palette and gradients

* Parse all color variables

* Fix gradients

* Update global styles mocked data

* Move color settings

* Removed added spaces

* Add tests

* Update experimental features path and prepare for rawGlobalStylesBaseStyles

* Remove mock data and update code to use latest API changes

* Removes Android rawFeatures prop

* Mobile - Remove usage of rawFeatures

* Remove rawFeatures

* Adds raw Styles in React Native Bridge

* Mobile - Pass rawStyles on initial props and fix colors and gradients

* Add Raw Features back

* Revert "Removes Android rawFeatures prop"

This reverts commit 32a2b3a.

* Add rawFeatures in the mobile editor

* Mobile - Global styles: Set theme's background and text color (#30810)

* Mobile - Read global styles and set color palette and gradients

* Mobile - Enable colors for blocks that support it

* Parse all color variables

* Mobile - Set background, title, text and link colors

* Fix gradients

* Add placeholder color

* Update global styles mocked data

* Move color settings

* Removed added spaces

* Add tests

* Update experimental features path and prepare for rawGlobalStylesBaseStyles

* Add missing provider

* Get the right color attribute

* Remove mock data

* Mobile - Fix base global colors

* Remove old usage of useEditorFeature

* Remove old mock data

* Add support for block styles of the Verse block in mobile

* Rename mergedStyle to style

Co-authored-by: Antonis Lilis <antonis.lilis@automattic.com>
Co-authored-by: Chip <chip.snyder3@gmail.com>
  • Loading branch information
3 people authored Jul 7, 2021
1 parent 87a696e commit 0de0598
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function BlockForType( {
globalStyle,
wrapperProps.style,
attributes,
defaultColors
defaultColors,
name
);
}, [
defaultColors,
Expand All @@ -85,7 +86,7 @@ function BlockForType( {
// Block level styles
wrapperProps={ wrapperProps }
// inherited styles merged with block level styles
mergedStyle={ mergedStyle }
style={ mergedStyle }
clientId={ clientId }
parentWidth={ parentWidth }
contentStyle={ contentStyle }
Expand Down
13 changes: 8 additions & 5 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ButtonEdit extends Component {
}

getBackgroundColor() {
const { attributes, colors, gradients } = this.props;
const { attributes, colors, gradients, style } = this.props;
const { backgroundColor, gradient } = attributes;

// Return named gradient value if available.
Expand All @@ -207,12 +207,13 @@ class ButtonEdit extends Component {
colorObject?.color ||
colorProps.style?.backgroundColor ||
colorProps.style?.background ||
style?.backgroundColor ||
styles.defaultButton.backgroundColor
);
}

getTextColor() {
const { attributes, colors } = this.props;
const { attributes, colors, style } = this.props;
const colorProps = getColorClassesAndStyles( attributes );

// Retrieve named color object to force inline styles for themes that
Expand All @@ -225,6 +226,7 @@ class ButtonEdit extends Component {
return (
colorObject?.color ||
colorProps.style?.color ||
style?.color ||
styles.defaultButton.color
);
}
Expand Down Expand Up @@ -375,11 +377,12 @@ class ButtonEdit extends Component {
mergeBlocks,
parentWidth,
setAttributes,
style,
} = this.props;
const {
placeholder,
text,
style,
style: buttonStyle,
url,
align = 'center',
width,
Expand All @@ -391,7 +394,7 @@ class ButtonEdit extends Component {
return null;
}

const borderRadius = style?.border?.radius;
const borderRadius = buttonStyle?.border?.radius;

const borderRadiusValue = Number.isInteger( borderRadius )
? borderRadius
Expand Down Expand Up @@ -463,7 +466,7 @@ class ButtonEdit extends Component {
} }
textAlign={ align }
placeholderTextColor={
styles.placeholderTextColor.color
style?.color || styles.placeholderTextColor.color
}
identifier="text"
tagName="p"
Expand Down
2 changes: 0 additions & 2 deletions packages/block-library/src/column/editor.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
.columnPlaceholder {
flex: 1;
padding: $block-selected-to-content;
background-color: $white;
border: $border-width dashed $gray;
border-radius: 4px;
}

.columnPlaceholderDark {
background-color: $black;
border: $border-width dashed $gray-70;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const ColumnsEditContainerWrapper = withDispatch(
)( memo( ColumnsEditContainer ) );

const ColumnsEdit = ( props ) => {
const { clientId, isSelected } = props;
const { clientId, isSelected, style } = props;
const {
columnCount,
isDefaultColumns,
Expand Down Expand Up @@ -505,7 +505,7 @@ const ColumnsEdit = ( props ) => {
}, [] );

return (
<>
<View style={ style }>
<ColumnsEditContainerWrapper
columnCount={ columnCount }
innerWidths={ memoizedInnerWidths }
Expand All @@ -520,7 +520,7 @@ const ColumnsEdit = ( props ) => {
clientId={ clientId }
isVisible={ isVisible }
/>
</>
</View>
);
};

Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/group/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function GroupEdit( {
isSelected,
isLastInnerBlockSelected,
getStylesFromColorScheme,
mergedStyle,
style,
blockWidth,
} ) {
const { align } = attributes;
Expand Down Expand Up @@ -79,13 +79,13 @@ function GroupEdit( {
<View
style={ [
isSelected && hasInnerBlocks && styles.innerBlocks,
mergedStyle,
style,
isSelected &&
hasInnerBlocks &&
mergedStyle?.backgroundColor &&
style?.backgroundColor &&
styles.hasBackgroundAppender,
isLastInnerBlockSelected &&
mergedStyle?.backgroundColor &&
style?.backgroundColor &&
styles.isLastInnerBlockSelected,
] }
>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function HeadingEdit( {
setAttributes,
mergeBlocks,
onReplace,
mergedStyle,
style,
clientId,
} ) {
const { textAlign, content, level, placeholder } = attributes;
Expand All @@ -34,7 +34,7 @@ function HeadingEdit( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
style: mergedStyle,
style,
} );

return (
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function ListEdit( {
setAttributes,
mergeBlocks,
onReplace,
style,
} ) {
const { ordered, values, type, reversed, start, placeholder } = attributes;
const tagName = ordered ? 'ol' : 'ul';
Expand Down Expand Up @@ -132,7 +133,9 @@ export default function ListEdit( {
</>
);

const blockProps = useBlockProps();
const blockProps = useBlockProps( {
style,
} );

return (
<>
Expand Down
36 changes: 17 additions & 19 deletions packages/block-library/src/media-text/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class MediaTextEdit extends Component {
setAttributes,
isSelected,
isRTL,
wrapperProps,
style,
blockWidth,
} = this.props;
const {
Expand All @@ -273,14 +273,21 @@ class MediaTextEdit extends Component {
? 100
: this.state.mediaWidth || mediaWidth;
const widthString = `${ temporaryMediaWidth }%`;
const innerBlockWidth = shouldStack ? 100 : 100 - temporaryMediaWidth;
const innerBlockWidthString = `${ innerBlockWidth }%`;

const innerBlockContainerStyle = ! shouldStack
? styles.innerBlock
: {
...( mediaPosition === 'left'
? styles.innerBlockStackMediaLeft
: styles.innerBlockStackMediaRight ),
};
const innerBlockContainerStyle = [
{ width: innerBlockWidthString },
! shouldStack
? styles.innerBlock
: {
...( mediaPosition === 'left'
? styles.innerBlockStackMediaLeft
: styles.innerBlockStackMediaRight ),
},
( style?.backgroundColor || backgroundColor.color ) &&
styles.innerBlockPaddings,
];

const containerStyles = {
...styles[ 'wp-block-media-text' ],
Expand All @@ -295,14 +302,10 @@ class MediaTextEdit extends Component {
? styles[ 'is-stacked-on-mobile.has-media-on-the-right' ]
: {} ),
...( isSelected && styles[ 'is-selected' ] ),
backgroundColor:
wrapperProps?.style?.backgroundColor || backgroundColor.color,
backgroundColor: style?.backgroundColor || backgroundColor.color,
paddingBottom: 0,
};

const innerBlockWidth = shouldStack ? 100 : 100 - temporaryMediaWidth;
const innerBlockWidthString = `${ innerBlockWidth }%`;

const mediaContainerStyle = [
{ flex: 1 },
shouldStack
Expand Down Expand Up @@ -375,12 +378,7 @@ class MediaTextEdit extends Component {
>
{ this.renderMediaArea( shouldStack ) }
</View>
<View
style={ {
width: innerBlockWidthString,
...innerBlockContainerStyle,
} }
>
<View style={ innerBlockContainerStyle }>
<InnerBlocks
template={ TEMPLATE }
blockWidth={ blockWidth }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/media-text/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ $media-to-text: 12px;
padding-left: $media-to-text;
}

.innerBlockPaddings {
padding: 0 $media-to-text $media-to-text;
}

// Media STACK
.mediaStackLeft {
margin-bottom: $media-to-text;
Expand Down
10 changes: 4 additions & 6 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function ParagraphBlock( {
mergeBlocks,
onReplace,
setAttributes,
mergedStyle,
style,
clientId,
} ) {
Expand All @@ -30,12 +29,11 @@ function ParagraphBlock( {
const { align, content, placeholder } = attributes;

const styles = {
...( mergedStyle?.baseColors && {
color: mergedStyle.baseColors?.color?.text,
placeholderColor: mergedStyle.baseColors?.color?.text,
linkColor: mergedStyle.baseColors?.elements?.link?.color?.text,
...( style?.baseColors && {
color: style.baseColors?.color?.text,
placeholderColor: style.color || style.baseColors?.color?.text,
linkColor: style.baseColors?.elements?.link?.color?.text,
} ),
...mergedStyle,
...style,
};

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export default function QuoteEdit( {
onReplace,
className,
insertBlocksAfter,
mergedStyle,
style,
} ) {
const { align, value, citation } = attributes;
const blockProps = useBlockProps( {
className: classnames( className, {
[ `has-text-align-${ align }` ]: align,
} ),
style: mergedStyle,
style,
} );

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/verse/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export default function VerseEdit( {
setAttributes,
mergeBlocks,
onRemove,
style,
} ) {
const { textAlign, content } = attributes;
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
style,
} );

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/color-palette/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
Text,
} from 'react-native';
import { map, uniq } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef, useEffect } from '@wordpress/element';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';

/**
* Internal dependencies
*/
Expand Down
Loading

0 comments on commit 0de0598

Please sign in to comment.