Skip to content

Commit fc6d209

Browse files
authored
🦊 Add style prop to Grid and GridItem (#87)
1 parent 94a4b92 commit fc6d209

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,15 @@ Setting `collision` prop to `compress` will compress items vertically towards th
405405

406406
### Style related props:
407407

408-
Component can be styled with css framework of your choice or with global classes. To do so, you can use the following props:
408+
Component can be styled with css framework of your choice, global classes or `style` prop. To do so, you can use the following props:
409409

410410
- `<Grid class="..." />` - class name for grid container.
411+
- `<Grid style="..." />` - inline style for grid container.
411412
- `<GridItem class="..." />` - class name for grid item.
412413
- `<GridItem activeClass="..." />` - class name that applies when item is currently being dragged or resized. By default, it is used to make active grid item transparent.
413414
- `<GridItem previewClass="..." />` - class name for preview where item will be placed after interaction.
414415
- `<GridItem resizerClass="..." />` - class name for item's resize handle.
416+
- `<GridItem style="..." />` - inline style for grid item.
415417

416418
To understand how to use these props, look at `<Grid />` component simplified structure.
417419

‎src/lib/Grid.svelte‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
class={`svelte-grid-extended ${classes}`}
273273
bind:this={gridContainer}
274274
style={`width: ${containerWidth ? `${containerWidth}px` : '100%'};
275-
height: ${containerHeight ? `${containerHeight}px` : '100%'};`}
275+
height: ${containerHeight ? `${containerHeight}px` : '100%'}; ${$$restProps.style ?? ''}`}
276276
>
277277
{#if $gridSettings.itemSize}
278278
<slot />

‎src/lib/GridItem.svelte‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@
522522
class:non-active-default={!active}
523523
on:pointerdown={_movable && !$$slots.moveHandle ? moveStart : null}
524524
style={`position: absolute; left:${left}px; top:${top}px; width: ${width}px; height: ${height}px;
525-
${_movable && !$$slots.moveHandle ? 'cursor: move;' : ''} touch-action: none; user-select: none;`}
525+
${_movable && !$$slots.moveHandle ? 'cursor: move;' : ''} touch-action: none; user-select: none;
526+
${$$restProps.style ?? ''}`}
526527
bind:this={itemRef}
527528
>
528529
{#if _movable}

0 commit comments

Comments
 (0)