Skip to content

Commit

Permalink
add bordered button variant (#1900)
Browse files Browse the repository at this point in the history
* add bordered variant

* add some more stories

* add disabled state to bordered button and update stories

* fix hover and disabled colors
  • Loading branch information
gumaerc authored Dec 12, 2024
1 parent c7b87d4 commit 6a1b436
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontends/ol-components/src/components/Button/Button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as ButtonStories from "./Button.stories"

# Button

Use prop `variant="primary" | "secondary" | "tertiary" | "text"` to set the button variant:
Use prop `variant="primary" | "secondary" | "tertiary" | "bordered" | "noBorder" | "inverted" | "success" | "text"` to set the button variant:

<Canvas of={ButtonStories.VariantStory} />

Expand Down
43 changes: 36 additions & 7 deletions frontends/ol-components/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const meta: Meta<typeof Button> = {
"primary",
"secondary",
"tertiary",
"text",
"bordered",
"noBorder",
"inverted",
"text-secondary",
"success",
"text",
],
control: { type: "select" },
},
Expand Down Expand Up @@ -88,15 +90,21 @@ export const VariantStory: Story = {
<Button {...args} variant="tertiary">
Tertiary
</Button>
<Button {...args} variant="text">
Text
<Button {...args} variant="bordered">
Bordered
</Button>
<Button {...args} variant="noBorder">
Text Secondary
No Border
</Button>
<Button {...args} variant="inverted">
Inverted
</Button>
<Button {...args} variant="success">
Success
</Button>
<Button {...args} variant="text">
Text
</Button>
</Stack>
),
}
Expand Down Expand Up @@ -149,9 +157,21 @@ export const DisabledStory: Story = {
<Button {...args} disabled variant="secondary">
Secondary
</Button>
<Button {...args} variant="tertiary">
<Button {...args} disabled variant="tertiary">
Tertiary
</Button>
<Button {...args} disabled variant="bordered">
Bordered
</Button>
<Button {...args} disabled variant="noBorder">
No Border
</Button>
<Button {...args} disabled variant="inverted">
Inverted
</Button>
<Button {...args} disabled variant="success">
Success
</Button>
<Button {...args} disabled variant="text">
Text
</Button>
Expand Down Expand Up @@ -217,7 +237,16 @@ export const IconOnlyStory: Story = {

const EDGES = ["rounded", "circular", "none"] as const

const VARIANTS = ["primary", "secondary", "tertiary", "text"] as const
const VARIANTS = [
"primary",
"secondary",
"tertiary",
"bordered",
"noBorder",
"success",
"inverted",
"text",
] as const
const EXTRA_PROPS = [
{},
/**
Expand Down
30 changes: 19 additions & 11 deletions frontends/ol-components/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type ButtonVariant =
| "primary"
| "secondary"
| "tertiary"
| "text"
| "bordered"
| "noBorder"
| "inverted"
| "success"
| "text"
type ButtonSize = "small" | "medium" | "large"
type ButtonEdge = "circular" | "rounded" | "none"

Expand Down Expand Up @@ -98,7 +99,7 @@ const buildStyles = (props: ButtonStyleProps & { theme: Theme }) => {
...props,
}
const { colors } = theme.custom
const hasBorder = variant === "secondary"
const hasBorder = variant === "secondary" || variant === "bordered"
return css([
{
color: theme.palette.text.primary,
Expand Down Expand Up @@ -142,11 +143,6 @@ const buildStyles = (props: ButtonStyleProps & { theme: Theme }) => {
boxShadow: "none",
},
},
hasBorder && {
backgroundColor: "transparent",
borderColor: "currentcolor",
borderStyle: "solid",
},
variant === "success" && {
backgroundColor: colors.darkGreen,
color: colors.white,
Expand All @@ -163,13 +159,11 @@ const buildStyles = (props: ButtonStyleProps & { theme: Theme }) => {
boxShadow: "none",
},
},
hasBorder && {
variant === "secondary" && {
color: colors.red,
backgroundColor: "transparent",
borderColor: "currentcolor",
borderStyle: "solid",
},
variant === "secondary" && {
color: colors.red,
":hover:not(:disabled)": {
backgroundColor: tinycolor(colors.brightRed).setAlpha(0.06).toString(),
},
Expand All @@ -188,6 +182,20 @@ const buildStyles = (props: ButtonStyleProps & { theme: Theme }) => {
color: colors.silverGray,
},
},
variant === "bordered" && {
backgroundColor: colors.white,
color: colors.silverGrayDark,
border: `1px solid ${colors.silverGrayLight}`,
":hover:not(:disabled)": {
backgroundColor: colors.lightGray1,
color: colors.darkGray2,
},
":disabled": {
backgroundColor: colors.lightGray2,
border: `1px solid ${colors.lightGray2}`,
color: colors.silverGrayDark,
},
},
variant === "noBorder" && {
backgroundColor: colors.white,
color: colors.darkGray2,
Expand Down

0 comments on commit 6a1b436

Please sign in to comment.