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

Try: Remove segmented control vertical separators #35497

Merged
merged 4 commits into from
Oct 11, 2021
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
11 changes: 0 additions & 11 deletions packages/components/src/toggle-group-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ export const ButtonContentView = styled.div`
transform: translate( -50%, -50% );
`;

export const SeparatorView = styled.div`
background: ${ CONFIG.colorDivider };
height: calc( 100% - 4px - 4px );
position: absolute;
right: 0;
top: 4px;
transition: background ${ CONFIG.transitionDuration } linear;
${ reduceMotion( 'transition' ) }
width: 1px;
`;

export const separatorActive = css`
background: transparent;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ import * as styles from './styles';
import type { ToggleGroupControlButtonProps } from './types';
import { useCx } from '../utils/hooks';

const {
ButtonContentView,
LabelPlaceholderView,
LabelView,
SeparatorView,
} = styles;
const { ButtonContentView, LabelPlaceholderView, LabelView } = styles;

function ToggleGroupControlButton( {
className,
forwardedRef,
isBlock = false,
label,
showSeparator,
value,
...props
}: ToggleGroupControlButtonProps ) {
Expand Down Expand Up @@ -56,17 +50,8 @@ function ToggleGroupControlButton( {
{ label }
</LabelPlaceholderView>
</Radio>
<ToggleGroupControlSeparator isActive={ ! showSeparator } />
</LabelView>
);
}

const ToggleGroupControlSeparator = memo(
( { isActive }: { isActive: boolean } ) => {
const cx = useCx();
const classes = cx( isActive && styles.separatorActive );
return <SeparatorView aria-hidden className={ classes } />;
}
);

export default memo( ToggleGroupControlButton );
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,9 @@ import {
WordPressComponentProps,
} from '../ui/context';
import ToggleGroupControlButton from './toggle-group-control-button';
import type {
ToggleGroupControlOptionProps,
ToggleGroupControlContextProps,
} from './types';
import type { ToggleGroupControlOptionProps } from './types';
import { useToggleGroupControlContext } from './toggle-group-control-context';

function getShowSeparator(
toggleGroupControlContext: ToggleGroupControlContextProps,
index: number
) {
const { currentId, items, state } = toggleGroupControlContext;
if ( items.length < 3 ) {
return false;
}
const targetNodeExists =
items.find( ( { id } ) => id === currentId )?.ref?.current?.dataset
?.value === state;
const isLast = index === items.length - 1;
// If no target node exists, don't show the separator after the last item.
if ( ! targetNodeExists ) {
return ! isLast;
}
const isActive = items[ index ]?.id === currentId;
const isNextActive = items[ index + 1 ]?.id === currentId;
return ! ( isActive || isNextActive || isLast );
}

function ToggleGroupControlOption(
props: WordPressComponentProps< ToggleGroupControlOptionProps, 'input' >,
forwardedRef: import('react').Ref< any >
Expand All @@ -53,17 +29,12 @@ function ToggleGroupControlOption(
{ ...props, id },
'ToggleGroupControlOption'
);
const index = toggleGroupControlContext.items.findIndex(
( item ) => item.id === buttonProps.id
);
const showSeparator = getShowSeparator( toggleGroupControlContext, index );
return (
<ToggleGroupControlButton
ref={ forwardedRef }
{ ...{
...toggleGroupControlContext,
...buttonProps,
showSeparator,
} }
/>
);
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/toggle-group-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export type ToggleGroupControlButtonProps = {
isBlock?: boolean;
label: string;
'aria-label'?: string;
showSeparator?: boolean;
value?: ReactText;
state?: any;
};
Expand Down