-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): added icon button component, updated secondary button style…
… and added select to barrel export
- Loading branch information
Showing
7 changed files
with
205 additions
and
9 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
60 changes: 60 additions & 0 deletions
60
frontend/src/components/v2/IconButton/IconButton.stories.tsx
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,60 @@ | ||
import { faPlus } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { IconButton } from './IconButton'; | ||
|
||
const meta: Meta<typeof IconButton> = { | ||
title: 'Components/IconButton', | ||
component: IconButton, | ||
tags: ['v2'], | ||
argTypes: { | ||
isRounded: { | ||
defaultValue: true, | ||
type: 'boolean' | ||
}, | ||
ariaLabel: { | ||
defaultValue: 'Some buttons...' | ||
} | ||
} | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof IconButton>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args | ||
export const Primary: Story = { | ||
args: { | ||
children: <FontAwesomeIcon icon={faPlus} /> | ||
} | ||
}; | ||
|
||
export const Secondary: Story = { | ||
args: { | ||
children: <FontAwesomeIcon icon={faPlus} />, | ||
colorSchema: 'secondary', | ||
variant: 'outline' | ||
} | ||
}; | ||
|
||
export const Danger: Story = { | ||
args: { | ||
children: <FontAwesomeIcon icon={faPlus} />, | ||
colorSchema: 'danger', | ||
variant: 'solid' | ||
} | ||
}; | ||
|
||
export const Plain: Story = { | ||
args: { | ||
children: <FontAwesomeIcon icon={faPlus} />, | ||
variant: 'plain' | ||
} | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
children: <FontAwesomeIcon icon={faPlus} />, | ||
disabled: true | ||
} | ||
}; |
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,131 @@ | ||
import { ButtonHTMLAttributes, forwardRef, ReactNode } from 'react'; | ||
import { cva, VariantProps } from 'cva'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
// This is kept as required because by accessibility convention and eslint | ||
// when button doesn't have text an aria-label needs to be passed | ||
ariaLabel: string; | ||
isDisabled?: boolean; | ||
}; | ||
|
||
const iconButtonVariants = cva( | ||
[ | ||
'button', | ||
'transition-all', | ||
'font-medium', | ||
'cursor-pointer', | ||
'inline-flex items-center justify-center', | ||
'relative' | ||
], | ||
{ | ||
variants: { | ||
colorSchema: { | ||
primary: ['bg-primary', 'text-black', 'border-primary hover:bg-opacity-80'], | ||
secondary: ['bg-mineshaft', 'text-gray-300', 'border-mineshaft hover:bg-opacity-80'], | ||
danger: ['bg-red', 'text-white', 'border-red'] | ||
}, | ||
variant: { | ||
solid: '', | ||
outline: ['bg-transparent', 'border-2', 'border-solid'], | ||
plain: '' | ||
}, | ||
isDisabled: { | ||
true: 'bg-opacity-70 cursor-not-allowed', | ||
false: '' | ||
}, | ||
isRounded: { | ||
true: 'rounded-md', | ||
false: '' | ||
}, | ||
size: { | ||
xs: ['text-xs', 'py-1', 'px-2'], | ||
sm: ['text-sm', 'py-2', 'px-3'], | ||
md: ['text-md', 'py-3', 'px-4'], | ||
lg: ['text-lg', 'py-3', 'px-6'] | ||
} | ||
}, | ||
compoundVariants: [ | ||
{ | ||
colorSchema: 'primary', | ||
variant: 'outline', | ||
className: 'text-primary hover:bg-primary hover:text-black' | ||
}, | ||
{ | ||
colorSchema: 'secondary', | ||
variant: 'outline', | ||
className: 'hover:bg-mineshaft' | ||
}, | ||
{ | ||
colorSchema: 'danger', | ||
variant: 'outline', | ||
className: 'text-red hover:bg-red hover:text-black' | ||
}, | ||
{ | ||
colorSchema: 'primary', | ||
variant: 'plain', | ||
className: 'text-primary' | ||
}, | ||
{ | ||
colorSchema: 'secondary', | ||
variant: 'plain', | ||
className: 'text-mineshaft' | ||
}, | ||
{ | ||
colorSchema: 'danger', | ||
variant: 'plain', | ||
className: 'text-red' | ||
}, | ||
{ | ||
colorSchema: ['danger', 'primary', 'secondary'], | ||
variant: ['plain'], | ||
className: 'bg-transparent py-1 px-1' | ||
} | ||
] | ||
} | ||
); | ||
|
||
export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'aria-label'> & | ||
VariantProps<typeof iconButtonVariants> & | ||
Props; | ||
|
||
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>( | ||
( | ||
{ | ||
children, | ||
ariaLabel, | ||
isDisabled = false, | ||
className, | ||
size = 'md', | ||
variant = 'solid', | ||
isRounded = true, | ||
colorSchema = 'primary', | ||
...props | ||
}, | ||
ref | ||
): JSX.Element => ( | ||
<button | ||
ref={ref} | ||
aria-disabled={isDisabled} | ||
type="button" | ||
aria-label={ariaLabel} | ||
className={twMerge( | ||
iconButtonVariants({ | ||
className, | ||
colorSchema, | ||
size, | ||
variant, | ||
isRounded, | ||
isDisabled | ||
}) | ||
)} | ||
disabled={isDisabled} | ||
{...props} | ||
> | ||
{children} | ||
</button> | ||
) | ||
); | ||
|
||
IconButton.displayName = 'IconButton'; |
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,2 @@ | ||
export type { IconButtonProps } from './IconButton'; | ||
export { IconButton } from './IconButton'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {Select} from './Select' | ||
export type { SelectItemProps, SelectProps } from './Select'; | ||
export { Select, SelectItem } from './Select'; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './Button'; | ||
export * from './FormControl'; | ||
export * from './IconButton'; | ||
export * from './Input'; | ||
export * from './Select'; |