# ColorInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/color_input

Category: Input controls

provides a UI to select or edit an oklch-based color with optional opacity, chroma, and hue controls

Public component import: `ColorInput`

Public manager import: `create_color_input_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { ColorInput, create_color_input_manager } from "sveltekit-ui"

  const manager = create_color_input_manager({
    label: "Accent color",
    val: { l: 12, c: 14, h: 16, o: 24, is_dark_theme_invert: true },
    is_show_opacity: true,
  })
</script>

<ColorInput {manager} />
<pre>{JSON.stringify(manager.val, null, 2)}</pre>
```

## Configuration

### `val`

- type: object
- default: null
- description: initial color data with shape { l, c, h, o, is_dark_theme_invert } or null

### `label`

- type: string
- default: null
- description: optional label displayed above the color input

### `is_show_opacity`

- type: boolean
- default: true
- description: whether to show opacity picker controls

### `l_options`

- type: array
- default: [0..24]
- description: the range of valid 'l' (lightness) indices

### `c_options`

- type: array
- default: [0..24]
- description: the range of valid 'c' (chroma) indices

### `h_options`

- type: array
- default: [0..24]
- description: the range of valid 'h' (hue) indices

### `o_options`

- type: array
- default: [0..24]
- description: the range of valid 'o' (opacity) indices

### `on_change`

- type: function
- default: null
- description: callback invoked whenever color values are updated

### `on_finish`

- type: function
- default: null
- description: callback invoked when the user finishes color selection

## Methods

### `init()`

- description: initializes internal state, sub-managers, and sets the initial value
- parameters:
  - config: object
- returns: void

### `set_val()`

- description: updates the color object to the provided value or null
- parameters:
  - input: object
- returns: void

### `set_lightness()`

- description: increments/decrements the 'l' value within the allowed range
- parameters:
  - l: number
  - change: number
  - is_ignore_on_change: boolean
- returns: void

### `set_chroma()`

- description: increments/decrements the 'c' value within the allowed range
- parameters:
  - c: number
  - change: number
- returns: void

### `set_hue()`

- description: increments/decrements the 'h' value within the allowed range
- parameters:
  - h: number
  - change: number
  - is_ignore_on_change: boolean
- returns: void

### `set_opacity()`

- description: increments/decrements the 'o' value within the allowed range
- parameters:
  - o: number
  - change: number
- returns: void

### `set_lightness_and_hue()`

- description: sets both lightness and hue simultaneously, optionally ignoring on_change callback
- parameters:
  - l_input: number
  - h_input: number
- returns: void

### `set_is_dark_theme_invert()`

- description: toggles is_dark_theme_invert boolean within the color object
- parameters:
  - input: boolean
- returns: void

### `finish()`

- description: closes the popover and invokes on_finish with the current color object
- parameters:
- returns: void

## Returned state

### `id`

- type: string
- description: unique id for this color input instance

### `val_base`

- type: object
- description: the default color object used if none is provided

### `val`

- type: object
- description: the current color value or null if unset

### `label`

- type: string
- description: an optional text label for the control

### `css_val`

- type: string
- description: the color as an oklch() string or 'transparent' if none

### `is_show_opacity`

- type: boolean
- description: true if the opacity picker is visible

### `l_options`

- type: array
- description: the valid range of lightness values

### `c_options`

- type: array
- description: the valid range of chroma values

### `h_options`

- type: array
- description: the valid range of hue values

### `o_options`

- type: array
- description: the valid range of opacity values

### `popover_manager`

- type: object
- description: popover manager controlling the color selection popover

### `is_dark_theme_invert_checkbox_manager`

- type: object
- description: checkbox manager controlling the is_dark_theme_invert toggle

### `toggle_button_manager`

- type: object
- description: button manager used to open the color picker popover

### `finish_button_manager`

- type: object
- description: button manager to finish color selection

### `lightness_up_button_manager`

- type: object
- description: button manager to increment lightness

### `lightness_down_button_manager`

- type: object
- description: button manager to decrement lightness

### `chroma_up_button_manager`

- type: object
- description: button manager to increment chroma

### `chroma_down_button_manager`

- type: object
- description: button manager to decrement chroma

### `hue_up_button_manager`

- type: object
- description: button manager to increment hue

### `hue_down_button_manager`

- type: object
- description: button manager to decrement hue

### `opacity_up_button_manager`

- type: object
- description: button manager to increment opacity

### `opacity_down_button_manager`

- type: object
- description: button manager to decrement opacity

### `set_null_button_manager`

- type: object
- description: button manager to set the color value to null
