-
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.
- Loading branch information
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Checkbox } from './Checkbox'; | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
title: 'Components/Checkbox', | ||
component: Checkbox, | ||
tags: ['v2'], | ||
argTypes: {} | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Checkbox>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args | ||
export const Simple: Story = { | ||
args: { | ||
children: 'Accept the condition' | ||
} | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
children: 'Accept the condition', | ||
isDisabled: true | ||
} | ||
}; | ||
|
||
export const Required: Story = { | ||
args: { | ||
children: 'Accept the condition', | ||
isRequired: 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,51 @@ | ||
import { ReactNode } from 'react'; | ||
import { faCheck } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
export type CheckboxProps = Omit< | ||
CheckboxPrimitive.CheckboxProps, | ||
'checked' | 'disabled' | 'required' | ||
> & { | ||
children: ReactNode; | ||
id: string; | ||
isDisabled?: boolean; | ||
isChecked?: boolean; | ||
isRequired?: boolean; | ||
}; | ||
|
||
export const Checkbox = ({ | ||
children, | ||
className, | ||
id, | ||
isChecked, | ||
isDisabled, | ||
isRequired, | ||
...props | ||
}: CheckboxProps): JSX.Element => { | ||
return ( | ||
<div className="flex items-center text-bunker-300"> | ||
<CheckboxPrimitive.Root | ||
className={twMerge( | ||
'flex items-center justify-center w-5 h-5 mr-3 transition-all rounded shadow hover:bg-bunker-200 bg-bunker-300', | ||
isDisabled && 'bg-bunker-400 hover:bg-bunker-400', | ||
className | ||
)} | ||
required={isRequired} | ||
checked={isChecked} | ||
disabled={isDisabled} | ||
{...props} | ||
id={id} | ||
> | ||
<CheckboxPrimitive.Indicator className="text-bunker-800"> | ||
<FontAwesomeIcon icon={faCheck} size="sm" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
<label className="text-sm" htmlFor={id}> | ||
{children} | ||
{isRequired && <span className="pl-1 text-red">*</span>} | ||
</label> | ||
</div> | ||
); | ||
}; |
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 { CheckboxProps } from './Checkbox'; | ||
export { Checkbox } from './Checkbox'; |
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