import React, { useState, useMemo, PureComponent } from 'react';
import Tooltip from '../index';
import './story.scss';
import {
Tag,
Icon,
IconButton,
Switch,
Checkbox,
Radio,
Button,
Select,
InputNumber,
Space,
Popover,
Input,
RadioGroup,
SideSheet,
Dropdown,
Popconfirm
} from '@douyinfe/semi-ui';
import InTableDemo from './InTable';
import EdgeDemo from './Edge';
import ScrollTooltip from './ScrollDemo';
import DangerousHtml from './DangerousHtml';
import ArrowPointAtCenter from './ArrowPointAtCenter';
import CustomContainer from './CustomContainer';
import ContainerPosition from './ContainerPosition';
import { IconList, IconSidebar, IconEdit } from '@douyinfe/semi-icons';
import {
Right2Left, Right2LeftTop, Right2LeftBottom, Right2RightTop, Right2RightBottom,
Left2Right, Left2RightTop, Left2RightBottom, Left2LeftTop, Left2LeftBottom,
Top2Bottom, Top2BottomLeft, Top2BottomRight, Top2TopLeft, Top2TopRight,
Bottom2Top, Bottom2TopLeft, Bottom2TopRight, Bottom2BottomLeft, Bottom2BottomRight,
} from './AutoAdjustOverflow';
export default {
title: 'Tooltip',
parameters: {
chromatic: { disableSnapshot: true },
},
};
function test(visible) {
console.log('visible Change:' + visible);
}
const ScrollDemo = function ScrollDemo(props = {}) {
const tops = [
['topLeft', 'TL'],
['top', 'Top'],
['topRight', 'TR'],
];
const lefts = [
['leftTop', 'LT'],
['left', 'Left'],
['leftBottom', 'LB'],
];
const rights = [
['rightTop', 'RT'],
['right', 'Right'],
['rightBottom', 'RB'],
];
const bottoms = [
['bottomLeft', 'BL'],
['bottom', 'Bottom'],
['bottomRight', 'BR'],
];
const { tagStyle, ...restProps } = props;
return (
{tops.map((pos, index) => (
hi bytedance
hi bytedance
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
trigger={'click'}
{...restProps}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{lefts.map((pos, index) => (
hi bytedance
hi bytedance
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
trigger={'click'}
{...restProps}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{rights.map((pos, index) => (
hi bytedance
hi bytedance
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
trigger={'click'}
{...restProps}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{bottoms.map((pos, index) => (
hi bytedance
hi bytedance
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
trigger={'click'}
{...restProps}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
);
};
export const TooltipOnVisibleChange = () => {
const [visible, setVisible] = useState(true);
return (
受控
hi bytedance
hi bytedance
}
position="top"
onVisibleChange={setVisible}
trigger="click"
visible={visible}
>
demo
非受控
hi bytedance
hi bytedance
}
position="leftTop"
onVisibleChange={test}
trigger="click"
>
demo
{/*
hi bytedance
hi bytedance
}
position="rightBottom"
onVisibleChange={test}
trigger="hover"
>
hover
hi bytedance
hi bytedance
}
mouseLeaveDelay={100}
position="rightBottom"
onVisibleChange={test}
trigger="hover"
>
hover with leave delay time
hi bytedance
hi bytedance
}
position="rightBottom"
onVisibleChange={test}
trigger="click"
>
click
*/}
);
};
TooltipOnVisibleChange.story = {
name: 'tooltip onVisibleChange',
};
export const GetPopupContainerDemo = () => (
hi bytedance
hi bytedance
}
position="bottom"
visible
trigger="custom"
getPopupContainer={() => document.querySelector('.content-layer')}
>
指定弹出层的容器
{/*
*/}
给定容器为window,看是否报错
window}>
单选
);
GetPopupContainerDemo.story = {
name: 'tooltip指定弹出层的容器',
};
export const TooltipAll = () => (
);
TooltipAll.story = {
name: 'tooltip All',
};
export const NoContent = () => (
);
NoContent.story = {
name: 'no content',
};
export const AdjustPosition = () => (
<>
第一个滚动区域
hi bytedance
hi bytedance
}
position="rightBottom"
trigger="click"
>
{/* topleft */}
test
hi bytedance
hi bytedance
}
position="topRight"
trigger="click"
>
topRight
hi bytedance
hi bytedance
}
position="bottomLeft"
trigger="click"
>
bottomLeft
hi bytedance
hi bytedance
}
position="bottomRight"
trigger="click"
>
bottomRight
>
);
AdjustPosition.story = {
name: '自适应',
};
export const AdjustPosIfNeed = () => {
const tops = [
['topLeft', 'TL'],
['top', 'Top'],
['topRight', 'TR'],
];
const lefts = [
['leftTop', 'LT'],
['left', 'Left'],
['leftBottom', 'LB'],
];
const rights = [
['rightTop', 'RT'],
['right', 'Right'],
['rightBottom', 'RB'],
];
const bottoms = [
['bottomLeft', 'BL'],
['bottom', 'Bottom'],
['bottomRight', 'BR'],
];
return (
{tops.map((pos, index) => (
Hi ByteDancer, this is a tooltip.
We have 2 lines.
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{lefts.map((pos, index) => (
Hi ByteDancer, this is a tooltip.
We have 2 lines.
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{rights.map((pos, index) => (
Hi ByteDancer, this is a tooltip.
We have 2 lines.
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
{bottoms.map((pos, index) => (
Hi ByteDancer, this is a tooltip.
We have 2 lines.
}
position={Array.isArray(pos) ? pos[0] : pos}
key={index}
>
{Array.isArray(pos) ? pos[1] : pos}
))}
);
}
AdjustPosIfNeed.story = {
name: '自适应位置',
};
export const CompositeComponent = () => (
hi bytedance
hi bytedance
}
position="top"
>
} />
选择框
单选
);
CompositeComponent.story = {
name: '复合组件',
};
export const WrapDisabledElems = () => (
} />
} block />
编辑
编辑
);
WrapDisabledElems.story = {
name: 'wrap disabled elems',
};
export const InTable = () => (
);
InTable.story = {
name: 'in table',
};
export const _EdgeDemo = () => ;
_EdgeDemo.story = {
name: 'edge demo',
};
export const ScrollTooltipDemo = () => ;
ScrollTooltipDemo.story = {
name: 'scroll demo and set popup container',
};
export const DangerousHtmlDemo = () => ;
DangerousHtmlDemo.story = {
name: 'in dangerous html',
};
export const ArrowPointAtCenterDemo = () => ;
ArrowPointAtCenterDemo.story = {
name: 'arrow point at center',
};
export const CustomContainerDemo = () => ;
CustomContainerDemo.story = {
name: 'custom container',
};
export const ContainerPositionDemo = () => ;
ContainerPositionDemo.story = {
name: 'container observer',
};
export const QuickMoveMouse = () => {
/**
* mouseEnterDelay, mouseLeaveDelay 默认都为 50
* mouseEnterDelay, mouseLeaveDelay 都为 0,快速滑动可能出现两个 tooltip 出现
*/
const Demo = () => {
const props = {
mouseEnterDelay: 50,
mouseLeaveDelay: 0,
};
return (
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
);
};
return ;
};
QuickMoveMouse.story = {
name: '快速移动鼠标可见性',
};
export const MotionFalseFix1402 = () => {
function Demo() {
const Test = React.forwardRef((props, ref) => (
Test
));
return (
);
}
return ;
};
MotionFalseFix1402.story = {
name: 'motion=false fix #1402',
};
export const DisabledWrapperCls = () => (
<>
按钮
禁用的单个按钮
正常的多个按钮
正常的多个按钮
抖音
火山
剪映
西瓜视频
>
);
DisabledWrapperCls.story = {
name: 'disabledWrapperCls',
};
export const ShowArrow = () => {
function Demo() {
const Test = React.forwardRef((props, ref) => (
Test
));
return (
should show content and arrow when click
);
}
return ;
};
ShowArrow.story = {
name: 'showArrow',
};
export const OnClickOutSideDemo = () => {
let [v, setV] = useState(false);
let clickOutSide = () => {
console.log('clickOutSide');
setV(false);
};
return (
<>
clickOutSide()} content={'hi bytedance'} visible={v} trigger="custom">
setV(true)}>按钮
console.log('clickOutSide')} content={'hi bytedance'} trigger="click">
单个按钮
>
);
};
OnClickOutSideDemo.story = {
name: 'OnClickOutSide',
};
export const AutoAdjustWithSpacing = () => {
const [height, setHeight] = useState(84);
const [key, setKey] = useState(1);
const initSpacing = 8;
const [spacing, setSpacing] = useState(initSpacing);
const change = (height, hasSpace) => {
setHeight(height);
hasSpace ? setSpacing(initSpacing) : setSpacing(0);
setKey(Math.random());
};
return (
hi bytedance, + padding 20
hi bytedance
}
position="top"
trigger="custom"
visible={true}
>
demo
change(height, hasSpace)}
checked={spacing === initSpacing ? true : false}
>
change(Number(height))} value={height} style={{ width: 200 }} />
);
};
AutoAdjustWithSpacing.story = {
name: 'AutoAdjustWithSpacing',
};
/**
* Chromatic UI test
*/
export const leftTopOverDemo = () => {
const [visible, setVisible] = useState(true);
const content = Semi Design
;
const commonProps = {
content,
showArrow: false,
visible:true,
trigger: 'custom',
motion: false,
};
const buttonStyle = {
width: 200,
};
return (
setVisible(!visible)} data-cy="toggleVisible">toggle visible
leftBottomOver
rightBottomOver
leftTopOver
rightTopOver
);
};
leftTopOverDemo.storyName = `leftTopOver visible`;
leftTopOverDemo.parameters = {
chromatic: {
disableSnapshot: false,
delay: 3000,
viewports: [1200],
},
};
/**
* Cypress test
*/
export const leftTopOverAutoAdjustOverflow = () => {
const content = Semi Design
;
const commonProps = {
content,
trigger: 'click',
showArrow: false,
};
return (
);
};
leftTopOverAutoAdjustOverflow.storyName = `leftTopOver autoAdjustOverflow`;
export const autoFocusContentDemo = () => {
const [controlMotionVisible, setControlMotionVisible] = React.useState(false);
const [controlNoMotionVisible, setControlNoMotionVisible] = React.useState(false);
const onMotionVisibleChange = React.useCallback(() => {
setControlMotionVisible(!controlMotionVisible);
}, [setControlMotionVisible, controlMotionVisible]);
const onNoMotionVisibleChange = React.useCallback(() => {
setControlNoMotionVisible(!controlNoMotionVisible);
}, [setControlNoMotionVisible, controlNoMotionVisible]);
return (
Hover触发
}>
motion
}>
no motion
Click触发
} trigger="click">
motion
} trigger="click">
no motion
受控
motion状态切换
}>
motion
no motion状态切换
}
>
no motion
);
};
export const FlashWithReact18 = () => {
const [visible, setV] = useState(false);
const change = () => {
setV(false);
}
return (<>
setV(true)}>show, semi with react 18 motion=true, abnormal
change()}>hide
>);
}
export const Transition = () => {
const [transitionState, setT] = useState('');
const [insert, setInsert] = useState(false);
const handleLeave = () => {
console.log('set insert false')
setInsert(false);
}
const CommonDOM = () => {
const enterCls = `semi-tooltip-bounceIn`;
const leaveCls = `semi-tooltip-zoomOut`;
const animateStyle = {
animationDirection: 'normal',
animationName: transitionState === 'enter' ? enterCls : leaveCls,
animationDuration: '1000ms',
}
const handleEnd = () => {
if (transitionState === 'enter') {
console.log('animation end of show');
} else if (transitionState === 'leave') {
console.log('animation end of hide');
handleLeave();
}
}
return test
};
const toggleShow = (insert) => {
if (!transitionState) {
setT('enter');
setInsert(insert);
} else if (transitionState === 'enter') {
setT('leave');
} else if (transitionState === 'leave') {
setT('enter');
setInsert(insert);
}
};
return (
<>
{
insert ? (
): null
}
toggleShow(true)}>show
toggleShow(false)}>hide
>
)
}
export const TransitionDemo = () => {
const [key, setKey] = useState(1);
return (
<>
setKey(Math.random())}>reset Demo
>
)
}
export const AdjustPosIfNeedTBLR = () => {
const content =
Hi ByteDancer, this is a tooltip.
We have 2 lines.
const contentHigh =
Hi ByteDancer, this is a tooltip.
We have 2 lines.
We have 2 lines.
return (
top to bottomLeft
top to bottomRight
top to topLeft
top to topRight
bottom to bottomLeft
bottom to bottomRight
bottom to topLeft
bottom to topRight
left to leftTop
left to leftBottom
left to rightTop
left to rightBottom
right to rightTop
right to rightBottom
right to leftTop
right to leftBottom
right to leftBottom
);
}
export const marginDemo = () => {
const [visible, setVisible] = useState(false);
const change = () => {
setVisible(!visible);
};
return (
<>
Open SideSheet
document.querySelector('#test')}
content='cecece'
position='bottom'
margin={{ marginTop: 0, marginLeft: 0, marginBottom: 36, marginRight: 0 }}
>
test
>
);
};
export const SmartPosAdjustDemo = () => {
const [pos, setPosition] = useState('top');
const onChange = (e) => {
setPosition(e.target.value);
};
return (
hi semi! hi semi! hi semi!hi semi! hi semi
hi semi! hi semi! hi semi!hi semi! hi semi
hi semi! hi semi! hi semi!
}
>
悬停此处
TL
top
TR
BL
Bottom
BR
LT
Left
LB
RT
Right
RB
)
}
export const OcclusionDemo = () => {
return (
我的上侧被遮挡啦!但是我可以正常显示! 我的上侧被遮挡啦!但是我可以正常显示!我的上侧被遮挡啦!但是我可以正常显示!
}
>
我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!
我的右侧被遮挡啦!但是我可以正常显示! 我的右侧被遮挡啦!但是我可以正常显示! 我的右侧被遮挡啦!但是我可以正常显示!
}
>
我的右侧被遮挡啦!
);
}
export const Fix1449 = () =>{
return
抖音
轻颜相机
剪映
西瓜视频
贴右显示
}>
缩小视口以遮挡我的右侧
}
// right -> other
export const AutoRight2LeftDemo = () => ;
AutoRight2LeftDemo.storyName = `✅ auto : right -> left`;
export const AutoRight2LeftBottomDemo = () => ;
AutoRight2LeftBottomDemo.storyName = `✅ auto : right -> leftBottom`;
export const AutoRight2LeftTopDemo = () => ;
AutoRight2LeftTopDemo.storyName = `✅ auto : riht -> leftTop`;
export const AutoRight2RightBottomDemo = () => ;
AutoRight2RightBottomDemo.storyName = `✅ auto : right -> rightBottom`;
export const AutoRight2RightTopDemo = () => ;
AutoRight2RightTopDemo.storyName = `✅ auto : riht -> rightTop`;
// left -> other
export const Left2RightDemo = () => ;
Left2RightDemo.storyName = `✅ auto : left -> right`;
export const Left2LeftBottomDemo = () => ;
Left2LeftBottomDemo.storyName = `✅ auto : left -> leftBottom`;
export const Left2LeftTopDemo = () => ;
Left2LeftTopDemo.storyName = `✅ auto : left -> leftTop`;
export const Left2RightBottomDemo = () => ;
Left2RightBottomDemo.storyName = `✅ auto : left -> rightBottom`;
export const Left2RightTopDemo = () => ;
Left2RightTopDemo.storyName = `✅ auto : left -> rightTop`;
// top -> other
export const Top2BottomDemo = () => ;
Top2BottomDemo.storyName = `✅ auto : top -> bottom`;
export const Top2BottomLeftDemo = () => ;
Top2BottomLeftDemo.storyName = `✅ auto : top -> bottomLeft`;
export const Top2BottomRightDemo = () => ;
Top2BottomRightDemo.storyName = `✅ auto : top -> bottomRight`;
export const Top2TopLeftDemo = () => ;
Top2TopLeftDemo.storyName = `✅ auto : top -> topLeft`;
export const Top2TopRightDemo = () => ;
Top2TopRightDemo.storyName = `✅ auto : top -> topRight`;
// bottom -> other
export const Bottom2TopDemo = () => ;
Bottom2TopDemo.storyName = `✅ auto : bottom -> top`;
export const Bottom2TopLeftDemo = () => ;
Bottom2TopLeftDemo.storyName = `✅ auto : bottom -> topLeft`;
export const Bottom2TopRightDemo = () => ;
Bottom2TopRightDemo.storyName = `✅ auto : bottom -> topRight`;
export const Bottom2BottomLeftDemo = () => ;
Bottom2BottomLeftDemo.storyName = `✅ auto : bottom -> bottomLeft`;
export const Bottom2BottomRightDemo = () => ;
Bottom2BottomRightDemo.storyName = `✅ auto : bottom -> bottomRight`;
export const Fix1557 = () =>{
return (
>
}
>
点我后再点击select, Dropdown 面板不收起
}
>
Hover Me
);
}