@bitrise/bitkit 13.96.0 → 13.98.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "13.96.0",
4
+ "version": "13.98.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -1,6 +1,6 @@
1
1
  import type { ComponentStyleConfig } from '@chakra-ui/theme';
2
2
  import { rem } from '../../utils/utils';
3
- import { AvatarSizes, AvatarVariant } from './Avatar';
3
+ import { AvatarProps, AvatarSizes, AvatarVariant } from './Avatar';
4
4
 
5
5
  const COLORS = [
6
6
  {
@@ -41,7 +41,7 @@ const getStyleForUserVariant = (size: AvatarSizes) => {
41
41
  const borderRadius = {
42
42
  24: '12',
43
43
  32: '16',
44
- 40: '24',
44
+ 40: '20',
45
45
  48: '24',
46
46
  64: '12',
47
47
  128: '24',
@@ -54,7 +54,7 @@ const getStyleForUserVariant = (size: AvatarSizes) => {
54
54
 
55
55
  const getStyleForWorkspaceVariant = (size: AvatarSizes) => {
56
56
  const borderRadius = {
57
- 24: '24',
57
+ 24: '4',
58
58
  32: '8',
59
59
  40: '8',
60
60
  48: '12',
@@ -120,7 +120,7 @@ const getStyleForBrandVariant = (size: AvatarSizes) => {
120
120
 
121
121
  const getStyleForLettersVariant = (size: AvatarSizes) => {
122
122
  const borderRadius = {
123
- 24: '12',
123
+ 24: '4',
124
124
  32: '8',
125
125
  40: '8',
126
126
  48: '12',
@@ -166,17 +166,17 @@ const getStyleForStepVariant = (size: AvatarSizes) => {
166
166
 
167
167
  const getSizeBasedTextStyle = (size: AvatarSizes) => {
168
168
  const textStyles = {
169
- 24: 'heading/h5',
170
- 32: 'heading/h3',
171
- 40: 'heading/h2',
172
- 48: 'heading/h1',
173
- 64: 'display/sm',
174
- 128: 'display/lg',
169
+ 24: 'sans/size-1/bold',
170
+ 32: 'sans/size-3/bold',
171
+ 40: 'sans/size-4/bold',
172
+ 48: 'sans/size-5/semibold',
173
+ 64: 'sans/size-6/semibold',
174
+ 128: 'sans/size-8/semibold',
175
175
  };
176
176
 
177
177
  return {
178
178
  textStyle: textStyles[size],
179
- fontWeight: 'bold',
179
+ fontWeight: Number(size) > 40 ? 'semibold' : 'bold',
180
180
  };
181
181
  };
182
182
 
@@ -209,23 +209,26 @@ const getStyleBySizeAndType = (size: AvatarSizes, variant: AvatarVariant) => {
209
209
  }
210
210
  };
211
211
 
212
- const AvatarTheme: ComponentStyleConfig = {
213
- baseStyle: ({ name, variant, size }) => {
214
- let colors = {};
215
- if (name) {
216
- const str = name.toUpperCase();
217
- const seed = str.charCodeAt(0) + str.charCodeAt(str.length - 1);
218
- colors = COLORS[seed % COLORS.length];
219
- } else if (variant === 'brand') {
220
- colors = { backgroundColor: 'sys/neutral/subtle', color: 'text/secondary' };
221
- }
212
+ const getColors = ({ name, variant }: AvatarProps) => {
213
+ if (name) {
214
+ const str = name.toUpperCase();
215
+ const seed = str.charCodeAt(0) + str.charCodeAt(str.length - 1);
216
+ return COLORS[seed % COLORS.length];
217
+ }
218
+ if (variant === 'brand') {
219
+ return { backgroundColor: 'sys/neutral/subtle', color: 'text/secondary' };
220
+ }
221
+ };
222
222
 
223
+ const AvatarTheme: ComponentStyleConfig = {
224
+ baseStyle: ({ name, size, variant }) => {
223
225
  return {
224
226
  container: {
225
- ...colors,
227
+ ...getColors({ name, variant }),
226
228
  overflow: 'hidden',
227
229
  height: rem(size),
228
230
  width: rem(size),
231
+ textTransform: 'capitalize',
229
232
  ...getSizeBasedTextStyle(size),
230
233
  ...getStyleBySizeAndType(size, variant),
231
234
  },
@@ -1,3 +1,4 @@
1
+ import { useState } from 'react';
1
2
  import { Avatar as ChakraAvatar, AvatarProps as ChakraAvatarProps, forwardRef } from '@chakra-ui/react';
2
3
  import Icon, { TypeIconName } from '../Icon/Icon';
3
4
 
@@ -33,12 +34,29 @@ const getInitials = (name: string) => {
33
34
  const Avatar = forwardRef<AvatarProps, 'span'>((props, ref) => {
34
35
  const { iconName, variant = 'user', size = '32', ...rest } = props;
35
36
 
37
+ const [hasError, setError] = useState<boolean | undefined>(undefined);
38
+
36
39
  let icon;
37
40
  if (iconName) {
38
41
  icon = <Icon color="sys/neutral/strong" name={iconName} />;
39
42
  }
40
43
 
41
- return <ChakraAvatar getInitials={getInitials} icon={icon} size={size} variant={variant} {...rest} ref={ref} />;
44
+ const onError = () => {
45
+ setError(true);
46
+ };
47
+
48
+ return (
49
+ <ChakraAvatar
50
+ getInitials={getInitials}
51
+ icon={icon}
52
+ onError={onError}
53
+ size={size}
54
+ variant={variant}
55
+ background={hasError === false ? 'transparent' : undefined}
56
+ {...rest}
57
+ ref={ref}
58
+ />
59
+ );
42
60
  });
43
61
 
44
62
  export default Avatar;