Skip to content

Commit 26b12ad

Browse files
committed
feat: introduce standard spacing to the theme
1 parent 48fc6cc commit 26b12ad

File tree

6 files changed

+45
-7
lines changed

6 files changed

+45
-7
lines changed

src/components/Alert/Alert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from 'styled-components';
33
import PropTypes from 'prop-types';
44

55
import Text from '../Text';
6+
import { spacing } from '../../theme/selectors';
67
import { fromAtoms } from '../../utils/theme';
78

89
const StyledAlert = styled.div`
@@ -13,7 +14,7 @@ const StyledAlert = styled.div`
1314
margin: 8px 0 8px 0;
1415
min-height: 1em;
1516
opacity: ${props => (props.visible ? '1' : '0')};
16-
padding: 1em;
17+
padding: ${spacing('small')};
1718
transition: opacity 0.2s linear;
1819
1920
a {

src/components/Alert/__snapshots__/Alert.test.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports[`<Alert /> snapshots renders default 1`] = `
1212
margin: 8px 0 8px 0;
1313
min-height: 1em;
1414
opacity: 1;
15-
padding: 1em;
15+
padding: 16px;
1616
-webkit-transition: opacity 0.2s linear;
1717
transition: opacity 0.2s linear;
1818
}
@@ -62,7 +62,7 @@ exports[`<Alert /> snapshots renders error 1`] = `
6262
margin: 8px 0 8px 0;
6363
min-height: 1em;
6464
opacity: 1;
65-
padding: 1em;
65+
padding: 16px;
6666
-webkit-transition: opacity 0.2s linear;
6767
transition: opacity 0.2s linear;
6868
}
@@ -112,7 +112,7 @@ exports[`<Alert /> snapshots renders icon if provided 1`] = `
112112
margin: 8px 0 8px 0;
113113
min-height: 1em;
114114
opacity: 1;
115-
padding: 1em;
115+
padding: 16px;
116116
-webkit-transition: opacity 0.2s linear;
117117
transition: opacity 0.2s linear;
118118
}
@@ -162,7 +162,7 @@ exports[`<Alert /> snapshots renders success 1`] = `
162162
margin: 8px 0 8px 0;
163163
min-height: 1em;
164164
opacity: 1;
165-
padding: 1em;
165+
padding: 16px;
166166
-webkit-transition: opacity 0.2s linear;
167167
transition: opacity 0.2s linear;
168168
}
@@ -221,7 +221,7 @@ exports[`<Alert /> snapshots renders title if provided 1`] = `
221221
margin: 8px 0 8px 0;
222222
min-height: 1em;
223223
opacity: 1;
224-
padding: 1em;
224+
padding: 16px;
225225
-webkit-transition: opacity 0.2s linear;
226226
transition: opacity 0.2s linear;
227227
}
@@ -289,7 +289,7 @@ exports[`<Alert /> snapshots renders warning 1`] = `
289289
margin: 8px 0 8px 0;
290290
min-height: 1em;
291291
opacity: 1;
292-
padding: 1em;
292+
padding: 16px;
293293
-webkit-transition: opacity 0.2s linear;
294294
transition: opacity 0.2s linear;
295295
}

src/components/Input/__snapshots__/Input.test.js.snap

+9
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ exports[`<Input /> should render correctly 1`] = `
266266
"tooltip": 6,
267267
},
268268
"overlayIconSize": "300px",
269+
"spacing": Object {
270+
"base": "24px",
271+
"large": "48px",
272+
"none": "0px",
273+
"small": "16px",
274+
"xl": "64px",
275+
"xs": "8px",
276+
"xss": "4px",
277+
},
269278
"textColor": "hsl(0, 0%, 10%)",
270279
}
271280
}

src/theme/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { colors, themeColorsAsScss } from './colors';
22
import { fontSizes, fontFamilies, themeFontsAsScss } from './fonts';
33
import { borderRadius, themeBorderRadiiAsScss } from './borders';
44
import { layers, themeLayersAsScss } from './layers';
5+
import { spacing, themeSpacingsAsScss } from './spacings';
56
import { overlayIconSize, textColor, themeMiscVarsAsScss } from './misc';
67
import { boxShadow } from './box-shadows';
78
import { atoms } from './atoms';
@@ -12,6 +13,7 @@ export function themeVarsAsScss() {
1213
.concat(themeLayersAsScss())
1314
.concat(themeFontsAsScss())
1415
.concat(themeBorderRadiiAsScss())
16+
.concat(themeSpacingsAsScss())
1517
.concat(themeMiscVarsAsScss());
1618
return `${themeVariables.join('; ')};`;
1719
}
@@ -36,6 +38,9 @@ const theme = {
3638
// z-index layers
3739
layers,
3840

41+
// Spacings
42+
spacing,
43+
3944
// Misc
4045
overlayIconSize,
4146
textColor,

src/theme/selectors.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export const boxShadow = themeSelector('boxShadow');
1818
export const borderRadius = themeSelector('borderRadius');
1919
export const color = themeSelector('colors');
2020
export const fontSize = themeSelector('fontSizes');
21+
export const spacing = themeSelector('spacing');

src/theme/spacings.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { forEach } from 'lodash';
2+
3+
export const spacing = {
4+
none: '0px',
5+
xss: '4px',
6+
xs: '8px',
7+
small: '16px',
8+
base: '24px',
9+
large: '48px',
10+
xl: '64px',
11+
};
12+
13+
// Collects all theme spacing vars as SCSS vars.
14+
export function themeSpacingsAsScss() {
15+
const themeSpacings = [];
16+
17+
forEach(spacing, (value, name) => {
18+
themeSpacings.push(`$spacing-${name}: ${value}`);
19+
});
20+
21+
return themeSpacings;
22+
}

0 commit comments

Comments
 (0)