Skip to content

Commit 5cb8554

Browse files
committed
Add styleVars keys
1 parent a46f080 commit 5cb8554

File tree

1 file changed

+76
-28
lines changed
  • packages/components/src/components/Button

1 file changed

+76
-28
lines changed

packages/components/src/components/Button/index.tsx

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { Button as DevupButton, css } from '@devup-ui/react'
1+
import { Box, Button as DevupButton, Center, css } from '@devup-ui/react'
22
import clsx from 'clsx'
33

44
type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
55
variant?: 'primary' | 'default'
66
colors?: {
77
primary?: string
88
error?: string
9+
text?: string
10+
border?: string
11+
inputBg?: string
12+
primaryFocus?: string
913
}
1014
isError?: boolean
1115
size?: 'sm' | 'md'
16+
icon?: React.ReactNode
17+
ellipsis?: boolean
1218
}
1319

1420
const variants = {
@@ -56,15 +62,27 @@ const variants = {
5662
borderColor: `var(--primary, #000)`,
5763
bg: `color-mix(in srgb, var(--primary, #000) 10%, #FFF 90%)`,
5864
},
59-
bg: '$inputBg',
60-
border: '1px solid $border',
65+
bg: 'var(--inputBg, #FFF)',
66+
border: '1px solid var(--border, #000)',
6167
borderRadius: '10px',
62-
color: '$text',
68+
color: 'var(--text, #000)',
69+
typography: 'buttonxs',
70+
_themeDark: {
71+
_hover: {
72+
borderColor: `var(--primary, #000)`,
73+
bg: `color-mix(in srgb, var(--primary, #FFF) 10%, var(--inputBg, #000) 90%)`,
74+
},
75+
_active: {
76+
bg: 'var(--primary, #000)',
77+
color: 'var(--text, #FFF)',
78+
},
79+
},
6380
}),
6481
}
6582

6683
const errorClassNames = css({
6784
styleOrder: 3,
85+
color: 'var(--error, #000)',
6886
_active: {
6987
bg: 'var(--error, #000)',
7088
border: '1px solid var(--error, #000)',
@@ -74,41 +92,43 @@ const errorClassNames = css({
7492
outlineColor: 'var(--error, #000)',
7593
},
7694
_hover: {
95+
bg: 'inherit',
7796
border: '1px solid var(--error, #000)',
7897
},
7998
_themeDark: {
8099
_active: {
81100
bg: 'var(--error, #000)',
82101
border: '1px solid var(--error, #000)',
83-
color: '#000',
102+
color: '#FFF',
84103
},
85104
_hover: {
86-
bg: '$inputBg',
105+
bg: 'var(--inputBg, #000)',
106+
borderColor: 'var(--error, #000)',
107+
},
108+
_focusVisible: {
109+
outlineColor: 'var(--error, #000)',
87110
},
88111
},
112+
typography: 'inputBold',
113+
})
114+
115+
const buttonTextEllipsis = css({
116+
overflow: 'hidden',
117+
textOverflow: 'ellipsis',
118+
whiteSpace: 'nowrap',
89119
})
90120

91-
/**
92-
* Button
93-
* ## Design Token
94-
* ### Color
95-
* - inputDisabledBackground
96-
* - inputDisabled
97-
* - inputBackground
98-
* - primaryHover
99-
* - text
100-
* - border
101-
*
102-
* @constructor
103-
*/
104121
export function Button({
105122
variant = 'default',
106-
className = '',
107123
type = 'button',
108124
colors,
109125
isError = false,
110126
children,
111127
size = 'md',
128+
className = '',
129+
style,
130+
icon,
131+
ellipsis = false,
112132
...props
113133
}: ButtonProps): React.ReactElement {
114134
const isPrimary = variant === 'primary'
@@ -122,7 +142,7 @@ export function Button({
122142
}}
123143
_focusVisible={{
124144
outline: '2px solid',
125-
outlineColor: '$primaryFocus',
145+
outlineColor: 'var(--primaryFocus, #000)',
126146
}}
127147
_themeDark={{
128148
_disabled: {
@@ -132,21 +152,31 @@ export function Button({
132152
borderColor: 'transparent',
133153
},
134154
_focusVisible: {
135-
outlineColor: '$primaryFocus',
155+
outlineColor: 'var(--primaryFocus, #FFF)',
136156
},
137157
}}
158+
boxSizing="border-box"
138159
className={clsx(
139160
variants[variant],
140161
isError && variant === 'default' && errorClassNames,
141162
className,
142163
)}
143-
color={isError ? 'var(--error, #000)' : '$text'}
164+
color="var(--text, #000)"
144165
cursor="pointer"
145166
outlineOffset="2px"
167+
pos="relative"
146168
px="40px"
147169
py="12px"
170+
style={style}
148171
styleOrder={1}
149-
styleVars={{ primary: colors?.primary, error: colors?.error }}
172+
styleVars={{
173+
primary: colors?.primary,
174+
error: colors?.error,
175+
text: colors?.text,
176+
border: colors?.border,
177+
inputBg: colors?.inputBg,
178+
primaryFocus: colors?.primaryFocus,
179+
}}
150180
transition=".25s"
151181
type={type}
152182
typography={
@@ -155,13 +185,31 @@ export function Button({
155185
sm: 'buttonS',
156186
md: 'buttonM',
157187
}[size]
158-
: isError
159-
? 'inputBold'
160-
: 'buttonxs'
188+
: undefined
161189
}
162190
{...props}
163191
>
164-
{children}
192+
<Box maxW="100%" mx="auto" pos="relative" w="fit-content">
193+
{icon && (
194+
<Center
195+
boxSize="24px"
196+
left="4px"
197+
pos="absolute"
198+
role="presentation"
199+
top="50%"
200+
transform="translate(-100%, -50%)"
201+
>
202+
{icon}
203+
</Center>
204+
)}
205+
<Box
206+
className={clsx(ellipsis && buttonTextEllipsis)}
207+
minH="1em"
208+
transform={!!icon && 'translateX(8px)'}
209+
>
210+
{children}
211+
</Box>
212+
</Box>
165213
</DevupButton>
166214
)
167215
}

0 commit comments

Comments
 (0)