-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use
ToggleGroup
for quest group toggle instead of Dropdown (#220
- Loading branch information
Showing
4 changed files
with
80 additions
and
31 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,5 @@ | ||
--- | ||
"namesake": minor | ||
--- | ||
|
||
Simplify quest grouping UX |
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,31 +1,54 @@ | ||
import type { LucideIcon } from "lucide-react"; | ||
import { | ||
ToggleButton as AriaToggleButton, | ||
type ToggleButtonProps, | ||
type ToggleButtonProps as AriaToggleButtonProps, | ||
composeRenderProps, | ||
} from "react-aria-components"; | ||
import { tv } from "tailwind-variants"; | ||
import { buttonStyles } from "../Button"; | ||
import { focusRing } from "../utils"; | ||
|
||
export interface ToggleButtonProps extends AriaToggleButtonProps { | ||
children?: React.ReactNode; | ||
icon?: LucideIcon; | ||
size?: "small" | "medium"; | ||
} | ||
|
||
const styles = tv({ | ||
extend: focusRing, | ||
base: "h-10 px-3.5 [&:has(svg:only-child)]:px-2 text-sm text-center transition rounded-lg border border-black/10 dark:border-white/10", | ||
base: "px-3.5 [&:has(svg:only-child)]:px-2 text-sm text-center transition rounded-lg border border-black/10 dark:border-white/10", | ||
variants: { | ||
isSelected: { | ||
false: buttonStyles.variants.variant.secondary, | ||
true: "bg-gray-12 dark:bg-graydark-12 text-gray-1 dark:text-gray-12 shadow-sm", | ||
}, | ||
isDisabled: buttonStyles.variants.isDisabled, | ||
size: { | ||
small: "h-8", | ||
medium: "h-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "medium", | ||
}, | ||
}); | ||
|
||
export function ToggleButton(props: ToggleButtonProps) { | ||
export function ToggleButton({ | ||
size, | ||
icon: Icon, | ||
className, | ||
children, | ||
...props | ||
}: ToggleButtonProps) { | ||
return ( | ||
<AriaToggleButton | ||
{...props} | ||
className={composeRenderProps(props.className, (className, renderProps) => | ||
styles({ ...renderProps, className }), | ||
className={composeRenderProps(className, (className, renderProps) => | ||
styles({ ...renderProps, size, className }), | ||
)} | ||
/> | ||
> | ||
{Icon && <Icon size={size === "small" ? 16 : 20} />} | ||
{children} | ||
</AriaToggleButton> | ||
); | ||
} |
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