Skip to content

Commit 7efc77e

Browse files
authored
fix: Theming and typography (#56)
* Remove unused helper * Fix wrong Icon reference * Re-enable Storybook on IE11 * Update style mixins for Button * Add Label component * Speed-up Icon mouting * Condense helpers * Remove labels from CheckBox and RadioButton * Avoid runtime string transformations * Update theming for CheckBox, RadioButton, and ToggleSwitch * Add Hint component; update Field, ButtonGroup, and FieldGroup * Remove obsolete mixins * Remove styled-components from the final bundle * Use adimensional lengths on tokens * Add some typographic components * Update storybook helpers * Update dependencies * Autoprefix standard classes * Rename typography module as textStyles * Rename actions module as buttonColors * Drop CSS variables again * Remove some subclasses * Add missing diplayName * Reenable CSS vars to base theme variables * Reattach theme variables to components
1 parent bb323c0 commit 7efc77e

File tree

369 files changed

+2485
-1736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+2485
-1736
lines changed

package.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
"packages/*"
77
],
88
"devDependencies": {
9-
"@babel/core": "^7.4.5",
10-
"@babel/preset-env": "^7.4.5",
11-
"@babel/preset-react": "^7.0.0",
12-
"babel-loader": "^8.0.6",
139
"cross-env": "^5.2.0",
1410
"fs-extra": "^8.0.1",
1511
"gh-pages": "^2.0.1",
1612
"husky": "^2.3.0",
17-
"jest": "^24.8.0",
18-
"lerna": "^3.14.1",
19-
"webpack-cli": "^3.3.2"
13+
"lerna": "^3.14.1"
2014
},
2115
"scripts": {
2216
"build": "lerna run build --stream",
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

packages/fuselage/.storybook/addons.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ import '@storybook/addon-links/register';
66
import '@storybook/addon-notes/register';
77
import '@storybook/addon-options/register';
88
import '@storybook/addon-viewport/register';
9-
import 'storybook-addon-jsx/register';

packages/fuselage/.storybook/jest-results.json

+1-1
Large diffs are not rendered by default.

packages/fuselage/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"lint-staged": "lint-staged",
2727
"test": "jest",
2828
"test:results": "jest --json --outputFile=.storybook/jest-results.json",
29-
"loki:test": "loki test --chromeDockerImage=chinello/alpine-chrome:73 --chromeFlags=\"--headless --no-sandbox --disable-gpu\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
30-
"loki:update": "loki update --chromeDockerImage=chinello/alpine-chrome:73 --chromeFlags=\"--headless --no-sandbox --disable-gpu\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
31-
"loki:test-ci": "loki test --chromeFlags=\"--headless --no-sandbox --disable-gpu\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
32-
"loki:update-ci": "loki update --chromeFlags=\"--headless --no-sandbox --disable-gpu\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
29+
"loki:test": "loki test --chromeDockerImage=chinello/alpine-chrome:73 --chromeFlags=\"--headless --no-sandbox --disable-gpu --disable-features=VizDisplayCompositor\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
30+
"loki:update": "loki update --chromeDockerImage=chinello/alpine-chrome:73 --chromeFlags=\"--headless --no-sandbox --disable-gpu --disable-features=VizDisplayCompositor\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
31+
"loki:test-ci": "loki test --chromeFlags=\"--headless --no-sandbox --disable-gpu --disable-features=VizDisplayCompositor\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
32+
"loki:update-ci": "loki update --chromeFlags=\"--headless --no-sandbox --disable-gpu --disable-features=VizDisplayCompositor\" --verboseRenderer --requireReference --reactUri file:./storybook-static",
3333
"storybook": "start-storybook -p 6006",
3434
"build-storybook": "build-storybook",
3535
"update-storybook": "run-s test:results build-storybook loki:update"
@@ -58,6 +58,7 @@
5858
"babel-eslint": "^10.0.2",
5959
"babel-loader": "^8.0.6",
6060
"babel-plugin-styled-components": "^1.10.6",
61+
"cross-env": "^5.2.0",
6162
"css-vars-ponyfill": "^2.0.2",
6263
"cssnano": "^4.1.10",
6364
"eslint": "^6.1.0",
@@ -79,7 +80,6 @@
7980
"react-final-form-hooks": "^2.0.0",
8081
"react-helmet": "^5.2.1",
8182
"sass-loader": "^7.1.0",
82-
"storybook-addon-jsx": "^7.1.2",
8383
"stylelint": "^10.0.1",
8484
"stylelint-order": "^3.0.0",
8585
"webpack-bundle-analyzer": "^3.3.2",
+73-154
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,100 @@
11
import styled, { css } from 'styled-components';
22

3-
import { rebuildClassName } from '../../helpers/rebuildClassName';
4-
import { disableable } from '../../mixins/disableable';
5-
import { reset } from '../../mixins/reset';
6-
import { unselectable } from '../../mixins/unselectable';
7-
import { withText } from '../../mixins/withText';
3+
import { extendClassName } from '../../helpers';
4+
import {
5+
withText,
6+
normalized,
7+
clickable,
8+
withTruncatedText,
9+
withBorder,
10+
withButtonActionColors,
11+
} from '../../mixins';
812
import { Icon } from '../Icon';
9-
import theme from './theme';
10-
11-
12-
const sizeVariant = ({
13-
height,
14-
paddingVertical,
15-
paddingHorizontal,
16-
fontSize,
17-
lineHeight,
18-
iconSize,
13+
import {
14+
mediumSizeParameters,
15+
smallSizeParameters,
16+
basicColors,
17+
basicDangerColors,
18+
primaryColors,
19+
primaryDangerColors,
20+
ghostColors,
21+
ghostDangerColors,
22+
} from './theme';
23+
24+
25+
const withSizeVariant = ({
26+
border,
27+
paddingX,
28+
textStyle,
29+
iconSizeRatio,
1930
}) => css`
20-
height: ${ height };
21-
padding: ${ paddingVertical } ${ paddingHorizontal };
31+
${ withBorder(border) }
32+
padding: 0 calc(${ paddingX } - ${ border.width });
33+
34+
${ withText(textStyle) }
2235
23-
font-size: ${ fontSize };
24-
line-height: ${ lineHeight };
36+
line-height: calc(2 * ${ textStyle.lineHeight } - 2 * ${ border.width });
2537
2638
& > ${ Icon } {
27-
font-size: ${ iconSize };
39+
font-size: ${ iconSizeRatio * textStyle.lineHeight };
2840
}
2941
3042
${ ({ square }) => square && css`
31-
width: ${ height };
32-
padding: ${ paddingVertical } 0;
43+
width: calc(2 * ${ textStyle.lineHeight });
44+
padding: 0;
3345
34-
& > .rcx-icon {
35-
font-size: ${ lineHeight };
46+
& > ${ Icon } {
47+
font-size: ${ textStyle.lineHeight };
3648
}
3749
` }
3850
`;
3951

40-
const mediumSizeVariant = () => sizeVariant({
41-
height: theme.height,
42-
paddingVertical: theme.paddingVertical,
43-
paddingHorizontal: theme.paddingHorizontal,
44-
fontSize: theme.fontSize,
45-
lineHeight: theme.lineHeight,
46-
iconSize: theme.iconSize,
47-
});
48-
49-
const smallSizeVariant = ({ small }) => small && sizeVariant({
50-
height: theme.smallHeight,
51-
paddingVertical: theme.smallPaddingVertical,
52-
paddingHorizontal: theme.smallPaddingHorizontal,
53-
fontSize: theme.smallFontSize,
54-
lineHeight: theme.smallLineHeight,
55-
iconSize: theme.smallIconSize,
56-
});
57-
58-
const colorsVariant = ({
59-
color,
60-
backgroundColor,
61-
hoverBackgroundColor,
62-
activeBackgroundColor,
63-
focusBackgroundColor,
64-
focusBorderColor,
65-
focusShadowColor,
66-
disabledColor,
67-
disabledBackgroundColor,
68-
}) => css`
69-
color: ${ color };
70-
border-color: ${ backgroundColor };
71-
background-color: ${ backgroundColor };
72-
73-
&:enabled:focus,
74-
&:enabled.focus {
75-
border-color: ${ focusBorderColor };
76-
background-color: ${ focusBackgroundColor };
77-
78-
${ focusShadowColor && css`box-shadow: 0 0 0 6px ${ focusShadowColor };` }
79-
}
80-
81-
&:enabled:hover,
82-
&:enabled.hover {
83-
border-color: ${ hoverBackgroundColor };
84-
background-color: ${ hoverBackgroundColor };
85-
box-shadow: none;
86-
}
87-
88-
&:enabled:active,
89-
&:enabled.active {
90-
border-color: ${ activeBackgroundColor };
91-
background-color: ${ activeBackgroundColor };
92-
box-shadow: none;
93-
}
94-
95-
&:disabled {
96-
color: ${ disabledColor };
97-
border-color: ${ disabledBackgroundColor };
98-
background-color: ${ disabledBackgroundColor };
99-
}
100-
`;
101-
102-
const basicColorsVariant = () => css`
103-
${ colorsVariant({
104-
color: theme.basicColor,
105-
backgroundColor: theme.basicBackgroundColor,
106-
hoverBackgroundColor: theme.basicHoverBackgroundColor,
107-
activeBackgroundColor: theme.basicActiveBackgroundColor,
108-
focusBackgroundColor: theme.basicFocusBackgroundColor,
109-
focusBorderColor: theme.basicFocusBorderColor,
110-
focusShadowColor: theme.basicFocusShadowColor,
111-
disabledColor: theme.basicDisabledColor,
112-
disabledBackgroundColor: theme.basicDisabledBackgroundColor,
113-
}) }
114-
115-
${ ({ danger }) => danger && colorsVariant({
116-
color: theme.basicDangerColor,
117-
disabledColor: theme.basicDisabledDangerColor,
118-
}) }
119-
`;
120-
121-
const primaryColorsVariant = ({ primary }) => primary && css`
122-
${ colorsVariant({
123-
color: theme.primaryColor,
124-
backgroundColor: theme.primaryBackgroundColor,
125-
hoverBackgroundColor: theme.primaryHoverBackgroundColor,
126-
activeBackgroundColor: theme.primaryActiveBackgroundColor,
127-
focusBackgroundColor: theme.primaryFocusBackgroundColor,
128-
focusBorderColor: theme.primaryFocusBorderColor,
129-
focusShadowColor: theme.primaryFocusShadowColor,
130-
disabledColor: theme.primaryColor,
131-
disabledBackgroundColor: theme.primaryDisabledBackgroundColor,
132-
}) }
133-
134-
${ ({ danger }) => danger && colorsVariant({
135-
color: theme.primaryColor,
136-
backgroundColor: theme.primaryDangerBackgroundColor,
137-
hoverBackgroundColor: theme.primaryDangerHoverBackgroundColor,
138-
activeBackgroundColor: theme.primaryDangerActiveBackgroundColor,
139-
focusBackgroundColor: theme.primaryDangerFocusBackgroundColor,
140-
focusBorderColor: theme.primaryDangerFocusBorderColor,
141-
focusShadowColor: theme.primaryDangerFocusShadowColor,
142-
disabledColor: theme.primaryColor,
143-
disabledBackgroundColor: theme.primaryDangerDisabledBackgroundColor,
144-
}) }
145-
`;
146-
147-
const ghostColorsVariant = ({ ghost }) => ghost && colorsVariant({
148-
backgroundColor: 'transparent',
149-
});
150-
151-
export const Button = styled.button.attrs(rebuildClassName('rcx-button'))`
152-
${ reset }
153-
${ disableable }
154-
${ unselectable }
155-
${ withText }
52+
const mediumSized = withSizeVariant(mediumSizeParameters);
53+
const smallSized = withSizeVariant(smallSizeParameters);
54+
55+
const basicColored = withButtonActionColors(basicColors);
56+
const basicDangerColored = withButtonActionColors(basicDangerColors);
57+
const primaryColored = withButtonActionColors(primaryColors);
58+
const primaryDangerColored = withButtonActionColors(primaryDangerColors);
59+
const ghostColored = withButtonActionColors(ghostColors);
60+
const ghostDangerColored = withButtonActionColors(ghostDangerColors);
61+
62+
export const Button = styled.button.attrs(({
63+
className,
64+
external,
65+
...props
66+
}) => ({
67+
className: extendClassName('button', className, props),
68+
type: props.type || ((!props.as || props.as === 'button') && 'button') || undefined,
69+
rel: props.rel || (props.as === 'a' && external && 'noopener noreferrer') || undefined,
70+
target: props.target || (props.as === 'a' && external && '_blank') || undefined,
71+
}))`
72+
${ normalized }
73+
${ clickable }
74+
${ withTruncatedText }
15675
15776
display: inline-block;
15877
159-
cursor: pointer;
160-
161-
border-width: ${ theme.borderWidth };
162-
border-style: solid;
163-
border-radius: ${ theme.borderRadius };
164-
16578
text-align: center;
79+
vertical-align: middle;
16680
167-
font-family: ${ theme.fontFamily };
168-
font-weight: ${ theme.fontWeight };
81+
appearance: none;
16982
17083
& > ${ Icon } {
17184
vertical-align: middle;
17285
}
17386
174-
${ mediumSizeVariant }
175-
${ smallSizeVariant }
176-
177-
${ basicColorsVariant }
178-
${ primaryColorsVariant }
179-
${ ghostColorsVariant }
87+
${ ({ small }) =>
88+
(small && smallSized)
89+
|| mediumSized }
90+
91+
${ ({ danger, ghost, primary }) =>
92+
(ghost && danger && ghostDangerColored)
93+
|| (ghost && ghostColored)
94+
|| (primary && danger && primaryDangerColored)
95+
|| (primary && primaryColored)
96+
|| (danger && basicDangerColored)
97+
|| basicColored }
18098
`;
99+
181100
Button.displayName = 'Button';

packages/fuselage/src/components/Button/stories.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import * as icons from '@rocket.chat/icons/dist/font';
2+
import { action } from '@storybook/addon-actions';
23
import centered from '@storybook/addon-centered/react';
34
import { withKnobs, text, select } from '@storybook/addon-knobs';
45
import { storiesOf } from '@storybook/react';
56
import React from 'react';
6-
import { jsxDecorator } from 'storybook-addon-jsx';
77

8-
import { Document, TextSection, VariationsTable, createPropsFromKnobs, handleEvent } from '../../helpers/storybook';
8+
import {
9+
createPropsFromKnobs,
10+
Document,
11+
PropsVariationSection,
12+
TextSection,
13+
} from '../../helpers/storybook';
914
import { Icon } from '../Icon';
1015
import { Button } from './index';
1116

1217

1318
storiesOf('Elements|Button', module)
19+
.addParameters({ jest: ['Button/spec'] })
1420
.lokiSkip('Button', () => <Document>
1521
<TextSection>
1622
<h1>Button</h1>
@@ -21,7 +27,7 @@ storiesOf('Elements|Button', module)
2127
<TextSection>
2228
<h2>Basic</h2>
2329
</TextSection>
24-
<VariationsTable
30+
<PropsVariationSection
2531
component={Button}
2632
xAxis={{
2733
text: { children: 'Button' },
@@ -40,7 +46,7 @@ storiesOf('Elements|Button', module)
4046
<TextSection>
4147
<h2>Primary</h2>
4248
</TextSection>
43-
<VariationsTable
49+
<PropsVariationSection
4450
component={Button}
4551
common={{ primary: true }}
4652
xAxis={{
@@ -60,7 +66,7 @@ storiesOf('Elements|Button', module)
6066
<TextSection>
6167
<h2>Ghost</h2>
6268
</TextSection>
63-
<VariationsTable
69+
<PropsVariationSection
6470
component={Button}
6571
common={{ ghost: true }}
6672
xAxis={{
@@ -88,14 +94,13 @@ const props = createPropsFromKnobs({
8894
small: false,
8995
square: false,
9096
children: 'Button',
91-
onClick: handleEvent('click'),
97+
onClick: action('click'),
9298
});
9399

94100
storiesOf('Elements|Button', module)
95-
.addDecorator(jsxDecorator)
96101
.addDecorator(withKnobs)
97102
.addDecorator(centered)
98-
.addParameters({ jest: ['spec'] })
103+
.addParameters({ jest: ['Button/spec'] })
99104
.add('basic', () => <Button {...props()} />)
100105
.add('primary', () => <Button {...props({ primary: true })} />)
101106
.add('ghost', () => <Button {...props({ ghost: true })} />)
@@ -110,10 +115,9 @@ storiesOf('Elements|Button', module)
110115
/>)
111116
.add('as link', () => <Button
112117
{...props()}
113-
forwardedAs='a'
118+
as='a'
114119
href='https://rocket.chat'
115-
target='_blank'
116-
rel='noopener noreferrer'
120+
external
117121
/>
118122
)
119123
.add('square', () => (

0 commit comments

Comments
 (0)