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

Commit b25675a

Browse files
committed
feat: support styled-components v4
BREAKING CHANGE: - styled-components v4 is required - `.extend` has been removed, please use `styled()` instead - `component` prop has been removed, please use `as` instead
1 parent 330dd20 commit b25675a

File tree

21 files changed

+5064
-142
lines changed

21 files changed

+5064
-142
lines changed

docs/GettingStarted.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ export default App
3434
Even if it is not required, is recommended to apply a global normalize before using Smooth UI.
3535

3636
```js
37-
import { injectGlobal } from 'styled-components'
38-
import { globalStyle } from '@smooth-ui/core-sc'
39-
40-
injectGlobal`${globalStyle()}`
37+
import { globalStyle, createGlobalStyle } from '@smooth-ui/core-sc'
38+
const GlobalStyle = createGlobalStyle`${globalStyle()}`
4139
```
4240

4341
If you don't want to use a global normalize, at least add `* { box-sizing: border-box; }`.

docs/advanced/ExtendStyles.mdx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ menu: Advanced
44
---
55

66
import { Playground } from 'docz'
7-
import { Button, Switch } from '@smooth-ui/core-sc'
7+
import { Button, Switch, styled } from '@smooth-ui/core-sc'
88

99
# Extend Styles
1010

@@ -46,15 +46,17 @@ An example of inline style to change the `padding` of a button.
4646
</Button>
4747
```
4848

49-
## Local extend using .extend
49+
## Local extend using styled
5050

51-
Every Smooth UI components expose a method `.extend`. You can use it to override any CSS property of the original component. It creates a new component and doesn't affect other components.
51+
You can override any CSS property of the original component using `styled`. It creates a new component and doesn't affect other components.
5252

5353
An example of a `BorderedButton` extended from a `Button`:
5454

5555
<Playground>
5656
{() => {
57-
const BorderedButton = Button.extend`
57+
// import { styled } from '@smooth-ui/core-sc'
58+
59+
const BorderedButton = styled(Button)`
5860
border: 2px solid black;
5961
6062
&:hover {
@@ -80,7 +82,9 @@ An example of a custom `Switch` with a black ball 🎱.
8082

8183
<Playground>
8284
{() => {
83-
const BlackBallSwitch = Switch.extend`
85+
// import { styled } from '@smooth-ui/core-sc'
86+
87+
const BlackBallSwitch = styled(Switch)`
8488
.sui-switch-ball {
8589
background-color: black !important;
8690
}

docs/advanced/Refs.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { Input, styled } from '@smooth-ui/core-sc'
88

99
# Refs
1010

11-
Passing a `innerRef` prop to a Smooth UI component will give you the ref of the DOM node.
11+
Passing a `ref` prop to a Smooth UI component will give you the ref of the DOM node.
12+
13+
> Be careful, if you use emotion or styled-components v4, you have to use "innerRef" instead of "ref".
1214
1315
<Playground>
1416
{() => {
@@ -21,7 +23,7 @@ Passing a `innerRef` prop to a Smooth UI component will give you the ref of the
2123
render() {
2224
return (
2325
<Input
24-
innerRef={this.inputRef}
26+
ref={this.inputRef}
2527
placeholder="Hover to focus!"
2628
onMouseEnter={() => {
2729
this.inputRef.current.focus()

docs/components/Modal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
2-
import { ModalDialog } from '@smooth-ui/core-sc'
2+
import { styled, ModalDialog } from '@smooth-ui/core-sc'
33

4-
export const ModalDialogExample = ModalDialog.extend`
4+
export const ModalDialogExample = styled(ModalDialog)`
55
left: auto;
66
margin-right: auto;
77
margin-left: auto;

docs/config/Wrapper.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@
22
import React from 'react'
33
import { transparentize } from 'polished'
44
import { ThemeProvider } from 'emotion-theming'
5-
import { theme, th, injectGlobal, globalStyle } from '@smooth-ui/core-sc'
5+
import { theme, th, createGlobalStyle, globalStyle } from '@smooth-ui/core-sc'
66

7-
const fromTheme = value => th(value)({ theme })
8-
9-
injectGlobal`
7+
const GlobalStyle = createGlobalStyle`
108
${globalStyle()}
119
1210
.sui-row + .sui-row {
1311
margin-top: 1rem;
1412
}
1513
1614
.sui-col {
17-
border: 1px solid ${fromTheme('primary')};
18-
background-color: ${transparentize(0.6, fromTheme('primary'))};
15+
border: 1px solid ${th('primary')};
16+
background-color: ${th('primary', color => transparentize(0.6, color))};
1917
padding-top: .75rem;
2018
padding-bottom: .75rem;
2119
}
2220
2321
.example-row-flex-cols .sui-row {
2422
min-height: 10rem;
25-
background-color: ${transparentize(0.7, fromTheme('primary'))};
23+
background-color: ${th('primary', color => transparentize(0.7, color))};
2624
}
2725
`
2826

2927
const Wrapper = ({ children }) => (
30-
<ThemeProvider theme={{ ...theme }}>{children}</ThemeProvider>
28+
<ThemeProvider theme={{ ...theme }}>
29+
<>
30+
<GlobalStyle theme={{ ...theme }} />
31+
{children}
32+
</>
33+
</ThemeProvider>
3134
)
3235

3336
export default Wrapper

examples/emotion/.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "presets": ["@babel/preset-env", "@babel/preset-react"] }

examples/emotion/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<title>Page Title</title>
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
</head>
10+
11+
<body>
12+
13+
<script src="/main.js"></script>
14+
</body>
15+
16+
</html>

examples/emotion/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "emotion",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"devDependencies": {
7+
"@babel/preset-env": "^7.1.0",
8+
"@babel/preset-react": "^7.0.0",
9+
"@emotion/core": "^10.0.0-beta.0",
10+
"babel-loader": "^8.0.4",
11+
"emotion": "^10.0.0-beta.0",
12+
"emotion-theming": "^10.0.0-beta.0",
13+
"react-emotion": "^10.0.0-beta.0",
14+
"webpack": "^4.20.2",
15+
"webpack-cli": "^3.1.2",
16+
"webpack-dev-server": "^3.1.9"
17+
}
18+
}

examples/emotion/src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable */
2+
import React from 'react'
3+
import { render } from 'react-dom'
4+
import { Button, styled } from '@smooth-ui/core-em'
5+
6+
const LinkButton = styled(Button.withComponent('a').withComponent('div'))`
7+
color: blue !important;
8+
`
9+
10+
const App = () => <LinkButton>Hello</LinkButton>
11+
12+
const root = document.createElement('div')
13+
document.body.appendChild(root)
14+
15+
render(<App />, root)

examples/emotion/webpack.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
module: {
3+
rules: [
4+
{
5+
test: /\.js$/,
6+
loader: 'babel-loader',
7+
},
8+
],
9+
},
10+
}

0 commit comments

Comments
 (0)