Skip to content

Commit 3b0270d

Browse files
committed
[#40] ♻️ update Button components w/ fullWidth props & clsx
1 parent 9ac6b38 commit 3b0270d

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
import clsx from 'clsx'
2+
13
import { Clickable, ClickableProps } from './Clickable'
24

3-
interface ButtonProps
5+
export interface ButtonProps
46
extends ClickableProps,
57
React.ButtonHTMLAttributes<HTMLButtonElement> {}
68

79
export const Button = ({
810
onClick,
911
type = 'button',
1012
disabled = false,
13+
fullWidth,
1114
...props
1215
}: ButtonProps): JSX.Element => (
13-
<button onClick={onClick} type={type} disabled={disabled}>
14-
<Clickable {...props} disabled={disabled} />
16+
<button
17+
onClick={onClick}
18+
type={type}
19+
disabled={disabled}
20+
className={clsx({ 'w-full': fullWidth })}
21+
>
22+
<Clickable {...props} disabled={disabled} fullWidth={fullWidth} />
1523
</button>
1624
)

src/components/common/button/Clickable.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import clsx from 'clsx'
2-
import { twMerge } from 'tailwind-merge'
32

43
export interface ClickableProps {
54
label?: string
@@ -83,18 +82,18 @@ export const Clickable = ({
8382
: ''
8483
const textColorClass = textColor ? styleByTextColor[textColor] : ''
8584

86-
const clickableStyle = twMerge(
85+
const clickableStyle = clsx(
8786
baseStyle,
8887
styleByVariant[variant],
8988
styleBySize[size],
9089
textColorClass,
91-
clsx({
90+
{
9291
[borderColorClass]: variant === 'outlined',
9392
[backgroundColorClass]: variant !== 'text',
9493
[disabledStyle]: disabled,
9594
'w-full': fullWidth,
9695
'justify-start': leftAlign,
97-
}),
96+
},
9897
className
9998
)
10099

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import NextLink from 'next/link'
22

3+
import clsx from 'clsx'
4+
35
import { Clickable, ClickableProps } from './Clickable'
46

5-
interface LinkProps
7+
export interface LinkProps
68
extends ClickableProps,
79
React.AnchorHTMLAttributes<HTMLAnchorElement> {}
810

911
export const Link = ({
1012
href = '#',
1113
disabled,
14+
onClick = () => {},
15+
fullWidth,
1216
...props
1317
}: LinkProps): JSX.Element => (
1418
<NextLink
@@ -18,9 +22,12 @@ export const Link = ({
1822
onClick={e => {
1923
if (disabled) {
2024
e.preventDefault()
25+
} else {
26+
onClick(e)
2127
}
2228
}}
29+
className={clsx({ 'w-full': fullWidth })}
2330
>
24-
<Clickable {...props} disabled={disabled} />
31+
<Clickable {...props} disabled={disabled} fullWidth={fullWidth} />
2532
</NextLink>
2633
)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button } from './Button'
2-
import { Link } from './Link'
1+
import { Button, type ButtonProps } from './Button'
2+
import { Link, type LinkProps } from './Link'
33

4-
export { Button, Link }
4+
export { Button, ButtonProps, Link, LinkProps }

0 commit comments

Comments
 (0)