Skip to content

Commit

Permalink
[docs-infra] Always document the className and render props (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Jan 4, 2025
1 parent 9fb1b40 commit 3d2f42f
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/reference/generated/menu-checkbox-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
"type": "boolean",
"default": "false",
"description": "Whether the component should ignore user interaction."
},
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/generated/menu-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
"type": "boolean",
"default": "false",
"description": "Whether the component should ignore user interaction."
},
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {},
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/generated/menu-radio-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
"type": "boolean",
"default": "false",
"description": "Whether the component should ignore user interaction."
},
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {
Expand Down
11 changes: 10 additions & 1 deletion docs/reference/generated/select-item-text.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "SelectItemText",
"description": "A text label of the select item.\nRenders a `<div>` element.",
"props": {},
"props": {
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {},
"cssVariables": {}
}
8 changes: 8 additions & 0 deletions docs/reference/generated/select-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"type": "boolean",
"default": "false",
"description": "Whether the component should ignore user interaction."
},
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {},
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/generated/select-scroll-down-arrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"name": "SelectScrollDownArrow",
"description": "An element that scrolls the select menu down when hovered.\nRenders a `<div>` element.",
"props": {
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"keepMounted": {
"type": "boolean",
"default": "false",
"description": "Whether to keep the HTML element in the DOM while the select menu is not scrollable."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/generated/select-scroll-up-arrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"name": "SelectScrollUpArrow",
"description": "An element that scrolls the select menu down when hovered.\nRenders a `<div>` element.",
"props": {
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"keepMounted": {
"type": "boolean",
"default": "false",
"description": "Whether to keep the HTML element in the DOM while the select menu is not scrollable."
},
"render": {
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
}
},
"dataAttributes": {
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/menu/checkbox-item/MenuCheckboxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ MenuCheckboxItem.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether to close the menu when the item is clicked.
* @default false
Expand Down Expand Up @@ -314,6 +319,13 @@ MenuCheckboxItem.propTypes /* remove-proptypes */ = {
* The click handler for the menu item.
*/
onClick: PropTypes.func,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export { MenuCheckboxItem };
12 changes: 12 additions & 0 deletions packages/react/src/menu/item/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ MenuItem.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether to close the menu when the item is clicked.
*
Expand All @@ -255,6 +260,13 @@ MenuItem.propTypes /* remove-proptypes */ = {
* The click handler for the menu item.
*/
onClick: PropTypes.func,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export { MenuItem };
12 changes: 12 additions & 0 deletions packages/react/src/menu/radio-item/MenuRadioItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ MenuRadioItem.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether to close the menu when the item is clicked.
* @default false
Expand All @@ -297,6 +302,13 @@ MenuRadioItem.propTypes /* remove-proptypes */ = {
* The click handler for the menu item.
*/
onClick: PropTypes.func,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* Value of the radio item.
* This is the value that will be set in the MenuRadioGroup when the item is selected.
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/select/item-text/SelectItemText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ SelectItemText.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export { SelectItemText };
12 changes: 12 additions & 0 deletions packages/react/src/select/item/SelectItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ SelectItem.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether the component should ignore user interaction.
* @default false
Expand All @@ -331,6 +336,13 @@ SelectItem.propTypes /* remove-proptypes */ = {
* and when the item is matched during keyboard text navigation.
*/
label: PropTypes.string,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* A unique value that identifies this select item.
* @default null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ SelectScrollDownArrow.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether to keep the HTML element in the DOM while the select menu is not scrollable.
* @default false
*/
keepMounted: PropTypes.bool,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export { SelectScrollDownArrow };
12 changes: 12 additions & 0 deletions packages/react/src/select/scroll-up-arrow/SelectScrollUpArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ SelectScrollUpArrow.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Whether to keep the HTML element in the DOM while the select menu is not scrollable.
* @default false
*/
keepMounted: PropTypes.bool,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export { SelectScrollUpArrow };
6 changes: 2 additions & 4 deletions scripts/generateProptypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async function generateProptypes(project: TypeScriptProject, sourceFile: string)

const sourceContent = await fse.readFile(sourceFile, 'utf8');
const isTsFile = /(\.(ts|tsx))/.test(sourceFile);
const propsFile = sourceFile.replace(/(\.d\.ts|\.tsx|\.ts)/g, '.types.ts');

const result = injectPropTypesInFile({
components,
Expand Down Expand Up @@ -117,16 +116,15 @@ async function generateProptypes(project: TypeScriptProject, sourceFile: string)
return generated;
},
shouldInclude: ({ prop }) => {
if (prop.name === 'children') {
if (prop.name === 'children' || prop.name === 'className' || prop.name === 'render') {
return true;
}
let shouldDocument;

prop.filenames.forEach((filename) => {
const isExternal = filename !== sourceFile;

const implementedBySelfPropsFile = filename === propsFile;
if (!isExternal || implementedBySelfPropsFile) {
if (!isExternal) {
shouldDocument = true;
}
});
Expand Down

0 comments on commit 3d2f42f

Please sign in to comment.