-
-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: created toggle and checkbox components and added stories for them #3082
Merged
asyncapi-bot
merged 19 commits into
asyncapi:master
from
devilkiller-ag:add-storybook-toggle-and-checkbox
Aug 30, 2024
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a09ea90
resolved merge conflict
devilkiller-ag bba7090
extracted toggle from tools filters dropdown and created story for it
devilkiller-ag d2dd439
added variant stories for toggle and checkbox
devilkiller-ag 54262ae
rectified checkbox story
devilkiller-ag 2e03937
removed unneccesary changes
devilkiller-ag 5cdaefb
Merge branch 'asyncapi:master' into add-storybook-toggle-and-checkbox
devilkiller-ag 589b1e1
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag 4c2283e
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag 21b5c9e
Merge branch 'asyncapi:master' into add-storybook-toggle-and-checkbox
devilkiller-ag 8bc0d8f
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag ae6cf58
Merge branch 'asyncapi:master' into add-storybook-toggle-and-checkbox
devilkiller-ag eb20e42
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag 73133ae
moved CheckboxProps to types folder
devilkiller-ag ba9ed24
moved ToggleProps to types folder
devilkiller-ag 594cfe5
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag e6c868e
Merge branch 'master' into add-storybook-toggle-and-checkbox
devilkiller-ag 23c5d00
Merge branch 'master' of https://github.com/asyncapi/website into add…
devilkiller-ag 78a272e
Merge branch 'master' into add-storybook-toggle-and-checkbox
akshatnema bc9b542
Merge branch 'master' into add-storybook-toggle-and-checkbox
akshatnema File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,45 @@ | ||
import { useArgs } from '@storybook/preview-api'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import type { CheckboxProps } from '@/types/components/tools/CheckboxPropsType'; | ||
|
||
import Checkbox from './Checkbox'; | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
title: 'Components/Checkbox', | ||
component: Checkbox | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Checkbox>; | ||
|
||
export const DefaultCheckbox: Story = { | ||
args: { | ||
name: 'Check me!', | ||
checked: true | ||
}, | ||
|
||
render: (args: CheckboxProps) => { | ||
const [{ checked }, updateArgs] = useArgs(); | ||
|
||
const handleClickOption = () => { | ||
updateArgs({ checked: !checked }); | ||
}; | ||
|
||
return <Checkbox {...args} checked={checked} handleClickOption={handleClickOption} />; | ||
} | ||
}; | ||
|
||
export const ColorfulCheckbox: Story = { | ||
...DefaultCheckbox, | ||
|
||
args: { | ||
...DefaultCheckbox.args, | ||
bgColor: 'bg-gray-200', | ||
textColor: 'text-primary-500', | ||
borderColor: 'border-primary-500', | ||
checkedStateBgColor: 'bg-primary-500', | ||
checkedStateTextColor: 'text-white' | ||
} | ||
}; |
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,40 @@ | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import type { CheckboxProps } from '@/types/components/tools/CheckboxPropsType'; | ||
|
||
/** | ||
* This component renders a checkbox. | ||
*/ | ||
const Checkbox = ({ | ||
name, | ||
checked, | ||
bgColor = 'bg-white', | ||
textColor = 'text-secondary-600', | ||
borderColor = 'border-secondary-600', | ||
checkedStateBgColor = 'bg-secondary-600', | ||
checkedStateTextColor = 'text-white', | ||
handleClickOption | ||
}: CheckboxProps) => { | ||
const handleClick = (event: React.MouseEvent) => { | ||
event.stopPropagation(); // Prevents the event from propagating to parent elements | ||
handleClickOption(name); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={twMerge( | ||
`border ${borderColor} ${bgColor} ${textColor} p-1 pb-0 rounded-2xl flex gap-1 cursor-pointer items-start ${checked ? `${checkedStateBgColor} ${checkedStateTextColor}` : ''}` | ||
)} | ||
onClick={handleClick} | ||
> | ||
{checked ? ( | ||
<img src='/img/illustrations/icons/CheckedIcon.svg' alt='checked' /> | ||
) : ( | ||
<img src='/img/illustrations/icons/UncheckedIcon.svg' alt='unchecked' /> | ||
)} | ||
<div className='-mt-px mb-px text-xs'>{name}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default 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
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,42 @@ | ||
import { useArgs } from '@storybook/preview-api'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import type { ToggleProps } from '@/types/components/tools/TogglePropsType'; | ||
|
||
import Toggle from './Toggle'; | ||
|
||
const meta: Meta<typeof Toggle> = { | ||
title: 'Components/Toggle', | ||
component: Toggle | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Toggle>; | ||
|
||
export const DefaultToggle: Story = { | ||
args: { | ||
checked: true, | ||
label: 'Toggle me!' | ||
}, | ||
|
||
render: (args: ToggleProps) => { | ||
const [{ checked }, updateArgs] = useArgs(); | ||
|
||
const setChecked = () => { | ||
updateArgs({ checked: !checked }); | ||
}; | ||
|
||
return <Toggle {...args} checked={checked} setChecked={setChecked} />; | ||
} | ||
}; | ||
|
||
export const ColorfulToggle: Story = { | ||
...DefaultToggle, | ||
|
||
args: { | ||
...DefaultToggle.args, | ||
bgColor: 'bg-gray-200', | ||
checkedStateBgColor: 'bg-primary-500' | ||
} | ||
}; |
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,33 @@ | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import type { ToggleProps } from '@/types/components/tools/TogglePropsType'; | ||
|
||
/** | ||
* Toggle component for displaying and controlling a toggle switch. | ||
*/ | ||
const Toggle = ({ | ||
checked, | ||
setChecked, | ||
label, | ||
bgColor = 'bg-gray-200', | ||
checkedStateBgColor = 'bg-secondary-500' | ||
}: ToggleProps) => { | ||
return ( | ||
<label className='relative inline-flex cursor-pointer items-center'> | ||
<input | ||
type='checkbox' | ||
value={checked ? 'true' : 'false'} | ||
className='peer sr-only' | ||
onChange={() => setChecked(!checked)} | ||
/> | ||
<div | ||
className={twMerge( | ||
`w-11 h-6 ${bgColor} peer-focus:outline-none rounded-full peer after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all ${checked ? `after:translate-x-full after:border-white ${checkedStateBgColor}` : ''}` | ||
)} | ||
></div> | ||
{label && <div className='ml-2 text-sm font-medium'>{label}</div>} | ||
</label> | ||
); | ||
}; | ||
|
||
export default Toggle; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export interface CheckboxProps { | ||
// eslint-disable-next-line prettier/prettier | ||
|
||
/** The name to be displayed inside the checkbox. */ | ||
name: string; | ||
|
||
/** If the checkbox is checked or not. */ | ||
checked: boolean; | ||
|
||
/** The background color of the checkbox. */ | ||
bgColor?: string; | ||
|
||
/** The text color of the checkbox. */ | ||
textColor?: string; | ||
|
||
/** The border color of the checkbox. */ | ||
borderColor?: string; | ||
|
||
/** The background color of the checkbox when it is checked. */ | ||
checkedStateBgColor?: string; | ||
|
||
/** The text color of the checkbox when it is checked. */ | ||
checkedStateTextColor?: string; | ||
|
||
/** Function to handle the click event of the checkbox. */ | ||
handleClickOption: (name: string) => void; | ||
} |
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,18 @@ | ||
export interface ToggleProps { | ||
// eslint-disable-next-line prettier/prettier | ||
|
||
/** Current state of the toggle. */ | ||
checked: boolean; | ||
|
||
/** Function to update the toggle state. */ | ||
setChecked: React.Dispatch<React.SetStateAction<boolean>>; | ||
|
||
/** Label text for the toggle. */ | ||
label?: string; | ||
|
||
/** The background color of the checkbox. */ | ||
bgColor?: string; | ||
|
||
/** The background color of the checkbox when it is checked. */ | ||
checkedStateBgColor?: string; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why there are changes in package-lock.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a merge conflict in the version of the storybook(3.2.2). I resolved it.