Skip to content

Commit 0ca9e24

Browse files
authored
refactor: reduce popover type duplication (#19656)
* refactor: reduce popover type duplication * refactor(OverflowMenu): update v12 component types
1 parent 0a27b45 commit 0ca9e24

File tree

6 files changed

+52
-140
lines changed

6 files changed

+52
-140
lines changed

packages/react/src/components/AILabel/index.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
2222
import { Undo } from '@carbon/icons-react';
2323
import { useId } from '../../internal/useId';
2424
import { deprecate } from '../../prop-types/deprecate';
25+
import type {
26+
DeprecatedPopoverAlignment,
27+
NewPopoverAlignment,
28+
PopoverAlignment,
29+
} from '../Popover';
2530

2631
export type AILabelContentProps = React.HTMLAttributes<HTMLSpanElement>;
2732

@@ -102,31 +107,11 @@ AILabelActions.propTypes = {
102107
* Deprecated popover alignment values.
103108
* @deprecated Use NewPopoverAlignment instead.
104109
*/
105-
export type DeprecatedAlignment =
106-
| 'top-left'
107-
| 'top-right'
108-
| 'bottom-left'
109-
| 'bottom-right'
110-
| 'left-bottom'
111-
| 'left-top'
112-
| 'right-bottom'
113-
| 'right-top';
114-
115-
export type NewAlignment =
116-
| 'top'
117-
| 'bottom'
118-
| 'left'
119-
| 'right'
120-
| 'top-start'
121-
| 'top-end'
122-
| 'bottom-start'
123-
| 'bottom-end'
124-
| 'left-end'
125-
| 'left-start'
126-
| 'right-end'
127-
| 'right-start';
128-
129-
export type Alignment = DeprecatedAlignment | NewAlignment;
110+
export type DeprecatedAlignment = DeprecatedPopoverAlignment;
111+
112+
export type NewAlignment = NewPopoverAlignment;
113+
114+
export type Alignment = PopoverAlignment;
130115

131116
export interface AILabelProps {
132117
AILabelContent?: React.ReactNode;

packages/react/src/components/CodeSnippet/CodeSnippet.tsx

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import copy from 'copy-to-clipboard';
2424
import { deprecate } from '../../prop-types/deprecate';
2525
import { usePrefix } from '../../internal/usePrefix';
2626
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';
27+
import type {
28+
DeprecatedPopoverAlignment,
29+
NewPopoverAlignment,
30+
PopoverAlignment,
31+
} from '../Popover';
2732
import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
2833

2934
const rowHeightInPixels = 16;
@@ -32,33 +37,11 @@ const defaultMaxExpandedNumberOfRows = 0;
3237
const defaultMinCollapsedNumberOfRows = 3;
3338
const defaultMinExpandedNumberOfRows = 16;
3439

35-
export type DeprecatedCodeSnippetAlignment =
36-
| 'top-left'
37-
| 'top-right'
38-
| 'bottom-left'
39-
| 'bottom-right'
40-
| 'left-bottom'
41-
| 'left-top'
42-
| 'right-bottom'
43-
| 'right-top';
44-
45-
export type NewCodeSnippetAlignment =
46-
| 'top'
47-
| 'bottom'
48-
| 'left'
49-
| 'right'
50-
| 'top-start'
51-
| 'top-end'
52-
| 'bottom-start'
53-
| 'bottom-end'
54-
| 'left-end'
55-
| 'left-start'
56-
| 'right-end'
57-
| 'right-start';
58-
59-
export type CodeSnippetAlignment =
60-
| DeprecatedCodeSnippetAlignment
61-
| NewCodeSnippetAlignment;
40+
export type DeprecatedCodeSnippetAlignment = DeprecatedPopoverAlignment;
41+
42+
export type NewCodeSnippetAlignment = NewPopoverAlignment;
43+
44+
export type CodeSnippetAlignment = PopoverAlignment;
6245

6346
export interface CodeSnippetProps {
6447
/**

packages/react/src/components/Copy/Copy.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,17 @@ import { IconButton } from '../IconButton';
2222
import { noopFn } from '../../internal/noopFn';
2323
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';
2424
import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
25+
import type {
26+
DeprecatedPopoverAlignment,
27+
NewPopoverAlignment,
28+
PopoverAlignment,
29+
} from '../Popover';
2530

26-
export type DeprecatedCopyAlignment =
27-
| 'top-left'
28-
| 'top-right'
29-
| 'bottom-left'
30-
| 'bottom-right'
31-
| 'left-bottom'
32-
| 'left-top'
33-
| 'right-bottom'
34-
| 'right-top';
35-
36-
export type NewCopyAlignment =
37-
| 'top'
38-
| 'bottom'
39-
| 'left'
40-
| 'right'
41-
| 'top-start'
42-
| 'top-end'
43-
| 'bottom-start'
44-
| 'bottom-end'
45-
| 'left-end'
46-
| 'left-start'
47-
| 'right-end'
48-
| 'right-start';
49-
50-
export type CopyAlignment = DeprecatedCopyAlignment | NewCopyAlignment;
31+
export type DeprecatedCopyAlignment = DeprecatedPopoverAlignment;
32+
33+
export type NewCopyAlignment = NewPopoverAlignment;
34+
35+
export type CopyAlignment = PopoverAlignment;
5136

5237
export interface CopyProps
5338
extends React.ButtonHTMLAttributes<HTMLButtonElement> {

packages/react/src/components/CopyButton/CopyButton.tsx

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,17 @@ import { usePrefix } from '../../internal/usePrefix';
1616
import { noopFn } from '../../internal/noopFn';
1717
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';
1818
import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
19+
import type {
20+
DeprecatedPopoverAlignment,
21+
NewPopoverAlignment,
22+
PopoverAlignment,
23+
} from '../Popover';
1924

20-
export type DeprecatedCopyButtonAlignment =
21-
| 'top-left'
22-
| 'top-right'
23-
| 'bottom-left'
24-
| 'bottom-right'
25-
| 'left-bottom'
26-
| 'left-top'
27-
| 'right-bottom'
28-
| 'right-top';
29-
30-
export type NewCopyButtonAlignment =
31-
| 'top'
32-
| 'bottom'
33-
| 'left'
34-
| 'right'
35-
| 'top-start'
36-
| 'top-end'
37-
| 'bottom-start'
38-
| 'bottom-end'
39-
| 'left-end'
40-
| 'left-start'
41-
| 'right-end'
42-
| 'right-start';
43-
44-
export type CopyButtonAlignment =
45-
| DeprecatedCopyButtonAlignment
46-
| NewCopyButtonAlignment;
25+
export type DeprecatedCopyButtonAlignment = DeprecatedPopoverAlignment;
26+
27+
export type NewCopyButtonAlignment = NewPopoverAlignment;
28+
29+
export type CopyButtonAlignment = PopoverAlignment;
4730

4831
export interface CopyButtonProps extends ButtonProps<'button'> {
4932
/**

packages/react/src/components/IconButton/index.tsx

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { usePrefix } from '../../internal/usePrefix';
1515
import ButtonBase from '../Button/ButtonBase';
1616
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';
1717
import BadgeIndicator from '../BadgeIndicator';
18+
import type {
19+
DeprecatedPopoverAlignment,
20+
NewPopoverAlignment,
21+
PopoverAlignment,
22+
} from '../Popover';
1823
import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
1924

2025
export const IconButtonKinds = [
@@ -26,33 +31,11 @@ export const IconButtonKinds = [
2631

2732
export type IconButtonKind = (typeof IconButtonKinds)[number];
2833

29-
export type DeprecatedIconButtonAlignment =
30-
| 'top-left'
31-
| 'top-right'
32-
| 'bottom-left'
33-
| 'bottom-right'
34-
| 'left-bottom'
35-
| 'left-top'
36-
| 'right-bottom'
37-
| 'right-top';
38-
39-
export type NewIconButtonAlignment =
40-
| 'top'
41-
| 'bottom'
42-
| 'left'
43-
| 'right'
44-
| 'top-start'
45-
| 'top-end'
46-
| 'bottom-start'
47-
| 'bottom-end'
48-
| 'left-end'
49-
| 'left-start'
50-
| 'right-end'
51-
| 'right-start';
52-
53-
export type IconButtonAlignment =
54-
| DeprecatedIconButtonAlignment
55-
| NewIconButtonAlignment;
34+
export type DeprecatedIconButtonAlignment = DeprecatedPopoverAlignment;
35+
36+
export type NewIconButtonAlignment = NewPopoverAlignment;
37+
38+
export type IconButtonAlignment = PopoverAlignment;
5639

5740
export interface IconButtonProps
5841
extends React.ButtonHTMLAttributes<HTMLButtonElement> {

packages/react/src/components/OverflowMenu/next/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useFeatureFlag } from '../../FeatureFlags';
1414

1515
import { IconButton } from '../../IconButton';
1616
import { Menu } from '../../Menu';
17+
import type { PopoverAlignment } from '../../Popover';
1718
import mergeRefs from '../../../tools/mergeRefs';
1819

1920
import { useId } from '../../../internal/useId';
@@ -63,15 +64,7 @@ interface OverflowMenuProps {
6364
/**
6465
* Specify how the trigger tooltip should be aligned.
6566
*/
66-
tooltipAlignment?:
67-
| 'top'
68-
| 'top-left'
69-
| 'top-right'
70-
| 'bottom'
71-
| 'bottom-left'
72-
| 'bottom-right'
73-
| 'left'
74-
| 'right';
67+
tooltipAlignment?: PopoverAlignment;
7568

7669
/**
7770
* Specify a DOM node where the Menu should be rendered in. Defaults to document.body.

0 commit comments

Comments
 (0)