-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `ui/components/shared/Button` component has long confused me. It exports a lot of component variants, many of which don't seem to be used directly (rather the base `Button` component is used with various combinations of props) and many of which don't actually work (combinations of attributes that don't produce usable styles). In addition to that, most of our newer DevTools code can't use these buttons because the `replay-next` package can't import from the legacy `ui` package. This PR adds a new `Button` component to `replay-next` that supports our two style variants (solid vs outlined) and colors (primary vs secondary). The API is more constrained (e.g. it doesn't try to support a dozen colors, when we only use two and it doesn't export a dozen components when there is, conceptually, only one button). ## Comparison screenshots Here is a side by side comparison of the old and new buttons. | Dark theme | Light theme | | :--- | :--- | | ![Screenshot 2024-02-22 at 10 06 52 AM](https://github.com/replayio/devtools/assets/29597/857900c1-e41f-440a-aeb8-37af1230b67c) | ![Screenshot 2024-02-22 at 10 07 02 AM](https://github.com/replayio/devtools/assets/29597/b25c4da6-1bc8-4456-9497-a24dd33df4c3) | The new button component fixes some issues with the old one, some of which can be seen in the comparison above: * Legacy variants that should work, but don't (like secondary + outline) * Legacy hover states that don't work (secondary) * Disabled colors for dark theme * Add disabled state for outline variant ## Example replacements Below I've updated a couple of pages to use the new button component instead. | Before | After | | :--- | :--- | | ![Screenshot 2024-02-22 at 10 07 25 AM](https://github.com/replayio/devtools/assets/29597/844bed44-eb23-4f6f-a179-309d6b50d822) | ![Screenshot 2024-02-22 at 10 07 44 AM](https://github.com/replayio/devtools/assets/29597/94b14a2d-4483-4cfb-84bb-f920df028997) | | ![Screenshot 2024-02-22 at 10 07 32 AM](https://github.com/replayio/devtools/assets/29597/5c473b45-fb88-4bb3-93c2-fc9bb07dee06) | ![Screenshot 2024-02-22 at 10 07 50 AM](https://github.com/replayio/devtools/assets/29597/a27d1e12-77ac-465f-b57d-3f74099b0328) | | ![Screenshot 2024-02-22 at 10 07 38 AM](https://github.com/replayio/devtools/assets/29597/28fd8a56-3116-4b77-aad7-113e2dc444f2) | ![Screenshot 2024-02-22 at 10 08 01 AM](https://github.com/replayio/devtools/assets/29597/7bb03cbc-83dc-48b4-9215-69fe2fcda819) | | ![Screenshot 2024-02-22 at 10 58 38 AM](https://github.com/replayio/devtools/assets/29597/67132ac2-9774-49bb-b4ec-de0c5e23db5e) | ![Screenshot 2024-02-22 at 10 58 42 AM](https://github.com/replayio/devtools/assets/29597/2c454dc5-1e79-4c19-a5a9-7c7b8099b8df) | | ![Screenshot 2024-02-22 at 10 59 24 AM](https://github.com/replayio/devtools/assets/29597/504c3fda-3adf-4da4-9d0d-84d9b60bce92) | ![Screenshot 2024-02-22 at 10 59 28 AM](https://github.com/replayio/devtools/assets/29597/3ba59f62-97d1-4b27-87e0-f6cf10219349) | | ![Screenshot 2024-02-22 at 10 59 39 AM](https://github.com/replayio/devtools/assets/29597/d1ad8a77-616c-4691-8514-965b8bd240e1) | ![Screenshot 2024-02-22 at 10 59 44 AM](https://github.com/replayio/devtools/assets/29597/bb962d4d-72b9-46bc-ae3d-04929b71baad) | Note that by updating this page we fix the following problems: * Bright disabled button style on a dark theme page * Bright background on outline button (bad contrast– blue on white) * "Done" button is overlapped/hidden entirely when selecting elements. * Generally simplifies the code required to use our standard button UI/UX * Removes the only instance of a "red" button color in favor of a standard color; (this might be controversial and we could change this if needed) ## Follow up work to this PR - Update `replay-next` code to use these buttons instead of one-off re-implementing the styles everywhere - Gradually remove references to `ui/components/shared/Button` and replace with new buttons - Delete all `ui/components/shared/Button` components once references have been removed
- Loading branch information
Showing
9 changed files
with
102 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.Button { | ||
font-family: var(--font-family-default); | ||
font-size: 0.875rem; | ||
line-height: 1rem; | ||
font-weight: 500; | ||
padding: 0.5rem 0.75rem; | ||
border: 1px solid transparent; | ||
border-radius: 0.375rem; | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 1ch; | ||
} | ||
.Button:disabled { | ||
--accent-color: var(--background-color-disabled-button); | ||
--accent-color-hover: var(--background-color-disabled-button); | ||
--contrast-color: var(--color-disabled-button); | ||
|
||
color: var(--color-dimmer); | ||
} | ||
|
||
.Button[data-color="primary"]:not(:disabled) { | ||
--accent-color: var(--primary-accent); | ||
--accent-color-hover: var(--primary-accent-hover); | ||
--contrast-color: var(--color-primary-button); | ||
} | ||
.Button[data-color="secondary"]:not(:disabled) { | ||
--accent-color: var(--secondary-accent); | ||
--accent-color-hover: var(--secondary-accent-hover); | ||
--contrast-color: var(--color-secondary-button); | ||
} | ||
|
||
.Button[data-variant="outline"] { | ||
border-color: var(--accent-color); | ||
} | ||
.Button[data-variant="outline"]:hover { | ||
border-color: var(--accent-color-hover); | ||
} | ||
.Button[data-variant="solid"] { | ||
background-color: var(--accent-color); | ||
color: var(--contrast-color); | ||
} | ||
.Button[data-variant="solid"]:hover { | ||
background-color: var(--accent-color-hover); | ||
} | ||
|
||
.Button[data-size="large"] { | ||
font-size: 1rem; | ||
line-height: 1.5rem; | ||
padding: 0.75rem 1.5rem; | ||
border-radius: 0.375rem; | ||
} | ||
.Button[data-size="small"] { | ||
font-size: 0.75rem; | ||
line-height: 1rem; | ||
padding: 0.375rem 0.625rem; | ||
border-radius: 0.25rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ButtonHTMLAttributes } from "react"; | ||
|
||
import styles from "./Button.module.css"; | ||
|
||
export function Button({ | ||
className = "", | ||
color = "primary", | ||
size = "normal", | ||
variant = "solid", | ||
...rest | ||
}: ButtonHTMLAttributes<HTMLButtonElement> & { | ||
color?: "primary" | "secondary"; | ||
size?: "normal" | "large" | "small"; | ||
variant?: "outline" | "solid"; | ||
}) { | ||
return ( | ||
<button | ||
className={`${className} ${styles.Button}`} | ||
data-color={color} | ||
data-size={size} | ||
data-variant={variant} | ||
{...rest} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters