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

Add compact grid #758

Merged
merged 22 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ddb7eab
Add padding classes
VincentSmedinga Nov 12, 2023
3f3d118
Rename padding to space and use margin
VincentSmedinga Nov 13, 2023
3710313
Use padding again because of collapsing margins
VincentSmedinga Nov 13, 2023
b09357d
Allow start alignment of screen
VincentSmedinga Nov 14, 2023
a4fe5de
Remove explicit horizontal centring of grid
VincentSmedinga Nov 14, 2023
cc67efd
Implement dense grid
VincentSmedinga Nov 16, 2023
f19c3ba
Add documentation
VincentSmedinga Nov 16, 2023
fdb0bb2
Make spacing a local prop for Grid for now
VincentSmedinga Nov 16, 2023
7f03def
Document vertical spacing
VincentSmedinga Nov 16, 2023
e2cf93c
Rename ‘space’ to ‘margin’
VincentSmedinga Nov 16, 2023
c24db19
Finish rename
VincentSmedinga Nov 16, 2023
1db4ea5
Prevent using vertical margin together with top or bottom
VincentSmedinga Nov 16, 2023
bdc38a4
Update design documentation
VincentSmedinga Nov 16, 2023
a786c41
Remove unnecessary test
VincentSmedinga Nov 16, 2023
132d144
Halve the number of margin classes with local custom properties
VincentSmedinga Nov 16, 2023
1791e58
Add compact story and a control for density
VincentSmedinga Nov 16, 2023
3a8de05
Revert "Allow start alignment of screen"
VincentSmedinga Nov 16, 2023
773ff2a
Improve documentation and story controls
VincentSmedinga Nov 17, 2023
c60c03b
Capitalise column headers
VincentSmedinga Nov 17, 2023
3880f94
Rename ‘margin’ to ‘padding’
VincentSmedinga Nov 17, 2023
cf2ecac
Remove docs covered by TypeScript types
VincentSmedinga Nov 17, 2023
e373c9e
Merge branch 'main' into feature/DES-450-compact-grid
VincentSmedinga Nov 17, 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
5 changes: 0 additions & 5 deletions packages/css/src/footer/footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@

.amsterdam-footer__top {
background-color: var(--amsterdam-footer-top-background-color);
padding-block: 2.5rem;
}

.amsterdam-footer__bottom {
padding-block: 0.5rem;
}
45 changes: 44 additions & 1 deletion packages/css/src/grid/grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
@import "../../utils/breakpoint";

.amsterdam-grid {
--amsterdam-grid-gap: var(--amsterdam-grid-density-low-gap);
dlnr marked this conversation as resolved.
Show resolved Hide resolved
--amsterdam-grid-padding-inline: var(--amsterdam-grid-density-low-padding-inline);

display: grid;
gap: var(--amsterdam-grid-gap);
grid-template-columns: repeat(var(--amsterdam-grid-column-count), 1fr);
margin-inline: auto;
padding-inline: var(--amsterdam-grid-padding-inline);

@media screen and (min-width: $amsterdam-breakpoint-medium) {
Expand All @@ -20,3 +22,44 @@
grid-template-columns: repeat(var(--amsterdam-grid-wide-column-count), 1fr);
}
}

.amsterdam-grid--density-high {
--amsterdam-grid-gap: var(--amsterdam-grid-density-high-gap);
--amsterdam-grid-padding-inline: var(--amsterdam-grid-density-high-padding-inline);
}

.amsterdam-grid--margin-bottom--small {
padding-block-end: calc(var(--amsterdam-grid-gap) / 2);
dlnr marked this conversation as resolved.
Show resolved Hide resolved
}

.amsterdam-grid--margin-bottom--medium {
padding-block-end: var(--amsterdam-grid-gap);
}

.amsterdam-grid--margin-bottom--large {
padding-block-end: calc(var(--amsterdam-grid-gap) * 2);
}

.amsterdam-grid--margin-top--small {
padding-block-start: calc(var(--amsterdam-grid-gap) / 2);
}

.amsterdam-grid--margin-top--medium {
padding-block-start: var(--amsterdam-grid-gap);
}

.amsterdam-grid--margin-top--large {
padding-block-start: calc(var(--amsterdam-grid-gap) * 2);
}

.amsterdam-grid--margin-vertical--small {
padding-block: calc(var(--amsterdam-grid-gap) / 2);
}

.amsterdam-grid--margin-vertical--medium {
padding-block: var(--amsterdam-grid-gap);
}

.amsterdam-grid--margin-vertical--large {
padding-block: calc(var(--amsterdam-grid-gap) * 2);
}
4 changes: 0 additions & 4 deletions packages/css/src/highlight/highlight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* Copyright (c) 2023 Gemeente Amsterdam
*/

.amsterdam-highlight {
padding-block: var(--amsterdam-highlight-padding-block);
}

.amsterdam-highlight--blue {
background-color: var(--amsterdam-highlight-blue-background-color);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/css/src/screen/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

.amsterdam-screen {
@include reset;
}

.amsterdam-screen--center {
alimpens marked this conversation as resolved.
Show resolved Hide resolved
margin-inline: auto;
}

Expand Down
42 changes: 42 additions & 0 deletions packages/react/src/Grid/Grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,48 @@ describe('Grid', () => {
expect(component).toHaveClass('amsterdam-grid')
})

it('renders the high-density class name', () => {
const { container } = render(<Grid density="high" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--density-high')
})

it('renders a medium vertical spacing class name for a low-density grid', () => {
const { container } = render(<Grid marginVertical="medium" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-vertical--medium')
})

it('renders a medium vertical spacing class name for a high-density grid', () => {
const { container } = render(<Grid density="high" marginVertical="medium" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-vertical--medium')
})

it('renders a small top class name for a low-density grid', () => {
const { container } = render(<Grid marginTop="small" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-top--small')
})

it('renders a small top class name for a high-density grid', () => {
const { container } = render(<Grid density="high" marginTop="small" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-top--small')
})

it('renders a large bottom class name for a low-density grid', () => {
const { container } = render(<Grid marginBottom="large" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-bottom--large')
})

it('renders a large bottom class name for a high-density grid', () => {
const { container } = render(<Grid density="high" marginBottom="large" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--margin-bottom--large')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLDivElement>()
const { container } = render(<Grid ref={ref} />)
Expand Down
67 changes: 63 additions & 4 deletions packages/react/src/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,76 @@ export type GridColumnNumbers = {
wide: GridColumnNumber
}

interface GridComponent
extends ForwardRefExoticComponent<PropsWithChildren<HTMLAttributes<HTMLDivElement>> & RefAttributes<HTMLDivElement>> {
type GridDensity = 'low' | 'high'
dlnr marked this conversation as resolved.
Show resolved Hide resolved

type GridMarginSize = 'small' | 'medium' | 'large'
alimpens marked this conversation as resolved.
Show resolved Hide resolved

type GridMarginVerticalProp = {
marginBottom?: never
marginTop?: never
/** The amount of vertical whitespace above and below the grid. */
alimpens marked this conversation as resolved.
Show resolved Hide resolved
marginVertical?: GridMarginSize
}

type GridMarginTopAndBottomProps = {
/** The amount of vertical whitespace below the grid. */
marginBottom?: GridMarginSize
/** The amount of vertical whitespace above the grid. */
marginTop?: GridMarginSize
marginVertical?: never
}

export type GridProps = {
/**
* The density of the grid: low (for websites) or high (for applications).
* Adjusts the pace with which columns get wider, and the start width as well.
* This is to be implemented more generally – it will be moved into a theme soon.
*/
density?: GridDensity
} & (GridMarginVerticalProp | GridMarginTopAndBottomProps) &
PropsWithChildren<HTMLAttributes<HTMLDivElement>>

const marginClasses = (
marginBottom?: GridMarginSize,
marginTop?: GridMarginSize,
marginVertical?: GridMarginSize,
): string[] => {
const classes = [] as string[]

if (marginVertical) {
return [`amsterdam-grid--margin-vertical--${marginVertical}`]
}

if (marginBottom) {
classes.push(`amsterdam-grid--margin-bottom--${marginBottom}`)
}

if (marginTop) {
classes.push(`amsterdam-grid--margin-top--${marginTop}`)
}

return classes
}

interface GridComponent extends ForwardRefExoticComponent<GridProps & RefAttributes<HTMLDivElement>> {
Cell: typeof GridCell
}

export const Grid = forwardRef(
(
{ children, className, ...restProps }: PropsWithChildren<HTMLAttributes<HTMLDivElement>>,
{ children, className, density = 'low', marginBottom, marginTop, marginVertical, ...restProps }: GridProps,
dlnr marked this conversation as resolved.
Show resolved Hide resolved
ref: ForwardedRef<HTMLDivElement>,
) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-grid', className)}>
<div
{...restProps}
ref={ref}
className={clsx(
'amsterdam-grid',
density && `amsterdam-grid--density-${density}`,
marginClasses(marginBottom, marginTop, marginVertical),
className,
)}
>
{children}
</div>
),
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/Grid/GridCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type GridCellColumnProps = {
start?: GridColumnNumber | GridColumnNumbers
}

// The discriminated union and the `never` types prevent using `fullWidth` together with `span` or `start`.
export type GridCellProps = (GridCellFullWidthProp | GridCellColumnProps) &
PropsWithChildren<HTMLAttributes<HTMLDivElement>>

Expand Down
13 changes: 11 additions & 2 deletions packages/react/src/Screen/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
import clsx from 'clsx'
import { ForwardedRef, forwardRef, HTMLAttributes, PropsWithChildren } from 'react'

type ScreenAlign = 'center' | 'start'
type ScreenMaxWidth = 'wide' | 'x-wide'

export interface ScreenProps extends PropsWithChildren<HTMLAttributes<HTMLDivElement>> {
align?: ScreenAlign
maxWidth?: ScreenMaxWidth
}

export const Screen = forwardRef(
({ children, className, maxWidth = 'wide', ...restProps }: ScreenProps, ref: ForwardedRef<HTMLDivElement>) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-screen', `amsterdam-screen--${maxWidth}`, className)}>
(
{ align = 'center', children, className, maxWidth, ...restProps }: ScreenProps,
ref: ForwardedRef<HTMLDivElement>,
) => (
<div
{...restProps}
ref={ref}
className={clsx('amsterdam-screen', `amsterdam-screen--${align}`, `amsterdam-screen--${maxWidth}`, className)}
>
{children}
</div>
),
Expand Down
24 changes: 18 additions & 6 deletions proprietary/tokens/src/components/amsterdam/grid.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
"column-count": {
"value": "4"
},
"gap": {
"value": "clamp(0.5rem, 0.375rem + 3.125vw, 3.5rem)",
"comment": "Grows from 8px at 320px wide to 56px at 1440px wide."
"density-low": {
"gap": {
"value": "clamp(1rem, 3.125vw + 0.375rem, 3.5rem)",
"comment": "Grows from 16px at 320px wide to 56px at 1600px wide."
},
"padding-inline": {
"value": "clamp(1.5rem, 4.6875vw + 0.5625rem, 5.25rem)",
"comment": "Equals 1.5 times the gap."
}
},
"padding-inline": {
"value": "clamp(0.75rem, 0.5625rem + 4.875vw, 5.25rem)",
"comment": "Equals 1.5 times the gap."
"density-high": {
"gap": {
"value": "clamp(1rem, 1.5625vw - 0.0625rem, 2.5rem)",
"comment": "Grows from 16px at 1088px wide to 40px at 2624px wide."
},
"padding-inline": {
"value": "clamp(1rem, 1.5625vw - 0.0625rem, 2.5rem)",
"comment": "Equals the gap."
}
},
"medium": {
"column-count": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"amsterdam": {
"highlight": {
"padding-block": {
"value": "2rem"
},
"blue": {
"background-color": {
"value": "{amsterdam.color.primary-blue}"
Expand Down
Loading