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

[base-ui] Improve recommended usage guide #38570

Merged
merged 2 commits into from
Sep 10, 2023

Conversation

oliviertassinari
Copy link
Member

From looking at #38138 (comment)

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation package: base-ui Specific to @mui/base labels Aug 20, 2023
@oliviertassinari oliviertassinari changed the title [base] Improve recommended usage guide [base-ui] Improve recommended usage guide Aug 20, 2023
@mui-bot
Copy link

mui-bot commented Aug 20, 2023

Netlify deploy preview

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 19e9a62

@@ -61,6 +62,8 @@ In this example we're using the [clsx](https://www.npmjs.com/package/clsx) utili
Use [`slotProps`](#customizing-slot-props) to apply custom styles using [Tailwind CSS](https://tailwindcss.com/), as shown below:

```tsx
import { Switch as UnstyledSwitch, SwitchOwnerState } from '@mui/base/Switch';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it easier to start

const StyledSwitch = styled(Switch)`
const Switch = styled(UnstyledSwitch)`
Copy link
Member Author

@oliviertassinari oliviertassinari Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes more sense to me. These components are likely to be used called Switch in the final app pages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use BaseSwitch in these contexts. Would it work for you as well?

Copy link
Member Author

@oliviertassinari oliviertassinari Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use this instance to come with a standard for all the demos in the documentation. I see two decisions we can make:

  1. prefix vs. suffit: BaseSwitch vs. SwitchBase
  2. Name: UnstyledSwich vs. BaseSwitch vs. else

Prefix makes sense for me, it makes it easier to spot what's styled and what's not.
Base references the projet name, it makes sense. It's also faster to type and read.

I think we can bring in @samuelsycamore, @mnajdova, @mj12albert on this discussion, they have also created demos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like BaseSwitch the best 👍

Would it be const Switch = styled(BaseSwitch) then? That looks great to me.

Copy link
Member Author

@oliviertassinari oliviertassinari Sep 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright BaseSwitch, I'm renaming it in this PR.

I think that we should update the rest of the docs/codebase. I have created #38904 to keep track of it.

const Input = styled('input')`
const SwitchInput = styled('input')`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other demos. But I guess it's also simpler to assume a global namespace. I hope that we have the static CSS extraction, we will be able to use this name to help debug.

Comment on lines 71 to 81
return (
<BasicSwitchRoot className={clsx(stateClasses)}>
<BasicSwitchThumb className={clsx(stateClasses)} />
<BasicSwitchInput {...getInputProps()} aria-label="Demo switch" />
</BasicSwitchRoot>
<SwitchRoot className={clsx(stateClasses)}>
<SwitchThumb className={clsx(stateClasses)} />
<SwitchInput {...getInputProps()} aria-label={props['aria-label']} />
</SwitchRoot>
);
}

export default function StylingHooks() {
return <BasicSwitch />;
return <Switch aria-label="Demo switch" />;
}
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 custom aria-label value inside the Switch component didn't make sense to me. This is can't be part of the design system.

Actually, this makes me wonder why in Base UI switch we aren't forwarding all the props to the hook. I find this strange:

const useSwitchProps = {
checked: checkedProp,
defaultChecked,
disabled: disabledProp,
onBlur,
onChange,
onFocus,
onFocusVisible,
readOnly: readOnlyProp,
};
const { getInputProps, checked, disabled, focusVisible, readOnly } = useSwitch(useSwitchProps);

It could be this, no?

  const { getInputProps, checked, disabled, focusVisible, readOnly } = useSwitch(props);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point 👍

Comment on lines -63 to -64
thumb: { className: 'thumb' },
input: { className: 'input' },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary and not the best practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, yes, but you can disable generation of default classes.

@oliviertassinari oliviertassinari merged commit a1ffff3 into mui:master Sep 10, 2023
@oliviertassinari oliviertassinari deleted the fix-backward-naming branch September 10, 2023 20:03
xcode-it pushed a commit to xcode-it/material-ui that referenced this pull request Sep 11, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants