resizable.stories.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. import React, { createRef, useState } from 'react';
  2. import { Resizable } from '../../index';
  3. import { Toast, Button, Tag } 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: '100%', height: '100px' }}>
  221. <ResizeGroup direction='horizontal'>
  222. <ResizeItem
  223. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
  224. defaultSize={2}
  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={'600px'}
  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. <ResizeHandler></ResizeHandler>
  256. <ResizeItem
  257. style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
  258. defaultSize={1.3}
  259. onChange={() => { setText('resizing') }}
  260. >
  261. <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
  262. {text}
  263. </div>
  264. </ResizeItem>
  265. </ResizeGroup>
  266. </div>
  267. );
  268. }
  269. export const Single_defaultSize = () => {
  270. const [text, setText] = useState('test')
  271. const opts_1 = {
  272. content: 'resize start',
  273. duration: 1,
  274. stack: true,
  275. };
  276. const opts = {
  277. content: 'resize end',
  278. duration: 1,
  279. stack: true,
  280. };
  281. return (
  282. <div style={{ width: '500px', height: '60%' }}>
  283. <Resizable
  284. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  285. defaultSize={{
  286. width: '60%',
  287. height: 300,
  288. }}
  289. onChange={(e, d, s) => { setText('resizing'); }}
  290. onResizeStart={() => {Toast.info(opts_1)}}
  291. onResizeEnd={() => { Toast.info(opts); setText('test') }}
  292. >
  293. <div style={{ marginLeft: '20%' }}>
  294. <Tag>{text}</Tag>
  295. </div>
  296. </Resizable>
  297. </div>
  298. );
  299. }
  300. export const Single_Enabel = () => {
  301. const [b, setB] = useState(false)
  302. return (
  303. <div style={{ width: '500px', height: '60%' }}>
  304. <Button onClick={() => (setB(!b))}>{'left:' + b}</Button>
  305. <Resizable
  306. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  307. enable={{
  308. left: b
  309. }}
  310. defaultSize={{
  311. width: 200,
  312. height: 200,
  313. }}
  314. >
  315. <div style={{ marginLeft: '20%' }}>
  316. test
  317. </div>
  318. </Resizable>
  319. </div>
  320. );
  321. }
  322. export const Single_ratio = () => {
  323. return (
  324. <div style={{ width: '500px', height: '60%' }}>
  325. <Resizable
  326. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  327. defaultSize={{
  328. width: '60%',
  329. height: 300,
  330. }}
  331. ratio={2}
  332. >
  333. <div style={{ marginLeft: '20%' }}>
  334. test
  335. </div>
  336. </Resizable>
  337. </div>
  338. );
  339. }
  340. export const Single_lock_aspect = () => {
  341. const aspectRatio = 16 / 9
  342. return (
  343. <div style={{ width: '500px', height: '60%' }}>
  344. <Resizable
  345. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  346. defaultSize={{
  347. width: '60%',
  348. height: 300,
  349. }}
  350. lockAspectRatio
  351. >
  352. <div style={{ marginLeft: '20%' }}>
  353. lock
  354. </div>
  355. </Resizable>
  356. <Resizable
  357. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  358. defaultSize={{
  359. width: 200,
  360. height: 1800 / 16,
  361. }}
  362. lockAspectRatio={16 / 9}
  363. >
  364. <div style={{ marginLeft: '20%' }}>
  365. 16 / 9
  366. </div>
  367. </Resizable>
  368. </div>
  369. );
  370. }
  371. export const singleMaxMin = () => {
  372. return (
  373. <div style={{ width: '500px', height: '60%' }}>
  374. <Resizable
  375. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  376. maxWidth={500}
  377. maxHeight={600}
  378. minWidth={50}
  379. minHeight={50}
  380. defaultSize={{
  381. width: 200,
  382. height: 300,
  383. }}
  384. >
  385. <div style={{ marginLeft: '20%' }}>
  386. width在50到500之间,height在50到600之间
  387. </div>
  388. </Resizable>
  389. </div>
  390. )
  391. }
  392. export const Single_change = () => {
  393. const [size, setSize] = useState({ width: 200, height: 300 });
  394. const ref = createRef()
  395. const onChange = (() => {
  396. let realSize = { width: size.width + 10, height: size.height + 10 };
  397. setSize(realSize);
  398. })
  399. return (
  400. <div style={{ width: '500px', height: '60%' }}>
  401. <Button onClick={onChange}>set += 10</Button>
  402. <Resizable
  403. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  404. defaultSize={{
  405. width: '60%',
  406. height: 300,
  407. }}
  408. onChange={(s) => { setSize(s); }}
  409. size={size}
  410. >
  411. <div style={{ marginLeft: '20%' }}>
  412. 受控
  413. </div>
  414. </Resizable>
  415. </div>
  416. );
  417. }
  418. export const Single_scale = () => {
  419. return (
  420. <div style={{ width: '500px', height: '60%', transform: 'scale(0.5)', transformOrigin: '0 0' }}>
  421. <Resizable
  422. style={{ marginLeft: '20%', backgroundColor: 'light blue', border: 'var(--semi-color-border) 5px solid' }}
  423. defaultSize={{
  424. width: '60%',
  425. height: 300,
  426. }}
  427. scale={0.5}
  428. >
  429. <div style={{ marginLeft: '20%' }}>
  430. scale 0.5
  431. </div>
  432. </Resizable>
  433. </div>
  434. );
  435. }
  436. export const Single_bound = () => {
  437. return (
  438. <div style={{ width: '500px', height: '600px', border: 'var(--semi-color-border) 5px solid' }}>
  439. <Resizable
  440. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  441. defaultSize={{
  442. width: '60%',
  443. height: 300,
  444. }}
  445. boundElement={'parent'}
  446. >
  447. <div style={{ marginLeft: '20%' }}>
  448. 受控
  449. </div>
  450. </Resizable>
  451. </div>
  452. );
  453. }
  454. export const Single_handler = () => {
  455. return (
  456. <div style={{ width: '500px', height: '60%' }}>
  457. <Resizable
  458. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  459. defaultSize={{
  460. width: '60%',
  461. height: 300,
  462. }}
  463. handleNode={{
  464. bottomRight: <Button type="primary">hi</Button>
  465. }}
  466. handleStyle={{
  467. bottomRight: {
  468. width: '100px',
  469. height: '100px',
  470. backgroundColor: 'red'
  471. }
  472. }}
  473. >
  474. <div style={{ marginLeft: '20%' }}>
  475. bottomRight
  476. </div>
  477. </Resizable>
  478. </div>
  479. );
  480. }
  481. export const Single_grid = () => {
  482. return (
  483. <div style={{ width: '500px', height: '60%' }}>
  484. <Resizable
  485. style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
  486. defaultSize={{
  487. width: '60%',
  488. height: 300,
  489. }}
  490. grid={[100, 100]}
  491. snapGap={20}
  492. >
  493. <div style={{ marginLeft: '20%' }}>
  494. snap
  495. </div>
  496. </Resizable>
  497. </div >
  498. );
  499. }