UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

239 lines (238 loc) 9.22 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.SliderRoot = void 0; var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _useComponentRenderer = require("../../utils/useComponentRenderer"); var _CompositeList = require("../../composite/list/CompositeList"); var _DirectionContext = require("../../direction-provider/DirectionContext"); var _styleHooks = require("./styleHooks"); var _useSliderRoot = require("./useSliderRoot"); var _SliderRootContext = require("./SliderRootContext"); var _FieldRootContext = require("../../field/root/FieldRootContext"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * Groups all parts of the slider. * Renders a `<div>` element. * * Documentation: [Base UI Slider](https://base-ui.com/react/components/slider) */const SliderRoot = exports.SliderRoot = /*#__PURE__*/React.forwardRef(function SliderRoot(props, forwardedRef) { const { 'aria-labelledby': ariaLabelledby, className, defaultValue, disabled: disabledProp = false, id, format, largeStep, render, max, min, minStepsBetweenValues, name, onValueChange, onValueCommitted, orientation = 'horizontal', step, tabIndex, value, ...otherProps } = props; const direction = (0, _DirectionContext.useDirection)(); const { labelId, state: fieldState, disabled: fieldDisabled } = (0, _FieldRootContext.useFieldRootContext)(); const disabled = fieldDisabled || disabledProp; const { getRootProps, ...slider } = (0, _useSliderRoot.useSliderRoot)({ 'aria-labelledby': ariaLabelledby ?? labelId, defaultValue, direction, disabled, id, largeStep, max, min, minStepsBetweenValues, name, onValueChange, onValueCommitted, orientation, rootRef: forwardedRef, step, tabIndex, value }); const state = React.useMemo(() => ({ ...fieldState, activeThumbIndex: slider.active, disabled, dragging: slider.dragging, orientation, max: slider.max, min: slider.min, minStepsBetweenValues: slider.minStepsBetweenValues, step: slider.step, values: slider.values }), [fieldState, disabled, orientation, slider.active, slider.dragging, slider.max, slider.min, slider.minStepsBetweenValues, slider.step, slider.values]); const contextValue = React.useMemo(() => ({ ...slider, format, state }), [slider, format, state]); const { renderElement } = (0, _useComponentRenderer.useComponentRenderer)({ propGetter: getRootProps, render: render ?? 'div', state, className, extraProps: otherProps, customStyleHookMapping: _styleHooks.sliderStyleHookMapping }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderRootContext.SliderRootContext.Provider, { value: contextValue, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CompositeList.CompositeList, { elementsRef: slider.thumbRefs, children: renderElement() }) }); }); process.env.NODE_ENV !== "production" ? SliderRoot.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * Identifies the element (or elements) that labels the current element. * @see aria-describedby. */ 'aria-labelledby': _propTypes.default.string, /** * @ignore */ children: _propTypes.default.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]), /** * The uncontrolled value of the slider when it’s initially rendered. * * To render a controlled slider, use the `value` prop instead. */ defaultValue: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.number), _propTypes.default.number]), /** * Whether the component should ignore user interaction. * @default false */ disabled: _propTypes.default.bool, /** * Options to format the input value. */ format: _propTypes.default.shape({ compactDisplay: _propTypes.default.oneOf(['long', 'short']), currency: _propTypes.default.string, currencyDisplay: _propTypes.default.oneOf(['code', 'name', 'narrowSymbol', 'symbol']), currencySign: _propTypes.default.oneOf(['accounting', 'standard']), localeMatcher: _propTypes.default.oneOf(['best fit', 'lookup']), maximumFractionDigits: _propTypes.default.number, maximumSignificantDigits: _propTypes.default.number, minimumFractionDigits: _propTypes.default.number, minimumIntegerDigits: _propTypes.default.number, minimumSignificantDigits: _propTypes.default.number, notation: _propTypes.default.oneOf(['compact', 'engineering', 'scientific', 'standard']), numberingSystem: _propTypes.default.string, signDisplay: _propTypes.default.oneOf(['always', 'auto', 'exceptZero', 'never']), style: _propTypes.default.oneOf(['currency', 'decimal', 'percent', 'unit']), unit: _propTypes.default.string, unitDisplay: _propTypes.default.oneOf(['long', 'narrow', 'short']), useGrouping: _propTypes.default.bool }), /** * @ignore */ id: _propTypes.default.string, /** * The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down. * @default 10 */ largeStep: _propTypes.default.number, /** * The maximum allowed value of the slider. * Should not be equal to min. * @default 100 */ max: _propTypes.default.number, /** * The minimum allowed value of the slider. * Should not be equal to max. * @default 0 */ min: _propTypes.default.number, /** * The minimum steps between values in a range slider. * @default 0 */ minStepsBetweenValues: _propTypes.default.number, /** * Identifies the field when a form is submitted. */ name: _propTypes.default.string, /** * Callback function that is fired when the slider's value changed. * * @param {number | number[]} value The new value. * @param {Event} event The corresponding event that initiated the change. * You can pull out the new value by accessing `event.target.value` (any). * @param {number} activeThumbIndex Index of the currently moved thumb. */ onValueChange: _propTypes.default.func, /** * Callback function that is fired when the `pointerup` is triggered. * * @param {number | number[]} value The new value. * @param {Event} event The corresponding event that initiated the change. * **Warning**: This is a generic event not a change event. */ onValueCommitted: _propTypes.default.func, /** * The component orientation. * @default 'horizontal' */ orientation: _propTypes.default.oneOf(['horizontal', 'vertical']), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]), /** * The granularity with which the slider can step through values. (A "discrete" slider.) * The `min` prop serves as the origin for the valid values. * We recommend (max - min) to be evenly divisible by the step. * @default 1 */ step: _propTypes.default.number, /** * @ignore */ tabIndex: _propTypes.default.number, /** * The value of the slider. * For ranged sliders, provide an array with two values. */ value: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.number), _propTypes.default.number]) } : void 0;