-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏷️ [#445] Convert the Body component and stories to TS
Turns out we need the babel presets after all for the storybook processing :( I'm not sure why things work without in the renderer repo, but we'll figure it out at some point. This strongly types the Body component with its 'component' prop, allowing strings of intrinsic elements to be passed. Support for custom react components is dropped, as it doesn't appear to be used anywhere so this simplifies things a bit.
- Loading branch information
1 parent
7ab6f23
commit 43e5063
Showing
8 changed files
with
328 additions
and
82 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {getBEMClassName} from 'utils'; | ||
|
||
export const VARIANTS = ['big', 'muted', 'small', 'wysiwyg', 'inline'] as const; | ||
export type Variant = (typeof VARIANTS)[number]; | ||
|
||
export type BodyProps<T extends React.ElementType = 'p'> = { | ||
children?: React.ReactNode; | ||
component?: T; | ||
modifiers?: Variant[]; | ||
} & React.ComponentPropsWithoutRef<T>; | ||
|
||
const Body = <T extends React.ElementType = 'p'>({ | ||
modifiers = [], | ||
component, | ||
children, | ||
...props | ||
}: BodyProps<T>) => { | ||
const Component = component || 'p'; | ||
const className = getBEMClassName('body', modifiers); | ||
return ( | ||
<Component className={className} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
}; | ||
|
||
export default Body; |