-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: responsive grid rewrite + remove react-grid-system package
- Loading branch information
1 parent
1b52856
commit f3d4176
Showing
9 changed files
with
123 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/dm-core-plugins/blueprints/responsive_grid/ColumnItem.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "ColumnItem", | ||
"name": "GridItem", | ||
"type": "dmss://system/SIMOS/Blueprint", | ||
"attributes": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
packages/dm-core-plugins/blueprints/responsive_grid/RowItem.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 20 additions & 28 deletions
48
packages/dm-core-plugins/src/responsive_grid/ResponsiveGridPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
} |