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: Correct layout of Description List if multiple terms share a description #1763

Merged
merged 23 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b926bec
Inline style to prevent row skip
dlnr Nov 26, 2024
56a4d48
Fixed it and gave it a story
dlnr Nov 26, 2024
64575b5
inline html
dlnr Nov 26, 2024
425fa29
A solution using groups and no subgrid
dlnr Nov 26, 2024
11d1d5e
The tests
dlnr Nov 26, 2024
7e39a94
Align dd on first row of group if there are multiple terms
dlnr Dec 4, 2024
ae5e76d
Merge branch 'develop' into feature/DES-998-multiple-terms
VincentSmedinga Dec 4, 2024
25d4a27
Apply suggestions from code review
dlnr Dec 4, 2024
3142a2a
Refactor description list grid layout and update storybook examples f…
dlnr Dec 5, 2024
4bb4506
Seems like to only way to fix this is an inline style
dlnr Dec 5, 2024
7d53b0d
Add support for subgrid alignment in description list groups
dlnr Dec 5, 2024
3501236
Increase specificity for subgrid alignment in description list groups
dlnr Dec 5, 2024
1804de0
Update documentation for DescriptionList to clarify subgrid compatibi…
dlnr Dec 5, 2024
6bab918
Rename DescriptionListGroup to DescriptionListSection and update rela…
dlnr Dec 5, 2024
8b2750e
Refactor DescriptionList story to remove unnecessary keys from terms
dlnr Dec 5, 2024
5dfe987
Update tests to reflect renaming of DescriptionListGroup to Descripti…
dlnr Dec 10, 2024
f4ad94b
Refactor DescriptionList styles and documentation to enhance grid lay…
dlnr Dec 11, 2024
322fee1
Remove @supports
dlnr Dec 11, 2024
e1700c9
Merge branch 'develop' into feature/DES-998-multiple-terms
VincentSmedinga Dec 11, 2024
58ad1cd
Any element or class would also work the other way around
dlnr Dec 11, 2024
6323d4f
Merge branch 'feature/DES-998-multiple-terms' of https://github.com/A…
dlnr Dec 11, 2024
b536cd1
Applied suggestions
dlnr Dec 13, 2024
77e3c24
Merge branch 'develop' into feature/DES-998-multiple-terms
VincentSmedinga Dec 13, 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
34 changes: 28 additions & 6 deletions packages/css/src/components/description-list/description-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
margin-block: 0;
}

@mixin reset-dd {
margin-inline: 0;
}

.ams-description-list {
box-sizing: border-box;
color: var(--ams-description-list-color);
Expand All @@ -25,19 +29,23 @@
}

@media screen and (min-width: $ams-breakpoint-medium) {
.ams-description-list {
.ams-description-list,
.ams-description-list__section {
grid-template-columns: auto 1fr;
}

.ams-description-list--terms-width-sm {
.ams-description-list--terms-width-sm,
.ams-description-list--terms-width-sm .ams-description-list__section {
grid-template-columns: 1fr 4fr;
}

.ams-description-list--terms-width-md {
.ams-description-list--terms-width-md,
.ams-description-list--terms-width-md .ams-description-list__section {
grid-template-columns: 1fr 2fr;
}

.ams-description-list--terms-width-lg {
.ams-description-list--terms-width-lg,
.ams-description-list--terms-width-lg .ams-description-list__section {
grid-template-columns: 1fr 1fr;
}
}
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -54,8 +62,22 @@
}
}

@mixin reset-dd {
margin-inline: 0;
.ams-description-list__section {
@media screen and (min-width: $ams-breakpoint-medium) {
column-gap: var(--ams-description-list-column-gap);
display: grid;
grid-column: span 2;

:only-of-type {
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
grid-row: 1 / 9;
}
}
}

// Solution for browsers that support subgrid, the group will align to the parent grid
// This selector is to increase specificity to override the previously set grid-template-columns
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
.ams-description-list .ams-description-list__section {
grid-template-columns: subgrid;
}

.ams-description-list__description {
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/DescriptionList/DescriptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'
import { DescriptionListDescription } from './DescriptionListDescription'
import { DescriptionListSection } from './DescriptionListSection'
import { DescriptionListTerm } from './DescriptionListTerm'

export const descriptionListTermsWidths = ['sm', 'md', 'lg'] as const
Expand Down Expand Up @@ -42,6 +43,7 @@ const DescriptionListRoot = forwardRef(
DescriptionListRoot.displayName = 'DescriptionList'

export const DescriptionList = Object.assign(DescriptionListRoot, {
Term: DescriptionListTerm,
Description: DescriptionListDescription,
Section: DescriptionListSection,
Term: DescriptionListTerm,
})
41 changes: 41 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListSection.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 Section', () => {
it('renders', () => {
const { container } = render(<DescriptionList.Section>Test</DescriptionList.Section>)

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

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

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

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

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

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

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

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

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

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

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

expect(ref.current).toBe(component)
})
})
20 changes: 20 additions & 0 deletions packages/react/src/DescriptionList/DescriptionListSection.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 DescriptionListSectionProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>>

export const DescriptionListSection = forwardRef(
({ children, className, ...restProps }: DescriptionListSectionProps, ref: ForwardedRef<HTMLDivElement>) => (
<div {...restProps} ref={ref} className={clsx('ams-description-list__section', className)}>
{children}
</div>
),
)

DescriptionListSection.displayName = 'DescriptionList.Section'
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ A term may have multiple descriptions.

<Canvas of={DescriptionListStories.MultipleDescriptions} />

### Multiple terms

If multiple terms share a single description, group them in a `DescriptionList.Section` component to ensure proper grid layout.

<Canvas of={DescriptionListStories.MultipleTerms} />

### Rich description

A description can include rich content such as inline formatting, links, paragraphs, and even lists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ export const MultipleDescriptions: Story = {
},
}

export const MultipleTerms: Story = {
args: {
termsWidth: 'md',
children: [
<DescriptionList.Term key={1}>Achternaam</DescriptionList.Term>,
<DescriptionList.Description key={2}>
De naam die een persoon van zijn of haar ouders krijgt
</DescriptionList.Description>,
<DescriptionList.Section key={3}>
<DescriptionList.Term>Voornaam</DescriptionList.Term>
<DescriptionList.Term>Roepnaam</DescriptionList.Term>
<DescriptionList.Term>Bijnaam</DescriptionList.Term>
<DescriptionList.Description>De naam waarmee een persoon wordt aangesproken</DescriptionList.Description>
</DescriptionList.Section>,
<DescriptionList.Term key={4}>Geboortedatum</DescriptionList.Term>,
<DescriptionList.Description key={5}>De datum waarop een persoon is geboren</DescriptionList.Description>,
],
},
}

export const RichDescription: Story = {
render: (args) => (
<DescriptionList {...args}>
Expand Down
Loading