UNPKG

react-native-a11y-slider

Version:

An accessible range slider that supports assistive devices like screen readers

69 lines 3.15 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { useCallback, useMemo } from "react"; import { MarkerType, SliderType, } from "./types"; export default function useA11yMarkerProps(_a) { var position = _a.position, type = _a.type, sliderType = _a.sliderType, minValue = _a.minValue, maxValue = _a.maxValue, setValue = _a.setValue, setA11yMarkerProps = _a.setA11yMarkerProps, a11yProps = __rest(_a, ["position", "type", "sliderType", "minValue", "maxValue", "setValue", "setA11yMarkerProps"]); var onAccessibilityAction = useCallback(function (event) { var action = event.nativeEvent.actionName; switch (action) { case "increment": setValue(position.index + 1, true); break; case "decrement": setValue(position.index - 1, true); } }, [position === null || position === void 0 ? void 0 : position.index, setValue]); var calculatedA11yProps = useMemo(function () { var custom = {}; if (typeof setA11yMarkerProps === "function") { custom = setA11yMarkerProps({ markerType: type, value: position.value, minValue: minValue, maxValue: maxValue, }); } var accessibilityLabel = "Select value"; if (sliderType === SliderType.RANGE) { accessibilityLabel = type === MarkerType.LOWER ? "Min" : "Max"; } return __assign(__assign(__assign({ accessibilityLabel: accessibilityLabel, accessible: true, accessibilityRole: "adjustable", accessibilityValue: { min: typeof minValue === "number" ? minValue : undefined, max: typeof maxValue === "number" ? maxValue : undefined, now: typeof position.value === "number" ? position.value : undefined, text: String(position.value), } }, a11yProps), custom), { onAccessibilityAction: onAccessibilityAction, accessibilityActions: [{ name: "increment" }, { name: "decrement" }] }); }, [ setA11yMarkerProps, sliderType, minValue, maxValue, position.value, a11yProps, onAccessibilityAction, type, ]); return calculatedA11yProps; } //# sourceMappingURL=useA11yMarkerProps.js.map