Skip to content

Commit

Permalink
feat: make use of Icon component for Link with iconRight
Browse files Browse the repository at this point in the history
  • Loading branch information
thekidnamedkd committed Jan 24, 2024
1 parent f769a67 commit 6827b52
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/icon/iconList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import WysiwygListOrdered from '../../assets/icons/wysiwyg-list-ordered.svg';
import WysiwygListUnordered from '../../assets/icons/wysiwyg-list-unordered.svg';
import { IconType } from './iconType';

type IconComponent = React.FC<SVGProps<SVGSVGElement>>;
export type IconComponent = React.FC<SVGProps<SVGSVGElement>>;

export const iconList: Record<IconType, IconComponent> = {
[IconType.ADD]: Add,
Expand Down
2 changes: 1 addition & 1 deletion src/components/link/link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Primary: Story = {
variant: 'primary',
},
render: ({ showIconRight, ...props }) => (
<Link {...props} iconRight={showIconRight ? IconType.APP_GOVERNANCE : undefined} />
<Link {...props} iconRight={showIconRight ? IconType.UPPER_RIGHT_ARROW : undefined} />
),
};

Expand Down
6 changes: 2 additions & 4 deletions src/components/link/link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import React from 'react';
import { iconList } from '../icon/iconList';
import { Icon } from '../icon';
import type { ILinkProps, LinkVariant } from './link.api';

export const variantToLabelClassNames: Record<LinkVariant, string[]> = {
Expand Down Expand Up @@ -41,8 +41,6 @@ export const Link = React.forwardRef<HTMLAnchorElement, ILinkProps>(
disabled ? disabledStyle : variantToLabelClassNames[variant],
'test-focus',
);
const IconComponent = iconRight ? iconList[iconRight] : null;
const iconSize: React.CSSProperties = { height: iconHeight ? `${iconHeight}px` : 'auto', width: 'auto' };
const descriptionClassName = classNames('truncate', disabled ? disabledStyle : 'text-neutral-500');

return (
Expand All @@ -58,7 +56,7 @@ export const Link = React.forwardRef<HTMLAnchorElement, ILinkProps>(
>
<div className="flex items-center gap-x-2 truncate">
{label}
{IconComponent && <IconComponent style={iconSize} />}
{iconRight && <Icon icon={iconRight} size="sm" />}
</div>
{description && <p className={descriptionClassName}>{description}</p>}
</a>
Expand Down

0 comments on commit 6827b52

Please sign in to comment.