Button variations solution
First I added some new variables to my theme.
import { blue, neutral, yellow, green, red } from "./colors";
...
status: {
warningColor: yellow[100],
warningColorHover: yellow[200],
warningColorActive: yellow[300],
errorColor: red[100],
errorColorHover: red[200],
errorColorActive: red[300],
successColor: green[100],
successColorHover: green[200],
successColorActive: green[300]
}
Next let's add the modifiers for the warning, success, and error states.
import styled from "styled-components";
import { applyStyleModifiers } from "styled-components-modifiers";
import { defaultTheme, helperText, header5, paragraph } from "../utils";
const BUTTON_MODIFIERS = {
small: () => `
font-size: ${typeScale.helperText};
padding: 8px;
`,
large: () => `
font-size: ${typeScale.header5};
padding: 16px 24px;
`,
warning: () => `
background: none;
color: ${defaultTheme.status.warningColor};
&:hover, &:focus {
background-color: ${defaultTheme.status.warningColorHover};
outline: 3px solid ${defaultTheme.status.warningColorHover};
outline-offset: 2px;
border: 2px solid transparent;
}
&:active {
background-color: ${defaultTheme.status.warningColorActive};
}
`,
primaryButtonWarning: () => `
background-color: ${defaultTheme.status.warningColor};
color: ${defaultTheme.textColorInverted};
`,
secondaryButtonWarning: () => `
border: 2px solid ${defaultTheme.status.warningColor};
`,
error: () => `
background: none;
color: ${defaultTheme.status.errorColor};
&:hover, &:focus {
background-color: ${defaultTheme.status.errorColorHover};
outline: 3px solid ${defaultTheme.status.errorColorHover};
outline-offset: 2px;
border: 2px solid transparent;
}
&:active {
background-color: ${defaultTheme.status.errorColorActive};
}
`,
primaryButtonError: () => `
background-color: ${defaultTheme.status.errorColor};
color: ${defaultTheme.textColorInverted};
`,
secondaryButtonError: () => `
border: 2px solid ${defaultTheme.status.warningColor};
`,
success: () => `
background: none;
color: ${defaultTheme.status.successColor};
&:hover, &:focus {
background-color: ${defaultTheme.status.successColorHover};
outline: 3px solid ${defaultTheme.status.successColorHover};
outline-offset: 2px;
border: 2px solid transparent;
}
&:active {
background-color: ${defaultTheme.status.successColorActive};
}
`,
primaryButtonSuccess: () => `
background-color: ${defaultTheme.status.successColor};
color: ${defaultTheme.textColorInverted};
`,
secondaryButtonSuccess: () => `
border: 2px solid ${defaultTheme.status.warningColor};
`
};
Now inside index.js
we can add another modifier to our buttons.
<PrimaryButton modifiers={["small", "success", "primaryButtonSuccess"]}>
Hello world
</PrimaryButton>
<SecondaryButton modifiers={["large", "warning", "secondaryButtonWarning"]}>
Goodbye world
</SecondaryButton>
<TertiaryButton modifiers={["error", "tertiaryButtonError"]}>
Hey world
</TertiaryButton>