Skip to content

Commit

Permalink
Add documentation for the Gap utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga committed Jul 22, 2024
1 parent 38cc30f commit c69d6c7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/css/src/components/gap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

# Gap

Use these utility classes to add consistent white space between a set of elements.
Adds white space between a set of elements.

The five sizes of [Component Space](/docs/foundation-design-tokens-space--docs) are available for the length of the gap.

## Guidelines

- Use this utility class to vertically separate the children of a parent element from each other.
- It can be used on any element and sets the `gap` CSS property.
It also makes the element a grid container; the gap would be ignored otherwise.
These declarations are marked with the `!important` flag to ensure they override any other gaps and display modes.
- To add a gap between 2 siblings, the first one can be given a [Margin Bottom](/docs/utilities-css-margin--docs) instead.
This may be preferable because it doesn’t change the parent’s display mode.
6 changes: 4 additions & 2 deletions packages/css/src/components/gap/gap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
}

@each $size in map-keys($ams-sizes) {
.ams-gap--#{$size} {
gap: var(--ams-gap-#{$size}) !important;
@if $size != "no" {
.ams-gap--#{$size} {
grid-gap: var(--ams-gap-#{$size}) !important;
}
}
}
13 changes: 13 additions & 0 deletions storybook/src/utils/Gap/Gap.docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{/* @license CC0-1.0 */}

import { Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import * as GapStories from "./Gap.stories.tsx";
import README from "../../../../packages/css/src/components/gap/README.md?raw";

<Meta of={GapStories} />

<Markdown>{README}</Markdown>

<Primary />

<Controls />
46 changes: 46 additions & 0 deletions storybook/src/utils/Gap/Gap.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/

import { Meta, StoryObj } from '@storybook/react'
import type { HTMLAttributes } from 'react'

type GapProps = {
length: (typeof lengthOptions)[number]
} & HTMLAttributes<HTMLElement>

const lengthOptions = ['xs', 'sm', 'md', 'lg', 'xl'] as const

const Gap = ({ children, length }: GapProps) => <span className={`ams-gap--${length}`}>{children}</span>

const render = ({ length }: GapProps) => (
<div className={`ams-gap--${length}`}>
<p className="ams-paragraph">These paragraphs are separated by a gap.</p>
<p className="ams-paragraph">These paragraphs are separated by a gap.</p>
<p className="ams-paragraph">These paragraphs are separated by a gap.</p>
</div>
)

const meta = {
title: 'Utilities/CSS/Gap',
component: Gap,
args: {
length: 'xs',
},
argTypes: {
length: {
control: 'radio',
description: 'The amount of white space to add between the children.',
options: ['xs', 'sm', 'md', 'lg', 'xl'],
},
},
} satisfies Meta<typeof Gap>

export default meta

type Story = StoryObj<typeof meta>

export const Default: Story = {
render,
}

0 comments on commit c69d6c7

Please sign in to comment.