Skip to content

Commit

Permalink
Merge pull request #308 from XiaoMi/develop
Browse files Browse the repository at this point in the history
v1.5
  • Loading branch information
solarjoker authored Jun 14, 2019
2 parents ae81280 + 0774814 commit 28a1170
Show file tree
Hide file tree
Showing 114 changed files with 9,130 additions and 1,764 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# 更新日志

## 1.5.0

- 新增:`<Select />` 组件 `onChange` 支持获取改变值 [#291](https://github.com/XiaoMi/hiui/issues/291)
- 新增:`<Tree />` 组件 `onCheck` 事件 [#267](https://github.com/XiaoMi/hiui/issues/267)
- 新增:`<Select />` 组件支持控制下拉菜单展示的属性 [#262](https://github.com/XiaoMi/hiui/issues/262)
- 新增:`<Button />` 组件 loading 状态 [#166](https://github.com/XiaoMi/hiui/issues/166)
- 新增:`<Timeline />` 时间轴组件 [#239](https://github.com/XiaoMi/hiui/issues/239)
- 新增:`<Loading />` 组件 UI 样式 [#238](https://github.com/XiaoMi/hiui/issues/238)
- 新增:`<Tooltip />` 组件 api 调用功能 [#240](https://github.com/XiaoMi/hiui/issues/240)
- 新增:`<Transfer />` 穿梭框组件 [#108](https://github.com/XiaoMi/hiui/issues/108)
- 新增:`<Rate />` 评分组件 [#106](https://github.com/XiaoMi/hiui/issues/106)
- 新增:`<Switch />` 开关组件 [#107](https://github.com/XiaoMi/hiui/issues/107)
- 新增:`<Card />` 组件[#113](https://github.com/XiaoMi/hiui/issues/113)
- 优化:`<Datepicker />` 组件,调整新的 UI,增加新的 API [#105](https://github.com/XiaoMi/hiui/issues/105)
- 优化:`<Tree />` 组件,增加搜索、拖拽、编辑功能 [#112](https://github.com/XiaoMi/hiui/issues/112)

## 1.4.6

- 修复:`<Select />` 组件搜索特殊字符造成的崩溃问题 [#294](https://github.com/XiaoMi/hiui/issues/294)
Expand Down
78 changes: 37 additions & 41 deletions components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ import PropTypes from 'prop-types'
import classNames from 'classnames'
import Provider from '../context'
import Icon from '../icon'
import IconLoading from './IconLoading'
import deprecatedPropsCheck from '../_util/deprecatedPropsCheck'

class Button extends Component {
static propTypes = {
type: PropTypes.oneOf(['primary', 'line', 'success', 'danger', 'default', 'warning', 'info']),
type: PropTypes.oneOf([
'primary',
'line',
'success',
'danger',
'default',
'warning',
'info'
]),
size: PropTypes.oneOf(['large', 'small', 'normal']),
appearance: PropTypes.oneOf(['link', 'button', 'line']),
className: PropTypes.string,
style: PropTypes.object,
disabled: PropTypes.bool,
onClick: PropTypes.func,
href: PropTypes.string,
loading: PropTypes.bool,
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top'])
}

Expand All @@ -30,72 +40,58 @@ class Button extends Component {
size: 'normal'
}

clickCb (e) {
if (this.props.onClick) {
this.props.onClick(e)
}
}

render () {
const {
type,
disabled,
className,
size,
disabled,
type,
appearance,
style,
title,
href,
target,
theme,
icon,
children
loading,
children,
...rest
} = this.props
const classes = classNames(
'theme__' + theme,
`hi-btn`,
className && `${className}`,
className,
appearance && `hi-btn--appearance--${appearance}`,
size && `hi-btn--size--${size}`,
disabled && `hi-btn--disabled`,
icon && `hi-btn--icon`,
loading && `hi-btn--loading`,

// For version < 1.1.0
(type === 'primary' && appearance === 'line')
type === 'primary' && appearance === 'line'
? `hi-btn--type--line`
: `hi-btn--type--${type}`
)

const disabledBool = !!disabled

deprecatedPropsCheck(this.deprecatedProps, this.props, 'Button')

return (
href
? <a
className={classes}
onClick={(e) => this.clickCb(e)}
style={style}
title={title}
href={href}
target={target}
>
{icon && <Icon name={icon} /> }
{children}
</a>
: <button
className={classes}
disabled={disabledBool}
onClick={(e) => this.clickCb(e)}
style={style}
title={title}
type='button'
>
{icon && <Icon name={icon} />}
{children}
</button>
<ButtonWrapper className={classes} {...rest}>
{loading && <IconLoading />}
{icon && !loading && <Icon name={icon} />}
{(icon || loading) && children && (
<span className='hi-btn--icon__spacer' />
)}
{children}
</ButtonWrapper>
)
}
}

function ButtonWrapper ({ children, theme, locale, localeDatas, ...props }) {
return props.href ? (
<a {...props}>{children}</a>
) : (
<button {...props} type='button'>
{children}
</button>
)
}

export default Provider(Button)
18 changes: 18 additions & 0 deletions components/button/IconLoading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'

export default function IconLoading () {
const size = '0.8em'
return (
<i className='hi-icon hi-btn--loading--icon'>
<svg viewBox='0 0 18 18' width={size} height={size} fill='currentColor'>
<g>
<path
d='m9 18c-4.9706 0-9-4.0294-9-9 0-4.9706 4.0294-9 9-9 4.9706 0 9 4.0294 9 9 0 4.9706-4.0294 9-9 9zm0-2c3.866 0 7-3.134 7-7 0-3.866-3.134-7-7-7-3.866 0-7 3.134-7 7 0 3.866 3.134 7 7 7z'
opacity='.15'
/>
<path d='m15.547 2.8242c0.37904 0.40168 0.36068 1.0346-0.040996 1.4136-0.40168 0.37904-1.0346 0.36068-1.4136-0.040996-1.315-1.3935-3.1381-2.1969-5.0922-2.1969-3.866 0-7 3.134-7 7 0 0.55228-0.44772 1-1 1s-1-0.44772-1-1c0-4.9706 4.0294-9 9-9 2.5103 0 4.8578 1.0343 6.5468 2.8242z' />
</g>
</svg>
</i>
)
}
40 changes: 40 additions & 0 deletions components/button/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,49 @@
outline: 0;
}

&::before {
content: '';
display: block;
position: absolute;
top: -1px;
bottom: -1px;
left: -1px;
right: -1px;
background-color: #fff;
opacity: 0;
transition: opacity 0.3s ease;
}

&--loading {
&::before {
opacity: 0.4;
}

&--icon {
width: 1em;
height: 1em;
display: inline-block;

svg {
@keyframes rotate {
to {
transform: rotate(360deg);
}
}

animation: rotate 1s linear infinite;
}
}
}

&--icon {
padding-left: 8px;
padding-right: 8px;

&__spacer {
width: $spacer-2;
display: inline-block;
}
}

// Common Styles
Expand Down
132 changes: 132 additions & 0 deletions components/card/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import './style/index'

class Card extends Component {
constructor (props) {
super(props)
this.state = {
extraShow: props.extraShow === 'stay'
}
}
render () {
const { style, size, hoverable, title, extra, cover, description, children, disabled, extraShow, type } = this.props
const cls = classNames(
'hi-card',
hoverable && 'hi-card--hover',
size && `hi-card--${size}`,
disabled && 'hi-card--disabled',
!cover && type !== 'simple' && 'hi-card--padding',
type === 'simple' && `hi-card--simple-${size}`
)
const headerCls = classNames(
'hi-card__header',
!title && extra && 'hi-card__header--onlyextra'
)
const coverCls = classNames(
'hi-card__content',
cover && 'hi-card__content--cover'
)
const extraCls = classNames(
'hi-card__extra',
!this.state.extraShow && 'hi-card__extra--hide'
)
const header = (title || extra) && (
<div className={headerCls}>
<div className='hi-card__title'>
{title}
</div>
{
extra && (
<div className={extraCls}>
{extra}
</div>
)
}
</div>
)

let body = (
<React.Fragment>
{header}
<div className={coverCls}>
{children}
</div>
</React.Fragment>
)
let coverDom = null
if (cover) {
coverDom = (
<React.Fragment>
{
React.cloneElement(cover, {style: {width: '100%'}})
}
<div className={coverCls}>
{header}
{description}
</div>
</React.Fragment>
)
}
if (type === 'simple') {
body = <div className='hi-card__content hi-card__content--simple'>{children}</div>
coverDom = null
}
return (
<div
className={cls}
style={style}
onMouseEnter={() => {
extraShow === 'hover' && this.setState({
extraShow: true
})
}}
onMouseLeave={() => {
extraShow === 'hover' && this.setState({
extraShow: false
})
}}
>
{coverDom || body}
</div>
)
}
}
Card.defaultProps = {
hoverable: false,
title: '',
extra: '',
extraShow: 'hover'
}
Card.propTypes = {
// 支持三种宽度预设值 small -> 276px middle -> 376px large -> 576px,如果传入 style 则忽略该值,如果缺省 style 及 size 则默认100%
size: PropTypes.oneOf(['small', 'middle', 'large']),
// 一种简单的小卡片
type: PropTypes.oneOf(['simple']),
style: PropTypes.object,
// 鼠标移入是否显示悬停态(浮起)
hoverable: PropTypes.bool,
// 卡片标题
title: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string
]),
// 扩展工具(出现在卡片右上角)
extra: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.array
]),
// 封面图(图片卡片) 含有 cover 属性时,title 将会做为图片下文的 title,而不会出现在卡片左上角
cover: PropTypes.element,
// 用于图片卡片,做为描述
description: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string
]),
disabled: PropTypes.bool,
// 扩展按钮显示模式
extraShow: PropTypes.oneOf(['stay', 'hover'])
}
export default Card
1 change: 1 addition & 0 deletions components/card/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index.scss'
Loading

0 comments on commit 28a1170

Please sign in to comment.