Skip to content

Commit 9ade3af

Browse files
added forwardRef to py-button
1 parent 9afbe4a commit 9ade3af

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

source/library/components/py-box/py-box.types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
PropsWithChildren,
66
WeakValidationMap,
77
} from "react";
8-
98
import type ReactElementProps from "~types/react-element-properties/react-element-properties";
109

1110
export type PyBoxPropertiesBase = PropsWithChildren<
@@ -16,13 +15,14 @@ export type PyBoxPropertiesBase = PropsWithChildren<
1615
}
1716
>;
1817

19-
export type PyBoxProperties<T> = T extends infer T
20-
? T & PyBoxPropertiesBase
21-
: PyBoxPropertiesBase;
18+
export type PyBoxProperties<OptionalProperties> =
19+
OptionalProperties extends infer OptionalProperties
20+
? OptionalProperties & PyBoxPropertiesBase
21+
: PyBoxPropertiesBase;
2222

2323
export type PyBoxTag = {
24-
<T extends object>(
25-
properties: PyBoxProperties<T>,
24+
<OptionalProperties extends object>(
25+
properties: PyBoxProperties<OptionalProperties>,
2626
reference: LegacyRef<HTMLElement> | undefined,
2727
): JSX.Element;
2828
displayName?: string;

source/library/components/py-button/py-button.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import propTypes from "prop-types";
2+
import { forwardRef, type ForwardedRef } from "react";
23
import type { PyButtonProperties, PyButtonTag } from "./py-button.types";
34

45
/**
@@ -7,17 +8,21 @@ import type { PyButtonProperties, PyButtonTag } from "./py-button.types";
78
* @param root0.label
89
* @deprecated
910
*/
10-
const PyButton: PyButtonTag = <T extends object>({
11-
children,
12-
label,
13-
...rest
14-
}: PyButtonProperties<T>): JSX.Element => {
15-
return (
16-
<py-button {...rest} label={label}>
17-
{children}
18-
</py-button>
19-
);
20-
};
11+
const PyButton: PyButtonTag = forwardRef(
12+
<T extends object>(
13+
{ children, label, ...rest }: PyButtonProperties<T>,
14+
reference: ForwardedRef<HTMLElement> | undefined,
15+
// eslint-disable-next-line max-params
16+
): JSX.Element => {
17+
return (
18+
<py-button ref={reference} {...rest} label={label}>
19+
{children}
20+
</py-button>
21+
);
22+
},
23+
) as PyButtonTag;
24+
25+
PyButton.displayName = "PyButton";
2126

2227
PyButton.propTypes = {
2328
children: propTypes.string.isRequired,
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type {
22
DetailedHTMLProps,
33
HTMLAttributes,
4+
LegacyRef,
45
WeakValidationMap,
56
} from "react";
6-
import ReactElementProps from "~types/react-element-properties/react-element-properties";
7+
import type ReactElementProps from "~types/react-element-properties/react-element-properties";
78

89
export type PyButtonPropertiesBase = Omit<
910
ReactElementProps<
@@ -15,11 +16,17 @@ export type PyButtonPropertiesBase = Omit<
1516
label: string;
1617
};
1718

18-
export type PyButtonProperties<T> = T extends infer T
19-
? T & PyButtonPropertiesBase
20-
: PyButtonPropertiesBase;
19+
export type PyButtonProperties<OptionalProperties> =
20+
OptionalProperties extends infer OptionalProperties
21+
? OptionalProperties & PyButtonPropertiesBase
22+
: PyButtonPropertiesBase;
2123

2224
export type PyButtonTag = {
23-
<T extends object>(properties: PyButtonProperties<T>): JSX.Element;
24-
propTypes: WeakValidationMap<PyButtonPropertiesBase>;
25+
<OptionalProperties extends object>(
26+
properties: PyButtonProperties<OptionalProperties>,
27+
reference: LegacyRef<HTMLElement> | undefined,
28+
): JSX.Element;
29+
displayName?: string;
30+
defaultProps?: Partial<PyButtonPropertiesBase>;
31+
propTypes?: WeakValidationMap<PyButtonPropertiesBase>;
2532
};

0 commit comments

Comments
 (0)