Skip to content

Feature/emotion #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 12, 2020
Prev Previous commit
Next Next commit
setup config override rules for emotion styles
  • Loading branch information
ShMcK committed Jan 12, 2020
commit 457cdc64f0567b648ebf0fee65d46b45328073f4
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/camelcase': 'off',
'react/forbid-component-props': [1, { forbid: ['style'] }],
'react/forbid-dom-props': [1, { forbid: ['style'] }],
// 'react/forbid-component-props': [1, { forbid: ['style'] }],
// 'react/forbid-dom-props': [1, { forbid: ['style'] }],
},
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.organizeImports": false,
"source.fixAll": true
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
Expand Down
7 changes: 6 additions & 1 deletion web-app/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ module.exports = ({ config }) => {
},
],
],
presets: [['react-app', { flow: false, typescript: true }], ['@emotion/babel-preset-css-prop']],
presets: [
// react-app
['react-app', { flow: false, typescript: true }],
// allow emotion css prop on html
['@emotion/babel-preset-css-prop'],
],
},
})

Expand Down
42 changes: 40 additions & 2 deletions web-app/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
const { addLessLoader, addBabelPreset } = require('customize-cra')
const path = require('path') // eslint-disable-line

module.exports = function override(config) {
addBabelPreset('@emotion/babel-preset-css-prop')(config)
config.module.rules.push({
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
})

config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
plugins: [
// load css for @alifd/next components
[
'babel-plugin-import',
{
libraryName: '@alifd/next',
style: true,
},
],
],
presets: [
// react-app
['react-app', { flow: false, typescript: true }],
// allow emotion css prop on html
['@emotion/babel-preset-css-prop'],
],
},
})

config.resolve.extensions.push('.ts', '.tsx')

config.resolve.modules = ['node_modules', path.resolve(__dirname, './src')]

return config
}
3 changes: 1 addition & 2 deletions web-app/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Button as AlifdButton } from '@alifd/next'
import * as React from 'react'
import { css, jsx } from '@emotion/core'

interface Props {
style?: React.CSSProperties
Expand All @@ -11,7 +10,7 @@ interface Props {
}

const Button = (props: Props) => (
<AlifdButton onClick={props.onClick} type={props.type} disabled={props.disabled} css={props.style}>
<AlifdButton onClick={props.onClick} type={props.type} disabled={props.disabled} style={props.style}>
{props.children}
</AlifdButton>
)
Expand Down
3 changes: 1 addition & 2 deletions web-app/src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Icon as AlifdIcon } from '@alifd/next'
import * as React from 'react'
import { css, jsx } from '@emotion/core'

interface Props {
type: string
Expand All @@ -10,7 +9,7 @@ interface Props {
}

const Icon = (props: Props) => {
return <AlifdIcon type={props.type} role={props.role} size={props.size} css={props.style} />
return <AlifdIcon type={props.type} role={props.role} size={props.size} style={props.style} />
}

export default Icon
1 change: 0 additions & 1 deletion web-app/src/styles/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import '~@alifd/next/dist/next.css';
@import '~@alifd/theme-4/dist/next.css';

html {
Expand Down