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

HexInput component #18

Merged
merged 11 commits into from
Aug 21, 2020
Merged

HexInput component #18

merged 11 commits into from
Aug 21, 2020

Conversation

omgovich
Copy link
Owner

@omgovich omgovich commented Aug 20, 2020

In case if the user needs to have a text field to type/paste HEX-color, he could import additional HexInput component which works well in pair with the picker and costs just 400 bytes:

import ColorPicker from "react-colorful";
import HexInput from 'react-colorful/HexInput';

const YourComponent = () => {
  const [color, setColor] = useState("#aabbcc");
  return (
    <div>
      <ColorPicker color={color} onChange={setColor} />
      <HexInput color={color} onChange={setColor} />
    </div>
  );
};

This component doesn't have any default styles. It's just an input with proper behavior. The developers could place and tweak this component any way they want.

BTW I noticed that ~33% of the HexInput's bundle size was the spread operator polyfill, so I used React.createElement("input", Object.assign({}, props, extraProps)) to fix that.

How to test

npm run start-demo

@omgovich omgovich self-assigned this Aug 20, 2020
@omgovich
Copy link
Owner Author

@molefrog Could you take a look?

@omgovich omgovich requested a review from molefrog August 20, 2020 17:16
@omgovich
Copy link
Owner Author

omgovich commented Aug 20, 2020

@molefrog I updated "Why react-colorful" section with:

ships only a minimal amount of manually optimized color conversion algorithms (while most of the popular pickers import entire color manipulation libraries that increase the bundle size by more than 10 KB and make your app slower).

Just wanted to mention that I polished the code to save bytes.
But not sure about the text inside the brackets. Probably too aggressive)

Alternative text:

doesn't import 10+ KB color conversion libraries, but ships only a minimal amount of manually optimized color conversion algorithms.

@molefrog
Copy link
Collaborator

@omgovich Should be fine!

(e) => {
if (!validHex(e.target.value)) setValue(escape(color));
},
[color]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, that's smart!

@omgovich omgovich merged commit cfe55ac into master Aug 21, 2020
@omgovich omgovich deleted the feature/hex-input branch August 21, 2020 08:44
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