Skip to content

Commit

Permalink
feat(react): export usePrefix and add story (#11615)
Browse files Browse the repository at this point in the history
* feat(react): export usePrefix and add story

* chore(react): fix typo
  • Loading branch information
abbeyhrt committed Jun 14, 2022
1 parent 45c41b7 commit c99af17
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8710,6 +8710,7 @@ Map {
"unstable_useContextMenu" => Object {},
"unstable_useFeatureFlag" => Object {},
"unstable_useFeatureFlags" => Object {},
"usePrefix" => Object {},
"useTheme" => 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 @@ -230,6 +230,7 @@ describe('Carbon Components React', () => {
"unstable_useContextMenu",
"unstable_useFeatureFlag",
"unstable_useFeatureFlags",
"usePrefix",
"useTheme",
]
`);
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 @@ -237,3 +237,4 @@ export unstable_TreeView, {
} from './components/TreeView';
export { TabPanel, TabPanels, TabList, IconTab } from './components/Tabs';
export { GlobalTheme, Theme, useTheme } from './components/Theme';
export { usePrefix } from './internal/usePrefix';
34 changes: 34 additions & 0 deletions packages/react/src/internal/usePrefix.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { usePrefix } from './usePrefix';
import { Meta } from '@storybook/addon-docs';

<Meta title="Hooks/usePrefix" component={usePrefix} />

# usePrefix

[Source code](https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/internal/usePrefix.js)

## Overview

A hook that returns the prefix used in our classes.

## Examples

```js
import { usePrefix } from '@carbon/react';

function ExampleComponent() {
const prefix = usePrefix();
}
```

Typically, `usePrefix` will be used alongside `classnames`.

```js
import { usePrefix } from '@carbon/react';
import { cx } from 'classnames';

function ExampleComponent() {
const prefix = usePrefix();
const className = cx(`${prefix}--custom-component`);
}
```

0 comments on commit c99af17

Please sign in to comment.