Skip to content

Commit

Permalink
Updated Icons to be more explicit thanks to Jono
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelArestad committed Aug 1, 2022
1 parent fc334e3 commit c50eff0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
6 changes: 3 additions & 3 deletions code/lib/components/src/icon/icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { styled, css } from '@storybook/theming';

import { Icons } from './icon';
import { icons } from './icons';
import { icons, IconKey } from './icons';

const Meta = styled.div`
color: #666;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const Labels = () => (
<List>
{Object.keys(icons).map((key) => (
<Item key={key}>
<Icons icon={key as keyof typeof icons} aria-hidden />
<Icons icon={key as IconKey} aria-hidden />
<Meta>{key}</Meta>
</Item>
))}
Expand All @@ -81,7 +81,7 @@ export const NoLabels = () => (
<List>
{Object.keys(icons).map((key) => (
<Item minimal key={key}>
<Icons icon={key as keyof typeof icons} aria-label={key} />
<Icons icon={key as IconKey} aria-label={key} />
</Item>
))}
</List>
Expand Down
17 changes: 5 additions & 12 deletions code/lib/components/src/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@ const Svg = styled.svg`
}
`;

/**
* An Icon is a piece of visual element, but we must ensure its accessibility while using it.
* It can have 2 purposes:
*
* - *decorative only*: for example, it illustrates a label next to it. We must ensure that it is ignored by screen readers, by setting `aria-hidden` attribute (ex: `<Icon icon="check" aria-hidden />`)
* - *non-decorative*: it means that it delivers information. For example, an icon as only child in a button. The meaning can be obvious visually, but it must have a proper text alternative via `aria-label` for screen readers. (ex: `<Icon icon="print" aria-label="Print this document" />`)
*/
export interface IconsProps {
icon?: IconType;
symbol?: IconType;
export interface IconsProps extends ComponentProps<typeof Svg> {
icon: IconType;
useSymbol?: boolean;
}

export const Icons: FunctionComponent<IconsProps> = ({ icon, symbol, ...props }: IconsProps) => {
export const Icons: FunctionComponent<IconsProps> = ({ icon, useSymbol, ...props }: IconsProps) => {
return (
<Svg viewBox="0 0 14 14" width="14px" height="14px" {...props}>
{symbol ? <use xlinkHref={`#icon--${symbol}`} /> : icons[icon]}
{useSymbol ? <use xlinkHref={`#icon--${icon}`} /> : icons[icon]}
</Svg>
);
};
Expand Down
8 changes: 4 additions & 4 deletions code/lib/ui/src/components/sidebar/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const GroupNode: FunctionComponent<
> = React.memo(({ children, isExpanded = false, isExpandable = false, ...props }) => (
<BranchNode isExpandable={isExpandable} tabIndex={-1} {...props}>
{isExpandable ? <CollapseIcon isExpanded={isExpanded} /> : null}
<TypeIcon symbol="folder" color="primary" />
<TypeIcon icon="folder" useSymbol color="primary" />
{children}
</BranchNode>
));
Expand All @@ -156,7 +156,7 @@ export const ComponentNode: FunctionComponent<ComponentProps<typeof BranchNode>>
({ theme, children, isExpanded, isExpandable, isSelected, ...props }) => (
<BranchNode isExpandable={isExpandable} tabIndex={-1} {...props}>
{isExpandable && <CollapseIcon isExpanded={isExpanded} />}
<TypeIcon symbol="component" color="secondary" />
<TypeIcon icon="component" useSymbol color="secondary" />
{children}
</BranchNode>
)
Expand All @@ -166,15 +166,15 @@ export const DocumentNode: FunctionComponent<
ComponentProps<typeof LeafNode> & { docsMode: boolean }
> = React.memo(({ theme, children, docsMode, ...props }) => (
<LeafNode tabIndex={-1} {...props}>
<TypeIcon symbol="document" docsMode={docsMode} />
<TypeIcon icon="document" useSymbol docsMode={docsMode} />
{children}
</LeafNode>
));

export const StoryNode: FunctionComponent<ComponentProps<typeof LeafNode>> = React.memo(
({ theme, children, ...props }) => (
<LeafNode tabIndex={-1} {...props}>
<TypeIcon symbol="bookmarkhollow" />
<TypeIcon icon="bookmarkhollow" useSymbol />
{children}
</LeafNode>
)
Expand Down

0 comments on commit c50eff0

Please sign in to comment.