Skip to content
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

UX-284 Darken button hover background colors #564

Merged
merged 4 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ jest.mock('../packages/matchbox/src/components/ThemeProvider/theme', () => ({
colors: {
gray: {
700: 'gray',
900: 'gray',
},
red: {
700: 'red',
900: 'red',
},
blue: {
700: 'blue',
},
white: 'white',
},
}));

Expand Down
4 changes: 2 additions & 2 deletions packages/matchbox/src/components/Banner/tests/Banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Banner', () => {
.at(0)
.simulate('click');
expect(action.onClick).toHaveBeenCalledTimes(1);
expect(wrapper.find('button').at(0)).toHaveStyleRule('background', tokens.color_gray_900);
expect(wrapper.find('button').at(0)).toHaveStyleRule('background', 'gray');
});

it('renders multiple banner actions', () => {
Expand All @@ -89,7 +89,7 @@ describe('Banner', () => {
.at(0)
.simulate('click');
expect(actions[0].onClick).toHaveBeenCalledTimes(1);
expect(wrapper.find('button').at(0)).toHaveStyleRule('background', tokens.color_blue_700);
expect(wrapper.find('button').at(0)).toHaveStyleRule('background', 'blue');

wrapper
.find('button')
Expand Down
32 changes: 17 additions & 15 deletions packages/matchbox/src/components/Button/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ export const colorVariant = props => {
switch (props.buttonColor) {
case 'orange': // To be deprecated
case 'blue':
color = tokens.color_blue_700;
darkHoverColor = tokens.color_blue_800;
lightActiveColor = tokens.color_blue_200;
lightHoverColor = tokens.color_blue_100;
color = props.theme.colors.blue['700'];
darkHoverColor = props.theme.colors.blue['800'];
lightActiveColor = props.theme.colors.blue['300'];
lightHoverColor = props.theme.colors.blue['200'];
break;

case 'red':
color = tokens.color_red_700;
darkHoverColor = tokens.color_red_800;
lightActiveColor = tokens.color_red_200;
lightHoverColor = tokens.color_red_100;
color = props.theme.colors.red['700'];
darkHoverColor = props.theme.colors.red['800'];
lightActiveColor = props.theme.colors.red['300'];
lightHoverColor = props.theme.colors.red['200'];
break;

case 'gray':
default:
color = tokens.color_gray_900;
darkHoverColor = tokens.color_gray_1000;
lightActiveColor = tokens.color_gray_200;
lightHoverColor = tokens.color_gray_100;
color = props.theme.colors.gray['900'];
darkHoverColor = props.theme.colors.gray['1000'];
lightActiveColor = props.theme.colors.gray['400'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do blue and red also need to be 2 steps darker than they were before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kind of just eyeballed it, it seemed a little too light at first. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they're good how they are

lightHoverColor = props.theme.colors.gray['300'];
break;
}

Expand All @@ -117,13 +117,13 @@ export const colorVariant = props => {
return `
&, &:visited {
background: ${color};
color: ${tokens.color_white};
color: ${props.theme.colors.white};

&:hover {
${!props.disabled ? `background: ${darkHoverColor};` : ''}
}
&:focus, &:hover {
color: ${tokens.color_white};
color: ${props.theme.colors.white};
}
&:active {
background: ${color};
Expand Down Expand Up @@ -151,7 +151,9 @@ export const colorVariant = props => {
default:
return `
&, &:visited {
border: 1px solid ${props.visualWeight == 'outline' ? tokens.color_gray_400 : color};
border: 1px solid ${
props.visualWeight == 'outline' ? props.theme.colors.gray['400'] : color
};
background: transparent;
color: ${color};
&:hover {
Expand Down
14 changes: 7 additions & 7 deletions packages/matchbox/src/components/Button/tests/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ describe('Button', () => {
props: {},
assert: [
['height', '2.5rem'],
['color', '#ffffff'],
['background', '#39444d'],
['color', 'white'],
['background', 'gray'],
],
},
{ name: 'large size', props: { size: 'large' }, assert: ['height', '3.5rem'] },
{ name: 'disabled', props: { disabled: true }, assert: ['opacity', '0.6'] },
{ name: 'destructive', props: { destructive: true }, assert: ['background', '#d9363e'] },
{ name: 'destructive', props: { destructive: true }, assert: ['background', 'red'] },
{ name: 'flat', props: { flat: true }, assert: ['background', 'transparent'] },
{
name: 'flat with color',
props: { flat: true, color: 'blue' },
assert: [
['background', 'transparent'],
['color', '#1273e6'],
['color', 'blue'],
],
},
{
name: 'flat with color and disabled',
props: { flat: true, color: 'red', disabled: true },
assert: [
['background', 'transparent'],
['color', '#d9363e'],
['color', 'red'],
['opacity', '0.6'],
],
},
{
name: 'outline enabled',
props: { outlineBorder: true },
assert: [
['border', '1px solid #39444d'],
['border', '1px solid gray'],
['background', 'transparent'],
],
},
Expand All @@ -56,7 +56,7 @@ describe('Button', () => {
{
name: 'deprecated prop - primary',
props: { primary: true },
assert: ['background', '#1273e6'],
assert: ['background', 'blue'],
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe('Pagination', () => {
});

it('renders active page styles correctly', () => {
expect(wrapper.find('button').at(1)).toHaveStyleRule('background', tokens.color_blue_700);
expect(wrapper.find('button').at(1)).toHaveStyleRule('color', tokens.color_white);
expect(wrapper.find('button').at(1)).toHaveStyleRule('background', 'blue');
expect(wrapper.find('button').at(1)).toHaveStyleRule('color', 'white');
});

it('invokes onChange on page', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/matchbox/src/components/ThemeProvider/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const theme = {
gray: tokens.color_brand_gray,
blue: tokens.color_brand_blue,
},
white: tokens.color_white,
},

// Example: <Box marginBottom="400" padding={400} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ describe('Tooltip', () => {
});

it('should pass through system props', () => {
const wrapper = subject({ bg: 'blue', fontSize: '400', pr: '500' });
const wrapper = subject({ bg: 'bg', fontSize: '400', pr: '500' });
wrapper.find('button').simulate('mouseOver');
expect(content(wrapper)).toHaveStyleRule('background-color', 'blue');
expect(content(wrapper)).toHaveStyleRule('background-color', 'bg');
expect(content(wrapper)).toHaveStyleRule('font-size', '1rem');
expect(content(wrapper)).toHaveStyleRule('padding-right', '1.5rem');
});
Expand Down
4 changes: 2 additions & 2 deletions stories/action/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Sizing = withInfo()(() => (
));

export const Colors = withInfo({ propTables: [Button] })(() => (
<>
<Box bg="gray.100">
<Inline>
<Button>Button</Button>
<Button disabled>Disabled</Button>
Expand Down Expand Up @@ -64,7 +64,7 @@ export const Colors = withInfo({ propTables: [Button] })(() => (
Outline
</Button>
</Inline>
</>
</Box>
));

export const Destructive = withInfo()(() => (
Expand Down