| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- import React, { createRef, useState } from 'react';
- import { Resizable } from '../../index';
- import { Toast, Button, Tag } from '@douyinfe/semi-ui'
- export default {
- title: 'Resizable'
- }
- import { ResizeItem, ResizeHandler, ResizeGroup } from '../../index'
- export const Group_layout = () => {
- const [text, setText] = useState('test')
- const opts_1 = {
- content: 'resize start',
- duration: 1,
- stack: true,
- };
- const opts = {
- content: 'resize end',
- duration: 1,
- stack: true,
- };
- return (
- <div style={{ width: '1000px', height: '600px' }}>
- <ResizeGroup direction='vertical'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)' }}
- defaultSize={"20%"}
- // onChange={() => { setText('resizing') }}
- // onResizeStart={() => {{Toast.info(opts_1)}}}
- // onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {'header'}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- defaultSize={"80%"}
- // onChange={() => { setText('resizing') }}
- >
- <ResizeGroup direction='horizontal'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
- defaultSize={"20%"}
- // onChange={() => { setText('resizing') }}
- // onResizeStart={() => {Toast.info(opts_1)}}
- // onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {'tab'}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
- // onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 1px solid' }}
- // defaultSize={"90%"}
- // onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
-
- </ResizeGroup>
- </ResizeItem>
- </ResizeGroup>
- </div>
- );
- }
- export const Group_nested = () => {
- const [text, setText] = useState('test')
- const opts_1 = {
- content: 'resize start',
- duration: 1,
- stack: true,
- };
- const opts = {
- content: 'resize end',
- duration: 1,
- stack: true,
- };
- return (
- <div style={{ width: '500px', height: '600px' }}>
- <ResizeGroup direction='vertical'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={"20%"}
- onChange={() => { setText('resizing') }}
- onResizeStart={() => {{Toast.info(opts_1)}}}
- onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler><div>{'hahaha, man'}</div></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={'20%'}
- onChange={() => { setText('resizing') }}
- >
- <ResizeGroup direction='horizontal'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid',
- padding: '10px' }}
- defaultSize={"25%"}
- onChange={() => { setText('resizing') }}
- onResizeStart={() => {Toast.info(opts_1)}}
- onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={"25%"}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- </ResizeGroup>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={"20%"}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- </ResizeGroup>
- </div>
- );
- }
- export const Group_vertical = () => {
- const [text, setText] = useState('test')
- const opts_1 = {
- content: 'resize start',
- duration: 1,
- stack: true,
- };
- const opts = {
- content: 'resize end',
- duration: 1,
- stack: true,
- };
- return (
- <div style={{ width: '500px', height: '600px' }}>
- <ResizeGroup direction='vertical'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={"20%"}
- min={'10%'}
- max={'30%'}
- onChange={() => { setText('resizing') }}
- onResizeStart={() => {Toast.info(opts_1)}}
- onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text + " min:10% max:30%"}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={'20%'}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={'20%'}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
-
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%' }}>
- {text}
- </div>
- </ResizeItem>
- </ResizeGroup>
- </div>
- );
- }
- export const Group_horizontal = () => {
- const [text, setText] = useState('test')
- return (
- <div style={{ width: '100%', height: '100px' }}>
- <ResizeGroup direction='horizontal'>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
- defaultSize={2}
- min={'10%'}
- onChange={() => { setText('resizing') }}
- onResizeEnd={() => { setText('test') }}
- >
- <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
- {text + " min:10%"}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
- defaultSize={'20%'}
- min={'10%'}
- max={'30%'}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
- {text + " min:10% max:30%"}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
- defaultSize={'600px'}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
- {text}
- </div>
- </ResizeItem>
- <ResizeHandler></ResizeHandler>
- <ResizeItem
- style={{ backgroundColor: 'rgba(var(--semi-grey-1), 1)', }}
- defaultSize={1.3}
- onChange={() => { setText('resizing') }}
- >
- <div style={{ marginLeft: '20%', border: 'var(--semi-color-border) solid 1px', padding:'5px' }}>
- {text}
- </div>
- </ResizeItem>
- </ResizeGroup>
- </div>
- );
- }
- export const Single_defaultSize = () => {
- const [text, setText] = useState('test')
- const opts_1 = {
- content: 'resize start',
- duration: 1,
- stack: true,
- };
- const opts = {
- content: 'resize end',
- duration: 1,
- stack: true,
- };
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- onChange={(e, d, s) => { setText('resizing'); }}
- onResizeStart={() => {Toast.info(opts_1)}}
- onResizeEnd={() => { Toast.info(opts); setText('test') }}
- >
- <div style={{ marginLeft: '20%' }}>
- <Tag>{text}</Tag>
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_Enabel = () => {
- const [b, setB] = useState(false)
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Button onClick={() => (setB(!b))}>{'left:' + b}</Button>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- enable={{
- left: b
- }}
- defaultSize={{
- width: 200,
- height: 200,
- }}
- >
- <div style={{ marginLeft: '20%' }}>
- test
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_ratio = () => {
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- ratio={2}
- >
- <div style={{ marginLeft: '20%' }}>
- test
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_lock_aspect = () => {
- const aspectRatio = 16 / 9
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- lockAspectRatio
- >
- <div style={{ marginLeft: '20%' }}>
- lock
- </div>
- </Resizable>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: 200,
- height: 1800 / 16,
- }}
- lockAspectRatio={16 / 9}
- >
- <div style={{ marginLeft: '20%' }}>
- 16 / 9
- </div>
- </Resizable>
- </div>
- );
- }
- export const singleMaxMin = () => {
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- maxWidth={500}
- maxHeight={600}
- minWidth={50}
- minHeight={50}
- defaultSize={{
- width: 200,
- height: 300,
- }}
- >
- <div style={{ marginLeft: '20%' }}>
- width在50到500之间,height在50到600之间
- </div>
- </Resizable>
- </div>
- )
- }
- export const Single_change = () => {
- const [size, setSize] = useState({ width: 200, height: 300 });
- const ref = createRef()
- const onChange = (() => {
- let realSize = { width: size.width + 10, height: size.height + 10 };
- setSize(realSize);
- })
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Button onClick={onChange}>set += 10</Button>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- onChange={(s) => { setSize(s); }}
- size={size}
- >
- <div style={{ marginLeft: '20%' }}>
- 受控
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_scale = () => {
- return (
- <div style={{ width: '500px', height: '60%', transform: 'scale(0.5)', transformOrigin: '0 0' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'light blue', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- scale={0.5}
- >
- <div style={{ marginLeft: '20%' }}>
- scale 0.5
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_bound = () => {
- return (
- <div style={{ width: '500px', height: '600px', border: 'var(--semi-color-border) 5px solid' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- boundElement={'parent'}
- >
- <div style={{ marginLeft: '20%' }}>
- 受控
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_handler = () => {
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- handleNode={{
- bottomRight: <Button type="primary">hi</Button>
- }}
- handleStyle={{
- bottomRight: {
- width: '100px',
- height: '100px',
- backgroundColor: 'red'
- }
- }}
- >
- <div style={{ marginLeft: '20%' }}>
- bottomRight
- </div>
- </Resizable>
- </div>
- );
- }
- export const Single_grid = () => {
- return (
- <div style={{ width: '500px', height: '60%' }}>
- <Resizable
- style={{ marginLeft: '20%', backgroundColor: 'rgba(var(--semi-grey-1), 1)', border: 'var(--semi-color-border) 5px solid' }}
- defaultSize={{
- width: '60%',
- height: 300,
- }}
- grid={[100, 100]}
- snapGap={20}
- >
- <div style={{ marginLeft: '20%' }}>
- snap
- </div>
- </Resizable>
- </div >
- );
- }
|