Skip to content

Commit

Permalink
CustomSelectControl V2: allow wrapping item hint to new line (WordPre…
Browse files Browse the repository at this point in the history
…ss#62848)

* Wrap item hint when it doesn't fit

* Set more legacy classnames

* Use padding instead of margin

* CHANGELOG

* Move hint styles to bottom of file, add more specificity to override v1 styles

* Better defaults for V2 legacy styles

* Use line-height variable

* Add block margin to hint for better spacing when collapsed

* More renaming

* Today I (re-)learned row and column gap

* Comment out legacy classnames, remove && specificity hack in styles

* Swap row-gap with margin-block on the hint for better vertical spacing when on separate rows

--- 

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
4 people authored and carstingaxion committed Jul 18, 2024
1 parent 479f342 commit 2e97bb4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `CustomSelectControlV2`: add root element wrapper. ([#62803](https://github.com/WordPress/gutenberg/pull/62803))
- `CustomSelectControlV2`: fix popover styles. ([#62821](https://github.com/WordPress/gutenberg/pull/62821))
- `CustomSelectControlV2`: fix trigger text alignment in RTL languages ([#62869](https://github.com/WordPress/gutenberg/pull/62869)).
- `CustomSelectControlV2`: allow wrapping item hint to new line ([#62848](https://github.com/WordPress/gutenberg/pull/62848)).
- `CustomSelectControlV2`: fix select popover content overflow. ([#62844](https://github.com/WordPress/gutenberg/pull/62844))
- Extract `TimeInput` component from `TimePicker` ([#60613](https://github.com/WordPress/gutenberg/pull/60613)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
const children = options.map(
( { name, key, __experimentalHint, style, className } ) => {
const withHint = (
<Styled.WithHintWrapper>
<Styled.WithHintItemWrapper>
<span>{ name }</span>
<Styled.ExperimentalHintItem className="components-custom-select-control__item-hint">
<Styled.WithHintItemHint
// TODO: Legacy classname. Add V1 styles are removed from the codebase
// className="components-custom-select-control__item-hint"
>
{ __experimentalHint }
</Styled.ExperimentalHintItem>
</Styled.WithHintWrapper>
</Styled.WithHintItemHint>
</Styled.WithHintItemWrapper>
);

return (
Expand All @@ -78,7 +81,15 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
value={ name }
children={ __experimentalHint ? withHint : name }
style={ style }
className={ className }
className={ clsx(
// TODO: Legacy classname. Add V1 styles are removed from the codebase
// 'components-custom-select-control__item',
className
// TODO: Legacy classname. Add V1 styles are removed from the codebase
// {
// 'has-hint': __experimentalHint,
// }
) }
/>
);
}
Expand All @@ -94,7 +105,10 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
return (
<Styled.SelectedExperimentalHintWrapper>
{ currentValue }
<Styled.SelectedExperimentalHintItem className="components-custom-select-control__hint">
<Styled.SelectedExperimentalHintItem
// TODO: Legacy classname. Add V1 styles are removed from the codebase
// className="components-custom-select-control__hint"
>
{ currentHint?.__experimentalHint }
</Styled.SelectedExperimentalHintItem>
</Styled.SelectedExperimentalHintWrapper>
Expand Down Expand Up @@ -125,7 +139,8 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
size={ translatedSize }
store={ store }
className={ clsx(
'components-custom-select-control',
// TODO: Legacy classname. Add V1 styles are removed from the codebase
// 'components-custom-select-control',
classNameProp
) }
isLegacy
Expand Down
62 changes: 34 additions & 28 deletions packages/components/src/custom-select-control-v2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,10 @@ import type { CustomSelectButtonSize } from './types';

const ITEM_PADDING = space( 2 );

const truncateStyles = css`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

export const WithHintWrapper = styled.div`
display: flex;
justify-content: space-between;
flex: 1;
`;

export const SelectedExperimentalHintWrapper = styled.div`
${ truncateStyles }
`;

export const SelectedExperimentalHintItem = styled.span`
color: ${ COLORS.theme.gray[ 600 ] };
margin-inline-start: ${ space( 2 ) };
`;

export const ExperimentalHintItem = styled.span`
color: ${ COLORS.theme.gray[ 600 ] };
text-align: right;
margin-inline-end: ${ space( 1 ) };
`;

export const SelectLabel = styled( Ariakit.SelectLabel )`
font-size: 11px;
font-weight: 500;
line-height: 1.4;
line-height: ${ CONFIG.fontLineHeightBase };
text-transform: uppercase;
margin-bottom: ${ space( 2 ) };
`;
Expand Down Expand Up @@ -129,6 +102,7 @@ export const SelectPopover = styled( Ariakit.SelectPopover )`
`;

export const SelectItem = styled( Ariakit.SelectItem )`
cursor: default;
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -154,3 +128,35 @@ export const SelectedItemCheck = styled( Ariakit.SelectItemCheck )`
margin-inline-start: ${ ITEM_PADDING };
font-size: 24px; // Size of checkmark icon
`;

const truncateStyles = css`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

export const SelectedExperimentalHintWrapper = styled.div`
${ truncateStyles }
`;

export const SelectedExperimentalHintItem = styled.span`
color: ${ COLORS.theme.gray[ 600 ] };
margin-inline-start: ${ space( 2 ) };
`;

export const WithHintItemWrapper = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
flex: 1;
column-gap: ${ space( 4 ) };
`;

export const WithHintItemHint = styled.span`
color: ${ COLORS.theme.gray[ 600 ] };
text-align: initial;
line-height: ${ CONFIG.fontLineHeightBase };
padding-inline-end: ${ space( 1 ) };
margin-block: ${ space( 1 ) };
`;

0 comments on commit 2e97bb4

Please sign in to comment.