4.8.1 • Published 3 years ago

@workday/canvas-kit-labs-react-color-picker v4.8.1

Weekly downloads
1,024
License
Apache-2.0
Repository
github
Last release
3 years ago

Canvas Kit React Color Picker

Color Picker is a popup for selecting a color.

The Color Picker is designed to be used different contexts. The pattern shown below is one where the Color Picker is used as a popup from a button target by using hooks around the callbacks provided by the component.

Installation

yarn add @workday/canvas-kit-labs-react-color-picker

or

yarn add @workday/canvas-kit-labs-react-color-picker

Usage

import * as React from 'react';
import ColorPicker from '@workday/canvas-kit-labs-react-color-picker';
import {colors} from '@workday/canvas-kit-react-core';
import {Button} from '@workday/canvas-kit-react-button';
import {Popper} from '@workday/canvas-kit-react-common';

const MyComponent: React.FunctionComponent = () => {
  const [isOpen, setIsOpen] = React.useState(false);
  const [color, setColor] = React.useState('');
  const buttonRef = React.useRef(null);

  const toggleOpen = () => setIsOpen(!isOpen);

  const handleSubmit = React.useCallback(
    (submitColor: string) => {
      setColor(submitColor.toUpperCase());
      setIsOpen(false);
    },
    [setIsOpen]
  );

  return (
    <>
      <Button buttonRef={buttonRef} variant={Button.Variant.Primary} onClick={toggleOpen}>
        Toggle Color Picker
      </Button>
      <Popper placement={'bottom'} open={isOpen} anchorElement={buttonRef.current!}>
        <ColorPicker
          resetColor={colors.blueberry400}
          resetLabel={'Reset'}
          showCustomHexInput={true}
          onColorChange={handleSubmit}
          onColorReset={() => handleSubmit(colors.blueberry400)}
          onSubmitClick={toggleOpen}
          value={color}
          style={{marginTop: 8}}
        />
      </Popper>
    </>
  );
};

Static Properties

None

Component Props

Required

onColorChange: (color: string) => void

This handler is called when the user selects a color through either a mouse or keyboard event. It is called with the hex value of the color selected by the user, or with a custom hex value entered by the user in the custom input.

Optional

onColorReset: Function

When this handler is provided, a Reset button will be displayed at the top of the picker using the resetLabel provided. This handler is called when the reset button is selected through either a mouse or keyboard event.


resetColor: string

The color to display as part of the Reset button. It is strongly recommended that consumers provide a properly globalized value.

Note: This prop is only necessary when the onColorReset handler is provided.


resetLabel: string

The text to display as part of the Reset button. It is strongly recommended that consumers provide a properly globalized value.

Note: This prop is only necessary when the onColorReset handler is provided.

Default: Reset


value: string

The hex value of the color to display styled in a selected state. If the value doesn't match one of the available colors, the hex value will be displayed in the custom input.


colorSet: string[]

The hex values of the colors to display in the color picker grid. If no custom colors are provided, a default set will be rendered.


showCustomHexInput: boolean

When true the ColorInput component and a submit button will be displayed at the bottom of the picker allowing the user to enter a custom hex value.

Default: false


customHexInputLabel: string

The text to display abover the custom input. It is strongly recommended that consumers provide a properly globalized value.

Note: This prop is only used when showCustomHexInput is true.

Default: Custom Hex Color


onSubmitClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void

When this handler is provided, an action can be tied to clicking the check button provided. This handler is called when the check button is selected through a keyboard event only.

Note: This prop is only used when showCustomHexInput is true.


4.8.3

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.1-next.18

3 years ago

4.7.1-next.14

3 years ago

4.7.1-next.15

3 years ago

4.7.1-next.16

3 years ago

4.7.1-next.0

3 years ago

4.7.1-next.1

3 years ago

4.7.1-next.2

3 years ago

4.7.1-next.3

3 years ago

4.7.1-next.4

3 years ago

4.7.1-next.5

3 years ago

4.7.1-next.6

3 years ago

4.7.1-next.7

3 years ago

4.7.1-next.8

3 years ago

4.7.1-next.9

3 years ago

4.7.1-next.10

3 years ago

4.7.1-next.11

3 years ago

4.7.1-next.12

3 years ago

4.7.0

3 years ago

4.6.1-next.3

3 years ago

4.6.1-next.2

3 years ago

4.6.1-next.1

3 years ago

4.6.0

3 years ago

4.5.2-next.3

3 years ago

4.5.2-next.1

3 years ago

4.5.2-next.2

3 years ago

4.5.2-next.0

3 years ago

4.5.1

3 years ago

4.5.1-next.4

3 years ago

4.5.1-next.3

3 years ago

4.5.1-next.2

3 years ago

4.5.1-next.1

3 years ago

4.5.1-next.0

3 years ago

4.5.0

3 years ago

4.4.3-next.15

3 years ago

4.4.3-next.17

3 years ago

4.4.3-next.16

3 years ago

4.4.3-next.18

3 years ago

4.4.3-next.14

3 years ago

4.4.3-next.13

3 years ago

4.4.3-next.12

3 years ago

4.4.3-next.11

3 years ago

5.0.0-beta.0

3 years ago

4.4.3-next.10

3 years ago

4.4.3-next.9

3 years ago

4.4.3-next.8

3 years ago

4.4.3-next.7

3 years ago

4.4.3-next.6

3 years ago

4.4.3-next.5

3 years ago

4.4.3-next.4

3 years ago

4.4.3-next.3

3 years ago

4.4.3-next.0

3 years ago

4.4.3-next.1

3 years ago

4.4.2

3 years ago

4.4.2-next.4

3 years ago

4.4.2-next.3

3 years ago

4.4.2-next.2

3 years ago

4.4.1-next.4

3 years ago

4.4.1

3 years ago

4.4.1-next.3

3 years ago

4.4.1-next.2

3 years ago

4.4.1-next.1

3 years ago

4.4.1-next.0

3 years ago

4.4.0

3 years ago

4.3.2-next.6

3 years ago

4.3.2-next.4

3 years ago

4.3.2-next.3

3 years ago

4.3.2-next.5

3 years ago

4.3.2-next.2

3 years ago

4.3.2-next.1

3 years ago

4.3.2-next.0

3 years ago

4.3.1

4 years ago

4.3.1-next.4

4 years ago

4.3.1-next.3

4 years ago

4.3.1-next.2

4 years ago

4.3.1-next.1

4 years ago

4.3.1-next.0

4 years ago

4.1.3-next.28

4 years ago

4.3.0

4 years ago

4.1.3-next.27

4 years ago

4.1.3-next.26

4 years ago

4.1.3-next.25

4 years ago

4.1.3-next.24

4 years ago

4.1.3-next.23

4 years ago

4.1.3-next.22

4 years ago

4.1.3-next.20

4 years ago

4.1.3-next.21

4 years ago

4.1.3-next.17

4 years ago

4.1.3-next.18

4 years ago

4.1.3-next.16

4 years ago

4.2.0

4 years ago

4.1.3-next.13

4 years ago

4.1.3-next.12

4 years ago

4.1.3-next.10

4 years ago

4.1.3-next.11

4 years ago

4.1.3-next.8

4 years ago

4.1.3-next.9

4 years ago

4.1.3-next.6

4 years ago

4.1.3-next.7

4 years ago

4.1.3-next.4

4 years ago

4.1.3-next.3

4 years ago

4.1.3-next.1

4 years ago

4.1.3-next.0

4 years ago

4.0.3

4 years ago

4.1.2

4 years ago

4.1.2-next.0

4 years ago

4.0.2

4 years ago

4.1.1

4 years ago

4.1.1-next.5

4 years ago

4.1.1-next.4

4 years ago

4.1.1-next.3

4 years ago

4.1.1-next.2

4 years ago

4.1.1-next.0

4 years ago

3.9.2

4 years ago

4.0.1-next.18

4 years ago

4.1.0

4 years ago

4.0.1-next.17

4 years ago

4.0.1-next.16

4 years ago

4.0.1-next.15

4 years ago

4.0.1-next.14

4 years ago

4.0.1

4 years ago

3.9.1

4 years ago

4.0.1-next.12

4 years ago

4.0.1-next.11

4 years ago

4.0.1-next.9

4 years ago

4.0.1-next.10

4 years ago

4.0.1-next.7

4 years ago

4.0.1-next.8

4 years ago

4.0.1-next.6

4 years ago

4.0.1-next.5

4 years ago

4.0.1-next.4

4 years ago

4.0.1-next.1

4 years ago

4.0.1-next.2

4 years ago

4.0.1-next.0

4 years ago

3.8.1-next.16

4 years ago

3.8.1-next.17

4 years ago

4.0.0

4 years ago

3.9.0

4 years ago

4.0.0-beta.5

4 years ago

3.8.1-next.15

4 years ago

3.8.1-next.14

4 years ago

3.8.1-next.13

4 years ago

3.8.1-next.12

4 years ago

3.8.1-next.11

4 years ago

3.8.1-next.10

4 years ago

3.8.1-next.7

4 years ago

3.8.1-next.8

4 years ago

3.8.1-next.9

4 years ago

3.8.1-next.6

4 years ago

3.8.1-next.5

4 years ago

3.8.1-next.3

4 years ago

3.8.1-next.4

4 years ago

3.8.1-next.2

4 years ago

3.8.1-next.1

4 years ago

3.8.1-next.0

4 years ago

3.8.0

4 years ago

3.7.1-next.8

4 years ago

3.7.1-next.7

4 years ago

3.7.1-next.6

4 years ago

3.7.1-next.3

4 years ago

3.7.1-next.4

4 years ago

3.7.1-next.5

4 years ago

4.0.0-beta.4

4 years ago

3.7.1-next.2

4 years ago

3.7.1-next.0

4 years ago

4.0.0-beta.3

4 years ago

4.0.0-beta.2

4 years ago

3.6.1-next.14

4 years ago

3.7.0

4 years ago

3.6.1-next.13

4 years ago

3.6.1-next.12

4 years ago

3.6.1-next.11

4 years ago

3.6.1-next.10

4 years ago

3.6.1-next.9

4 years ago

3.6.1-next.8

4 years ago

3.6.1-next.7

4 years ago

3.6.1-next.6

4 years ago

3.6.1-next.5

4 years ago

3.6.1-next.4

4 years ago

3.6.1-next.3

4 years ago

3.6.1-next.2

4 years ago

3.6.1-next.1

4 years ago

3.6.1-next.0

4 years ago

4.0.0-beta.1

4 years ago

3.5.1-next.10

4 years ago

3.6.0

4 years ago

3.5.1-next.9

4 years ago

3.5.1-next.8

4 years ago

4.0.0-beta.0

4 years ago

3.5.1-next.7

4 years ago

3.5.1-next.6

4 years ago

3.5.1-next.5

4 years ago

3.5.1-next.4

4 years ago

3.5.1-next.2

4 years ago

3.5.1-next.3

4 years ago

3.5.1-next.1

4 years ago

3.5.1-next.0

4 years ago