Skip to content

Commit 299e5c9

Browse files
committed
fix(buttons): add inverted, disabled, and active modes to button
1 parent 7b6426a commit 299e5c9

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

components/common/Button.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
1212
className?: string;
1313
disableTracking?: boolean;
1414
variant?: Variant;
15+
disabled?: boolean;
16+
active?: boolean;
17+
invertedActive?: boolean;
1518
}
1619

1720
export const Button: FC<Props> = ({
@@ -21,10 +24,13 @@ export const Button: FC<Props> = ({
2124
variant = 'button',
2225
onClick,
2326
children,
27+
disabled = false,
28+
active = false,
29+
invertedActive = false,
2430
...props
2531
}) => {
26-
const handleClick: typeof onClick = (...props) => {
27-
onClick?.(...props);
32+
const handleClick: typeof onClick = (...params) => {
33+
onClick?.(...params);
2834
if (!disableTracking) {
2935
const value = extractTextFromElement(children);
3036
trackEvent({ action: 'click', category: 'button', value });
@@ -36,9 +42,13 @@ export const Button: FC<Props> = ({
3642
className={cx(className, styles.base, {
3743
[styles.buttonVariant]: variant === 'button',
3844
[styles.linkVariant]: variant === 'link',
45+
[styles.disabled]: disabled,
46+
[styles.active]: active,
47+
[styles.inverted]: invertedActive,
3948
})}
4049
type={type}
4150
onClick={handleClick}
51+
disabled={disabled}
4252
{...props}
4353
>
4454
{children}

components/common/button.module.scss

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@
1616
&:hover {
1717
border: solid 1px var(--text-color);
1818
}
19+
20+
&:disabled,
21+
&.disabled {
22+
cursor: auto;
23+
}
24+
25+
&:focus,
26+
&:focus-visible,
27+
&:active,
28+
&.active {
29+
border: solid 1px var(--text-color);
30+
}
31+
32+
&.active,
33+
&:active {
34+
&.inverted {
35+
color: var(--inverted-text-color);
36+
background-color: var(--inverted-background-color-offset);
37+
outline: 0;
38+
}
39+
}
40+
41+
&:not(:focus, :focus-visible, :active, .active) {
42+
border: none;
43+
outline: 0;
44+
}
1945
}
2046

2147
.linkVariant {

pages/global.scss

+11-2
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,27 @@
7777
--text-color: var(--white-base);
7878
--background-color: var(--black-base);
7979
--background-color-offset: var(--black-base-offset);
80+
--inverted-text-color: var(--black-text);
81+
--inverted-background-color: var(--white-base);
82+
--inverted-background-color-offset: var(--white-offset);
8083
}
8184

8285
@media (prefers-color-scheme: light) {
83-
--background-color: var(--white-base);
8486
--text-color: var(--black-text);
87+
--background-color: var(--white-base);
8588
--background-color-offset: var(--white-offset);
89+
--inverted-text-color: var(--white-base);
90+
--inverted-background-color: var(--black-base);
91+
--inverted-background-color-offset: var(--black-base-offset);
8692
}
8793

8894
[data-reach-dialog-content] {
89-
--background-color: var(--white-base);
9095
--text-color: var(--black-text);
96+
--background-color: var(--white-base);
9197
--background-color-offset: var(--white-offset);
98+
--inverted-text-color: var(--white-base);
99+
--inverted-background-color: var(--black-base);
100+
--inverted-background-color-offset: var(--black-base-offset);
92101
}
93102
}
94103

0 commit comments

Comments
 (0)