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

feat(#15866): % of users in a11y simulation tool #18003

Merged
merged 6 commits into from
May 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 22 additions & 16 deletions addons/a11y/src/components/VisionSimulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ import { Filters } from './ColorFilters';

const iframeId = 'storybook-preview-iframe';

interface Option {
name: string;
percentage?: number;
}

const baseList = [
'blurred vision',
'deuteranomaly',
'deuteranopia',
'protanomaly',
'protanopia',
'tritanomaly',
'tritanopia',
'achromatomaly',
'achromatopsia',
'grayscale',
] as const;
{ name: 'blurred vision', percentage: 22.9 },
{ name: 'deuteranomaly', percentage: 2.7 },
{ name: 'deuteranopia', percentage: 0.56 },
{ name: 'protanomaly', percentage: 0.66 },
{ name: 'protanopia', percentage: 0.59 },
{ name: 'tritanomaly', percentage: 0.01 },
{ name: 'tritanopia', percentage: 0.016 },
{ name: 'achromatomaly', percentage: 0.00001 },
{ name: 'achromatopsia', percentage: 0.0001 },
{ name: 'grayscale' },
] as Option[];

type Filter = typeof baseList[number] | null;
type Filter = Option | null;

const getFilter = (filter: Filter) => {
if (!filter) {
return 'none';
}
if (filter === 'blurred vision') {
if (filter.name === 'blurred vision') {
return 'blur(2px)';
}
if (filter === 'grayscale') {
if (filter.name === 'grayscale') {
return 'grayscale(100%)';
}
return `url('#${filter}')`;
Expand Down Expand Up @@ -81,8 +86,9 @@ const getColorList = (active: Filter, set: (i: Filter) => void): Link[] => [
]
: []),
...baseList.map((i) => ({
id: i,
title: i.charAt(0).toUpperCase() + i.slice(1),
id: i.name,
title: i.name.charAt(0).toUpperCase() + i.name.slice(1),
description: i.percentage !== undefined ? `${i.percentage}% of users` : undefined,
onClick: () => {
set(i);
},
Expand Down
34 changes: 25 additions & 9 deletions lib/components/src/tooltip/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const Right = styled.span<RightProps>(
);

const Center = styled.span({
flex: 1,
textAlign: 'left',
display: 'inline-flex',

Expand All @@ -82,6 +81,18 @@ const Center = styled.span({
},
});

const Column = styled.span({
jsomsanith marked this conversation as resolved.
Show resolved Hide resolved
flex: 1,
display: 'flex',
flexDirection: 'column',
alignItems: 'stretch',
});

const Description = styled.span({
fontSize: '0.85em',
color: 'gray',
});

export interface CenterTextProps {
active?: boolean;
disabled?: boolean;
Expand Down Expand Up @@ -188,6 +199,7 @@ export interface ListItemProps extends Omit<ComponentProps<typeof Item>, 'href'
loading?: boolean;
left?: ReactNode;
title?: ReactNode;
description?: ReactNode;
center?: ReactNode;
right?: ReactNode;
active?: boolean;
Expand All @@ -200,6 +212,7 @@ const ListItem: FunctionComponent<ListItemProps> = ({
loading,
left,
title,
description,
center,
right,
active,
Expand All @@ -216,14 +229,17 @@ const ListItem: FunctionComponent<ListItemProps> = ({
<Item {...commonProps} {...rest} {...itemProps}>
{left && <Left {...commonProps}>{left}</Left>}
{title || center ? (
<Center>
{title && (
<Title {...commonProps} loading={loading}>
{title}
</Title>
)}
{center && <CenterText {...commonProps}>{center}</CenterText>}
</Center>
<Column>
<Center>
{title && (
<Title {...commonProps} loading={loading}>
{title}
</Title>
)}
{center && <CenterText {...commonProps}>{center}</CenterText>}
</Center>
{description && <Description>{description}</Description>}
</Column>
) : null}
{right && <Right {...commonProps}>{right}</Right>}
</Item>
Expand Down
14 changes: 2 additions & 12 deletions lib/components/src/tooltip/TooltipLinkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const List = styled.div<{}>(
minWidth: 180,
overflow: 'hidden',
overflowY: 'auto',
maxHeight: 13.5 * 32, // 11.5 items
maxHeight: 10 * 50, // 10 items with description
},
({ theme }) => ({
borderRadius: theme.appBorderRadius * 2,
Expand All @@ -28,7 +28,6 @@ export interface TooltipLinkListProps {

const Item: FunctionComponent<TooltipLinkListProps['links'][number]> = (props) => {
const { LinkWrapper, onClick: onClickFromProps, ...rest } = props;
const { title, href, active } = rest;
const onClick = useCallback(
(event: SyntheticEvent) => {
onClickFromProps(event, rest);
Expand All @@ -38,16 +37,7 @@ const Item: FunctionComponent<TooltipLinkListProps['links'][number]> = (props) =

const hasOnClick = !!onClickFromProps;

return (
<ListItem
title={title}
active={active}
href={href}
LinkWrapper={LinkWrapper}
{...rest}
{...(hasOnClick ? { onClick } : {})}
/>
);
return <ListItem LinkWrapper={LinkWrapper} {...rest} {...(hasOnClick ? { onClick } : {})} />;
};

export const TooltipLinkList: FunctionComponent<TooltipLinkListProps> = ({
Expand Down