UNPKG

@carbon/react

Version:

React components for the Carbon Design System

52 lines (46 loc) 1.54 kB
/** * 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. */ 'use strict'; var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = require('prop-types'); var React = require('react'); var LayoutDirectionContext = require('./LayoutDirectionContext.js'); // eslint-disable-next-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452 function LayoutDirection({ as: BaseComponent = 'div', children, dir, ...rest }) { const value = React.useMemo(() => { return { direction: dir }; }, [dir]); return /*#__PURE__*/React.createElement(LayoutDirectionContext.LayoutDirectionContext.Provider, { value: value }, /*#__PURE__*/React.createElement(BaseComponent, _rollupPluginBabelHelpers.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 }; exports.LayoutDirectionContext = LayoutDirectionContext.LayoutDirectionContext; exports.LayoutDirection = LayoutDirection;