Skip to content

Commit

Permalink
udpate pkg&docs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed May 24, 2017
1 parent 347ea78 commit f733c52
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 15 deletions.
106 changes: 95 additions & 11 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,103 @@
> React component for status manager.

## resource:
+ http://www.cnblogs.com/Kummy/p/4966937.html
+ https://github.com/steven5538/vue-button
+ https://yarnpkg.com/en/docs/install

## properties:
```javascript

## props:
| name | type | value | description |
| :----| :----| :----| :----|
| visible | Boolean | true/false | v-show |
static propTypes = {
className:PropTypes.string,
statusList:PropTypes.array
};

static defaultProps = {
statusList:[]
};

```

## usage:
```html
<react-status-manager :visible="true" />
```jsx
class App extends React.Component{
constructor(props){
super(props);
this.state = {
status:'init',
smStatus:'N',
step:0,
};
}

click1 = (e)=>{
this.setState({status:'init'});
console.log('click1');
}
click2 = (e)=>{
this.setState({status:'active'});
console.log('click2');
}
click3 = (e)=>{
this.setState({status:'running'});
console.log('click3');
}
click4 = (e)=>{
this.setState({status:'finish'});
console.log('click4');
}

_click5 =(e)=>{
this.setState({
smStatus:'A'
})
};

_clickStep = (e) =>{
let step = this.state.step;
this.setState({
step: step ===3 ? 0: step+1
})
};

render(){
return (
<div className="hello-react-refresher">
<ReactStatusManager size="16px" status={this.state.status} statusList={['init','active','running','finish']}>
<span>下拉刷新</span>
<span>释放更新</span>
<img width="30" src={loadingImg} alt="" />
<span>更新完毕</span>
</ReactStatusManager>


<ReactStatusManager status={this.state.smStatus} className={`wp-icon-${this.state.smStatus}`} statusList={['N','A','F']}>
<span>未开始</span>
<span>进行中</span>
<span>已经结束</span>
</ReactStatusManager>

<button onClick={this.click1}>to `init`</button>
<button onClick={this.click2}>to `active`</button>
<button onClick={this.click3}>to `running`</button>
<button onClick={this.click4}>to `finish`</button>

<button onClick={this._click5}>SetSMStatus</button>

<h2>Wizard</h2>
<button onClick={this._clickStep}>next step</button>
<ReactStatusManager status={this.state.step} statusList={[0,1,2,3]}>
<div className="step">step1,input password</div>
<div className="step">step2,input phone</div>
<div className="step">step3,input other info</div>
<div className="step">step4,do submit! <button>SUBMIT</button></div>
</ReactStatusManager>
</div>
);
}
}

```



## resource:
+ http://ionicframework.com/docs/components/#full-buttons

19 changes: 19 additions & 0 deletions _README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# react-status-manager
> React component for status manager.

## properties:
```javascript
BACKUP_PROPERTIES
```

## usage:
```jsx
BACKUP_USAGE
```



## resource:
+ http://ionicframework.com/docs/components/#full-buttons

25 changes: 25 additions & 0 deletions build/auto-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');
const fileRegExp = require('file-regexp');
const exampleRE = /\/\*===example start===\*\/\n([a-zA-Z.{\s()<="-<_>}?:+0-9\[\]\u4E00-\u9FA5`!]*)\/\*===example end===\*\//;
const templateRE = /\/\*===properties start===\*\/([()\[\]\w\s={}:.;,'"]*)\/\*===properties end===\*\//;

const targetPropsRE = /## properties:\n```javascript\n(.*)\n```/;
const targetUsageRE = /## usage:\n```jsx\n(.*)\n```/;

let readmeFile = path.join(__dirname,'../README.MD');
let _readmeFile = path.join(__dirname,'../_README.MD');
let exampleFile = path.join(__dirname,'../src/dev.js');
let templateFile = path.join(__dirname,'../src/components/react-status-manager.js');



let exampleRs = fileRegExp.fileGetContent(exampleFile,exampleRE);
let templateRs = fileRegExp.fileGetContent(templateFile,templateRE);

// set default readme file:
fs.writeFileSync(readmeFile, fs.readFileSync(_readmeFile,'utf-8'));

//do replace:
fileRegExp.fileReplaceContent(readmeFile,targetPropsRE,templateRs);
fileRegExp.fileReplaceContent(readmeFile,targetUsageRE,exampleRs);
2 changes: 1 addition & 1 deletion dist/react-status-manager.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"homepage": "https://github.com/afeiship/react-status-manager",
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js"
"build": "node build/build.js",
"docs": "node build/auto-readme.js"
},
"main": "./dist/react-status-manager.js",
"devDependencies": {
Expand Down Expand Up @@ -54,6 +55,7 @@
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"file-regexp": "github:afeiship/file-regexp",
"function-bind": "^1.0.2",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.8.1",
Expand Down
2 changes: 2 additions & 0 deletions src/components/react-status-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

export default class extends PureComponent{
/*===properties start===*/
static propTypes = {
className:PropTypes.string,
statusList:PropTypes.array
Expand All @@ -12,6 +13,7 @@ export default class extends PureComponent{
static defaultProps = {
statusList:[]
};
/*===properties end===*/

render(){
const { className, status, statusList, size ,children,...props} = this.props;
Expand Down
22 changes: 20 additions & 2 deletions src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import './dev.scss';
import ReactStatusManager from './main';
import loadingImg from 'assets/loading.svg';

/*===example start===*/
class App extends React.Component{
constructor(props){
super(props);
this.state = {
status:'init',
smStatus:'N'
smStatus:'N',
step:0,
};
}

Expand All @@ -35,6 +37,13 @@ class App extends React.Component{
})
};

_clickStep = (e) =>{
let step = this.state.step;
this.setState({
step: step ===3 ? 0: step+1
})
};

render(){
return (
<div className="hello-react-refresher">
Expand All @@ -58,11 +67,20 @@ class App extends React.Component{
<button onClick={this.click4}>to `finish`</button>

<button onClick={this._click5}>SetSMStatus</button>

<h2>Wizard</h2>
<button onClick={this._clickStep}>next step</button>
<ReactStatusManager status={this.state.step} statusList={[0,1,2,3]}>
<div className="step">step1,input password</div>
<div className="step">step2,input phone</div>
<div className="step">step3,input other info</div>
<div className="step">step4,do submit! <button>SUBMIT</button></div>
</ReactStatusManager>
</div>
);
}
}

/*===example end===*/

ReactDOM.render(
<App />,
Expand Down
10 changes: 10 additions & 0 deletions src/dev.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ ul,li{list-style: none;}
outline: none;
}
}

.step{
background: #f60;
color:#fff;
padding:10px;
button{
width:30%;
padding:10px;
}
}
}

0 comments on commit f733c52

Please sign in to comment.