Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit cec1029

Browse files
committed
feat: simplify core & remove theme dependency
Refactor all components to avoid theme dependency. It should reduce bundle size and load only needed functions from theme. The library will be able to scale easily. BREAKING CHANGE: - `prop` utility has been removed - Undocumented utilities are no longer exported - `controlFocus` has been renamed `baseFocus`, `controlFocus` is only for controls (when control prop is `true`) - `mixin` function is no longer available, also mixins have changed **Mixins:** Previously mixins were called using `mixin` helper: ```js import { styled, mixin } from '@smooth-ui/core-sc' const Styled = styled.div` color: ${mixin('colorLevel', 'red', 5)}; ` ``` All mixins are now exported: ```js import { styled, colorLevel } from '@smooth-ui/core-sc' const Styled = styled.div` color: ${colorLevel('red', 5)}; ` ``` **Theme** Theme is no longer required, Smooth UI will work well without theme and you can override only needed properties without having to load the entire theme. The benefit from that approach is that code splitting is fully efficient, if you use only one component in Smooth UI you will load only theme primitives of this component. The size of a result bundle that is using only a `Button`: ``` 202K bundle-smooth-ui-v8.js 194K bundle-smooth-ui-v9.js 65K bundle-smooth-ui-v8.js.gz 63K bundle-smooth-ui-v9.js.gz ``` As you can see the bundle has been reduced of 8K (no gzip) and of 2K (gzip).
1 parent 3ac41ec commit cec1029

Some content is hidden

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

78 files changed

+3202
-3585
lines changed

docs/basics/Accessibility.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Smooth UI takes accessibility seriously. We do our best to ensure that all compo
1414

1515
All components implement [reduced motion media query](https://css-tricks.com/introduction-reduced-motion-media-query/), it means they respect settings of users.
1616

17-
`transition` mixin automatically adds the reduced motion media query.
17+
`transition` utility automatically adds the reduced motion media query.
1818

1919
```js
20-
import { mixin } from '@smooth-ui/core-sc'
20+
import { transition } from '@smooth-ui/core-sc'
2121

2222
const AccessibleButton = styled.button`
2323
background-color: red;
24-
${mixin('transition', 'background-color 200ms')};
24+
${transition('background-color 200ms')};
2525
2626
&:hover {
2727
background-color: blue;

docs/basics/Theming.mdx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ Smooth UI has a powerful theming feature. It uses [Styled Components theming fea
1313

1414
## Create a custom theme
1515

16-
The recommended way to create a custom theme is to create a file named `theme.js` that exports all `@smooth-ui/core-*/theme` and overrides only the needed parts.
16+
The recommended way to create a custom theme is to create a file named `theme.js`, you can add your custom values and override existing ones.
1717

1818
```js
1919
// theme.js
20-
import { theme } from '@smooth-ui/core-sc'
2120

2221
export default {
23-
...theme,
2422
primary: 'blue',
23+
myNewColor: '#000',
2524
}
2625
```
2726

@@ -46,11 +45,35 @@ render(
4645

4746
## Default theme
4847

49-
You can find all theme values in [the default theme](https://github.com/smooth-code/smooth-ui/blob/master/packages/shared/core/theme.js).
48+
You can find all theme values in [theming section](https://github.com/smooth-code/smooth-ui/blob/master/packages/shared/core/theming/).
5049

51-
Two ways to import theme in your code:
50+
The whole theme is exported under `theme` named export:
5251

5352
```js
5453
import { theme } from '@smooth-ui/core-sc'
55-
import theme from '@smooth-ui/core-sc/theme'
54+
```
55+
56+
## Use theme property
57+
58+
You can use `th` utility to use a theme property in your code:
59+
60+
```js
61+
import { styled, th } from '@smooth-ui/core-sc'
62+
63+
const RedBox = styled.div`
64+
background-color: ${th('primary')};
65+
`
66+
```
67+
68+
But you can also use it to create a reference in your theme:
69+
70+
```js
71+
// theme.js
72+
import { th } from '@smooth-ui/core-sc'
73+
74+
export default {
75+
blue: '#00bdff',
76+
// primary is now a reference to `blue`
77+
primary: th('blue'),
78+
}
5679
```

docs/basics/Utilities.mdx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const Box = styled.div`
4545

4646
### th
4747

48-
`th` lets you get a property from the theme, you can also apply a modifier.
48+
`th` lets you get a property from the theme, you can also apply a transform function.
4949

5050
```js
5151
import { styled, th } from '@smooth-ui/core-sc'
@@ -58,20 +58,6 @@ const RedBox = styled.div`
5858
`
5959
```
6060

61-
### prop
62-
63-
`prop` lets you get a property from props, you can also specify a theme default.
64-
65-
```js
66-
import { styled, prop } from '@smooth-ui/core-sc'
67-
68-
const RedBox = styled.div`
69-
width: 200px;
70-
height: 200px;
71-
background-color: ${prop('bgColor', 'primary')};
72-
`
73-
```
74-
7561
### unit, px
7662

7763
`unit` automatically adds unit.

docs/components/Checkbox.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Disable using `disabled` prop.
5656

5757
## Control & Validation
5858

59-
* Set `display` to "block" and `width` to "100%" using `control` prop.
60-
* Set validation using `valid` or `valid={false}`
59+
- Set custom focus effect using `control` prop.
60+
- Set validation using `valid` or `valid={false}`
6161

6262
<Playground>
6363
<FormCheck>

docs/components/Radio.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,52 @@ Disable using `disabled` prop.
5050

5151
In most of case you don't need a `RadioGroup`. It is only necessary if you use [uncontrolled radio buttons](https://reactjs.org/docs/uncontrolled-components.html). All moderns like [Final Form](https://github.com/final-form/react-final-form) or [Formik](https://github.com/jaredpalmer/formik) uses controlled components, so `RadioGroup` is not required.
5252

53+
## Control & Validation
54+
55+
- Set custom focus effect using `control` prop.
56+
- Set validation using `valid` or `valid={false}`
57+
58+
<Playground>
59+
<RadioGroup>
60+
<FormCheck>
61+
<Radio control id="controlRadio1" name="controlRadios" value="option1" />
62+
<FormCheckLabel htmlFor="controlRadio1">Control</FormCheckLabel>
63+
</FormCheck>
64+
<FormCheck>
65+
<Radio
66+
control
67+
valid={true}
68+
id="controlRadio2"
69+
name="controlRadios"
70+
value="option2"
71+
/>
72+
<FormCheckLabel htmlFor="controlRadio2">Valid control</FormCheckLabel>
73+
</FormCheck>
74+
<FormCheck>
75+
<Radio
76+
control
77+
valid={false}
78+
id="controlRadio3"
79+
name="controlRadios"
80+
value="option3"
81+
/>
82+
<FormCheckLabel htmlFor="controlRadio3">Invalid control</FormCheckLabel>
83+
</FormCheck>
84+
</RadioGroup>
85+
</Playground>
86+
5387
## API
5488

5589
### Radio
5690

5791
<PropsTable
5892
of={PropDesc({
5993
checked: PropDesc.bool,
94+
control: PropDesc.bool,
6095
disabled: PropDesc.bool,
6196
onChange: PropDesc.func,
6297
size: PropDesc.oneOf(['sm', 'lg']),
98+
valid: PropDesc.bool,
6399
value: PropDesc.string,
64100
...getSystemPropDesc(Radio),
65101
})}

docs/components/Typography.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ HTML component is automatically determined from variant. You can customize it us
5858
}}
5959
</Playground>
6060

61-
### Using `uiAs` property
61+
### Using `as` property
6262

6363
<Playground>
64-
<Typography variant="h4" uiAs="div">
64+
<Typography variant="h4" as="div">
6565
div displayed as h4
6666
</Typography>
6767
</Playground>

examples/basics/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist/

examples/basics/src/emotion/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* @jsx jsx */
33
import React from 'react'
44
import { render } from 'react-dom'
5-
import { jsx, css, Button, Normalize, styled, uiAs } from '@smooth-ui/core-em'
5+
import { jsx, css, Button, Normalize, styled } from '@smooth-ui/core-em'
66

77
const BlackButton = styled(Button)`
88
color: black;
@@ -35,6 +35,7 @@ const App = () => (
3535
<div>
3636
<Button
3737
css={{ color: 'black' }}
38+
backgroundColor="secondary"
3839
>{`<Button css={{{color: 'black'}}>`}</Button>
3940
</div>
4041
</>

examples/basics/src/styled-components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
import React from 'react'
3-
import { Button, Normalize, styled, uiAs } from '@smooth-ui/core-sc'
3+
import { Button, Normalize, styled } from '@smooth-ui/core-sc'
44

55
const BlackButton = styled(Button)`
66
color: black;
@@ -33,6 +33,7 @@ const App = () => (
3333
<div>
3434
<Button
3535
css={{ color: 'black' }}
36+
backgroundColor="secondary"
3637
>{`<Button css={{{color: 'black'}}>`}</Button>
3738
</div>
3839
</>

examples/basics/webpack.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
mode: 'development',
2+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
33
module: {
44
rules: [
55
{
@@ -8,4 +8,7 @@ module.exports = {
88
},
99
],
1010
},
11+
optimization: {
12+
usedExports: true,
13+
},
1114
}

0 commit comments

Comments
 (0)