@carbon/react
Version:
React components for the Carbon Design System
47 lines (43 loc) • 1.27 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import PropTypes from 'prop-types';
import React from 'react';
import { LayoutDirectionContext } from './LayoutDirectionContext.js';
function LayoutDirection({
as: BaseComponent = 'div',
children,
dir,
...rest
}) {
const value = React.useMemo(() => {
return {
direction: dir
};
}, [dir]);
return /*#__PURE__*/React.createElement(LayoutDirectionContext.Provider, {
value: value
}, /*#__PURE__*/React.createElement(BaseComponent, _extends({
dir: dir
}, rest), children));
}
LayoutDirection.propTypes = {
/**
* Customize the element type used to render the outermost node
*/
as: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.elementType]),
/**
* Provide child elements or components to be rendered inside of this
* component
*/
children: PropTypes.node,
/**
* Specify the layout direction of this part of the page
*/
dir: PropTypes.oneOf(['ltr', 'rtl']).isRequired
};
export { LayoutDirection, LayoutDirectionContext };