@instructure/ui-avatar 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 +39 -294
- package/es/Avatar/{index.js → v1/index.js} +2 -2
- package/es/Avatar/v2/index.js +168 -0
- package/es/Avatar/v2/props.js +35 -0
- package/es/Avatar/v2/styles.js +166 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Avatar/{index.js → v1/index.js} +3 -3
- package/lib/Avatar/v2/index.js +174 -0
- package/lib/Avatar/v2/props.js +40 -0
- package/lib/Avatar/v2/styles.js +172 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +39 -17
- package/src/Avatar/{index.tsx → v1/index.tsx} +2 -2
- package/src/Avatar/v2/README.md +277 -0
- package/src/Avatar/v2/index.tsx +175 -0
- package/src/Avatar/v2/props.ts +137 -0
- package/src/Avatar/v2/styles.ts +194 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Avatar/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Avatar/v1/index.d.ts.map +1 -0
- package/types/Avatar/v1/props.d.ts.map +1 -0
- package/types/Avatar/v1/styles.d.ts.map +1 -0
- package/types/Avatar/v1/theme.d.ts.map +1 -0
- package/types/Avatar/v2/index.d.ts +60 -0
- package/types/Avatar/v2/index.d.ts.map +1 -0
- package/types/Avatar/v2/props.d.ts +76 -0
- package/types/Avatar/v2/props.d.ts.map +1 -0
- package/types/Avatar/v2/styles.d.ts +26 -0
- package/types/Avatar/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/Avatar/index.d.ts.map +0 -1
- package/types/Avatar/props.d.ts.map +0 -1
- package/types/Avatar/styles.d.ts.map +0 -1
- package/types/Avatar/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Avatar/{props.js → v1/props.js} +0 -0
- /package/es/Avatar/{styles.js → v1/styles.js} +0 -0
- /package/es/Avatar/{theme.js → v1/theme.js} +0 -0
- /package/lib/Avatar/{props.js → v1/props.js} +0 -0
- /package/lib/Avatar/{styles.js → v1/styles.js} +0 -0
- /package/lib/Avatar/{theme.js → v1/theme.js} +0 -0
- /package/src/Avatar/{README.md → v1/README.md} +0 -0
- /package/src/Avatar/{props.ts → v1/props.ts} +0 -0
- /package/src/Avatar/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Avatar/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Avatar/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Avatar/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Avatar/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
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 { useStyle } from '@instructure/emotion'
|
|
26
|
+
import { useState, useEffect, forwardRef, SyntheticEvent } from 'react'
|
|
27
|
+
|
|
28
|
+
import { passthroughProps } from '@instructure/ui-react-utils'
|
|
29
|
+
import { renderIconWithProps } from '@instructure/ui-icons'
|
|
30
|
+
import { AvatarProps, avatarSizeToIconSize } from './props'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
|
|
34
|
+
const ICON_COLOR_MAP = {
|
|
35
|
+
accent1: 'accentBlueColor',
|
|
36
|
+
accent2: 'accentGreenColor',
|
|
37
|
+
accent3: 'accentRedColor',
|
|
38
|
+
accent4: 'accentOrangeColor',
|
|
39
|
+
accent5: 'accentGreyColor',
|
|
40
|
+
accent6: 'accentAshColor',
|
|
41
|
+
ai: 'onColor'
|
|
42
|
+
} as const
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
category: components
|
|
47
|
+
---
|
|
48
|
+
**/
|
|
49
|
+
const Avatar = forwardRef<HTMLDivElement, AvatarProps>(
|
|
50
|
+
(props: AvatarProps, ref) => {
|
|
51
|
+
const {
|
|
52
|
+
size = 'medium',
|
|
53
|
+
color = 'accent1',
|
|
54
|
+
hasInverseColor = false,
|
|
55
|
+
showBorder = 'auto',
|
|
56
|
+
shape = 'circle',
|
|
57
|
+
display = 'inline',
|
|
58
|
+
onImageLoaded = (_event: SyntheticEvent) => {},
|
|
59
|
+
src,
|
|
60
|
+
name,
|
|
61
|
+
renderIcon,
|
|
62
|
+
alt,
|
|
63
|
+
themeOverride,
|
|
64
|
+
margin
|
|
65
|
+
} = props
|
|
66
|
+
const [loaded, setLoaded] = useState(false)
|
|
67
|
+
|
|
68
|
+
const styles = useStyle({
|
|
69
|
+
generateStyle,
|
|
70
|
+
themeOverride,
|
|
71
|
+
params: {
|
|
72
|
+
loaded,
|
|
73
|
+
size,
|
|
74
|
+
color,
|
|
75
|
+
hasInverseColor,
|
|
76
|
+
shape,
|
|
77
|
+
src,
|
|
78
|
+
showBorder,
|
|
79
|
+
display,
|
|
80
|
+
margin
|
|
81
|
+
},
|
|
82
|
+
componentId: 'Avatar',
|
|
83
|
+
displayName: 'Avatar'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
// in case the image is unset in an update, show icons/initials again
|
|
88
|
+
if (loaded && !src) {
|
|
89
|
+
setLoaded(false)
|
|
90
|
+
}
|
|
91
|
+
// Image already loaded (common in SSR)
|
|
92
|
+
//TODO-rework make this work
|
|
93
|
+
// if (src && !loaded && imgRef.current && imgRef.current.complete) {
|
|
94
|
+
// setLoaded(true)
|
|
95
|
+
// onImageLoaded?.()
|
|
96
|
+
// }
|
|
97
|
+
}, [loaded, src])
|
|
98
|
+
|
|
99
|
+
const makeInitialsFromName = () => {
|
|
100
|
+
if (!name || typeof name !== 'string' || name.trim().length === 0) {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
const currentName = name.trim()
|
|
104
|
+
|
|
105
|
+
if (currentName.match(/\s+/)) {
|
|
106
|
+
const names = currentName.split(/\s+/)
|
|
107
|
+
return (names[0][0] + names[names.length - 1][0]).toUpperCase()
|
|
108
|
+
} else {
|
|
109
|
+
return currentName[0].toUpperCase()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const renderInitials = () => {
|
|
114
|
+
return <span aria-hidden="true">{makeInitialsFromName()}</span>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const renderImage = () => (
|
|
118
|
+
<img
|
|
119
|
+
style={{
|
|
120
|
+
width: '100%',
|
|
121
|
+
height: '100%',
|
|
122
|
+
objectFit: 'cover',
|
|
123
|
+
objectPosition: 'center',
|
|
124
|
+
...(loaded ? {} : { display: 'none' })
|
|
125
|
+
}}
|
|
126
|
+
src={src}
|
|
127
|
+
alt={alt ? alt : ''}
|
|
128
|
+
onLoad={(event: SyntheticEvent) => {
|
|
129
|
+
setLoaded(true)
|
|
130
|
+
onImageLoaded(event)
|
|
131
|
+
}}
|
|
132
|
+
/>
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
const renderContent = () => {
|
|
136
|
+
//image in avatar - prioritize image over icon
|
|
137
|
+
if (src) {
|
|
138
|
+
return (
|
|
139
|
+
<>
|
|
140
|
+
{renderImage()}
|
|
141
|
+
{loaded ? null : renderInitials()}
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//icon in avatar
|
|
147
|
+
if (renderIcon) {
|
|
148
|
+
const iconSize = avatarSizeToIconSize[size]
|
|
149
|
+
const iconColor = hasInverseColor ? 'onColor' : ICON_COLOR_MAP[color]
|
|
150
|
+
|
|
151
|
+
return renderIconWithProps(renderIcon, iconSize, iconColor)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//initials in avatar
|
|
155
|
+
return renderInitials()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<div
|
|
160
|
+
{...passthroughProps({ ...props })}
|
|
161
|
+
ref={ref}
|
|
162
|
+
aria-label={alt ? alt : undefined}
|
|
163
|
+
role={alt ? 'img' : undefined}
|
|
164
|
+
css={styles?.avatar}
|
|
165
|
+
>
|
|
166
|
+
{renderContent()}
|
|
167
|
+
</div>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
Avatar.displayName = 'Avatar'
|
|
173
|
+
|
|
174
|
+
export default Avatar
|
|
175
|
+
export { Avatar }
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { SyntheticEvent } from 'react'
|
|
26
|
+
|
|
27
|
+
import type {
|
|
28
|
+
Spacing,
|
|
29
|
+
ComponentStyle,
|
|
30
|
+
ThemeOverrideValue
|
|
31
|
+
} from '@instructure/emotion'
|
|
32
|
+
import type {
|
|
33
|
+
AsElementType,
|
|
34
|
+
OtherHTMLAttributes,
|
|
35
|
+
Renderable
|
|
36
|
+
} from '@instructure/shared-types'
|
|
37
|
+
|
|
38
|
+
const avatarSizeToIconSize = {
|
|
39
|
+
'xx-small': 'xs',
|
|
40
|
+
'x-small': 'xs',
|
|
41
|
+
small: 'sm',
|
|
42
|
+
medium: 'md',
|
|
43
|
+
large: 'lg',
|
|
44
|
+
'x-large': 'xl',
|
|
45
|
+
'xx-large': '2xl'
|
|
46
|
+
} as const
|
|
47
|
+
|
|
48
|
+
type AvatarOwnProps = {
|
|
49
|
+
/**
|
|
50
|
+
* The name to display. It will be automatically converted to initials.
|
|
51
|
+
*/
|
|
52
|
+
name: string
|
|
53
|
+
/**
|
|
54
|
+
* URL of the image to display as the background image
|
|
55
|
+
*/
|
|
56
|
+
src?: string
|
|
57
|
+
/**
|
|
58
|
+
* Accessible label
|
|
59
|
+
*/
|
|
60
|
+
alt?: string
|
|
61
|
+
size?: keyof typeof avatarSizeToIconSize
|
|
62
|
+
color?:
|
|
63
|
+
| 'accent1'
|
|
64
|
+
| 'accent2'
|
|
65
|
+
| 'accent3'
|
|
66
|
+
| 'accent4'
|
|
67
|
+
| 'accent5'
|
|
68
|
+
| 'accent6'
|
|
69
|
+
| 'ai'
|
|
70
|
+
/**
|
|
71
|
+
* In inverse color mode the background and text/icon colors are inverted
|
|
72
|
+
*/
|
|
73
|
+
hasInverseColor?: boolean
|
|
74
|
+
/**
|
|
75
|
+
* `auto` only shows a border when there is no source image. This prop can force to always or never show that border.
|
|
76
|
+
*/
|
|
77
|
+
showBorder?: 'auto' | 'always' | 'never'
|
|
78
|
+
shape?: 'circle' | 'rectangle'
|
|
79
|
+
display?: 'inline' | 'block'
|
|
80
|
+
/**
|
|
81
|
+
* Valid values are `0`, `none`, `auto`, and Spacing token values,
|
|
82
|
+
* see https://instructure.design/layout-spacing. Apply these values via
|
|
83
|
+
* familiar CSS-like shorthand. For example, `margin="small auto large"`.
|
|
84
|
+
*/
|
|
85
|
+
margin?: Spacing
|
|
86
|
+
/**
|
|
87
|
+
* Callback fired when the avatar image has loaded.
|
|
88
|
+
* `event` can be `undefined`, if its already loaded when the page renders
|
|
89
|
+
* (can happen in SSR)
|
|
90
|
+
*/
|
|
91
|
+
onImageLoaded?: (event?: SyntheticEvent) => void
|
|
92
|
+
/**
|
|
93
|
+
* The element type to render as
|
|
94
|
+
*/
|
|
95
|
+
as?: AsElementType
|
|
96
|
+
/**
|
|
97
|
+
* provides a reference to the underlying html root element
|
|
98
|
+
*/
|
|
99
|
+
elementRef?: (element: Element | null) => void
|
|
100
|
+
/**
|
|
101
|
+
* An icon, or function that returns an icon that gets displayed. If the `src` prop is provided, `src` will have priority.
|
|
102
|
+
* When using Lucide icons, Avatar will automatically pass the appropriate size and color props based on the Avatar's size and color.
|
|
103
|
+
*/
|
|
104
|
+
renderIcon?: Renderable
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type AvatarState = {
|
|
108
|
+
loaded: boolean
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type PropKeys = keyof AvatarOwnProps
|
|
112
|
+
|
|
113
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
114
|
+
|
|
115
|
+
type AvatarProps = AvatarOwnProps & {
|
|
116
|
+
themeOverride?: ThemeOverrideValue
|
|
117
|
+
} & OtherHTMLAttributes<AvatarOwnProps>
|
|
118
|
+
|
|
119
|
+
type AvatarStyle = ComponentStyle<'avatar' | 'image'>
|
|
120
|
+
|
|
121
|
+
const allowedProps: AllowedPropKeys = [
|
|
122
|
+
'name',
|
|
123
|
+
'src',
|
|
124
|
+
'alt',
|
|
125
|
+
'size',
|
|
126
|
+
'color',
|
|
127
|
+
'hasInverseColor',
|
|
128
|
+
'shape',
|
|
129
|
+
'margin',
|
|
130
|
+
'display',
|
|
131
|
+
'onImageLoaded',
|
|
132
|
+
'renderIcon',
|
|
133
|
+
'showBorder'
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
export type { AvatarProps, AvatarStyle }
|
|
137
|
+
export { allowedProps, avatarSizeToIconSize }
|
|
@@ -0,0 +1,194 @@
|
|
|
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 { calcSpacingFromShorthand } from '@instructure/emotion'
|
|
26
|
+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
27
|
+
import { AvatarProps, AvatarStyle } from './props'
|
|
28
|
+
|
|
29
|
+
type StyleParams = {
|
|
30
|
+
loaded: boolean
|
|
31
|
+
size: AvatarProps['size']
|
|
32
|
+
color: AvatarProps['color']
|
|
33
|
+
hasInverseColor: AvatarProps['hasInverseColor']
|
|
34
|
+
shape: AvatarProps['shape']
|
|
35
|
+
src: AvatarProps['src']
|
|
36
|
+
showBorder: AvatarProps['showBorder']
|
|
37
|
+
display: AvatarProps['display']
|
|
38
|
+
margin: AvatarProps['margin']
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* ---
|
|
42
|
+
* private: true
|
|
43
|
+
* ---
|
|
44
|
+
* Generates the style object from the theme and provided additional information
|
|
45
|
+
* @param componentTheme The theme variable object.
|
|
46
|
+
* @param params Additional parameters to customize the style.
|
|
47
|
+
* @param sharedTokens Shared token object that stores common values for the theme.
|
|
48
|
+
* @return The final style object, which will be used in the component
|
|
49
|
+
*/
|
|
50
|
+
const generateStyle = (
|
|
51
|
+
componentTheme: NewComponentTypes['Avatar'],
|
|
52
|
+
params: StyleParams,
|
|
53
|
+
sharedTokens: SharedTokens
|
|
54
|
+
): AvatarStyle => {
|
|
55
|
+
const {
|
|
56
|
+
loaded,
|
|
57
|
+
size,
|
|
58
|
+
color,
|
|
59
|
+
hasInverseColor,
|
|
60
|
+
shape,
|
|
61
|
+
showBorder,
|
|
62
|
+
display,
|
|
63
|
+
margin
|
|
64
|
+
} = params
|
|
65
|
+
|
|
66
|
+
const sizeStyles = {
|
|
67
|
+
'xx-small': {
|
|
68
|
+
fontSize: componentTheme.fontSize2xs,
|
|
69
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
70
|
+
width: componentTheme.size2xs,
|
|
71
|
+
height: componentTheme.size2xs
|
|
72
|
+
},
|
|
73
|
+
'x-small': {
|
|
74
|
+
fontSize: componentTheme.fontSizeXs,
|
|
75
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
76
|
+
width: componentTheme.sizeXs,
|
|
77
|
+
height: componentTheme.sizeXs
|
|
78
|
+
},
|
|
79
|
+
small: {
|
|
80
|
+
fontSize: componentTheme.fontSizeSm,
|
|
81
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
82
|
+
width: componentTheme.sizeSm,
|
|
83
|
+
height: componentTheme.sizeSm
|
|
84
|
+
},
|
|
85
|
+
medium: {
|
|
86
|
+
fontSize: componentTheme.fontSizeMd,
|
|
87
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
88
|
+
width: componentTheme.sizeMd,
|
|
89
|
+
height: componentTheme.sizeMd
|
|
90
|
+
},
|
|
91
|
+
large: {
|
|
92
|
+
fontSize: componentTheme.fontSizeLg,
|
|
93
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
94
|
+
width: componentTheme.sizeLg,
|
|
95
|
+
height: componentTheme.sizeLg
|
|
96
|
+
},
|
|
97
|
+
'x-large': {
|
|
98
|
+
fontSize: componentTheme.fontSizeXl,
|
|
99
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
100
|
+
width: componentTheme.sizeXl,
|
|
101
|
+
height: componentTheme.sizeXl
|
|
102
|
+
},
|
|
103
|
+
'xx-large': {
|
|
104
|
+
fontSize: componentTheme.fontSize2xl,
|
|
105
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
106
|
+
width: componentTheme.size2xl,
|
|
107
|
+
height: componentTheme.size2xl
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const colorVariants = {
|
|
112
|
+
accent1: {
|
|
113
|
+
text: componentTheme.blueTextColor,
|
|
114
|
+
background: componentTheme.blueBackgroundColor
|
|
115
|
+
},
|
|
116
|
+
accent2: {
|
|
117
|
+
text: componentTheme.greenTextColor,
|
|
118
|
+
background: componentTheme.greenBackgroundColor
|
|
119
|
+
},
|
|
120
|
+
accent3: {
|
|
121
|
+
text: componentTheme.redTextColor,
|
|
122
|
+
background: componentTheme.redBackgroundColor
|
|
123
|
+
},
|
|
124
|
+
accent4: {
|
|
125
|
+
text: componentTheme.orangeTextColor,
|
|
126
|
+
background: componentTheme.orangeBackgroundColor
|
|
127
|
+
},
|
|
128
|
+
accent5: {
|
|
129
|
+
text: componentTheme.greyTextColor,
|
|
130
|
+
background: componentTheme.greyBackgroundColor
|
|
131
|
+
},
|
|
132
|
+
accent6: {
|
|
133
|
+
text: componentTheme.ashTextColor,
|
|
134
|
+
background: componentTheme.ashBackgroundColor
|
|
135
|
+
},
|
|
136
|
+
ai: {
|
|
137
|
+
text: componentTheme.textOnColor,
|
|
138
|
+
background: `linear-gradient(135deg, ${componentTheme.aiTopGradientColor} 0%, ${componentTheme.aiBottomGradientColor} 100%)`
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const getBorder = () => {
|
|
143
|
+
if (showBorder === 'never') {
|
|
144
|
+
return 'none'
|
|
145
|
+
}
|
|
146
|
+
if (showBorder === 'always') {
|
|
147
|
+
return 'solid'
|
|
148
|
+
}
|
|
149
|
+
//if none of the above, so auto
|
|
150
|
+
if (hasInverseColor || color === 'ai') {
|
|
151
|
+
return 'none'
|
|
152
|
+
}
|
|
153
|
+
return 'solid'
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
avatar: {
|
|
158
|
+
label: 'avatar',
|
|
159
|
+
boxSizing: 'border-box',
|
|
160
|
+
border: getBorder(),
|
|
161
|
+
borderRadius: shape === 'circle' ? '50%' : 0,
|
|
162
|
+
...sizeStyles[size!],
|
|
163
|
+
background:
|
|
164
|
+
hasInverseColor || color === 'ai'
|
|
165
|
+
? colorVariants[color!].background
|
|
166
|
+
: componentTheme.backgroundColor,
|
|
167
|
+
display: display === 'inline' ? 'inline-flex' : 'flex',
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
justifyContent: 'center',
|
|
170
|
+
verticalAlign: 'middle',
|
|
171
|
+
color: hasInverseColor
|
|
172
|
+
? componentTheme.textOnColor
|
|
173
|
+
: colorVariants[color!].text,
|
|
174
|
+
borderColor: componentTheme.borderColor,
|
|
175
|
+
fontWeight: componentTheme.fontWeight,
|
|
176
|
+
overflow: 'hidden',
|
|
177
|
+
// TODO handle the merging on tokens inside the util
|
|
178
|
+
margin: calcSpacingFromShorthand(margin, {
|
|
179
|
+
...sharedTokens.spacing,
|
|
180
|
+
...sharedTokens.legacy.spacing
|
|
181
|
+
})
|
|
182
|
+
},
|
|
183
|
+
image: {
|
|
184
|
+
label: 'avatar__image',
|
|
185
|
+
width: '100%',
|
|
186
|
+
height: '100%',
|
|
187
|
+
objectFit: 'cover',
|
|
188
|
+
objectPosition: 'center',
|
|
189
|
+
...(loaded ? {} : { display: 'none' })
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export default generateStyle
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
export { Avatar } from '../Avatar/v1'
|
|
25
|
+
export type { AvatarProps } from '../Avatar/v1/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
export { Avatar } from '../Avatar/v2'
|
|
25
|
+
export type { AvatarProps } from '../Avatar/v2/props'
|