@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,170 @@
|
|
|
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 { Component, Children, ReactElement } from 'react'
|
|
26
|
+
|
|
27
|
+
import { View } from '@instructure/ui-view/latest'
|
|
28
|
+
import {
|
|
29
|
+
safeCloneElement,
|
|
30
|
+
withDeterministicId
|
|
31
|
+
} from '@instructure/ui-react-utils'
|
|
32
|
+
|
|
33
|
+
import { withStyle } from '@instructure/emotion'
|
|
34
|
+
|
|
35
|
+
import generateStyle from './styles'
|
|
36
|
+
|
|
37
|
+
import { allowedProps } from './props'
|
|
38
|
+
import type { BadgeProps } from './props'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
---
|
|
42
|
+
category: components
|
|
43
|
+
---
|
|
44
|
+
**/
|
|
45
|
+
@withDeterministicId()
|
|
46
|
+
@withStyle(generateStyle)
|
|
47
|
+
class Badge extends Component<BadgeProps> {
|
|
48
|
+
static readonly componentId = 'Badge'
|
|
49
|
+
|
|
50
|
+
static allowedProps = allowedProps
|
|
51
|
+
static defaultProps = {
|
|
52
|
+
standalone: false,
|
|
53
|
+
type: 'count',
|
|
54
|
+
variant: 'primary',
|
|
55
|
+
display: 'inline-block',
|
|
56
|
+
pulse: false,
|
|
57
|
+
placement: 'top end',
|
|
58
|
+
elementRef: () => {},
|
|
59
|
+
formatOverflowText: (_count: number, countUntil: number) =>
|
|
60
|
+
`${countUntil - 1} +`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
constructor(props: BadgeProps) {
|
|
64
|
+
super(props)
|
|
65
|
+
this._defaultId = this.props.deterministicId!()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_defaultId: string
|
|
69
|
+
|
|
70
|
+
ref: Element | null = null
|
|
71
|
+
|
|
72
|
+
handleRef = (el: Element | null) => {
|
|
73
|
+
const { elementRef } = this.props
|
|
74
|
+
|
|
75
|
+
this.ref = el
|
|
76
|
+
|
|
77
|
+
if (typeof elementRef === 'function') {
|
|
78
|
+
elementRef(el)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
componentDidMount() {
|
|
83
|
+
this.props.makeStyles?.()
|
|
84
|
+
}
|
|
85
|
+
componentDidUpdate() {
|
|
86
|
+
this.props.makeStyles?.()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
countOverflow() {
|
|
90
|
+
const { count, countUntil } = this.props
|
|
91
|
+
|
|
92
|
+
return countUntil && count && countUntil > 1 && count >= countUntil
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
renderOutput() {
|
|
96
|
+
const { count, countUntil, formatOverflowText, formatOutput, type } =
|
|
97
|
+
this.props
|
|
98
|
+
|
|
99
|
+
// If the badge count is >= than the countUntil limit, format the badge text
|
|
100
|
+
// via the formatOverflowText function prop
|
|
101
|
+
let formattedCount = (count || '').toString()
|
|
102
|
+
if (
|
|
103
|
+
count &&
|
|
104
|
+
countUntil &&
|
|
105
|
+
formatOverflowText &&
|
|
106
|
+
type === 'count' &&
|
|
107
|
+
this.countOverflow()
|
|
108
|
+
) {
|
|
109
|
+
formattedCount = formatOverflowText(count, countUntil)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (typeof formatOutput === 'function') {
|
|
113
|
+
return formatOutput(formattedCount)
|
|
114
|
+
} else {
|
|
115
|
+
return type === 'count' ? formattedCount : null
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
renderBadge() {
|
|
120
|
+
const { count, margin, standalone, type, styles } = this.props
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<View
|
|
124
|
+
margin={standalone ? margin : 'none'}
|
|
125
|
+
css={styles?.badge}
|
|
126
|
+
title={
|
|
127
|
+
type === 'count' && this.countOverflow() ? count?.toString() : ''
|
|
128
|
+
}
|
|
129
|
+
id={!standalone ? this._defaultId : undefined}
|
|
130
|
+
display={standalone ? 'inline-block' : 'block'}
|
|
131
|
+
{...(standalone && { elementRef: this.handleRef, 'data-cid': 'Badge' })}
|
|
132
|
+
>
|
|
133
|
+
{this.renderOutput()}
|
|
134
|
+
</View>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
renderChildren() {
|
|
139
|
+
return Children.map(this.props.children, (child) => {
|
|
140
|
+
return safeCloneElement(child as ReactElement, {
|
|
141
|
+
'aria-describedby': this._defaultId
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
render() {
|
|
147
|
+
const { margin, standalone, display, as, styles } = this.props
|
|
148
|
+
|
|
149
|
+
if (standalone) {
|
|
150
|
+
return this.renderBadge()
|
|
151
|
+
} else {
|
|
152
|
+
return (
|
|
153
|
+
<View
|
|
154
|
+
as={as}
|
|
155
|
+
margin={margin}
|
|
156
|
+
elementRef={this.handleRef}
|
|
157
|
+
css={styles?.wrapper}
|
|
158
|
+
display={display}
|
|
159
|
+
data-cid="Badge"
|
|
160
|
+
>
|
|
161
|
+
{this.renderChildren()}
|
|
162
|
+
{this.renderBadge()}
|
|
163
|
+
</View>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default Badge
|
|
170
|
+
export { Badge }
|
|
@@ -0,0 +1,112 @@
|
|
|
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 React from 'react'
|
|
26
|
+
import type { AsElementType, BadgeTheme } from '@instructure/shared-types'
|
|
27
|
+
import type {
|
|
28
|
+
Spacing,
|
|
29
|
+
WithStyleProps,
|
|
30
|
+
ComponentStyle
|
|
31
|
+
} from '@instructure/emotion'
|
|
32
|
+
import type { PlacementPropValues } from '@instructure/ui-position'
|
|
33
|
+
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
34
|
+
import type { PropsWithChildren } from 'react'
|
|
35
|
+
|
|
36
|
+
type BadgeOwnProps = {
|
|
37
|
+
count?: number
|
|
38
|
+
/**
|
|
39
|
+
* The number at which the count gets truncated by
|
|
40
|
+
* formatOverflowText. For example, a countUntil of 100
|
|
41
|
+
* would stop the count at 99.
|
|
42
|
+
*/
|
|
43
|
+
countUntil?: number
|
|
44
|
+
/**
|
|
45
|
+
* Render Badge as a counter (`count`) or as a smaller dot (`notification`) with
|
|
46
|
+
* no count number displayed.
|
|
47
|
+
*/
|
|
48
|
+
type?: 'count' | 'notification'
|
|
49
|
+
/**
|
|
50
|
+
* Render Badge as an inline html element that is not positioned relative
|
|
51
|
+
* to a child.
|
|
52
|
+
*/
|
|
53
|
+
standalone?: boolean
|
|
54
|
+
/**
|
|
55
|
+
* Make the Badge slowly pulse twice to get the user's attention.
|
|
56
|
+
*/
|
|
57
|
+
pulse?: boolean
|
|
58
|
+
variant?: 'primary' | 'success' | 'danger' | 'inverse'
|
|
59
|
+
/**
|
|
60
|
+
* provides a reference to the underlying html root element
|
|
61
|
+
*/
|
|
62
|
+
elementRef?: (element: Element | null) => void
|
|
63
|
+
formatOverflowText?: (count: number, countUntil: number) => string
|
|
64
|
+
formatOutput?: (formattedCount: string) => React.JSX.Element | string | number
|
|
65
|
+
as?: AsElementType
|
|
66
|
+
/**
|
|
67
|
+
* Specifies the display property of the container.
|
|
68
|
+
*
|
|
69
|
+
* __Use "block" only when the content inside the Badge also has "block" display.__
|
|
70
|
+
*/
|
|
71
|
+
display?: 'inline-block' | 'block'
|
|
72
|
+
/**
|
|
73
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
74
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
75
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
76
|
+
*/
|
|
77
|
+
margin?: Spacing
|
|
78
|
+
/**
|
|
79
|
+
* Supported values are `top start`, `top end`, `end center`, `bottom end`,
|
|
80
|
+
* `bottom start`, and `start center`
|
|
81
|
+
*/
|
|
82
|
+
placement?: PlacementPropValues
|
|
83
|
+
} & PropsWithChildren<unknown> // <unknown is needed for React 17 support
|
|
84
|
+
|
|
85
|
+
type PropKeys = keyof BadgeOwnProps
|
|
86
|
+
|
|
87
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
88
|
+
|
|
89
|
+
type BadgeProps = BadgeOwnProps &
|
|
90
|
+
WithStyleProps<BadgeTheme, BadgeStyle> &
|
|
91
|
+
WithDeterministicIdProps
|
|
92
|
+
|
|
93
|
+
type BadgeStyle = ComponentStyle<'badge' | 'wrapper'>
|
|
94
|
+
const allowedProps: AllowedPropKeys = [
|
|
95
|
+
'count',
|
|
96
|
+
'countUntil',
|
|
97
|
+
'children',
|
|
98
|
+
'type',
|
|
99
|
+
'standalone',
|
|
100
|
+
'pulse',
|
|
101
|
+
'variant',
|
|
102
|
+
'placement',
|
|
103
|
+
'display',
|
|
104
|
+
'margin',
|
|
105
|
+
'elementRef',
|
|
106
|
+
'formatOverflowText',
|
|
107
|
+
'formatOutput',
|
|
108
|
+
'as'
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
export type { BadgeProps, BadgeStyle }
|
|
112
|
+
export { allowedProps }
|
|
@@ -0,0 +1,226 @@
|
|
|
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
|
+
|
|
27
|
+
import type { NewComponentTypes } from '@instructure/ui-themes'
|
|
28
|
+
import type { BadgeProps, BadgeStyle } from './props'
|
|
29
|
+
|
|
30
|
+
// keyframes have to be outside of 'generateStyle',
|
|
31
|
+
// since it is causing problems in style recalculation
|
|
32
|
+
const pulseAnimation = keyframes`
|
|
33
|
+
to {
|
|
34
|
+
transform: scale(1);
|
|
35
|
+
opacity: 0.9;
|
|
36
|
+
}`
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ---
|
|
40
|
+
* private: true
|
|
41
|
+
* ---
|
|
42
|
+
* Generates the style object from the theme and provided additional information
|
|
43
|
+
* @param {Object} componentTheme The theme variable object.
|
|
44
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
45
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
46
|
+
* @return {Object} The final style object, which will be used in the component
|
|
47
|
+
*/
|
|
48
|
+
const generateStyle = (
|
|
49
|
+
componentTheme: NewComponentTypes['Badge'],
|
|
50
|
+
props: BadgeProps
|
|
51
|
+
): BadgeStyle => {
|
|
52
|
+
const { type, variant, placement = '', standalone, pulse } = props
|
|
53
|
+
|
|
54
|
+
const top = placement.indexOf('top') > -1
|
|
55
|
+
const bottom = placement.indexOf('bottom') > -1
|
|
56
|
+
const start = placement.indexOf('start') > -1
|
|
57
|
+
const end = placement.indexOf('end') > -1
|
|
58
|
+
const center = placement.indexOf('center') > -1
|
|
59
|
+
|
|
60
|
+
const variants = {
|
|
61
|
+
danger: {
|
|
62
|
+
badge: {
|
|
63
|
+
color: componentTheme.color,
|
|
64
|
+
backgroundColor: componentTheme.colorDanger
|
|
65
|
+
},
|
|
66
|
+
pulseBorder: {
|
|
67
|
+
borderColor: componentTheme.colorDanger
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
success: {
|
|
71
|
+
badge: {
|
|
72
|
+
color: componentTheme.color,
|
|
73
|
+
backgroundColor: componentTheme.colorSuccess
|
|
74
|
+
},
|
|
75
|
+
pulseBorder: {
|
|
76
|
+
borderColor: componentTheme.colorSuccess
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
primary: {
|
|
80
|
+
badge: {
|
|
81
|
+
color: componentTheme.color,
|
|
82
|
+
backgroundColor: componentTheme.colorPrimary
|
|
83
|
+
},
|
|
84
|
+
pulseBorder: {
|
|
85
|
+
borderColor: componentTheme.colorPrimary
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
inverse: {
|
|
89
|
+
// text and background colors are swapped
|
|
90
|
+
badge: {
|
|
91
|
+
color: componentTheme.colorInverse,
|
|
92
|
+
backgroundColor: componentTheme.color
|
|
93
|
+
},
|
|
94
|
+
pulseBorder: {
|
|
95
|
+
borderColor: componentTheme.color
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const countPositions = {
|
|
101
|
+
...(top && { top: `calc(-1 * ${componentTheme.countOffset})` }),
|
|
102
|
+
...(bottom && { bottom: `calc(-1 * ${componentTheme.countOffset})` }),
|
|
103
|
+
...(start && {
|
|
104
|
+
insetInlineStart: `calc(-1 * ${componentTheme.countOffset})`,
|
|
105
|
+
insetInlineEnd: 'auto'
|
|
106
|
+
}),
|
|
107
|
+
...(end && {
|
|
108
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.countOffset})`,
|
|
109
|
+
insetInlineStart: 'auto'
|
|
110
|
+
}),
|
|
111
|
+
...(center && {
|
|
112
|
+
...((end || start) && {
|
|
113
|
+
top: `calc(50% - (${componentTheme.size} / 2))`
|
|
114
|
+
}),
|
|
115
|
+
...(start && {
|
|
116
|
+
insetInlineStart: 'auto',
|
|
117
|
+
insetInlineEnd: `calc(100% - ${componentTheme.countOffset})`
|
|
118
|
+
}),
|
|
119
|
+
...(end && {
|
|
120
|
+
insetInlineEnd: 'auto',
|
|
121
|
+
insetInlineStart: `calc(100% - ${componentTheme.countOffset})`
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const notificationPositions = {
|
|
127
|
+
...(top && { top: componentTheme.notificationOffset }),
|
|
128
|
+
...(bottom && { bottom: componentTheme.notificationOffset }),
|
|
129
|
+
...(start && {
|
|
130
|
+
insetInlineStart: componentTheme.notificationOffset,
|
|
131
|
+
insetInlineEnd: 'auto'
|
|
132
|
+
}),
|
|
133
|
+
...(end && {
|
|
134
|
+
insetInlineEnd: componentTheme.notificationOffset,
|
|
135
|
+
insetInlineStart: 'auto'
|
|
136
|
+
}),
|
|
137
|
+
...(center && {
|
|
138
|
+
...((end || start) && {
|
|
139
|
+
top: `calc(50% - (${componentTheme.sizeNotification} / 2))`
|
|
140
|
+
}),
|
|
141
|
+
...(start && {
|
|
142
|
+
insetInlineStart: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
143
|
+
insetInlineEnd: 'auto'
|
|
144
|
+
}),
|
|
145
|
+
...(end && {
|
|
146
|
+
insetInlineEnd: `calc(-1 * ${componentTheme.sizeNotification} / 2)`,
|
|
147
|
+
insetInlineStart: 'auto'
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const notStandaloneTypeVariant = {
|
|
153
|
+
count: countPositions,
|
|
154
|
+
notification: notificationPositions
|
|
155
|
+
}
|
|
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
|
+
|
|
170
|
+
return {
|
|
171
|
+
badge: {
|
|
172
|
+
label: 'badge',
|
|
173
|
+
fontFamily: componentTheme.fontFamily,
|
|
174
|
+
fontWeight: componentTheme.fontWeight,
|
|
175
|
+
boxSizing: 'border-box',
|
|
176
|
+
pointerEvents: 'none',
|
|
177
|
+
textAlign: 'center',
|
|
178
|
+
fontSize: componentTheme.fontSize,
|
|
179
|
+
whiteSpace: 'nowrap',
|
|
180
|
+
borderRadius: componentTheme.borderRadius,
|
|
181
|
+
|
|
182
|
+
...variants[variant!].badge,
|
|
183
|
+
|
|
184
|
+
...(pulse && {
|
|
185
|
+
position: 'relative',
|
|
186
|
+
|
|
187
|
+
'&::before': {
|
|
188
|
+
content: '""',
|
|
189
|
+
width: 'calc(100% + 0.5rem)',
|
|
190
|
+
height: 'calc(100% + 0.5rem)',
|
|
191
|
+
borderRadius: componentTheme.borderRadius,
|
|
192
|
+
position: 'absolute',
|
|
193
|
+
top: '-0.25rem',
|
|
194
|
+
insetInlineEnd: 'auto',
|
|
195
|
+
insetInlineStart: '-0.25rem',
|
|
196
|
+
boxSizing: 'border-box',
|
|
197
|
+
border: `${componentTheme.pulseBorderThickness} solid`,
|
|
198
|
+
opacity: 0,
|
|
199
|
+
transform: 'scale(0.75)',
|
|
200
|
+
animationName: pulseAnimation,
|
|
201
|
+
animationDuration: '1s',
|
|
202
|
+
animationIterationCount: '4',
|
|
203
|
+
animationDirection: 'alternate',
|
|
204
|
+
...variants[variant!].pulseBorder
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
|
|
208
|
+
...typeVariant[type!],
|
|
209
|
+
|
|
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
|
+
|
|
221
|
+
svg: { display: 'block' }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export default generateStyle
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export { Badge } from '../Badge/v1'
|
|
26
|
+
export type { BadgeProps } from '../Badge/v1/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export { Badge } from '../Badge/v2'
|
|
26
|
+
export type { BadgeProps } from '../Badge/v2/props'
|