Skip to main content

A draggable and resizable grid layout with responsive breakpoints, for Dash

Project description

dash-snap-grid

A draggable and resizable grid layout with responsive breakpoints, for Dash.

(A dash port of react-grid-layout with some additional features specific to Dash)

demo animation

Installation

pip install dash-snap-grid

Basic Usage

You must set the env variable REACT_VERSION=18.2.0 before starting up the app.

import dash
from dash import html
from dash_snap_grid import Grid

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        Grid(
            id="grid",
            cols=12,
            rowHeight=100,
            layout=[
                # i should match the id of the children
                {"i": "1", "x": 0, "y": 0, "w": 1, "h": 2},
                {"i": "2", "x": 1, "y": 0, "w": 3, "h": 2},
                {"i": "3", "x": 4, "y": 0, "w": 1, "h": 2},
            ],
            children=[
                html.Div(
                    "1", id="1", style={"background": "lightblue", "height": "100%"}
                ),
                html.Div(
                    "2", id="2", style={"background": "lightgreen", "height": "100%"}
                ),
                html.Div(
                    "3", id="3", style={"background": "lightcoral", "height": "100%"}
                ),
            ],
        ),
    ]
)

if __name__ == "__main__":
    app.run_server(debug=True)

Components

Grid

The main component that wraps the children and handles the layout.

Props

  • id (str): The id of the component.
  • width (int): The initial width of the grid.
  • autoSize (bool): If true, the grid will automatically resize to fit the children. (default: True)
  • cols (int): The number of columns in the grid. (default: 12)
  • draggableCancel (str): A css selector for elements that should not trigger drag. Use this if you have input elements or buttons inside the grid.
  • draggableHandle (str): A css selector for elements that should be used as the drag handle.
  • compactType (str | None): The type of compacting to use when moving elements around. Options: None, vertical, horizontal. (default: None)
  • layout (List[Dict[str, Any]]): The initial layout of the grid. Each item should have the following keys:
    • i (str): The id of the child.
    • x (int): The x position of the child.
    • y (int): The y position of the child.
    • w (int): The width of the child. (count of columns)
    • h (int): The height of the child. (count of rows) The following keys are optional:
    • minW (int): The minimum width of the child. (default: 0)
    • maxW (int): The maximum width of the child. (default: Infinity)
    • minH (int): The minimum height of the child. (default: 0)
    • maxH (int): The maximum height of the child. (default: Infinity)
    • static (bool): If true, the child cannot be moved or resized. (default: False)
    • isDraggable (bool): If false, the child cannot be dragged. (default: True)
    • isResizable (bool): If false, the child cannot be resized. (default: True)
    • isBounded (bool): If true, the child will be bounded by the grid. (default: False) Reloading the page will restore the last layout update that the user did.
  • margin (List[int]): The margin between the children. (default: [10, 10])
  • containerPadding (List[int]): The padding of the container. (default: [10, 10])
  • rowHeight (int): The height of a row in pixels. (default: 150)
  • isDraggable (bool): If true, the children can be dragged. (default: True)
  • isResizable (bool): If true, the children can be resized. (default: True)
  • isBounded (bool): If true, the children will be bounded by the grid. (default: False)
  • useCSSTransforms (bool): If true, the children will be moved using css transforms. (default: True)
  • transformScale (float): The scale of the transform. (default: 1)
  • allowOverlap (bool): If true, the children can overlap. (default: False)
  • preventCollision (bool): If true, the children will not collide with each other. (default: False)
  • isDroppable (bool): If true, the children can be dropped. (default: False). Once an item is dropped, the droppedItem prop will be updated with the layout details of the dropped item, which contains the the layout details of the dropped item. the i key will be set to the id of the dropped item.
  • resizeHandles (List[str]): The handles that can be used to resize the children. Options: ['s', 'e', 'n', 'w', 'se', 'ne', 'sw', 'nw']. (default: ['se'])
  • children (List[html.Div]): The children of the grid. Make sure the id of the children matches the i key of the layout items.

ResponsiveGrid

A responsive version of the grid that changes the layout based on the screen size.

Props

  • id (str): The id of the component.
  • width (int): The initial width of the grid.
  • autoSize (bool): If true, the grid will automatically resize to fit the children. (default: True)
  • breakpoints (Dict[str, int]): The breakpoints for the grid. The keys should be the screen sizes and the values should be the number of columns in the grid for that screen size. default: {'lg': 1200, 'md': 996, 'sm': 768, 'xs': 400, 'xxs': 0}
  • cols (dict[str, int]): Number of columns per screen size. The keys should be the screen sizes and the values should be the number of columns in the grid for that screen size. default: {'lg': 12, 'md': 10, 'sm': 6, 'xs': 4, 'xxs': 2}
  • draggableCancel (str): A css selector for elements that should not trigger drag. Use this if you have input elements or buttons inside the grid.
  • draggableHandle (str): A css selector for elements that should be used as the drag handle.
  • compactType (str | None): The type of compacting to use when moving elements around. Options: None, vertical, horizontal. (default: None)
  • layout (List[Dict[str, Any]]): The current layout (Read only) Each item should have the following keys:
    • i (str): The id of the child.
    • x (int): The x position of the child.
    • y (int): The y position of the child.
    • w (int): The width of the child. (count of columns)
    • h (int): The height of the child. (count of rows) The following keys are optional:
    • minW (int): The minimum width of the child. (default: 0)
    • maxW (int): The maximum width of the child. (default: Infinity)
    • minH (int): The minimum height of the child. (default: 0)
    • maxH (int): The maximum height of the child. (default: Infinity)
    • static (bool): If true, the child cannot be moved or resized. (default: False)
    • isDraggable (bool): If false, the child cannot be dragged. (default: True)
    • isResizable (bool): If false, the child cannot be resized. (default: True)
    • isBounded (bool): If true, the child will be bounded by the grid. (default: False)
  • layouts (Dict[str, List[Dict[str, Any]]]): The initial layout of the grid for each screen size. This is dictionary of layouts, where the keys are the screen sizes and the values are the layouts. If you want to set the layout for a given screen size, this prop should be set. layout prop is only to read the current layout. for example: {'lg': [...], 'md': [...], 'sm': [...], 'xs': [...], 'xxs': [...]}.
  • persistLayout (bool): If true, any changes to the layout will be stored in browser storage. The layout change made at each breakpoint will be saved separately. So layout presistance will happen at each breakpoint.
  • margin (List[int] | dict[str, int]): The margin between the children. (default: [10, 10]) You can also specify the margin for each screen size by passing a dictionary. for example: {'lg': [10, 10], 'md': [5, 5], 'sm': [2, 2], 'xs': [1, 1], 'xxs': [0, 0]}
  • containerPadding (List[int] | dict[str, int]): The padding of the container. (default: [10, 10]) Similar to the margin, you can also specify the padding for each screen size by passing a dictionary.
  • rowHeight (int): The height of a row in pixels. (default: 150)
  • isDraggable (bool): If true, the children can be dragged. (default: True)
  • isResizable (bool): If true, the children can be resized. (default: True)
  • isBounded (bool): If true, the children will be bounded by the grid. (default: False)
  • useCSSTransforms (bool): If true, the children will be moved using css transforms. (default: True)
  • transformScale (float): The scale of the transform. (default: 1)
  • allowOverlap (bool): If true, the children can overlap. (default: False)
  • preventCollision (bool): If true, the children will not collide with each other. (default: False)
  • isDroppable (bool): If true, the children can be dropped. (default: False). Once an item is dropped, the droppedItem prop will be updated with the layout details of the dropped item, which contains the the layout details of the dropped item. the i key will be set to the id of the dropped item.
  • resizeHandles (List[str]): The handles that can be used to resize the children. Options: ['s', 'e', 'n', 'w', 'se', 'ne', 'sw', 'nw']. (default: ['se'])
  • children (List[html.Div]): The children of the grid. Make sure the id of the children matches the i key of the layout items.

DraggableDiv

A draggable div that can be used as a an item that can be dragged and dropped in the grid.

Props

  • id (str): The id of the component.
  • children (html.Div): The children of the div.
  • style (dict): The style of the div.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash_snap_grid-0.4.2.tar.gz (151.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dash_snap_grid-0.4.2-py3-none-any.whl (154.0 kB view details)

Uploaded Python 3

File details

Details for the file dash_snap_grid-0.4.2.tar.gz.

File metadata

  • Download URL: dash_snap_grid-0.4.2.tar.gz
  • Upload date:
  • Size: 151.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dash_snap_grid-0.4.2.tar.gz
Algorithm Hash digest
SHA256 48c4116356a7eb6072c8dd135a4ed2bb0e8a4dbb17141ab618ac4c64fd81c317
MD5 3e362c07393645461e2ab2c98da362e3
BLAKE2b-256 4c20ae80f7c5856b95b0fb62f155af867cf3dfb90d0540d5e24f64d1db9f6027

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_snap_grid-0.4.2.tar.gz:

Publisher: python-publish.yml on idling-mind/dash_snap_grid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dash_snap_grid-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: dash_snap_grid-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 154.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dash_snap_grid-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0dd72257d9f4cc4959b06eeb7fc57f9834943161d7df84c06f1587f05724fd82
MD5 1df4f8460eb6b32332b313da927f38ed
BLAKE2b-256 3776ade3191479843acb5db6f3e6e1d10a57b5f9e83dc848933861059ab4f6cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_snap_grid-0.4.2-py3-none-any.whl:

Publisher: python-publish.yml on idling-mind/dash_snap_grid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page