Skip to content

Commit

Permalink
Add gradient color to Button Component (#1316)
Browse files Browse the repository at this point in the history
## Description

1. What is this PR about (link the issue and add a short description)
This PR contains the changes for the Gradient color for the button
component

Here is an example of share button with `gradient` color:


https://user-images.githubusercontent.com/74011196/228329202-54f1b143-cc99-47d5-bd17-decf170fbe82.mov


## Steps for reproduction

1. Create a Button component
2. set `color="gradient"` in Button Component

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [x] made a self-review
- [x] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [x] tested locally and on preview environment (preview dev login:
5de6)
- [x] updated [test
cases](https://github.com/webstudio-is/webstudio-builder/blob/main/apps/builder/docs/test-cases.md)
document
- [x] added tests
- [x] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory

---------

Co-authored-by: Oleg Isonen <oleg008@gmail.com>
  • Loading branch information
lokeswaran-aj and kof authored Mar 30, 2023
1 parent 2731bfb commit fbc401c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion apps/builder/app/builder/features/topbar/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const ShareButton = ({ projectId }: { projectId: Project["id"] }) => {
<FloatingPanelAnchor>
<Tooltip side="bottom" content={tooltipContent}>
<FloatingPanelPopoverTrigger asChild>
<Button disabled={isShareDisabled}>Share</Button>
<Button disabled={isShareDisabled} color="gradient">
Share
</Button>
</FloatingPanelPopoverTrigger>
</Tooltip>
</FloatingPanelAnchor>
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/src/components/button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const colors: ReadonlyArray<ComponentProps<typeof ButtonComponent>["color"]> = [
"positive",
"ghost",
"dark",
"gradient",
];

const states: ReadonlyArray<ComponentProps<typeof ButtonComponent>["state"]> = [
Expand Down
26 changes: 18 additions & 8 deletions packages/design-system/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const colors = [
"neutral",
"ghost",
"dark",
"gradient",
] as const;

type ButtonColor = (typeof colors)[number];
Expand All @@ -32,6 +33,7 @@ const backgrounds: Record<ButtonColor, string> = {
positive: theme.colors.backgroundSuccessMain,
ghost: theme.colors.backgroundHover,
dark: theme.colors.backgroundTopbar,
gradient: theme.colors.backgroundGradientPrimary,
};

const foregrounds: Record<ButtonColor, string> = {
Expand All @@ -41,6 +43,7 @@ const foregrounds: Record<ButtonColor, string> = {
neutral: theme.colors.foregroundMain,
ghost: theme.colors.foregroundMain,
dark: theme.colors.foregroundContrastMain,
gradient: theme.colors.foregroundContrastMain,
};

// CSS supports multiple gradients as backgrounds but not multiple colors
Expand All @@ -52,10 +55,13 @@ const perColorStyle = (variant: ButtonColor) => ({
color: foregrounds[variant],

"&[data-state=auto]:hover, &[data-state=hover]": {
background: backgroundColors(
backgrounds[variant],
theme.colors.backgroundButtonHover
),
background:
variant === "gradient"
? `linear-gradient(${theme.colors.backgroundButtonHover}, ${theme.colors.backgroundButtonHover}), ${backgrounds[variant]}`
: backgroundColors(
backgrounds[variant],
theme.colors.backgroundButtonHover
),
},

"&[data-state=auto]:focus-visible, &[data-state=focus]": {
Expand All @@ -64,10 +70,13 @@ const perColorStyle = (variant: ButtonColor) => ({
},

"&[data-state=auto]:active, &[data-state=pressed]": {
background: backgroundColors(
backgrounds[variant],
theme.colors.backgroundButtonPressed
),
background:
variant === "gradient"
? `linear-gradient(${theme.colors.backgroundButtonPressed}, ${theme.colors.backgroundButtonPressed}), ${backgrounds[variant]}`
: backgroundColors(
backgrounds[variant],
theme.colors.backgroundButtonPressed
),
},

"&[data-state=disabled]": {
Expand Down Expand Up @@ -101,6 +110,7 @@ const StyledButton = styled("button", {
neutral: perColorStyle("neutral"),
ghost: perColorStyle("ghost"),
dark: perColorStyle("dark"),
gradient: perColorStyle("gradient"),
},
},

Expand Down

0 comments on commit fbc401c

Please sign in to comment.