Skip to content

Commit a3d63cb

Browse files
author
Kræn Hansen
authored
LG-4724: Export prop types which are already wrapped in the polymorphic types (re-created) (#2613)
* Export prop types already wrapped in polymorphic types * Adding a changeset * Add explicit type-parameter to event-handlers
1 parent 274d7e1 commit a3d63cb

File tree

15 files changed

+82
-24
lines changed

15 files changed

+82
-24
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@leafygreen-ui/input-option': patch
3+
'@leafygreen-ui/search-input': patch
4+
'@leafygreen-ui/split-button': patch
5+
'@leafygreen-ui/card': patch
6+
'@leafygreen-ui/menu': patch
7+
---
8+
9+
Export prop types for components already wrapped in polymorphic types

packages/card/src/Card/Card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
} from '@leafygreen-ui/polymorphic';
1010

1111
import { colorSet, containerStyle } from './styles';
12-
import { CardProps, ContentStyle } from './types';
12+
import { ContentStyle, InternalCardProps } from './types';
1313

1414
/**
1515
* Cards are used to organize information into consumable chunks.
1616
*/
17-
export const Card = InferredPolymorphic<CardProps, 'div'>(
17+
export const Card = InferredPolymorphic<InternalCardProps, 'div'>(
1818
(
1919
{
2020
as = 'div' as PolymorphicAs,

packages/card/src/Card/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { DarkModeProps } from '@leafygreen-ui/lib';
2+
import {
3+
InferredPolymorphicProps,
4+
PolymorphicAs,
5+
} from '@leafygreen-ui/polymorphic';
26

37
export const ContentStyle = {
48
None: 'none',
@@ -7,7 +11,7 @@ export const ContentStyle = {
711

812
export type ContentStyle = (typeof ContentStyle)[keyof typeof ContentStyle];
913

10-
export interface CardProps extends DarkModeProps {
14+
export interface InternalCardProps extends DarkModeProps {
1115
/**
1216
* Determines whether the Card should be styled as clickable.
1317
*
@@ -23,3 +27,7 @@ export interface CardProps extends DarkModeProps {
2327
*/
2428
title?: string;
2529
}
30+
31+
// External only
32+
export type CardProps<TAsProp extends PolymorphicAs = 'div'> =
33+
InferredPolymorphicProps<TAsProp, InternalCardProps>;

packages/input-option/src/InputOption/InputOption.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
getInputOptionWedge,
1616
inputOptionClassName,
1717
} from './InputOption.style';
18-
import { InputOptionProps } from './InputOption.types';
18+
import { InternalInputOptionProps } from './InputOption.types';
1919

20-
export const InputOption = Polymorphic<InputOptionProps>(
20+
export const InputOption = Polymorphic<InternalInputOptionProps>(
2121
(
2222
{
2323
as = 'li' as PolymorphicAs,

packages/input-option/src/InputOption/InputOption.types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AriaLabelPropsWithChildren } from '@leafygreen-ui/a11y';
22
import { DarkModeProps } from '@leafygreen-ui/lib';
3+
import { PolymorphicAs, PolymorphicProps } from '@leafygreen-ui/polymorphic';
34

45
/**
56
* TERMINOLOGY
@@ -55,6 +56,10 @@ export interface BaseInputOptionProps {
5556
isInteractive?: boolean;
5657
}
5758

58-
export type InputOptionProps = DarkModeProps &
59+
export type InternalInputOptionProps = DarkModeProps &
5960
AriaLabelPropsWithChildren &
6061
BaseInputOptionProps;
62+
63+
// External only
64+
export type InputOptionProps<TAsProp extends PolymorphicAs = 'li'> =
65+
PolymorphicProps<TAsProp, InternalInputOptionProps>;

packages/menu/src/MenuItem/InternalMenuItemContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import {
2020
getMenuItemStyles,
2121
getNestedMenuItemStyles,
2222
} from './MenuItem.styles';
23-
import { MenuItemProps, Variant } from './MenuItem.types';
23+
import { InternalMenuItemProps, Variant } from './MenuItem.types';
2424

2525
export type InternalMenuItemContentProps = InferredPolymorphicProps<
2626
PolymorphicAs,
27-
MenuItemProps
27+
InternalMenuItemProps
2828
> & {
2929
index: number;
3030
};

packages/menu/src/MenuItem/MenuItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { MenuDescendantsContext } from '../MenuContext';
99

1010
import { InternalMenuItemContent } from './InternalMenuItemContent';
1111
import { menuItemClassName, menuItemContainerStyles } from './MenuItem.styles';
12-
import { MenuItemProps } from './MenuItem.types';
12+
import { InternalMenuItemProps } from './MenuItem.types';
1313

14-
export const MenuItem = InferredPolymorphic<MenuItemProps, 'button'>(
14+
export const MenuItem = InferredPolymorphic<InternalMenuItemProps, 'button'>(
1515
(
1616
{ as, disabled = false, active = false, onClick, ...rest },
1717
fwdRef: React.Ref<any>,

packages/menu/src/MenuItem/MenuItem.types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ReactElement, ReactNode } from 'react';
22

3+
import {
4+
InferredPolymorphicProps,
5+
PolymorphicAs,
6+
} from '@leafygreen-ui/polymorphic';
7+
38
const Variant = {
49
Default: 'default',
510
Destructive: 'destructive',
@@ -9,7 +14,7 @@ type Variant = (typeof Variant)[keyof typeof Variant];
914

1015
export { Variant };
1116

12-
export interface MenuItemProps {
17+
export interface InternalMenuItemProps {
1318
/**
1419
* Determines whether or not the MenuItem is disabled.
1520
*/
@@ -54,3 +59,7 @@ export interface MenuItemProps {
5459
// TODO: codemod to remove `size` props from existing implementations
5560
size?: 'default' | 'large';
5661
}
62+
63+
// External only
64+
export type MenuItemProps<TAsProp extends PolymorphicAs = 'button'> =
65+
InferredPolymorphicProps<TAsProp, InternalMenuItemProps>;

packages/menu/src/SubMenu/SubMenu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export const SubMenu = InferredPolymorphic<InternalSubMenuProps, 'button'>(
9797
const submenuTriggerRef = useRef<HTMLButtonElement>(null);
9898
const subMenuHeight = useChildrenHeight(submenuRef, [open]);
9999

100-
const handleClick: MouseEventHandler = e => {
100+
const handleClick: MouseEventHandler<
101+
HTMLAnchorElement & HTMLButtonElement
102+
> = e => {
101103
if (onClick || rest.href) {
102104
if (!disabled) {
103105
onClick?.(e);

packages/menu/src/SubMenu/SubMenu.types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,5 @@ export interface InternalSubMenuProps
5151
}
5252

5353
// External only
54-
export type SubMenuProps = InferredPolymorphicProps<
55-
PolymorphicAs,
56-
InternalSubMenuProps
57-
>;
54+
export type SubMenuProps<TAsProp extends PolymorphicAs = 'button'> =
55+
InferredPolymorphicProps<TAsProp, InternalSubMenuProps>;

0 commit comments

Comments
 (0)