Skip to content

Commit

Permalink
fix(Button): 修復 breakpoints.map is not a function 問題
Browse files Browse the repository at this point in the history
原因出在 styled-system@^5.1.4 底下的 @styled-system/css/dist/index.esm.js 第 115 與 116 行:

```js
var breakpoints = get(theme, 'breakpoints', defaultBreakpoints);
var mediaQueries = [null].concat(breakpoints.map(function (n) {
```

這裡的 `theme.breakpoints` default 本來應該是 array,但因為 2B 剛好也有 `theme.breakpoints`,而且類型是 object,加上 theme override [1] 機制在 [email protected] 又壞掉!

所以兩個問題加起來,導致 `breakpoints.map is not a function`。

解決方法:

1. 避免 Button 的 theme 被 override [1]
2. 升級 [email protected] 修復 theme override bug [2][3]

- [1] https://styled-components.com/docs/advanced#the-theme-prop
- [2] styled-components/styled-components#294
- [3] styled-components/styled-components@14c1c29

Ref hahow/hahow-for-business#724
  • Loading branch information
amowu committed Feb 4, 2020
1 parent f115078 commit fb030dd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 69 deletions.
72 changes: 25 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"peerDependencies": {
"react": "16.x",
"styled-components": ">= 4"
"styled-components": ">= 5"
},
"devDependencies": {
"@percy/storybook": "^3.2.0",
Expand Down Expand Up @@ -67,7 +67,7 @@
"nwb": "0.23.x",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"styled-components": "^4.4.1"
"styled-components": "^5.0.0"
},
"author": "",
"homepage": "",
Expand Down
39 changes: 19 additions & 20 deletions src/components/Button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,25 @@ const Button = ({
// 以下為另外處理的 props
children, icon, iconPos, testId,
}) => (
<ThemeProvider theme={theme}>
<StyledButton
block={block}
brand={brand}
className={className}
data-test-id={testId}
disabled={disabled}
href={href}
htmlType={htmlType}
loading={loading}
onClick={onClick}
size={size}
target={target}
type={type}
>
{icon && iconPos === 'left' && <Icon type={icon} />}
{children}
{icon && iconPos === 'right' && <Icon type={icon} />}
</StyledButton>
</ThemeProvider>
<StyledButton
block={block}
brand={brand}
className={className}
data-test-id={testId}
disabled={disabled}
href={href}
htmlType={htmlType}
loading={loading}
onClick={onClick}
size={size}
target={target}
theme={theme}
type={type}
>
{icon && iconPos === 'left' && <Icon type={icon} />}
{children}
{icon && iconPos === 'right' && <Icon type={icon} />}
</StyledButton>
);

Button.propTypes = {
Expand Down

0 comments on commit fb030dd

Please sign in to comment.