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

feat: Add Description List component #1139

Merged
merged 26 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0b619d4
Add DescriptionList component
dlnr Mar 15, 2024
279f406
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Mar 15, 2024
c6a0b22
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Mar 20, 2024
dd59abe
Not all dd values are paragraphs
dlnr Mar 21, 2024
a980c1a
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Mar 21, 2024
461a38b
Breakpoints and tokens
dlnr Mar 21, 2024
0571d3c
Add inverse color style to DescriptionList component
dlnr Mar 21, 2024
3d85231
Add hyphenation to terms and details
dlnr Mar 21, 2024
9444997
Some documentation
dlnr Mar 21, 2024
42034d6
Remove console.log statement in DescriptionList component
dlnr Mar 22, 2024
a7d4c05
Update packages/css/src/components/description-list/README.md
dlnr Mar 26, 2024
81b0839
Remove unused imports and mixins
dlnr Mar 26, 2024
95c784c
Removed Row and added tests for children
dlnr Mar 27, 2024
33099a6
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Mar 27, 2024
c83e40b
Update description-list.scss with text-rendering import
dlnr Mar 27, 2024
83c689a
Update proprietary/tokens/src/components/ams/description-list.tokens.…
dlnr Mar 27, 2024
0255fe9
Update docs
VincentSmedinga Mar 27, 2024
929d981
Remove render from DescriptionList
dlnr Apr 2, 2024
a8e7bc5
Refactor description list styles and update test cases
dlnr Apr 2, 2024
b9bd5ca
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Apr 2, 2024
08b114d
Update packages/css/src/components/description-list/README.md
dlnr Apr 2, 2024
eb83c80
Refactor description list component styles and story
dlnr Apr 2, 2024
5750184
Merge branch 'feature/DES-576-description-list' of https://github.com…
dlnr Apr 2, 2024
c7855cc
Use roles DescriptionList child component tests
dlnr Apr 3, 2024
6d205dc
Add reset-details mixin to description-list.scss
dlnr Apr 3, 2024
ff9032f
Move reset to class using it
alimpens Apr 3, 2024
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
10 changes: 10 additions & 0 deletions packages/css/src/components/description-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- @license CC0-1.0 -->

# Description List

A description list is a list of terms and their details.

## References
dlnr marked this conversation as resolved.
Show resolved Hide resolved

- [MDN: `<dl>`: The Description List element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl)
- [WCAG: Using description lists](https://www.w3.org/WAI/WCAG22/Techniques/html/H40)
55 changes: 55 additions & 0 deletions packages/css/src/components/description-list/description-list.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/

@import "../../common/breakpoint";
@import "../../common/text-rendering";

@mixin reset {
box-sizing: border-box;
margin-block: 0;
margin-inline: 0;
}

.ams-description-list {
color: var(--ams-description-list-color);
display: grid;
font-family: var(--ams-description-list-font-family);
font-size: var(--ams-description-list-font-size);
font-weight: var(--ams-description-list-font-weight);
gap: var(--ams-description-list-gap);
grid-template-columns: 1fr;
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
line-height: var(--ams-description-list-line-height);

@media screen and (min-width: $ams-breakpoint-medium) {
grid-template-columns: 1fr 2fr;
}

@include reset;
}

.ams-description-list--inverse-color {
color: var(--ams-description-list-inverse-color);
}

.ams-description-list__term {
@include reset;
alimpens marked this conversation as resolved.
Show resolved Hide resolved
@include text-rendering;
alimpens marked this conversation as resolved.
Show resolved Hide resolved
}
alimpens marked this conversation as resolved.
Show resolved Hide resolved

.ams-description-list__details {
font-weight: var(--ams-description-list-details-font-weight);
padding-inline-start: var(--ams-description-list-details-padding-inline-start);

@media screen and (min-width: $ams-breakpoint-medium) {
padding-inline-start: 0;
}

@media screen and (min-width: $ams-breakpoint-medium) {
grid-column-start: 2;
}
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved

@include reset;
alimpens marked this conversation as resolved.
Show resolved Hide resolved
@include text-rendering;
}
1 change: 1 addition & 0 deletions packages/css/src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "./document/document";
@import "./avatar/avatar";
@import "./form-field-character-counter/form-field-character-counter";
@import "./description-list/description-list";
@import "./row/row";
@import "./radio/radio";
@import "./tabs/tabs";
Expand Down
49 changes: 49 additions & 0 deletions packages/react/src/DescriptionList/DescriptionList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { DescriptionList } from './DescriptionList'
import '@testing-library/jest-dom'

describe('Description list', () => {
it('renders', () => {
const { container } = render(<DescriptionList />)

const component = container.querySelector(':only-child')

expect(component).toBeInTheDocument()
expect(component).toBeVisible()
})

it('renders a design system BEM class name', () => {
const { container } = render(<DescriptionList />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list')
})

it('renders an additional class name', () => {
const { container } = render(<DescriptionList className="extra" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list extra')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLDListElement>()

const { container } = render(<DescriptionList ref={ref} />)

const component = container.querySelector(':only-child')

expect(ref.current).toBe(component)
})

it('renders the right inverse color class', () => {
const { container } = render(<DescriptionList inverseColor />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list--inverse-color')
})
})
alimpens marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions packages/react/src/DescriptionList/DescriptionList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/

import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'
import { DescriptionListDetails } from './DescriptionListDetails'
import { DescriptionListTerm } from './DescriptionListTerm'

export type DescriptionListProps = {
inverseColor?: boolean
} & PropsWithChildren<HTMLAttributes<HTMLDListElement>>

const DescriptionListRoot = forwardRef(
({ children, className, inverseColor, ...restProps }: DescriptionListProps, ref: ForwardedRef<HTMLDListElement>) => {
return (
<dl
{...restProps}
ref={ref}
className={clsx('ams-description-list', inverseColor && 'ams-description-list--inverse-color', className)}
>
{children}
</dl>
)
},
dlnr marked this conversation as resolved.
Show resolved Hide resolved
)

DescriptionListRoot.displayName = 'DescriptionList'

export const DescriptionList = Object.assign(DescriptionListRoot, {
Term: DescriptionListTerm,
Details: DescriptionListDetails,
})
41 changes: 41 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { DescriptionList } from './DescriptionList'
import '@testing-library/jest-dom'

describe('Description list details', () => {
it('renders', () => {
const { container } = render(<DescriptionList.Details>Test</DescriptionList.Details>)

const component = container.querySelector(':only-child')
alimpens marked this conversation as resolved.
Show resolved Hide resolved

expect(component).toBeInTheDocument()
expect(component).toBeVisible()
})

it('renders a design system BEM class name', () => {
const { container } = render(<DescriptionList.Details>Test</DescriptionList.Details>)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list__details')
})

it('renders an additional class name', () => {
const { container } = render(<DescriptionList.Details className="extra">Test</DescriptionList.Details>)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list__details extra')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLElement>()

const { container } = render(<DescriptionList.Details ref={ref}>Test</DescriptionList.Details>)

const component = container.querySelector(':only-child')
alimpens marked this conversation as resolved.
Show resolved Hide resolved

expect(ref.current).toBe(component)
})
})
20 changes: 20 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/

import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'

export type DescriptionListDetailsProps = PropsWithChildren<HTMLAttributes<HTMLElement>>

export const DescriptionListDetails = forwardRef(
({ children, className, ...restProps }: DescriptionListDetailsProps, ref: ForwardedRef<HTMLElement>) => (
<dd {...restProps} ref={ref} className={clsx('ams-description-list__details', className)}>
{children}
</dd>
),
)

DescriptionListDetails.displayName = 'DescriptionList.Details'
41 changes: 41 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListTerm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { DescriptionList } from './DescriptionList'
import '@testing-library/jest-dom'

describe('Description list term', () => {
it('renders', () => {
const { container } = render(<DescriptionList.Term>Test</DescriptionList.Term>)

const component = container.querySelector(':only-child')
alimpens marked this conversation as resolved.
Show resolved Hide resolved

expect(component).toBeInTheDocument()
expect(component).toBeVisible()
})

it('renders a design system BEM class name', () => {
const { container } = render(<DescriptionList.Term>Test</DescriptionList.Term>)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list__term')
})

it('renders an additional class name', () => {
const { container } = render(<DescriptionList.Term className="extra">Test</DescriptionList.Term>)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-description-list__term extra')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLElement>()

const { container } = render(<DescriptionList.Term ref={ref}>Test</DescriptionList.Term>)

const component = container.querySelector(':only-child')
alimpens marked this conversation as resolved.
Show resolved Hide resolved

expect(ref.current).toBe(component)
})
})
20 changes: 20 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListTerm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/

import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'

export type DescriptionListTermProps = PropsWithChildren<HTMLAttributes<HTMLElement>>

export const DescriptionListTerm = forwardRef(
({ children, className, ...restProps }: DescriptionListTermProps, ref: ForwardedRef<HTMLElement>) => (
<dt {...restProps} ref={ref} className={clsx('ams-description-list__term', className)}>
{children}
</dt>
),
)

DescriptionListTerm.displayName = 'DescriptionList.Term'
5 changes: 5 additions & 0 deletions packages/react/src/DescriptionList/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- @license CC0-1.0 -->

# React Description List component

[Description List documentation](../../../css/src/components/description-list/README.md)
4 changes: 4 additions & 0 deletions packages/react/src/DescriptionList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { DescriptionList } from './DescriptionList'
export type { DescriptionListProps } from './DescriptionList'
export type { DescriptionListTermProps } from './DescriptionListTerm'
export type { DescriptionListDetailsProps } from './DescriptionListDetails'
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* Append here */
export * from './Avatar'
export * from './FormFieldCharacterCounter'
export * from './DescriptionList'
export * from './Row'
export * from './Radio'
export * from './Tabs'
Expand Down
20 changes: 20 additions & 0 deletions proprietary/tokens/src/components/ams/description-list.tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"ams": {
"description-list": {
"color": { "value": "{ams.color.primary-black}" },
"font-family": { "value": "{ams.text.font-family}" },
"font-size": { "value": "{ams.text.level.5.font-size}" },
"font-weight": { "value": "{ams.text.font-weight.normal}" },
"gap": { "value": "{ams.space.stack.md}" },
"inverse-color": { "value": "{ams.color.primary-white}" },
"line-height": { "value": "{ams.text.level.5.line-height}" },
"row": {
"gap": { "value": "{ams.space.stack.md}" }
},
"details": {
"font-weight": { "value": "{ams.text.font-weight.bold}" },
"padding-inline-start": { "value": "{ams.space.inside.xl}" }
}
}
}
}
21 changes: 21 additions & 0 deletions storybook/src/components/DescriptionList/DescriptionList.docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Canvas, Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import * as DescriptionListStories from "./DescriptionList.stories.tsx";
import README from "../../../../packages/css/src/components/description-list/README.md?raw";

<Meta of={DescriptionListStories} />

<Markdown>{README}</Markdown>

<Primary />

<Controls />

## Mutiple details in a row

If needed, you can display multiple details in a row.

<Canvas of={DescriptionListStories.MultipleDetails} />

## Inverted Color

<Canvas of={DescriptionListStories.InvertedColor} />
Loading
Loading