react-resizable vs react-grid-layout vs react-splitter-layout
Web開発におけるレイアウト管理ライブラリ
react-resizablereact-grid-layoutreact-splitter-layout類似パッケージ:
Web開発におけるレイアウト管理ライブラリ

これらのライブラリは、Reactアプリケーションにおけるレイアウトの管理を容易にするために設計されています。特に、ユーザーインターフェースのダイナミックな配置やサイズ変更をサポートし、開発者が直感的に操作できるようにします。これにより、より柔軟でインタラクティブなウェブアプリケーションの構築が可能になります。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-resizable1,715,8162,549116 kB783年前MIT
react-grid-layout1,248,66821,748508 kB2515ヶ月前MIT
react-splitter-layout15,369431-387年前MIT
機能比較: react-resizable vs react-grid-layout vs react-splitter-layout

レイアウト管理

  • react-resizable:

    react-resizableは、個々のコンポーネントのサイズを変更するためのシンプルなAPIを提供します。ユーザーはマウスでサイズを調整でき、動的なUIを構築するのに役立ちます。

  • react-grid-layout:

    react-grid-layoutは、グリッドベースのレイアウトを提供し、コンポーネントをドラッグ&ドロップで配置できます。レスポンシブデザインをサポートし、異なる画面サイズに応じてレイアウトを調整できます。

  • react-splitter-layout:

    react-splitter-layoutは、複数のコンポーネントを分割して表示するためのレイアウトを提供します。ユーザーは分割バーをドラッグしてパネルのサイズを調整でき、特に情報を整理するのに便利です。

ユーザーインタラクション

  • react-resizable:

    ユーザーは、サイズ変更ハンドルを使用して、コンポーネントのサイズを直感的に変更できます。この機能は、特にダイナミックなコンテンツが必要なアプリケーションで役立ちます。

  • react-grid-layout:

    ユーザーは、グリッド内のアイテムをドラッグして移動したり、サイズを変更したりできます。これにより、インタラクティブなダッシュボードやカスタマイズ可能なUIを構築できます。

  • react-splitter-layout:

    ユーザーは、パネルのサイズを調整するために分割バーをドラッグできます。これにより、データ表示や情報整理のための柔軟なレイアウトが可能になります。

パフォーマンス

  • react-resizable:

    react-resizableは、サイズ変更の際に最小限の再レンダリングを行うため、パフォーマンスを向上させる設計がされています。特に、サイズ変更が頻繁に行われる場合でもスムーズな操作が可能です。

  • react-grid-layout:

    react-grid-layoutは、効率的なレイアウト管理を実現するために、最適化されたレンダリングを行います。大量のアイテムを扱う場合でも、パフォーマンスを維持するための工夫がされています。

  • react-splitter-layout:

    react-splitter-layoutは、パネルのサイズ変更において効率的な再レンダリングを行い、ユーザーが快適に操作できるように設計されています。

拡張性

  • react-resizable:

    react-resizableは、独自のサイズ変更ハンドルやスタイルを追加することで、カスタマイズが容易です。開発者は、プロジェクトの要件に応じて機能を拡張できます。

  • react-grid-layout:

    react-grid-layoutは、カスタムコンポーネントやプラグインを追加することで、機能を拡張することができます。これにより、特定のニーズに応じた柔軟なレイアウトが可能になります。

  • react-splitter-layout:

    react-splitter-layoutは、異なるレイアウトやスタイルを簡単に追加できるため、プロジェクトに応じたカスタマイズが可能です。

学習曲線

  • react-resizable:

    react-resizableは、シンプルなAPIを持っているため、学習曲線は緩やかです。基本的なサイズ変更機能を理解するのに時間はかかりません。

  • react-grid-layout:

    react-grid-layoutは、グリッドシステムに基づいているため、初めて使う場合でも比較的簡単に学習できます。直感的なAPIが提供されており、すぐに使い始めることができます。

  • react-splitter-layout:

    react-splitter-layoutは、分割レイアウトの概念を理解するのが容易で、基本的な使い方を学ぶのにそれほど時間はかかりません。

選び方: react-resizable vs react-grid-layout vs react-splitter-layout
  • react-resizable:

    要素のサイズを自由に変更したい場合は、react-resizableを選択してください。このライブラリは、個々のコンポーネントのサイズ変更を簡単に実装できるため、特定の要素に対して柔軟性が求められる場合に適しています。

  • react-grid-layout:

    グリッドレイアウトが必要な場合や、複雑なレイアウトを簡単に管理したい場合は、react-grid-layoutを選択してください。特に、ドラッグ&ドロップ機能を活用したい場合に最適です。

  • react-splitter-layout:

    複数のパネルを分割して表示したい場合は、react-splitter-layoutを選択してください。このライブラリは、ユーザーがパネルのサイズを調整できるインターフェースを提供し、特にダッシュボードやデータ表示に便利です。

react-resizable のREADME

React-Resizable

View the Demo

A simple widget that can be resized via one or more handles.

You can either use the <Resizable> element directly, or use the much simpler <ResizableBox> element.

See the example and associated code in ExampleLayout and ResizableBox for more details.

Make sure you use the associated styles in /css/styles.css, as without them, you will have problems with handle placement and visibility.

You can pass options directly to the underlying DraggableCore instance by using the prop draggableOpts. See the demo for more on this.

Installation

$ npm install --save react-resizable

Compatibility

React-Resizable 3.x is compatible with React >= 16.3. React-Resizable 2.x has been skipped. React-Resizable 1.x is compatible with React 14-17.

Usage

This package has two major exports:

  • <Resizable>: A raw component that does not have state. Use as a building block for larger components, by listening to its callbacks and setting its props.
  • <ResizableBox>: A simple <div {...props} /> element that manages basic state. Convenient for simple use-cases.

<Resizable>

const {Resizable} = require('react-resizable');

// ES6
import { Resizable } from 'react-resizable';

// ...
class Example extends React.Component {
  state = {
    width: 200,
    height: 200,
  };

  // On top layout
  onResize = (event, {node, size, handle}) => {
    this.setState({width: size.width, height: size.height});
  };

  render() {
    return (
      <Resizable height={this.state.height} width={this.state.width} onResize={this.onResize}>
        <div className="box" style={{width: this.state.width + 'px', height: this.state.height + 'px'}}>
          <span>Contents</span>
        </div>
      </Resizable>
    );
  }
}

<ResizableBox>

const {ResizableBox} = require('react-resizable');

// ES6
import { ResizableBox } from 'react-resizable';

class Example extends React.Component {
  render() {
    return (
      <ResizableBox width={200} height={200} draggableOpts={{...}}
          minConstraints={[100, 100]} maxConstraints={[300, 300]}>
        <span>Contents</span>
      </ResizableBox>
    );
  }
}

Props

These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.

type ResizeCallbackData = {
  node: HTMLElement,
  size: {width: number, height: number},
  handle: ResizeHandleAxis
};
type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';

type ResizableProps =
{
  children: React.Element<any>,
  width: number,
  height: number,
  // Either a ReactElement to be used as handle, or a function returning an element that is fed the handle's location as its first argument.
  handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
  // If you change this, be sure to update your css
  handleSize: [number, number] = [10, 10],
  lockAspectRatio: boolean = false,
  axis: 'both' | 'x' | 'y' | 'none' = 'both',
  minConstraints: [number, number] = [10, 10],
  maxConstraints: [number, number] = [Infinity, Infinity],
  onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  draggableOpts?: ?Object,
  resizeHandles?: ?Array<ResizeHandleAxis> = ['se']
};

The following props can also be used on <ResizableBox>:

{
  style?: Object // styles the returned <div />
}

If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.

Resize Handle

If you override the resize handle, we expect that any ref passed to your new handle with represent the underlying DOM element.

This is required, as react-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.

There are a few ways to do this:

Native DOM Element

This requires no special treatment.

<Resizable handle={<div className="foo" />} />
Custom React Component

You must forward the ref and props to the underlying DOM element.

Class Components
class MyHandleComponent extends React.Component {
  render() {
    const {handleAxis, innerRef, ...props} = this.props;
    return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
  }
}
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);

<Resizable handle={<MyHandle />} />
Functional Components
const MyHandle = React.forwardRef((props, ref) => {
  const {handleAxis, ...restProps} = props;
  return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
});

<Resizable handle={<MyHandle />} />
Custom Function

You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.

const MyHandle = (props) => {
  return <div ref={props.innerRef} className="foo" {...props} />;
};

<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} {...props} />} />