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

fix: Merge grid cell files into grid files and directories #815

Merged
merged 25 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ad6741
Merge cell files into the grid ones
VincentSmedinga Nov 30, 2023
59ecd76
Improve docs and format Markdown
VincentSmedinga Nov 26, 2023
d68c66d
Grid Cell actions with ArgTypes
dlnr Nov 28, 2023
119901c
Radios looks better inline
dlnr Nov 28, 2023
6f14ac9
Fullwidth bug when defined
dlnr Nov 28, 2023
c99cc38
Add missing control options for span and start
VincentSmedinga Nov 30, 2023
1fd3274
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Nov 30, 2023
413c058
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 5, 2023
30cf944
Merge Cell component into Grid file and stop exporting it individually
VincentSmedinga Dec 5, 2023
0b989a8
WIP Attempt to hide the ‘Grid Cell’ entry from the sidebar
VincentSmedinga Dec 6, 2023
6fa3288
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 8, 2023
e0b0da5
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 8, 2023
3bb7cd6
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 8, 2023
5b77c1d
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 11, 2023
4be1604
Move grid cell stories into grid docs
VincentSmedinga Dec 11, 2023
6344238
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 12, 2023
8dfb930
Apply BEM to grid cell class names
VincentSmedinga Dec 13, 2023
2c625d4
Remove unused Storybook config
VincentSmedinga Dec 13, 2023
d169c02
Fix earlier incorrect merge
VincentSmedinga Dec 13, 2023
2f69f45
Fix a line in docs
VincentSmedinga Dec 13, 2023
acdc2c7
Remove Dutch labels for stories
VincentSmedinga Dec 13, 2023
710e8a6
Improve grid docs
VincentSmedinga Dec 15, 2023
56a8d8a
Move grid cell component into its own file
VincentSmedinga Dec 15, 2023
b081434
Reuse array of grid cells
VincentSmedinga Dec 15, 2023
4e894d9
Merge branch 'develop' into refactor/merge-grid-and-cell
VincentSmedinga Dec 15, 2023
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
14 changes: 0 additions & 14 deletions packages/css/src/components/grid/README.grid-cell.md

This file was deleted.

17 changes: 0 additions & 17 deletions packages/css/src/components/grid/README.grid.md

This file was deleted.

21 changes: 21 additions & 0 deletions packages/css/src/components/grid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Grid

Verdeelt de breedte van het scherm in kolommen waarop de elementen van een pagina worden uitgelijnd.

## Gebruik

Elke pagina moet het grid gebruiken als basis voor de layout.
Het staat dus direct binnen [Screen](?path=/docs/layout-screen--docs).

Een [Footer](?path=/docs/react_containers-footer--docs) en een [Highlight](?path=/docs/react_containers-highlight--docs) zijn iets breder dan het grid.
Vóór deze componenten sluit je een instantie van het grid af.
Erbinnen en eventueel erna start je een nieuwe.
Meerdere instanties van het grid component zijn dus mogelijk op een pagina.
De kolommen van alle grids moeten wel precies op elkaar aansluiten.

Binnen het grid maak je cellen die de gewenste inhoud bevatten.
Een cel beslaat vaak meerdere kolommen van het grid.

## Ontwerp

De [ontwerpkeuzes](?path=/docs/docs-designrichtlijnen-grid--docs) staan beschreven onder de designrichtlijnen.
46 changes: 0 additions & 46 deletions packages/css/src/components/grid/grid-cell.scss

This file was deleted.

40 changes: 40 additions & 0 deletions packages/css/src/components/grid/grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,43 @@
.amsterdam-grid--padding-vertical--large {
padding-block: calc(var(--amsterdam-grid-gap) * 2);
}

.amsterdam-grid__cell--full-width {
grid-column: 1 / -1;
}

// The order of the following declaration blocks ensures the intended specificity.

@for $i from 1 through 12 {
.amsterdam-grid__cell--span-#{$i} {
grid-column-end: span $i;
}

.amsterdam-grid__cell--start-#{$i} {
grid-column-start: $i;
}
}

@media screen and (min-width: $amsterdam-breakpoint-medium) {
@for $i from 1 through 12 {
.amsterdam-grid__cell--span-#{$i}-medium {
grid-column-end: span $i;
}

.amsterdam-grid__cell--start-#{$i}-medium {
grid-column-start: $i;
}
}
}

@media screen and (min-width: $amsterdam-breakpoint-wide) {
@for $i from 1 through 12 {
.amsterdam-grid__cell--span-#{$i}-wide {
grid-column-end: span $i;
}

.amsterdam-grid__cell--start-#{$i}-wide {
grid-column-start: $i;
}
}
}
1 change: 0 additions & 1 deletion packages/css/src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@import "./checkbox/checkbox";
@import "./form-label/form-label";
@import "./grid/grid";
@import "./grid/grid-cell";
@import "./heading/heading";
@import "./spotlight/spotlight";
@import "./icon/icon";
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ export const Grid = forwardRef(

Grid.Cell = GridCell
Grid.displayName = 'Grid'
GridCell.displayName = 'Grid.Cell'
20 changes: 10 additions & 10 deletions packages/react/src/Grid/GridCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('Grid.Cell', () => {
it('renders a design system BEM class name', () => {
const { container } = render(<Grid.Cell />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid-cell')
expect(component).toHaveClass('amsterdam-grid__cell')
})

it('renders an additional class name', () => {
const { container } = render(<Grid.Cell className="extra" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid-cell extra')
expect(component).toHaveClass('amsterdam-grid__cell extra')
})

it('supports ForwardRef in React', () => {
Expand All @@ -32,43 +32,43 @@ describe('Grid.Cell', () => {

it('renders no class names for undefined values for start and span', () => {
const { container } = render(<Grid.Cell />)
const elementWithSpanClass = container.querySelector('[class*="amsterdam-grid-cell--span"]')
const elementWithStartClass = container.querySelector('[class*="amsterdam-grid-cell--start"]')
const elementWithSpanClass = container.querySelector('[class*="amsterdam-grid__cell--span"]')
const elementWithStartClass = container.querySelector('[class*="amsterdam-grid__cell--start"]')
expect(elementWithSpanClass).not.toBeInTheDocument()
expect(elementWithStartClass).not.toBeInTheDocument()
})

it('renders class names for single number values for start and span', () => {
const { container } = render(<Grid.Cell span={4} start={2} />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid-cell--span-4 amsterdam-grid-cell--start-2')
expect(component).toHaveClass('amsterdam-grid__cell--span-4 amsterdam-grid__cell--start-2')
})

it('renders class names for a single number value for start', () => {
const { container } = render(<Grid.Cell span={8} />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid-cell--span-8')
expect(component).toHaveClass('amsterdam-grid__cell--span-8')
})

it('renders class names for a single number value for span', () => {
const { container } = render(<Grid.Cell start={6} />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid-cell--start-6')
expect(component).toHaveClass('amsterdam-grid__cell--start-6')
})

it('renders class names for a single number for span and array values for start', () => {
const { container } = render(<Grid.Cell span={8} start={{ narrow: 2, medium: 4, wide: 6 }} />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass(
'amsterdam-grid-cell--span-8 amsterdam-grid-cell--start-2 amsterdam-grid-cell--start-4-medium amsterdam-grid-cell--start-6-wide',
'amsterdam-grid__cell--span-8 amsterdam-grid__cell--start-2 amsterdam-grid__cell--start-4-medium amsterdam-grid__cell--start-6-wide',
)
})

it('renders class names for array values for span and a single number for start', () => {
const { container } = render(<Grid.Cell span={{ narrow: 3, medium: 5, wide: 7 }} start={2} />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass(
'amsterdam-grid-cell--span-3 amsterdam-grid-cell--span-5-medium amsterdam-grid-cell--span-7-wide amsterdam-grid-cell--start-2',
'amsterdam-grid__cell--span-3 amsterdam-grid__cell--span-5-medium amsterdam-grid__cell--span-7-wide amsterdam-grid__cell--start-2',
)
})

Expand All @@ -78,7 +78,7 @@ describe('Grid.Cell', () => {
)
const component = container.querySelector(':only-child')
expect(component).toHaveClass(
'amsterdam-grid-cell--span-2 amsterdam-grid-cell--span-4-medium amsterdam-grid-cell--span-6-wide amsterdam-grid-cell--start-1 amsterdam-grid-cell--start-3-medium amsterdam-grid-cell--start-5-wide',
'amsterdam-grid__cell--span-2 amsterdam-grid__cell--span-4-medium amsterdam-grid__cell--span-6-wide amsterdam-grid__cell--start-1 amsterdam-grid__cell--start-3-medium amsterdam-grid__cell--start-5-wide',
)
})
})
9 changes: 4 additions & 5 deletions packages/react/src/Grid/GridCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
* @license EUPL-1.2+
* Copyright (c) 2023 Gemeente Amsterdam
*/

import clsx from 'clsx'
import { ForwardedRef, forwardRef, HTMLAttributes, PropsWithChildren } from 'react'
import type { GridColumnNumber, GridColumnNumbers } from './Grid'
import { type ForwardedRef, forwardRef, type HTMLAttributes, type PropsWithChildren } from 'react'
import { GridColumnNumber, GridColumnNumbers } from './Grid'
import { gridCellClasses } from './gridCellClasses'

type GridCellFullWidthProp = {
Expand All @@ -32,8 +31,8 @@ export const GridCell = forwardRef(
{...restProps}
ref={ref}
className={clsx(
'amsterdam-grid-cell',
fullWidth && 'amsterdam-grid-cell--full-width',
'amsterdam-grid__cell',
fullWidth && 'amsterdam-grid__cell--full-width',
gridCellClasses(span, start),
className,
)}
Expand Down
16 changes: 8 additions & 8 deletions packages/react/src/Grid/gridCellClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ export const gridCellClasses = (span?: GridCellProps['span'], start?: GridCellPr
const classes = [] as string[]

if (typeof span === 'number') {
classes.push(`amsterdam-grid-cell--span-${span}`)
classes.push(`amsterdam-grid__cell--span-${span}`)
} else if (span) {
const { narrow, medium, wide } = span
classes.push(
`amsterdam-grid-cell--span-${narrow}`,
`amsterdam-grid-cell--span-${medium}-medium`,
`amsterdam-grid-cell--span-${wide}-wide`,
`amsterdam-grid__cell--span-${narrow}`,
`amsterdam-grid__cell--span-${medium}-medium`,
`amsterdam-grid__cell--span-${wide}-wide`,
)
}

if (typeof start === 'number') {
classes.push(`amsterdam-grid-cell--start-${start}`)
classes.push(`amsterdam-grid__cell--start-${start}`)
} else if (start) {
const { narrow, medium, wide } = start
classes.push(
`amsterdam-grid-cell--start-${narrow}`,
`amsterdam-grid-cell--start-${medium}-medium`,
`amsterdam-grid-cell--start-${wide}-wide`,
`amsterdam-grid__cell--start-${narrow}`,
`amsterdam-grid__cell--start-${medium}-medium`,
`amsterdam-grid__cell--start-${wide}-wide`,
)
}

Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/Grid/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './Grid'
export * from './GridCell'

export type { GridCellProps } from './GridCell'
Loading
Loading