Using a framework
The objects are framework-free on purpose: a class that takes an element. Every framework can hand one over. The pattern is always the same: create on mount, update when options change, destroy on unmount.
On this page
The quickest way is the wrapper that ships in every package: wrappers/react.mjs, vue.mjs, svelte.mjs, or element.mjs for a custom element that works in Angular, Astro or a plain page. On any piece's page, pick your framework in the Code tab and it writes the example with your settings. Below is what the wrappers do for you, if you'd rather wire it yourself.
React
import { useEffect, useRef } from 'react';
import { Odometer } from './odometer/odometer.mjs';
import './odometer/odometer.css';
export function Seats({ value }) {
const host = useRef(null);
const odo = useRef(null);
useEffect(() => {
odo.current = new Odometer(host.current, { value, digits: 3 });
return () => odo.current.destroy();
}, []);
useEffect(() => { odo.current?.setValue(value); }, [value]);
return <div ref={host} />;
}In Next.js, put 'use client' at the top of the file: the objects draw in the browser.
Vue
<script setup>
import { onMounted, onBeforeUnmount, ref, watch } from 'vue';
import { Iris } from './iris/iris.mjs';
import './iris/iris.css';
const props = defineProps({ open: Number });
const host = ref(null);
let iris;
onMounted(() => { iris = new Iris(host.value, { driver: 'manual' }); });
watch(() => props.open, (v) => iris?.open(v));
onBeforeUnmount(() => iris?.destroy());
</script>
<template><div ref="host"><img src="/work.jpg" alt="The project"></div></template>Svelte
<script>
import { onMount } from 'svelte';
import { PinScreen } from './pin-screen/pin-screen.mjs';
import './pin-screen/pin-screen.css';
export let text = 'HELLO';
let host, board;
onMount(() => {
board = new PinScreen(host, { text });
return () => board.destroy();
});
$: board?.update({ text });
</script>
<div bind:this={host} style="height: 420px"></div>Astro
<div id="vessel" style="height: 360px"></div>
<link rel="stylesheet" href="/vessel/vessel.css" />
<script>
import { Vessel } from '../vessel/vessel.mjs';
new Vessel(document.getElementById('vessel'), { level: 0.62 });
</script>Server rendering
The objects touch window, document and the canvas, so construct them only in the browser: in an effect, onMount, a client script or behind a dynamic import. Rendering the empty host element on the server is fine; it is what the object fills.
With UI SDK
UI SDK is a library of unstyled custom elements that bring their own behaviour. If your app already uses it, its slider can wear the kit's fader. This is a recipe, not a supported line: Tactile itself stays plain classes on native elements, with no dependency.
Three things to know first:
- It needs JavaScript. UI SDK's slider draws nothing until its script runs. The kit's own fader is a native
<input type="range">that works without any script. - It loads UI SDK. You install
@ui-sdk/webyourself; nothing here ships it. It is in beta, so a new release can change the elements this CSS targets. - Only the plain finish carries over. The kit's other finish families draw the fader on the browser's own range parts, so on UI SDK they fall back to the plain look.
Install UI SDK, load kit.css (the fader's tokens come with the kit), import the slider, and give the element the class tui-fader-sdk:
npm install @ui-sdk/web<script type="module">import '@ui-sdk/web/slider';</script>
<ui-slider class="tui-fader-sdk" default-value="62" name="level" aria-label="Level">
<ui-slider-control><ui-slider-track><ui-slider-indicator></ui-slider-indicator><ui-slider-thumb aria-label="Level"></ui-slider-thumb></ui-slider-track></ui-slider-control>
</ui-slider>Then add this CSS after kit.css. The track is inset by half a cap (8px), so the cap stops at the slot's ends as the native one does, and the focus ring goes on the thumb, because UI SDK puts focus on a hidden input inside it:
ui-slider.tui-fader-sdk { display: block; width: 100%; }
.tui-fader-sdk ui-slider-control { position: relative; height: 32px; cursor: pointer; }
.tui-fader-sdk ui-slider-control::before {
content: ''; position: absolute; inset-inline: 0; top: 50%; height: 6px; translate: 0 -50%;
border-radius: 3px;
background: var(--tui-well-fill) var(--tui-well);
box-shadow: var(--tui-depth-well, inset 0 1.5px 2px rgb(var(--tui-sh) / calc(var(--tui-sh-a) * 2)), 0 1px 0 var(--tui-hl));
}
.tui-fader-sdk ui-slider-track { display: block; height: 100%; margin-inline: 8px; }
.tui-fader-sdk ui-slider-indicator { display: none; }
.tui-fader-sdk ui-slider-thumb {
width: 16px; height: 28px; border-radius: 4px;
background:
linear-gradient(var(--tui-ink), var(--tui-ink)) center / 100% 1.5px no-repeat,
var(--tui-depth-cap, linear-gradient(90deg, var(--tui-face-lo), var(--tui-face-hi) 30%, var(--tui-face-hi) 60%, var(--tui-face-lo)));
box-shadow: var(--tui-depth-key, inset 0 1px 0 var(--tui-hl), 0 2px 0 var(--tui-skirt), 0 4px 8px rgb(var(--tui-sh) / 0.35));
}
.tui-fader-sdk ui-slider-thumb:has(:focus-visible) { outline: 2px solid var(--tui-focus); outline-offset: 2px; }
.tui-fader-sdk[disabled] { opacity: 0.45; }
.tui-fader-sdk[disabled] ui-slider-control { cursor: not-allowed; }It works in both finishes, aluminium and graphite. Keyboard, pointer, form posting and what a screen reader hears are UI SDK's, and match the kit's fader. UI SDK is Apache-2.0: you install it yourself, so this CSS carries no obligations of its own.