UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

47 lines (43 loc) 1.22 kB
/** * MSKCC 2021, 2024 */ import PropTypes from 'prop-types'; import React__default, { useRef, useMemo, useEffect } from 'react'; import { TextDirectionContext } from './TextDirectionContext.js'; function TextDirection(_ref) { let { children, dir = 'auto', getTextDirection } = _ref; const savedCallback = useRef(getTextDirection); const value = useMemo(() => { return { direction: dir, getTextDirection: savedCallback }; }, [dir]); useEffect(() => { savedCallback.current = getTextDirection; }); return /*#__PURE__*/React__default.createElement(TextDirectionContext.Provider, { value: value }, children); } TextDirection.propTypes = { /** * Provide children to be rendered inside of this component */ children: PropTypes.node, /** * Specify the text direction for rendered children */ dir: PropTypes.oneOf(['ltr', 'rtl', 'auto']), /** * Optionally provide a custom function to get the text direction for a piece * of text. Whatever is returned will become the value of the `dir` attribute * on a node of text. Should return one of: 'ltr', 'rtl', or 'auto' */ getTextDirection: PropTypes.func }; export { TextDirection };