Skip to content

Commit 8d680ce

Browse files
committed
ref(ui): Adjust spacing on idBadge based on avatarSize
1 parent 8a4122a commit 8d680ce

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {css} from '@emotion/react';
22
import styled from '@emotion/styled';
33

4-
import {space} from 'sentry/styles/space';
5-
64
const BadgeDisplayName = styled('span')<{hideOverflow?: string | boolean}>`
75
${p =>
86
p.hideOverflow &&
@@ -12,7 +10,6 @@ const BadgeDisplayName = styled('span')<{hideOverflow?: string | boolean}>`
1210
? p.hideOverflow
1311
: p.theme.settings.maxCrumbWidth};
1412
`};
15-
padding: ${space(0.25)} 0;
1613
`;
1714

1815
export default BadgeDisplayName;

static/app/components/idBadge/baseBadge.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {memo} from 'react';
22
import styled from '@emotion/styled';
33

44
import Avatar from 'sentry/components/avatar';
5-
import {space} from 'sentry/styles/space';
5+
import {space, ValidSize} from 'sentry/styles/space';
66
import type {Actor, AvatarProject, AvatarUser, Organization, Team} from 'sentry/types';
77

88
export interface BaseBadgeProps {
@@ -38,35 +38,40 @@ export const BaseBadge = memo(
3838
project,
3939
actor,
4040
className,
41-
}: AllBaseBadgeProps) => (
42-
<Wrapper className={className}>
43-
{!hideAvatar && (
44-
<Avatar
45-
{...avatarProps}
46-
size={avatarSize}
47-
team={team}
48-
user={user}
49-
organization={organization}
50-
project={project}
51-
actor={actor}
52-
/>
53-
)}
41+
}: AllBaseBadgeProps) => {
42+
// Space items appropriatley depending on avatar size
43+
const wrapperGap: ValidSize = avatarSize <= 14 ? 0.5 : avatarSize <= 20 ? 0.75 : 1;
5444

55-
{(!hideName || !!description) && (
56-
<DisplayNameAndDescription>
57-
{!hideName && (
58-
<DisplayName data-test-id="badge-display-name">{displayName}</DisplayName>
59-
)}
60-
{!!description && <Description>{description}</Description>}
61-
</DisplayNameAndDescription>
62-
)}
63-
</Wrapper>
64-
)
45+
return (
46+
<Wrapper className={className} gap={wrapperGap}>
47+
{!hideAvatar && (
48+
<Avatar
49+
{...avatarProps}
50+
size={avatarSize}
51+
team={team}
52+
user={user}
53+
organization={organization}
54+
project={project}
55+
actor={actor}
56+
/>
57+
)}
58+
59+
{(!hideName || !!description) && (
60+
<DisplayNameAndDescription>
61+
{!hideName && (
62+
<DisplayName data-test-id="badge-display-name">{displayName}</DisplayName>
63+
)}
64+
{!!description && <Description>{description}</Description>}
65+
</DisplayNameAndDescription>
66+
)}
67+
</Wrapper>
68+
);
69+
}
6570
);
6671

67-
const Wrapper = styled('div')`
72+
const Wrapper = styled('div')<{gap: ValidSize}>`
6873
display: flex;
69-
gap: ${space(1)};
74+
gap: ${p => space(p.gap)};
7075
align-items: center;
7176
flex-shrink: 0;
7277
`;

static/app/components/idBadge/index.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@ import useProjects from 'sentry/utils/useProjects';
66
import {useTeams} from 'sentry/utils/useTeams';
77
import {useUser} from 'sentry/utils/useUser';
88

9+
import Matrix, {PropMatrix} from '../stories/matrix';
910
import SideBySide from '../stories/sideBySide';
1011

12+
import {OrganizationBadgeProps} from './organizationBadge';
1113
import IdBadge from '.';
1214

1315
export default storyBook(IdBadge, story => {
16+
story('Props', () => {
17+
const org = useOrganization();
18+
19+
const propMatrix: PropMatrix<OrganizationBadgeProps> = {
20+
avatarSize: [12, 16, 24],
21+
};
22+
23+
return (
24+
<Matrix<OrganizationBadgeProps>
25+
render={props => <IdBadge {...props} organization={org} />}
26+
propMatrix={propMatrix}
27+
selectedProps={['avatarSize']}
28+
/>
29+
);
30+
});
31+
1432
story('Organization', () => {
1533
const org = useOrganization();
1634
return <IdBadge organization={org} />;

0 commit comments

Comments
 (0)