Skip to content

Commit 745e945

Browse files
afonsodelgadomlent
authored andcommitted
feat: Add hover state and change selected styles for Selector component (#421)
* Change Selector selector state and add hover state * Remove colors from selected state * Increase border width on hover states
1 parent 1e7f859 commit 745e945

File tree

3 files changed

+112
-15
lines changed

3 files changed

+112
-15
lines changed

src/components/Selector/Selector.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,36 @@ import PropTypes from 'prop-types';
1717
import styled from '@emotion/styled';
1818
import { css } from '@emotion/core';
1919
import withAriaSelected from '../../util/withAriaSelected';
20+
import { shadowSingle } from '../../styles/style-helpers';
2021

2122
const baseStyles = ({ theme }) => css`
2223
label: selector;
2324
cursor: pointer;
24-
padding: ${theme.spacings.mega};
25-
border-radius: ${theme.borderRadius.mega};
26-
border: 1px solid ${theme.colors.n300};
27-
background-color: 1px solid ${theme.colors.n100};
25+
padding: ${theme.spacings.giga};
26+
border-radius: ${theme.borderRadius.giga};
27+
border: ${theme.borderWidth.kilo} solid ${theme.colors.n300};
28+
background-color: ${theme.colors.white};
2829
margin-bottom: ${theme.spacings.mega};
30+
fill: ${theme.colors.n400};
2931
`;
3032

33+
const hoverStyles = ({ selected, theme }) =>
34+
!selected &&
35+
css`
36+
label: selector--hover;
37+
&:hover {
38+
border: ${theme.borderWidth.mega} solid ${theme.colors.n300};
39+
background-color: ${theme.colors.n100};
40+
}
41+
`;
42+
3143
const selectedStyles = ({ selected, theme }) =>
3244
selected &&
3345
css`
3446
label: selector--selected;
3547
border: ${theme.borderWidth.mega} solid ${theme.colors.p500};
36-
background-color: ${theme.colors.white};
48+
background-color: ${theme.colors.b100};
49+
${shadowSingle({ theme })};
3750
`;
3851

3952
const disabledStyles = ({ disabled, theme }) =>
@@ -48,7 +61,12 @@ const disabledStyles = ({ disabled, theme }) =>
4861
* A selector allows users to choose between several mutually-exlusive choices,
4962
* accompanied by descriptions, possibly with tabular data.
5063
*/
51-
const Selector = styled('div')(baseStyles, selectedStyles, disabledStyles);
64+
const Selector = styled.div(
65+
baseStyles,
66+
hoverStyles,
67+
selectedStyles,
68+
disabledStyles
69+
);
5270

5371
Selector.propTypes = {
5472
/**

src/components/Selector/Selector.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import Selector from '.';
1919

2020
describe('Selector', () => {
2121
it('should render a default selector appropriately', () => {
22-
const component = <Selector />;
23-
expect(component).toMatchSnapshot();
22+
const actual = mount(<Selector />);
23+
expect(actual).toMatchSnapshot();
2424
});
2525
it('should render a disabled selector appropriately', () => {
26-
const component = <Selector disabled />;
27-
expect(component).toMatchSnapshot();
26+
const actual = mount(<Selector disabled />);
27+
expect(actual).toMatchSnapshot();
2828
});
2929
it('should render a selected selector appropriately', () => {
30-
const component = <Selector selected />;
31-
expect(component).toMatchSnapshot();
30+
const actual = mount(<Selector selected />);
31+
expect(actual).toMatchSnapshot();
3232
});
3333
});
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,94 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Selector should render a default selector appropriately 1`] = `<withProps(Styled(div)) />`;
3+
exports[`Selector should render a default selector appropriately 1`] = `
4+
.circuit-0 {
5+
cursor: pointer;
6+
padding: 24px;
7+
border-radius: 5px;
8+
border: 1px solid #D8DDE1;
9+
background-color: #FFFFFF;
10+
margin-bottom: 16px;
11+
}
12+
13+
.circuit-0:hover {
14+
border: 2px solid #D8DDE1;
15+
background-color: #FAFBFC;
16+
}
17+
18+
<withProps(Styled(div))>
19+
<Styled(div)
20+
disabled={false}
21+
selected={false}
22+
>
23+
<div
24+
className="circuit-0 circuit-1"
25+
disabled={false}
26+
selected={false}
27+
/>
28+
</Styled(div)>
29+
</withProps(Styled(div))>
30+
`;
431

532
exports[`Selector should render a disabled selector appropriately 1`] = `
33+
.circuit-0 {
34+
cursor: pointer;
35+
padding: 24px;
36+
border-radius: 5px;
37+
border: 1px solid #D8DDE1;
38+
background-color: #FFFFFF;
39+
margin-bottom: 16px;
40+
color: #9DA7B1;
41+
cursor: default;
42+
}
43+
44+
.circuit-0:hover {
45+
border: 2px solid #D8DDE1;
46+
background-color: #FAFBFC;
47+
}
48+
649
<withProps(Styled(div))
750
disabled={true}
8-
/>
51+
>
52+
<Styled(div)
53+
disabled={true}
54+
selected={false}
55+
>
56+
<div
57+
className="circuit-0 circuit-1"
58+
disabled={true}
59+
selected={false}
60+
/>
61+
</Styled(div)>
62+
</withProps(Styled(div))>
963
`;
1064

1165
exports[`Selector should render a selected selector appropriately 1`] = `
66+
.circuit-0 {
67+
cursor: pointer;
68+
padding: 24px;
69+
border-radius: 5px;
70+
border: 1px solid #D8DDE1;
71+
background-color: #FFFFFF;
72+
margin-bottom: 16px;
73+
border: 2px solid #3388FF;
74+
background-color: #EDF4FC;
75+
box-shadow: 0 0 0 1px rgba(12,15,20,0.02), 0 0 1px 0 rgba(12,15,20,0.06), 0 2px 2px 0 rgba(12,15,20,0.06);
76+
}
77+
1278
<withProps(Styled(div))
1379
selected={true}
14-
/>
80+
>
81+
<Styled(div)
82+
aria-selected={true}
83+
disabled={false}
84+
selected={true}
85+
>
86+
<div
87+
aria-selected={true}
88+
className="circuit-0 circuit-1"
89+
disabled={false}
90+
selected={true}
91+
/>
92+
</Styled(div)>
93+
</withProps(Styled(div))>
1594
`;

0 commit comments

Comments
 (0)