Icon small button variant (#6525)
* Icon small button variant * Rename * Update CVA + Update button WIP * add ticket ref and fix padding * Update button and all uses of Icon button * SB deployment test * Fixing type error * Fix lint * Add icon button to canvas Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
1 parent
18246e0dc1
commit
cfaecc3e02
37 files changed
+145
-93
No files matched your search
@@ -36,6 +36,11 @@ const buttonClasses = cva(
|
||||
"inline-flex items-center text-sm font-medium relative rounded-md transition-colors",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
button: "",
|
||||
icon: "flex justify-center",
|
||||
fab: "h-14 w-14 sm:h-9 sm:w-auto rounded-full justify-center sm:rounded-md sm:px-4 sm:py-2.5 radix-state-open:rotate-45 sm:radix-state-open:rotate-0 transition-transform radix-state-open:shadown-none radix-state-open:ring-0 !shadow-none",
|
||||
},
|
||||
color: {
|
||||
primary: "text-white dark:text-black",
|
||||
secondary: "text-gray-900 dark:text-darkgray-900",
|
||||
@@ -46,10 +51,6 @@ const buttonClasses = cva(
|
||||
sm: "px-3 py-2 leading-4 rounded-sm" /** For backwards compatibility */,
|
||||
base: "h-9 px-4 py-2.5 ",
|
||||
lg: "h-[36px] px-4 py-2.5 ",
|
||||
icon: "flex justify-center min-h-[36px] min-w-[36px] ",
|
||||
// fab = floating action button, used for the main action in a page.
|
||||
// it uses the same primary classNames for desktop size
|
||||
fab: "h-14 w-14 sm:h-9 sm:w-auto rounded-full justify-center sm:rounded-md sm:px-4 sm:py-2.5 radix-state-open:rotate-45 sm:radix-state-open:rotate-0 transition-transform radix-state-open:shadown-none radix-state-open:ring-0 !shadow-none",
|
||||
},
|
||||
loading: {
|
||||
true: "cursor-wait",
|
||||
@@ -133,8 +134,20 @@ const buttonClasses = cva(
|
||||
className:
|
||||
"border dark:text-white text-gray-900 hover:text-red-700 focus:text-red-700 dark:hover:text-red-700 dark:focus:text-red-700 hover:border-red-100 focus:border-red-100 hover:bg-red-100 focus:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset focus:ring-red-700",
|
||||
}),
|
||||
// https://github.com/joe-bell/cva/issues/95 created an issue about using !p-2 on the icon variants as i would expect this to take priority
|
||||
{
|
||||
variant: "icon",
|
||||
size: "base",
|
||||
className: "min-h-[36px] min-w-[36px] !p-2",
|
||||
},
|
||||
{
|
||||
variant: "icon",
|
||||
size: "sm",
|
||||
className: "h-6 w-6 !p-1",
|
||||
},
|
||||
],
|
||||
defaultVariants: {
|
||||
variant: "button",
|
||||
color: "primary",
|
||||
size: "base",
|
||||
},
|
||||
@@ -149,6 +162,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
loading = false,
|
||||
color = "primary",
|
||||
size,
|
||||
variant = "button",
|
||||
type = "button",
|
||||
StartIcon,
|
||||
EndIcon,
|
||||
@@ -169,7 +183,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
type: !isLink ? type : undefined,
|
||||
ref: forwardedRef,
|
||||
className: classNames(
|
||||
buttonClasses({ color, size, loading, disabled: props.disabled }),
|
||||
buttonClasses({ color, size, loading, disabled: props.disabled, variant }),
|
||||
props.className
|
||||
),
|
||||
// if we click a disabled button, we prevent going through the click handler
|
||||
@@ -182,7 +196,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
<>
|
||||
{StartIcon && (
|
||||
<>
|
||||
{size === "fab" ? (
|
||||
{variant === "fab" ? (
|
||||
<>
|
||||
<StartIcon className="hidden h-4 w-4 stroke-[1.5px] ltr:mr-2 rtl:ml-2 sm:inline-flex" />
|
||||
<Icon.FiPlus className="inline h-6 w-6 sm:hidden" />
|
||||
@@ -190,14 +204,14 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
) : (
|
||||
<StartIcon
|
||||
className={classNames(
|
||||
"inline-flex",
|
||||
size === "icon" ? "h-4 w-4 " : "h-4 w-4 stroke-[1.5px] ltr:mr-2 rtl:ml-2"
|
||||
variant === "icon" && "h-4 w-4",
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:mr-2 rtl:ml-2"
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{size === "fab" ? <span className="hidden sm:inline">{props.children}</span> : props.children}
|
||||
{variant === "fab" ? <span className="hidden sm:inline">{props.children}</span> : props.children}
|
||||
{loading && (
|
||||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 transform">
|
||||
<svg
|
||||
@@ -216,13 +230,19 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
)}
|
||||
{EndIcon && (
|
||||
<>
|
||||
{size === "fab" ? (
|
||||
{variant === "fab" ? (
|
||||
<>
|
||||
<EndIcon className="-mr-1 hidden h-5 w-5 ltr:ml-2 rtl:-ml-1 rtl:mr-2 sm:inline" />
|
||||
<Icon.FiPlus className="inline h-6 w-6 sm:hidden" />
|
||||
</>
|
||||
) : (
|
||||
<EndIcon className="inline h-5 w-5 ltr:-mr-1 ltr:ml-2 rtl:mr-2" />
|
||||
<EndIcon
|
||||
className={classNames(
|
||||
"inline-flex",
|
||||
variant === "icon" && "h-4 w-4",
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:mr-2 rtl:ml-2"
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -65,6 +65,17 @@ Button are clickable elements that initiates user actions. Labels in the button
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Icons">
|
||||
<Example title="Icon Normal">
|
||||
<Button StartIcon={Icon.FiX} variant="icon" size="base" color="minimal"></Button>
|
||||
</Example>
|
||||
<Example title="Icon Small">
|
||||
<Button StartIcon={Icon.FiX} variant="icon" size="sm" color="minimal"></Button>
|
||||
</Example>
|
||||
<Example title="Icon Loading">
|
||||
<Button StartIcon={Icon.FiX} variant="icon" size="sm" color="minimal" loading></Button>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
## Anatomy
|
||||
Button are clickable elements that initiates user actions. Labels in the button guide users to what action will occur when the user interacts with it.
|
||||
@@ -80,36 +91,41 @@ Button are clickable elements that initiates user actions. Labels in the button
|
||||
|
||||
<Canvas>
|
||||
<Story name="All variants">
|
||||
<VariantsTable titles={['Primary', 'Secondary', 'Minimal', 'Destructive']} columnMinWidth={150}>
|
||||
<VariantsTable titles={['Primary', 'Secondary', 'Minimal', 'Destructive',"Icon"]} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<Button>Button text</Button>
|
||||
<Button color="secondary">Button text</Button>
|
||||
<Button color="minimal">Button text</Button>
|
||||
<Button color="destructive">Button text</Button>
|
||||
<Button color="destructive" variant="icon" StartIcon={Icon.FiX}></Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Hover">
|
||||
<Button className="sb-pseudo--hover">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="secondary">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="minimal">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="destructive">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="destructive" variant="icon" StartIcon={Icon.FiX}></Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Focus">
|
||||
<Button className="sb-pseudo--focus">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="secondary">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="minimal">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="destructive">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="destructive" variant="icon" StartIcon={Icon.FiX}></Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Loading">
|
||||
<Button loading>Button text</Button>
|
||||
<Button loading color="secondary">Button text</Button>
|
||||
<Button loading color="minimal">Button text</Button>
|
||||
<Button loading color="destructive">Button text</Button>
|
||||
<Button loading color="destructive" variant="icon" StartIcon={Icon.FiX}></Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Disabled">
|
||||
<Button disabled>Button text</Button>
|
||||
<Button disabled color="secondary">Button text</Button>
|
||||
<Button disabled color="minimal">Button text</Button>
|
||||
<Button disabled color="destructive">Button text</Button>
|
||||
<Button disabled color="destructive" variant="icon" StartIcon={Icon.FiX}></Button>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
|
||||
@@ -21,7 +21,7 @@ export function ButtonGroup({ children, combined = false, containerProps }: Prop
|
||||
"flex",
|
||||
!combined
|
||||
? "space-x-2 rtl:space-x-reverse"
|
||||
: "[&_button]:rounded-none [&_button]:ltr:border-l-0 rtl:[&_button]:border-r-0 ltr:[&>*:first-child]:rounded-l-md ltr:[&>*:first-child]:border-l rtl:[&>*:first-child]:rounded-r-md rtl:[&>*:first-child]:border-r [&_a]:rounded-none ltr:[&_a]:border-l-0 rtl:[&_a]:border-r-0 ltr:[&>*:last-child]:rounded-r-md rtl:[&>*:last-child]:rounded-l-md",
|
||||
: "ltr:[&>*:first-child]:rounded-l-md ltr:[&>*:first-child]:border-l rtl:[&>*:first-child]:rounded-r-md rtl:[&>*:first-child]:border-r ltr:[&>*:last-child]:rounded-r-md rtl:[&>*:last-child]:rounded-l-md [&_button]:rounded-none [&_button]:ltr:border-l-0 rtl:[&_button]:border-r-0 [&_a]:rounded-none ltr:[&_a]:border-l-0 rtl:[&_a]:border-r-0",
|
||||
containerProps?.className
|
||||
)}>
|
||||
{children}
|
||||
|
||||
@@ -31,16 +31,16 @@ Button group enables multiple buttons to be combined into a single unit. It offe
|
||||
>
|
||||
<Example title="Default" >
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</Example>
|
||||
<Example title="Combined">
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</Example>
|
||||
</Examples>
|
||||
@@ -52,31 +52,31 @@ Button group enables multiple buttons to be combined into a single unit. It offe
|
||||
<VariantsTable titles={["Default",'Secondary',"Minimal"]} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon"/>
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon"/>
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" color="minimal" />
|
||||
</ButtonGroup>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Combined">
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiTrash} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} variant="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} variant="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
|
||||
@@ -45,7 +45,7 @@ export const DropdownActions = ({
|
||||
<Dropdown>
|
||||
{!actionTrigger ? (
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button type="button" color="secondary" size="icon" StartIcon={Icon.FiMoreHorizontal} />
|
||||
<Button type="button" color="secondary" variant="icon" StartIcon={Icon.FiMoreHorizontal} />
|
||||
</DropdownMenuTrigger>
|
||||
) : (
|
||||
<DropdownMenuTrigger asChild>{actionTrigger}</DropdownMenuTrigger>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"@radix-ui/react-select": "^0.1.1",
|
||||
"@tanstack/react-query": "^4.3.9",
|
||||
"@wojtekmaj/react-daterange-picker": "^3.3.1",
|
||||
"class-variance-authority": "^0.3.0",
|
||||
"class-variance-authority": "^0.4.0",
|
||||
"downshift": "^6.1.9",
|
||||
"next": "^13.1.1",
|
||||
"react": "^18.2.0",
|
||||
|
||||
Reference in new issue
Block a user