Skip to content

Commit

Permalink
feat(icons): add prefix to context
Browse files Browse the repository at this point in the history
  • Loading branch information
Niznikr committed Jul 20, 2023
1 parent 8138782 commit cbe81a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/icons/src/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const Icon = ({
}: IconProps) => {
const sizeClass = size ? styles[size] : false;
const classes = cx(styles.icon, sizeClass, subtle && styles.subtle, `icon-${name}`, className);
const prefix = `svg-${useId()}`;
const uniqueId = `svg-${useId()}`;
const isAriaHidden = ariaHidden ?? (!ariaLabelledBy && !ariaLabel);
const titleId = title && `${prefix}-${name}-title`;
const descriptionId = description && `${prefix}-${name}-description`;
const titleId = title && `${uniqueId}-${name}-title`;
const descriptionId = description && `${uniqueId}-${name}-description`;

const { path: contextPath } = useContext(IconContext);
const iconId = `lp-icon-${name}`;
const { path: contextPath, prefix } = useContext(IconContext);
const iconPrefix = prefix === undefined ? 'lp-icon-' : prefix;
const spritePath = contextPath === undefined ? '/static/sprite.svg' : contextPath;

return (
Expand All @@ -56,7 +56,7 @@ const Icon = ({
>
{title && <title id={titleId}>{title}</title>}
{description && <desc id={descriptionId}>{description}</desc>}
<use href={`${spritePath}#${iconId}`} />
<use href={`${spritePath}#${iconPrefix}${name}`} />
</svg>
</span>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/icons/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createContext } from 'react';

type IconContextState = {
path?: string;
prefix?: string;
};

const IconContext = createContext<IconContextState>({ path: undefined });
const IconContext = createContext<IconContextState>({ path: undefined, prefix: undefined });

export { IconContext };
export type { IconContextState };

0 comments on commit cbe81a8

Please sign in to comment.