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

ItemGroup: experimenting with chevron icon #36654

Merged
merged 2 commits into from
Nov 23, 2021
Merged
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
84 changes: 83 additions & 1 deletion packages/components/src/item-group/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
* External dependencies
*/
import { boolean, select } from '@storybook/addon-knobs';
import { css } from '@emotion/react';
import styled from '@emotion/styled';

/**
* WordPress dependencies
*/
import { typography } from '@wordpress/icons';
import { typography, chevronRight } from '@wordpress/icons';
import { useMemo } from '@wordpress/element';
import { isRTL } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useCx } from '../../utils';
import { ItemGroup, Item } from '..';
import Button from '../../button';
import { FlexItem, FlexBlock } from '../../flex';
Expand Down Expand Up @@ -117,6 +122,58 @@ const SimpleColorSwatch = ( { color, style } ) => (
/>
);

const ChevronWrapper = styled( FlexItem )`
display: block;
fill: currentColor;
transition: transform 0.15s ease-out;
`;

const ItemWithChevron = ( {
children,
className,
alwaysVisible,
...otherProps
} ) => {
const isRtlLayout = isRTL();
const cx = useCx();

const appearingChevron = css`
&:not( :hover ):not( :focus ) ${ ChevronWrapper } {
display: none;
}
`;

const itemClassName = useMemo(
() => cx( ! alwaysVisible && appearingChevron, className ),
[ alwaysVisible, className ]
);

const chevronIconClassName = useMemo(
() =>
cx( css`
display: block;
fill: currentColor;
transform: ${ isRtlLayout ? 'scaleX( -100% )' : 'none' };
` ),
[ isRtlLayout ]
);

return (
<Item { ...otherProps } className={ itemClassName }>
<HStack justify="flex-start">
<FlexBlock>{ children }</FlexBlock>
<ChevronWrapper>
<Icon
className={ chevronIconClassName }
icon={ chevronRight }
size={ 24 }
/>
</ChevronWrapper>
</HStack>
</Item>
);
};

export const complexLayouts = () => {
const colors = [
{
Expand Down Expand Up @@ -177,6 +234,31 @@ export const complexLayouts = () => {
</FlexItem>
</HStack>
</Item>

<ItemWithChevron onClick={ () => alert( 'Single color setting' ) }>
<HStack justify="flex-start">
<SimpleColorSwatch
color="#2FB63F"
style={ { flexShrink: 0 } }
/>

<Truncate>Chevron on hover and focus</Truncate>
</HStack>
</ItemWithChevron>

<ItemWithChevron
alwaysVisible
onClick={ () => alert( 'Single color setting' ) }
>
<HStack justify="flex-start">
<SimpleColorSwatch
color="#D175D0"
style={ { flexShrink: 0 } }
/>

<Truncate>Chevron always visible</Truncate>
</HStack>
</ItemWithChevron>
</ItemGroup>
);
};
Expand Down