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

Class name customize API #276

Open
3 tasks
oliviertassinari opened this issue Oct 12, 2024 · 3 comments
Open
3 tasks

Class name customize API #276

oliviertassinari opened this issue Oct 12, 2024 · 3 comments
Assignees
Labels
bug 🐛 Something doesn't work dx Related to developers' experience regression A bug, but worse status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Milestone

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 12, 2024

Summary

Today, the class names look something like this:

SCR-20241013-bpwm

It's far from great DX, especially in dev-mode. It's actually a DX regression compared to emotion/sc. Also to note that emotion/sc were are DX regression compared to JSS.

Instead, I believe that we should get:

  • 1. Start the class name prefix from -2 or something like -va1 not -1 for variants. There is already a first one, the main one, it's confusing.
  • 2. In dev mode, use the names, like sc/emotion
SCR-20241013-btzi

How do we get the name? Either from the JavaScript variable name, or using some kind of a configurator. For example, sc uses withConfig({ displayName }), emotion uses styled(, { label }.

  • 3. In prod mode, allow to reproduce https://v4.mui.com/ global class names with no class name hash like f1bxvs2e
SCR-20241022-nrni

This should only be done for labels that developers provide and guarantee to be unique in the namespace. So it's important to distinguish two types of labels: a. the ones developers can add without thinking about unicity and b. the ones that are guaranteed to be unique.

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer regression A bug, but worse dx Related to developers' experience labels Oct 12, 2024
@brijeshb42 brijeshb42 added this to the Road to v1 milestone Oct 18, 2024
@brijeshb42 brijeshb42 assigned brijeshb42 and unassigned siriwatknp Oct 18, 2024
@brijeshb42
Copy link
Contributor

This is already in the works and will be part of v1. Default will always be random class though.

@oliviertassinari
Copy link
Member Author

This is already in the works and will be part of v1.

@brijeshb42 Great

Default will always be random class though.

Do you have more details on the behavior that we plan to implement? I'm not sure to understand this point.

@brijeshb42
Copy link
Contributor

brijeshb42 commented Oct 22, 2024

It'll be similar to what we do with emotion right now except it'll be configuratble by users as well -

const Component = styled('div', metadata)(cssObject)

The structure of metadata will be upto the user/library and in case of @mui/material, it'll be same as interface {name: string; slot: string}.

From Pigment config, users can have an option like

const pigmentConfig = {
  generateClassName(metadata: Metadata, randomClassSlug: string, variantObject?: Record<string,) {
    // in case of @mui/material
    return `${metadata.name}-${metadata.slot}${variantObject ? variantObject.className : ''}`;
  },
};

This is the rough API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work dx Related to developers' experience regression A bug, but worse status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants