Skip to main content

XYPad

Two-dimensional slider component.

Source Style
Loading...
function App() {
  const [valueX, setValueX] = useState(32)
  const [valueY, setValueY] = useState(56)

  return (
    <div>
      <XYPad.Root
        className={xyPadTheme.root}
        value={[valueX, valueY]}
        min={0}
        max={100}
        onChange={([x, y]) => {
          setValueX(x)
          setValueY(y)
        }}
      >
        <XYPad.Area className={xyPadTheme.area}>
          <XYPad.Thumb
            className={xyPadTheme.thumb}
            aria-label={['X position', 'Y position']}
          />
        </XYPad.Area>
      </XYPad.Root>
      <p>
        x: {valueX}, y: {valueY}
      </p>
    </div>
  )
}

Import​

import { XYPad } from '@tremolo-ui/react'

API Reference​

Each part lists the props of its own. It also takes the attributes of the element it renders, such as className and style.

In Svelte and Vue the props are the same, written their way — class rather than className, bind:value or v-model, snippets or slots for content. See Svelte and Vue.

State is on the element as a data attribute, so it is a selector away — see Styling. An attribute is only there while its state is on.

Root​

Holds the value of both axes and the settings, and passes them to the parts inside.

PropTypeDefault
value*XY<number>—
min*number | readonly [number, number]—
max*number | readonly [number, number]—
stepnumber | readonly [number, number]1
scaleScale | readonly [Scale, Scale]linearScale
reverseboolean | readonly [boolean, boolean]false
wheelModifierValue<InputEventOption> | null['raw', 1]
dragSensitivityModifierValue<number>{ default: 1, shift: 0.1 }
keyboardModifierValue<InputEventOption> | null{ default: ['raw', 1], shift: ['raw', 0.1] }
dragCursorCursor'pointer'
disabledboolean—
readOnlyboolean—
onChange(value: XY<number>) => void—
onChangeStart(value: XY<number>, source: ChangeSource) => void—
onChangeEnd(value: XY<number>, source: ChangeSource) => void—
changeEndDelaynumber500
children*ReactNode—
actionsRefRef<XYPadMethods>—

Full reference: XYPadProps

Data attributeValues
[data-disabled]Present when disabled is set
[data-readonly]Present when readonly is set

Area​

The surface the thumb moves across. XYPad.Thumb goes inside it.

Set its size and background with CSS or style. It takes the attributes of a <div>.

Thumb​

The handle. Two visually hidden range inputs inside it, one per axis, take the focus and carry the ARIA.

Its children are drawn inside it. The thumb is one element either way, so what is passed there is decoration on top of it rather than a replacement for it — className and style are how its own appearance is changed.

PropTypeDefault
colorstring—
aria-labelstring | readonly [string | undefined, string | undefined]—
aria-labelledbystring | readonly [string | undefined, string | undefined]—
aria-describedbystring | readonly [string | undefined, string | undefined]—
aria-valuetextstring | readonly [string | undefined, string | undefined]—
actionsRefRef<XYPadThumbMethods>—

Full reference: XYPadThumbProps

Custom propertyWritten byWhat it sets
--colorcolorColour of the thumb.
Data attributeValues
[data-disabled]Present when disabled is set
[data-readonly]Present when readonly is set