UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

56 lines (48 loc) 1.64 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var PropTypes = require('prop-types'); var React = require('react'); var TextDirectionContext = require('./TextDirectionContext.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); function TextDirection(_ref) { let { children, dir = 'auto', getTextDirection } = _ref; const savedCallback = React.useRef(getTextDirection); const value = React.useMemo(() => { return { direction: dir, getTextDirection: savedCallback }; }, [dir]); React.useEffect(() => { savedCallback.current = getTextDirection; }); return /*#__PURE__*/React__default["default"].createElement(TextDirectionContext.TextDirectionContext.Provider, { value: value }, children); } TextDirection.propTypes = { /** * Provide children to be rendered inside of this component */ children: PropTypes__default["default"].node, /** * Specify the text direction for rendered children */ dir: PropTypes__default["default"].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__default["default"].func }; exports.TextDirection = TextDirection;