@carbon/react
Version:
React components for the Carbon Design System
61 lines (53 loc) • 1.88 kB
JavaScript
/**
* 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.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var PropTypes = require('prop-types');
var React = require('react');
require('./index.js');
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);
const TextDirection = ({
children,
dir = 'auto',
getTextDirection
}) => {
const savedCallback = React.useRef(getTextDirection);
const value = React.useMemo(() => {
return {
direction: dir,
getTextDirection: savedCallback
};
}, [dir]);
React.useEffect(() => {
savedCallback.current = getTextDirection;
// TODO: Is this `useEffect` supposed to have a dependency on
// `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;