-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Column component and Gap and Margin utilities for vertical …
…spacing (#1083) Co-authored-by: Aram <[email protected]>
- Loading branch information
1 parent
c6bccd6
commit d092cb3
Showing
35 changed files
with
399 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline | |
* Adjust size of breadcrumb separator and allow natural text wrapping ([#913](https://github.com/Amsterdam/design-system/issues/913)) ([caba940](https://github.com/Amsterdam/design-system/commit/caba94024c5aedf9092a5afbbf625d921fd124b5)) | ||
* Improve examples and documentation for cards ([#936](https://github.com/Amsterdam/design-system/issues/936)) ([0f91370](https://github.com/Amsterdam/design-system/commit/0f913702de12cb7b9ca50e8f9da4899c3d934320)) | ||
* Merge grid cell files into grid files and directories ([#815](https://github.com/Amsterdam/design-system/issues/815)) ([f4b4ec5](https://github.com/Amsterdam/design-system/commit/f4b4ec5de92d283ee2ef083075297a64b3dfd1cb)) | ||
* Resolve malformed outline and remove excessive whitespace on dialog ([#937](https://github.com/Amsterdam/design-system/issues/937)) ([1fc264a](https://github.com/Amsterdam/design-system/commit/1fc264ac577edaa92e37d4c7e81427dd75b6dbe7)) | ||
* Resolve malformed outline and remove excessive white space on dialog ([#937](https://github.com/Amsterdam/design-system/issues/937)) ([1fc264a](https://github.com/Amsterdam/design-system/commit/1fc264ac577edaa92e37d4c7e81427dd75b6dbe7)) | ||
* Use rems for checkbox underline ([#944](https://github.com/Amsterdam/design-system/issues/944)) ([8622326](https://github.com/Amsterdam/design-system/commit/8622326b8686856c44ad03856bac886ee4e5632b)) | ||
|
||
## [0.2.0](https://github.com/Amsterdam/design-system/compare/@amsterdam/[email protected]...@amsterdam/[email protected]) (2023-12-01) | ||
|
@@ -81,7 +81,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline | |
|
||
* Add common link tokens and use them in all link-like components ([#814](https://github.com/Amsterdam/design-system/issues/814)) ([9b5bd55](https://github.com/Amsterdam/design-system/commit/9b5bd55d0b118f246b828e023b75be1e84f98af4)) | ||
* Allow end-alignment on page menu ([#835](https://github.com/Amsterdam/design-system/issues/835)) ([035ca08](https://github.com/Amsterdam/design-system/commit/035ca08842ee8ad955b260fb26693fe739801df4)) | ||
* Allow small and large vertical whitespace on grids ([#821](https://github.com/Amsterdam/design-system/issues/821)) ([aa54eb9](https://github.com/Amsterdam/design-system/commit/aa54eb911bfed633856a74e0be4e11d4ad8f3ebc)) | ||
* Allow small and large vertical white space on grids ([#821](https://github.com/Amsterdam/design-system/issues/821)) ([aa54eb9](https://github.com/Amsterdam/design-system/commit/aa54eb911bfed633856a74e0be4e11d4ad8f3ebc)) | ||
* Update typography system and values, implement compact theme ([#803](https://github.com/Amsterdam/design-system/issues/803)) ([9b087ec](https://github.com/Amsterdam/design-system/commit/9b087ec5c6e75dfafadcdcde710747ef63951917)) | ||
|
||
## [0.1.9](https://github.com/Amsterdam/design-system/compare/@amsterdam/[email protected]...@amsterdam/[email protected]) (2023-11-27) | ||
|
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,13 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
/** The set of available options for sizing. */ | ||
$amsterdam-sizes: ( | ||
"xs": "extra-small", | ||
"sm": "small", | ||
"md": "medium", | ||
"lg": "large", | ||
"xl": "extra-large", | ||
); |
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,3 @@ | ||
# Column | ||
|
||
Stacks its children vertically and adds a vertical gap between them. |
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,16 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
@import "../../common/size"; | ||
|
||
.amsterdam-column { | ||
display: grid; | ||
} | ||
|
||
@each $size, $label in $amsterdam-sizes { | ||
.amsterdam-column--#{$label} { | ||
gap: var(--amsterdam-column-gap-#{$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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Gap | ||
|
||
Use these utility classes to add consistent white space between a set of elements. |
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,16 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
@import "../../common/size"; | ||
|
||
[class|="amsterdam-gap-"] { | ||
display: grid !important; | ||
} | ||
|
||
@each $size in map-keys($amsterdam-sizes) { | ||
.amsterdam-gap--#{$size} { | ||
gap: var(--amsterdam-gap-#{$size}) !important; | ||
} | ||
} |
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
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,3 @@ | ||
# Margin | ||
|
||
Use these utility classes to add white space below a single element. |
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,12 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
@import "../../common/size"; | ||
|
||
@each $size in map-keys($amsterdam-sizes) { | ||
.amsterdam-mb--#{$size} { | ||
margin-block-end: var(--amsterdam-margin-#{$size}) !important; | ||
} | ||
} |
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
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,67 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { Column, columnGapSizes } from './Column' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Column', () => { | ||
it('renders', () => { | ||
const { container } = render(<Column />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<Column />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('amsterdam-column--medium') | ||
}) | ||
|
||
columnGapSizes.map((size) => | ||
it('renders with ${size} gap', () => { | ||
const { container } = render(<Column gap={size} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass(`amsterdam-column--${size}`) | ||
}), | ||
) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<Column className="extra" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('amsterdam-column--medium extra') | ||
}) | ||
|
||
it('renders with an article tag', () => { | ||
render(<Column as="article" />) | ||
|
||
const component = screen.getByRole('article') | ||
|
||
expect(component).toBeInTheDocument() | ||
}) | ||
|
||
it('renders with a section tag', () => { | ||
const { container } = render(<Column as="section" />) | ||
|
||
const component = container.querySelector('section') | ||
|
||
expect(component).toBeInTheDocument() | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLDivElement>() | ||
|
||
const { container } = render(<Column ref={ref} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(ref.current).toBe(component) | ||
}) | ||
}) |
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,33 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export const columnGapSizes: Array<string> = ['extra-small', 'small', 'medium', 'large', 'extra-large'] | ||
|
||
type ColumnTag = 'article' | 'div' | 'section' | ||
type ColumnGap = (typeof columnGapSizes)[number] | ||
|
||
export type ColumnProps = { | ||
/** The element to render the column with. */ | ||
as?: ColumnTag | ||
/** The amount of vertical space between the column’s children. */ | ||
gap?: ColumnGap | ||
} & PropsWithChildren<HTMLAttributes<HTMLDivElement>> | ||
|
||
export const Column = forwardRef( | ||
( | ||
{ as: Tag = 'div', children, className, gap = 'medium', ...restProps }: ColumnProps, | ||
ref: ForwardedRef<HTMLDivElement>, | ||
) => ( | ||
<Tag {...restProps} ref={ref} className={clsx('amsterdam-column', `amsterdam-column--${gap}`, className)}> | ||
{children} | ||
</Tag> | ||
), | ||
) | ||
|
||
Column.displayName = 'Column' |
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,3 @@ | ||
# React Column component | ||
|
||
[Column documentation](../../../css/src/components/column/README.md) |
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,2 @@ | ||
export { Column } from './Column' | ||
export type { ColumnProps } from './Column' |
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
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
11 changes: 11 additions & 0 deletions
11
proprietary/tokens/src/brand/amsterdam/space.compact.tokens.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"amsterdam": { | ||
"space": { | ||
"xs": { "value": "clamp(0.25rem, calc(0.390625vw - 0.015625rem), 0.625rem)" }, | ||
"sm": { "value": "clamp(0.5rem, calc(0.78125vw - 0.03125rem), 1.25rem)" }, | ||
"md": { "value": "clamp(1rem, calc(1.5625vw - 0.0625rem), 2.5rem)" }, | ||
"lg": { "value": "clamp(1.5rem, calc(2.34375vw - 0.09375rem), 3.75rem)" }, | ||
"xl": { "value": "clamp(2rem, calc(3.125vw - 0.125rem), 5rem)" } | ||
} | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"amsterdam": { | ||
"space": { | ||
"xs": { "value": "clamp(0.25rem, calc(0.78125vw + 0.09375rem), 0.875rem)" }, | ||
"sm": { "value": "clamp(0.5rem, calc(1.5625vw + 0.1875rem), 1.75rem)" }, | ||
"md": { "value": "clamp(1rem, calc(3.125vw + 0.375rem), 3.5rem)" }, | ||
"lg": { "value": "clamp(1.5rem, calc(4.6875vw + 0.5625rem), 5.25rem)" }, | ||
"xl": { "value": "clamp(2rem, calc(6.25vw + 0.75rem), 7rem)" } | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
proprietary/tokens/src/components/amsterdam/column.tokens.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"amsterdam": { | ||
"column": { | ||
"gap": { | ||
"xs": { "value": "{amsterdam.space.xs}" }, | ||
"sm": { "value": "{amsterdam.space.sm}" }, | ||
"md": { "value": "{amsterdam.space.md}" }, | ||
"lg": { "value": "{amsterdam.space.lg}" }, | ||
"xl": { "value": "{amsterdam.space.xl}" } | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
proprietary/tokens/src/components/amsterdam/gap.tokens.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"amsterdam": { | ||
"gap": { | ||
"xs": { "value": "{amsterdam.space.xs}" }, | ||
"sm": { "value": "{amsterdam.space.sm}" }, | ||
"md": { "value": "{amsterdam.space.md}" }, | ||
"lg": { "value": "{amsterdam.space.lg}" }, | ||
"xl": { "value": "{amsterdam.space.xl}" } | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
proprietary/tokens/src/components/amsterdam/margin.tokens.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"amsterdam": { | ||
"margin": { | ||
"xs": { "value": "{amsterdam.space.xs}" }, | ||
"sm": { "value": "{amsterdam.space.sm}" }, | ||
"md": { "value": "{amsterdam.space.md}" }, | ||
"lg": { "value": "{amsterdam.space.lg}" }, | ||
"xl": { "value": "{amsterdam.space.xl}" } | ||
} | ||
} | ||
} |
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,7 +1,7 @@ | ||
{ | ||
"amsterdam": { | ||
"mark": { | ||
"background-color": { "value": "var(--amsterdam-color-yellow)" } | ||
"background-color": { "value": "{amsterdam.color.yellow}" } | ||
} | ||
} | ||
} |
Oops, something went wrong.