UNPKG

@carbon/react

Version:

React components for the Carbon Design System

94 lines (92 loc) 3.94 kB
/** * 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 { deprecate } from "../../prop-types/deprecate.js"; import { FeatureFlags, createScope } from "@carbon/feature-flags"; import { createContext, useContext, useMemo } from "react"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; //#region src/components/FeatureFlags/index.tsx /** * Copyright IBM Corp. 2015, 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. */ /** * Our FeatureFlagContext is used alongside the FeatureFlags component to enable * or disable feature flags in a given React tree */ const FeatureFlagContext = createContext(FeatureFlags); /** * Supports an object of feature flag values with the `flags` prop, merging them * along with the current `FeatureFlagContext` to provide consumers to check if * a feature flag is enabled or disabled in a given React tree */ const FeatureFlags$1 = ({ children, flags = {}, enableV12TileDefaultIcons = false, enableV12TileRadioIcons = false, enableV12Overflowmenu = false, enableTreeviewControllable = false, enableExperimentalFocusWrapWithoutSentinels = false, enableFocusWrapWithoutSentinels = false, enableDialogElement = false, enableV12DynamicFloatingStyles = false, enableEnhancedFileUploader = false, enablePresence = false }) => { const parentScope = useContext(FeatureFlagContext); const scope = useMemo(() => { const scope = createScope({ "enable-v12-tile-default-icons": enableV12TileDefaultIcons, "enable-v12-tile-radio-icons": enableV12TileRadioIcons, "enable-v12-overflowmenu": enableV12Overflowmenu, "enable-treeview-controllable": enableTreeviewControllable, "enable-experimental-focus-wrap-without-sentinels": enableExperimentalFocusWrapWithoutSentinels, "enable-focus-wrap-without-sentinels": enableFocusWrapWithoutSentinels, "enable-dialog-element": enableDialogElement, "enable-v12-dynamic-floating-styles": enableV12DynamicFloatingStyles, "enable-enhanced-file-uploader": enableEnhancedFileUploader, "enable-presence": enablePresence, ...flags }); scope.mergeWithScope(parentScope); return scope; }, [ enableV12TileDefaultIcons, enableV12TileRadioIcons, enableV12Overflowmenu, enableTreeviewControllable, enableExperimentalFocusWrapWithoutSentinels, enableFocusWrapWithoutSentinels, enableDialogElement, enableV12DynamicFloatingStyles, enableEnhancedFileUploader, enablePresence, flags, parentScope ]); return /* @__PURE__ */ jsx(FeatureFlagContext.Provider, { value: scope, children }); }; FeatureFlags$1.propTypes = { children: PropTypes.node, flags: deprecate(PropTypes.objectOf(PropTypes.bool), "The `flags` prop for `FeatureFlag` has been deprecated. Please run the `featureflag-deprecate-flags-prop` codemod to migrate to individual boolean props.npx @carbon/upgrade migrate featureflag-deprecate-flags-prop --write"), enableV12TileDefaultIcons: PropTypes.bool, enableV12TileRadioIcons: PropTypes.bool, enableV12Overflowmenu: PropTypes.bool, enableTreeviewControllable: PropTypes.bool, enableExperimentalFocusWrapWithoutSentinels: PropTypes.bool, enableFocusWrapWithoutSentinels: PropTypes.bool, enableDialogElement: PropTypes.bool, enableV12DynamicFloatingStyles: PropTypes.bool, enableEnhancedFileUploader: PropTypes.bool, enablePresence: PropTypes.bool }; /** * Access whether a given flag is enabled or disabled in a given * FeatureFlagContext */ const useFeatureFlag = (flag) => { return useContext(FeatureFlagContext).enabled(flag); }; /** * Access all feature flag information for the given FeatureFlagContext */ const useFeatureFlags = () => useContext(FeatureFlagContext); //#endregion export { FeatureFlags$1 as FeatureFlags, useFeatureFlag, useFeatureFlags };