Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(carbon-react): update to usePrefix #9728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/carbon-react/src/components/Layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix';

export function Layer({
as: BaseComponent = 'div',
className: customClassName,
children,
...rest
}) {
const className = cx('bx--layer', customClassName);
const prefix = usePrefix();
const className = cx(`${prefix}--layer`, customClassName);
return (
<BaseComponent {...rest} className={className}>
{children}
Expand Down
10 changes: 6 additions & 4 deletions packages/carbon-react/src/components/Theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions packages/carbon-react/src/internal/usePrefix.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -8863,5 +8863,6 @@ Map {
},
},
},
"unstable_usePrefix" => Object {},
}
`;
1 change: 1 addition & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Array [
"unstable_useContextMenu",
"unstable_useFeatureFlag",
"unstable_useFeatureFlags",
"unstable_usePrefix",
]
`);
});
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';