-
Notifications
You must be signed in to change notification settings - Fork 18
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(ui): toggle component and more #1913
Merged
+202
−90
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6702e10
feat(ui): add toggle UI component
VanishMax 8ee902b
feat(ui): add `medium` density
VanishMax 6c68693
feat(ui): add new text style `xxs`
VanishMax fe77020
fix(ui): improve Tabs styles
VanishMax 7055f71
chore: changeset
VanishMax a4e36a3
fix: after review
VanishMax 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,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
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.
question: can't we do this?
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.
though if we specifically need those names as a field, we could also do this:
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.
Density and Text components initially had this style of props that is more neat:
<Density compact/>
,<Text body/>
. I personally don't mind the union type but it is already a bit too late to change – so many components depend on a shorter syntax.Changed the types to the version from your second comment