@carbon/react
Version:
React components for the Carbon Design System
46 lines (44 loc) • 1.2 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 { TextDirectionContext } from "./TextDirectionContext.js";
import { useEffect, useMemo, useRef } from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/Text/TextDirection.tsx
/**
* 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.
*/
const TextDirection = ({ children, dir = "auto", getTextDirection }) => {
const savedCallback = useRef(getTextDirection);
const value = useMemo(() => {
return {
direction: dir,
getTextDirection: savedCallback
};
}, [dir]);
useEffect(() => {
savedCallback.current = getTextDirection;
}, [getTextDirection]);
return /* @__PURE__ */ jsx(TextDirectionContext.Provider, {
value,
children
});
};
TextDirection.propTypes = {
children: PropTypes.node,
dir: PropTypes.oneOf([
"ltr",
"rtl",
"auto"
]),
getTextDirection: PropTypes.func
};
//#endregion
export { TextDirection };