tooltip.stories.jsx 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. import React, { useState, useMemo, PureComponent } from 'react';
  2. import Tooltip from '../index';
  3. import './story.scss';
  4. import {
  5. Tag,
  6. Icon,
  7. IconButton,
  8. Switch,
  9. Checkbox,
  10. Radio,
  11. Button,
  12. Select,
  13. InputNumber,
  14. Space,
  15. Popover,
  16. Input,
  17. RadioGroup,
  18. SideSheet,
  19. Dropdown,
  20. Popconfirm
  21. } from '@douyinfe/semi-ui';
  22. import InTableDemo from './InTable';
  23. import EdgeDemo from './Edge';
  24. import ScrollTooltip from './ScrollDemo';
  25. import DangerousHtml from './DangerousHtml';
  26. import ArrowPointAtCenter from './ArrowPointAtCenter';
  27. import CustomContainer from './CustomContainer';
  28. import ContainerPosition from './ContainerPosition';
  29. import { IconList, IconSidebar, IconEdit } from '@douyinfe/semi-icons';
  30. import {
  31. Right2Left, Right2LeftTop, Right2LeftBottom, Right2RightTop, Right2RightBottom,
  32. Left2Right, Left2RightTop, Left2RightBottom, Left2LeftTop, Left2LeftBottom,
  33. Top2Bottom, Top2BottomLeft, Top2BottomRight, Top2TopLeft, Top2TopRight,
  34. Bottom2Top, Bottom2TopLeft, Bottom2TopRight, Bottom2BottomLeft, Bottom2BottomRight,
  35. } from './AutoAdjustOverflow';
  36. import FixedStringEllipsis from './FixedStringEllipsis';
  37. export {
  38. FixedStringEllipsis,
  39. }
  40. export default {
  41. title: 'Tooltip',
  42. parameters: {
  43. chromatic: { disableSnapshot: true },
  44. },
  45. };
  46. function test(visible) {
  47. console.log('visible Change:' + visible);
  48. }
  49. export const ContextMenuTooltip = () => {
  50. return <Tooltip content='context menu content' trigger='contextMenu'>
  51. <Button>点击右键展开 Tooltip</Button>
  52. </Tooltip>
  53. };
  54. const ScrollDemo = function ScrollDemo(props = {}) {
  55. const tops = [
  56. ['topLeft', 'TL'],
  57. ['top', 'Top'],
  58. ['topRight', 'TR'],
  59. ];
  60. const lefts = [
  61. ['leftTop', 'LT'],
  62. ['left', 'Left'],
  63. ['leftBottom', 'LB'],
  64. ];
  65. const rights = [
  66. ['rightTop', 'RT'],
  67. ['right', 'Right'],
  68. ['rightBottom', 'RB'],
  69. ];
  70. const bottoms = [
  71. ['bottomLeft', 'BL'],
  72. ['bottom', 'Bottom'],
  73. ['bottomRight', 'BR'],
  74. ];
  75. const { tagStyle, ...restProps } = props;
  76. return (
  77. <div
  78. style={{
  79. paddingLeft: 40,
  80. }}
  81. >
  82. <div
  83. style={{
  84. marginLeft: 40,
  85. whiteSpace: 'nowrap',
  86. }}
  87. >
  88. {tops.map((pos, index) => (
  89. <Tooltip
  90. content={
  91. <article>
  92. <p>hi bytedance</p>
  93. <p>hi bytedance</p>
  94. </article>
  95. }
  96. position={Array.isArray(pos) ? pos[0] : pos}
  97. key={index}
  98. trigger={'click'}
  99. {...restProps}
  100. >
  101. <Tag style={tagStyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  102. </Tooltip>
  103. ))}
  104. </div>
  105. <div
  106. style={{
  107. width: 40,
  108. float: 'left',
  109. }}
  110. >
  111. {lefts.map((pos, index) => (
  112. <Tooltip
  113. content={
  114. <article>
  115. <p>hi bytedance</p>
  116. <p>hi bytedance</p>
  117. </article>
  118. }
  119. position={Array.isArray(pos) ? pos[0] : pos}
  120. key={index}
  121. trigger={'click'}
  122. {...restProps}
  123. >
  124. <Tag style={tagStyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  125. </Tooltip>
  126. ))}
  127. </div>
  128. <div
  129. style={{
  130. width: 40,
  131. marginLeft: 180,
  132. }}
  133. >
  134. {rights.map((pos, index) => (
  135. <Tooltip
  136. content={
  137. <article>
  138. <p>hi bytedance</p>
  139. <p>hi bytedance</p>
  140. </article>
  141. }
  142. position={Array.isArray(pos) ? pos[0] : pos}
  143. key={index}
  144. trigger={'click'}
  145. {...restProps}
  146. >
  147. <Tag style={tagStyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  148. </Tooltip>
  149. ))}
  150. </div>
  151. <div
  152. style={{
  153. marginLeft: 40,
  154. clear: 'both',
  155. whiteSpace: 'nowrap',
  156. }}
  157. >
  158. {bottoms.map((pos, index) => (
  159. <Tooltip
  160. content={
  161. <article>
  162. <p>hi bytedance</p>
  163. <p>hi bytedance</p>
  164. </article>
  165. }
  166. position={Array.isArray(pos) ? pos[0] : pos}
  167. key={index}
  168. trigger={'click'}
  169. {...restProps}
  170. >
  171. <Tag style={tagStyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  172. </Tooltip>
  173. ))}
  174. </div>
  175. </div>
  176. );
  177. };
  178. export const TooltipOnVisibleChange = () => {
  179. const [visible, setVisible] = useState(true);
  180. return (
  181. <div className="demo">
  182. <div>
  183. <label>受控</label>
  184. <Tooltip
  185. content={
  186. <article>
  187. <p>hi bytedance</p>
  188. <p>hi bytedance</p>
  189. </article>
  190. }
  191. position="top"
  192. onVisibleChange={setVisible}
  193. trigger="click"
  194. visible={visible}
  195. >
  196. <Tag>demo</Tag>
  197. </Tooltip>
  198. </div>
  199. <br />
  200. <br />
  201. <div>
  202. <label>非受控</label>
  203. <Tooltip
  204. content={
  205. <article>
  206. <p>hi bytedance</p>
  207. <p>hi bytedance</p>
  208. </article>
  209. }
  210. position="leftTop"
  211. onVisibleChange={test}
  212. trigger="click"
  213. >
  214. <Tag>demo</Tag>
  215. </Tooltip>
  216. </div>
  217. <br />
  218. <br />
  219. {/* <Tooltip
  220. content={
  221. <article>
  222. <p>hi bytedance</p>
  223. <p>hi bytedance</p>
  224. </article>
  225. }
  226. position="rightBottom"
  227. onVisibleChange={test}
  228. trigger="hover"
  229. >
  230. <Tag>hover</Tag>
  231. </Tooltip>
  232. <br />
  233. <br />
  234. <Tooltip
  235. content={
  236. <article>
  237. <p>hi bytedance</p>
  238. <p>hi bytedance</p>
  239. </article>
  240. }
  241. mouseLeaveDelay={100}
  242. position="rightBottom"
  243. onVisibleChange={test}
  244. trigger="hover"
  245. >
  246. <Tag>hover with leave delay time</Tag>
  247. </Tooltip>
  248. <br />
  249. <br />
  250. <Tooltip
  251. content={
  252. <article>
  253. <p>hi bytedance</p>
  254. <p>hi bytedance</p>
  255. </article>
  256. }
  257. position="rightBottom"
  258. onVisibleChange={test}
  259. trigger="click"
  260. >
  261. <Tag>click</Tag>
  262. </Tooltip> */}
  263. </div>
  264. );
  265. };
  266. TooltipOnVisibleChange.story = {
  267. name: 'tooltip onVisibleChange',
  268. };
  269. export const GetPopupContainerDemo = () => (
  270. <div className="demo">
  271. <div className="content-layer" />
  272. <Tooltip
  273. content={
  274. <article>
  275. <p>hi bytedance</p> <p>hi bytedance</p>
  276. </article>
  277. }
  278. position="bottom"
  279. visible
  280. trigger="custom"
  281. getPopupContainer={() => document.querySelector('.content-layer')}
  282. >
  283. <Tag>指定弹出层的容器</Tag>
  284. {/* <div className='content'></div> */}
  285. </Tooltip>
  286. <div>
  287. <label>给定容器为window,看是否报错</label>
  288. <Tooltip content={'单选'} position="top" getPopupContainer={() => window}>
  289. <Radio style={{ display: 'inline-flex' }}>单选</Radio>
  290. </Tooltip>
  291. </div>
  292. </div>
  293. );
  294. GetPopupContainerDemo.story = {
  295. name: 'tooltip指定弹出层的容器',
  296. };
  297. export const TooltipAll = () => (
  298. <div className="demo">
  299. <ScrollDemo />
  300. <div
  301. style={{
  302. padding: 120,
  303. }}
  304. >
  305. <ScrollDemo
  306. showArrow
  307. tagStyle={{
  308. height: 80,
  309. }}
  310. />
  311. </div>
  312. </div>
  313. );
  314. TooltipAll.story = {
  315. name: 'tooltip All',
  316. };
  317. export const NoContent = () => (
  318. <div className="demo">
  319. <div
  320. style={{
  321. padding: 120,
  322. }}
  323. >
  324. <ScrollDemo showArrow content={''} />
  325. </div>
  326. <div
  327. style={{
  328. padding: 120,
  329. }}
  330. >
  331. <ScrollDemo
  332. showArrow
  333. tagStyle={{
  334. minHeight: 80,
  335. minWidth: 120,
  336. }}
  337. content={''}
  338. />
  339. </div>
  340. </div>
  341. );
  342. NoContent.story = {
  343. name: 'no content',
  344. };
  345. export const AdjustPosition = () => (
  346. <>
  347. <div className="adjust">
  348. <div className="wrapper">
  349. 第一个滚动区域
  350. <Tooltip
  351. content={
  352. <article>
  353. <p>hi bytedance</p>
  354. <p>hi bytedance</p>
  355. </article>
  356. }
  357. position="rightBottom"
  358. trigger="click"
  359. >
  360. {/* <Tag className='topLeft'>topleft</Tag> */}
  361. <div>test</div>
  362. </Tooltip>
  363. <Tooltip
  364. content={
  365. <article>
  366. <p>hi bytedance</p>
  367. <p>hi bytedance</p>
  368. </article>
  369. }
  370. position="topRight"
  371. trigger="click"
  372. >
  373. <Tag className="topRight">topRight</Tag>
  374. </Tooltip>
  375. <Tooltip
  376. content={
  377. <article>
  378. <p>hi bytedance</p>
  379. <p>hi bytedance</p>
  380. </article>
  381. }
  382. position="bottomLeft"
  383. trigger="click"
  384. >
  385. <Tag className="bottomLeft">bottomLeft</Tag>
  386. </Tooltip>
  387. <Tooltip
  388. content={
  389. <article>
  390. <p>hi bytedance</p>
  391. <p>hi bytedance</p>
  392. </article>
  393. }
  394. position="bottomRight"
  395. trigger="click"
  396. >
  397. <Tag className="bottomRight">bottomRight</Tag>
  398. </Tooltip>
  399. </div>
  400. </div>
  401. <div className="adjust2">
  402. <div className="wrapper2">第二个滚动区域</div>
  403. </div>
  404. </>
  405. );
  406. AdjustPosition.story = {
  407. name: '自适应',
  408. };
  409. export const AdjustPosIfNeed = () => {
  410. const tops = [
  411. ['topLeft', 'TL'],
  412. ['top', 'Top'],
  413. ['topRight', 'TR'],
  414. ];
  415. const lefts = [
  416. ['leftTop', 'LT'],
  417. ['left', 'Left'],
  418. ['leftBottom', 'LB'],
  419. ];
  420. const rights = [
  421. ['rightTop', 'RT'],
  422. ['right', 'Right'],
  423. ['rightBottom', 'RB'],
  424. ];
  425. const bottoms = [
  426. ['bottomLeft', 'BL'],
  427. ['bottom', 'Bottom'],
  428. ['bottomRight', 'BR'],
  429. ];
  430. return (
  431. <div style={{ paddingLeft: 40 }}>
  432. <div style={{ marginLeft: 40, whiteSpace: 'nowrap' }}>
  433. {tops.map((pos, index) => (
  434. <Tooltip
  435. showArrow
  436. arrowPointAtCenter
  437. content={
  438. <article>
  439. Hi ByteDancer, this is a tooltip.
  440. <br /> We have 2 lines.
  441. </article>
  442. }
  443. position={Array.isArray(pos) ? pos[0] : pos}
  444. key={index}
  445. >
  446. <Tag
  447. style={{ marginRight: '8px' }}
  448. data-cy={Array.isArray(pos) ? pos[0] : pos}
  449. >
  450. {Array.isArray(pos) ? pos[1] : pos}
  451. </Tag>
  452. </Tooltip>
  453. ))}
  454. </div>
  455. <div style={{ width: 40, float: 'left' }}>
  456. {lefts.map((pos, index) => (
  457. <Tooltip
  458. showArrow
  459. arrowPointAtCenter
  460. content={
  461. <article>
  462. Hi ByteDancer, this is a tooltip.
  463. <br /> We have 2 lines.
  464. </article>
  465. }
  466. position={Array.isArray(pos) ? pos[0] : pos}
  467. key={index}
  468. >
  469. <Tag data-cy={Array.isArray(pos) ? pos[0] : pos} style={{ marginBottom: '8px' }}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  470. </Tooltip>
  471. ))}
  472. </div>
  473. <div style={{ width: 40, marginLeft: 180 }}>
  474. {rights.map((pos, index) => (
  475. <Tooltip
  476. showArrow
  477. arrowPointAtCenter
  478. content={
  479. <article>
  480. Hi ByteDancer, this is a tooltip.
  481. <br /> We have 2 lines.
  482. </article>
  483. }
  484. position={Array.isArray(pos) ? pos[0] : pos}
  485. key={index}
  486. >
  487. <Tag data-cy={Array.isArray(pos) ? pos[0] : pos} style={{ marginBottom: '8px' }}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  488. </Tooltip>
  489. ))}
  490. </div>
  491. <div style={{ marginLeft: 40, clear: 'both', whiteSpace: 'nowrap' }}>
  492. {bottoms.map((pos, index) => (
  493. <Tooltip
  494. showArrow
  495. arrowPointAtCenter
  496. content={
  497. <article>
  498. Hi ByteDancer, this is a tooltip.
  499. <br /> We have 2 lines.
  500. </article>
  501. }
  502. position={Array.isArray(pos) ? pos[0] : pos}
  503. key={index}
  504. >
  505. <Tag data-cy={Array.isArray(pos) ? pos[0] : pos} position={Array.isArray(pos) ? pos[0] : pos} style={{ marginRight: '8px' }}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
  506. </Tooltip>
  507. ))}
  508. </div>
  509. </div>
  510. );
  511. }
  512. AdjustPosIfNeed.story = {
  513. name: '自适应位置',
  514. };
  515. export const CompositeComponent = () => (
  516. <div
  517. style={{
  518. padding: 50,
  519. }}
  520. >
  521. <Tooltip
  522. content={
  523. <article>
  524. <p>hi bytedance</p> <p>hi bytedance</p>
  525. </article>
  526. }
  527. position="top"
  528. >
  529. <IconList />
  530. </Tooltip>
  531. <Tooltip content={'收起'} position="top">
  532. <IconButton icon={<IconSidebar />} />
  533. </Tooltip>
  534. <Tooltip content={'开关'} position="top">
  535. <Switch />
  536. </Tooltip>
  537. <Tooltip content={'选择框'} position="top">
  538. <Checkbox
  539. style={{
  540. display: 'inline-flex',
  541. }}
  542. >
  543. 选择框
  544. </Checkbox>
  545. </Tooltip>
  546. <Tooltip content={'单选'} position="top">
  547. <Radio
  548. style={{
  549. display: 'inline-flex',
  550. }}
  551. >
  552. 单选
  553. </Radio>
  554. </Tooltip>
  555. </div>
  556. );
  557. CompositeComponent.story = {
  558. name: '复合组件',
  559. };
  560. export const WrapDisabledElems = () => (
  561. <div
  562. style={{
  563. padding: 50,
  564. }}
  565. >
  566. <Tooltip content="disabled">
  567. <IconButton disabled icon={<IconEdit />} />
  568. </Tooltip>
  569. <Tooltip content="disabled">
  570. <IconButton disabled icon={<IconEdit />} block />
  571. </Tooltip>
  572. <Tooltip content="disabled">
  573. <Button disabled block>
  574. 编辑
  575. </Button>
  576. </Tooltip>
  577. <Tooltip content="disabled">
  578. <Button
  579. disabled
  580. style={{
  581. display: 'block',
  582. }}
  583. >
  584. 编辑
  585. </Button>
  586. </Tooltip>
  587. </div>
  588. );
  589. WrapDisabledElems.story = {
  590. name: 'wrap disabled elems',
  591. };
  592. export const InTable = () => (
  593. <div
  594. style={{
  595. marginTop: 50,
  596. }}
  597. >
  598. <InTableDemo />
  599. </div>
  600. );
  601. InTable.story = {
  602. name: 'in table',
  603. };
  604. export const _EdgeDemo = () => <EdgeDemo />;
  605. _EdgeDemo.story = {
  606. name: 'edge demo',
  607. };
  608. export const ScrollTooltipDemo = () => <ScrollTooltip />;
  609. ScrollTooltipDemo.story = {
  610. name: 'scroll demo and set popup container',
  611. };
  612. export const DangerousHtmlDemo = () => <DangerousHtml />;
  613. DangerousHtmlDemo.story = {
  614. name: 'in dangerous html',
  615. };
  616. export const ArrowPointAtCenterDemo = () => <ArrowPointAtCenter />;
  617. ArrowPointAtCenterDemo.story = {
  618. name: 'arrow point at center',
  619. };
  620. export const CustomContainerDemo = () => <CustomContainer />;
  621. CustomContainerDemo.story = {
  622. name: 'custom container',
  623. };
  624. export const ContainerPositionDemo = () => <ContainerPosition />;
  625. ContainerPositionDemo.story = {
  626. name: 'container observer',
  627. };
  628. export const QuickMoveMouse = () => {
  629. /**
  630. * mouseEnterDelay, mouseLeaveDelay 默认都为 50
  631. * mouseEnterDelay, mouseLeaveDelay 都为 0,快速滑动可能出现两个 tooltip 出现
  632. */
  633. const Demo = () => {
  634. const props = {
  635. mouseEnterDelay: 50,
  636. mouseLeaveDelay: 0,
  637. };
  638. return (
  639. <div className="demo">
  640. <div>
  641. <Tooltip content={'1'} {...props}>
  642. aaaaaaaaaaa
  643. </Tooltip>
  644. </div>
  645. <div>
  646. <Tooltip content={'2'} {...props}>
  647. bbbbbbbbbbb
  648. </Tooltip>
  649. </div>
  650. <div>
  651. <Tooltip content={'3'} {...props}>
  652. ccccccccccc
  653. </Tooltip>
  654. </div>
  655. <div>
  656. <Tooltip content={'4'} {...props}>
  657. aaaaaaaaaaa
  658. </Tooltip>
  659. </div>
  660. <div>
  661. <Tooltip content={'5'} {...props}>
  662. bbbbbbbbbbb
  663. </Tooltip>
  664. </div>
  665. <div>
  666. <Tooltip content={'6'} {...props}>
  667. ccccccccccc
  668. </Tooltip>
  669. </div>
  670. <div>
  671. <Tooltip content={'7'} {...props}>
  672. aaaaaaaaaaa
  673. </Tooltip>
  674. </div>
  675. <div>
  676. <Tooltip content={'8'} {...props}>
  677. bbbbbbbbbbb
  678. </Tooltip>
  679. </div>
  680. <div>
  681. <Tooltip content={'9'} {...props}>
  682. ccccccccccc
  683. </Tooltip>
  684. </div>
  685. </div>
  686. );
  687. };
  688. return <Demo />;
  689. };
  690. QuickMoveMouse.story = {
  691. name: '快速移动鼠标可见性',
  692. };
  693. export const MotionFalseFix1402 = () => {
  694. function Demo() {
  695. const Test = React.forwardRef((props, ref) => (
  696. <span {...props} ref={ref}>
  697. Test
  698. </span>
  699. ));
  700. return (
  701. <div>
  702. <Tooltip content={'hi bytedance'} motion={false}>
  703. <Test />
  704. </Tooltip>
  705. <br />
  706. <br />
  707. <Tooltip content={'hi bytedance'}>
  708. <Test />
  709. </Tooltip>
  710. </div>
  711. );
  712. }
  713. return <Demo />;
  714. };
  715. MotionFalseFix1402.story = {
  716. name: 'motion=false fix #1402',
  717. };
  718. export const DisabledWrapperCls = () => (
  719. <>
  720. <Tooltip wrapperClassName="test" content={'hi bytedance'}>
  721. <Button>按钮</Button>
  722. </Tooltip>
  723. <br />
  724. <br />
  725. <Tooltip wrapperClassName="test" content={'hi bytedance'}>
  726. <Button disabled>禁用的单个按钮</Button>
  727. </Tooltip>
  728. <br />
  729. <br />
  730. <Tooltip wrapperClassName="test" content={'hi bytedance'}>
  731. <Button>正常的多个按钮</Button>
  732. <Button>正常的多个按钮</Button>
  733. </Tooltip>
  734. <br />
  735. <br />
  736. <Tooltip wrapperClassName="test" content={'hi bytedance'}>
  737. <Select disabled placeholder="请选择业务线" style={{ width: 120 }}>
  738. <Select.Option value="abc">抖音</Select.Option>
  739. <Select.Option value="hotsoon">火山</Select.Option>
  740. <Select.Option value="jianying" disabled>
  741. 剪映
  742. </Select.Option>
  743. <Select.Option value="xigua">西瓜视频</Select.Option>
  744. </Select>
  745. </Tooltip>
  746. <br />
  747. <br />
  748. </>
  749. );
  750. DisabledWrapperCls.story = {
  751. name: 'disabledWrapperCls',
  752. };
  753. export const ShowArrow = () => {
  754. function Demo() {
  755. const Test = React.forwardRef((props, ref) => (
  756. <Tag {...props} ref={ref}>
  757. Test
  758. </Tag>
  759. ));
  760. return (
  761. <div>
  762. <h4>should show content and arrow when click</h4>
  763. <Tooltip showArrow trigger="click" content={'hi bytedance'}>
  764. <Test />
  765. </Tooltip>
  766. </div>
  767. );
  768. }
  769. return <Demo />;
  770. };
  771. ShowArrow.story = {
  772. name: 'showArrow',
  773. };
  774. export const OnClickOutSideDemo = () => {
  775. let [v, setV] = useState(false);
  776. let clickOutSide = () => {
  777. console.log('clickOutSide');
  778. setV(false);
  779. };
  780. return (
  781. <>
  782. <Tooltip onClickOutSide={() => clickOutSide()} content={'hi bytedance'} visible={v} trigger="custom">
  783. <Button onClick={() => setV(true)}>按钮</Button>
  784. </Tooltip>
  785. <br />
  786. <br />
  787. <Tooltip onClickOutSide={() => console.log('clickOutSide')} content={'hi bytedance'} trigger="click">
  788. <Button>单个按钮</Button>
  789. </Tooltip>
  790. </>
  791. );
  792. };
  793. OnClickOutSideDemo.story = {
  794. name: 'OnClickOutSide',
  795. };
  796. export const AutoAdjustWithSpacing = () => {
  797. const [height, setHeight] = useState(84);
  798. const [key, setKey] = useState(1);
  799. const initSpacing = 8;
  800. const [spacing, setSpacing] = useState(initSpacing);
  801. const change = (height, hasSpace) => {
  802. setHeight(height);
  803. hasSpace ? setSpacing(initSpacing) : setSpacing(0);
  804. setKey(Math.random());
  805. };
  806. return (
  807. <div className="demo1">
  808. <div>
  809. <Tooltip
  810. motion={false}
  811. rePosKey={key}
  812. // spacing={spacing}
  813. content={
  814. <article style={{ boxSizing: 'border-box', height: height }}>
  815. <p>hi bytedance, + padding 20</p>
  816. <p>hi bytedance</p>
  817. </article>
  818. }
  819. position="top"
  820. trigger="custom"
  821. visible={true}
  822. >
  823. <Tag>demo</Tag>
  824. </Tooltip>
  825. </div>
  826. <div style={{ marginTop: 200 }}>
  827. <Switch
  828. onChange={hasSpace => change(height, hasSpace)}
  829. checked={spacing === initSpacing ? true : false}
  830. ></Switch>
  831. <InputNumber onChange={height => change(Number(height))} value={height} style={{ width: 200 }} />
  832. </div>
  833. </div>
  834. );
  835. };
  836. AutoAdjustWithSpacing.story = {
  837. name: 'AutoAdjustWithSpacing',
  838. };
  839. /**
  840. * Chromatic UI test
  841. */
  842. export const leftTopOverDemo = () => {
  843. const [visible, setVisible] = useState(true);
  844. const content = <div style={{ height: 200, width: 200 }}>Semi Design</div>;
  845. const commonProps = {
  846. content,
  847. showArrow: false,
  848. visible:true,
  849. trigger: 'custom',
  850. motion: false,
  851. };
  852. const buttonStyle = {
  853. width: 200,
  854. };
  855. return (
  856. <div data-cy="wrapper">
  857. <Button onClick={() => setVisible(!visible)} data-cy="toggleVisible">toggle visible</Button>
  858. <div style={{ paddingTop: 110 }}>
  859. <Space spacing={80}>
  860. <Tooltip {...commonProps} position="leftBottomOver" trigger="click">
  861. <Button data-cy="leftBottomOver" style={buttonStyle}>
  862. leftBottomOver
  863. </Button>
  864. </Tooltip>
  865. <Tooltip {...commonProps} position="rightBottomOver" trigger="click">
  866. <Button data-cy="rightBottomOver" style={buttonStyle}>
  867. rightBottomOver
  868. </Button>
  869. </Tooltip>
  870. </Space>
  871. </div>
  872. <Space spacing={80}>
  873. <Tooltip {...commonProps} position="leftTopOver" trigger="click">
  874. <Button data-cy="leftTopOver" style={buttonStyle}>
  875. leftTopOver
  876. </Button>
  877. </Tooltip>
  878. <Tooltip {...commonProps} position="rightTopOver" trigger="click">
  879. <Button data-cy="rightTopOver" style={buttonStyle}>
  880. rightTopOver
  881. </Button>
  882. </Tooltip>
  883. </Space>
  884. </div>
  885. );
  886. };
  887. leftTopOverDemo.storyName = `leftTopOver visible`;
  888. leftTopOverDemo.parameters = {
  889. chromatic: {
  890. disableSnapshot: false,
  891. delay: 3000,
  892. viewports: [1200],
  893. },
  894. };
  895. /**
  896. * Cypress test
  897. */
  898. export const leftTopOverAutoAdjustOverflow = () => {
  899. const content = <div style={{ height: 200, width: 200 }}>Semi Design</div>;
  900. const commonProps = {
  901. content,
  902. trigger: 'click',
  903. showArrow: false,
  904. };
  905. return (
  906. <div
  907. data-cy="wrapper"
  908. style={{ width: '200vw', height: '200vw', display: 'flex', alignItems: 'center', justifyContent: 'center' }}
  909. >
  910. <div>
  911. <Tooltip {...commonProps} position="leftTopOver">
  912. <Button data-cy="leftTopOver" style={{ width: 200 }}>
  913. leftTopOver
  914. </Button>
  915. </Tooltip>
  916. </div>
  917. </div>
  918. );
  919. };
  920. leftTopOverAutoAdjustOverflow.storyName = `leftTopOver autoAdjustOverflow`;
  921. export const autoFocusContentDemo = () => {
  922. const [controlMotionVisible, setControlMotionVisible] = React.useState(false);
  923. const [controlNoMotionVisible, setControlNoMotionVisible] = React.useState(false);
  924. const onMotionVisibleChange = React.useCallback(() => {
  925. setControlMotionVisible(!controlMotionVisible);
  926. }, [setControlMotionVisible, controlMotionVisible]);
  927. const onNoMotionVisibleChange = React.useCallback(() => {
  928. setControlNoMotionVisible(!controlNoMotionVisible);
  929. }, [setControlNoMotionVisible, controlNoMotionVisible]);
  930. return (
  931. <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
  932. <div style={{ display: 'flex', gap: 18, flex: 1, alignItems: 'center' }}>
  933. <span>Hover触发</span>
  934. <Popover position="bottomLeft" content={<Input autofocus data-cy="hoverInput"/>}>
  935. <Button data-cy="hover">motion</Button>
  936. </Popover>
  937. <Popover motion={false} position="bottomLeft" content={<Input autofocus data-cy="hoverNoMotionInput"/>}>
  938. <Button data-cy="hoverNoMotion">no motion</Button>
  939. </Popover>
  940. </div>
  941. <div style={{ display: 'flex', gap: 18, flex: 1, alignItems: 'center' }}>
  942. <span>Click触发</span>
  943. <Popover position="bottomLeft" content={<Input autofocus data-cy="clickInput"/>} trigger="click">
  944. <Button data-cy="click">motion</Button>
  945. </Popover>
  946. <Popover motion={false} position="bottomLeft" content={<Input autofocus data-cy="clickNoMotionInput"/>} trigger="click">
  947. <Button data-cy="clickNoMotion">no motion</Button>
  948. </Popover>
  949. </div>
  950. <div style={{ display: 'flex', gap: 18, flex: 1, alignItems: 'center' }}>
  951. <span>受控</span>
  952. <Button onClick={onMotionVisibleChange} data-cy="controlled">motion状态切换</Button>
  953. <Popover visible={controlMotionVisible} trigger="custom" position="bottomLeft" content={<Input autofocus data-cy="controlledInput"/>}>
  954. <Button disabled data-cy="controlledDisableBtn">motion</Button>
  955. </Popover>
  956. <Button onClick={onNoMotionVisibleChange } data-cy="controlledNoMotion">no motion状态切换</Button>
  957. <Popover
  958. visible={controlNoMotionVisible}
  959. trigger="custom"
  960. motion={false}
  961. position="bottomLeft"
  962. content={<Input autofocus data-cy="controlledNoMotionInput"/>}
  963. >
  964. <Button disabled data-cy="controlledNoMotionDisableBtn">no motion</Button>
  965. </Popover>
  966. </div>
  967. </div>
  968. );
  969. };
  970. export const FlashWithReact18 = () => {
  971. const [visible, setV] = useState(false);
  972. const change = () => {
  973. setV(false);
  974. }
  975. return (<>
  976. <Tooltip content='test work with react 18' position='bottom' trigger='custom' visible={visible}>
  977. <Button style={{ marginLeft: 10 }} onClick={() => setV(true)}>show, semi with react 18 motion=true, abnormal</Button>
  978. </Tooltip>
  979. <Button style={{ marginLeft: 10 }} onClick={() => change()}>hide</Button>
  980. </>);
  981. }
  982. export const Transition = () => {
  983. const [transitionState, setT] = useState('');
  984. const [insert, setInsert] = useState(false);
  985. const handleLeave = () => {
  986. console.log('set insert false')
  987. setInsert(false);
  988. }
  989. const CommonDOM = () => {
  990. const enterCls = `semi-tooltip-bounceIn`;
  991. const leaveCls = `semi-tooltip-zoomOut`;
  992. const animateStyle = {
  993. animationDirection: 'normal',
  994. animationName: transitionState === 'enter' ? enterCls : leaveCls,
  995. animationDuration: '1000ms',
  996. }
  997. const handleEnd = () => {
  998. if (transitionState === 'enter') {
  999. console.log('animation end of show');
  1000. } else if (transitionState === 'leave') {
  1001. console.log('animation end of hide');
  1002. handleLeave();
  1003. }
  1004. }
  1005. return <div style={{ ...animateStyle }} onAnimationEnd={handleEnd}>test</div>
  1006. };
  1007. const toggleShow = (insert) => {
  1008. if (!transitionState) {
  1009. setT('enter');
  1010. setInsert(insert);
  1011. } else if (transitionState === 'enter') {
  1012. setT('leave');
  1013. } else if (transitionState === 'leave') {
  1014. setT('enter');
  1015. setInsert(insert);
  1016. }
  1017. };
  1018. return (
  1019. <>
  1020. <div style={{ width: 200, height: 90, border: '1px solid var(--semi-color-text-1)' }}>
  1021. {
  1022. insert ? (
  1023. <CommonDOM></CommonDOM>
  1024. ): null
  1025. }
  1026. </div>
  1027. <Button onClick={() => toggleShow(true)}>show</Button>
  1028. <Button onClick={() => toggleShow(false)}>hide</Button>
  1029. </>
  1030. )
  1031. }
  1032. export const TransitionDemo = () => {
  1033. const [key, setKey] = useState(1);
  1034. return (
  1035. <>
  1036. <Transition key={key} />
  1037. <Button onClick={() => setKey(Math.random())}>reset Demo</Button>
  1038. </>
  1039. )
  1040. }
  1041. export const AdjustPosIfNeedTBLR = () => {
  1042. const content = <article>
  1043. Hi ByteDancer, this is a tooltip.
  1044. <br /> We have 2 lines.
  1045. </article>
  1046. const contentHigh = <article>
  1047. Hi ByteDancer, this is a tooltip.
  1048. <br /> We have 2 lines.
  1049. <br /> We have 2 lines.
  1050. </article>
  1051. return (
  1052. <div style={{ paddingLeft: 0, width: 800, height: '100%' }}>
  1053. <Tooltip
  1054. showArrow
  1055. arrowPointAtCenter
  1056. content={content}
  1057. position={'top'}
  1058. >
  1059. <Tag style={{ position: 'absolute', left: 20, top: 40 }}>top to bottomLeft</Tag>
  1060. </Tooltip>
  1061. <Tooltip
  1062. showArrow
  1063. arrowPointAtCenter
  1064. content={content}
  1065. position={'top'}
  1066. >
  1067. <Tag style={{ position: 'absolute', right: 20, top: 40 }}>top to bottomRight</Tag>
  1068. </Tooltip>
  1069. <Tooltip
  1070. showArrow
  1071. arrowPointAtCenter
  1072. content={content}
  1073. position={'top'}
  1074. >
  1075. <Tag style={{ position: 'absolute', left: 20, top: 70 }}>top to topLeft</Tag>
  1076. </Tooltip>
  1077. <Tooltip
  1078. showArrow
  1079. arrowPointAtCenter
  1080. content={content}
  1081. position={'top'}
  1082. >
  1083. <Tag style={{ position: 'absolute', right: 20, top: 70 }}>top to topRight</Tag>
  1084. </Tooltip>
  1085. <Tooltip
  1086. showArrow
  1087. arrowPointAtCenter
  1088. content={content}
  1089. position={'bottom'}
  1090. >
  1091. <Tag data-cy={'bottom'} style={{ position: 'absolute', left: 20, bottom: 70 }}>bottom to bottomLeft</Tag>
  1092. </Tooltip>
  1093. <Tooltip
  1094. showArrow
  1095. arrowPointAtCenter
  1096. content={content}
  1097. position={'bottom'}
  1098. >
  1099. <Tag data-cy={'bottom'} style={{ position: 'absolute', right: 20, bottom: 70 }}>bottom to bottomRight</Tag>
  1100. </Tooltip>
  1101. <Tooltip
  1102. showArrow
  1103. arrowPointAtCenter
  1104. content={content}
  1105. position={'bottom'}
  1106. >
  1107. <Tag data-cy={'bottom'} style={{ position: 'absolute', left: 20, bottom: 40 }}>bottom to topLeft</Tag>
  1108. </Tooltip>
  1109. <Tooltip
  1110. showArrow
  1111. arrowPointAtCenter
  1112. content={content}
  1113. position={'bottom'}
  1114. >
  1115. <Tag data-cy={'bottom'} style={{ position: 'absolute', right: 20, bottom: 40 }}>bottom to topRight</Tag>
  1116. </Tooltip>
  1117. <Tooltip
  1118. showArrow
  1119. arrowPointAtCenter
  1120. content={contentHigh}
  1121. position={'left'}
  1122. >
  1123. <Tag style={{ position: 'absolute', left: 300, top: 20 }}>left to leftTop</Tag>
  1124. </Tooltip>
  1125. <Tooltip
  1126. showArrow
  1127. arrowPointAtCenter
  1128. content={contentHigh}
  1129. position={'left'}
  1130. >
  1131. <Tag style={{ position: 'absolute', left: 300, bottom: 20 }}>left to leftBottom</Tag>
  1132. </Tooltip>
  1133. <Tooltip
  1134. showArrow
  1135. arrowPointAtCenter
  1136. content={contentHigh}
  1137. position={'left'}
  1138. >
  1139. <Tag style={{ position: 'absolute', left: 180, top: 20 }}>left to rightTop</Tag>
  1140. </Tooltip>
  1141. <Tooltip
  1142. showArrow
  1143. arrowPointAtCenter
  1144. content={contentHigh}
  1145. position={'left'}
  1146. >
  1147. <Tag style={{ position: 'absolute', left: 180, bottom: 20 }}>left to rightBottom</Tag>
  1148. </Tooltip>
  1149. <Tooltip
  1150. showArrow
  1151. arrowPointAtCenter
  1152. content={contentHigh}
  1153. position={'right'}
  1154. >
  1155. <Tag style={{ position: 'absolute', right: 300, top: 20 }}>right to rightTop</Tag>
  1156. </Tooltip>
  1157. <Tooltip
  1158. showArrow
  1159. arrowPointAtCenter
  1160. content={contentHigh}
  1161. position={'right'}
  1162. >
  1163. <Tag style={{ position: 'absolute', right: 300, bottom: 20 }}>right to rightBottom</Tag>
  1164. </Tooltip>
  1165. <Tooltip
  1166. showArrow
  1167. arrowPointAtCenter
  1168. content={contentHigh}
  1169. position={'right'}
  1170. >
  1171. <Tag style={{ position: 'absolute', right: 180, top: 20 }}>right to leftTop</Tag>
  1172. </Tooltip>
  1173. <Tooltip
  1174. showArrow
  1175. arrowPointAtCenter
  1176. content={contentHigh}
  1177. position={'right'}
  1178. >
  1179. <Tag style={{ position: 'absolute', right: 180, bottom: 20 }}>right to leftBottom</Tag>
  1180. </Tooltip>
  1181. <Tooltip
  1182. showArrow
  1183. arrowPointAtCenter
  1184. content={contentHigh}
  1185. position={'rightTop'}
  1186. >
  1187. <Tag style={{ position: 'absolute', right: 180, bottom: 50 }}>right to leftBottom</Tag>
  1188. </Tooltip>
  1189. </div>
  1190. );
  1191. }
  1192. export const marginDemo = () => {
  1193. const [visible, setVisible] = useState(false);
  1194. const change = () => {
  1195. setVisible(!visible);
  1196. };
  1197. return (
  1198. <>
  1199. <Button onClick={change}>Open SideSheet</Button>
  1200. <SideSheet title="滑动侧边栏" visible={visible} onCancel={change}>
  1201. <div style={{ height: '800px', overflow: 'scroll' }}>
  1202. <div
  1203. id='test'
  1204. style={{
  1205. height: '880px',
  1206. display: 'flex',
  1207. flexDirection: 'column-reverse',
  1208. position: 'relative'
  1209. }}
  1210. >
  1211. <Tooltip
  1212. getPopupContainer={() => document.querySelector('#test')}
  1213. content='cecece'
  1214. position='bottom'
  1215. margin={{ marginTop: 0, marginLeft: 0, marginBottom: 36, marginRight: 0 }}
  1216. >
  1217. <div style={{ marginBottom: 20 }}>
  1218. test
  1219. </div>
  1220. </Tooltip>
  1221. </div>
  1222. </div>
  1223. <footer style={{
  1224. position: 'sticky',
  1225. bottom: 0,
  1226. height: 36,
  1227. border: '1px solid pink'
  1228. }}>
  1229. i am footer
  1230. </footer>
  1231. </SideSheet>
  1232. </>
  1233. );
  1234. };
  1235. export const SmartPosAdjustDemo = () => {
  1236. const [pos, setPosition] = useState('top');
  1237. const onChange = (e) => {
  1238. setPosition(e.target.value);
  1239. };
  1240. return (
  1241. <div style={{ width: 800, height: 800 }}>
  1242. <Popover
  1243. position={pos}
  1244. showArrow={true}
  1245. content={
  1246. <div style={{ minWidth: 900, height: 900, backgroundColor: 'lightblue' }}>
  1247. <article>
  1248. <p>hi semi! hi semi! hi semi!hi semi! hi semi</p>
  1249. <p>hi semi! hi semi! hi semi!hi semi! hi semi</p>
  1250. <p>hi semi! hi semi! hi semi!</p>
  1251. </article>
  1252. </div>
  1253. }
  1254. >
  1255. <Tag style={{ marginLeft: 450, marginTop: 550 }}>悬停此处</Tag>
  1256. </Popover>
  1257. <div style={{ marginLeft: 250, width: 300 }}>
  1258. <RadioGroup onChange={onChange} value={pos} aria-label="position" name="position">
  1259. <Radio value={'topLeft'}>TL </Radio>
  1260. <Radio value={'top'}>top </Radio>
  1261. <Radio value={'topRight'}>TR </Radio>
  1262. <Radio value={'bottomLeft'}>BL</Radio>
  1263. <Radio value={'bottom'}>Bottom</Radio>
  1264. <Radio value={'bottomRight'}>BR</Radio>
  1265. <Radio value={'leftTop'}>LT</Radio>
  1266. <Radio value={'left'}>Left</Radio>
  1267. <Radio value={'leftBottom'}>LB</Radio>
  1268. <Radio value={'rightTop'}>RT</Radio>
  1269. <Radio value={'right'}>Right</Radio>
  1270. <Radio value={'rightBottom'}>RB</Radio>
  1271. </RadioGroup>
  1272. </div>
  1273. </div>
  1274. )
  1275. }
  1276. export const OcclusionDemo = () => {
  1277. return (
  1278. <div>
  1279. <Tooltip
  1280. position='left'
  1281. content={
  1282. <div
  1283. style={{
  1284. width: 520,
  1285. height: 360
  1286. }}
  1287. >
  1288. 我的上侧被遮挡啦!但是我可以正常显示! 我的上侧被遮挡啦!但是我可以正常显示!我的上侧被遮挡啦!但是我可以正常显示!
  1289. </div>
  1290. }
  1291. >
  1292. <div
  1293. style={{
  1294. position: "absolute",
  1295. top: -120,
  1296. width: 150,
  1297. height: 200,
  1298. backgroundColor: "lightBlue",
  1299. }}
  1300. >
  1301. 我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!我的上侧被遮挡啦!
  1302. </div>
  1303. </Tooltip>
  1304. <Tooltip
  1305. content={
  1306. <div
  1307. style={{
  1308. width: 520,
  1309. height: 360
  1310. }}
  1311. >
  1312. 我的右侧被遮挡啦!但是我可以正常显示! 我的右侧被遮挡啦!但是我可以正常显示! 我的右侧被遮挡啦!但是我可以正常显示!
  1313. </div>
  1314. }
  1315. >
  1316. <div
  1317. style={{
  1318. position: "absolute",
  1319. right: -120,
  1320. width: 150,
  1321. height: 20,
  1322. lineHeight: "20px",
  1323. backgroundColor: "lightBlue",
  1324. }}
  1325. >
  1326. 我的右侧被遮挡啦!
  1327. </div>
  1328. </Tooltip>
  1329. </div>
  1330. );
  1331. }
  1332. export const Fix1449 = () =>{
  1333. return <div style={{ width: "100%", overflow: "hidden" }}>
  1334. <div style={{ position: "relative", height: 200 }}>
  1335. <Select
  1336. placeholder=""
  1337. style={{ width: 400, left: 500, position: "absolute" }}
  1338. filter
  1339. position='bottomLeft'
  1340. autoAdjustOverflow
  1341. >
  1342. <Select.Option value="abc">抖音</Select.Option>
  1343. <Select.Option value="ulikecam">轻颜相机</Select.Option>
  1344. <Select.Option value="jianying" disabled>
  1345. 剪映
  1346. </Select.Option>
  1347. <Select.Option value="xigua">西瓜视频</Select.Option>
  1348. </Select>
  1349. </div>
  1350. <div style={{ position: "relative", height: 100 }}>
  1351. <Tooltip
  1352. visible
  1353. position='topLeft'
  1354. content={
  1355. <div >
  1356. 贴右显示
  1357. </div>
  1358. }>
  1359. <Button style={{ width: 200, left: 700, top: 50, position: "absolute" }}>
  1360. 缩小视口以遮挡我的右侧
  1361. </Button>
  1362. </Tooltip>
  1363. </div>
  1364. </div>
  1365. }
  1366. // right -> other
  1367. export const AutoRight2LeftDemo = () => <Right2Left />;
  1368. AutoRight2LeftDemo.storyName = `✅ auto : right -> left`;
  1369. export const AutoRight2LeftBottomDemo = () => <Right2LeftBottom />;
  1370. AutoRight2LeftBottomDemo.storyName = `✅ auto : right -> leftBottom`;
  1371. export const AutoRight2LeftTopDemo = () => <Right2LeftTop />;
  1372. AutoRight2LeftTopDemo.storyName = `✅ auto : riht -> leftTop`;
  1373. export const AutoRight2RightBottomDemo = () => <Right2RightBottom />;
  1374. AutoRight2RightBottomDemo.storyName = `✅ auto : right -> rightBottom`;
  1375. export const AutoRight2RightTopDemo = () => <Right2RightTop />;
  1376. AutoRight2RightTopDemo.storyName = `✅ auto : riht -> rightTop`;
  1377. // left -> other
  1378. export const Left2RightDemo = () => <Left2Right />;
  1379. Left2RightDemo.storyName = `✅ auto : left -> right`;
  1380. export const Left2LeftBottomDemo = () => <Left2LeftBottom />;
  1381. Left2LeftBottomDemo.storyName = `✅ auto : left -> leftBottom`;
  1382. export const Left2LeftTopDemo = () => <Left2LeftTop />;
  1383. Left2LeftTopDemo.storyName = `✅ auto : left -> leftTop`;
  1384. export const Left2RightBottomDemo = () => <Left2RightBottom />;
  1385. Left2RightBottomDemo.storyName = `✅ auto : left -> rightBottom`;
  1386. export const Left2RightTopDemo = () => <Left2RightTop />;
  1387. Left2RightTopDemo.storyName = `✅ auto : left -> rightTop`;
  1388. // top -> other
  1389. export const Top2BottomDemo = () => <Top2Bottom />;
  1390. Top2BottomDemo.storyName = `✅ auto : top -> bottom`;
  1391. export const Top2BottomLeftDemo = () => <Top2BottomLeft />;
  1392. Top2BottomLeftDemo.storyName = `✅ auto : top -> bottomLeft`;
  1393. export const Top2BottomRightDemo = () => <Top2BottomRight />;
  1394. Top2BottomRightDemo.storyName = `✅ auto : top -> bottomRight`;
  1395. export const Top2TopLeftDemo = () => <Top2TopLeft />;
  1396. Top2TopLeftDemo.storyName = `✅ auto : top -> topLeft`;
  1397. export const Top2TopRightDemo = () => <Top2TopRight />;
  1398. Top2TopRightDemo.storyName = `✅ auto : top -> topRight`;
  1399. // bottom -> other
  1400. export const Bottom2TopDemo = () => <Bottom2Top />;
  1401. Bottom2TopDemo.storyName = `✅ auto : bottom -> top`;
  1402. export const Bottom2TopLeftDemo = () => <Bottom2TopLeft />;
  1403. Bottom2TopLeftDemo.storyName = `✅ auto : bottom -> topLeft`;
  1404. export const Bottom2TopRightDemo = () => <Bottom2TopRight />;
  1405. Bottom2TopRightDemo.storyName = `✅ auto : bottom -> topRight`;
  1406. export const Bottom2BottomLeftDemo = () => <Bottom2BottomLeft />;
  1407. Bottom2BottomLeftDemo.storyName = `✅ auto : bottom -> bottomLeft`;
  1408. export const Bottom2BottomRightDemo = () => <Bottom2BottomRight />;
  1409. Bottom2BottomRightDemo.storyName = `✅ auto : bottom -> bottomRight`;
  1410. export const Fix1557 = () =>{
  1411. return (
  1412. <Dropdown
  1413. trigger='hover'
  1414. disableFocusListener
  1415. render={
  1416. <Dropdown.Menu>
  1417. <Popconfirm
  1418. content={
  1419. <>
  1420. <Select filter/>
  1421. </>
  1422. }
  1423. >
  1424. <Button>点我后再点击select, Dropdown 面板不收起</Button>
  1425. </Popconfirm>
  1426. </Dropdown.Menu>
  1427. }
  1428. >
  1429. <Tag>Hover Me</Tag>
  1430. </Dropdown>
  1431. );
  1432. }
  1433. export const wordBreak = () => {
  1434. const gapElement = (gap=200) => <div style={{ marginTop: gap }}></div>;
  1435. const tooltipShowProps = {
  1436. trigger: "custom",
  1437. visible: true ,
  1438. // showArrow: false
  1439. };
  1440. const testContent = {
  1441. '长hash': 'ide2d3a4e9d7b7d93fc4c3b8e4b1b4b08e4f5a9f13ed8b8d6f7c5b7c4c7e4b9e6b9e6e5d4e4c5f6e3b1e7b3a3e3e5c5f4e9c8',
  1442. 'url测试': 'https://semi.design/zh-CN/show/tooltip#%E4%BB%85%E5%BD%93%E5%86%85%E5%AE%B9%E5%AE%BD%E5%BA%A6%E8%B6%85%E5%87%BA%E6%97%B6%E5%B1%95%E7%A4%BA%20Tooltip',
  1443. '中文测试': '中文测试中文测试中文测试中文测试中文测试中文测试中文测试中文测试中文测试中文测试中文测试中文测试',
  1444. // 以下为英文中最长的单词
  1445. '英文测试': 'pneumonoultramicroscopicsilicovolcanoconiosis',
  1446. '日语测试': '超音波検査による胸部エコー検査結果、心拍数や脈波などの検査結果から、緊急性はないものの肺炎の可能性があるため、抗生物質の処方箋を出します。',
  1447. '韩语测试': '인공지능과 빅데이터 기술을 활용한 자율주행 자동차의 개발은 현재 국내외에서 많은 관심을 받고 있습니다.',
  1448. '泰语测试': 'เทคโนโลยีการผลิตอาหารและสารสกัดจากพืชชนิดต่าง ๆ กำลังเป็นที่สนใจในวงการอาหารทั่วโลก',
  1449. '阿拉伯语测试': 'تطور التكنولوجيا والذكاء الاصطناعي يؤثر بشكل كبير على صناعة العمليات الإنتاجية ونمط الحياة الحديثة.',
  1450. '越南语': 'Ứng dụng công nghệ thông tin và trí tuệ nhân tạo đang ngày càng được sử dụng rộng rãi trong lĩnh vực sản xuất và dịch vụ. không-gian-phi-trụ-điện-từ',
  1451. '俄罗斯语': 'Разработка новейших технологий искусственного интеллекта и машинного обучения становится все более важной в наши дни.',
  1452. '印尼语': 'Pemanfaatan teknologi informasi dan kecerdasan buatan semakin penting dalam industri modern.',
  1453. '马来语': 'Penggunaan teknologi maklumat dan kecerdasan buatan semakin penting dalam industri moden.',
  1454. '泰语': 'บริการจัดส่งสินค้าทางไปรษณีย์ภายในประเทศไทยมีความสะดวกสบายและรวดเร็วมากยิ่งขึ้นด้วยการใช้เทคโนโลยีที่ทันสมัยในการติดตามสถานะและการจัดส่งสินค้า นอกจากนี้ยังมีการให้บริการเพิ่มเติมอย่างต่างๆ เช่น การจัดส่งพิเศษ การรับส่งเอกสาร การจัดส่งด่วน เป็นต้น',
  1455. '土耳其语': "Otomobil endüstrisi, Türkiye'nin en önemli sanayi kollarından biridir. Türkiye, yılda yaklaşık 1 milyon adet otomobil üretimiyle Avrupa'nın önde gelen üreticileri arasındadır.",
  1456. '葡萄牙语': "A eletricidade é uma fonte de energia renovável e limpa, que é produzida a partir de fontes como a energia solar, eólica, hidroelétrica e geotérmica.",
  1457. '西班牙语': "La biotecnología es una rama de la ciencia que utiliza organismos vivos o partes de ellos para desarrollar productos y servicios que mejoren la calidad de vida.",
  1458. '意大利语': "L'ingegneria genetica è una branca della biologia molecolare che si occupa di manipolare il DNA per creare organismi con caratteristiche specifiche.",
  1459. '法语': 'La pharmacologie est la science qui étudie les effets des médicaments sur les êtres vivants et leur utilisation pour la prévention, le diagnostic et le traitement des maladies.',
  1460. '德语': 'Die Kernenergie ist eine umstrittene Energiequelle, die durch die Nutzung der Energie aus Atomkernen Strom erzeugt.',
  1461. '罗马尼亚语': 'Ingineria software este o ramură a informaticii care se ocupă cu dezvoltarea de programe și aplicații software.',
  1462. '瑞典语': 'Neurovetenskap är studiet av nervsystemet och dess funktioner, inklusive dess relationer till beteende och kognition.',
  1463. '波兰语': 'Archeologia jest nauką humanistyczną zajmującą się badaniem śladów pozostawionych przez człowieka w przeszłości.',
  1464. '荷兰语': 'Psychologie is de wetenschappelijke studie van het menselijk gedrag en de processen die daaraan ten grondslag liggen.',
  1465. };
  1466. const longWordContent = {
  1467. '英文测试': "pneumonoultramicroscopicsilicovolcanoconiosis",
  1468. '泰语测试': "หน้าต่างจอภาพ",
  1469. '阿拉伯语测试': "أفاستسقيناكموها",
  1470. '越南语': "bấtđồngxứngđáng",
  1471. '俄罗斯语': "человеконенавистничество",
  1472. '印尼语': "melipatgandakan",
  1473. '马来语': "pengangkutan",
  1474. '土耳其语': "çekoslovakyalılaştıramadıklarımızdanmışsınızcasına",
  1475. '葡萄牙语': "otorrinolaringologista",
  1476. '西班牙语': "electroencefalografista",
  1477. '意大利语': "precipitevolissimevolmente",
  1478. '法语': "anticonstitutionnellement ",
  1479. '德语': "Donaudampfschifffahrtsgesellschaftskapitän",
  1480. '罗马尼亚语': "neîncorporabile",
  1481. '瑞典语': "realisationsvinstbeskattning",
  1482. '波兰语': "najedźcieżżebrzącychświniątkach",
  1483. '荷兰语': "Kindercarnavalsoptochtvoorbereidingswerkzaamheden"
  1484. }
  1485. return (
  1486. <>
  1487. {['bottom','top'].map((item, index) => {
  1488. return <div key={`${index}`}>
  1489. <Tooltip {...tooltipShowProps} content={'中'} position={item}>
  1490. <span style={{ marginRight: 10 }}>中文测试</span>
  1491. </Tooltip>
  1492. <Tooltip {...tooltipShowProps} content={'-'} position={item}>
  1493. <span style={{ marginRight: 10 }}>高度测试</span>
  1494. </Tooltip>
  1495. <Tooltip showArrow={false} {...tooltipShowProps} content={'中'} position={item} >
  1496. <span style={{ marginRight: 10 }}>中文无 arrow 测试</span>
  1497. </Tooltip>
  1498. <Tooltip showArrow={false} {...tooltipShowProps} content={'t'} position={item}>
  1499. <span style={{ marginRight: 10 }}>英文无 arrow 测试</span>
  1500. </Tooltip>
  1501. {gapElement(100)}
  1502. </div>
  1503. })}
  1504. <p style={{ marginTop: 50 }}>以下为 word-wrap: break-word <strong>VS</strong> word-wrap: normal </p>
  1505. {Object.entries(testContent).map((item, index) => {
  1506. const [key, value] = item;
  1507. return <div key={`${index}`}>
  1508. {gapElement(200)}
  1509. <Tooltip {...tooltipShowProps} content={value} position={'top'}>
  1510. {`${key}`}
  1511. </Tooltip>
  1512. <Tooltip {...tooltipShowProps} content={value} position={'top'} style={{ wordWrap: 'normal' }}>
  1513. <span style={{ marginLeft: 350 }}>{`${key}`}</span>
  1514. </Tooltip>
  1515. </div>
  1516. })}
  1517. {Object.entries(longWordContent).map((item, index) => {
  1518. const [key, value] = item;
  1519. return <div key={`${index}`}>
  1520. {gapElement(100)}
  1521. <Tooltip {...tooltipShowProps} content={value} position={'top'} style={{ width: 50 }}>
  1522. {`${key}`}
  1523. </Tooltip>
  1524. <Tooltip {...tooltipShowProps} content={value} position={'top'} style={{ wordWrap: 'normal', width: 50 }}>
  1525. <span style={{ marginLeft: 350 }}>{`${key}`}</span>
  1526. </Tooltip>
  1527. </div>
  1528. })}
  1529. </>
  1530. );
  1531. }
  1532. export const ViewportPrioritJudgment = () => {
  1533. // If the viewport reverse space is sufficient, the viewport result shall prevail
  1534. return (
  1535. <div style={{ height: '1000px' }}>
  1536. <Tooltip content={"hi bytedance"} position='top'>
  1537. <Button theme="solid" type="tertiary" style={{ marginBottom: 20, marginTop: 200 }}>
  1538. 悬停显示
  1539. </Button>
  1540. </Tooltip>
  1541. </div>
  1542. )
  1543. }