-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ae9242
commit 5328e4a
Showing
17 changed files
with
325 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { PureComponent, cloneElement } from 'react'; | ||
import cls from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default class Breadcrumb extends PureComponent { | ||
static defaultProps = { | ||
prefix: 'cuke-breadcrumb', | ||
separator: '/' | ||
}; | ||
|
||
static propTypes = { | ||
separator: PropTypes.oneOfType([ | ||
PropTypes.string.isRequired, | ||
PropTypes.object.isRequired, | ||
]) | ||
}; | ||
|
||
render() { | ||
const { prefix, className, separator, children, ...attr } = this.props; | ||
|
||
const items = React.Children.map(children, (element, index) => { | ||
return cloneElement(element, { | ||
separator, | ||
key: index | ||
}); | ||
}); | ||
|
||
return ( | ||
<div | ||
className={cls( | ||
prefix, | ||
className | ||
)} | ||
{...attr} | ||
> | ||
{items} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { PureComponent } from 'react'; | ||
import cls from 'classnames'; | ||
|
||
class BreadcrumbItem extends PureComponent { | ||
static defaultProps = { | ||
prefix: 'cuke-breadcrumb-item', | ||
separator: '/' | ||
}; | ||
|
||
render() { | ||
const { prefix, className, separator, children, ...attr } = this.props; | ||
return ( | ||
<span className={cls(prefix, className)} {...attr}> | ||
<span className={`${prefix}-text`}>{children}</span> | ||
<span className={`${prefix}-separator`}>{separator}</span> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default BreadcrumbItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Breadcrumb from './Breadcrumb'; | ||
import BreadcrumbItem from './BreadcrumbItem'; | ||
import "./styles.less" | ||
|
||
Breadcrumb.Item = BreadcrumbItem; | ||
|
||
export default Breadcrumb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@import "../styles/vars.less"; | ||
|
||
.cuke-breadcrumb { | ||
margin-bottom: 20px; | ||
padding: 10px 15px; | ||
line-height: normal; | ||
color: lighten(@font-color,50%); | ||
|
||
> span:last-child { | ||
font-weight: bold; | ||
color: @font-color; | ||
|
||
.cuke-breadcrumb-item-separator { | ||
display: none; | ||
} | ||
} | ||
.cuke-breadcrumb-item-separator { | ||
margin: 0 8px; | ||
color: #d9d9d9; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export { default as Button } from './button'; | ||
export { default as BreadCrumb } from './breadcrumb'; | ||
export { default as MusicPlayer } from './musicPlayer'; | ||
export { default as WordPad } from './wordPad'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { PureComponent } from 'react'; | ||
import cls from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
|
||
//TODO: 输入框组件 | ||
export default class Input extends PureComponent { | ||
static defaultProps = { | ||
prefix: 'cuke-input', | ||
}; | ||
|
||
static propTypes = { | ||
separator: PropTypes.oneOfType([ | ||
PropTypes.string.isRequired, | ||
PropTypes.object.isRequired, | ||
]) | ||
}; | ||
|
||
render() { | ||
const { | ||
prefix, | ||
className, | ||
...attr | ||
} = this.props | ||
return ( | ||
<div | ||
className={cls( | ||
prefix, | ||
className | ||
)} | ||
{...attr} | ||
> | ||
<input type="text"/> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cuke-input { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React, { PureComponent } from 'react'; | ||
import propTypes from 'prop-types'; | ||
import cls from 'classnames' | ||
|
||
import './styles.less'; | ||
|
||
export default class WordPad extends PureComponent { | ||
state = { | ||
isMouseDown: false, | ||
//上一次的坐标 | ||
lastCoordinate: { | ||
x: 0, | ||
y: 0 | ||
} | ||
}; | ||
static defaultProps = { | ||
prefix: 'cuke-word-pad', | ||
clear: false, | ||
width: 700, | ||
height: 700, | ||
lineCap:"round", | ||
lineJoin: "round", | ||
strokeWidth: 10, | ||
strokeColor: "#444", | ||
getCanvas: ()=>{} | ||
}; | ||
static propTypes = { | ||
width: propTypes.number.isRequired, | ||
height: propTypes.number.isRequired, | ||
strokeColor: propTypes.string, | ||
strokeWidth: propTypes.number, | ||
lineJoin: propTypes.string, | ||
lineCap: propTypes.string, | ||
getCanvas: propTypes.func | ||
}; | ||
constructor(props) { | ||
super(props); | ||
} | ||
render() { | ||
const { prefix, className, ...attr } = this.props; | ||
return ( | ||
<canvas | ||
className={cls(prefix, className)} | ||
{...attr} | ||
ref={node => (this.canvas = node)} | ||
> | ||
你的浏览器不支持 canvas | ||
</canvas> | ||
); | ||
} | ||
clear() { | ||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); | ||
} | ||
windowToCanvas(x, y) { | ||
const { left, top } = this.canvas.getBoundingClientRect(); | ||
return { | ||
x: Math.round(x - left), | ||
y: Math.round(y - top) | ||
}; | ||
} | ||
bindEvents() { | ||
this.canvas.onmousedown = e => { | ||
e.preventDefault(); | ||
this.setState({ isMouseDown: true }); | ||
this.setState({ | ||
lastCoordinate: this.windowToCanvas(e.clientX, e.clientY) | ||
}); | ||
}; | ||
this.canvas.onmouseup = e => { | ||
e.preventDefault(); | ||
this.setState({ | ||
isMouseDown: false | ||
}); | ||
}; | ||
this.canvas.onmouseout = e => { | ||
e.preventDefault(); | ||
this.setState({ | ||
isMouseDown: false | ||
}); | ||
}; | ||
this.canvas.onmousemove = e => { | ||
e.preventDefault(); | ||
const { isMouseDown, lastCoordinate } = this.state; | ||
const { strokeColor,strokeWidth,lineCap,lineJoin } = this.props; | ||
if (isMouseDown) { | ||
//如果鼠标移动的时候鼠标是按下时 执行绘制 | ||
const nowCoordinate = this.windowToCanvas(e.clientX, e.clientY); | ||
this.ctx.beginPath(); | ||
this.ctx.moveTo(lastCoordinate.x, lastCoordinate.y); | ||
this.ctx.lineTo(nowCoordinate.x, nowCoordinate.y); | ||
this.ctx.lineWidth = strokeWidth; | ||
this.ctx.strokeStyle = strokeColor; | ||
this.ctx.lineCap = lineCap; //线是圆滑的 | ||
this.ctx.lineJoin = lineJoin; //两根线过渡圆形 | ||
this.ctx.stroke(); | ||
|
||
//更新坐标 | ||
this.setState({ | ||
lastCoordinate: nowCoordinate | ||
}); | ||
} | ||
}; | ||
} | ||
componentWillReceiveProps({ clear }) { | ||
if (clear) { | ||
this.clear(); | ||
} | ||
} | ||
componentDidMount() { | ||
const { width, height } = this.props; | ||
this.ctx = this.canvas.getContext('2d'); | ||
this.canvas.width = width; | ||
this.canvas.height = height; | ||
this.bindEvents(); | ||
this.props.getCanvas(this.canvas, this.ctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cuke-word-pad { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from "@storybook/addon-actions"; | ||
import WordPad from '../components/wordPad'; | ||
import Button from '../components/button'; | ||
|
||
storiesOf('数据录入', module).add('WordPad 写字板', () => ( | ||
<div> | ||
<h3>用鼠标在上面写字</h3> | ||
<WordPad | ||
width={300} | ||
height={300} | ||
style={{ | ||
border: '1px solid #444', | ||
margin:"10px 0" | ||
}} | ||
getCanvas={(canvas,ctx)=> action(canvas,ctx)} | ||
/> | ||
<Button type="primary">获取文字</Button> | ||
|
||
<h3>自定义画笔</h3> | ||
<WordPad | ||
width={200} | ||
height={200} | ||
strokeColor="#396" | ||
strokeWidth={3} | ||
style={{ | ||
border: '1px solid #444', | ||
margin:"10px 0" | ||
}} | ||
|
||
/> | ||
</div> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import Breadcrumb from '../components/breadcrumb'; | ||
|
||
storiesOf('导航', module).add('Breadcrumb 面包屑', () => ( | ||
<div> | ||
<h3>默认导航</h3> | ||
<Breadcrumb> | ||
<Breadcrumb.Item>黄瓜 ui</Breadcrumb.Item> | ||
<Breadcrumb.Item>面包屑</Breadcrumb.Item> | ||
<Breadcrumb.Item>导航</Breadcrumb.Item> | ||
</Breadcrumb> | ||
|
||
<h3>自定义分隔符</h3> | ||
|
||
<Breadcrumb separator=">"> | ||
<Breadcrumb.Item>黄瓜 ui</Breadcrumb.Item> | ||
<Breadcrumb.Item>面包屑</Breadcrumb.Item> | ||
<Breadcrumb.Item> | ||
<a href="#">链接</a> | ||
</Breadcrumb.Item> | ||
<Breadcrumb.Item>导航</Breadcrumb.Item> | ||
</Breadcrumb> | ||
</div> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters