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

[Mobile] - Search block - Colors support #35511

Merged
merged 7 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 46 additions & 12 deletions packages/block-library/src/search/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function SearchEdit( {
setAttributes,
className,
blockWidth,
style,
} ) {
const [ isButtonSelected, setIsButtonSelected ] = useState( false );
const [ isLabelSelected, setIsLabelSelected ] = useState( false );
Expand Down Expand Up @@ -222,12 +223,18 @@ export default function SearchEdit( {
styles.plainTextInput,
styles.plainTextInputDark
),
style?.baseColors?.color && { color: style?.baseColors?.color?.text },
];

const placeholderStyle = usePreferredColorSchemeStyle(
styles.plainTextPlaceholder,
styles.plainTextPlaceholderDark
);
const placeholderStyle = {
...usePreferredColorSchemeStyle(
styles.plainTextPlaceholder,
styles.plainTextPlaceholderDark
),
...( style?.baseColors?.color && {
color: style?.baseColors?.color?.text,
} ),
};

const searchBarStyle = [
styles.searchBarContainer,
Expand Down Expand Up @@ -332,18 +339,45 @@ export default function SearchEdit( {
? ''
: __( 'Add button text' );

const baseButtonStyles = {
...style?.baseColors?.blocks?.[ 'core/button' ]?.color,
...attributes?.style?.color,
...( style?.color && { text: style.color } ),
};

const richTextButtonContainerStyle = [
styles.buttonContainer,
isLongButton && styles.buttonContainerWide,
baseButtonStyles?.background && {
backgroundColor: baseButtonStyles.background,
borderWidth: 0,
},
style?.backgroundColor && {
backgroundColor: style.backgroundColor,
borderWidth: 0,
},
];

const richTextButtonStyle = {
...styles.richTextButton,
...( baseButtonStyles?.text && {
color: baseButtonStyles.text,
placeholderColor: baseButtonStyles.text,
} ),
};

const iconStyles = {
...styles.icon,
...( baseButtonStyles?.text && { fill: baseButtonStyles.text } ),
};

const renderButton = () => {
return (
<View
style={ [
styles.buttonContainer,
isLongButton && styles.buttonContainerWide,
] }
>
<View style={ richTextButtonContainerStyle }>
{ buttonUseIcon && (
<Icon
icon={ search }
{ ...styles.icon }
{ ...iconStyles }
onLayout={ onLayoutButton }
/>
) }
Expand All @@ -364,7 +398,7 @@ export default function SearchEdit( {
className="wp-block-search__button"
identifier="text"
tagName="p"
style={ styles.richTextButton }
style={ richTextButtonStyle }
placeholder={ buttonPlaceholderText }
value={ buttonText }
withoutInteractiveFormatting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ exports[`Search Block renders block with button inside option 1`] = `
Array [
false,
undefined,
undefined,
],
undefined,
]
Expand All @@ -109,6 +110,8 @@ exports[`Search Block renders block with button inside option 1`] = `
Array [
undefined,
false,
undefined,
undefined,
]
}
>
Expand Down Expand Up @@ -275,6 +278,7 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
Array [
undefined,
undefined,
undefined,
],
undefined,
]
Expand All @@ -287,6 +291,8 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
Array [
undefined,
false,
undefined,
undefined,
]
}
>
Expand Down Expand Up @@ -335,6 +341,7 @@ exports[`Search Block renders block with label hidden matches snapshot 1`] = `
Array [
undefined,
undefined,
undefined,
],
undefined,
]
Expand All @@ -347,6 +354,8 @@ exports[`Search Block renders block with label hidden matches snapshot 1`] = `
Array [
undefined,
false,
undefined,
undefined,
]
}
>
Expand Down Expand Up @@ -513,6 +522,7 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
Array [
undefined,
undefined,
undefined,
],
undefined,
]
Expand All @@ -525,6 +535,8 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
Array [
undefined,
false,
undefined,
undefined,
]
}
>
Expand Down Expand Up @@ -682,6 +694,7 @@ exports[`Search Block renders with no-button option matches snapshot 1`] = `
Array [
undefined,
undefined,
undefined,
],
undefined,
]
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For each user feature we should also add a importance categorization label to i
-->

## Unreleased
- [**] Search block - Text and background color support [#35511]

## 1.64.0
- [*] [Embed block] Fix inline preview cut-off when editing URL [#35321]
Expand Down