anchor.stories.js 8.1 KB

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