UNPKG

tldraw

Version:

A tiny little drawing editor.

92 lines (91 loc) 3.35 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var TldrawUiSlider_exports = {}; __export(TldrawUiSlider_exports, { TldrawUiSlider: () => TldrawUiSlider }); module.exports = __toCommonJS(TldrawUiSlider_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_radix_ui = require("radix-ui"); var import_react = require("react"); var import_useTranslation = require("../../hooks/useTranslation/useTranslation"); const TldrawUiSlider = (0, import_react.memo)(function Slider({ onHistoryMark, title, steps, value, label, onValueChange, ["data-testid"]: testId }) { const msg = (0, import_useTranslation.useTranslation)(); const [tabIndex, setTabIndex] = (0, import_react.useState)(-1); (0, import_react.useEffect)(() => { setTabIndex(0); }, []); const handleValueChange = (0, import_react.useCallback)( (value2) => { onValueChange(value2[0]); }, [onValueChange] ); const handlePointerDown = (0, import_react.useCallback)(() => { onHistoryMark("click slider"); }, [onHistoryMark]); const handlePointerUp = (0, import_react.useCallback)(() => { if (!value) return; onValueChange(value); }, [value, onValueChange]); const handleKeyEvent = (0, import_react.useCallback)((event) => { if (event.key === "Tab") { event.stopPropagation(); } }, []); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tlui-slider__container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_radix_ui.Slider.Root, { "data-testid": testId, className: "tlui-slider", dir: "ltr", min: 0, max: steps, step: 1, value: value ? [value] : void 0, onPointerDown: handlePointerDown, onValueChange: handleValueChange, onPointerUp: handlePointerUp, onKeyDownCapture: handleKeyEvent, onKeyUpCapture: handleKeyEvent, title: title + " \u2014 " + msg(label), children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Slider.Track, { className: "tlui-slider__track", dir: "ltr", children: value !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_radix_ui.Slider.Range, { className: "tlui-slider__range", dir: "ltr" }) }), value !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_radix_ui.Slider.Thumb, { "aria-label": msg("style-panel.opacity"), className: "tlui-slider__thumb", dir: "ltr", tabIndex } ) ] } ) }); }); //# sourceMappingURL=TldrawUiSlider.js.map