Skip to content

Commit 4948d60

Browse files
committed
Refactor demo to avoid proptypes generation
1 parent 15dbdc3 commit 4948d60

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

docs/data/material/components/menus/UnstyledMenuPopup.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ const Popper = styled(PopperUnstyled)`
7979
`;
8080

8181
function MenuWrapper(props) {
82-
const { children, contentRef, label } = props;
82+
const { children, label } = props;
8383

8484
const [isOpen, setOpen] = React.useState(false);
8585
const buttonRef = React.useRef(null);
86+
const contentRef = React.useRef(null);
8687

8788
const close = () => setOpen(false);
8889

@@ -106,7 +107,7 @@ function MenuWrapper(props) {
106107
>
107108
{isOpen && (
108109
<ClickAwayListener onClickAway={() => setOpen(false)}>
109-
{children?.(close)}
110+
{children?.(close, contentRef)}
110111
</ClickAwayListener>
111112
)}
112113
</Popper>
@@ -116,27 +117,13 @@ function MenuWrapper(props) {
116117

117118
MenuWrapper.propTypes = {
118119
children: PropTypes.func.isRequired,
119-
contentRef: PropTypes.shape({
120-
current: function (props, propName) {
121-
if (props[propName] == null) {
122-
return null;
123-
} else if (
124-
typeof props[propName] !== 'object' ||
125-
props[propName].nodeType !== 1
126-
) {
127-
return new Error("Expected prop '" + propName + "' to be of type Element");
128-
}
129-
},
130-
}).isRequired,
131120
label: PropTypes.string,
132121
};
133122

134123
export default function UnstyledMenuPopup() {
135-
const contentRef = React.useRef(null);
136-
137124
return (
138-
<MenuWrapper contentRef={contentRef} label="Language">
139-
{(close) => (
125+
<MenuWrapper label="Language">
126+
{(close, contentRef) => (
140127
<StyledMenu ref={contentRef}>
141128
<StyledMenuItem onClick={() => close()}>English</StyledMenuItem>
142129
<StyledMenuItem onClick={() => close()}>中文</StyledMenuItem>

docs/data/material/components/menus/UnstyledMenuPopup.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,19 @@ const Popper = styled(PopperUnstyled)`
7878
`;
7979

8080
interface MenuWrapperProps {
81-
contentRef: React.RefObject<HTMLElement>;
82-
children: (close: () => void) => JSX.Element;
81+
children: (
82+
close: () => void,
83+
contentRef: React.RefObject<HTMLElement>,
84+
) => JSX.Element;
8385
label?: string;
8486
}
8587

8688
function MenuWrapper(props: MenuWrapperProps) {
87-
const { children, contentRef, label } = props;
89+
const { children, label } = props;
8890

8991
const [isOpen, setOpen] = React.useState(false);
9092
const buttonRef = React.useRef<HTMLButtonElement>(null);
93+
const contentRef = React.useRef<HTMLElement>(null);
9194

9295
const close = () => setOpen(false);
9396

@@ -111,7 +114,7 @@ function MenuWrapper(props: MenuWrapperProps) {
111114
>
112115
{isOpen && (
113116
<ClickAwayListener onClickAway={() => setOpen(false)}>
114-
{children?.(close)}
117+
{children?.(close, contentRef)}
115118
</ClickAwayListener>
116119
)}
117120
</Popper>
@@ -120,11 +123,9 @@ function MenuWrapper(props: MenuWrapperProps) {
120123
}
121124

122125
export default function UnstyledMenuPopup() {
123-
const contentRef = React.useRef<HTMLElement>(null);
124-
125126
return (
126-
<MenuWrapper contentRef={contentRef} label="Language">
127-
{(close) => (
127+
<MenuWrapper label="Language">
128+
{(close, contentRef) => (
128129
<StyledMenu ref={contentRef}>
129130
<StyledMenuItem onClick={() => close()}>English</StyledMenuItem>
130131
<StyledMenuItem onClick={() => close()}>中文</StyledMenuItem>

docs/data/material/components/menus/UnstyledMenuPopup.tsx.preview

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<MenuWrapper contentRef={contentRef} label="Language">
2-
{(close) => (
1+
<MenuWrapper label="Language">
2+
{(close, contentRef) => (
33
<StyledMenu ref={contentRef}>
44
<StyledMenuItem onClick={() => close()}>English</StyledMenuItem>
55
<StyledMenuItem onClick={() => close()}>中文</StyledMenuItem>

0 commit comments

Comments
 (0)