Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: responsive grid rewrite + remove react-grid-system package #1457

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ColumnItem",
"name": "GridItem",
"type": "dmss://system/SIMOS/Blueprint",
"attributes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}

This file was deleted.

3 changes: 1 addition & 2 deletions packages/dm-core-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/dm-core-plugins/src/grid/GridPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const GridPlugin = (
}

return (
<Grid className='dm-parent-plugin' {...internalConfig.size}>
<Grid
className='dm-plugin-padding dm-parent-plugin'
{...internalConfig.size}
>
<GridItems
idReference={idReference}
items={internalConfig.items}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
import { IUIPlugin, ViewCreator } from '@development-framework/dm-core'
import { Typography } from '@equinor/eds-core-react'
import React from 'react'
import { Col, Container, Row } from 'react-grid-system'
import { TCol, TGridPluginConfig, TRow } from './types'

const defaultConfig: TGridPluginConfig = {
rows: [],
}
import * as Styled from './styles'
import { TCol, TGridPluginConfig, defaultConfig } from './types'

export const ResponsiveGridPlugin = (
props: IUIPlugin & { config: TGridPluginConfig }
): React.ReactElement => {
const { config, idReference, type, onSubmit, onChange } = props
const { config, idReference, onSubmit, onChange } = props

const internalConfig: TGridPluginConfig = {
...defaultConfig,
...config,
}

return (
<Container style={{ width: '100%' }}>
{internalConfig.rows.map((row: TRow) => {
const columns = row.columns.map((col: TCol) => {
return (
<Col {...col.size}>
<div style={{ marginBottom: '20px' }}>
{col?.title && (
<Typography variant='h4'>{col.title}</Typography>
)}
<ViewCreator
idReference={idReference}
viewConfig={col.viewConfig}
onSubmit={onSubmit}
onChange={onChange}
/>
</div>
</Col>
)
})
return <Row gutterWidth={row.gutterWidth || 30}>{columns}</Row>
<Styled.Grid
className='dm-plugin-padding dm-parent-plugin'
spacing={internalConfig.spacing}
>
{internalConfig.views.map((col: TCol) => {
return (
<Styled.GridItem size={col.size}>
{col?.title && <Typography variant='h4'>{col.title}</Typography>}
<ViewCreator
idReference={idReference}
viewConfig={col.viewConfig}
onSubmit={onSubmit}
onChange={onChange}
/>
</Styled.GridItem>
)
})}
</Container>
</Styled.Grid>
)
}
39 changes: 39 additions & 0 deletions packages/dm-core-plugins/src/responsive_grid/styles.ts
Original file line number Diff line number Diff line change
@@ -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)}
`
34 changes: 15 additions & 19 deletions packages/dm-core-plugins/src/responsive_grid/types.ts
Original file line number Diff line number Diff line change
@@ -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<TBreakpoint, number>

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: [],
}
Loading