diff --git a/packages/carbon-react/src/components/Layer/index.js b/packages/carbon-react/src/components/Layer/index.js index 688fa0990e20..d78280c1fe07 100644 --- a/packages/carbon-react/src/components/Layer/index.js +++ b/packages/carbon-react/src/components/Layer/index.js @@ -8,6 +8,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; +import { usePrefix } from '../../internal/usePrefix'; export function Layer({ as: BaseComponent = 'div', @@ -15,7 +16,8 @@ export function Layer({ children, ...rest }) { - const className = cx('bx--layer', customClassName); + const prefix = usePrefix(); + const className = cx(`${prefix}--layer`, customClassName); return ( {children} diff --git a/packages/carbon-react/src/components/Theme/index.js b/packages/carbon-react/src/components/Theme/index.js index dcbad8be4aae..68d7ae9a9157 100644 --- a/packages/carbon-react/src/components/Theme/index.js +++ b/packages/carbon-react/src/components/Theme/index.js @@ -8,6 +8,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; +import { usePrefix } from '../../internal/usePrefix'; const ThemeContext = React.createContext({ theme: 'white', @@ -23,11 +24,12 @@ export function Theme({ theme, ...rest }) { + const prefix = usePrefix(); const className = cx(customClassName, { - 'bx--white': theme === 'white', - 'bx--g10': theme === 'g10', - 'bx--g90': theme === 'g90', - 'bx--g100': theme === 'g100', + [`${prefix}--white`]: theme === 'white', + [`${prefix}--g10`]: theme === 'g10', + [`${prefix}--g90`]: theme === 'g90', + [`${prefix}--g100`]: theme === 'g100', }); const value = React.useMemo(() => { return { diff --git a/packages/carbon-react/src/internal/usePrefix.js b/packages/carbon-react/src/internal/usePrefix.js new file mode 100644 index 000000000000..54906b16cc06 --- /dev/null +++ b/packages/carbon-react/src/internal/usePrefix.js @@ -0,0 +1,10 @@ +/** + * Copyright IBM Corp. 2016, 2018 + * + * 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 { unstable_usePrefix } from 'carbon-components-react'; + +export const usePrefix = unstable_usePrefix; diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 6c6f926cb8af..39f8f6b54ee3 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -8863,5 +8863,6 @@ Map { }, }, }, + "unstable_usePrefix" => Object {}, } `; diff --git a/packages/react/src/__tests__/index-test.js b/packages/react/src/__tests__/index-test.js index 8b2cdc6a1b55..83249b451aac 100644 --- a/packages/react/src/__tests__/index-test.js +++ b/packages/react/src/__tests__/index-test.js @@ -215,6 +215,7 @@ Array [ "unstable_useContextMenu", "unstable_useFeatureFlag", "unstable_useFeatureFlags", + "unstable_usePrefix", ] `); }); diff --git a/packages/react/src/index.js b/packages/react/src/index.js index 360d25535f94..efff07203742 100644 --- a/packages/react/src/index.js +++ b/packages/react/src/index.js @@ -230,3 +230,4 @@ export { Section as unstable_Section, } from './components/Heading'; export { default as unstable_ProgressBar } from './components/ProgressBar'; +export { usePrefix as unstable_usePrefix } from './internal/usePrefix';