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 - Highlight words #36028

Merged
merged 39 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3f38edb
Mobile - WIP Word selected color
Oct 6, 2021
4b8a337
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Oct 11, 2021
7d8a3af
WIP color selected
Oct 14, 2021
f05b074
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Oct 15, 2021
5caf020
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Oct 21, 2021
68a1316
Mobile - Text color support
Oct 22, 2021
cfab1c0
Mobile - Restore initial html
Oct 22, 2021
44fa89a
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Oct 22, 2021
6838ea8
Mobile - Rich text - Highlight text colors from classes
Oct 22, 2021
31f856b
Mobile - Text color - Fix getActiveColors import
Oct 22, 2021
cd701c1
Mobile - Text Color - Remove web filter
Oct 26, 2021
7bbaa4c
Mobile - Rich text - Regex fix for default editor colors
Oct 28, 2021
ab75228
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Oct 28, 2021
7a1b2cb
Mobile - Highlight word - Fixes for iOS and color indicator
Nov 2, 2021
b1231f4
Mobile - Text color - Share index with web
Nov 3, 2021
6fdc2bc
Mobile - Move text color formatting button to its own ToolbarGroup
Nov 4, 2021
5364c71
Text color - Share setColors with Mobile
Nov 4, 2021
572d01a
Mobile - Color settings - Reset button: Reduce hit slop and fix the w…
Nov 4, 2021
271e0d5
Mobile - Button component - Allow for a custom background color for t…
Nov 4, 2021
5239d53
Mobile - Text color - Set the background color in the format button
Nov 4, 2021
516c9b7
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Nov 5, 2021
f3eb9bb
Mobile - Text color format: Manually set the current format when ther…
Nov 9, 2021
c08d7b8
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Nov 24, 2021
fd53dcb
Mobile - Aztec Text format - Add mark support
Nov 29, 2021
efb1059
Mobile - Update Aztec version
Nov 29, 2021
566d412
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Nov 29, 2021
51e920b
Mobile - Rich Text - Mark formatting support for iOS
Nov 30, 2021
5cb684a
Temp for testing - Use commit reference for Aztec
Nov 30, 2021
e6db8d2
Mobile - Text Color - Fix applying format
Dec 1, 2021
6944bd9
Mobile - Button component - Adds new customContainerStyles prop
Dec 2, 2021
bf598e1
Mobile - Inline Text Color - Update styles for the color indicator
Dec 2, 2021
36b3d09
Mobile - Update changelog
Dec 3, 2021
1e2ae84
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Dec 3, 2021
801e959
Merge branch 'trunk' into rnmobile/feature/word-selected-color
Dec 9, 2021
5c816f4
Mobile - Text color - use transparentValue
Dec 9, 2021
a621e87
Mobile - Update Aztec Android version
Dec 9, 2021
ebafc44
Mobile - Text color - Inline component, use native variant of parseCSS
Dec 9, 2021
9624442
Mobile - Update Aztec iOS version
Dec 9, 2021
34eec41
Mobile - Rich Text - Update core naming to default
Dec 9, 2021
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
16 changes: 15 additions & 1 deletion packages/components/src/button/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,29 @@ export function Button( props ) {
label,
shortcut,
tooltipPosition,
isActiveStyle,
customContainerStyles,
} = props;
const preferredColorScheme = usePreferredColorScheme();

const isDisabled = ariaDisabled || disabled;

const containerStyle = [
styles.container,
customContainerStyles && { ...customContainerStyles },
];

const buttonViewStyle = {
opacity: isDisabled ? 0.3 : 1,
...( fixedRatio && styles.fixedRatio ),
...( isPressed ? styles.buttonActive : styles.buttonInactive ),
...( isPressed &&
isActiveStyle?.borderRadius && {
borderRadius: isActiveStyle.borderRadius,
} ),
...( isActiveStyle?.backgroundColor && {
backgroundColor: isActiveStyle.backgroundColor,
} ),
};

const states = [];
Expand Down Expand Up @@ -159,7 +173,7 @@ export function Button( props ) {
accessibilityHint={ hint }
onPress={ onClick }
onLongPress={ onLongPress }
style={ styles.container }
style={ containerStyle }
disabled={ isDisabled }
testID={ testID }
>
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/mobile/color-settings/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ColorSettingsMemo = memo(
gradientValue,
onGradientChange,
label,
hideNavigation,
} ) => {
useEffect( () => {
shouldEnableBottomSheetMaxHeight( true );
Expand All @@ -44,6 +45,7 @@ const ColorSettingsMemo = memo(
gradientValue,
onGradientChange,
label,
hideNavigation,
} }
>
<PaletteScreen />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { colorsUtils } from './utils';

import styles from './style.scss';

const HIT_SLOP = { top: 22, bottom: 22, left: 22, right: 22 };
const HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 };

const PaletteScreen = () => {
const route = useRoute();
Expand All @@ -38,6 +38,7 @@ const PaletteScreen = () => {
onGradientChange,
colorValue,
defaultSettings,
hideNavigation = false,
} = route.params || {};
const { segments, isGradient } = colorsUtils;
const [ currentValue, setCurrentValue ] = useState( colorValue );
Expand Down Expand Up @@ -164,10 +165,12 @@ const PaletteScreen = () => {
}
return (
<View>
<NavBar>
<NavBar.BackButton onPress={ navigation.goBack } />
<NavBar.Heading>{ label } </NavBar.Heading>
</NavBar>
{ ! hideNavigation && (
<NavBar>
<NavBar.BackButton onPress={ navigation.goBack } />
<NavBar.Heading>{ label } </NavBar.Heading>
</NavBar>
) }
<ColorPalette
setColor={ setColor }
activeColor={ currentValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}

.clearButtonContainer {
align-items: flex-end;
align-self: flex-end;
}

.clearButton {
Expand Down
3 changes: 2 additions & 1 deletion packages/format-library/src/default-formats.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import { bold } from './bold';
import { italic } from './italic';
import { link } from './link';
import { strikethrough } from './strikethrough';
import { textColor } from './text-color';

export default [ bold, italic, link, strikethrough ];
export default [ bold, italic, link, strikethrough, textColor ];
191 changes: 191 additions & 0 deletions packages/format-library/src/text-color/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useCallback, useMemo, useState } from '@wordpress/element';
import { BlockControls, useSetting } from '@wordpress/block-editor';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { Icon, textColor as textColorIcon } from '@wordpress/icons';
import { removeFormat } from '@wordpress/rich-text';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';

/**
* Internal dependencies
*/
import { getActiveColors } from './inline.js';
import { transparentValue } from './index.js';
import { default as InlineColorUI } from './inline';
import styles from './style.scss';

const name = 'core/text-color';
const title = __( 'Text color' );

const EMPTY_ARRAY = [];

function getComputedStyleProperty( element, property ) {
const {
props: { style = {} },
} = element;

if ( property === 'background-color' ) {
const { backgroundColor, baseColors } = style;

if ( backgroundColor !== 'transparent' ) {
return backgroundColor;
} else if ( baseColors && baseColors?.color?.background ) {
return baseColors?.color?.background;
}

return 'transparent';
}
}

function fillComputedColors( element, { color, backgroundColor } ) {
if ( ! color && ! backgroundColor ) {
return;
}

return {
color: color || getComputedStyleProperty( element, 'color' ),
backgroundColor: getComputedStyleProperty(
element,
'background-color'
),
};
}

function TextColorEdit( {
value,
onChange,
isActive,
activeAttributes,
contentRef,
} ) {
const allowCustomControl = useSetting( 'color.custom' );
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const [ isAddingColor, setIsAddingColor ] = useState( false );
const enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [
setIsAddingColor,
] );
const disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [
setIsAddingColor,
] );
const colorIndicatorStyle = useMemo(
() =>
fillComputedColors(
contentRef,
getActiveColors( value, name, colors )
),
[ value, colors ]
);

const hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl;

const onPressButton = useCallback( () => {
if ( hasColorsToChoose ) {
enableIsAddingColor();
} else {
onChange( removeFormat( value, name ) );
}
}, [ hasColorsToChoose, value ] );

const outlineStyle = usePreferredColorSchemeStyle(
styles[ 'components-inline-color__outline' ],
styles[ 'components-inline-color__outline--dark' ]
);

if ( ! hasColorsToChoose && ! isActive ) {
return null;
}

const isActiveStyle = {
...colorIndicatorStyle,
...( ! colorIndicatorStyle?.backgroundColor
? { backgroundColor: 'transparent' }
: {} ),
...styles[ 'components-inline-color--is-active' ],
};

const customContainerStyles =
styles[ 'components-inline-color__button-container' ];

return (
<>
<BlockControls>
<ToolbarGroup>
{ isActive && (
<View style={ outlineStyle } pointerEvents="none" />
) }

<ToolbarButton
name="text-color"
isActive={ isActive }
icon={
<Icon
icon={ textColorIcon }
style={
colorIndicatorStyle?.color && {
color: colorIndicatorStyle.color,
}
}
/>
}
title={ title }
extraProps={ {
isActiveStyle,
customContainerStyles,
} }
// If has no colors to choose but a color is active remove the color onClick
onClick={ onPressButton }
/>
</ToolbarGroup>
</BlockControls>
{ isAddingColor && (
<InlineColorUI
name={ name }
onClose={ disableIsAddingColor }
activeAttributes={ activeAttributes }
value={ value }
onChange={ onChange }
contentRef={ contentRef }
/>
) }
</>
);
}

export const textColor = {
name,
title,
tagName: 'mark',
className: 'has-inline-color',
attributes: {
style: 'style',
class: 'class',
},
/*
* Since this format relies on the <mark> tag, it's important to
* prevent the default yellow background color applied by most
* browsers. The solution is to detect when this format is used with a
* text color but no background color, and in such cases to override
* the default styling with a transparent background.
*
* @see https://github.com/WordPress/gutenberg/pull/35516
*/
__unstableFilterAttributeValue( key, value ) {
if ( key !== 'style' ) return value;
// We should not add a background-color if it's already set
if ( value && value.includes( 'background-color' ) ) return value;
const addedCSS = [ 'background-color', transparentValue ].join( ':' );
// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
// rules will already include a `;`.
return value ? [ addedCSS, value ].join( ';' ) : addedCSS;
},
edit: TextColorEdit,
};
2 changes: 1 addition & 1 deletion packages/format-library/src/text-color/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function parseCSS( css = '' ) {
}, {} );
}

function parseClassName( className = '', colorSettings ) {
export function parseClassName( className = '', colorSettings ) {
return className.split( ' ' ).reduce( ( accumulator, name ) => {
// `colorSlug` could contain dashes, so simply match the start and end.
if ( name.startsWith( 'has-' ) && name.endsWith( '-color' ) ) {
Expand Down
Loading