@instructure/ui-badge 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -282
- package/es/Badge/{index.js → v1/index.js} +2 -2
- package/es/Badge/v2/index.js +145 -0
- package/es/Badge/v2/props.js +28 -0
- package/es/Badge/v2/styles.js +220 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/Badge/v1/index.js +152 -0
- package/lib/Badge/{index.js → v2/index.js} +4 -5
- package/lib/Badge/v2/props.js +33 -0
- package/lib/Badge/v2/styles.js +226 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +39 -17
- package/src/Badge/{index.tsx → v1/index.tsx} +2 -2
- package/src/Badge/v2/README.md +277 -0
- package/src/Badge/v2/index.tsx +170 -0
- package/src/Badge/v2/props.ts +112 -0
- package/src/Badge/v2/styles.ts +226 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Badge/v1/index.d.ts.map +1 -0
- package/types/Badge/v1/props.d.ts.map +1 -0
- package/types/Badge/v1/styles.d.ts.map +1 -0
- package/types/Badge/v1/theme.d.ts.map +1 -0
- package/types/Badge/v2/index.d.ts +35 -0
- package/types/Badge/v2/index.d.ts.map +1 -0
- package/types/Badge/v2/props.d.ts +62 -0
- package/types/Badge/v2/props.d.ts.map +1 -0
- package/types/Badge/v2/styles.d.ts +15 -0
- package/types/Badge/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Badge/index.d.ts.map +0 -1
- package/types/Badge/props.d.ts.map +0 -1
- package/types/Badge/styles.d.ts.map +0 -1
- package/types/Badge/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Badge/{props.js → v1/props.js} +0 -0
- /package/es/Badge/{styles.js → v1/styles.js} +0 -0
- /package/es/Badge/{theme.js → v1/theme.js} +0 -0
- /package/lib/Badge/{props.js → v1/props.js} +0 -0
- /package/lib/Badge/{styles.js → v1/styles.js} +0 -0
- /package/lib/Badge/{theme.js → v1/theme.js} +0 -0
- /package/src/Badge/{README.md → v1/README.md} +0 -0
- /package/src/Badge/{props.ts → v1/props.ts} +0 -0
- /package/src/Badge/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Badge/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Badge/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/Badge/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Badge/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Badge/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _emotion = require("@instructure/emotion");
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// keyframes have to be outside of 'generateStyle',
|
|
33
|
+
// since it is causing problems in style recalculation
|
|
34
|
+
const pulseAnimation = (0, _emotion.keyframes)`
|
|
35
|
+
to {
|
|
36
|
+
transform: scale(1);
|
|
37
|
+
opacity: 0.9;
|
|
38
|
+
}`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* ---
|
|
42
|
+
* private: true
|
|
43
|
+
* ---
|
|
44
|
+
* Generates the style object from the theme and provided additional information
|
|
45
|
+
* @param {Object} componentTheme The theme variable object.
|
|
46
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
47
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
48
|
+
* @return {Object} The final style object, which will be used in the component
|
|
49
|
+
*/
|
|
50
|
+
const generateStyle = (componentTheme, props) => {
|
|
51
|
+
const type = props.type,
|
|
52
|
+
variant = props.variant,
|
|
53
|
+
_props$placement = props.placement,
|
|
54
|
+
placement = _props$placement === void 0 ? '' : _props$placement,
|
|
55
|
+
standalone = props.standalone,
|
|
56
|
+
pulse = props.pulse;
|
|
57
|
+
const top = placement.indexOf('top') > -1;
|
|
58
|
+
const bottom = placement.indexOf('bottom') > -1;
|
|
59
|
+
const start = placement.indexOf('start') > -1;
|
|
60
|
+
const end = placement.indexOf('end') > -1;
|
|
61
|
+
const center = placement.indexOf('center') > -1;
|
|
62
|
+
const variants = {
|
|
63
|
+
danger: {
|
|
64
|
+
badge: {
|
|
65
|
+
color: componentTheme.color,
|
|
66
|
+
backgroundColor: componentTheme.colorDanger
|
|
67
|
+
},
|
|
68
|
+
pulseBorder: {
|
|
69
|
+
borderColor: componentTheme.colorDanger
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
success: {
|
|
73
|
+
badge: {
|
|
74
|
+
color: componentTheme.color,
|
|
75
|
+
backgroundColor: componentTheme.colorSuccess
|
|
76
|
+
},
|
|
77
|
+
pulseBorder: {
|
|
78
|
+
borderColor: componentTheme.colorSuccess
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
primary: {
|
|
82
|
+
badge: {
|
|
83
|
+
color: componentTheme.color,
|
|
84
|
+
backgroundColor: componentTheme.colorPrimary
|
|
85
|
+
},
|
|
86
|
+
pulseBorder: {
|
|
87
|
+
borderColor: componentTheme.colorPrimary
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
inverse: {
|
|
91
|
+
// text and background colors are swapped
|
|
92
|
+
badge: {
|
|
93
|
+
color: componentTheme.colorInverse,
|
|
94
|
+
backgroundColor: componentTheme.color
|
|
95
|
+
},
|
|
96
|
+
pulseBorder: {
|
|
97
|
+
borderColor: componentTheme.color
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const countPositions = {
|
|
102
|
+
...(top && {
|
|
103
|
+
top: `calc(-1 * ${componentTheme.countOffset})`
|
|
104
|
+
}),
|
|
105
|
+
...(bottom && {
|
|
106
|
+
bottom: `calc(-1 * ${componentTheme.countOffset})`
|
|
107
|
+
}),
|
|
108
|
+
...(start && {
|
|
109
|
+
insetInlineStart: `calc(-1 * ${componentTheme.countOffset})`,
|
|
110
|
+
insetInlineEnd: 'auto'
|
|
111
|
+
}),
|
|
112
|
+
...(end && {
|
|
113
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.countOffset})`,
|
|
114
|
+
insetInlineStart: 'auto'
|
|
115
|
+
}),
|
|
116
|
+
...(center && {
|
|
117
|
+
...((end || start) && {
|
|
118
|
+
top: `calc(50% - (${componentTheme.size} / 2))`
|
|
119
|
+
}),
|
|
120
|
+
...(start && {
|
|
121
|
+
insetInlineStart: 'auto',
|
|
122
|
+
insetInlineEnd: `calc(100% - ${componentTheme.countOffset})`
|
|
123
|
+
}),
|
|
124
|
+
...(end && {
|
|
125
|
+
insetInlineEnd: 'auto',
|
|
126
|
+
insetInlineStart: `calc(100% - ${componentTheme.countOffset})`
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
const notificationPositions = {
|
|
131
|
+
...(top && {
|
|
132
|
+
top: componentTheme.notificationOffset
|
|
133
|
+
}),
|
|
134
|
+
...(bottom && {
|
|
135
|
+
bottom: componentTheme.notificationOffset
|
|
136
|
+
}),
|
|
137
|
+
...(start && {
|
|
138
|
+
insetInlineStart: componentTheme.notificationOffset,
|
|
139
|
+
insetInlineEnd: 'auto'
|
|
140
|
+
}),
|
|
141
|
+
...(end && {
|
|
142
|
+
insetInlineEnd: componentTheme.notificationOffset,
|
|
143
|
+
insetInlineStart: 'auto'
|
|
144
|
+
}),
|
|
145
|
+
...(center && {
|
|
146
|
+
...((end || start) && {
|
|
147
|
+
top: `calc(50% - (${componentTheme.sizeNotification} / 2))`
|
|
148
|
+
}),
|
|
149
|
+
...(start && {
|
|
150
|
+
insetInlineStart: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
151
|
+
insetInlineEnd: 'auto'
|
|
152
|
+
}),
|
|
153
|
+
...(end && {
|
|
154
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
155
|
+
insetInlineStart: 'auto'
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
const notStandaloneTypeVariant = {
|
|
160
|
+
count: countPositions,
|
|
161
|
+
notification: notificationPositions
|
|
162
|
+
};
|
|
163
|
+
const typeVariant = {
|
|
164
|
+
count: {
|
|
165
|
+
lineHeight: componentTheme.size,
|
|
166
|
+
minWidth: componentTheme.size,
|
|
167
|
+
paddingInlineStart: componentTheme.padding,
|
|
168
|
+
paddingInlineEnd: componentTheme.padding
|
|
169
|
+
},
|
|
170
|
+
notification: {
|
|
171
|
+
width: componentTheme.sizeNotification,
|
|
172
|
+
height: componentTheme.sizeNotification
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
badge: {
|
|
177
|
+
label: 'badge',
|
|
178
|
+
fontFamily: componentTheme.fontFamily,
|
|
179
|
+
fontWeight: componentTheme.fontWeight,
|
|
180
|
+
boxSizing: 'border-box',
|
|
181
|
+
pointerEvents: 'none',
|
|
182
|
+
textAlign: 'center',
|
|
183
|
+
fontSize: componentTheme.fontSize,
|
|
184
|
+
whiteSpace: 'nowrap',
|
|
185
|
+
borderRadius: componentTheme.borderRadius,
|
|
186
|
+
...variants[variant].badge,
|
|
187
|
+
...(pulse && {
|
|
188
|
+
position: 'relative',
|
|
189
|
+
'&::before': {
|
|
190
|
+
content: '""',
|
|
191
|
+
width: 'calc(100% + 0.5rem)',
|
|
192
|
+
height: 'calc(100% + 0.5rem)',
|
|
193
|
+
borderRadius: componentTheme.borderRadius,
|
|
194
|
+
position: 'absolute',
|
|
195
|
+
top: '-0.25rem',
|
|
196
|
+
insetInlineEnd: 'auto',
|
|
197
|
+
insetInlineStart: '-0.25rem',
|
|
198
|
+
boxSizing: 'border-box',
|
|
199
|
+
border: `${componentTheme.pulseBorderThickness} solid`,
|
|
200
|
+
opacity: 0,
|
|
201
|
+
transform: 'scale(0.75)',
|
|
202
|
+
animationName: pulseAnimation,
|
|
203
|
+
animationDuration: '1s',
|
|
204
|
+
animationIterationCount: '4',
|
|
205
|
+
animationDirection: 'alternate',
|
|
206
|
+
...variants[variant].pulseBorder
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
209
|
+
...typeVariant[type],
|
|
210
|
+
...(!standalone && {
|
|
211
|
+
position: 'absolute',
|
|
212
|
+
zIndex: componentTheme.notificationZIndex,
|
|
213
|
+
...notStandaloneTypeVariant[type]
|
|
214
|
+
})
|
|
215
|
+
},
|
|
216
|
+
wrapper: {
|
|
217
|
+
label: 'badge__wrapper',
|
|
218
|
+
position: 'relative',
|
|
219
|
+
boxSizing: 'border-box',
|
|
220
|
+
svg: {
|
|
221
|
+
display: 'block'
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
var _default = exports.default = generateStyle;
|
package/lib/exports/b.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-badge",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A badge component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,20 +15,20 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/emotion": "11.6.
|
|
19
|
-
"@instructure/
|
|
20
|
-
"@instructure/ui-color-utils": "11.6.
|
|
21
|
-
"@instructure/ui-react-utils": "11.6.
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-view": "11.6.
|
|
18
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/ui-position": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-view": "11.6.1-snapshot-129"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/jest-dom": "^6.6.3",
|
|
27
27
|
"@testing-library/react": "15.0.7",
|
|
28
28
|
"vitest": "^3.2.2",
|
|
29
|
-
"@instructure/ui-axe-check": "11.6.
|
|
30
|
-
"@instructure/ui-babel-preset": "11.6.
|
|
31
|
-
"@instructure/ui-themes": "11.6.
|
|
29
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
30
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129",
|
|
31
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": ">=18 <=19"
|
|
@@ -38,17 +38,39 @@
|
|
|
38
38
|
},
|
|
39
39
|
"sideEffects": false,
|
|
40
40
|
"exports": {
|
|
41
|
-
".": {
|
|
42
|
-
"types": "./types/index.d.ts",
|
|
43
|
-
"import": "./es/index.js",
|
|
44
|
-
"require": "./lib/index.js",
|
|
45
|
-
"default": "./es/index.js"
|
|
46
|
-
},
|
|
47
41
|
"./lib/*": "./lib/*",
|
|
48
42
|
"./es/*": "./es/*",
|
|
49
43
|
"./types/*": "./types/*",
|
|
50
44
|
"./package.json": "./package.json",
|
|
51
|
-
"./src/*": "./src/*"
|
|
45
|
+
"./src/*": "./src/*",
|
|
46
|
+
".": {
|
|
47
|
+
"src": "./src/exports/a.ts",
|
|
48
|
+
"types": "./types/exports/a.d.ts",
|
|
49
|
+
"import": "./es/exports/a.js",
|
|
50
|
+
"require": "./lib/exports/a.js",
|
|
51
|
+
"default": "./es/exports/a.js"
|
|
52
|
+
},
|
|
53
|
+
"./v11_6": {
|
|
54
|
+
"src": "./src/exports/a.ts",
|
|
55
|
+
"types": "./types/exports/a.d.ts",
|
|
56
|
+
"import": "./es/exports/a.js",
|
|
57
|
+
"require": "./lib/exports/a.js",
|
|
58
|
+
"default": "./es/exports/a.js"
|
|
59
|
+
},
|
|
60
|
+
"./v11_7": {
|
|
61
|
+
"src": "./src/exports/b.ts",
|
|
62
|
+
"types": "./types/exports/b.d.ts",
|
|
63
|
+
"import": "./es/exports/b.js",
|
|
64
|
+
"require": "./lib/exports/b.js",
|
|
65
|
+
"default": "./es/exports/b.js"
|
|
66
|
+
},
|
|
67
|
+
"./latest": {
|
|
68
|
+
"src": "./src/exports/b.ts",
|
|
69
|
+
"types": "./types/exports/b.d.ts",
|
|
70
|
+
"import": "./es/exports/b.js",
|
|
71
|
+
"require": "./lib/exports/b.js",
|
|
72
|
+
"default": "./es/exports/b.js"
|
|
73
|
+
}
|
|
52
74
|
},
|
|
53
75
|
"scripts": {
|
|
54
76
|
"lint": "ui-scripts lint",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
|
|
25
25
|
import { Component, Children, ReactElement } from 'react'
|
|
26
26
|
|
|
27
|
-
import { View } from '@instructure/ui-view'
|
|
27
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
28
28
|
import {
|
|
29
29
|
safeCloneElement,
|
|
30
30
|
withDeterministicId
|
|
31
31
|
} from '@instructure/ui-react-utils'
|
|
32
32
|
|
|
33
|
-
import { withStyle } from '@instructure/emotion'
|
|
33
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
34
34
|
|
|
35
35
|
import generateStyle from './styles'
|
|
36
36
|
import generateComponentTheme from './theme'
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Badge
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
### Making badges accessible
|
|
6
|
+
|
|
7
|
+
Badge counts are automatically fed to screenreaders through the `aria-describedby`
|
|
8
|
+
attribute. Often a stand alone number doesn't give a screenreader user enough context (_"3" vs. "You have 3 unread emails"_).
|
|
9
|
+
The examples below use the `formatOutput` prop to make the badge more screenreader-friendly.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
---
|
|
13
|
+
type: example
|
|
14
|
+
---
|
|
15
|
+
<div>
|
|
16
|
+
<Badge
|
|
17
|
+
count={99}
|
|
18
|
+
pulse
|
|
19
|
+
margin="0 medium 0 0"
|
|
20
|
+
formatOutput={function (formattedCount) {
|
|
21
|
+
return (
|
|
22
|
+
<AccessibleContent alt={`You have ${formattedCount} new edits to review`}>
|
|
23
|
+
{formattedCount}
|
|
24
|
+
</AccessibleContent>
|
|
25
|
+
)
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<IconButton
|
|
29
|
+
renderIcon={<UserRoundInstUIIcon />}
|
|
30
|
+
screenReaderLabel="Edits"
|
|
31
|
+
withBorder={false}
|
|
32
|
+
withBackground={false}
|
|
33
|
+
/>
|
|
34
|
+
</Badge>
|
|
35
|
+
<Badge
|
|
36
|
+
type="notification"
|
|
37
|
+
formatOutput={function () {
|
|
38
|
+
return <ScreenReaderContent>You have new edits to review</ScreenReaderContent>
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
<IconButton
|
|
42
|
+
renderIcon={<UserRoundInstUIIcon />}
|
|
43
|
+
screenReaderLabel="Edits"
|
|
44
|
+
withBorder={false}
|
|
45
|
+
withBackground={false}
|
|
46
|
+
/>
|
|
47
|
+
</Badge>
|
|
48
|
+
</div>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> Note the use of the `pulse` prop in the first example to make the Badge slowly pulse twice on mount.
|
|
52
|
+
|
|
53
|
+
### Limit the count
|
|
54
|
+
|
|
55
|
+
Use the `countUntil` prop to set a limit for the count. The default for `formatOverflowText` is a "+" symbol.
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
---
|
|
59
|
+
type: example
|
|
60
|
+
---
|
|
61
|
+
<div>
|
|
62
|
+
<Badge count={105} countUntil={100} margin="0 medium 0 0">
|
|
63
|
+
<Button>Inbox</Button>
|
|
64
|
+
</Badge>
|
|
65
|
+
<Badge count={250} countUntil={100}>
|
|
66
|
+
<Button>Assignments</Button>
|
|
67
|
+
</Badge>
|
|
68
|
+
</div>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Standalone, notification and color variants
|
|
72
|
+
|
|
73
|
+
Setting the `standalone` prop to `true` renders Badge as a standalone
|
|
74
|
+
element that is not positioned relative to a child and displays inline-block.
|
|
75
|
+
Setting `type="notification"` will render small circles that should not contain any visible text.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
---
|
|
79
|
+
type: example
|
|
80
|
+
---
|
|
81
|
+
<div>
|
|
82
|
+
<Flex padding='small' display='inline-flex' alignItems="center">
|
|
83
|
+
<Badge standalone count={6} margin='0 small 0 0' />
|
|
84
|
+
<Badge
|
|
85
|
+
type="notification"
|
|
86
|
+
standalone
|
|
87
|
+
formatOutput={function () {
|
|
88
|
+
return <ScreenReaderContent>This is a notification</ScreenReaderContent>
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
</Flex>
|
|
92
|
+
<Flex padding='small' display='inline-flex' alignItems="center">
|
|
93
|
+
<Badge standalone variant="success" count={12} margin='0 small 0 0' />
|
|
94
|
+
<Badge
|
|
95
|
+
variant="success"
|
|
96
|
+
type="notification"
|
|
97
|
+
standalone
|
|
98
|
+
formatOutput={function () {
|
|
99
|
+
return <ScreenReaderContent>This is a success notification</ScreenReaderContent>
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
</Flex>
|
|
103
|
+
<Flex padding='small' display='inline-flex' alignItems="center">
|
|
104
|
+
<Badge standalone variant="danger" count={18} countUntil={10} margin='0 small 0 0' />
|
|
105
|
+
<Badge
|
|
106
|
+
variant="danger"
|
|
107
|
+
type="notification"
|
|
108
|
+
standalone
|
|
109
|
+
formatOutput={function () {
|
|
110
|
+
return <ScreenReaderContent>This is a danger notification</ScreenReaderContent>
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
</Flex>
|
|
114
|
+
<View display='inline-flex' background='primary-inverse'>
|
|
115
|
+
<Flex padding='small' display='inline-flex' alignItems="center" background='primary-inverse'>
|
|
116
|
+
<Badge standalone variant="inverse" count={8} margin='0 small 0 0' />
|
|
117
|
+
<Badge
|
|
118
|
+
variant="inverse"
|
|
119
|
+
type="notification"
|
|
120
|
+
standalone
|
|
121
|
+
formatOutput={function () {
|
|
122
|
+
return <ScreenReaderContent>This is a danger notification</ScreenReaderContent>
|
|
123
|
+
}}
|
|
124
|
+
/>
|
|
125
|
+
</Flex>
|
|
126
|
+
</View>
|
|
127
|
+
</div>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Placement
|
|
131
|
+
|
|
132
|
+
Default is `top end`. **Note that standalone badges can't be placed.**
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
---
|
|
136
|
+
type: example
|
|
137
|
+
---
|
|
138
|
+
const EditButton = () => (
|
|
139
|
+
<IconButton
|
|
140
|
+
renderIcon={<UserRoundInstUIIcon />}
|
|
141
|
+
screenReaderLabel="Edit page"
|
|
142
|
+
withBorder={false}
|
|
143
|
+
withBackground={false}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
const Example = () => (
|
|
148
|
+
<div>
|
|
149
|
+
<View as="div" margin="0 0 medium">
|
|
150
|
+
<Badge count={21} margin="0 large 0 0" placement="top start">
|
|
151
|
+
<EditButton />
|
|
152
|
+
</Badge>
|
|
153
|
+
<Badge count={21} margin="0 large 0 0">
|
|
154
|
+
<EditButton />
|
|
155
|
+
</Badge>
|
|
156
|
+
<Badge count={21} margin="0 large 0 0" placement="bottom start">
|
|
157
|
+
<EditButton />
|
|
158
|
+
</Badge>
|
|
159
|
+
<Badge count={21} margin="0 large 0 0" placement="bottom end">
|
|
160
|
+
<EditButton />
|
|
161
|
+
</Badge>
|
|
162
|
+
<Badge count={21} margin="0 large 0 0" placement="start center">
|
|
163
|
+
<EditButton />
|
|
164
|
+
</Badge>
|
|
165
|
+
<Badge count={21} placement="end center">
|
|
166
|
+
<EditButton />
|
|
167
|
+
</Badge>
|
|
168
|
+
</View>
|
|
169
|
+
<View as="div">
|
|
170
|
+
<Badge
|
|
171
|
+
type="notification"
|
|
172
|
+
margin="0 large 0 0"
|
|
173
|
+
placement="top start"
|
|
174
|
+
formatOutput={function () {
|
|
175
|
+
return (
|
|
176
|
+
<ScreenReaderContent>
|
|
177
|
+
Updates are available for your account
|
|
178
|
+
</ScreenReaderContent>
|
|
179
|
+
)
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<EditButton />
|
|
183
|
+
</Badge>
|
|
184
|
+
<Badge
|
|
185
|
+
type="notification"
|
|
186
|
+
margin="0 large 0 0"
|
|
187
|
+
formatOutput={function () {
|
|
188
|
+
return (
|
|
189
|
+
<ScreenReaderContent>
|
|
190
|
+
Updates are available for your account
|
|
191
|
+
</ScreenReaderContent>
|
|
192
|
+
)
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
<EditButton />
|
|
196
|
+
</Badge>
|
|
197
|
+
<Badge
|
|
198
|
+
type="notification"
|
|
199
|
+
margin="0 large 0 0"
|
|
200
|
+
placement="bottom start"
|
|
201
|
+
formatOutput={function () {
|
|
202
|
+
return (
|
|
203
|
+
<ScreenReaderContent>
|
|
204
|
+
Updates are available for your account
|
|
205
|
+
</ScreenReaderContent>
|
|
206
|
+
)
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<EditButton />
|
|
210
|
+
</Badge>
|
|
211
|
+
<Badge
|
|
212
|
+
type="notification"
|
|
213
|
+
margin="0 large 0 0"
|
|
214
|
+
placement="bottom end"
|
|
215
|
+
formatOutput={function () {
|
|
216
|
+
return (
|
|
217
|
+
<ScreenReaderContent>
|
|
218
|
+
Updates are available for your account
|
|
219
|
+
</ScreenReaderContent>
|
|
220
|
+
)
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<EditButton />
|
|
224
|
+
</Badge>
|
|
225
|
+
<Badge
|
|
226
|
+
type="notification"
|
|
227
|
+
margin="0 large 0 0"
|
|
228
|
+
placement="start center"
|
|
229
|
+
formatOutput={function () {
|
|
230
|
+
return (
|
|
231
|
+
<ScreenReaderContent>
|
|
232
|
+
Updates are available for your account
|
|
233
|
+
</ScreenReaderContent>
|
|
234
|
+
)
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
<EditButton />
|
|
238
|
+
</Badge>
|
|
239
|
+
<Badge
|
|
240
|
+
type="notification"
|
|
241
|
+
placement="end center"
|
|
242
|
+
formatOutput={function () {
|
|
243
|
+
return (
|
|
244
|
+
<ScreenReaderContent>
|
|
245
|
+
Updates are available for your account
|
|
246
|
+
</ScreenReaderContent>
|
|
247
|
+
)
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
<EditButton />
|
|
251
|
+
</Badge>
|
|
252
|
+
</View>
|
|
253
|
+
</div>
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
render(<Example />)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Guidelines
|
|
260
|
+
|
|
261
|
+
```js
|
|
262
|
+
---
|
|
263
|
+
type: embed
|
|
264
|
+
---
|
|
265
|
+
<Guidelines>
|
|
266
|
+
<Figure recommendation="yes" title="Do">
|
|
267
|
+
<Figure.Item>Use count for up to 2 digits of numbers</Figure.Item>
|
|
268
|
+
<Figure.Item>Use "+" symbol for more than 2 digits (99+)</Figure.Item>
|
|
269
|
+
<Figure.Item>Use for numeric count (like unread messages)</Figure.Item>
|
|
270
|
+
<Figure.Item>Provide accessible text for what the number represents</Figure.Item>
|
|
271
|
+
</Figure>
|
|
272
|
+
<Figure recommendation="no" title="Don't">
|
|
273
|
+
<Figure.Item>Use as a status indicator refer to Pill</Figure.Item>
|
|
274
|
+
<Figure.Item>Use for text strings</Figure.Item>
|
|
275
|
+
</Figure>
|
|
276
|
+
</Guidelines>
|
|
277
|
+
```
|