Skip to content

Commit f75e398

Browse files
committed
Clean up components, using flex gap
1 parent 8d48d60 commit f75e398

File tree

4 files changed

+15
-57
lines changed

4 files changed

+15
-57
lines changed

packages/compass-components/src/components/actions/item-action-button.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import React from 'react';
2-
import { css, cx } from '@leafygreen-ui/emotion';
3-
import { spacing } from '@leafygreen-ui/tokens';
2+
import { cx } from '@leafygreen-ui/emotion';
43

54
import { ItemActionButtonSize } from './constants';
65
import type { ItemComponentProps } from './types';
76
import { SmallIconButton } from './small-icon-button';
87

9-
// TODO: Move to a parent component - or a flex gap
10-
const buttonStyle = css({
11-
'&:not(:first-child)': {
12-
marginLeft: spacing[100],
13-
},
14-
});
15-
168
export function ItemActionButton<Action extends string>({
179
action,
1810
icon = <></>,
@@ -36,7 +28,7 @@ export function ItemActionButton<Action extends string>({
3628
data-action={action}
3729
data-testid={dataTestId}
3830
onClick={onClick}
39-
className={cx(buttonStyle, iconClassName, className)}
31+
className={cx(iconClassName, className)}
4032
style={iconStyle}
4133
disabled={isDisabled}
4234
/>

packages/compass-components/src/components/actions/item-action-controls.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ const actionControlsStyle = css({
1212
marginLeft: 'auto',
1313
alignItems: 'center',
1414
display: 'flex',
15-
});
16-
17-
// Action buttons are rendered 4px apart from each other. With this we keep the
18-
// same spacing also when action buttons are rendered alongside action menu
19-
// (happens when collapseAfter prop is specified)
20-
const actionMenuWithActionControlsStyles = css({
21-
marginLeft: spacing[100],
15+
gap: spacing[100],
2216
});
2317

2418
export type ItemActionControlsProps<Action extends string> = {
@@ -79,6 +73,7 @@ export function ItemActionControls<Action extends string>({
7973
}),
8074
[menuClassName, usePortal]
8175
);
76+
8277
if (actions.length === 0) {
8378
return null;
8479
}
@@ -89,19 +84,12 @@ export function ItemActionControls<Action extends string>({
8984
const collapsedActions = actions.slice(collapseAfter);
9085
return (
9186
<div className={actionControlsStyle}>
92-
<ItemActionGroup
93-
actions={visibleActions}
94-
{...sharedProps}
95-
></ItemActionGroup>
87+
<ItemActionGroup {...sharedProps} actions={visibleActions} />
9688
<ItemActionMenu
97-
actions={collapsedActions}
9889
{...sharedProps}
9990
{...sharedMenuProps}
100-
className={cx(
101-
actionMenuWithActionControlsStyles,
102-
sharedProps.className
103-
)}
104-
></ItemActionMenu>
91+
actions={collapsedActions}
92+
/>
10593
</div>
10694
);
10795
}
@@ -110,13 +98,9 @@ export function ItemActionControls<Action extends string>({
11098

11199
if (shouldShowMenu) {
112100
return (
113-
<ItemActionMenu
114-
actions={actions}
115-
{...sharedProps}
116-
{...sharedMenuProps}
117-
></ItemActionMenu>
101+
<ItemActionMenu actions={actions} {...sharedProps} {...sharedMenuProps} />
118102
);
119103
}
120104

121-
return <ItemActionGroup actions={actions} {...sharedProps}></ItemActionGroup>;
105+
return <ItemActionGroup actions={actions} {...sharedProps} />;
122106
}

packages/compass-components/src/components/actions/item-action-group.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ const containerStyle = css({
1919
marginLeft: 'auto',
2020
alignItems: 'center',
2121
display: 'flex',
22-
});
23-
24-
// TODO: Move to a parent component - or a flex gap
25-
const actionGroupButtonStyle = css({
26-
'&:not(:first-child)': {
27-
marginLeft: spacing[100],
28-
},
22+
gap: spacing[100],
2923
});
3024

3125
export type ItemActionGroupProps<Action extends string> = {
@@ -80,6 +74,7 @@ export function ItemActionGroup<Action extends string>({
8074
const item = (
8175
<ItemComponent
8276
{...itemProps}
77+
key={itemProps.action}
8378
iconSize={iconSize}
8479
iconStyle={iconStyle}
8580
iconClassName={iconClassName}
@@ -93,14 +88,9 @@ export function ItemActionGroup<Action extends string>({
9388
<Tooltip
9489
key={itemProps.action}
9590
{...tooltipProps}
96-
trigger={
97-
<div
98-
className={actionGroupButtonStyle}
99-
style={{ display: 'inherit' }}
100-
>
101-
{item}
102-
</div>
103-
}
91+
// Wrapping the item in a div, because the `trigger` must accept and render `children`
92+
// See docs for the prop for more information
93+
trigger={<div style={{ display: 'inherit' }}>{item}</div>}
10494
>
10595
{tooltip}
10696
</Tooltip>

packages/compass-components/src/components/actions/item-action-menu.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useCallback, useRef, useState } from 'react';
22
import { css, cx } from '@leafygreen-ui/emotion';
3-
import { spacing } from '@leafygreen-ui/tokens';
43

54
import { Menu, MenuItem, MenuSeparator } from '../leafygreen';
65

@@ -30,13 +29,6 @@ const containerStyle = css({
3029
display: 'flex',
3130
});
3231

33-
// TODO: Move to a parent component - or a flex gap
34-
const buttonStyle = css({
35-
'&:not(:first-child)': {
36-
marginLeft: spacing[100],
37-
},
38-
});
39-
4032
export type ItemActionMenuProps<Action extends string> = {
4133
actions: MenuAction<Action>[];
4234
onAction(actionName: Action): void;
@@ -119,7 +111,7 @@ export function ItemActionMenu<Action extends string>({
119111
evt.stopPropagation();
120112
onClick && onClick(evt);
121113
}}
122-
className={cx(buttonStyle, iconClassName)}
114+
className={iconClassName}
123115
style={iconStyle}
124116
>
125117
{children}

0 commit comments

Comments
 (0)