Skip to content

Commit 5f8ee56

Browse files
committed
added alt tag
1 parent 2d30814 commit 5f8ee56

File tree

16 files changed

+187
-455
lines changed

16 files changed

+187
-455
lines changed
5.49 KB
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Meta, Story } from '@storybook/blocks';
2+
import * as AltTagStories from './AltTagDemo.stories';
3+
4+
<Meta of={AltTagStories} title="Images/Alt Tags" />
5+
6+
# Alt Tag Best Practices
7+
8+
Alt tags are essential for making images accessible to screen readers and when images fail to load. Here are some key guidelines:
9+
10+
- Use empty alt tags (`alt=""`) for decorative images
11+
- Don't use phrases like "Image of" or "Picture of" - screen readers already announce that it's an image
12+
- Be concise but descriptive
13+
- Focus on the purpose and content of the image
14+
15+
## Examples
16+
17+
### Decorative Image
18+
19+
When an image is purely decorative and doesn't convey meaningful content, use an empty alt tag:
20+
21+
<Story name="Examples" args={{ altType: 'decorative' }} />
22+
23+
```html
24+
<img src="../assets/find-dhs-form.png" alt="" />
25+
```
26+
27+
### Descriptive Image
28+
29+
When an image contains important information, provide a clear, concise description:
30+
31+
<Story name="Examples" args={{ altType: 'descriptive' }} />
32+
33+
```html
34+
<img
35+
src="../assets/find-dhs-form.png"
36+
alt="Hand holding a pen writing on a printed piece of paper"
37+
/>
38+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { AltTagDemo } from './AltTagDemo';
3+
4+
const meta = {
5+
title: 'Images/Alt Tags',
6+
component: AltTagDemo,
7+
parameters: {
8+
layout: 'centered',
9+
},
10+
argTypes: {
11+
altType: {
12+
control: 'radio',
13+
options: ['decorative', 'descriptive'],
14+
description: 'Type of alt tag to demonstrate',
15+
},
16+
},
17+
} satisfies Meta<typeof AltTagDemo>;
18+
19+
export default meta;
20+
type Story = StoryObj<typeof meta>;
21+
22+
export const Examples: Story = {
23+
args: {
24+
altType: 'descriptive',
25+
},
26+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import findDhsForm from '../assets/images/find-dhs-form.jpg';
2+
3+
interface AltTagDemoProps {
4+
altType: 'decorative' | 'descriptive';
5+
}
6+
7+
export const AltTagDemo = ({ altType }: AltTagDemoProps) => {
8+
if (altType === 'decorative') {
9+
return (
10+
<div>
11+
<img
12+
src={findDhsForm}
13+
alt=""
14+
style={{ width: 'auto', height: '200px' }}
15+
/>
16+
<p>
17+
This decorative image uses an empty alt tag: <code>alt=""</code>
18+
</p>
19+
</div>
20+
);
21+
}
22+
23+
return (
24+
<div>
25+
<img
26+
src={findDhsForm}
27+
alt="Screenshot of DHS form search interface showing search filters and results"
28+
style={{ width: 'auto', height: '200px' }}
29+
/>
30+
<p>
31+
This descriptive image uses a meaningful alt tag that describes the
32+
content
33+
</p>
34+
</div>
35+
);
36+
};

storybook/src/stories/Button.stories.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

storybook/src/stories/Button.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

storybook/src/stories/ColorContrast.stories.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,34 @@ import type { Meta, StoryObj } from '@storybook/react';
22
import { ColorContrastDemo } from './ColorContrastDemo';
33

44
const meta = {
5-
title: 'Example/Color Contrast',
5+
title: 'Color/Color Contrast',
66
component: ColorContrastDemo,
77
parameters: {
88
layout: 'centered',
99
},
10-
tags: ['autodocs'],
10+
// tags: ['autodocs'],
1111
argTypes: {
1212
textColor: {
1313
control: { type: 'color' },
1414
description: 'Color of the headings',
15+
name: 'Text Color',
1516
},
1617
backgroundColor: {
1718
control: { type: 'color' },
1819
description: 'Background color of the container',
20+
name: 'Background Color',
21+
},
22+
paragraphFontSize: {
23+
control: { type: 'number', min: 8, max: 96, step: 1 },
24+
description: 'Font size of the paragraph',
25+
name: 'Paragraph Font Size',
26+
defaultValue: 16,
27+
},
28+
paragraphFontWeight: {
29+
control: { type: 'number' },
30+
description: 'Font weight of the paragraph',
31+
name: 'Paragraph Font Weight',
32+
defaultValue: 400,
1933
},
2034
},
2135
} satisfies Meta<typeof ColorContrastDemo>;
@@ -27,5 +41,7 @@ export const Default: Story = {
2741
args: {
2842
textColor: '#000000',
2943
backgroundColor: '#ffffff',
44+
paragraphFontSize: 16,
45+
paragraphFontWeight: 400,
3046
},
3147
};

storybook/src/stories/ColorContrastDemo.tsx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const getContrastRatio = (color1: string, color2: string) => {
3737
interface ColorContrastDemoProps {
3838
textColor: string;
3939
backgroundColor: string;
40+
paragraphFontSize: number;
41+
paragraphFontWeight: number;
4042
}
4143

4244
// Add new component for contrast info
@@ -92,9 +94,16 @@ const ContrastInfo = ({
9294
</div>
9395
{fontSize && weight && (
9496
<div>
95-
Font size: <strong>{fontSize.em}</strong>em /{' '}
96-
<strong>{fontSize.rem}</strong>rem / <strong>{fontSize.px}</strong>px
97-
• Font weight: <strong>{weight}</strong>
97+
<ul>
98+
<li>
99+
Font size: <strong>{fontSize.em}</strong>em /{' '}
100+
<strong>{fontSize.rem}</strong>rem /{' '}
101+
<strong>{fontSize.px}</strong>px
102+
</li>
103+
<li>
104+
Font weight: <strong>{weight}</strong>
105+
</li>
106+
</ul>
98107
</div>
99108
)}
100109
</p>
@@ -104,6 +113,8 @@ const ContrastInfo = ({
104113
export const ColorContrastDemo = ({
105114
textColor = '#000000',
106115
backgroundColor = '#ffffff',
116+
paragraphFontSize = 16,
117+
paragraphFontWeight = 400,
107118
}: ColorContrastDemoProps) => {
108119
const containerStyle = {
109120
padding: '20px',
@@ -244,7 +255,13 @@ export const ColorContrastDemo = ({
244255
<hr />
245256
</div>
246257
))}
247-
<p style={headingStyle}>
258+
<p
259+
style={{
260+
...headingStyle,
261+
fontSize: `${paragraphFontSize}px`,
262+
fontWeight: `${paragraphFontWeight}`,
263+
}}
264+
>
248265
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
249266
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
250267
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
@@ -255,9 +272,18 @@ export const ColorContrastDemo = ({
255272
</p>
256273
<ContrastInfo
257274
contrastRatio={contrastRatio}
258-
requiredRatio={4.5}
259-
fontSize={{ em: 1, rem: 1, px: 16 }}
260-
weight={400}
275+
requiredRatio={
276+
(paragraphFontSize > 18.66 && paragraphFontWeight >= 700) ||
277+
paragraphFontSize >= 24
278+
? 3
279+
: 4.5
280+
}
281+
fontSize={{
282+
em: paragraphFontSize / 16,
283+
rem: paragraphFontSize / 16,
284+
px: paragraphFontSize,
285+
}}
286+
weight={paragraphFontWeight}
261287
/>
262288
</div>
263289
</>

0 commit comments

Comments
 (0)