Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[RNMobile] Use default placeholder text color for native List Item (#…
…43353)

* Use default placeholder text color for native List Item

* Move list item placeholder hex value to stylesheet

* Resolve test failure

* Add opacity to list block placeholder color styles

* Update List block v2 placholder currentTextColor

* Mobile - List Item - Check if currentTextColor is not undefined and moves opacity value into a const

* Mobile - List Item - Add optional chaining for style.color

Co-authored-by: Gerardo <[email protected]>
  • Loading branch information
derekblank and Gerardo authored Aug 25, 2022
commit 94b8447887f4dd7e3897baa9f849a1898877abb4
32 changes: 31 additions & 1 deletion packages/block-library/src/list-item/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useState, useCallback } from '@wordpress/element';

Expand All @@ -26,6 +27,8 @@ import { IndentUI } from './edit.js';
import styles from './style.scss';
import ListStyleType from './list-style-type';

const OPACITY = '9e';

export default function ListItemEdit( {
attributes,
setAttributes,
Expand Down Expand Up @@ -84,11 +87,35 @@ export default function ListItemEdit( {
const blockProps = useBlockProps( {
...( hasInnerBlocks && styles[ 'wp-block-list-item__nested-blocks' ] ),
} );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: [ 'core/list' ],
useCompactList: true,
} );

// Set default placeholder text color from light/dark scheme or base colors
const defaultPlaceholderFromScheme = usePreferredColorSchemeStyle(
styles[ 'wp-block-list-item__list-item-placeholder' ],
styles[ 'wp-block-list-item__list-item-placeholder--dark' ]
);

const currentTextColor = style?.color || style?.baseColors?.color?.text;

const defaultPlaceholderTextColor = currentTextColor
? currentTextColor
: defaultPlaceholderFromScheme?.color;

// Add hex opacity to default placeholder text color and style object
const defaultPlaceholderTextColorWithOpacity =
defaultPlaceholderTextColor + OPACITY;

const styleWithPlaceholderOpacity = {
...style,
...( style?.color && {
placeholderColor: style.color + OPACITY,
} ),
};

const onSplit = useSplit( clientId );
const onMerge = useMerge( clientId );
const onLayout = useCallback( ( { nativeEvent } ) => {
Expand Down Expand Up @@ -128,12 +155,15 @@ export default function ListItemEdit( {
}
value={ content }
placeholder={ placeholder || __( 'List' ) }
placeholderTextColor={
defaultPlaceholderTextColorWithOpacity
}
onSplit={ onSplit }
onMerge={ onMerge }
onReplace={ ( blocks, ...args ) => {
onReplace( convertToListItems( blocks ), ...args );
} }
style={ style }
style={ styleWithPlaceholderOpacity }
deleteEnter={ true }
containerWidth={ contentWidth }
/>
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/list-item/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@
.wp-block-list-item__list-item-container {
margin-right: 8;
}

.wp-block-list-item__list-item-placeholder {
color: $gray;
}

.wp-block-list-item__list-item-placeholder--dark {
color: $gray-50;
}