--- title: Resizable description: "`Resizable`は、キーボードのサポートを備えたサイズ変更可能なレイアウトコンポーネントです。" links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/resizable/resizable.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/resizable - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-resizable--basic --- ```tsx One Two ``` ## 使い方 ```tsx import { Resizable } from "@yamada-ui/react" ``` ```tsx import { Resizable } from "@/components/ui" ``` ```tsx import { Resizable } from "@workspaces/ui" ``` ```tsx ``` ### バリアントを変更する ```tsx {(variant) => ( {toTitleCase(variant)} Two )} ``` ### カラースキームを変更する ```tsx {(colorScheme) => ( One Two )} ``` ### 方向を変更する 方向を変更する場合は、`orientation`に`"horizontal"`または`"vertical"`を設定します。デフォルトでは、`"horizontal"`が設定されています。 ```tsx {(orientation) => ( One Two )} ``` ### デフォルトサイズを使う デフォルトサイズを使う場合は、`Resizable.Item`の`defaultSize`に数値(割合)を設定します。 ```tsx One Two ``` ### 最小・最大サイズを使う 最小・最大サイズを使う場合は、`Resizable.Item`の`minSize`と`maxSize`に数値(割合)を設定します。 ```tsx One Two ``` ### キーボードステップを使う キーボードステップを使う場合は、`keyboardStep`に数値(割合)を設定します。 ```tsx One Two ``` ### 折りたたみを可能にする 折りたたみを可能にする場合は、`collapsible`を`true`に設定します。 `minSize`は折りたたむ前の数値を設定し、`collapsedSize`は折りたたんだ状態の数値を設定します。 ```tsx { console.log("collapsed item") }} onExpand={() => { console.log("expand item") }} > One Two { console.log("collapsed item") }} onExpand={() => { console.log("expand item") }} > One Two ``` ### アイコンを追加する アイコンを追加する場合は、`Resizable.Trigger`の`icon`に`ReactNode`を設定します。 ```tsx One } /> Two One } /> Two ``` ### ネストした構造 ```tsx Left Top Bottom Top Left Right ``` ### 無効にする 無効にする場合は、`disabled`を`true`に設定します。 ```tsx One Two Three ``` ```tsx One Two Three ``` ### リサイズイベントをハンドルする リサイズイベントをハンドルする場合は、`onResize`を使用します。`onResize`は、変更したサイズと前回のサイズを提供します。 ```tsx { console.log("resized", size, prevSize) }} > One Two ``` ### ローカルストレージに値を保存する ローカルストレージに値を保存する場合は、`storageKey`にローカルストレージに保存するキーを設定します。 :::warning ローカルストレージなどに値を保存する場合は、保存された各値と`Resizable.Item`を関連付けするために`Resizable.Item`に`id`を設定する必要があります。 ::: :::warning もし、`Resizable.Item`を動的にマウントさせる場合は、`order`に数値を設定してアイテムの並び順を固定化する必要があります。 ::: ```tsx const [showLeft, showLeftControls] = useBoolean(true) const [showRight, showRightControls] = useBoolean(true) return ( One Two {showLeft ? ( <> Left ) : null} Middle {showRight ? ( <> Right ) : null} ) ``` ### Cookieに値を保存する `cookies`に値を保存する場合は、`storage`に`getItem`と`setItem`を設定します。 :::note Next.jsなどのサーバー側でレンダリングされるサイトに有効なアプローチです。 ::: ```tsx preview functional client const storage = useMemo( () => ({ getItem: (key) => { const match = document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`)) return match ? match[2] : null }, setItem: (key, value) => { document.cookie = `${key}=${value}; max-age=31536000; path=/` }, }), [], ) return ( One Two ) ``` ### 制御する ```tsx const controlRef = useRef(null) return ( One Two ) ``` ## Props ### Resizable.Root | Prop | Default | Type | Description | | -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `variant` | `"border"` | `"border" \| "plain" \| "spacer"` | The variant of the component. | | `controlRef` | - | `RefObject` | Ref of the resizable item callback. | | `disabled` | - | `boolean` | If `true`, the resizable trigger will be disabled. | | `groupProps` | - | `ResizableGroupProps` | Props for resizable component. | | `keyboardStep` | `10` | `number` | Unit to resize by keyboard operation. | | `onLayout` | - | `PanelGroupOnLayout` | The callback invoked when resizable items are resized. | | `orientation` | `"horizontal"` | `"horizontal" \| "vertical"` | The orientation of the resizable. | | `rootRef` | - | `ForwardedRef` | Ref for resizable root element. | | `storage` | - | `PanelGroupStorage` | A callback that gets and sets a value in custom storage. | | `storageKey` | - | `string` | Key of value saved in storage. By default, it is saved to `local storage`. | ### Resizable.Item | Prop | Default | Type | Description | | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | | `as` | - | `keyof HTMLElementTagNameMap` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `collapsedSize` | - | `number` | The collapsed size of the resizable item. | | `collapsible` | `false` | `boolean` | If `true`, the resizable item can be collapsed. | | `controlRef` | - | `RefObject` | Ref of the resizable item callback. | | `defaultSize` | - | `number` | The initial size of the resizable item. | | `maxSize` | - | `number` | The maximum allowed value of the resizable item. | | `minSize` | - | `number` | The minimum allowed value of the resizable item. | | `onCollapse` | - | `() => void` | The callback invoked when resizable item are collapsed. | | `onExpand` | - | `() => void` | The callback invoked when resizable item are expanded. | | `onResize` | - | `(size: number, prevSize: number \| undefined) => void` | The callback invoked when resizable item are resized. | | `order` | - | `number` | Order for the resizable item. | ### Resizable.Trigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | | `as` | - | `keyof HTMLElementTagNameMap` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `disabled` | `false` | `boolean` | If `true`, the resizable trigger will be disabled. | | `icon` | - | `ReactElement` | The resizable trigger icon to use. | | `iconProps` | - | `HTMLStyledProps` | Props for resizable trigger icon component. | | `onDragging` | - | `(dragging: boolean) => void` | The callback invoked when resizable trigger are dragged. | ## アクセシビリティ 現在、v2の移行に伴い、このセクションは更新中です。