Skip to content

Commit

Permalink
add material-design for list.item
Browse files Browse the repository at this point in the history
  • Loading branch information
pingan1927 committed Mar 22, 2017
1 parent 1cf0e56 commit d8fd669
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
67 changes: 65 additions & 2 deletions components/list/ListItem.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,70 @@ class ListItem extends React.Component<ListItemProps, any> {
error: false,
multipleLine: false,
wrap: false,
material: false,
};

static Brief = Brief;
debounceTimeout: any;

constructor(props) {
super(props);
this.state = {
coverRipleStyle: {},
RipleClicked: false,
};
}

componentWillUnmount() {
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);
this.debounceTimeout = null;
}
}

onClick = (ev) => {
const { onClick, material } = this.props;
if (!!navigator.userAgent.match(/Android/i) && !!onClick && material) {
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);
this.debounceTimeout = null;
}
let Item = ev.currentTarget;
let RipleWidth = Math.max(Item.offsetHeight, Item.offsetWidth);
const ClientRect = ev.currentTarget.getBoundingClientRect();
let pointX = ev.clientX - ClientRect.left - Item.offsetWidth / 2;
let pointY = ev.clientY - ClientRect.top - Item.offsetWidth / 2;
const coverRipleStyle = {
width: `${RipleWidth}px`,
height: `${RipleWidth}px`,
left: `${pointX}px`,
top: `${pointY}px`,
};
this.setState({
coverRipleStyle,
RipleClicked: true,
}, () => {
this.debounceTimeout = setTimeout(() => {
this.setState({
coverRipleStyle: {},
RipleClicked: false,
});
}, 1000);
});
}

if (onClick) {
onClick(ev);
}
}

render() {

const {
prefixCls, className, activeStyle, error, align, wrap, disabled,
children, multipleLine, thumb, extra, arrow, ...restProps} = this.props;
children, multipleLine, thumb, extra, arrow, onClick, ...restProps} = this.props;

const { coverRipleStyle, RipleClicked } = this.state;
const wrapCls = {
[className as string]: className,
[`${prefixCls}-item`]: true,
Expand All @@ -39,6 +93,11 @@ class ListItem extends React.Component<ListItemProps, any> {
[`${prefixCls}-item-bottom`]: align === 'bottom',
};

const ripleCls = classNames({
[`${prefixCls}-riple`]: true,
[`${prefixCls}-riple-animate`]: RipleClicked,
});

const lineCls = classNames({
[`${prefixCls}-line`]: true,
[`${prefixCls}-line-multiple`]: multipleLine,
Expand All @@ -54,6 +113,9 @@ class ListItem extends React.Component<ListItemProps, any> {

const content = <div
{...restProps}
onClick={(ev) => {
this.onClick(ev);
}}
className={classNames(wrapCls)}
>
{thumb ? <div className={`${prefixCls}-thumb`}>
Expand All @@ -64,11 +126,12 @@ class ListItem extends React.Component<ListItemProps, any> {
{extra !== undefined && <div className={`${prefixCls}-extra`}>{extra}</div>}
{arrow && <div className={arrowCls} />}
</div>
<div style={coverRipleStyle} className={ripleCls} />
</div>;

return (
<Touchable
disabled={disabled || !restProps.onClick}
disabled={disabled || !onClick}
activeStyle={activeStyle}
activeClassName={`${prefixCls}-item-active`}
>
Expand Down
1 change: 1 addition & 0 deletions components/list/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ListItemProps {
styles?: any;
onPressIn?: (e?: any) => void;
onPressOut?: (e?: any) => void;
material?: boolean;
}

export interface BriefProps {
Expand Down
15 changes: 14 additions & 1 deletion components/list/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ class ListExample extends React.Component {
<Item arrow="horizontal" multipleLine>
标题文字 <Brief>副标题</Brief>
</Item>
<Item arrow="horizontal" thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png" multipleLine>
<Item
arrow="horizontal"
multipleLine
onClick={() => {}}
material
>
开启material点击效果<Brief>仅Android有效且设置了Click事件</Brief>
</Item>
<Item
arrow="horizontal"
thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
multipleLine
onClick={() => {}}
>
标题文字 <Brief>副标题</Brief>
</Item>
</List>
Expand Down
1 change: 1 addition & 0 deletions components/list/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Properties | Descrition | Type | Default
| multipleLine | 多行 | Boolean | `false` |
| wrap | 是否换行,默认情况下,文字超长会被隐藏, | Boolean | `false` |
| activeStyle(`web only`) | 自定义active的样式 | Object | |
| material(`web only`) | 开启material design点击效果(水波) | Boolean | `false` |

### List.Item.Brief

Expand Down
1 change: 1 addition & 0 deletions components/list/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ subtitle: 列表
| multipleLine | 多行 | Boolean | `false` |
| wrap | 是否换行,默认情况下,文字超长会被隐藏, | Boolean | `false` |
| activeStyle(`web only`) | 自定义active的样式 | Object | |
| material(`web only`) | 开启material design点击效果(水波) | Boolean | false |

### List.Item.Brief

Expand Down
20 changes: 20 additions & 0 deletions components/list/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
overflow: hidden;
.box-align;
transition: background-color 200ms;
.@{listPrefixCls}-riple {
position: absolute;
background: transparent;
display: inline-block;
overflow: hidden;
will-change: box-shadow,transform;
transition: box-shadow .2s cubic-bezier(.4,0,1,1), background-color .2s cubic-bezier(.4,0,.2,1), color .2s cubic-bezier(.4,0,.2,1);
outline: none;
cursor: pointer;
border-radius: 100%;
transform: scale(0);
&.@{listPrefixCls}-riple-animate {
background-color: hsla(0, 0%, 62%, .2);
animation: ripple 1s linear;
}
}
&.@{listPrefixCls}-item-top {
.@{listPrefixCls}-line {
.box-align(flex-start);
Expand Down Expand Up @@ -198,3 +214,7 @@
background-color: transparent;
}
}

@keyframes ripple {
100% {opacity: 0; transform: scale(2.5);}
}

0 comments on commit d8fd669

Please sign in to comment.