diff --git a/example/app/data/DemoDataSource/recipes/plugins/responsive_grid/example/dashboard.recipe.json b/example/app/data/DemoDataSource/recipes/plugins/responsive_grid/example/dashboard.recipe.json index 6b85d5b68..2f64bc4e1 100644 --- a/example/app/data/DemoDataSource/recipes/plugins/responsive_grid/example/dashboard.recipe.json +++ b/example/app/data/DemoDataSource/recipes/plugins/responsive_grid/example/dashboard.recipe.json @@ -6,55 +6,45 @@ "type": "CORE:UiRecipe", "config": { "type": "PLUGINS:dm-core-plugins/responsive_grid/ResponsiveGridPluginConfig", - "rows": [ + "views": [ { - "type": "PLUGINS:dm-core-plugins/responsive_grid/RowItem", - "columns": [ - { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnItem", - "viewConfig": { - "type": "CORE:ReferenceViewConfig", - "recipe": "aRecipeName", - "scope": "aNestedObjectWithCustomUI" - }, - "size": { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", - "sm": 12, - "md": 4 - } - }, - { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnItem", - "viewConfig": { - "type": "CORE:ReferenceViewConfig", - "recipe": "aRecipeName", - "scope": "aNestedObjectWithCustomUI" - }, - "size": { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", - "sm": 12, - "md": 4 - } - } - ] + "type": "PLUGINS:dm-core-plugins/responsive_grid/GridItem", + "viewConfig": { + "type": "CORE:ReferenceViewConfig", + "recipe": "aRecipeName", + "scope": "aNestedObjectWithCustomUI" + }, + "size": { + "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", + "sm": 12, + "md": 4 + } }, { - "type": "PLUGINS:dm-core-plugins/responsive_grid/RowItem", - "columns": [ - { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnItem", - "viewConfig": { - "type": "CORE:ReferenceViewConfig", - "recipe": "aRecipeName", - "scope": "aNestedObjectWithCustomUI" - }, - "size": { - "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", - "sm": 12, - "md": 4 - } - } - ] + "type": "PLUGINS:dm-core-plugins/responsive_grid/GridItem", + "viewConfig": { + "type": "CORE:ReferenceViewConfig", + "recipe": "aRecipeName", + "scope": "aNestedObjectWithCustomUI" + }, + "size": { + "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", + "sm": 12, + "md": 4 + } + }, + { + "type": "PLUGINS:dm-core-plugins/responsive_grid/GridItem", + "viewConfig": { + "type": "CORE:ReferenceViewConfig", + "recipe": "aRecipeName", + "scope": "aNestedObjectWithCustomUI" + }, + "size": { + "type": "PLUGINS:dm-core-plugins/responsive_grid/ColumnSize", + "sm": 12, + "md": 4 + } } ] }, diff --git a/packages/dm-core-plugins/blueprints/responsive_grid/ColumnItem.json b/packages/dm-core-plugins/blueprints/responsive_grid/ColumnItem.json index 543c26aee..6cee13a4d 100644 --- a/packages/dm-core-plugins/blueprints/responsive_grid/ColumnItem.json +++ b/packages/dm-core-plugins/blueprints/responsive_grid/ColumnItem.json @@ -1,5 +1,5 @@ { - "name": "ColumnItem", + "name": "GridItem", "type": "dmss://system/SIMOS/Blueprint", "attributes": [ { diff --git a/packages/dm-core-plugins/blueprints/responsive_grid/ResponsiveGridPluginConfig.json b/packages/dm-core-plugins/blueprints/responsive_grid/ResponsiveGridPluginConfig.json index 6f81b1374..8e82a55be 100644 --- a/packages/dm-core-plugins/blueprints/responsive_grid/ResponsiveGridPluginConfig.json +++ b/packages/dm-core-plugins/blueprints/responsive_grid/ResponsiveGridPluginConfig.json @@ -8,17 +8,17 @@ "attributeType": "string" }, { - "name": "showItemBorders", + "name": "views", "type": "CORE:BlueprintAttribute", - "attributeType": "boolean", - "default": false, - "optional": true + "attributeType": "PLUGINS:dm-core-plugins/responsive_grid/GridItem", + "dimensions": "*" }, { - "name": "rows", + "name": "spacing", "type": "CORE:BlueprintAttribute", - "attributeType": "PLUGINS:dm-core-plugins/responsive_grid/RowItem", - "dimensions": "*" + "attributeType": "number", + "default": 1, + "optional": true } ] } diff --git a/packages/dm-core-plugins/blueprints/responsive_grid/RowItem.json b/packages/dm-core-plugins/blueprints/responsive_grid/RowItem.json deleted file mode 100644 index c38215eda..000000000 --- a/packages/dm-core-plugins/blueprints/responsive_grid/RowItem.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "RowItem", - "type": "dmss://system/SIMOS/Blueprint", - "attributes": [ - { - "name": "type", - "type": "dmss://system/SIMOS/BlueprintAttribute", - "attributeType": "string" - }, - { - "name": "columns", - "type": "CORE:BlueprintAttribute", - "attributeType": "./ColumnItem", - "optional": true, - "dimensions": "*" - } - ] -} diff --git a/packages/dm-core-plugins/package.json b/packages/dm-core-plugins/package.json index 50798674a..e660cd03d 100644 --- a/packages/dm-core-plugins/package.json +++ b/packages/dm-core-plugins/package.json @@ -20,8 +20,7 @@ "react-hook-form": "^7.48.2", "react-toastify": "^9.1.3", "ts-node": "^10.9.1", - "yaml": "^2.3.2", - "react-grid-system": "^8.1.9" + "yaml": "^2.3.2" }, "devDependencies": { "@biomejs/biome": "1.4.1", diff --git a/packages/dm-core-plugins/src/grid/GridPlugin.tsx b/packages/dm-core-plugins/src/grid/GridPlugin.tsx index 41bd6636f..6e31acbb4 100644 --- a/packages/dm-core-plugins/src/grid/GridPlugin.tsx +++ b/packages/dm-core-plugins/src/grid/GridPlugin.tsx @@ -52,7 +52,10 @@ export const GridPlugin = ( } return ( - + { - const { config, idReference, type, onSubmit, onChange } = props + const { config, idReference, onSubmit, onChange } = props const internalConfig: TGridPluginConfig = { ...defaultConfig, @@ -19,27 +15,23 @@ export const ResponsiveGridPlugin = ( } return ( - - {internalConfig.rows.map((row: TRow) => { - const columns = row.columns.map((col: TCol) => { - return ( - -
- {col?.title && ( - {col.title} - )} - -
- - ) - }) - return {columns} + + {internalConfig.views.map((col: TCol) => { + return ( + + {col?.title && {col.title}} + + + ) })} -
+ ) } diff --git a/packages/dm-core-plugins/src/responsive_grid/styles.ts b/packages/dm-core-plugins/src/responsive_grid/styles.ts new file mode 100644 index 000000000..33277ac54 --- /dev/null +++ b/packages/dm-core-plugins/src/responsive_grid/styles.ts @@ -0,0 +1,39 @@ +import styled from 'styled-components' +import { TBreakpoint, TBreakpoints, breakpoints } from './types' + +const createSpacingStyles = (spacing: TBreakpoints) => + Object.entries(spacing) + .filter((bp) => bp[0] !== 'type') + .map( + (bp) => ` + @media (min-width: ${breakpoints[bp[0] as TBreakpoint]}px) { + gap: ${bp[1]}rem; + } + ` + ) + .join('') + +const createGridItemColumnSizes = (sizes: TBreakpoints) => + Object.entries(sizes) + .filter((bp) => bp[0] !== 'type') + .map( + (bp) => ` + @media (min-width: ${breakpoints[bp[0] as TBreakpoint]}px) { + grid-column: span ${bp[1]}; + } + ` + ) + .join('') + +export const Grid = styled.div<{ spacing?: TBreakpoints }>` + display: grid; + grid-template-columns: repeat(12, 1fr); + width: 100%; + gap: 1rem; + ${({ spacing }) => (spacing ? createSpacingStyles(spacing) : '')} +` + +export const GridItem = styled.div<{ size: TBreakpoints }>` + grid-column: span 12; + ${({ size }) => createGridItemColumnSizes(size)} +` diff --git a/packages/dm-core-plugins/src/responsive_grid/types.ts b/packages/dm-core-plugins/src/responsive_grid/types.ts index 657bd2a8a..d5a78da44 100644 --- a/packages/dm-core-plugins/src/responsive_grid/types.ts +++ b/packages/dm-core-plugins/src/responsive_grid/types.ts @@ -1,32 +1,28 @@ import { TViewConfig } from '@development-framework/dm-core' -export type TColSize = { - xs: number - sm: number - md: number - lg: number - xl: number - xxl: number +export type TBreakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' +export type TBreakpoints = Record + +export const breakpoints: TBreakpoints = { + xs: 576, + sm: 768, + md: 992, + lg: 1200, + xl: 1600, + xxl: 1920, } export type TCol = { viewConfig: TViewConfig - size: TColSize + size: TBreakpoints title?: string } -export type TRow = { - columns: TCol[] - gutterWidth: number -} - export type TGridPluginConfig = { - rows: TRow[] + views: TCol[] + spacing?: TBreakpoints } -export type TItemBorder = { - size: string - style: string - color: string - radius: string +export const defaultConfig: TGridPluginConfig = { + views: [], }