XY Pad
An XY pad component for controlling two parameters simultaneously. Perfect for synthesizers, filters, and effects that need two-dimensional control.
Loading...
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script>
<XYPad defaultValue={{ x: 50, y: 50 }} class="aspect-square" /> Installation
Install cva@npm:class-variance-authority :
Copy and paste the following code into your project.
Usage
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script> Basic XY Pad
<XYPad defaultValue={{ x: 50, y: 50 }} /> Custom Value Display
Loading...
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script>
<XYPad
defaultValue={{ x: 50, y: 50 }}
class="aspect-square"
formatValue={(val) => `X: ${val.x}, Y: ${val.y}`}
maxX={100}
maxY={100}
minX={0}
minY={0}
/> Hide Value Display
Loading...
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script>
<XYPad
defaultValue={{ x: 50, y: 50 }}
showValueDisplay={false}
maxX={100}
maxY={100}
minX={0}
minY={0}
class="aspect-square"
/> API Reference
XYPad
Props
Examples
Synthesizer Control
Loading...
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script>
<XYPad
defaultValue={{ x: 30, y: 70 }}
class="aspect-square"
formatValue={(v) => {
const freq = Math.round(20 + (v.x / 100) * 20_000);
const cutoff = Math.round(200 + (v.y / 100) * 8000);
return `${freq}Hz, ${cutoff}Hz`;
}}
/> Filter Control
Loading...
<script lang="ts">
import { XYPad } from "$lib/components/ui/audio/elements/xypad/index.js";
</script>
<XYPad
class="aspect-square"
defaultValue={{ x: 50, y: 50 }}
formatValue={(val) => `Freq: ${val.x}%, Res: ${val.y}%`}
/> Notes
Important Information:
- Native Implementation: This component is built as a pure Svelte implementation, providing a high-quality, accessible XY pad control without bulky dependencies.
- Grid Display: The pad includes a visual grid to help with positioning.
- Crosshair: Visual crosshairs indicate the current X and Y positions.
- Value Display: By default, a value display overlay shows the current position. You can customize the formatter function or hide it entirely.
- Size Variants: Four size variants are available (
sm,default,lg, andxl). These effectively control the pad height.- Keyboard Support: Arrow keys adjust the value by 1. Holding
Shiftwhile using arrow keys changes the step amount to 10.y = 100maps to the top of the pad following standard musical conventions.