Skip to content

Commit

Permalink
[core] Fix prop-types generation
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 6, 2023
1 parent 1a47213 commit b39c495
Show file tree
Hide file tree
Showing 68 changed files with 30 additions and 1,333 deletions.
18 changes: 11 additions & 7 deletions packages/api-docs-builder/utils/getPropsFromComponentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,26 @@ function getPropsFromVariableDeclaration({
return null;
}

let expression: ts.Expression = node.initializer;
if (ts.isAsExpression(node.initializer)) {
expression = node.initializer.expression;
}

if (
(ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) &&
node.initializer.parameters.length === 1
(ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) &&
expression.parameters.length === 1
) {
return parseFunctionComponent({
node,
shouldInclude,
project,
});
}

// x = React.memo((props:type) { return <div/> })
// x = React.forwardRef((props:type) { return <div/> })
if (ts.isCallExpression(node.initializer) && node.initializer.arguments.length > 0) {
const potentialComponent = node.initializer.arguments[0];
if (ts.isCallExpression(expression) && expression.arguments.length > 0) {
const potentialComponent = expression.arguments[0];
if (
(ts.isArrowFunction(potentialComponent) || ts.isFunctionExpression(potentialComponent)) &&
potentialComponent.parameters.length > 0 &&
Expand All @@ -250,14 +256,12 @@ function getPropsFromVariableDeclaration({
});
}
}

return null;
}

// handle component factories: x = createComponent()
if (
checkDeclarations &&
node.initializer &&
expression &&
getJSXLikeReturnValueFromFunction(type, project).length > 0
) {
return parseFunctionComponent({
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ Accordion.propTypes /* remove-proptypes */ = {
* @default 'neutral'
*/
color: PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, expands the accordion by default.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/AccordionDetails/AccordionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ AccordionDetails.propTypes /* remove-proptypes */ = {
* @default 'neutral'
*/
color: PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/AccordionGroup/AccordionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ AccordionGroup.propTypes /* remove-proptypes */ = {
* @default 'neutral'
*/
color: PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the divider between accordions will be hidden.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/AccordionSummary/AccordionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ AccordionSummary.propTypes /* remove-proptypes */ = {
* @default 'neutral'
*/
color: PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The indicator element to display.
* @default <KeyboardArrowDown />
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ Alert.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* Element placed after the children.
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/AspectRatio/AspectRatio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ AspectRatio.propTypes /* remove-proptypes */ = {
* @default 'neutral'
*/
color: PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* By default, the AspectRatio will maintain the aspect ratio of its content.
* Set this prop to `true` when the container is a flex row and you want the AspectRatio to fill the height of its container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ AutocompleteListbox.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The size of the component (affect other nested list* components).
* @default 'md'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ AutocompleteOption.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ Avatar.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The size of the component.
* It accepts theme values between 'sm' and 'lg'.
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/AvatarGroup/AvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ AvatarGroup.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The size of the component.
* It accepts theme values between 'sm' and 'lg'.
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,6 @@ Badge.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the badge is invisible.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ Breadcrumbs.propTypes /* remove-proptypes */ = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* Custom separator node.
* @default '/'
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ Button.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ ButtonGroup.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, all the buttons will be disabled.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ Card.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the children with an implicit color prop invert their colors to match the component's variant and color.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/CardActions/CardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ CardActions.propTypes /* remove-proptypes */ = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The component orientation.
* @default 'horizontal'
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/CardContent/CardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ CardContent.propTypes /* remove-proptypes */ = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The component orientation.
* @default 'vertical'
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/CardCover/CardCover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ CardCover.propTypes /* remove-proptypes */ = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/CardOverflow/CardOverflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ CardOverflow.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,6 @@ Checkbox.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The default checked state. Use when the component is not controlled.
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,6 @@ Chip.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/ChipDelete/ChipDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ ChipDelete.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* If `undefined`, the value inherits from the parent chip via a React context.
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/CircularProgress/CircularProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,6 @@ CircularProgress.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The boolean to select a variant.
* Use indeterminate when there is no progress value.
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ Divider.propTypes /* remove-proptypes */ = {
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* Class name applied to the divider to shrink or stretch the line based on the orientation.
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ FormControl.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the children are in disabled state.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/FormHelperText/FormHelperText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ FormHelperText.propTypes /* remove-proptypes */ = {
* The content of the component.
*/
children: PropTypes.node,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/FormLabel/FormLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ FormLabel.propTypes /* remove-proptypes */ = {
* The content of the component.
*/
children: PropTypes.node,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The asterisk is added if required=`true`
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ IconButton.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* @default false
Expand Down
5 changes: 0 additions & 5 deletions packages/mui-joy/src/LinearProgress/LinearProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ LinearProgress.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The boolean to select a variant.
* Use indeterminate when there is no progress value.
Expand Down
Loading

0 comments on commit b39c495

Please sign in to comment.