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

Add utility classes to ColorPicker component #322

Merged
merged 2 commits into from
Feb 23, 2025

Conversation

benfinnett
Copy link
Contributor

In relation to #320, adds utility classes to ColorPicker so users can override/extend the default styles of the gradient picker, text input, and swatch container. This provides extensive customisability to any components making use of the ColorPicker. It introduces a classes prop to control the styling by merging custom class names with the default generated utility classes.

Changes

  • Added a colorPickerUtilityClasses constant generated by the getUtilityClasses helper.
  • Exposed gradientPicker, colorTextInput, and swatchContainer for ColorPicker.
  • Introduced a classes prop on ColorPickerProps.
  • Applied utility classes to the <HexColorPicker>/<HexAlphaColorPicker>, <TextField>, and swatch container <div>.

Example

Apply the desired CSS class to the ColorPickerProps:

<MenuButtonTextColor
  defaultTextColor={theme.palette.text.primary}
  swatchColors={[
      { value: "#000000", label: "Black" },
      { value: "#ffffff", label: "White" },
      { value: "#ff0000", label: "Red" },
      { value: "#0000ff", label: "Blue" },
  ]}
  ColorPickerProps={{
    classes: {
      gradientPicker: "hide",
      colorTextInput: "hide",
    },
  }}
/>

Apply the wanted styles, for example to hide certain parts of the color picker:

}.MuiTiptap-ColorPicker-gradientPicker.hide {
  display: none;
}
}.MuiTiptap-ColorPicker-colorTextInput.hide {
  display: none;
}

@benfinnett benfinnett changed the title feat(ColorPicker): Add classes prop for style overrides Add classes prop for style overrides Feb 22, 2025
@benfinnett benfinnett changed the title Add classes prop for style overrides Add classes prop for style overrides on ColorPicker Feb 22, 2025
@benfinnett benfinnett changed the title Add classes prop for style overrides on ColorPicker Add Utility Classes to ColorPicker Component Feb 22, 2025
@benfinnett benfinnett changed the title Add Utility Classes to ColorPicker Component Add utility classes to ColorPicker component Feb 22, 2025
Copy link
Owner

@sjdemartini sjdemartini left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for opening the PR and providing the detailed notes!

Comment on lines 105 to 118
* default utility classes. For instance, to hide the swatch container,
* you could do:
*
* ColorPickerProps={{
* classes: {
* swatchContainer: "hide-swatch"
* }
* }}
*
* And in your CSS:
*
* .MuiTiptap-ColorPicker-swatchContainer.hide-swatch {
* display: none;
* }
Copy link
Owner

Choose a reason for hiding this comment

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

Note that if you always want to hide the swatch container (i.e., the logic isn't conditional around passing in the hide-swatch class), you could simply add the CSS .MuiTiptap-ColorPicker-swatchContainer { display: none } and not need to make any changes to your ColorPickerProps or refer to a new class.

Going to slightly tweak this comment

@sjdemartini sjdemartini enabled auto-merge (squash) February 23, 2025 06:11
@sjdemartini sjdemartini merged commit 59d7f8e into sjdemartini:main Feb 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants