Skip to content

Commit a20b884

Browse files
committed
feat(button): integrate handleClick for conditional navigation vs action buttons
1 parent e2c044e commit a20b884

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/components/Button.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNavigate } from 'react-router-dom';
12
import { tv } from 'tailwind-variants/lite';
23

34
const buttonVariants = tv({
@@ -24,7 +25,7 @@ const buttonVariants = tv({
2425
},
2526
// conditional style cases for specific prop combinations
2627
compoundVariants: [
27-
// remove drop shadow and lower font weight for onboarding quiz button
28+
// remove drop shadow and lower font weight for user selection button
2829
{
2930
color: 'secondary',
3031
size: 'md',
@@ -33,8 +34,18 @@ const buttonVariants = tv({
3334
]
3435
});
3536

36-
export default function Button({ size, color, label, onClick, isActive }) {
37+
export default function Button({ size, color, label, onClick, isActive, to }) {
38+
let navigate = useNavigate();
39+
40+
function handleClick(){
41+
if (to){
42+
navigate(to);
43+
} else {
44+
onClick();
45+
}
46+
}
47+
3748
return (
38-
<button onClick={onClick} className={isActive ? `${buttonVariants({ size, color })} active` : buttonVariants({ size, color })}>{label}</button>
39-
)
49+
<button onClick={handleClick} className={isActive ? `${buttonVariants({ size, color })} active` : buttonVariants({ size, color })}>{label}</button>
50+
);
4051
}

0 commit comments

Comments
 (0)