CxJS

ColorField

import { ColorField } from 'cx/widgets'; Copied

The ColorField widget is used for selecting colors. It displays a color picker dropdown and supports multiple color formats including RGBA, HSLA, and hexadecimal.

<LabelsTopLayout columns={2}>
  <ColorField label="Standard (RGBA)" value={m.color} autoFocus />
  <ColorField label="HSLA Format" value={m.hsla} format="hsla" />
  <ColorField label="Hex Format" value={m.hex} format="hex" />
  <ColorField label="Disabled" value={m.color} disabled />
  <ColorField label="Read-only" value={m.color} readOnly />
  <ColorField
    label="Placeholder"
    value={m.placeholder}
    placeholder="Pick a color..."
  />
</LabelsTopLayout>

Configuration

Core Properties

PropertyTypeDefaultDescription
valuestringnullColor value in rgba, hsla, or hex format
formatstring"rgba"Output format: "rgba", "hsla", or "hex"
placeholderstringHint text displayed when the field is empty
disabledbooleanfalseDisables the input
enabledbooleanOpposite of disabled
readOnlybooleanfalseMakes the input read-only
requiredbooleanfalseMarks the field as required
labelstringField label text
emptyValueanynullValue written to the store when the field is cleared

Appearance

PropertyTypeDefaultDescription
showClearbooleantrueShows a clear button when the field has a value
hideClearbooleanfalseOpposite of showClear
alwaysShowClearbooleanfalseShows clear button even when the field is required
tooltipstring/objectTooltip text or configuration
inputStylestring/objectCSS styles applied to the input element
inputClassstringCSS class applied to the input element

Behavior

PropertyTypeDefaultDescription
autoFocusbooleanfalseAutomatically focuses the field on mount
trackFocusbooleanfalseAdds cxs-focus CSS class when input is focused
dropdownOptionsobjectAdditional configuration passed to the dropdown

Validation

PropertyTypeDefaultDescription
errorstringCustom error message. Field is marked invalid if set
visitedbooleanIf true, shows validation errors immediately
validationModestring"tooltip"How to show errors: "tooltip", "help", "help-block"
onValidatefunction(value, instance, validationParams) => string - Custom validation