Skip to content

Commit 353c2b1

Browse files
committed
建立component模块,支持模块化less
1 parent 0c466c1 commit 353c2b1

12 files changed

+4104
-600
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
.env.test.local
1717
.env.production.local
1818

19+
# docz
20+
.docz
21+
1922
# idea
2023
.idea
2124

config-overrides.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const {injectBabelPlugin} = require('react-app-rewired');
2-
const rewireLess = require('react-app-rewire-less');
1+
const { injectBabelPlugin } = require("react-app-rewired");
2+
const rewireLess = require("react-app-rewire-less");
33

44
module.exports = function override(config, env) {
5-
config = injectBabelPlugin(['import', {libraryName: 'antd', style: true}], config);
6-
config = rewireLess.withLoaderOptions({
7-
javascriptEnabled: true,
8-
})(config, env);
9-
return config;
10-
};
5+
config = injectBabelPlugin(
6+
["import", { libraryName: "antd", style: true }],
7+
config
8+
);
9+
config = rewireLess.withLoaderOptions({
10+
javascriptEnabled: true
11+
})(config, env);
12+
return config;
13+
};

docz_config/docz.config.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="description" content="My awesome app using Docz">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
9+
<link rel="stylesheet" type="text/css" href="{{ publicUrl }}/antd.min.css">
10+
<title>Be Quank</title>
11+
</head>
12+
13+
<body>
14+
<div id="root" />
15+
</body>
16+
17+
</html>

doczrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { css } from "docz-plugin-css";
2+
3+
export default {
4+
plugins: [
5+
css({
6+
preprocessor: "less",
7+
cssmodules: true,
8+
loaderOpts: {
9+
/* whatever your preprocessor loader accept */
10+
javascriptEnabled: true
11+
}
12+
})
13+
],
14+
indexHtml: "./docz_config/docz.config.html"
15+
};

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "fontend_default",
2+
"name": "BeQuank",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
@@ -13,12 +13,14 @@
1313
"start": "react-app-rewired start",
1414
"build": "react-app-rewired build",
1515
"test": "react-app-rewired test --env=jsdom",
16-
"styleguide": "npx styleguidist server"
16+
"docz:dev": "docz dev",
17+
"docz:build": "docz build"
1718
},
1819
"devDependencies": {
1920
"babel-plugin-import": "^1.8.0",
21+
"docz": "^0.7.1",
22+
"docz-plugin-css": "^0.7.1",
2023
"react-app-rewire-less": "^2.1.2",
21-
"react-app-rewired": "^1.5.2",
22-
"react-styleguidist": "^7.1.1"
24+
"react-app-rewired": "^1.5.2"
2325
}
2426
}

src/App.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { Component } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
4-
import {Button} from 'antd'
5-
import style from './components/'
1+
import React, { Component } from "react";
2+
import logo from "./logo.svg";
3+
import "./App.css";
4+
import { Button } from "antd";
65
class App extends Component {
76
render() {
87
return (
@@ -14,7 +13,7 @@ class App extends Component {
1413
<p className="App-intro">
1514
To get started, edit <code>src/App.js</code> and save to reload.
1615
</p>
17-
<Button type={"primary"} >abc</Button>
16+
<Button type={"primary"}>abc</Button>
1817
</div>
1918
);
2019
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name:Button
3+
menu:Example
4+
---
5+
6+
import { Playground } from 'docz'
7+
import ButtonExample from './index'
8+
9+
# ButtonExample
10+
11+
## Basic usage
12+
13+
14+
<Playground>
15+
<ButtonExample type="primary">Primary</ButtonExample>
16+
<ButtonExample>Default</ButtonExample>
17+
<ButtonExample type="dashed">Dashed</ButtonExample>
18+
<ButtonExample type="danger">Danger</ButtonExample>
19+
</Playground>
20+

src/components/ButtonExample/README.md

-10
This file was deleted.

src/components/ButtonExample/index.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import React, { PureComponent } from "react";
22
import PropTypes from "prop-types";
33
import * as size from "./data/size";
44
import * as type from "./data/type";
5-
import {Button} from 'antd'
6-
import styles from './index.less'
5+
import { Button } from "antd";
6+
import styles from "./index.module.less";
77

88
const ButtonProps = {
99
/** Define size of button */
1010
size: PropTypes.oneOf([size.SMALL, size.DEFAULT, size.LARGE]).isRequired,
1111
/** Define type of button */
12-
type: PropTypes.oneOf([type.PRIMARY, type.DEFAULT,type.DANGER,type.DASHED]).isRequired,
12+
type: PropTypes.oneOf([type.PRIMARY, type.DEFAULT, type.DANGER, type.DASHED])
13+
.isRequired,
1314
/** Define loading state */
1415
loading: PropTypes.bool,
1516
/** Content of button */
16-
children: PropTypes.element.isRequired
17+
children: PropTypes.element.isRequired,
18+
19+
style: PropTypes.object
1720
};
1821

1922
const DefaultButtonProps = {
@@ -24,8 +27,18 @@ const DefaultButtonProps = {
2427

2528
class ButtonExample extends PureComponent {
2629
render() {
27-
const { size, type, loading, children } = this.props;
28-
return <Button style={styles.button} type={type} size={size} loading={loading}>{children}</Button>;
30+
const { style, size, type, loading, children } = this.props;
31+
// return <div>{children}</div>;
32+
return (
33+
<Button
34+
className={styles.button}
35+
type={type}
36+
size={size}
37+
loading={loading}
38+
>
39+
{children}
40+
</Button>
41+
);
2942
}
3043
}
3144

styleguide.config.js

-3
This file was deleted.

0 commit comments

Comments
 (0)