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

Pass custom data as props in ColorPicker component #186

Open
danielbettech opened this issue Oct 30, 2021 · 2 comments
Open

Pass custom data as props in ColorPicker component #186

danielbettech opened this issue Oct 30, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@danielbettech
Copy link

How can I pass a custom name to the Color Picker component, so I can catch up the name value in the onClick event?
I need this string so I can change the piece of data related to that component, as I have more than one ColorPicker in the website. In the event I'm only getting the color values.

I would be nice I can pass a name property to the component. Is there any way?

image

@danielbettech
Copy link
Author

I resolve it wrapping the component and passing props to the parent.

@danielbettech
Copy link
Author

danielbettech commented Nov 13, 2021

The solution in my last comment makes the component non reusable.

This is my code for the custom component:

import { ColorPicker } from 'material-ui-color'

function InputControlColor(props) {
  const { subtitle, value, name, handleChangeCurrentHexValue } = props

  return (
    <FormGroup>
      <Wrapper>
        <SubTitle>{subtitle}</SubTitle>
        <Value>{value}</Value>
      </Wrapper>

      <ColorPicker
        value={value}
        name={name}
        onChange={handleChangeCurrentHexValue}
      />
    </FormGroup>
  )
}

export default InputControlColor

Then I'm using the component like this:

<InputControlColor
  subtitle="COLOR"
  value={shapeBackgroundColor}
  name="shapeBackgroundColor"
  handleChangeCurrentHexValue={handleChangeCurrentHexValue}
/>

In my handleChangeCurrentHexValue function I'm catching the event, but I need the name so I can change the state programmatically.

This is my function:

const handleChangeCurrentHexValue = (event) => {
  const { hex } = event
  changeCurrentValue(activeControl, event.target.name, `#${hex}`)
}

But event.target.name is not set.

How can I achieve this? I'm using this component in different places so I need that name string to make it work.

@mikbry mikbry added the enhancement New feature or request label Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants