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

[core] Improve DX of importing Base UI components #700

Merged
merged 11 commits into from
Oct 14, 2024

Conversation

michaldudak
Copy link
Member

@michaldudak michaldudak commented Oct 2, 2024

Changed how components are exported. Previously we had two index files: index.ts containing unprefixed component names (such as Root, Input, Indicator) and index.barrel.ts with full names (SwitchRoot, CheckboxIndicator). The former was supposed to be used as import * as Foo from '@base_ui/react/Foo, while the latter import { FooRoot } from '@base_ui/react'.

Now we still have two index files per component, but only index.ts is meant to be imported. index.parts.ts aggregates and exports all parts of a component, while index.ts reexports them and names the exported namespace.

This makes all component parts accessible only through the component namespace:

import { Checkbox } from '@base_ui/react/Checkbox'; // or '@base_ui/react'
const CheckboxRoot = Checkbox.Root;

Closes #650

@michaldudak michaldudak added core Infrastructure work going on behind the scenes dx Related to developers' experience labels Oct 2, 2024
@mui-bot
Copy link

mui-bot commented Oct 2, 2024

Netlify deploy preview

https://deploy-preview-700--base-ui.netlify.app/

Generated by 🚫 dangerJS against 256ec7a

flaviendelangle added a commit to flaviendelangle/mui-x that referenced this pull request Oct 3, 2024
@michaldudak michaldudak marked this pull request as ready for review October 8, 2024 08:08
@atomiks
Copy link
Contributor

atomiks commented Oct 9, 2024

This still works with tree-shaking if you test a minimal Vite repo and build for production?

@michaldudak
Copy link
Member Author

Yes, the resulting bundle does not contain the code of unused parts.

@colmtuite colmtuite requested a review from vladmoroz October 9, 2024 09:41
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 14, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 14, 2024
@michaldudak michaldudak merged commit d86a97c into mui:master Oct 14, 2024
18 checks passed
@michaldudak michaldudak deleted the improve-import-dx branch October 14, 2024 07:26
mj12albert pushed a commit to mj12albert/base-ui that referenced this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes dx Related to developers' experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up exports
3 participants