Button
An interactive element used to trigger actions.
import { defineConfig } from '@pandacss/dev'
import { createPreset } from '@park-ui/panda-preset'
export default defineConfig({
preflight: true,
presets: [
'@pandacss/preset-base',
createPreset({
accentColor: '__ACCENT_COLOR__',
grayColor: '__GRAY_COLOR__',
borderRadius: '__BORDER_RADIUS__',
}),
],
include: ['./src/**/*.{js,jsx,ts,tsx}'],
jsxFramework: '__JS_FRAMEWORK__',
outdir: 'styled-system',
})
import { parkwindPlugin } from '@park-ui/tailwind-plugin'
import type { Config } from 'tailwindcss'
const config: Config = {
content: ['./src/**/*.{astro,html,js,jsx,svelte,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [parkwindPlugin],
parkUI: {
accentColor: '__ACCENT_COLOR__',
grayColor: '__GRAY_COLOR__',
borderRadius: '__BORDER_RADIUS__',
},
darkMode: ['class'],
}
export default config
import { ArrowRightIcon } from 'lucide-react'
import { Button, type ButtonProps } from '~/components/ui/button'
export const Demo = (props: ButtonProps) => {
return (
<Button {...props}>
Button
<ArrowRightIcon />
</Button>
)
}
Use the colorPalette
prop to change the color of the button.
<Flex gap="3">
<Button colorPalette="red" variant="solid">
Button
</Button>
<Button colorPalette="red" variant="subtle">
Button
</Button>
<Button colorPalette="red" variant="outline">
Button
</Button>
<Button colorPalette="red" variant="ghost">
Button
</Button>
</Flex>
Insert code snippet into your project. Update import paths as needed.
import { ark } from '@ark-ui/react/factory'
import type { ComponentProps } from 'react'
import { styled } from 'styled-system/jsx'
import { button } from 'styled-system/recipes'
export const Button = styled(ark.button, button)
export interface ButtonProps extends ComponentProps<typeof Button> {}
import { ark } from '@ark-ui/solid'
import type { ComponentProps } from 'solid-js'
import { styled } from 'styled-system/jsx'
import { button } from 'styled-system/recipes'
export const Button = styled(ark.button, button)
export interface ButtonProps extends ComponentProps<typeof Button> {}
Not yet available
This step is necessary only if you do not use any of the Park UI plugins.
import { defineRecipe } from '@pandacss/dev'
export const button = defineRecipe({
className: 'button',
base: {
alignItems: 'center',
appearance: 'none',
borderRadius: 'l2',
cursor: 'pointer',
display: 'inline-flex',
fontWeight: 'semibold',
minWidth: '0',
justifyContent: 'center',
outline: 'none',
transitionDuration: 'normal',
transitionProperty: 'background, border-color, color, box-shadow',
transitionTimingFunction: 'default',
userSelect: 'none',
verticalAlign: 'middle',
whiteSpace: 'nowrap',
_hidden: {
display: 'none',
},
},
defaultVariants: {
variant: 'solid',
size: 'md',
},
variants: {
variant: {
solid: {
background: 'colorPalette.default',
color: 'colorPalette.fg',
colorPalette: 'accent',
_hover: {
background: 'colorPalette.emphasized',
},
_focusVisible: {
outline: '2px solid',
outlineColor: 'colorPalette.default',
outlineOffset: '2px',
},
_disabled: {
color: 'fg.disabled',
background: 'bg.disabled',
cursor: 'not-allowed',
_hover: {
color: 'fg.disabled',
background: 'bg.disabled',
},
},
},
outline: {
borderWidth: '1px',
borderColor: 'colorPalette.a8',
color: 'colorPalette.text',
colorPalette: 'gray',
_hover: {
background: 'colorPalette.a2',
},
_disabled: {
borderColor: 'border.disabled',
color: 'fg.disabled',
cursor: 'not-allowed',
_hover: {
background: 'transparent',
borderColor: 'border.disabled',
color: 'fg.disabled',
},
},
_focusVisible: {
outline: '2px solid',
outlineColor: 'colorPalette.default',
outlineOffset: '2px',
},
_selected: {
background: 'accent.default',
borderColor: 'accent.default',
color: 'accent.fg',
_hover: {
background: 'accent.emphasized',
borderColor: 'accent.emphasized',
},
},
},
ghost: {
color: 'colorPalette.text',
colorPalette: 'gray',
_hover: {
background: 'colorPalette.a3',
},
_selected: {
background: 'colorPalette.a3',
},
_disabled: {
color: 'fg.disabled',
cursor: 'not-allowed',
_hover: {
background: 'transparent',
color: 'fg.disabled',
},
},
_focusVisible: {
outline: '2px solid',
outlineColor: 'colorPalette.default',
outlineOffset: '2px',
},
},
link: {
verticalAlign: 'baseline',
_disabled: {
color: 'border.disabled',
cursor: 'not-allowed',
_hover: {
color: 'border.disabled',
},
},
height: 'auto!',
px: '0!',
minW: '0!',
},
subtle: {
background: 'colorPalette.a3',
color: 'colorPalette.text',
colorPalette: 'gray',
_hover: {
background: 'colorPalette.a4',
},
_focusVisible: {
outline: '2px solid',
outlineColor: 'colorPalette.default',
outlineOffset: '2px',
},
_disabled: {
background: 'bg.disabled',
color: 'fg.disabled',
cursor: 'not-allowed',
_hover: {
background: 'bg.disabled',
color: 'fg.disabled',
},
},
},
},
size: {
xs: {
h: '8',
minW: '8',
textStyle: 'xs',
px: '3',
gap: '2',
'& svg': {
fontSize: 'md',
width: '4',
height: '4',
},
},
sm: {
h: '9',
minW: '9',
textStyle: 'sm',
px: '3.5',
gap: '2',
'& svg': {
width: '4',
height: '4',
},
},
md: {
h: '10',
minW: '10',
textStyle: 'sm',
px: '4',
gap: '2',
'& svg': {
width: '5',
height: '5',
},
},
lg: {
h: '11',
minW: '11',
textStyle: 'md',
px: '4.5',
gap: '2',
'& svg': {
width: '5',
height: '5',
},
},
xl: {
h: '12',
minW: '12',
textStyle: 'md',
px: '5',
gap: '2.5',
'& svg': {
width: '5',
height: '5',
},
},
'2xl': {
h: '16',
minW: '16',
textStyle: 'lg',
px: '7',
gap: '3',
'& svg': {
width: '6',
height: '6',
},
},
},
},
})