Skip to content

Commit 57173ce

Browse files
Adding figma image component
1 parent 33304e5 commit 57173ce

File tree

4 files changed

+103
-55
lines changed

4 files changed

+103
-55
lines changed

content/components/banner.mdx

+67-55
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Banner
33
description: Banner is used to highlight important information.
44
componentId: banner
55
reactId: banner
6-
railsIds:
6+
railsIds:
77
- Primer::Alpha::Banner
88
tags:
99
- flash, alert, notification
@@ -13,20 +13,23 @@ import {Box} from '@primer/react'
1313
import ComponentLayout from '~/src/layouts/component-layout'
1414
export default ComponentLayout
1515
import {AccessibilityLink} from '~/src/components/accessibility-link'
16+
import {FigmaImage} from '~/src/components/figma-image'
1617

17-
<img
18+
<FigmaImage
1819
width="960"
19-
alt="Image displaying each variant of banner, from top: critical, warning, success, info, upsell."
20-
src="https://github.com/primer/design/assets/813754/1f221ea9-0a82-4f4f-a8eb-b1d61ef1903d"
20+
alt="Image displaying each variant of the banner component, from top: critical, warning, success, info, upsell."
21+
src="https://www.figma.com/design/YlBTqHTbdRwYQt0bfIHvGw/Interface-guidelines?node-id=2825-15487&t=5Kg6u9zn7VW7tsip-4"
2122
/>
2223

2324
## Usage
2425

2526
Banner can be used in one of two ways:
27+
2628
1. To highlight prominent information on a page.
2729
2. To communicate feedback in response to a user action.
2830

2931
### Best practices
32+
3033
Use banners sparingly and only when necessary. Banners can disrupt the user experience and should only be used when and where relevant.
3134

3235
Keep the message concise and direct. Don't use heading styling or multiple type sizes in banners, rely on the default paragraph size and use the title when appropriate.
@@ -35,30 +38,32 @@ Don't show more than one banner at a time. For more information, see this articl
3538

3639
## Anatomy
3740

38-
<img
41+
<FigmaImage
3942
width="960"
4043
alt="Anatomy of a banner, including the message, title, icon, dismiss button, primary, and secondary action"
41-
src="https://github.com/primer/design/assets/813754/40ff27e0-8d69-490a-a619-a4956828e77e"
44+
src="https://www.figma.com/design/YlBTqHTbdRwYQt0bfIHvGw/Interface-guidelines?node-id=2825-19588&t=5Kg6u9zn7VW7tsip-4"
4245
/>
4346

4447
## Options
4548

4649
### Variant
4750

4851
#### Critical
52+
4953
<Box
5054
mb={3}
5155
display="flex"
5256
alignItems="flex-start"
5357
flexDirection={['column', 'column', 'column', 'column', 'row']}
5458
sx={{gap: 4}}
5559
>
56-
Use critical banners to signal critical errors, system failures, or necessary destructive actions. Examples: form validation error summary, repo deletion confirmations.
57-
<img
58-
width="456"
59-
alt="Text within a box that has a light red outline and a lighter red background. There is a vibrant red stop icon with an exclamation point inside that comes before the text within the banner."
60-
src="https://github.com/primer/primitives/assets/813754/9c245a1e-5d59-44bf-8574-aedb06a286b7"
61-
/>
60+
Use critical banners to signal critical errors, system failures, or necessary destructive actions. Examples: form
61+
validation error summary, repo deletion confirmations.
62+
<img
63+
width="456"
64+
alt="Text within a box that has a light red outline and a lighter red background. There is a vibrant red stop icon with an exclamation point inside that comes before the text within the banner."
65+
src="https://github.com/primer/primitives/assets/813754/9c245a1e-5d59-44bf-8574-aedb06a286b7"
66+
/>
6267
</Box>
6368

6469
#### Warning
@@ -70,12 +75,13 @@ Use critical banners to signal critical errors, system failures, or necessary de
7075
flexDirection={['column', 'column', 'column', 'column', 'row']}
7176
sx={{gap: 4}}
7277
>
73-
Use warning banners to alert users about potential issues or impactful changes. For example possible connectivity concerns or hidden items due to active filters.
74-
<img
75-
width="456"
76-
alt="Text within a box that has a yellow outline and a lighter yellow background. There is a dark yellow triangle icon with an exclamation point inside that comes before the text within the banner."
77-
src="https://github.com/primer/primitives/assets/813754/afa299a9-4efe-41c4-a8cd-4e166d93e750"
78-
/>
78+
Use warning banners to alert users about potential issues or impactful changes. For example possible connectivity
79+
concerns or hidden items due to active filters.
80+
<img
81+
width="456"
82+
alt="Text within a box that has a yellow outline and a lighter yellow background. There is a dark yellow triangle icon with an exclamation point inside that comes before the text within the banner."
83+
src="https://github.com/primer/primitives/assets/813754/afa299a9-4efe-41c4-a8cd-4e166d93e750"
84+
/>
7985
</Box>
8086

8187
#### Success
@@ -87,12 +93,13 @@ Use warning banners to alert users about potential issues or impactful changes.
8793
flexDirection={['column', 'column', 'column', 'column', 'row']}
8894
sx={{gap: 4}}
8995
>
90-
Use success banners to indicate task completion or successful actions. For example, a successful issue transfer when the user is not brought to the new page. Only use success messages if the success is not easily apparent in the UI.
91-
<img
92-
width="456"
93-
alt="Text within a box that has a green outline and a lighter green background. There is a vibrant green circle icon with a check icon inside the circle that comes before the text within the banner."
94-
src="https://github.com/primer/primitives/assets/813754/5bc8b2b6-f935-4153-809a-00282ec0e1a3"
95-
/>
96+
Use success banners to indicate task completion or successful actions. For example, a successful issue transfer when
97+
the user is not brought to the new page. Only use success messages if the success is not easily apparent in the UI.
98+
<img
99+
width="456"
100+
alt="Text within a box that has a green outline and a lighter green background. There is a vibrant green circle icon with a check icon inside the circle that comes before the text within the banner."
101+
src="https://github.com/primer/primitives/assets/813754/5bc8b2b6-f935-4153-809a-00282ec0e1a3"
102+
/>
96103
</Box>
97104

98105
#### Info
@@ -104,15 +111,15 @@ Use success banners to indicate task completion or successful actions. For examp
104111
flexDirection={['column', 'column', 'column', 'column', 'row']}
105112
sx={{gap: 4}}
106113
>
107-
Use info banners to inform about non-critical context and information. For example feature prompts or ongoing processes.
108-
<img
109-
width="456"
110-
alt="Text within a box that has a light blue outline and a lighter blue background. There is a vibrant blue circle icon with the letter i inside that comes before the text within the banner."
111-
src="https://github.com/primer/design/assets/813754/172e3eb4-35ea-4d75-a015-6d00d3ebd914"
112-
/>
114+
Use info banners to inform about non-critical context and information. For example feature prompts or ongoing
115+
processes.
116+
<img
117+
width="456"
118+
alt="Text within a box that has a light blue outline and a lighter blue background. There is a vibrant blue circle icon with the letter i inside that comes before the text within the banner."
119+
src="https://github.com/primer/design/assets/813754/172e3eb4-35ea-4d75-a015-6d00d3ebd914"
120+
/>
113121
</Box>
114122

115-
116123
#### Upsell
117124

118125
<Box
@@ -143,11 +150,11 @@ Use upsell banners to inform the users about a feature that can be enabled by up
143150
>
144151
<div>
145152

146-
Use a title to concisely present the topic of the banner when the message of the banner is complex and too long to scan.
153+
Use a title to concisely present the topic of the banner when the message of the banner is complex and too long to scan.
147154

148-
A title is required and will be used as a semantic page heading. However, you can visually hide the title. It is recommended to hide the title if the body of the banner is short and easily scannable.
155+
A title is required and will be used as a semantic page heading. However, you can visually hide the title. It is recommended to hide the title if the body of the banner is short and easily scannable.
149156

150-
Use the built-in accessibility annotations in the Figma components to define the heading level and text relevant to its context.
157+
Use the built-in accessibility annotations in the Figma components to define the heading level and text relevant to its context.
151158

152159
</div>
153160
<img
@@ -176,8 +183,14 @@ Banners with an `onDismiss` property automatically show a dismiss button. This s
176183
Use the following as a guideline:
177184

178185
<ul>
179-
<li>If you're on a page in which you can do other tasks, and the banner is not blocking / does not have to be addressed, then you should be able to have a close button.</li>
180-
<li>If accidental closure of the banner would leave the user confused or missing something critical, it should not have a close button.</li>
186+
<li>
187+
If you're on a page in which you can do other tasks, and the banner is not blocking / does not have to be addressed,
188+
then you should be able to have a close button.
189+
</li>
190+
<li>
191+
If accidental closure of the banner would leave the user confused or missing something critical, it should not have
192+
a close button.
193+
</li>
181194
</ul>
182195

183196
</div>
@@ -200,9 +213,9 @@ Use the following as a guideline:
200213
>
201214
<div>
202215

203-
Critical banners can't be dismissable. They are mostly used for errors which need to be resolved. As a result you can only get rid of a critical banner by resolving the error. If used to warn about destructive actions, the banner should also not be dismissable.
216+
Critical banners can't be dismissable. They are mostly used for errors which need to be resolved. As a result you can only get rid of a critical banner by resolving the error. If used to warn about destructive actions, the banner should also not be dismissable.
204217

205-
If the error must be resolved on a different page, use an action that directs the user to the page where the error can be resolved.
218+
If the error must be resolved on a different page, use an action that directs the user to the page where the error can be resolved.
206219

207220
</div>
208221

@@ -225,11 +238,11 @@ Use the following as a guideline:
225238
>
226239
<div>
227240

228-
A maximum of 2 actions can be added to a banner. Whenever possible it is recommended to only add a single action to better direct the users attention.
241+
A maximum of 2 actions can be added to a banner. Whenever possible it is recommended to only add a single action to better direct the users attention.
229242

230-
For banners with a single action, you can choose between adding a primary or secondary action depending on how much attention you want to draw to the action.
243+
For banners with a single action, you can choose between adding a primary or secondary action depending on how much attention you want to draw to the action.
231244

232-
For banners with two actions, one of them must be primary and the other must be secondary. In this case, use the primary action for the recommended action. For example, the primary action enables a feature and the secondary action links more information.
245+
For banners with two actions, one of them must be primary and the other must be secondary. In this case, use the primary action for the recommended action. For example, the primary action enables a feature and the secondary action links more information.
233246

234247
</div>
235248
<img
@@ -251,21 +264,17 @@ Use the following as a guideline:
251264

252265
The icon relates to the selected [variant](#variant) and can't be disabled. It can only be changed for banners of variant `info` or `upsell`.
253266

254-
<img
255-
width="456"
256-
alt="Three banners with leading icons. Success banner has its standard circle and check icon, upsell banner has a custom computer icon, and the info banner has a custom shield icon with a keyhole inside of the lock."
257-
src="https://github.com/primer/primitives/assets/813754/9de199af-6488-4ae3-b4a7-14896f5cb719"
258-
/>
267+
<img
268+
width="456"
269+
alt="Three banners with leading icons. Success banner has its standard circle and check icon, upsell banner has a custom computer icon, and the info banner has a custom shield icon with a keyhole inside of the lock."
270+
src="https://github.com/primer/primitives/assets/813754/9de199af-6488-4ae3-b4a7-14896f5cb719"
271+
/>
259272

260273
</Box>
261274

262-
263275
## Layouts
264-
<img
265-
width="960"
266-
alt=""
267-
src="https://github.com/primer/primitives/assets/813754/7aa6c298-3ca1-4e49-a95d-a774fda06a1d"
268-
/>
276+
277+
<img width="960" alt="" src="https://github.com/primer/primitives/assets/813754/7aa6c298-3ca1-4e49-a95d-a774fda06a1d" />
269278

270279
The internal banner layout changes for large banners depending on its content.
271280

@@ -275,6 +284,7 @@ The internal banner layout changes for large banners depending on its content.
275284
4. A banner with a title, a dismiss button and one or two actions has the dismiss button aligned to the top right corner and the actions below the content aligned to the left
276285

277286
### Responsive Design
287+
278288
<img
279289
width="960"
280290
alt="One banner at full width, with all of the content in one row, the second banner is shrunk to a smaller width, the icon, wrapped text, and dismiss button all in one row, with the action item in the second row."
@@ -284,6 +294,7 @@ The internal banner layout changes for large banners depending on its content.
284294
On large screens the layout of the elements within the banner adjust depending on which elements are enabled. On small screens the banner always uses the stacked layout.
285295

286296
### Position
297+
287298
A banner should always be positioned as close to the section it relates to as possible.
288299

289300
If a banner informs about something that relates to the current page, it should be placed above the pages headline. However, if the banner is only relevant to a portion of the page place it above the section it relates to.
@@ -298,8 +309,8 @@ Banners that are used to communicate feedback require extra accessibility consid
298309

299310
Consider using either a **live region announcement** or **focus management** technique:
300311

301-
* **Live region announcements**: can be used to announce the new content to screen reader users. This is the preferred method for non-critical information (**though exceptions apply**, such in scenarios where focus loss needs to be handled).
302-
* **Focus management**: involves shifting a user's focus directly the new Banner. This method is disruptive when used inappropriately, but is extremely helpful in scenarios where we need to guide the user towards an action.
312+
- **Live region announcements**: can be used to announce the new content to screen reader users. This is the preferred method for non-critical information (**though exceptions apply**, such in scenarios where focus loss needs to be handled).
313+
- **Focus management**: involves shifting a user's focus directly the new Banner. This method is disruptive when used inappropriately, but is extremely helpful in scenarios where we need to guide the user towards an action.
303314

304315
Here are some questions to consider when deciding which method to use:
305316

@@ -328,6 +339,7 @@ If the Banner appears as part of the new content on the page after a user experi
328339
Many scenarios are nuanced, and can be tricky to figure out the appropriate path forward for. These benefit from additional feedback from assistive technology users.
329340

330341
If you're unsure about which technique is appropriate for your usecase, please reach out to the Accessibility team who can help find a path forward.
342+
331343
### Known accessibility issues (GitHub staff only)
332344

333-
<AccessibilityLink label="Banner"/>
345+
<AccessibilityLink label="Banner" />
Loading
Loading

src/components/figma-image.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import {parseFigmaNodeUrl} from '@primer/figma-images/src/utils';
3+
import { Link, StyledOcticon } from '@primer/react';
4+
import {PencilIcon} from '@primer/octicons-react'
5+
6+
type FigmaImageProps = React.ImgHTMLAttributes<HTMLImageElement> & {
7+
src: string
8+
caption?: string
9+
}
10+
11+
const cssStyles = {
12+
width: "100%",
13+
maxWidth: "100%",
14+
margin: "0",
15+
"& img": {
16+
width: '100%'
17+
}
18+
}
19+
20+
const FigmaImageDir = '/images/figma';
21+
22+
export const FigmaImage: React.FC<FigmaImageProps> = ({src, caption, ...props}) => {
23+
// check for missing prop
24+
if(src === undefined) throw new Error("src is required on FigmaImage component");
25+
// get real image url
26+
const {nodeId, fileId} = parseFigmaNodeUrl(src);
27+
const imagePath = `${FigmaImageDir}/${fileId}-${nodeId}.png`
28+
// return image component
29+
return (<figure className="FigmaImage" style={cssStyles}>
30+
<img src={imagePath} {...props}/>
31+
<figcaption>
32+
{caption}
33+
<Link sx={{fontSize: '12px'}} className="link" href={src}><StyledOcticon icon={PencilIcon} sx={{mr: 2}} size="small"/>Edit in Figma</Link>
34+
</figcaption>
35+
</figure>)
36+
}

0 commit comments

Comments
 (0)