Skip to content

Commit 52bb155

Browse files
committed
Refactor actions, separating out types and utils
1 parent 71b529c commit 52bb155

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

packages/compass-components/src/components/actions/dropdown-menu-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { Button, Icon, Menu, MenuItem, MenuSeparator } from '../leafygreen';
77
import { WorkspaceContainer } from '../workspace-container';
88

99
import { ItemActionButtonSize } from './constants';
10-
import { actionTestId } from './utils';
1110
import { ActionGlyph } from './action-glyph';
12-
import { isSeparatorMenuAction, type MenuAction } from './item-action-menu';
11+
import { actionTestId, isSeparatorMenuAction } from './utils';
12+
import type { MenuAction } from './types';
1313

1414
const hiddenOnNarrowStyles = css({
1515
[`@container ${WorkspaceContainer.toolbarContainerQueryName} (width < 900px)`]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { MenuSeparator, Tooltip } from '../leafygreen';
66

77
import { ItemActionButtonSize } from './constants';
88
import type { ItemAction, ItemSeparator } from './types';
9-
import { isSeparatorMenuAction } from './item-action-menu';
109
import { ItemActionButton } from './item-action-button';
11-
import { actionTestId } from './utils';
10+
import { actionTestId, isSeparatorMenuAction } from './utils';
1211

1312
export type GroupedItemAction<Action extends string> = ItemAction<Action> & {
1413
tooltipProps?: Parameters<typeof Tooltip>;

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,9 @@ import { Menu, MenuItem, MenuSeparator } from '../leafygreen';
66

77
import { ItemActionButtonSize } from './constants';
88
import { ActionGlyph } from './action-glyph';
9-
import type { ItemBase, ItemSeparator } from './types';
9+
import type { MenuAction } from './types';
1010
import { SmallIconButton } from './small-icon-button';
11-
import { actionTestId } from './utils';
12-
13-
export type MenuAction<Action extends string> =
14-
| ItemBase<Action>
15-
| ItemSeparator;
16-
17-
export function isSeparatorMenuAction(value: unknown): value is ItemSeparator {
18-
return (
19-
typeof value === 'object' &&
20-
value !== null &&
21-
'separator' in value &&
22-
value.separator === true
23-
);
24-
}
11+
import { actionTestId, isSeparatorMenuAction } from './utils';
2512

2613
const containerStyle = css({
2714
flex: 'none',

packages/compass-components/src/components/actions/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ export type ItemAction<Action extends string> = {
3636
} & ItemBase<Action>;
3737

3838
export type ItemSeparator = { separator: true };
39+
40+
export type MenuAction<Action extends string> =
41+
| ItemBase<Action>
42+
| ItemSeparator;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import type { ItemSeparator, ItemAction, MenuAction } from './types';
2+
3+
export function isSeparatorMenuAction(value: unknown): value is ItemSeparator {
4+
return (
5+
typeof value === 'object' &&
6+
value !== null &&
7+
'separator' in value &&
8+
value.separator === true
9+
);
10+
}
11+
112
export function actionTestId(dataTestId: string | undefined, action: string) {
213
return dataTestId ? `${dataTestId}-${action}-action` : undefined;
314
}

packages/compass-components/src/index.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ import ResizableSidebar, {
5151
defaultSidebarWidth,
5252
} from './components/resizeable-sidebar';
5353

54-
import type {
54+
export type {
5555
ItemAction,
5656
ItemComponentProps,
5757
ItemSeparator,
58+
MenuAction,
5859
} from './components/actions/types';
59-
import type { GroupedItemAction } from './components/actions/item-action-group';
60-
import type { MenuAction } from './components/actions/item-action-menu';
60+
export type { GroupedItemAction } from './components/actions/item-action-group';
6161

62-
import { ItemActionControls } from './components/actions/item-action-controls';
63-
import { ItemActionGroup } from './components/actions/item-action-group';
64-
import { ItemActionMenu } from './components/actions/item-action-menu';
65-
import { DropdownMenuButton } from './components/actions/dropdown-menu-button';
62+
export { ItemActionControls } from './components/actions/item-action-controls';
63+
export { ItemActionGroup } from './components/actions/item-action-group';
64+
export { ItemActionMenu } from './components/actions/item-action-menu';
65+
export { DropdownMenuButton } from './components/actions/dropdown-menu-button';
6666

6767
export { DocumentIcon } from './components/icons/document-icon';
6868
export { FavoriteIcon } from './components/icons/favorite-icon';
@@ -108,11 +108,6 @@ export {
108108

109109
export type {
110110
FileInputBackend,
111-
ItemAction,
112-
ItemComponentProps,
113-
GroupedItemAction,
114-
MenuAction,
115-
ItemSeparator,
116111
ElectronFileDialogOptions,
117112
ElectronShowFileDialogProvider,
118113
};
@@ -131,10 +126,6 @@ export {
131126
ResizableSidebar,
132127
WarningSummary,
133128
WorkspaceTabs,
134-
ItemActionControls,
135-
ItemActionGroup,
136-
ItemActionMenu,
137-
DropdownMenuButton,
138129
defaultSidebarWidth,
139130
createElectronFileInputBackend,
140131
createJSDomFileInputDummyBackend,

0 commit comments

Comments
 (0)