生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

ColorSwatchPicker ​

Data entry component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="color-swatch-picker": root · label · item · swatch · indicator · hidden-input

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-color-swatch-picker>
Vue componentsXhColorSwatchPickerItem XhColorSwatchPickerLabel XhColorSwatchPickerRoot
ComposableuseColorSwatchPicker
State machinecolorSwatchPickerMachine
Skin@xihan-ui/styles/color-swatch-picker.css

Props ​

PropTypeRequired
swatchesColorSwatchPickerNode[]
valuestring | null
defaultValuestring | null
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
dirDirection
namestring
sizeSize
toneTone
translationsPartial<ColorSwatchPickerTranslations>
labelledboolean
ariaLabelstring
onValueChange(details: ColorSwatchPickerValueChangeDetails) => void

ColorSwatchPickerNode ​

Elements of swatches.

FieldTypeRequired
valuestringYes
labelstring
disabledboolean

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
value-changeColorSwatchPickerValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhColorSwatchPickerRootdefaultColorSwatchPickerRootSlotProps
XhColorSwatchPickerRootlabel—

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhColorSwatchPickerItemvaluestringYes
XhColorSwatchPickerItemlabelstring
XhColorSwatchPickerItemdisabledboolean
XhColorSwatchPickerRootlabelReactNode
XhColorSwatchPickerRootchildrenSlotChildren<ColorSwatchPickerRootSlotProps>

State ​

Public state is written to data-state.

PartValues
item'checked' | 'unchecked'
swatch'checked' | 'unchecked'
indicator'checked' | 'unchecked'
hidden-input'checked' | 'unchecked'

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · ITEM.SELECT · ITEM.FOCUS · GROUP.BLUR · FORM.RESET · PRESS.START · PRESS.END

Guards: canPress

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
valuestring | null
swatchesreadonly ColorSwatchPickerNodeMeta[]
focusedValuestring | null
isSelected(value: string) => boolean
setValue(next: string | null) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getItemProps(props: ColorSwatchPickerItemProps) => T['element']
getSwatchProps(props: ColorSwatchPickerItemProps) => T['element']
getIndicatorProps(props: ColorSwatchPickerItemProps) => T['element']
getHiddenInputProps(props: ColorSwatchPickerItemProps) => T['input']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Tab / Shift+Tabcolor-swatch-picker.kbd.tab
ArrowDown / ArrowRightcolor-swatch-picker.kbd.next
ArrowUp / ArrowLeftcolor-swatch-picker.kbd.prev
Spacecolor-swatch-picker.kbd.select
Spacecolor-swatch-picker.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-invalid'true' | 'false'
rootaria-labelprops.ariaLabel
rootaria-labelledbyid of the label part | undefined
rootaria-readonly'true' | 'false'
rootaria-required'true' | 'false'
rootrole'radiogroup'
itemaria-checked'true' | 'false'
itemaria-disabled'true' | 'false'
itemaria-labelitemLabel(item)
itemrole'radio'
swatcharia-hidden'true'
indicatoraria-hidden'true'
hidden-inputaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/color-swatch-picker.css is written against [data-scope="color-swatch-picker"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-color-swatch-picker in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-disabled'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
labeldata-disabled'' (present only while the condition holds)
itemdata-disabled'' (present only while the condition holds)
itemdata-invalid'' (present only while the condition holds)
itemdata-pressed'' (present only while the condition holds)
itemdata-readonly'' (present only while the condition holds)
itemdata-state'checked' | 'unchecked'
swatchdata-disabled'' (present only while the condition holds)
swatchdata-invalid'' (present only while the condition holds)
swatchdata-readonly'' (present only while the condition holds)
swatchdata-state'checked' | 'unchecked'
swatchdata-xh-swatch''
swatchdata-xh-swatch-sizeprops.size
indicatordata-disabled'' (present only while the condition holds)
indicatordata-invalid'' (present only while the condition holds)
indicatordata-readonly'' (present only while the condition holds)
indicatordata-state'checked' | 'unchecked'
hidden-inputdata-disabled'' (present only while the condition holds)
hidden-inputdata-invalid'' (present only while the condition holds)
hidden-inputdata-readonly'' (present only while the condition holds)
hidden-inputdata-state'checked' | 'unchecked'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-color-swatch-picker-gaplabel
root
gap
margin-block-end
default--xh-_color-swatch-picker-gap
--xh-color-swatch-picker-icon-sizeroot--xh-icon-sizedefault--xh-_color-swatch-picker-mark
--xh-color-swatch-picker-indicator-bgindicatorbackgrounddefault--xh-_color-swatch-picker-accent
--xh-color-swatch-picker-indicator-borderindicatorborderdefault--xh-bg-canvas
--xh-color-swatch-picker-indicator-fgindicatorbackground-color
color
default
empty
--xh-_tone-on
--xh-color-swatch-picker-indicator-sizeindicatorblock-size
inline-size
default--xh-_color-swatch-picker-indicator
--xh-color-swatch-picker-item-radiusitem
swatch
--xh-swatch-radius
border-radius
default--xh-shape-inset
--xh-color-swatch-picker-item-sizeitemblock-size
inline-size
default--xh-_color-swatch-picker-cell
--xh-color-swatch-picker-label-fglabelcolordefault--xh-fg-muted
--xh-color-swatch-picker-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-color-swatch-picker-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-color-swatch-picker-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-color-swatch-picker-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-color-swatch-picker-ringitem
swatch
--xh-swatch-borderstate=checked--xh-_tone
--xh-color-swatch-picker-swatch-borderitem
swatch
--xh-swatch-borderdefault--xh-border-default
--xh-color-swatch-picker-swatch-border-hoveritem
swatch
--xh-swatch-borderdisabled
hover
not([data-disabled], [data-readonly], [data-state='checked'])
readonly
state=checked
--xh-border-control-hover
--xh-color-swatch-picker-swatch-border-invalidswatch--xh-swatch-borderinvalid--xh-border-invalid
--xh-color-swatch-picker-swatch-border-presseditem
swatch
--xh-swatch-borderdisabled
is(:active, [data-pressed])
not([data-disabled], [data-readonly])
pressed
readonly
--xh-_tone

Released under The MIT License