Hex input with a swatch prefix or suffix
import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react";
import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react";
export default () => (
<ColorField aria-label="Colour" defaultValue="#0485F7">
<ColorInputGroup>
<ColorInputGroup.Prefix>
<ColorSwatch size="xs" />
</ColorInputGroup.Prefix>
<ColorInputGroup.Input />
<ColorInputGroup.Suffix>hex</ColorInputGroup.Suffix>
</ColorInputGroup>
</ColorField>
);
<ColorInputGroup className="w-40">
<ColorInputGroup.Input />
</ColorInputGroup>
@layer components {
.color-input-group {
--color-input-group-radius: var(--radius-lg);
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The ColorInputGroup component uses these CSS classes (view source styles):
.color-input-group - Shell with fill, border and focus ring
.color-input-group__input - Borderless, transparent control
.color-input-group__prefix - Slot before the control
.color-input-group__suffix - Slot after the control
.color-input-group--primary - Field fill with shadow (default)
.color-input-group--secondary - Neutral fill without shadow
.color-input-group--full-width - Fills the container width
[data-slot="color-input-group"]
[data-slot="color-input-group-input"]
[data-slot="color-input-group-prefix"]
[data-slot="color-input-group-suffix"]
| Variable | Purpose |
|---|
--color-input-group-bg | Fill |
--color-input-group-bg-hover | Fill on hover |
--color-input-group-bg-focus | Fill on focus |
--color-input-group-fg | Text colour |
--color-input-group-placeholder | Placeholder and slot colour |
--color-input-group-border | Border colour |
--color-input-group-border-hover | Border colour on hover |
--color-input-group-border-focus | Border colour on focus |
--color-input-group-radius | Corner radius |
--color-input-group-shadow | Field shadow |
- Hover:
:hover or [data-hovered] on .color-input-group
- Focus: the shell shows the ring while
.color-input-group__input has :focus or [data-focused]
- Invalid:
[data-invalid] or [aria-invalid="true"] on .color-input-group
- Disabled:
[data-disabled] or [aria-disabled="true"] on .color-input-group
| Prop | Type | Default | Description |
|---|
variant | "primary" | "secondary" | "primary" | Visual style of the group |
fullWidth | boolean | false | Makes the group fill its container |
className | string | ((values: GroupRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | | | Every React Aria Group prop |
| Prop | Type | Default | Description |
|---|
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered element; E defaults to "div" |
className | string | - | Additional classes |
...rest | | | Every attribute of the rendered element |
| Prop | Type | Default | Description |
|---|
className | string | ((values: InputRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | | | Every React Aria Input prop |
| Prop | Type | Default | Description |
|---|
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered element; E defaults to "div" |
className | string | - | Additional classes |
...rest | | | Every attribute of the rendered element |
className on ColorInputGroup receives these values:
| Prop | Type | Description |
|---|
isHovered | boolean | Whether the group is hovered |
isFocusWithin | boolean | Whether focus is inside the group |
isDisabled | boolean | Whether the group is disabled |
isInvalid | boolean | Whether the group is invalid |