-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request adds the icon button component to the designs system.
- Loading branch information
Showing
6 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { IconButton } from './icon-button'; | ||
import { CalendarIcon, LocationIcon, ProfileIcon, TimeIcon } from '../icons'; | ||
|
||
const meta: Meta<typeof IconButton> = { | ||
title: 'Components/Icon Button', | ||
component: IconButton, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = { | ||
args: { | ||
href: '#', | ||
children: 'Username', | ||
Icon: ProfileIcon, | ||
}, | ||
}; | ||
|
||
export const BaseColor: Story = { | ||
args: { | ||
href: '#', | ||
children: 'Timestamp', | ||
Icon: TimeIcon, | ||
variant: 'base', | ||
}, | ||
}; | ||
|
||
export const Location: Story = { | ||
args: { | ||
href: '#', | ||
children: 'Location', | ||
Icon: LocationIcon, | ||
variant: 'base', | ||
}, | ||
}; | ||
|
||
export const Calendar: Story = { | ||
args: { | ||
href: '#', | ||
children: 'Joined', | ||
Icon: CalendarIcon, | ||
variant: 'base', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { ComponentType, FC, LinkHTMLAttributes } from 'react'; | ||
import classnames from 'classnames'; | ||
import { IconProps } from '../icons/iconUtils'; | ||
|
||
export type IconButton<T> = { | ||
href: string; | ||
children: string; | ||
variant?: 'primary' | 'base'; | ||
linkComponent?: FC<T>; | ||
Icon: ComponentType<IconProps>; | ||
} & Omit<T, 'className' | 'target' | 'rel'>; | ||
|
||
export const IconButton = < | ||
T extends { | ||
className?: string; | ||
rel?: string; | ||
target?: string; | ||
} = LinkHTMLAttributes<HTMLElement>, | ||
>({ | ||
children, | ||
linkComponent, | ||
variant = 'primary', | ||
Icon, | ||
...props | ||
}: IconButton<T>) => { | ||
const LinkComponent: FC<T> | 'a' = linkComponent || 'a'; | ||
const colorClasses = classnames({ | ||
'text-primary-600 hover:text-primary-900': variant === 'primary', | ||
'text-base-600 hover:text-base-900 hover:fill-error': variant === 'base', | ||
}); | ||
|
||
return ( | ||
<LinkComponent | ||
/* explicitly set props to any instead of writing the whole statement for the sake of simplicity: | ||
* IntrinsicAttributes & T & ClassAttributes<HTMLAnchorElement> & AnchorHTMLAttributes<HTMLAnchorElement> | ||
* It should have no effect on typings for the user and therefor we consider it as best to keep the code simple. | ||
*/ | ||
/* eslint-disable-next-line */ | ||
{...(props as any)} | ||
className={classnames(' flex items-center gap-xxs transition-colors duration-300 mb-font-label-s', colorClasses)}> | ||
{<Icon size={'s'} color={'inherit'} />} | ||
<span>{children}</span> | ||
</LinkComponent> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { IconButton } from './icon-button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters