-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): toggle component and more (#1913)
* feat(ui): add toggle UI component * feat(ui): add `medium` density * feat(ui): add new text style `xxs` * fix(ui): improve Tabs styles * chore: changeset * fix: after review
- Loading branch information
Showing
13 changed files
with
187 additions
and
74 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,8 @@ | ||
--- | ||
'@penumbra-zone/ui': minor | ||
--- | ||
|
||
- Add Toggle UI component | ||
- Add `medium` density | ||
- Add `xxs` Text style | ||
- Improve the styles of `Tabs` component |
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
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
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,28 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useArgs } from '@storybook/preview-api'; | ||
|
||
import { Toggle } from '.'; | ||
|
||
const meta: Meta<typeof Toggle> = { | ||
component: Toggle, | ||
tags: ['autodocs', '!dev', 'density'], | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Toggle>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
value: false, | ||
label: 'Label', | ||
disabled: false, | ||
}, | ||
|
||
render: function Render(props) { | ||
const [, updateArgs] = useArgs(); | ||
|
||
const onChange = (value: boolean) => updateArgs({ value }); | ||
|
||
return <Toggle {...props} onChange={onChange} />; | ||
}, | ||
}; |
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,39 @@ | ||
import cn from 'clsx'; | ||
import * as RadixToggle from '@radix-ui/react-toggle'; | ||
import { useDisabled } from '../utils/disabled-context'; | ||
import { useDensity } from '../utils/density'; | ||
|
||
export interface ToggleProps { | ||
/** An accessibility label. */ | ||
label: string; | ||
value: boolean; | ||
onChange: (value: boolean) => void; | ||
/** @todo: Implement disabled state visually. */ | ||
disabled?: boolean; | ||
} | ||
|
||
export const Toggle = ({ label, value, onChange, disabled }: ToggleProps) => { | ||
const density = useDensity(); | ||
|
||
return ( | ||
<RadixToggle.Root | ||
aria-label={label} | ||
pressed={value} | ||
onPressedChange={onChange} | ||
disabled={useDisabled(disabled)} | ||
className={cn( | ||
'border border-solid border-other-tonalStroke rounded-full transition-colors cursor-pointer', | ||
value ? 'bg-primary-main' : 'bg-base-transparent', | ||
density === 'sparse' ? 'w-12' : 'w-8', | ||
)} | ||
> | ||
<div | ||
className={cn( | ||
'rounded-full transition-all', | ||
value ? 'bg-primary-contrast translate-x-[90%]' : 'bg-neutral-light translate-x-0', | ||
density === 'sparse' ? 'size-6' : 'size-4', | ||
)} | ||
/> | ||
</RadixToggle.Root> | ||
); | ||
}; |
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
Oops, something went wrong.