-
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.
Merge branch 'develop' into feat/DES-884-update-header
- Loading branch information
Showing
15 changed files
with
280 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# Figure | ||
|
||
Groups media content with a caption that describes it. |
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 Gemeente Amsterdam | ||
*/ | ||
|
||
@use "../../common/text-rendering" as *; | ||
|
||
@mixin reset-figure { | ||
margin-block: 0; | ||
margin-inline: 0; | ||
} | ||
|
||
.ams-figure { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--ams-figure-gap); | ||
|
||
@include reset-figure; | ||
} | ||
|
||
.ams-figure__caption { | ||
color: var(--ams-figure-caption-color); | ||
font-family: var(--ams-figure-caption-font-family); | ||
font-size: var(--ams-figure-caption-font-size); | ||
font-weight: var(--ams-figure-caption-font-weight); | ||
line-height: var(--ams-figure-caption-line-height); | ||
|
||
@include text-rendering; | ||
} | ||
|
||
.ams-figure__caption--inverse-color { | ||
color: var(--ams-figure-caption-inverse-color); | ||
} |
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,41 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { Figure } from './Figure' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Figure', () => { | ||
it('renders', () => { | ||
render(<Figure />) | ||
|
||
const component = screen.getByRole('figure') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
render(<Figure />) | ||
|
||
const component = screen.getByRole('figure') | ||
|
||
expect(component).toHaveClass('ams-figure') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
render(<Figure className="extra" />) | ||
|
||
const component = screen.getByRole('figure') | ||
|
||
expect(component).toHaveClass('ams-figure extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLElement>() | ||
|
||
render(<Figure ref={ref} />) | ||
|
||
const component = screen.getByRole('figure') | ||
|
||
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,21 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
import { FigureCaption } from './FigureCaption' | ||
|
||
export type FigureProps = PropsWithChildren<HTMLAttributes<HTMLElement>> | ||
|
||
const FigureRoot = forwardRef(({ children, className, ...restProps }: FigureProps, ref: ForwardedRef<HTMLElement>) => ( | ||
<figure {...restProps} ref={ref} className={clsx('ams-figure', className)}> | ||
{children} | ||
</figure> | ||
)) | ||
|
||
FigureRoot.displayName = 'Figure' | ||
|
||
export const Figure = Object.assign(FigureRoot, { Caption: FigureCaption }) |
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,49 @@ | ||
import { render } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { FigureCaption } from './FigureCaption' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Figure Caption', () => { | ||
it('renders', () => { | ||
const { container } = render(<FigureCaption />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<FigureCaption />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption') | ||
}) | ||
|
||
it('renders the right inverse color class', () => { | ||
const { container } = render(<FigureCaption inverseColor>Caption</FigureCaption>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption--inverse-color') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<FigureCaption className="extra" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLElement>() | ||
|
||
const { container } = render(<FigureCaption 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,27 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export type FigureCaptionProps = { | ||
/** Changes the text colour for readability on a dark background. */ | ||
inverseColor?: boolean | ||
} & PropsWithChildren<HTMLAttributes<HTMLElement>> | ||
|
||
export const FigureCaption = forwardRef( | ||
({ children, className, inverseColor, ...restProps }: FigureCaptionProps, ref: ForwardedRef<HTMLElement>) => ( | ||
<figcaption | ||
{...restProps} | ||
ref={ref} | ||
className={clsx('ams-figure__caption', inverseColor && 'ams-figure__caption--inverse-color', className)} | ||
> | ||
{children} | ||
</figcaption> | ||
), | ||
) | ||
|
||
FigureCaption.displayName = 'Figure.Caption' |
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,5 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# React Figure component | ||
|
||
[Figure documentation](../../../css/src/components/figure/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 { Figure } from './Figure' | ||
export type { FigureProps } from './Figure' |
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,15 @@ | ||
{ | ||
"ams": { | ||
"figure": { | ||
"gap": { "value": "{ams.space.sm}" }, | ||
"caption": { | ||
"color": { "value": "{ams.brand.color.neutral.100}" }, | ||
"font-family": { "value": "{ams.text.font-family}" }, | ||
"font-size": { "value": "{ams.text.level.6.font-size}" }, | ||
"font-weight": { "value": "{ams.text.font-weight.normal}" }, | ||
"line-height": { "value": "{ams.text.level.6.line-height}" }, | ||
"inverse-color": { "value": "{ams.brand.color.neutral.0}" } | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
{/* @license CC0-1.0 */} | ||
|
||
import { Canvas, Markdown, Meta, Primary } from "@storybook/blocks"; | ||
import * as FigureStories from "./Figure.stories.tsx"; | ||
import README from "../../../../packages/css/src/components/figure/README.md?raw"; | ||
|
||
<Meta of={FigureStories} /> | ||
|
||
<Markdown>{README}</Markdown> | ||
|
||
<Primary /> | ||
|
||
## Examples | ||
|
||
### Inverse colour | ||
|
||
Set the `inverseColor` prop if the Figure Caption sits on a dark background. | ||
This ensures the colour of the text provides enough contrast. | ||
|
||
<Canvas of={FigureStories.InverseColour} /> |
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,45 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import { Image } from '@amsterdam/design-system-react' | ||
import { Figure } from '@amsterdam/design-system-react/src' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { exampleCaption } from '../shared/exampleContent' | ||
|
||
const caption = exampleCaption() | ||
|
||
const meta = { | ||
title: 'Components/Media/Figure', | ||
component: Figure, | ||
args: { | ||
children: caption, | ||
inverseColor: false, | ||
}, | ||
render: ({ children, ...args }) => ( | ||
<Figure> | ||
<Image | ||
alt="" | ||
aspectRatio="2x-wide" | ||
sizes="(max-width: 36rem) 640px, (max-width: 68rem) 1280px, 1600px" | ||
src="https://picsum.photos/1600/500" | ||
srcSet="https://picsum.photos/640/200 640w, https://picsum.photos/1280/400 1280w, https://picsum.photos/1600/500 1600w" | ||
/> | ||
<Figure.Caption {...args}>{children}</Figure.Caption> | ||
</Figure> | ||
), | ||
} satisfies Meta<typeof Figure.Caption> | ||
// We use the Caption type here to allow inverseColor. This works as long as Figure has no props of its own. | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = {} | ||
|
||
export const InverseColour: Story = { | ||
args: { | ||
inverseColor: true, | ||
}, | ||
} |
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