-
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.
* Correct plop command in docs * Add initial Image component * Use image component in other stories * Add more applicable a11y links * Remove properties we’re not using yet * Remove empty file * Improve docs Co-authored-by: Aram <37216945+alimpens@users.noreply.github.com> --------- Co-authored-by: Aram <37216945+alimpens@users.noreply.github.com>
- Loading branch information
1 parent
752514a
commit 7e2e11f
Showing
14 changed files
with
130 additions
and
8 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
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,18 @@ | ||
# Image | ||
|
||
Toont een afbeelding. | ||
|
||
## Richtlijnen | ||
|
||
- Vergeet niet om een beschrijving van de afbeelding op te nemen in het `alt`-attribuut. | ||
Dit zorgt ervoor dat gebruikers van schermlezers deze informatie ook tot zich kunnen nemen. | ||
Daarnaast kan het helpen bij zoekmachineoptimalisatie. | ||
- Alleen voor decoratieve afbeeldingen is zo’n beschrijving niet nodig. Gebruik in dit geval `alt=""`. | ||
Denk aan afbeeldingen die weinig toevoegen aan de nabije tekst of afbeeldingen die louter bijdragen aan het ontwerp of de sfeer van de pagina (bron: [W3C Web Accessibility Initiative](https://www.w3.org/WAI/tutorials/images/decorative/)). | ||
- Zorg ervoor dat de afbeelding een beeldverhouding heeft die ondersteund wordt door het [Aspect Ratio](?path=/docs/layout-aspect-ratio--docs) component. | ||
|
||
## Relevante WCAG-eisen | ||
|
||
- [WCAG 1.1.1](https://www.w3.org/TR/WCAG22/#non-text-content): niet-tekstuele content heeft een tekstueel alternatief | ||
- [WCAG 1.4.5](https://www.w3.org/TR/WCAG22/#images-of-text): gebruik tekst in plaats van afbeeldingen van tekst | ||
- [WCAG 1.4.9](https://www.w3.org/TR/WCAG22/#images-of-text-no-exception): gebruik afbeeldingen van tekst alleen als er geen alternatief is |
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) 2023 Gemeente Amsterdam | ||
*/ | ||
|
||
.amsterdam-image { | ||
font-style: italic; /* [3] */ | ||
height: auto; /* [1] */ | ||
max-width: 100%; /* [1] */ | ||
vertical-align: middle; /* [2] */ | ||
} | ||
|
||
// [1] Allow for fluid image sizing while maintaining aspect ratio governed by width/height attributes | ||
// [2] Remove ‘phantom’ whitespace | ||
// [3] Italicise alt text to visually offset it from surrounding copy | ||
// Source: https://x.com/csswizardry/status/1717841334462005661 |
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,33 @@ | ||
import { render } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { Image } from './Image' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Image', () => { | ||
it('renders', () => { | ||
const { container } = render(<Image />) | ||
const component = container.querySelector(':only-child') | ||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<Image />) | ||
const component = container.querySelector(':only-child') | ||
expect(component).toHaveClass('amsterdam-image') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<Image className="extra" />) | ||
const component = container.querySelector(':only-child') | ||
expect(component).toHaveClass('extra') | ||
expect(component).toHaveClass('amsterdam-image') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLImageElement>() | ||
const { container } = render(<Image 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,15 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2023 Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { ForwardedRef, forwardRef, ImgHTMLAttributes } from 'react' | ||
|
||
export interface ImageProps extends ImgHTMLAttributes<HTMLImageElement> {} | ||
|
||
export const Image = forwardRef(({ className, ...restProps }: ImageProps, ref: ForwardedRef<HTMLImageElement>) => ( | ||
<img {...restProps} ref={ref} className={clsx('amsterdam-image', className)} /> | ||
)) | ||
|
||
Image.displayName = 'Image' |
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 Image component | ||
|
||
[Image documentation](../../../css/src/image/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 { Image } from './Image' | ||
export type { ImageProps } from './Image' |
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
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 @@ | ||
import { Controls, Markdown, Meta, Primary } from "@storybook/blocks"; | ||
import * as ImageStories from "./Image.stories.tsx"; | ||
import README from "../../../../packages/css/src/image/README.md?raw"; | ||
|
||
<Meta of={ImageStories} /> | ||
|
||
<Markdown>{README}</Markdown> | ||
|
||
<Primary /> | ||
|
||
<Controls /> |
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,23 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2023 Gemeente Amsterdam | ||
*/ | ||
|
||
import { Image } from '@amsterdam/design-system-react' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
const meta = { | ||
title: 'Media/Image', | ||
component: Image, | ||
} satisfies Meta<typeof Image> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
args: { | ||
alt: '', | ||
src: 'https://picsum.photos/1600/900', | ||
}, | ||
} |