-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Add hooks API pages for MUI Base #35828
Conversation
|
Signed-off-by: Marija Najdova <[email protected]>
@@ -91,7 +91,10 @@ export function writePrettifiedFile( | |||
* why the source includes relative url. We transform them to absolute urls with | |||
* this method. | |||
*/ | |||
async function computeApiDescription(api: ReactApi, options: { host: string }): Promise<string> { | |||
export async function computeApiDescription( | |||
api: { description: ReactApi['description'] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is simplified so that it can be used with the hooks generation too. Only the description is used in the function.
@@ -292,6 +292,13 @@ export interface UseAutocompleteProps< | |||
value?: AutocompleteValue<T, Multiple, DisableClearable, FreeSolo>; | |||
} | |||
|
|||
export interface UseAutocompleteParameters< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aliasing the interface so that it matches the name pattern used for the hooks parameters.
@@ -39,3 +40,33 @@ export interface UseButtonParameters { | |||
*/ | |||
type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type']; | |||
} | |||
|
|||
export interface UseButtonReturnValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit type added for the useButton
return value so that we can test out the generation of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also faster for TypeScript: https://github.com/microsoft/TypeScript/wiki/Performance#using-type-annotations.
I see that it's broken with the switch too https://deploy-preview-35828--material-ui.netlify.app/base/api/use-switch/#returnValue. Would it make sense to extract these changes out of this PR and to them iteratively?
* | ||
* - [useTabs API](https://mui.com/base/api/use-tabs/) | ||
*/ | ||
function useTabs(parameters: UseTabsParameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted to function for consistency and simplifying the generation script.
* | ||
* - [useTabsList API](https://mui.com/base/api/use-tabs-list/) | ||
*/ | ||
function useTabsList(parameters: UseTabsListParameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted to function for consistency and simplifying the generation script.
…dova/material-ui into docs/build-hooks-interfaces
return [] as any; | ||
} | ||
|
||
// Only keep `default` for bool props if it isn't 'false'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no harm for us in being explicit and stating all boolean props' default values, not just non-false ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed here the logic in the components' props builder. We could fix it separately in both scripts. There was already an issue related to this - #35822
const Table = styled('table')(({ theme }) => { | ||
const contentColor = | ||
theme.palette.mode === 'dark' | ||
? alpha(theme.palette.primaryDark[900], 1) | ||
: 'rgba(255, 255, 255, 1)'; | ||
const contentColorTransparent = | ||
theme.palette.mode === 'dark' | ||
? alpha(theme.palette.primaryDark[900], 0) | ||
: 'rgba(255, 255, 255, 0)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, you abstracted the PropretiesTable
, it helps 👍. I was thinking of going all the way to create a generic top-level API component and have a JavaScript API to control its rendering.
This is MUI X page https://github.com/mui/mui-x/blob/next/docs/src/modules/components/ApiPage.js that is almost exactly the same as https://github.com/mui/material-ui/blob/next/docs/src/modules/components/ApiPage.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see anything wrong with the UX 👌, it flows like the component API pages, developers will be happy to have these pages.
Ah, I see your point. I haven't looked into this, but I can do a follow-up on this and see what's different between the two. We can have one component that can handle all three scenarios (components, interfaces, hooks), but I woldn't change it in this PR so that we don't have unrelated changes. I will likely need two PRs, one on X side to test out the changes. |
The parameters table doesn't format the text as markdown. Specifically, text is backticks isn't formatted as code. See https://deploy-preview-35828--material-ui.netlify.app/base/api/use-button/#parameters and compare to https://deploy-preview-35828--material-ui.netlify.app/base/api/tab-unstyled/#props Aside from that, it looks good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find anything wrong. Good work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks fantastic! 👌 I did some testing and found a few things. Maybe you are already aware of this. Just listing them so they can be tracked. Some of them can be probably be addressed in this PR.
- There is no link to the demos on the
useAutocomplete
anduseSelect
pages. Its understandable foruseAutocomplete
since there is noAutocompleteUnstyled
, butuseSelect
can be linked toSelectUnstyled
page (the hook section)? - Menu related hooks APIs have
Hooks
section (plural) instead ofHook
in the demos page. - Tab/Tabs related hooks don't have their respective hooks section in their unstyled components page.
Looks super solid 👌 Maybe we could group the entries in the left NavBar to improve the readability. |
It's an interesting thought, it may depend on whether we want to group them by components vs hooks (maybe add level 2 subgroup), or by concept, for e.g. having ButtonUnstyled & useButton next to each other. Happy to iterate on this later (if we decide to keep the pages vs the tabs). |
Nice findings @ZeeshanTamboli
Fixed the
Added logic to point to #hooks if there are multiple hooks
cc @samuelsycamore we'll need to add it. |
Co-authored-by: Zeeshan Tamboli <[email protected]> Signed-off-by: Marija Najdova <[email protected]>
This PR adds logic for generating APIs for the hooks (currently used in MUI Base only). It generates the input params and return value considering the exported types from the project by using the following convention:
${hookName}Parameters
- for the params${hookname}ReturnValue
- for the return valueIt also adds annotation above the hooks about where the demos and API pages are (similar to the components).
Example: https://deploy-preview-35828--material-ui.netlify.app/base/api/use-button/
The API pages for the hooks are linked in the API section of the unstyled components: https://deploy-preview-35828--material-ui.netlify.app/base/react-button/#api For this to work, in the headers of the component markdown there is a new
hook
header.The relevant changes are in the following files:
ComponentApiBuilder
, but adjusted to hooks. The logic for generating the json APIs from interfaces was taken from MUI X, and slightly simplified and adjusted (in MUI Core we don't need to have distinction between different packages pro/premium etc.)HookApiBuilder
TODOs:
After the PR is merged:
Fixes #35792