Skip to content

Commit 2c43b12

Browse files
fix(carbon-react): update to usePrefix (#9728)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 3dd237d commit 2c43b12

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

packages/carbon-react/src/components/Layer/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import React from 'react';
99
import PropTypes from 'prop-types';
1010
import cx from 'classnames';
11+
import { usePrefix } from '../../internal/usePrefix';
1112

1213
export function Layer({
1314
as: BaseComponent = 'div',
1415
className: customClassName,
1516
children,
1617
...rest
1718
}) {
18-
const className = cx('bx--layer', customClassName);
19+
const prefix = usePrefix();
20+
const className = cx(`${prefix}--layer`, customClassName);
1921
return (
2022
<BaseComponent {...rest} className={className}>
2123
{children}

packages/carbon-react/src/components/Theme/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import React from 'react';
99
import PropTypes from 'prop-types';
1010
import cx from 'classnames';
11+
import { usePrefix } from '../../internal/usePrefix';
1112

1213
const ThemeContext = React.createContext({
1314
theme: 'white',
@@ -23,11 +24,12 @@ export function Theme({
2324
theme,
2425
...rest
2526
}) {
27+
const prefix = usePrefix();
2628
const className = cx(customClassName, {
27-
'bx--white': theme === 'white',
28-
'bx--g10': theme === 'g10',
29-
'bx--g90': theme === 'g90',
30-
'bx--g100': theme === 'g100',
29+
[`${prefix}--white`]: theme === 'white',
30+
[`${prefix}--g10`]: theme === 'g10',
31+
[`${prefix}--g90`]: theme === 'g90',
32+
[`${prefix}--g100`]: theme === 'g100',
3133
});
3234
const value = React.useMemo(() => {
3335
return {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { unstable_usePrefix } from 'carbon-components-react';
9+
10+
export const usePrefix = unstable_usePrefix;

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8863,5 +8863,6 @@ Map {
88638863
},
88648864
},
88658865
},
8866+
"unstable_usePrefix" => Object {},
88668867
}
88678868
`;

packages/react/src/__tests__/index-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Array [
215215
"unstable_useContextMenu",
216216
"unstable_useFeatureFlag",
217217
"unstable_useFeatureFlags",
218+
"unstable_usePrefix",
218219
]
219220
`);
220221
});

packages/react/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,4 @@ export {
230230
Section as unstable_Section,
231231
} from './components/Heading';
232232
export { default as unstable_ProgressBar } from './components/ProgressBar';
233+
export { usePrefix as unstable_usePrefix } from './internal/usePrefix';

0 commit comments

Comments
 (0)