### Install grid-layout-plus with pnpm
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Use this command to install the library if you are using pnpm as your package manager.
```sh
pnpm i grid-layout-plus
```
--------------------------------
### Install Grid Layout Plus
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Install the grid-layout-plus package using your preferred package manager.
```bash
pnpm i grid-layout-plus
```
```bash
yarn add grid-layout-plus
```
```bash
npm install grid-layout-plus
```
--------------------------------
### Install grid-layout-plus with yarn
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Use this command to install the library if you are using yarn as your package manager.
```sh
yarn add grid-layout-plus
```
--------------------------------
### Basic Grid Layout Setup in Vue 3
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Set up a basic grid layout with draggable and resizable items using Vue 3's `
{{ item.i }}
```
--------------------------------
### Import GridLayout and GridItem in a Vue component (script setup)
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Import the necessary components within a Vue component using the `
```
--------------------------------
### Responsive Layout Setup
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/example/responsive.md
When enabling responsive layouts, the `v-model` data must be defined using `ref` to ensure synchronization. Using `reactive` will not work.
```vue
{{ item.i }}
```
--------------------------------
### Implement Dragging External Elements into Grid
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
This Vue.js component enables dragging external elements into the grid. It requires setup for drag events and mouse position tracking. Ensure the 'lodash-es' library is installed for throttling.
```vue
Drag me into the grid!
{{ item.i }}
```
--------------------------------
### Include browser-ready bundle
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Include the browser-ready JavaScript bundle directly in your HTML file to use the library.
```html
```
--------------------------------
### Override Placeholder Background Color
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/custom-style.md
To change the placeholder's background color, redefine the `--vgl-placeholder-bg` CSS variable within the `.vgl-layout` class. This example sets the background to green.
```css
.vgl-layout {
--vgl-placeholder-bg: green;
}
```
--------------------------------
### Basic Demo Vue Component Source
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/example/basic.md
This Vue component file contains the source code for the basic demonstration. It is intended to be used within a Vue project, likely imported and rendered by another component.
```vue
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
```
--------------------------------
### Prevent Collision in Grid Layout
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Enable collision prevention to ensure grid items can only be dropped in blank spaces, preventing overlaps. Set `prevent-collision` to true. Note that `vertical-compact` is set to false in this example.
```vue
{{ item.i }}
```
--------------------------------
### Responsive Grid Layouts with Breakpoints
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Configure different grid layouts for various screen sizes using responsive layouts and breakpoint configurations. The `@breakpoint-changed` event provides information when the breakpoint changes.
```vue
{{ item.i }}
```
--------------------------------
### GridLayout layout-before-mount Event
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/events.md
Emitted on the component beforeMount lifecycle hook. Use this to perform actions just before the layout is initially mounted.
```typescript
function layoutBeforeMount(newLayout: Layout): void
```
--------------------------------
### GridLayout layout-ready Event
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/events.md
Emitted when finish all the operations on the mount lifecycle hook. This is useful for performing actions after all initial layout calculations and DOM manipulations are complete.
```typescript
function layoutReady(newLayout: Layout): void
```
--------------------------------
### Vue Component for Responsive Layouts Demo
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/example/responsive-layouts.md
This Vue component renders a demonstration of predefined responsive layouts. It relies on a child component `DemoResponsiveLayouts` for the actual UI. Ensure the `DemoResponsiveLayouts` component is correctly imported and registered.
```vue
```
--------------------------------
### Add Grid Lines to Layout
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/custom-style.md
Apply this CSS to the `.vgl-layout::before` pseudo-element to create visual grid lines within the layout. Adjust `background-size` to match your desired column and row dimensions.
```css
.vgl-layout::before {
position: absolute;
width: calc(100% - 5px);
height: calc(100% - 5px);
margin: 5px;
content: '';
background-image:
linear-gradient(to right,lightgrey 1px,transparent 1px),
linear-gradient(to bottom, lightgrey 1px, transparent 1px);
background-repeat: repeat;
background-size: calc(calc(100% - 5px) / 12) 40px;
}
```
--------------------------------
### Grid Item Properties
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/properties.md
Configuration options for individual grid items.
```APIDOC
## Grid Item Configuration Properties
This section details the properties that can be applied to individual grid items to control their behavior and appearance within the grid layout.
### min-h
- **Type**: `number`
- **Default**: `1`
- **Description**: Specifies the minimum height of the grid item. If the item's height (`h`) is set to be smaller than `min-h`, `h` will be adjusted to `min-h`.
### max-w
- **Type**: `number`
- **Default**: `Infinity`
- **Description**: Specifies the maximum width of the grid item. If the item's width (`w`) is set to be larger than `max-w`, `w` will be adjusted to `max-w`.
### max-h
- **Type**: `number`
- **Default**: `Infinity`
- **Description**: Specifies the maximum height of the grid item. If the item's height (`h`) is set to be larger than `max-h`, `h` will be adjusted to `max-h`.
### is-draggable
- **Type**: `boolean`
- **Default**: `null`
- **Description**: Determines if the grid item is draggable. If set to `null`, the draggable state is inherited from the parent component.
### is-resizable
- **Type**: `boolean`
- **Default**: `null`
- **Description**: Determines if the grid item is resizable. If set to `null`, the resizable state is inherited from the parent component.
### is-bounded
- **Type**: `boolean`
- **Default**: `null`
- **Description**: Determines if the grid item is constrained within the container boundaries when being dragged. If set to `null`, this behavior is inherited from the parent component.
### static
- **Type**: `boolean`
- **Default**: `false`
- **Description**: If `true`, the item is static and cannot be dragged, resized, or moved by other items in the grid.
### drag-ignore-from
- **Type**: `string`
- **Default**: `'a, button'`
- **Description**: A CSS-like selector string specifying elements within the item that should not trigger a drag event. Refer to [interact.js docs](http://interactjs.io/docs/#ignorable-selectors) for more details.
### drag-allow-from
- **Type**: `string`
- **Default**: `null`
- **Description**: A CSS-like selector string specifying elements within the item that should trigger a drag event. If `null`, any element (excluding those specified by `drag-ignore-from`) can initiate a drag. Refer to [interact.js docs](http://interactjs.io/docs/#ignorable-selectors) for more details.
### resize-ignore-from
- **Type**: `string`
- **Default**: `'a, button'`
- **Description**: A CSS-like selector string specifying elements within the item that should not trigger a resize event. Refer to [interact.js docs](http://interactjs.io/docs/#ignorable-selectors) for more details.
### preserve-aspect-ratio
- **Type**: `boolean`
- **Default**: `false`
- **Description**: If `true`, the grid item will maintain its aspect ratio when being resized.
### drag-option
- **Type**: `Record`
- **Default**: `{}`
- **Description**: An object for passing through configuration options directly to the [interact.js draggable configuration](https://interactjs.io/docs/draggable/).
### resize-option
- **Type**: `Record`
- **Default**: `{}`
- **Description**: An object for passing through configuration options directly to the [interact.js resizable configuration](https://interactjs.io/docs/resizable/).
```
--------------------------------
### GridLayout Properties
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/properties.md
Configuration options for the GridLayout component.
```APIDOC
## GridLayout Properties
### layout
- type: `Layout`
- required
This is the initial layout of the grid. The value must be an array. Each item must have `i`, `x`, `y`, `w` and `h` properties.
### responsive-layouts
- type: `Partial`
- default: `{}`
Initial layouts of the grid per breakpoint if `responsive` is set to `true`. The keys of the object are breakpoint names and each value is an array as defined by `layout` prop.
### col-num
- type: `number`
- default: `12`
Specifies the number of columns the grid has. The value should be a natural number.
### row-height
- type: `number`
- default: `150`
Specifies the height of a single row in pixels.
### max-rows
- type: `number`
- default: `Infinity`
Specifies the maximal number of rows in the grid.
### margin
- type: `number[]`
- default: `[10, 10]`
Specifies the margins of elements inside the grid. The value must be a number array with size two. Each value is expressed in pixels. The first value is horizontal margin, the second is vertical margin.
### is-draggable
- type: `boolean`
- default: `true`
Specifies if the grid items are draggable.
### is-resizable
- type: `boolean`
- default: `true`
Specifies if the grid items are resizable.
### is-mirrored
- type: `boolean`
- default: `false`
Specifies if the RTL/LTR should be reversed.
### is-bounded
- type: `boolean`
- default: `false`
Specifies if the grid items are bounded to the container when dragging.
### auto-size
- type: `boolean`
- default: `true`
Specifies if the container height should adjust to fit contents.
### vertical-compact
- type: `boolean`
- default: `true`
Specifies if the layout should be compacted vertically.
### restore-on-drag
- type: `boolean`
- default: `false`
Specifies if moved grid items should be restored after being dragged over.
### prevent-collision
- type: `boolean`
- default: `false`
Specifies whether to prevent items collision. When `true`, items can only be dropped to blank space.
### use-css-transforms
- type: `boolean`
- default: `true`
Specifies if the CSS `transition-property: transform;` should be used.
### responsive
- type: `boolean`
- default: `false`
Specifies if the layout should be responsive to window width.
### breakpoints
- type: `Breakpoints`
- default: `{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }`
Breakpoints defined for responsive layout.
### cols
- type: `Breakpoints`
- default: `{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }`
Defines the number of columns for each breakpoint.
### use-style-cursor
- type: `boolean`
- default: `true`
Specifies if the cursor style should be set dynamically. Setting this to `false` may alleviate problems when dragging freezes. This property is not reactive.
### transform-scale
- type: `number`
- default: `1`
Sets a scaling factor to the size of the grid items, `1` means 100%.
```
--------------------------------
### Handle GridLayout and GridItem Events
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Listen to layout and item events to track changes in the grid. This includes events for layout lifecycle, breakpoint changes, and item movement or resizing. Ensure necessary types are imported for event handlers.
```vue
{{ item.i }}
```
--------------------------------
### Vue.js Component for Styling Placeholder
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/example/styling-placeholder.md
This Vue.js component demonstrates the structure for a styling placeholder. It is intended for client-side rendering only.
```vue
```
--------------------------------
### Basic Vue Component Structure
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/example/basic.md
This is a standard Vue.js component structure for integrating client-side components. The `` tag ensures that the `DemoBasic` component is rendered only on the client side.
```vue
```
--------------------------------
### Configure GridItem Component Props
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Use these properties to configure individual grid items, including their position, size, and behavior like static placement or drag/resize constraints. Ensure a unique 'i' identifier for each item.
```vue
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:min-w="1"
:min-h="1"
:max-w="Infinity"
:max-h="Infinity"
:is-draggable="null"
:is-resizable="null"
:is-bounded="null"
:static="item.static"
drag-ignore-from="a, button"
drag-allow-from=".drag-handle"
resize-ignore-from="a, button"
:preserve-aspect-ratio="false"
>
{{ item.i }}{{ item.static ? ' - Static' : '' }}
```
--------------------------------
### Customize Grid Layout Appearance with CSS Variables
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Use CSS variables within the '.vgl-layout' class to customize the appearance of the grid, including placeholder colors, resizing opacity, and resizer handle styles. Apply specific styles to grid items using ':deep()' selectors for different states like resizing or static.
```vue
{{ item.i }}
```
--------------------------------
### LayoutItem Interface
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/properties.md
Extends LayoutItemRequired with optional properties for minimum/maximum dimensions, drag and resize states, and static positioning.
```typescript
interface LayoutItem extends LayoutItemRequired {
minW?: number,
minH?: number,
maxW?: number,
maxH?: number,
moved?: boolean,
static?: boolean,
isDraggable?: boolean,
isResizable?: boolean
}
```
--------------------------------
### TypeScript Types for Grid Layout Plus
Source: https://context7.com/qmhc/grid-layout-plus/llms.txt
Utilize the exported TypeScript types for robust type checking in your grid layout configurations. Define layouts, breakpoints, and responsive layouts with type safety.
```typescript
import type {
Layout,
LayoutItem,
LayoutItemRequired,
Breakpoint,
Breakpoints,
ResponsiveLayout,
} from 'grid-layout-plus'
// LayoutItemRequired - minimum required properties
interface LayoutItemRequired {
w: number // Width in grid units
h: number // Height in grid units
x: number // X position in grid units
y: number // Y position in grid units
i: number | string // Unique identifier
}
// LayoutItem - full item with optional properties
interface LayoutItem extends LayoutItemRequired {
minW?: number // Minimum width
minH?: number // Minimum height
maxW?: number // Maximum width
maxH?: number // Maximum height
moved?: boolean // Has been moved
static?: boolean // Cannot be moved or resized
isDraggable?: boolean // Override parent draggable
isResizable?: boolean // Override parent resizable
}
// Layout - array of layout items
type Layout = Array
// Breakpoint - responsive breakpoint names
type Breakpoint = 'xxs' | 'xs' | 'sm' | 'md' | 'lg'
// Breakpoints - width values for each breakpoint
type Breakpoints = Record
// ResponsiveLayout - layouts for each breakpoint
type ResponsiveLayout = Record
// Example usage
const layout: Layout = [
{ x: 0, y: 0, w: 2, h: 2, i: '0' },
{ x: 2, y: 0, w: 2, h: 4, i: '1', static: true },
]
const breakpoints: Breakpoints = {
lg: 1200,
md: 996,
sm: 768,
xs: 480,
xxs: 0,
}
const responsiveLayouts: Partial = {
lg: layout,
md: [{ x: 0, y: 0, w: 4, h: 2, i: '0' }],
}
```
--------------------------------
### Import GridLayout and GridItem in a Vue component (defineComponent)
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Import and register the GridLayout and GridItem components within a Vue component using the `defineComponent` option.
```vue
```
--------------------------------
### Types
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/zh/guide/properties.md
TypeScript type definitions used within GridLayout Plus.
```APIDOC
## Types
### LayoutItemRequired
```ts
interface LayoutItemRequired {
w: number,
h: number,
x: number,
y: number,
i: number | string
}
```
### LayoutItem
```ts
interface LayoutItem extends LayoutItemRequired {
minW?: number,
minH?: number,
maxW?: number,
maxH?: number,
moved?: boolean,
static?: boolean,
isDraggable?: boolean,
isResizable?: boolean
}
```
### Layout
```ts
type Layout = Array
```
### Breakpoint
```ts
type Breakpoint = 'xxs' | 'xs' | 'sm' | 'md' | 'lg'
```
### Breakpoints
```ts
type Breakpoints = Record
```
### ResponsiveLayout
```ts
type ResponsiveLayout = Record
```
```
--------------------------------
### Globally import GridLayout and GridItem
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/installation.md
Import and register the GridLayout and GridItem components globally in your Vue application.
```ts
import { GridLayout, GridItem } from 'grid-layout-plus'
app
.component('GridLayout', GridLayout)
.component('GridItem', GridItem)
```
--------------------------------
### Default Placeholder Styles
Source: https://github.com/qmhc/grid-layout-plus/blob/main/docs/guide/custom-style.md
The default CSS for placeholders uses variables to define z-index, background color, and opacity. Ensure these variables are set if you intend to override them.
```css
.vgl-item--placeholder {
z-index: var(--vgl-placeholder-z-index, 2);
user-select: none;
background-color: var(--vgl-placeholder-bg, red);
opacity: var(--vgl-placeholder-opacity, 20%);
transition-duration: 100ms;
}
```