Skip to content
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

Merged
merged 30 commits into from
Feb 2, 2023

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Jan 14, 2023

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 value

It 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:

TODOs:

  • Add one hook return type & generation
  • Add annotation on the hook for API and demos (similar to the components)

After the PR is merged:

Fixes #35792

@mnajdova mnajdova added the scope: docs-infra Specific to the docs-infra product label Jan 14, 2023
@mui-bot
Copy link

mui-bot commented Jan 14, 2023

Messages
📖 Netlify deploy preview: https://deploy-preview-35828--material-ui.netlify.app/

Details of bundle changes

Generated by 🚫 dangerJS against d1ba785

@mnajdova mnajdova changed the title [WIP][docs] Add hooks API pages [docs] Add hooks API pages Jan 18, 2023
@@ -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'] },
Copy link
Member Author

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<
Copy link
Member Author

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 {
Copy link
Member Author

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.

Copy link
Member

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) {
Copy link
Member Author

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) {
Copy link
Member Author

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.

@mnajdova mnajdova changed the title [docs] Add hooks API pages [docs] Add hooks API pages for MUI Base Jan 18, 2023
@mnajdova mnajdova added docs Improvements or additions to the documentation package: base-ui Specific to @mui/base labels Jan 18, 2023
@mnajdova mnajdova requested review from a team January 18, 2023 10:39
return [] as any;
}

// Only keep `default` for bool props if it isn't 'false'.
Copy link
Member

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.

Copy link
Member Author

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

@mnajdova mnajdova requested a review from michaldudak January 24, 2023 09:32
docs/src/modules/components/ApiPage.js Outdated Show resolved Hide resolved
Comment on lines 20 to 28
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)';
Copy link
Member

@oliviertassinari oliviertassinari Jan 29, 2023

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.

Copy link
Member

@oliviertassinari oliviertassinari left a 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.

@mnajdova
Copy link
Member Author

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.

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.

@michaldudak
Copy link
Member

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!

Copy link
Member

@michaldudak michaldudak left a 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!

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a 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 and useSelect pages. Its understandable for useAutocomplete since there is no AutocompleteUnstyled, but useSelect can be linked to SelectUnstyled page (the hook section)?
  • Menu related hooks APIs have Hooks section (plural) instead of Hook in the demos page.
  • Tab/Tabs related hooks don't have their respective hooks section in their unstyled components page.

@flaviendelangle
Copy link
Member

Looks super solid 👌

Maybe we could group the entries in the left NavBar to improve the readability.
It's not super urgent since the alphabetical sorting already does most of the work.

@mnajdova
Copy link
Member Author

mnajdova commented Feb 1, 2023

Maybe we could group the entries in the left NavBar to improve the readability.
It's not super urgent since the alphabetical sorting already does most of the work.

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).

@mnajdova
Copy link
Member Author

mnajdova commented Feb 1, 2023

Nice findings @ZeeshanTamboli

There is no link to the demos on the useAutocomplete and useSelect pages. Its understandable for useAutocomplete since there is no AutocompleteUnstyled, but useSelect can be linked to SelectUnstyled page (the hook section)?

Fixed the useSelect 👍

Menu related hooks APIs have Hooks section (plural) instead of Hook in the demos page.

Added logic to point to #hooks if there are multiple hooks

Tab/Tabs related hooks don't have their respective hooks section in their unstyled components page.

cc @samuelsycamore we'll need to add it.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 1, 2023
Co-authored-by: Zeeshan Tamboli <[email protected]>
Signed-off-by: Marija Najdova <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation package: base-ui Specific to @mui/base scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs] Document MUI Base hooks
7 participants