-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce o3 grid CSS custom properties (#1764)
* feat: introduce o3 grid CSS custom properties and `o3-grid` helper class --------- Co-authored-by: Akaki Mikaia <[email protected]> Co-authored-by: Lee Moody <[email protected]>
- Loading branch information
1 parent
62da89d
commit 19759d8
Showing
14 changed files
with
312 additions
and
19 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
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,35 @@ | ||
:root { | ||
--o3-grid-template: 0px | ||
repeat(var(--o3-grid-columns), 1fr) 0px; | ||
--o3-grid-area: 'bleed-left content-start . . content-end bleed-right'; | ||
--o3-grid-columns: 4; | ||
--o3-grid-gap: 16px; | ||
|
||
@media screen and (min-width: 740px) { | ||
--o3-grid-template: 8px | ||
repeat(var(--o3-grid-columns), 1fr) 8px; | ||
--o3-grid-area: 'bleed-left content-start . . . . . . content-end bleed-right'; | ||
--o3-grid-columns: 8; | ||
} | ||
|
||
@media screen and (min-width: 980px) { | ||
--o3-grid-template: 0px | ||
repeat(var(--o3-grid-columns), 1fr) 0px; | ||
--o3-grid-area: 'bleed-left content-start . . . . . . . . . . content-end bleed-right'; | ||
--o3-grid-columns: 12; | ||
--o3-grid-gap: 24px; | ||
} | ||
|
||
@media screen and (min-width: 1268px) { | ||
--column-width: calc((1220px - 11 * var(--o3-grid-gap)) / 12); | ||
--o3-grid-template: 1fr | ||
repeat(var(--o3-grid-columns), var(--column-width)) 1fr; | ||
} | ||
} | ||
|
||
.o3-grid { | ||
display: grid; | ||
grid-template-columns: var(--o3-grid-template); | ||
grid-template-areas: var(--o3-grid-area); | ||
column-gap: var(--o3-grid-gap); | ||
} |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import './fonts.css'; | ||
@import './normalise.css'; | ||
@import './focus.css'; | ||
@import './grid.css'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {GridMetaGenerator} from '../storyTemplates' | ||
|
||
export default { | ||
title: 'Core/o3-grid', | ||
tags: ['!autodocs'], | ||
...GridMetaGenerator('core') | ||
} as Meta; | ||
|
||
export const Grid: StoryObj = {}; |
10 changes: 10 additions & 0 deletions
10
components/o3-foundation/stories/core/proffesional/grid.stories.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {GridMetaGenerator} from '../../storyTemplates' | ||
|
||
export default { | ||
title: 'Core/Professional/o3-grid', | ||
tags: ['!autodocs'], | ||
...GridMetaGenerator('professional'), | ||
} as Meta; | ||
|
||
export const Grid: StoryObj = {}; |
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,9 @@ | ||
.o3-grid { | ||
row-gap: 4px; | ||
} | ||
|
||
.o3-grid-item { | ||
height: 100px; | ||
background-color: tomato; | ||
cursor: pointer; | ||
} |
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,79 @@ | ||
import {useEffect, useState} from 'react'; | ||
import "../grid.css"; | ||
|
||
const itemDetails = [ | ||
{ | ||
id: 1, | ||
span: `content-start / content-end`, | ||
text: 'Full content', | ||
}, | ||
{ | ||
id: 2, | ||
span: `content-start / span 6`, | ||
text: 'Span 6', | ||
}, | ||
{ | ||
id: 3, | ||
span: `span 3`, | ||
text: 'Span 3', | ||
}, | ||
{ | ||
id: 4, | ||
span: `span 1 / content-end`, | ||
text: 'Span 1', | ||
}, | ||
{ | ||
id: 5, | ||
span: `bleed-left / bleed-right`, | ||
text: 'Full bleed', | ||
}, | ||
{ | ||
id: 6, | ||
span: `bleed-left / content-end`, | ||
text: 'Bleed only left', | ||
}, | ||
]; | ||
|
||
export function O3Grid() { | ||
// on window resize update the grid | ||
const [gridItems, setGridItems] = useState(itemDetails); | ||
|
||
useEffect(() => { | ||
const handleResize = () => { | ||
if (window.innerWidth < 740) { | ||
const newGridItems = [...itemDetails]; | ||
itemDetails[1].span = `content-start / span 4`; | ||
itemDetails[1].text = `Span 4`; | ||
itemDetails[2].span = `content-start / span 2`; | ||
itemDetails[2].text = `Span 2`; | ||
|
||
setGridItems(newGridItems); | ||
} else if (window.innerWidth < 980) { | ||
const newGridItems = [...itemDetails]; | ||
itemDetails[2].span = `span 2`; | ||
itemDetails[2].text = `Span 2`; | ||
setGridItems(newGridItems); | ||
} | ||
}; | ||
|
||
handleResize(); | ||
window.addEventListener('resize', handleResize); | ||
return () => { | ||
window.removeEventListener('resize', handleResize); | ||
}; | ||
}, []); | ||
return ( | ||
<div className="o3-grid" style={{marginTop: '20px'}}> | ||
{gridItems.map(item => ( | ||
<div | ||
key={item.id} | ||
className="o3-grid-item" | ||
style={{ | ||
gridColumn: `${item.span}`, | ||
}}> | ||
{item.text} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
components/o3-foundation/stories/internal/grid.stories.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {GridMetaGenerator} from '../storyTemplates' | ||
|
||
export default { | ||
title: 'Internal/o3-grid', | ||
tags: ['!autodocs'], | ||
...GridMetaGenerator('internal'), | ||
} as Meta; | ||
|
||
export const Grid: StoryObj = {}; |
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,24 @@ | ||
import type {Meta} from '@storybook/react'; | ||
import {transformCode} from './utils'; | ||
import {O3Grid} from './grid'; | ||
import './grid-sb-styles.css'; | ||
|
||
export function GridMetaGenerator(brand: string): Meta { | ||
return { | ||
component: O3Grid, | ||
decorators: [ | ||
Story => ( | ||
<div data-o3-brand={brand}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
parameters: { | ||
layout: 'fullscreen', | ||
backgrounds: {default: 'paper'}, | ||
html: { | ||
transform: (code: string) => transformCode(code), | ||
}, | ||
}, | ||
}; | ||
} |
10 changes: 10 additions & 0 deletions
10
components/o3-foundation/stories/sustainable-views/grid.stories.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {GridMetaGenerator} from '../storyTemplates' | ||
|
||
export default { | ||
title: 'Sustainable-views/o3-grid', | ||
tags: ['!autodocs'], | ||
...GridMetaGenerator('sustainable-views'), | ||
} as Meta; | ||
|
||
export const Grid: StoryObj = {}; |
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,20 @@ | ||
export function transformCode(code: string) { | ||
let parser = new DOMParser(); | ||
let doc = parser.parseFromString(code, 'text/html'); | ||
|
||
// Remove the edit panel | ||
let editPanel = doc.querySelector('.edit-panel'); | ||
if (editPanel) { | ||
editPanel.remove(); | ||
} | ||
|
||
// Remove the class 'o3-grid-item' from all items | ||
let gridItems = doc.querySelectorAll('.o3-grid-item'); | ||
gridItems.forEach(item => { | ||
item.removeAttribute('class'); | ||
}); | ||
|
||
// Serialize the modified DOM back to a string | ||
let modifiedHtmlString = doc.body.innerHTML; | ||
return modifiedHtmlString | ||
} |
Oops, something went wrong.