Skip to content

Commit 0bc99a3

Browse files
tiagoevanpggazzo
andauthored
feat: Remove Box from Avatar component (#326)
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
1 parent 713009b commit 0bc99a3

13 files changed

+190
-165
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

packages/fuselage/src/components/Avatar/Avatar.stories.mdx

+133-127
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
import PropTypes from 'prop-types';
2-
import React, { useContext, createContext } from 'react';
2+
import React from 'react';
33
import flattenChildren from 'react-keyed-flatten-children';
44

5-
import { createPropType } from '../../helpers/createPropType';
6-
import { size } from '../../styleTokens';
7-
import { Box } from '../Box';
8-
9-
const AvatarContext = createContext({
10-
baseUrl: '',
11-
});
5+
import { prependClassName } from '../../helpers/prependClassName';
126

137
export function Avatar({
148
title,
9+
size = 'x36',
1510
rounded = false,
1611
url,
17-
size = 'x36',
1812
...props
1913
}) {
20-
const { baseUrl } = useContext(AvatarContext);
14+
props.className = prependClassName(
15+
props.className,
16+
['rcx-box rcx-box--full rcx-avatar', size && `rcx-avatar--${size}`]
17+
.filter(Boolean)
18+
.join(' ')
19+
);
20+
const innerClass = [
21+
'rcx-avatar__element',
22+
rounded && 'rcx-avatar__element--rounded',
23+
size && `rcx-avatar--${size}`,
24+
]
25+
.filter(Boolean)
26+
.join(' ');
2127

2228
return (
23-
<Box
24-
is='figure'
25-
rcx-avatar
26-
aria-label={title}
27-
{...props}
28-
width={size}
29-
height={size}
30-
verticalAlign='middle'
31-
>
32-
<Box
33-
is='img'
34-
{...props}
35-
rcx-avatar__element
36-
rcx-avatar__element--rounded={rounded}
37-
src={`${baseUrl}${url}`}
38-
width={size}
39-
height={size}
40-
/>
41-
</Box>
29+
<figure aria-label={title} {...props}>
30+
<img src={`${url}`} className={`${innerClass}`} />
31+
</figure>
4232
);
4333
}
4434

45-
Avatar.Context = AvatarContext;
46-
4735
Avatar.propTypes = {
4836
rounded: PropTypes.bool,
49-
size: createPropType(size),
37+
size: PropTypes.oneOf([
38+
'x16',
39+
'x18',
40+
'x20',
41+
'x24',
42+
'x28',
43+
'x32',
44+
'x36',
45+
'x48',
46+
'x124',
47+
'x200',
48+
'x332',
49+
]),
5050
title: PropTypes.string,
5151
url: PropTypes.string.isRequired,
5252
};
5353

54-
const AvatarStack = ({ children, ...props }) => (
55-
<Box rcx-avatar-stack {...props}>
54+
const AvatarStack = ({ children, className, ...props }) => (
55+
<div className={prependClassName('rcx-avatar-stack', className)} {...props}>
5656
{flattenChildren(children).reverse()}
57-
</Box>
57+
</div>
5858
);
5959

6060
Avatar.Stack = AvatarStack;

packages/fuselage/src/components/Avatar/styles.scss

+11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
@use '../../styles/colors.scss';
22
@use '../../styles/lengths.scss';
3+
@use '../../styles/functions.scss';
34

45
$avatar-stack-background-color: theme('avatar-background-color', colors.surface());
56

7+
$sizes: 16, 18, 20, 24, 28, 32, 36, 48, 124, 200, 332;
8+
69
.rcx-avatar {
710
display: inline-flex;
811

12+
vertical-align: middle;
13+
914
&__element {
1015
position: relative;
1116

@@ -33,4 +38,10 @@ $avatar-stack-background-color: theme('avatar-background-color', colors.surface(
3338
}
3439
}
3540
}
41+
42+
@each $size in $sizes {
43+
&--x#{$size} {
44+
@include square(functions.to-rem($size));
45+
}
46+
}
3647
}

packages/fuselage/src/components/Chip/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33

4+
import { Avatar, Box } from '..';
45
import { prependClassName } from '../../helpers/prependClassName';
5-
import { Avatar } from '../Avatar';
66
import { withBoxStyling } from '../Box/withBoxStyling';
77
import { Icon } from '../Icon';
88
import Margins from '../Margins';
99

10-
const defaultRenderThumb = ({ url }) => <Avatar size='x20' url={url} />;
10+
const defaultRenderThumb = ({ url }) => (
11+
<Box rcx-avatar>
12+
<Avatar size='x20' url={url} />
13+
</Box>
14+
);
1115
const defaultRenderDismissSymbol = () => <Icon name='cross' size='x16' />;
1216

1317
const Chip = ({

packages/fuselage/src/components/Modal/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export const ModalHeader = ({ children, ...props }) => (
4747
</Margins>
4848
);
4949

50-
export const ModalThumb = (props) => <Avatar size='x32' {...props} />;
50+
export const ModalThumb = (props) => (
51+
<Box>
52+
<Avatar size='x32' {...props} />
53+
</Box>
54+
);
5155

5256
export const ModalTitle = ({ children, ...props }) => (
5357
<Flex.Item grow={1} shrink={1}>

0 commit comments

Comments
 (0)