(front) add loader and icon props to Button

These shortcuts improve DX and will be used in the next commits.
This commit is contained in:
Nathan Vasse
2025-02-10 16:33:54 +01:00
committed by NathanVss
parent 48937bb7a3
commit ba873196c7
2 changed files with 12 additions and 2 deletions

View File

@@ -6,12 +6,15 @@ import { type RecipeVariantProps } from '@/styled-system/css'
import { buttonRecipe, type ButtonRecipe } from './buttonRecipe' import { buttonRecipe, type ButtonRecipe } from './buttonRecipe'
import { TooltipWrapper, type TooltipWrapperProps } from './TooltipWrapper' import { TooltipWrapper, type TooltipWrapperProps } from './TooltipWrapper'
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { Loader } from './Loader'
export type ButtonProps = RecipeVariantProps<ButtonRecipe> & export type ButtonProps = RecipeVariantProps<ButtonRecipe> &
RACButtonsProps & RACButtonsProps &
TooltipWrapperProps & { TooltipWrapperProps & {
// Use tooltip as description below the button. // Use tooltip as description below the button.
description?: boolean description?: boolean
} & {
icon?: ReactNode
} }
export const Button = ({ export const Button = ({
@@ -20,13 +23,16 @@ export const Button = ({
...props ...props
}: ButtonProps) => { }: ButtonProps) => {
const [variantProps, componentProps] = buttonRecipe.splitVariantProps(props) const [variantProps, componentProps] = buttonRecipe.splitVariantProps(props)
const { className, ...remainingComponentProps } = componentProps
return ( return (
<TooltipWrapper tooltip={tooltip} tooltipType={tooltipType}> <TooltipWrapper tooltip={tooltip} tooltipType={tooltipType}>
<RACButton <RACButton
className={buttonRecipe(variantProps)} className={[buttonRecipe(variantProps), className].join(' ')}
{...(componentProps as RACButtonsProps)} {...(remainingComponentProps as RACButtonsProps)}
> >
{!props.loading && props.icon}
{props.loading && <Loader />}
{componentProps.children as ReactNode} {componentProps.children as ReactNode}
{props.description && <span>{tooltip}</span>} {props.description && <span>{tooltip}</span>}
</RACButton> </RACButton>

View File

@@ -11,6 +11,7 @@ export const buttonRecipe = cva({
'&[data-disabled]': { '&[data-disabled]': {
cursor: 'default', cursor: 'default',
}, },
gap: '0.5rem',
}, },
variants: { variants: {
size: { size: {
@@ -266,6 +267,9 @@ export const buttonRecipe = cva({
width: 'full', width: 'full',
}, },
}, },
loading: {
true: {},
},
// some toggle buttons make more sense without a "pushed button" style when selected because their content changes to mark the state // some toggle buttons make more sense without a "pushed button" style when selected because their content changes to mark the state
shySelected: { shySelected: {
true: {}, true: {},