import React, { useState, Component, isValidElement, PureComponent, createRef } from 'react';
import ReactDOM from 'react-dom';
import { storiesOf } from '@storybook/react';
import { withKnobs, text, boolean } from '@storybook/addon-knobs';
import withPropsCombinations from 'react-storybook-addon-props-combinations';
import { Transition } from '../index';
import QueueTransition from './queue-transition';
import QueueStyledTransition from './queue-transition/styled';
import { Modal, Button, IconButton, Collapse, Nav, Switch, RadioGroup, Radio } from '@douyinfe/semi-ui';
const stories = storiesOf('semi-animation-react/Transition', module);
stories.addDecorator(withKnobs);
const itemStyle = {
backgroundColor: 'rgb(241, 101, 101)',
color: 'white',
borderRadius: 4,
padding: 10,
textAlign: 'center',
};
const bigSquareStyle = {
backgroundColor: 'rgb(241, 101, 101)',
width: 100,
height: 100,
margin: 20,
marginLeft: 50,
borderRadius: 4,
fontSize: 16,
color: 'white',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
};
stories.add('transition-bounceInOut', () => {
class App extends PureComponent {
constructor(props = {}) {
super(props);
this.state = {
visible: true,
};
this.ref = createRef();
}
setVisible = visible => this.setState({ visible });
render() {
const { visible } = this.state;
return (
{visible
? ({ scale, opacity }) => {
const node = this.ref.current;
console.log('ref rect: ', node && node.getBoundingClientRect());
return (
bounceInOut
);
}
: null}
);
}
}
class ModalDemo extends React.Component {
constructor() {
super();
this.state = { visible: false, visibleWithAnimation: false };
this.showDialog = this.showDialog.bind(this);
this.handleOk = this.handleOk.bind(this);
this.handleCancel = this.handleCancel.bind(this);
}
showDialog() {
this.setState({
visible: true,
visibleWithAnimation: true,
});
}
handleOk(e) {
this.setState({
// visible: false,
visibleWithAnimation: false,
});
}
handleCancel(e) {
this.setState({
// visible: false,
visibleWithAnimation: false,
});
}
render() {
const { visibleWithAnimation, visible } = this.state;
return (
<>
this.setState({ visible: false })}
>
{visibleWithAnimation
? ({ opacity, scale }) => (
This is a modal with customized styles.
More content...
)
: null}
>
);
}
}
return (
<>
>
);
});
stories.add('transition-bounceInOut-受控', () => {
class App extends PureComponent {
constructor(props = {}) {
super(props);
this.state = {
state: 'enter',
visible: true,
};
this.ref = createRef();
}
setVisible = visible => this.setState({ state: visible ? 'enter' : 'leave' });
didEnter = () => {
this.setState({ visible: true });
};
didLeave = () => {
this.setState({ visible: false });
};
render() {
const { visible, state } = this.state;
return (
{state === 'enter' || visible
? ({ scale, opacity }) => {
const node = this.ref.current;
// console.log('ref rect: ', node && node.getBoundingClientRect());
return (
bounceInOut
);
}
: null}
);
}
}
return (
<>
>
);
});
stories.add('transition-slideInOutDown', () => {
const SlideInOutDown = function SlideInOutDown(props = {}) {
return (
{props.children}
);
};
class App extends PureComponent {
state = {
itemKey: '',
};
setItemKey = itemKey => this.setState({ itemKey });
render() {
const { itemKey } = this.state;
return (
{['1', '2', '3'].map(key => (
{/* */}
{itemKey === key
? ({ maxHeight }) => (
Hi, bytedance dance dance. This is the docsite of Semi UI.{' '}
)
: null}
{/* */}
))}
);
}
}
return ;
});
stories.add('transition-slideInOutLeft', () => {
function SlideInOutLeft(props = {}) {
return (
{props.children}
);
}
class NavApp extends React.Component {
constructor() {
super();
this.state = {
isCollapsed: true,
defaultOpenKeys: ['2', '2-3'],
mode: 'vertical',
navHeight: 480,
selectedKeys: [],
openKeys: ['2'],
};
this.onSelect = (data = {}) => {
console.log('trigger onSelect: ', data);
let selectedKeys = Array.from(data.selectedKeys);
this.setState({ selectedKeys });
};
this.onOpenChange = (data = {}) => {
console.log('trigger onOpenChange: ', data);
let openKeys = Array.from(data.openKeys);
this.setState({ openKeys });
};
}
updateCollapsed(isCollapsed) {
this.setState({ isCollapsed });
}
toggleMode() {
let { mode, navHeight } = this.state;
if (mode === 'vertical') {
mode = 'horizontal';
navHeight = 60;
} else {
mode = 'vertical';
navHeight = 480;
}
this.setState({ mode, navHeight });
}
renderNavWithTransform = ({ transform, translateX }) => {
let { isCollapsed, defaultOpenKeys, mode, navHeight, selectedKeys, openKeys } = this.state;
let testIcon = '//lf1-cdn-tos.bytescm.com/obj/mosaic-legacy/da9d0015af0f09667998';
let vigoIcon = '//lf1-cdn-tos.bytescm.com/obj/mosaic-legacy/504100070cbe0498d66f';
let icon3 = '//lf1-cdn-tos.bytescm.com/eesz/resource/bear/public/doc-favicon-v4.902ddd709d8aaa55df8d.ico';
return (
);
};
render() {
let { isCollapsed, defaultOpenKeys, mode, navHeight, selectedKeys, openKeys } = this.state;
let testIcon = '//lf1-cdn-tos.bytescm.com/obj/mosaic-legacy/da9d0015af0f09667998';
let vigoIcon = '//lf1-cdn-tos.bytescm.com/obj/mosaic-legacy/504100070cbe0498d66f';
let icon3 = '//lf1-cdn-tos.bytescm.com/eesz/resource/bear/public/doc-favicon-v4.902ddd709d8aaa55df8d.ico';
return (
{isCollapsed
? ({ transform, translateX }) => (
)
: null}
this.updateCollapsed(!isCollapsed)}
/>
);
}
}
return ;
});
stories.add('queue transition', () => {
const Demo = () => {
const animStyle = { ...itemStyle, width: 100, marginBottom: 10 };
const [state, setState] = useState('enter');
const [position, setPosition] = useState('left');
const onSwitchPosition = e => {
setPosition(e.target.value);
};
const positionList = ['left', 'top', 'right', 'bottom'];
return (
1
2
3
4
方向
{positionList.map(pos => (
{pos}
))}
);
};
return ;
});
stories.add('queue styled transition', () => {
const Demo = () => {
const animStyle = {
backgroundColor: 'rgb(241, 101, 101)',
color: 'white',
borderRadius: 4,
padding: 10,
textAlign: 'center',
width: 100,
marginBottom: 10,
};
const [state, setState] = useState('enter');
const [position, setPosition] = useState('Left');
const switchState = state => {
setState(undefined);
setTimeout(() => setState(state));
};
const onSwitchPosition = e => {
setPosition(e.target.value);
};
const positionList = ['Left', 'Up', 'Right', 'Down'];
return (
{positionList.map(pos => (
{pos}
))}
);
};
return ;
});