@carbon/react
Version:
React components for the Carbon Design System
43 lines (41 loc) • 1.16 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* 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 { LayoutDirectionContext } from "./LayoutDirectionContext.js";
import React from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/LayoutDirection/LayoutDirection.tsx
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
function LayoutDirection({ as: BaseComponent = "div", children, dir, ...rest }) {
const value = React.useMemo(() => {
return { direction: dir };
}, [dir]);
return /* @__PURE__ */ jsx(LayoutDirectionContext.Provider, {
value,
children: /* @__PURE__ */ jsx(BaseComponent, {
dir,
...rest,
children
})
});
}
LayoutDirection.propTypes = {
as: PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.elementType
]),
children: PropTypes.node,
dir: PropTypes.oneOf(["ltr", "rtl"]).isRequired
};
//#endregion
export { LayoutDirection };