import React, { useState, useMemo } from 'react'; import Tooltip from '../index'; import './story.scss'; import { Tag, Icon, IconButton, Switch, Checkbox, Radio, Button, Select, InputNumber, Space, Popover, Input, } 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 TooltipTransition from '../TooltipStyledTransition'; 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}> 单选
); 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">

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, trigger: 'click', showArrow: false, visible:true, trigger: 'custom', motion: false, }; const buttonStyle = { width: 200, }; return (
); }; 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触发 }> }>
Click触发 } trigger="click"> } trigger="click">
受控 }> } >
); }; export const FlashWithReact18 = () => { const [visible, setV] = useState(false); const change = () => { setV(false); } return (<> ); } 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 }
) } export const TransitionDemo = () => { const [key, setKey] = useState(1); return ( <> ) }