1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/open-hand-choerodon-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
RippleChild.tsx 2.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
HughHzWu Отправлено 4 лет назад 5e5e851
import React, { Children, cloneElement, isValidElement, PureComponent, ReactElement, ReactNode } from 'react';
import Animate from '../animate';
import createChains from '../_util/createChains';
import MouseDown, { Size } from './MouseDown';
export interface RippleChildProps {
prefixCls?: string;
}
export default class RippleChild extends PureComponent<RippleChildProps> {
static displayName = 'RippleChild';
currentCircleStyle: any;
currentStyle: any;
componentProps?: any;
render() {
const { children } = this.props;
return this.ripple(Children.only(children));
}
getComponentProps(prefixCls) {
const className = `${prefixCls}-wrapper`;
const { componentProps } = this;
if (!componentProps || className !== componentProps.className) {
this.componentProps = {
className,
};
}
return this.componentProps;
}
handleMouseDown = (child: ReactElement<any>, size?: Size) => {
const { prefixCls, ...rest } = this.props;
const { children, style } = child.props;
if (size) {
const { x, y, width, height } = size;
const maxWidth = Math.max(width - x, x);
const maxHeight = Math.max(height - y, y);
const max = Math.sqrt(maxWidth * maxWidth + maxHeight * maxHeight);
this.currentCircleStyle = {
width: max + max,
height: max + max,
left: x - max,
top: y - max,
};
}
const newProps: any = {
...createChains(rest, child.props),
children: [
children,
<Animate
key="ripple"
component="div"
componentProps={this.getComponentProps(prefixCls)}
transitionName={size ? 'zoom-small-slow' : 'fade'}
hiddenProp="hidden"
>
{this.currentCircleStyle && (
<div
hidden={!size}
className={prefixCls}
key="circle"
style={this.currentCircleStyle}
/>
)}
</Animate>,
],
style: this.currentStyle || style,
};
if (size && size.position === 'static') {
newProps.style = { ...style, position: 'relative' };
this.currentStyle = newProps.style;
}
return cloneElement<any>(child, newProps);
};
ripple = (child: ReactNode) => {
if (isValidElement<any>(child)) {
return <MouseDown rippleChild={child}>{this.handleMouseDown}</MouseDown>;
}
return child;
};
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/open-hand-choerodon-ui.git
git@gitlife.ru:oschina-mirror/open-hand-choerodon-ui.git
oschina-mirror
open-hand-choerodon-ui
open-hand-choerodon-ui
master