anchor.stories.jsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import React, { useState } from 'react';
  2. import Button from '../../button';
  3. import { Anchor } from '../../index';
  4. export default {
  5. title: 'Anchor',
  6. }
  7. const getContainer = () => {
  8. const node = document.getElementById('box');
  9. return node;
  10. };
  11. const Link = Anchor.Link;
  12. export const Size = () => (
  13. <div>
  14. <div>小号尺寸</div>
  15. <Anchor aria-label='小号尺寸' size={'small'}>
  16. <Link href="#welcome" title="welcome" />
  17. <Link href="#api" title="api too much to show" />
  18. <Link href="#contact" title="contact" />
  19. </Anchor>
  20. <br />
  21. <div>默认</div>
  22. <Anchor>
  23. <Link href="#welcome" title="welcome" />
  24. <Link href="#api" title="api too much to show" />
  25. <Link href="#contact" title="contact" />
  26. </Anchor>
  27. </div>
  28. );
  29. export const Theme = () => (
  30. <div>
  31. <div>点击锚点查看效果</div>
  32. <br />
  33. <Anchor railTheme={'primary'}>
  34. <Link href="#组件" title="组件" />
  35. <Link href="#设计语言" title="设计语言" />
  36. <Link href="#物料平台" title="物料平台" />
  37. <Link href="#主题商店" title="主题商店" />
  38. </Anchor>
  39. <br />
  40. <Anchor railTheme={'tertiary'}>
  41. <Link href="#组件" title="组件" />
  42. <Link href="#设计语言" title="设计语言" />
  43. <Link href="#物料平台" title="物料平台" />
  44. <Link href="#主题商店" title="主题商店" />
  45. </Anchor>
  46. <br />
  47. <Anchor railTheme={'muted'}>
  48. <Link href="#组件" title="组件" />
  49. <Link href="#设计语言" title="设计语言" />
  50. <Link href="#物料平台" title="物料平台" />
  51. <Link href="#主题商店" title="主题商店" />
  52. </Anchor>
  53. </div>
  54. );
  55. export const autoCollapse = () => (
  56. <div>
  57. <div>Anchor 设置 autoCollapse 可以动态展示下一级锚点。</div>
  58. <br />
  59. <div>点击 1.Semi Design 查看效果</div>
  60. <Anchor autoCollapse={true}>
  61. <Link href="#Semi Design" title="1. Semi Design">
  62. <Link href="#组件" title="1.1 组件">
  63. <Link href="#头像" title="1.1.1 Avatar" />
  64. <Link href="#按钮" title="1.1.2 Button" />
  65. <Link href="#图标" title="1.1.3 Icon" />
  66. </Link>
  67. <Link href="#物料" title="1.2 物料" />
  68. <Link href="#主题商店" title="1.3 主题商店" />
  69. </Link>
  70. <Link href="#设计语言" title="2. 设计语言" />
  71. </Anchor>
  72. <br />
  73. <div>默认不进行动态折叠</div>
  74. <Anchor autoCollapse={false}>
  75. <Link href="#Semi Design" title="1. Semi Design">
  76. <Link href="#组件" title="1.1 组件">
  77. <Link href="#头像" title="1.1.1 Avatar" />
  78. <Link href="#按钮" title="1.1.2 Button" />
  79. <Link href="#图标" title="1.1.3 Icon" />
  80. </Link>
  81. <Link href="#物料" title="1.2 物料" />
  82. <Link href="#主题商店" title="1.3 主题商店" />
  83. </Link>
  84. <Link href="#设计语言" title="2. 设计语言" />
  85. </Anchor>
  86. </div>
  87. );
  88. export const showTooltip = () => (
  89. <div>
  90. <div>工具提示可以在 Link 超出最大宽度时显示 Link 的文字内容</div>
  91. <br />
  92. <Anchor showTooltip={true}>
  93. <Link href="#组件" title="组件" />
  94. <Link href="#设计语言" title="设计语言" />
  95. <Link href="#物料平台" title="物料平台" />
  96. <Link href="#主题商店" title="主题商店" />
  97. <Link
  98. href="#显示工具提示"
  99. title="工具提示是一个有用的工具,它可以在文字缩略时展示全部内容。"
  100. />
  101. </Anchor>
  102. <br />
  103. <div>position可以设置工具提示的位置</div>
  104. <Anchor showTooltip={true} position={'right'}>
  105. <Link href="#组件" title="组件" />
  106. <Link href="#设计语言" title="设计语言" />
  107. <Link href="#物料平台" title="物料平台" />
  108. <Link href="#主题商店" title="主题商店" />
  109. <Link
  110. href="#工具提示位置"
  111. title="工具提示是一个有用的工具,它可以在文字缩略时展示全部内容。"
  112. />
  113. </Anchor>
  114. </div>
  115. );
  116. export const MaxHeight = () => (
  117. <div>
  118. <div>设置 maxHeight 可以控制 Anchor 的高度,滚动显示 Anchor 内容</div>
  119. <br />
  120. <Anchor maxHeight={'100px'}>
  121. <Link href="#组件" title="组件" />
  122. <Link href="#设计语言" title="设计语言" />
  123. <Link href="#物料平台" title="物料平台" />
  124. <Link href="#主题商店" title="主题商店" />
  125. <Link
  126. href="#显示工具提示"
  127. title="工具提示是一个有用的工具,它可以在文字缩略时展示全部内容。"
  128. />
  129. </Anchor>
  130. </div>
  131. );
  132. export const StylePosition = () => (
  133. <div>
  134. <Anchor
  135. style={{ position: 'absolute', right: 0 }}
  136. scrollMotion={false}
  137. getContainer={getContainer}
  138. >
  139. <Link href="#welcome" title="welcome" />
  140. <Link href="#api" title="api too much to show">
  141. <Link href="#docs" title="docs">
  142. <Link href="#doc1" title="doc1" />
  143. <Link href="#doc2" title="doc2" />
  144. </Link>
  145. </Link>
  146. <Link href="#contact" title="contact" />
  147. </Anchor>
  148. <div>设置style对象可以改变 Anchor 组件的定位方式,右边就是个 fixed 的 Anchor</div>
  149. <div id="box" style={{ height: '500px', overflow: 'scroll' }}>
  150. <h1 id="welcome" style={{ height: '300px' }}>
  151. Welcome
  152. </h1>
  153. <h1 id="api" style={{ height: '300px' }}>
  154. API
  155. </h1>
  156. <h2 id="docs" style={{ height: '200px' }}>
  157. Docs
  158. </h2>
  159. <h3 id="doc1" style={{ height: '100px' }}>
  160. Doc1
  161. </h3>
  162. <h3 id="doc2" style={{ height: '100px' }}>
  163. Doc2
  164. </h3>
  165. <h1 id="contact" style={{ height: '300px' }}>
  166. Contact me
  167. </h1>
  168. </div>
  169. </div>
  170. );
  171. export const TargetOffset = () => (
  172. <div>
  173. <Anchor
  174. style={{ position: 'absolute', right: 0, top: 100 }}
  175. targetOffset={100}
  176. scrollMotion={true}
  177. getContainer={getContainer}
  178. >
  179. <Link href="#welcome" title="welcome" />
  180. <Link href="#api" title="api too much to show">
  181. <Link href="#docs" title="docs">
  182. <Link href="#doc1" title="doc1" />
  183. <Link href="#doc2" title="doc2" />
  184. </Link>
  185. </Link>
  186. <Link href="#contact" title="contact" />
  187. </Anchor>
  188. <div id="box" style={{ height: '500px', overflow: 'scroll', border: '1px solid #eee' }}>
  189. <div style={{ position: 'fixed', border: '1px solid red', height: 100, width: '100%' }}>
  190. 这是 fixed 的一段话
  191. </div>
  192. <h1 style={{ height: '300px' }}>whatever</h1>
  193. <h1 id="welcome" style={{ height: '300px' }}>
  194. Welcome
  195. </h1>
  196. <h1 id="api" style={{ height: '300px' }}>
  197. API
  198. </h1>
  199. <h2 id="docs" style={{ height: '200px' }}>
  200. Docs
  201. </h2>
  202. <h3 id="doc1" style={{ height: '100px' }}>
  203. Doc1
  204. </h3>
  205. <h3 id="doc2" style={{ height: '100px' }}>
  206. Doc2
  207. </h3>
  208. <h1 id="contact" style={{ height: '300px' }}>
  209. Contact me
  210. </h1>
  211. </div>
  212. </div>
  213. );
  214. export const FixContainerScrollBug1158 = () => (
  215. <div style={{ height: '120vh' }}>
  216. <div style={{ width: 500, height: 500, position: 'relative', overflowY: 'scroll' }}>
  217. <Anchor
  218. style={{ position: 'absolute', right: 0 }}
  219. scrollMotion={true}
  220. getContainer={getContainer}
  221. >
  222. <Link href="#welcome" title="welcome" />
  223. <Link href="#api" title="api too much to show">
  224. <Link href="#docs" title="docs">
  225. <Link href="#doc1" title="doc1" />
  226. <Link href="#doc2" title="doc2" />
  227. </Link>
  228. </Link>
  229. <Link href="#contact" title="contact" />
  230. </Anchor>
  231. <div id="box" style={{ height: 700, overflowY: 'scroll' }}>
  232. <h1 id="welcome" style={{ height: '300px' }}>
  233. Welcome
  234. </h1>
  235. <h1 id="api" style={{ height: '300px' }}>
  236. API
  237. </h1>
  238. <h2 id="docs" style={{ height: '200px' }}>
  239. Docs
  240. </h2>
  241. <h3 id="doc1" style={{ height: '100px' }}>
  242. Doc1
  243. </h3>
  244. <h3 id="doc2" style={{ height: '100px' }}>
  245. Doc2
  246. </h3>
  247. <h1 id="contact" style={{ height: '300px' }}>
  248. Contact me
  249. </h1>
  250. </div>
  251. </div>
  252. </div>
  253. );
  254. export const AutoCollapse = () => {
  255. const [href, setHref] = useState('#设计语言');
  256. return (
  257. <div>
  258. <Anchor autoCollapse>
  259. <Anchor.Link href="#动态展示" title="1. 动态展示">
  260. <Anchor.Link href="#组件" title="1.1 组件">
  261. <Anchor.Link href="#头像" title="1.1.1 Avatar" />
  262. <Anchor.Link href="#按钮" title="1.1.2 Button" />
  263. <Anchor.Link href="#图标" title="1.1.3 Icon" />
  264. </Anchor.Link>
  265. <Anchor.Link href="#物料" title="1.2 物料" />
  266. <Anchor.Link href="#主题商店" title="1.3 主题商店" />
  267. </Anchor.Link>
  268. <Anchor.Link href={href} title="2. 设计语言" />
  269. </Anchor>
  270. <Button onClick={()=>{console.log('sdf');setHref('#我改变啦')}}>setHref</Button>
  271. </div>
  272. )
  273. };