Skip to content

style(flat-button): implement inverted tone #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/components/buttons/flat-button/flat-button.js
Original file line number Diff line number Diff line change
@@ -16,12 +16,19 @@ const getIconElement = props => {
});
};

const getTextColor = (tone, isHover = false) => {
const getTextColor = (tone, isHover = false, theme) => {
const overwrittenVars = {
...vars,
...theme,
};

switch (tone) {
case 'primary':
return isHover ? vars.colorPrimary25 : vars.colorPrimary;
return isHover
? overwrittenVars.colorPrimary25
: overwrittenVars.colorPrimary;
case 'secondary':
return vars.colorSolid;
return overwrittenVars.colorSolid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's a dark background, it makes more sense to wrap that background in a ThemeProvider, overriding the colorSolid.

default:
return 'inherit';
}
@@ -40,38 +47,39 @@ export const FlatButton = props => {
label={props.label}
onClick={props.onClick}
isDisabled={props.isDisabled}
css={css`
css={theme => css`
display: flex;
align-items: center;
font-size: 1rem;
border: none;
background: none;
padding: 0;
min-height: initial;

p {
color: ${props.isDisabled
? vars.colorNeutral
: getTextColor(props.tone)};
: getTextColor(props.tone, false, theme)};
}

svg * {
fill: ${props.isDisabled
? vars.colorNeutral
: getTextColor(props.tone, false)};
: getTextColor(props.tone, false, theme)};
}

&:hover,
&:focus {
p {
color: ${props.isDisabled
? vars.colorNeutral
: getTextColor(props.tone, true)};
: getTextColor(props.tone, true, theme)};
}

svg * {
fill: ${props.isDisabled
? vars.colorNeutral
: getTextColor(props.tone, true)};
: getTextColor(props.tone, true, theme)};
}
}
`}
13 changes: 12 additions & 1 deletion src/components/buttons/flat-button/flat-button.visualroute.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { ThemeProvider } from 'emotion-theming';
import { FlatButton, InformationIcon } from 'ui-kit';
import { Suite, Spec } from '../../../../test/percy';

export const routePath = '/flat-button';

export const component = () => (
export const component = ({ themes }) => (
<Suite>
<Spec label="regular">
<FlatButton tone="primary" label="A label text" onClick={() => {}} />
@@ -42,5 +43,15 @@ export const component = () => (
icon={<InformationIcon />}
/>
</Spec>
<ThemeProvider theme={themes.darkTheme}>
<Spec label="secondary">
<FlatButton
tone="secondary"
label="Inverted"
onClick={() => {}}
icon={<InformationIcon />}
/>
</Spec>
</ThemeProvider>
</Suite>
);