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

[Joy] Make variants for more flexible #32931

Merged
merged 13 commits into from
May 28, 2022

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented May 27, 2022

Before

The global variants generated like this for hover, active and disabled:

{
  softHover: {
    '&:hover': { color, background, border }
  },
  softActive: {
    '&:active': { color, background, border }
  },
  softDisabled: {
    '&.Mui-disabled': { color, background, border }
  },
}

It makes customization confusing because softHover in this case can contain other style that's not speficific to hover and so on. Also the disabled state is fixed to .Mui-disabled which would be hard for the custom component to use.

After
The generation is flat without the states (the key is already explicit)

{
  softHover: { color, background, border },
  softActive: { color, background, border },
  softDisabled: { color, background, border },
}

// the component will have to consume like this:
const ButtonRoot = styled('buttton')(({ theme, ownerState }) => ([
  theme.variants[ownerState.variant!]?.[ownerState.color!],
  { '&:hover': theme.variants[`${ownerState.variant!}Hover`]?.[ownerState.color!] },
  { '&:active': theme.variants[`${ownerState.variant!}Active`]?.[ownerState.color!] },
  {
    [buttonClasses.disabled]:
      theme.variants[`${ownerState.variant!}Disabled`]?.[ownerState.color!],
  },
])

It is more flexible and easier to understand. Here is one example of bootstrap outlined button using Joy variants:

const ButtonRoot = styled('buttton')(({ theme, ownerState }) => ({
  ...theme.variants.outlined.primary,
  '&:hover': theme.variants.solidHover.primary,
});

Sorry, something went wrong.

@siriwatknp siriwatknp self-assigned this May 27, 2022
@siriwatknp siriwatknp added the package: joy-ui Specific to @mui/joy label May 27, 2022
@mui-bot
Copy link

mui-bot commented May 27, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 5c11ff6

@siriwatknp siriwatknp force-pushed the joy/flexible-variants branch from 03e4af9 to 74cdc6a Compare May 27, 2022 17:15
@siriwatknp siriwatknp force-pushed the joy/flexible-variants branch from 74cdc6a to 5c11ff6 Compare May 28, 2022 01:48
@siriwatknp siriwatknp changed the title [Joy] Refactor variants for more flexibility [Joy] Make variants for more flexible May 28, 2022
@siriwatknp siriwatknp merged commit 87ddb73 into mui:master May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants