Skip to content

Commit

Permalink
[#4] Button component (#54)
Browse files Browse the repository at this point in the history
* update button component

* update code lint
  • Loading branch information
vitran12 authored Jan 23, 2024
1 parent 388529f commit 3391167
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 81 deletions.
4 changes: 4 additions & 0 deletions panda.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig } from '@pandacss/dev';
import { avatarSlotRecipe } from '@/components/ui/avatar/AvatarSlotRecipe';
import { buttonRecipe } from '@/components/ui/button/ButtonRecipe';

export default defineConfig({
preflight: true,
Expand All @@ -11,6 +12,9 @@ export default defineConfig({
slotRecipes: {
avatar: avatarSlotRecipe,
},
recipes: {
button: buttonRecipe,
},
},
},
jsxFramework: 'react',
Expand Down
42 changes: 0 additions & 42 deletions src/components/ui/button/Button.mdx

This file was deleted.

36 changes: 0 additions & 36 deletions src/components/ui/button/Button.stories.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/components/ui/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ark } from '@ark-ui/react';
import { styled, type HTMLStyledProps } from '@/styled/jsx';
import { styled } from '@/styled/jsx';
import { button } from '@/styled/recipes';

export const Button = styled(ark.button, button);
export interface ButtonProps extends HTMLStyledProps<typeof Button> {}
218 changes: 218 additions & 0 deletions src/components/ui/button/ButtonRecipe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import { defineRecipe } from '@pandacss/dev';

/**
* Update styles for Button component.
*/
export const buttonRecipe = 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',
},
},
},
},
});
3 changes: 2 additions & 1 deletion src/components/ui/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, ButtonProps } from './Button';
import { Button } from './Button';
import { ButtonProps } from './interface';

export { Button };
export type { ButtonProps };
4 changes: 4 additions & 0 deletions src/components/ui/button/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type HTMLStyledProps } from '@/styled/jsx';
import { Button } from '@/components/ui/button';

export interface ButtonProps extends HTMLStyledProps<typeof Button> {}

0 comments on commit 3391167

Please sign in to comment.