@carbon/react
Version:
React components for the Carbon Design System
78 lines (76 loc) • 3.63 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { usePrefix } from "../../internal/usePrefix.js";
import useIsomorphicEffect from "../../internal/useIsomorphicEffect.js";
import { LowerHandle, UpperHandle } from "./SliderHandles.js";
import classNames from "classnames";
import { useState } from "react";
import PropTypes from "prop-types";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/components/Slider/Slider.Skeleton.tsx
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const SliderSkeleton = ({ ariaLabel = "slider handle", unstable_ariaLabelHandleUpper: ariaLabelHandleUpper = "upper slider handle", hideLabel, className, twoHandles, ...rest }) => {
const prefix = usePrefix();
const [isRtl, setIsRtl] = useState(false);
useIsomorphicEffect(() => {
setIsRtl(document ? document.dir === "rtl" : false);
}, []);
const containerClasses = classNames(`${prefix}--slider-container`, `${prefix}--skeleton`, {
[`${prefix}--slider-container--two-handles`]: twoHandles,
[`${prefix}--slider-container--rtl`]: isRtl
});
const lowerThumbClasses = classNames(`${prefix}--slider__thumb`, { [`${prefix}--slider__thumb--lower`]: twoHandles });
const upperThumbClasses = classNames(`${prefix}--slider__thumb`, { [`${prefix}--slider__thumb--upper`]: twoHandles });
const lowerThumbWrapperClasses = classNames(`${prefix}--slider__thumb-wrapper`, { [`${prefix}--slider__thumb-wrapper--lower`]: twoHandles });
const upperThumbWrapperClasses = classNames(`${prefix}--slider__thumb-wrapper`, { [`${prefix}--slider__thumb-wrapper--upper`]: twoHandles });
return /* @__PURE__ */ jsxs("div", {
className: classNames(`${prefix}--form-item`, className),
...rest,
children: [!hideLabel && /* @__PURE__ */ jsx("span", { className: `${prefix}--label ${prefix}--skeleton` }), /* @__PURE__ */ jsxs("div", {
className: containerClasses,
children: [
/* @__PURE__ */ jsx("span", { className: `${prefix}--slider__range-label` }),
/* @__PURE__ */ jsxs("div", {
className: `${prefix}--slider`,
children: [
/* @__PURE__ */ jsx("div", { className: `${prefix}--slider__track` }),
/* @__PURE__ */ jsx("div", { className: `${prefix}--slider__filled-track` }),
/* @__PURE__ */ jsx("div", {
className: lowerThumbWrapperClasses,
children: /* @__PURE__ */ jsx("div", {
className: lowerThumbClasses,
children: twoHandles && !isRtl ? /* @__PURE__ */ jsx(LowerHandle, { "aria-label": ariaLabel }) : twoHandles && isRtl ? /* @__PURE__ */ jsx(UpperHandle, { "aria-label": ariaLabelHandleUpper }) : void 0
})
}),
twoHandles ? /* @__PURE__ */ jsx("div", {
className: upperThumbWrapperClasses,
children: /* @__PURE__ */ jsx("div", {
className: upperThumbClasses,
children: twoHandles && !isRtl ? /* @__PURE__ */ jsx(UpperHandle, { "aria-label": ariaLabelHandleUpper }) : twoHandles && isRtl ? /* @__PURE__ */ jsx(LowerHandle, { "aria-label": ariaLabel }) : void 0
})
}) : void 0
]
}),
/* @__PURE__ */ jsx("span", { className: `${prefix}--slider__range-label` })
]
})]
});
};
SliderSkeleton.propTypes = {
ariaLabel: PropTypes.string,
unstable_ariaLabelHandleUpper: PropTypes.string,
className: PropTypes.string,
hideLabel: PropTypes.bool,
twoHandles: PropTypes.bool
};
//#endregion
export { SliderSkeleton as default };