@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
88 lines (85 loc) • 3.02 kB
JavaScript
import React, { useState } from 'react';
import cx from 'clsx';
import { Transition } from '../../Transition/Transition.js';
import useStyles from './Thumb.styles.js';
import { useMantineTheme } from '../../../theme/use-mantine-theme/use-mantine-theme.js';
import { mergeStyles } from '../../../theme/utils/merge-styles/merge-styles.js';
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
function Thumb({
max,
min,
value,
position,
label,
elementRef,
dragging,
onMouseDown,
color,
themeOverride,
classNames,
styles,
size,
labelTransition,
labelTransitionDuration,
labelTransitionTimingFunction,
labelAlwaysOn,
thumbLabel,
onFocus,
onBlur
}) {
const theme = useMantineTheme(themeOverride);
const classes = useStyles({ color, theme, size }, classNames, "slider");
const _styles = mergeStyles(classes, styles);
const [focused, setFocused] = useState(false);
return /* @__PURE__ */ React.createElement("div", {
tabIndex: 0,
role: "slider",
"aria-label": thumbLabel,
"aria-valuemax": max,
"aria-valuemin": min,
"aria-valuenow": value,
ref: elementRef,
className: cx(classes.thumb, { [classes.dragging]: dragging }),
onFocus: () => {
setFocused(true);
typeof onFocus === "function" && onFocus();
},
onBlur: () => {
setFocused(false);
typeof onBlur === "function" && onBlur();
},
onTouchStart: onMouseDown,
onMouseDown,
onClick: (event) => event.stopPropagation(),
style: __spreadProps(__spreadValues(__spreadValues({}, _styles.thumb), dragging ? _styles.dragging : null), { left: `${position}%` })
}, /* @__PURE__ */ React.createElement(Transition, {
mounted: label != null && (labelAlwaysOn || dragging || focused),
duration: labelTransitionDuration,
transition: labelTransition,
timingFunction: labelTransitionTimingFunction || theme.transitionTimingFunction
}, (transitionStyles) => /* @__PURE__ */ React.createElement("div", {
style: __spreadValues(__spreadValues({}, _styles.label), transitionStyles),
className: classes.label
}, label)));
}
Thumb.displayName = "@mantine/core/SliderThumb";
export { Thumb };
//# sourceMappingURL=Thumb.js.map