resizable.stories.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. import React, { createRef, useState } from 'react';
  2. import { Resizable } from '../../index';
  3. import { Toast, Button } from '@douyinfe/semi-ui'
  4. export default {
  5. title: 'Resizable'
  6. }
  7. import { ResizeItem, ResizeHandler, ResizeGroup } from '../../index'
  8. export const Group_layout = () => {
  9. const [text, setText] = useState('test')
  10. const opts_1 = {
  11. content: 'resize start',
  12. duration: 1,
  13. stack: true,
  14. };
  15. const opts = {
  16. content: 'resize end',
  17. duration: 1,
  18. stack: true,
  19. };
  20. return (
  21. <div style={{ width: '1000px', height: '600px' }}>
  22. <ResizeGroup direction='vertical'>
  23. <ResizeItem
  24. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)' }}
  25. defaultSize={"20%"}
  26. onChange={() => { setText('resizing') }}
  27. onResizeStart={() => {{Toast.info(opts_1)}}}
  28. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  29. >
  30. <div style={{ marginLeft: '20%' }}>
  31. {'header'}
  32. </div>
  33. </ResizeItem>
  34. <ResizeHandler></ResizeHandler>
  35. <ResizeItem
  36. defaultSize={"80%"}
  37. onChange={() => { setText('resizing') }}
  38. >
  39. <ResizeGroup direction='horizontal'>
  40. <ResizeItem
  41. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
  42. defaultSize={"20%"}
  43. onChange={() => { setText('resizing') }}
  44. onResizeStart={() => {Toast.info(opts_1)}}
  45. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  46. >
  47. <div style={{ marginLeft: '20%' }}>
  48. {'tab'}
  49. </div>
  50. </ResizeItem>
  51. <ResizeHandler></ResizeHandler>
  52. <ResizeItem
  53. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
  54. onChange={() => { setText('resizing') }}
  55. >
  56. <div style={{ marginLeft: '20%' }}>
  57. {text}
  58. </div>
  59. </ResizeItem>
  60. <ResizeHandler></ResizeHandler>
  61. <ResizeItem
  62. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
  63. // defaultSize={"90%"}
  64. onChange={() => { setText('resizing') }}
  65. >
  66. <div style={{ marginLeft: '20%' }}>
  67. {text}
  68. </div>
  69. </ResizeItem>
  70. </ResizeGroup>
  71. </ResizeItem>
  72. </ResizeGroup>
  73. </div>
  74. );
  75. }
  76. export const Group_nested = () => {
  77. const [text, setText] = useState('test')
  78. const opts_1 = {
  79. content: 'resize start',
  80. duration: 1,
  81. stack: true,
  82. };
  83. const opts = {
  84. content: 'resize end',
  85. duration: 1,
  86. stack: true,
  87. };
  88. return (
  89. <div style={{ width: '500px', height: '600px' }}>
  90. <ResizeGroup direction='vertical'>
  91. <ResizeItem
  92. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  93. defaultSize={"20%"}
  94. onChange={() => { setText('resizing') }}
  95. onResizeStart={() => {{Toast.info(opts_1)}}}
  96. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  97. >
  98. <div style={{ marginLeft: '20%' }}>
  99. {text}
  100. </div>
  101. </ResizeItem>
  102. <ResizeHandler><div>{'hahaha, man'}</div></ResizeHandler>
  103. <ResizeItem
  104. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  105. defaultSize={'20%'}
  106. onChange={() => { setText('resizing') }}
  107. >
  108. <ResizeGroup direction='horizontal'>
  109. <ResizeItem
  110. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid',
  111. padding: '10px' }}
  112. defaultSize={"25%"}
  113. onChange={() => { setText('resizing') }}
  114. onResizeStart={() => {Toast.info(opts_1)}}
  115. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  116. >
  117. <div style={{ marginLeft: '20%' }}>
  118. {text}
  119. </div>
  120. </ResizeItem>
  121. <ResizeHandler></ResizeHandler>
  122. <ResizeItem
  123. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  124. defaultSize={"25%"}
  125. onChange={() => { setText('resizing') }}
  126. >
  127. <div style={{ marginLeft: '20%' }}>
  128. {text}
  129. </div>
  130. </ResizeItem>
  131. <ResizeHandler></ResizeHandler>
  132. <ResizeItem
  133. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  134. onChange={() => { setText('resizing') }}
  135. >
  136. <div style={{ marginLeft: '20%' }}>
  137. {text}
  138. </div>
  139. </ResizeItem>
  140. </ResizeGroup>
  141. </ResizeItem>
  142. <ResizeHandler></ResizeHandler>
  143. <ResizeItem
  144. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  145. defaultSize={"20%"}
  146. onChange={() => { setText('resizing') }}
  147. >
  148. <div style={{ marginLeft: '20%' }}>
  149. {text}
  150. </div>
  151. </ResizeItem>
  152. </ResizeGroup>
  153. </div>
  154. );
  155. }
  156. export const Group_vertical = () => {
  157. const [text, setText] = useState('test')
  158. const opts_1 = {
  159. content: 'resize start',
  160. duration: 1,
  161. stack: true,
  162. };
  163. const opts = {
  164. content: 'resize end',
  165. duration: 1,
  166. stack: true,
  167. };
  168. return (
  169. <div style={{ width: '500px', height: '600px' }}>
  170. <ResizeGroup direction='vertical'>
  171. <ResizeItem
  172. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  173. defaultSize={"20%"}
  174. min={'10%'}
  175. max={'30%'}
  176. onChange={() => { setText('resizing') }}
  177. onResizeStart={() => {Toast.info(opts_1)}}
  178. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  179. >
  180. <div style={{ marginLeft: '20%' }}>
  181. {text + " min:10% max:30%"}
  182. </div>
  183. </ResizeItem>
  184. <ResizeHandler></ResizeHandler>
  185. <ResizeItem
  186. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  187. defaultSize={'20%'}
  188. onChange={() => { setText('resizing') }}
  189. >
  190. <div style={{ marginLeft: '20%' }}>
  191. {text}
  192. </div>
  193. </ResizeItem>
  194. <ResizeHandler></ResizeHandler>
  195. <ResizeItem
  196. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  197. defaultSize={'20%'}
  198. onChange={() => { setText('resizing') }}
  199. >
  200. <div style={{ marginLeft: '20%' }}>
  201. {text}
  202. </div>
  203. </ResizeItem>
  204. <ResizeHandler></ResizeHandler>
  205. <ResizeItem
  206. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  207. onChange={() => { setText('resizing') }}
  208. >
  209. <div style={{ marginLeft: '20%' }}>
  210. {text}
  211. </div>
  212. </ResizeItem>
  213. </ResizeGroup>
  214. </div>
  215. );
  216. }
  217. export const Group_horizontal = () => {
  218. const [text, setText] = useState('test')
  219. return (
  220. <div style={{ width: '500px', height: '100px' }}>
  221. <ResizeGroup direction='horizontal'>
  222. <ResizeItem
  223. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
  224. defaultSize={'20%'}
  225. min={'10%'}
  226. onChange={() => { setText('resizing') }}
  227. onResizeEnd={() => { setText('test') }}
  228. >
  229. <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
  230. {text + " min:10%"}
  231. </div>
  232. </ResizeItem>
  233. <ResizeHandler></ResizeHandler>
  234. <ResizeItem
  235. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
  236. defaultSize={'20%'}
  237. min={'10%'}
  238. max={'30%'}
  239. onChange={() => { setText('resizing') }}
  240. >
  241. <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
  242. {text + " min:10% max:30%"}
  243. </div>
  244. </ResizeItem>
  245. <ResizeHandler></ResizeHandler>
  246. <ResizeItem
  247. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
  248. defaultSize={'30%'}
  249. onChange={() => { setText('resizing') }}
  250. >
  251. <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
  252. {text}
  253. </div>
  254. </ResizeItem>
  255. </ResizeGroup>
  256. </div>
  257. );
  258. }
  259. export const Single_defaultSize = () => {
  260. const [text, setText] = useState('test')
  261. const opts_1 = {
  262. content: 'resize start',
  263. duration: 1,
  264. stack: true,
  265. };
  266. const opts = {
  267. content: 'resize end',
  268. duration: 1,
  269. stack: true,
  270. };
  271. return (
  272. <div style={{ width: '500px', height: '60%' }}>
  273. <Resizable
  274. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  275. defaultSize={{
  276. width: '60%',
  277. height: 300,
  278. }}
  279. onChange={(e, d, s) => { setText('resizing'); }}
  280. onResizeStart={() => {Toast.info(opts_1)}}
  281. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  282. >
  283. <div style={{ marginLeft: '20%' }}>
  284. {text}
  285. </div>
  286. </Resizable>
  287. </div>
  288. );
  289. }
  290. export const Single_Enabel = () => {
  291. const [b, setB] = useState(false)
  292. return (
  293. <div style={{ width: '500px', height: '60%' }}>
  294. <Button onClick={() => (setB(!b))}>{'left:' + b}</Button>
  295. <Resizable
  296. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  297. enable={{
  298. left: b
  299. }}
  300. defaultSize={{
  301. width: 200,
  302. height: 200,
  303. }}
  304. >
  305. <div style={{ marginLeft: '20%' }}>
  306. test
  307. </div>
  308. </Resizable>
  309. </div>
  310. );
  311. }
  312. export const Single_ratio = () => {
  313. return (
  314. <div style={{ width: '500px', height: '60%' }}>
  315. <Resizable
  316. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  317. defaultSize={{
  318. width: '60%',
  319. height: 300,
  320. }}
  321. ratio={2}
  322. >
  323. <div style={{ marginLeft: '20%' }}>
  324. test
  325. </div>
  326. </Resizable>
  327. </div>
  328. );
  329. }
  330. export const Single_lock_aspect = () => {
  331. const aspectRatio = 16 / 9
  332. return (
  333. <div style={{ width: '500px', height: '60%' }}>
  334. <Resizable
  335. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  336. defaultSize={{
  337. width: '60%',
  338. height: 300,
  339. }}
  340. lockAspectRatio
  341. >
  342. <div style={{ marginLeft: '20%' }}>
  343. lock
  344. </div>
  345. </Resizable>
  346. <Resizable
  347. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  348. defaultSize={{
  349. width: 200,
  350. height: 1800 / 16,
  351. }}
  352. lockAspectRatio={16 / 9}
  353. >
  354. <div style={{ marginLeft: '20%' }}>
  355. 16 / 9
  356. </div>
  357. </Resizable>
  358. </div>
  359. );
  360. }
  361. export const singleMaxMin = () => {
  362. return (
  363. <div style={{ width: '500px', height: '60%' }}>
  364. <Resizable
  365. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  366. maxWidth={500}
  367. maxHeight={600}
  368. minWidth={50}
  369. minHeight={50}
  370. defaultSize={{
  371. width: 200,
  372. height: 300,
  373. }}
  374. >
  375. <div style={{ marginLeft: '20%' }}>
  376. width在50到500之间,height在50到600之间
  377. </div>
  378. </Resizable>
  379. </div>
  380. )
  381. }
  382. export const Single_change = () => {
  383. const [size, setSize] = useState({ width: 200, height: 300 });
  384. const ref = createRef()
  385. const onChange = (() => {
  386. let realSize = { width: size.width + 10, height: size.height + 10 };
  387. setSize(realSize);
  388. })
  389. return (
  390. <div style={{ width: '500px', height: '60%' }}>
  391. <Button onClick={onChange}>set += 10</Button>
  392. <Resizable
  393. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  394. defaultSize={{
  395. width: '60%',
  396. height: 300,
  397. }}
  398. onChange={(s) => { setSize(s); }}
  399. size={size}
  400. >
  401. <div style={{ marginLeft: '20%' }}>
  402. 受控
  403. </div>
  404. </Resizable>
  405. </div>
  406. );
  407. }
  408. export const Single_scale = () => {
  409. return (
  410. <div style={{ width: '500px', height: '60%', transform: 'scale(0.5)', transformOrigin: '0 0' }}>
  411. <Resizable
  412. style={{ marginLeft: '20%', backgroundColor: 'light blue', border: 'var(--semi-color-border) 5px solid' }}
  413. defaultSize={{
  414. width: '60%',
  415. height: 300,
  416. }}
  417. scale={0.5}
  418. >
  419. <div style={{ marginLeft: '20%' }}>
  420. scale 0.5
  421. </div>
  422. </Resizable>
  423. </div>
  424. );
  425. }
  426. export const Single_bound = () => {
  427. return (
  428. <div style={{ width: '500px', height: '600px', border: 'var(--semi-color-border) 5px solid' }}>
  429. <Resizable
  430. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  431. defaultSize={{
  432. width: '60%',
  433. height: 300,
  434. }}
  435. boundElement={'parent'}
  436. >
  437. <div style={{ marginLeft: '20%' }}>
  438. 受控
  439. </div>
  440. </Resizable>
  441. </div>
  442. );
  443. }
  444. export const Single_handler = () => {
  445. return (
  446. <div style={{ width: '500px', height: '60%' }}>
  447. <Resizable
  448. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  449. defaultSize={{
  450. width: '60%',
  451. height: 300,
  452. }}
  453. handleNode={{
  454. bottomRight: <Button type="primary">hi</Button>
  455. }}
  456. handleStyle={{
  457. bottomRight: {
  458. width: '100px',
  459. height: '100px',
  460. backgroundColor: 'red'
  461. }
  462. }}
  463. >
  464. <div style={{ marginLeft: '20%' }}>
  465. bottomRight
  466. </div>
  467. </Resizable>
  468. </div>
  469. );
  470. }
  471. export const Single_grid = () => {
  472. return (
  473. <div style={{ width: '500px', height: '60%' }}>
  474. <Resizable
  475. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  476. defaultSize={{
  477. width: '60%',
  478. height: 300,
  479. }}
  480. grid={[100, 100]}
  481. snapGap={20}
  482. >
  483. <div style={{ marginLeft: '20%' }}>
  484. snap
  485. </div>
  486. </Resizable>
  487. </div >
  488. );
  489. }