@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,145 @@
|
|
|
1
|
+
var _dec, _dec2, _class, _Badge;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Component, Children } from 'react';
|
|
27
|
+
import { View } from '@instructure/ui-view/latest';
|
|
28
|
+
import { safeCloneElement, withDeterministicId } from '@instructure/ui-react-utils';
|
|
29
|
+
import { withStyle } from '@instructure/emotion';
|
|
30
|
+
import generateStyle from "./styles.js";
|
|
31
|
+
import { allowedProps } from "./props.js";
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
33
|
+
/**
|
|
34
|
+
---
|
|
35
|
+
category: components
|
|
36
|
+
---
|
|
37
|
+
**/
|
|
38
|
+
let Badge = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Badge = class Badge extends Component {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super(props);
|
|
41
|
+
this._defaultId = void 0;
|
|
42
|
+
this.ref = null;
|
|
43
|
+
this.handleRef = el => {
|
|
44
|
+
const elementRef = this.props.elementRef;
|
|
45
|
+
this.ref = el;
|
|
46
|
+
if (typeof elementRef === 'function') {
|
|
47
|
+
elementRef(el);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this._defaultId = this.props.deterministicId();
|
|
51
|
+
}
|
|
52
|
+
componentDidMount() {
|
|
53
|
+
var _this$props$makeStyle, _this$props;
|
|
54
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
55
|
+
}
|
|
56
|
+
componentDidUpdate() {
|
|
57
|
+
var _this$props$makeStyle2, _this$props2;
|
|
58
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
59
|
+
}
|
|
60
|
+
countOverflow() {
|
|
61
|
+
const _this$props3 = this.props,
|
|
62
|
+
count = _this$props3.count,
|
|
63
|
+
countUntil = _this$props3.countUntil;
|
|
64
|
+
return countUntil && count && countUntil > 1 && count >= countUntil;
|
|
65
|
+
}
|
|
66
|
+
renderOutput() {
|
|
67
|
+
const _this$props4 = this.props,
|
|
68
|
+
count = _this$props4.count,
|
|
69
|
+
countUntil = _this$props4.countUntil,
|
|
70
|
+
formatOverflowText = _this$props4.formatOverflowText,
|
|
71
|
+
formatOutput = _this$props4.formatOutput,
|
|
72
|
+
type = _this$props4.type;
|
|
73
|
+
|
|
74
|
+
// If the badge count is >= than the countUntil limit, format the badge text
|
|
75
|
+
// via the formatOverflowText function prop
|
|
76
|
+
let formattedCount = (count || '').toString();
|
|
77
|
+
if (count && countUntil && formatOverflowText && type === 'count' && this.countOverflow()) {
|
|
78
|
+
formattedCount = formatOverflowText(count, countUntil);
|
|
79
|
+
}
|
|
80
|
+
if (typeof formatOutput === 'function') {
|
|
81
|
+
return formatOutput(formattedCount);
|
|
82
|
+
} else {
|
|
83
|
+
return type === 'count' ? formattedCount : null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
renderBadge() {
|
|
87
|
+
const _this$props5 = this.props,
|
|
88
|
+
count = _this$props5.count,
|
|
89
|
+
margin = _this$props5.margin,
|
|
90
|
+
standalone = _this$props5.standalone,
|
|
91
|
+
type = _this$props5.type,
|
|
92
|
+
styles = _this$props5.styles;
|
|
93
|
+
return _jsx(View, {
|
|
94
|
+
margin: standalone ? margin : 'none',
|
|
95
|
+
css: styles === null || styles === void 0 ? void 0 : styles.badge,
|
|
96
|
+
title: type === 'count' && this.countOverflow() ? count === null || count === void 0 ? void 0 : count.toString() : '',
|
|
97
|
+
id: !standalone ? this._defaultId : void 0,
|
|
98
|
+
display: standalone ? 'inline-block' : 'block',
|
|
99
|
+
...(standalone && {
|
|
100
|
+
elementRef: this.handleRef,
|
|
101
|
+
'data-cid': 'Badge'
|
|
102
|
+
}),
|
|
103
|
+
children: this.renderOutput()
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
renderChildren() {
|
|
107
|
+
return Children.map(this.props.children, child => {
|
|
108
|
+
return safeCloneElement(child, {
|
|
109
|
+
'aria-describedby': this._defaultId
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
render() {
|
|
114
|
+
const _this$props6 = this.props,
|
|
115
|
+
margin = _this$props6.margin,
|
|
116
|
+
standalone = _this$props6.standalone,
|
|
117
|
+
display = _this$props6.display,
|
|
118
|
+
as = _this$props6.as,
|
|
119
|
+
styles = _this$props6.styles;
|
|
120
|
+
if (standalone) {
|
|
121
|
+
return this.renderBadge();
|
|
122
|
+
} else {
|
|
123
|
+
return _jsxs(View, {
|
|
124
|
+
as: as,
|
|
125
|
+
margin: margin,
|
|
126
|
+
elementRef: this.handleRef,
|
|
127
|
+
css: styles === null || styles === void 0 ? void 0 : styles.wrapper,
|
|
128
|
+
display: display,
|
|
129
|
+
"data-cid": "Badge",
|
|
130
|
+
children: [this.renderChildren(), this.renderBadge()]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, _Badge.displayName = "Badge", _Badge.componentId = 'Badge', _Badge.allowedProps = allowedProps, _Badge.defaultProps = {
|
|
135
|
+
standalone: false,
|
|
136
|
+
type: 'count',
|
|
137
|
+
variant: 'primary',
|
|
138
|
+
display: 'inline-block',
|
|
139
|
+
pulse: false,
|
|
140
|
+
placement: 'top end',
|
|
141
|
+
elementRef: () => {},
|
|
142
|
+
formatOverflowText: (_count, countUntil) => `${countUntil - 1} +`
|
|
143
|
+
}, _Badge)) || _class) || _class);
|
|
144
|
+
export default Badge;
|
|
145
|
+
export { Badge };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// <unknown is needed for React 17 support
|
|
26
|
+
|
|
27
|
+
const allowedProps = ['count', 'countUntil', 'children', 'type', 'standalone', 'pulse', 'variant', 'placement', 'display', 'margin', 'elementRef', 'formatOverflowText', 'formatOutput', 'as'];
|
|
28
|
+
export { allowedProps };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { keyframes } from '@instructure/emotion';
|
|
26
|
+
// keyframes have to be outside of 'generateStyle',
|
|
27
|
+
// since it is causing problems in style recalculation
|
|
28
|
+
const pulseAnimation = keyframes`
|
|
29
|
+
to {
|
|
30
|
+
transform: scale(1);
|
|
31
|
+
opacity: 0.9;
|
|
32
|
+
}`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ---
|
|
36
|
+
* private: true
|
|
37
|
+
* ---
|
|
38
|
+
* Generates the style object from the theme and provided additional information
|
|
39
|
+
* @param {Object} componentTheme The theme variable object.
|
|
40
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
41
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
42
|
+
* @return {Object} The final style object, which will be used in the component
|
|
43
|
+
*/
|
|
44
|
+
const generateStyle = (componentTheme, props) => {
|
|
45
|
+
const type = props.type,
|
|
46
|
+
variant = props.variant,
|
|
47
|
+
_props$placement = props.placement,
|
|
48
|
+
placement = _props$placement === void 0 ? '' : _props$placement,
|
|
49
|
+
standalone = props.standalone,
|
|
50
|
+
pulse = props.pulse;
|
|
51
|
+
const top = placement.indexOf('top') > -1;
|
|
52
|
+
const bottom = placement.indexOf('bottom') > -1;
|
|
53
|
+
const start = placement.indexOf('start') > -1;
|
|
54
|
+
const end = placement.indexOf('end') > -1;
|
|
55
|
+
const center = placement.indexOf('center') > -1;
|
|
56
|
+
const variants = {
|
|
57
|
+
danger: {
|
|
58
|
+
badge: {
|
|
59
|
+
color: componentTheme.color,
|
|
60
|
+
backgroundColor: componentTheme.colorDanger
|
|
61
|
+
},
|
|
62
|
+
pulseBorder: {
|
|
63
|
+
borderColor: componentTheme.colorDanger
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
success: {
|
|
67
|
+
badge: {
|
|
68
|
+
color: componentTheme.color,
|
|
69
|
+
backgroundColor: componentTheme.colorSuccess
|
|
70
|
+
},
|
|
71
|
+
pulseBorder: {
|
|
72
|
+
borderColor: componentTheme.colorSuccess
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
primary: {
|
|
76
|
+
badge: {
|
|
77
|
+
color: componentTheme.color,
|
|
78
|
+
backgroundColor: componentTheme.colorPrimary
|
|
79
|
+
},
|
|
80
|
+
pulseBorder: {
|
|
81
|
+
borderColor: componentTheme.colorPrimary
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
inverse: {
|
|
85
|
+
// text and background colors are swapped
|
|
86
|
+
badge: {
|
|
87
|
+
color: componentTheme.colorInverse,
|
|
88
|
+
backgroundColor: componentTheme.color
|
|
89
|
+
},
|
|
90
|
+
pulseBorder: {
|
|
91
|
+
borderColor: componentTheme.color
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const countPositions = {
|
|
96
|
+
...(top && {
|
|
97
|
+
top: `calc(-1 * ${componentTheme.countOffset})`
|
|
98
|
+
}),
|
|
99
|
+
...(bottom && {
|
|
100
|
+
bottom: `calc(-1 * ${componentTheme.countOffset})`
|
|
101
|
+
}),
|
|
102
|
+
...(start && {
|
|
103
|
+
insetInlineStart: `calc(-1 * ${componentTheme.countOffset})`,
|
|
104
|
+
insetInlineEnd: 'auto'
|
|
105
|
+
}),
|
|
106
|
+
...(end && {
|
|
107
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.countOffset})`,
|
|
108
|
+
insetInlineStart: 'auto'
|
|
109
|
+
}),
|
|
110
|
+
...(center && {
|
|
111
|
+
...((end || start) && {
|
|
112
|
+
top: `calc(50% - (${componentTheme.size} / 2))`
|
|
113
|
+
}),
|
|
114
|
+
...(start && {
|
|
115
|
+
insetInlineStart: 'auto',
|
|
116
|
+
insetInlineEnd: `calc(100% - ${componentTheme.countOffset})`
|
|
117
|
+
}),
|
|
118
|
+
...(end && {
|
|
119
|
+
insetInlineEnd: 'auto',
|
|
120
|
+
insetInlineStart: `calc(100% - ${componentTheme.countOffset})`
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
const notificationPositions = {
|
|
125
|
+
...(top && {
|
|
126
|
+
top: componentTheme.notificationOffset
|
|
127
|
+
}),
|
|
128
|
+
...(bottom && {
|
|
129
|
+
bottom: componentTheme.notificationOffset
|
|
130
|
+
}),
|
|
131
|
+
...(start && {
|
|
132
|
+
insetInlineStart: componentTheme.notificationOffset,
|
|
133
|
+
insetInlineEnd: 'auto'
|
|
134
|
+
}),
|
|
135
|
+
...(end && {
|
|
136
|
+
insetInlineEnd: componentTheme.notificationOffset,
|
|
137
|
+
insetInlineStart: 'auto'
|
|
138
|
+
}),
|
|
139
|
+
...(center && {
|
|
140
|
+
...((end || start) && {
|
|
141
|
+
top: `calc(50% - (${componentTheme.sizeNotification} / 2))`
|
|
142
|
+
}),
|
|
143
|
+
...(start && {
|
|
144
|
+
insetInlineStart: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
145
|
+
insetInlineEnd: 'auto'
|
|
146
|
+
}),
|
|
147
|
+
...(end && {
|
|
148
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
149
|
+
insetInlineStart: 'auto'
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
};
|
|
153
|
+
const notStandaloneTypeVariant = {
|
|
154
|
+
count: countPositions,
|
|
155
|
+
notification: notificationPositions
|
|
156
|
+
};
|
|
157
|
+
const typeVariant = {
|
|
158
|
+
count: {
|
|
159
|
+
lineHeight: componentTheme.size,
|
|
160
|
+
minWidth: componentTheme.size,
|
|
161
|
+
paddingInlineStart: componentTheme.padding,
|
|
162
|
+
paddingInlineEnd: componentTheme.padding
|
|
163
|
+
},
|
|
164
|
+
notification: {
|
|
165
|
+
width: componentTheme.sizeNotification,
|
|
166
|
+
height: componentTheme.sizeNotification
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
badge: {
|
|
171
|
+
label: 'badge',
|
|
172
|
+
fontFamily: componentTheme.fontFamily,
|
|
173
|
+
fontWeight: componentTheme.fontWeight,
|
|
174
|
+
boxSizing: 'border-box',
|
|
175
|
+
pointerEvents: 'none',
|
|
176
|
+
textAlign: 'center',
|
|
177
|
+
fontSize: componentTheme.fontSize,
|
|
178
|
+
whiteSpace: 'nowrap',
|
|
179
|
+
borderRadius: componentTheme.borderRadius,
|
|
180
|
+
...variants[variant].badge,
|
|
181
|
+
...(pulse && {
|
|
182
|
+
position: 'relative',
|
|
183
|
+
'&::before': {
|
|
184
|
+
content: '""',
|
|
185
|
+
width: 'calc(100% + 0.5rem)',
|
|
186
|
+
height: 'calc(100% + 0.5rem)',
|
|
187
|
+
borderRadius: componentTheme.borderRadius,
|
|
188
|
+
position: 'absolute',
|
|
189
|
+
top: '-0.25rem',
|
|
190
|
+
insetInlineEnd: 'auto',
|
|
191
|
+
insetInlineStart: '-0.25rem',
|
|
192
|
+
boxSizing: 'border-box',
|
|
193
|
+
border: `${componentTheme.pulseBorderThickness} solid`,
|
|
194
|
+
opacity: 0,
|
|
195
|
+
transform: 'scale(0.75)',
|
|
196
|
+
animationName: pulseAnimation,
|
|
197
|
+
animationDuration: '1s',
|
|
198
|
+
animationIterationCount: '4',
|
|
199
|
+
animationDirection: 'alternate',
|
|
200
|
+
...variants[variant].pulseBorder
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
...typeVariant[type],
|
|
204
|
+
...(!standalone && {
|
|
205
|
+
position: 'absolute',
|
|
206
|
+
zIndex: componentTheme.notificationZIndex,
|
|
207
|
+
...notStandaloneTypeVariant[type]
|
|
208
|
+
})
|
|
209
|
+
},
|
|
210
|
+
wrapper: {
|
|
211
|
+
label: 'badge__wrapper',
|
|
212
|
+
position: 'relative',
|
|
213
|
+
boxSizing: 'border-box',
|
|
214
|
+
svg: {
|
|
215
|
+
display: 'block'
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
export default generateStyle;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.Badge = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _v11_ = require("@instructure/ui-view/v11_6");
|
|
10
|
+
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
11
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
12
|
+
var _emotion = require("@instructure/emotion");
|
|
13
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
14
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
|
15
|
+
var _props = require("./props");
|
|
16
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
17
|
+
var _dec, _dec2, _class, _Badge;
|
|
18
|
+
/*
|
|
19
|
+
* The MIT License (MIT)
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
22
|
+
*
|
|
23
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
25
|
+
* in the Software without restriction, including without limitation the rights
|
|
26
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
28
|
+
* furnished to do so, subject to the following conditions:
|
|
29
|
+
*
|
|
30
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
31
|
+
* copies or substantial portions of the Software.
|
|
32
|
+
*
|
|
33
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
+
* SOFTWARE.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
category: components
|
|
44
|
+
---
|
|
45
|
+
**/
|
|
46
|
+
let Badge = exports.Badge = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_Badge = class Badge extends _react.Component {
|
|
47
|
+
constructor(props) {
|
|
48
|
+
super(props);
|
|
49
|
+
this._defaultId = void 0;
|
|
50
|
+
this.ref = null;
|
|
51
|
+
this.handleRef = el => {
|
|
52
|
+
const elementRef = this.props.elementRef;
|
|
53
|
+
this.ref = el;
|
|
54
|
+
if (typeof elementRef === 'function') {
|
|
55
|
+
elementRef(el);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this._defaultId = this.props.deterministicId();
|
|
59
|
+
}
|
|
60
|
+
componentDidMount() {
|
|
61
|
+
var _this$props$makeStyle, _this$props;
|
|
62
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
63
|
+
}
|
|
64
|
+
componentDidUpdate() {
|
|
65
|
+
var _this$props$makeStyle2, _this$props2;
|
|
66
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
67
|
+
}
|
|
68
|
+
countOverflow() {
|
|
69
|
+
const _this$props3 = this.props,
|
|
70
|
+
count = _this$props3.count,
|
|
71
|
+
countUntil = _this$props3.countUntil;
|
|
72
|
+
return countUntil && count && countUntil > 1 && count >= countUntil;
|
|
73
|
+
}
|
|
74
|
+
renderOutput() {
|
|
75
|
+
const _this$props4 = this.props,
|
|
76
|
+
count = _this$props4.count,
|
|
77
|
+
countUntil = _this$props4.countUntil,
|
|
78
|
+
formatOverflowText = _this$props4.formatOverflowText,
|
|
79
|
+
formatOutput = _this$props4.formatOutput,
|
|
80
|
+
type = _this$props4.type;
|
|
81
|
+
|
|
82
|
+
// If the badge count is >= than the countUntil limit, format the badge text
|
|
83
|
+
// via the formatOverflowText function prop
|
|
84
|
+
let formattedCount = (count || '').toString();
|
|
85
|
+
if (count && countUntil && formatOverflowText && type === 'count' && this.countOverflow()) {
|
|
86
|
+
formattedCount = formatOverflowText(count, countUntil);
|
|
87
|
+
}
|
|
88
|
+
if (typeof formatOutput === 'function') {
|
|
89
|
+
return formatOutput(formattedCount);
|
|
90
|
+
} else {
|
|
91
|
+
return type === 'count' ? formattedCount : null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
renderBadge() {
|
|
95
|
+
const _this$props5 = this.props,
|
|
96
|
+
count = _this$props5.count,
|
|
97
|
+
margin = _this$props5.margin,
|
|
98
|
+
standalone = _this$props5.standalone,
|
|
99
|
+
type = _this$props5.type,
|
|
100
|
+
styles = _this$props5.styles;
|
|
101
|
+
return (0, _jsxRuntime.jsx)(_v11_.View, {
|
|
102
|
+
margin: standalone ? margin : 'none',
|
|
103
|
+
css: styles === null || styles === void 0 ? void 0 : styles.badge,
|
|
104
|
+
title: type === 'count' && this.countOverflow() ? count === null || count === void 0 ? void 0 : count.toString() : '',
|
|
105
|
+
id: !standalone ? this._defaultId : void 0,
|
|
106
|
+
display: standalone ? 'inline-block' : 'block',
|
|
107
|
+
...(standalone && {
|
|
108
|
+
elementRef: this.handleRef,
|
|
109
|
+
'data-cid': 'Badge'
|
|
110
|
+
}),
|
|
111
|
+
children: this.renderOutput()
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
renderChildren() {
|
|
115
|
+
return _react.Children.map(this.props.children, child => {
|
|
116
|
+
return (0, _safeCloneElement.safeCloneElement)(child, {
|
|
117
|
+
'aria-describedby': this._defaultId
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
render() {
|
|
122
|
+
const _this$props6 = this.props,
|
|
123
|
+
margin = _this$props6.margin,
|
|
124
|
+
standalone = _this$props6.standalone,
|
|
125
|
+
display = _this$props6.display,
|
|
126
|
+
as = _this$props6.as,
|
|
127
|
+
styles = _this$props6.styles;
|
|
128
|
+
if (standalone) {
|
|
129
|
+
return this.renderBadge();
|
|
130
|
+
} else {
|
|
131
|
+
return (0, _jsxRuntime.jsxs)(_v11_.View, {
|
|
132
|
+
as: as,
|
|
133
|
+
margin: margin,
|
|
134
|
+
elementRef: this.handleRef,
|
|
135
|
+
css: styles === null || styles === void 0 ? void 0 : styles.wrapper,
|
|
136
|
+
display: display,
|
|
137
|
+
"data-cid": "Badge",
|
|
138
|
+
children: [this.renderChildren(), this.renderBadge()]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, _Badge.displayName = "Badge", _Badge.componentId = 'Badge', _Badge.allowedProps = _props.allowedProps, _Badge.defaultProps = {
|
|
143
|
+
standalone: false,
|
|
144
|
+
type: 'count',
|
|
145
|
+
variant: 'primary',
|
|
146
|
+
display: 'inline-block',
|
|
147
|
+
pulse: false,
|
|
148
|
+
placement: 'top end',
|
|
149
|
+
elementRef: () => {},
|
|
150
|
+
formatOverflowText: (_count, countUntil) => `${countUntil - 1} +`
|
|
151
|
+
}, _Badge)) || _class) || _class);
|
|
152
|
+
var _default = exports.default = Badge;
|
|
@@ -6,12 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.Badge = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var
|
|
9
|
+
var _latest = require("@instructure/ui-view/latest");
|
|
10
10
|
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
11
11
|
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
12
12
|
var _emotion = require("@instructure/emotion");
|
|
13
13
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
14
|
-
var _theme = _interopRequireDefault(require("./theme"));
|
|
15
14
|
var _props = require("./props");
|
|
16
15
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
17
16
|
var _dec, _dec2, _class, _Badge;
|
|
@@ -43,7 +42,7 @@ var _dec, _dec2, _class, _Badge;
|
|
|
43
42
|
category: components
|
|
44
43
|
---
|
|
45
44
|
**/
|
|
46
|
-
let Badge = exports.Badge = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default
|
|
45
|
+
let Badge = exports.Badge = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Badge = class Badge extends _react.Component {
|
|
47
46
|
constructor(props) {
|
|
48
47
|
super(props);
|
|
49
48
|
this._defaultId = void 0;
|
|
@@ -98,7 +97,7 @@ let Badge = exports.Badge = (_dec = (0, _withDeterministicId.withDeterministicId
|
|
|
98
97
|
standalone = _this$props5.standalone,
|
|
99
98
|
type = _this$props5.type,
|
|
100
99
|
styles = _this$props5.styles;
|
|
101
|
-
return (0, _jsxRuntime.jsx)(
|
|
100
|
+
return (0, _jsxRuntime.jsx)(_latest.View, {
|
|
102
101
|
margin: standalone ? margin : 'none',
|
|
103
102
|
css: styles === null || styles === void 0 ? void 0 : styles.badge,
|
|
104
103
|
title: type === 'count' && this.countOverflow() ? count === null || count === void 0 ? void 0 : count.toString() : '',
|
|
@@ -128,7 +127,7 @@ let Badge = exports.Badge = (_dec = (0, _withDeterministicId.withDeterministicId
|
|
|
128
127
|
if (standalone) {
|
|
129
128
|
return this.renderBadge();
|
|
130
129
|
} else {
|
|
131
|
-
return (0, _jsxRuntime.jsxs)(
|
|
130
|
+
return (0, _jsxRuntime.jsxs)(_latest.View, {
|
|
132
131
|
as: as,
|
|
133
132
|
margin: margin,
|
|
134
133
|
elementRef: this.handleRef,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// <unknown is needed for React 17 support
|
|
32
|
+
|
|
33
|
+
const allowedProps = exports.allowedProps = ['count', 'countUntil', 'children', 'type', 'standalone', 'pulse', 'variant', 'placement', 'display', 'margin', 'elementRef', 'formatOverflowText', 'formatOutput', 'as'];
|