-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a12f175
commit 2c34420
Showing
6 changed files
with
278 additions
and
140 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import type { FC } from 'react'; | ||
import { createElement, forwardRef } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { css } from '@emotion/css'; | ||
import { nl2br } from '../nl2br'; | ||
import type { TextProps } from './TextProps'; | ||
import { interpolation, shouldForwardProp } from './TextProps'; | ||
|
||
export const Text: FC<TextProps> = styled( | ||
forwardRef<unknown, TextProps>(({ as = 'span', children, ...restProps }, ref) => | ||
createElement(as, { | ||
ref, | ||
children: typeof children === 'string' ? nl2br(children) : children, | ||
...restProps, | ||
}) | ||
), | ||
{ | ||
shouldForwardProp, | ||
} | ||
)(interpolation); | ||
export const Text: FC<TextProps> = forwardRef<unknown, TextProps>(({ as = 'span', children, ...restProps }, ref) => { | ||
const className = Object.entries(interpolation({ ...restProps } ?? {})) | ||
.map(([key, value]) => css({ [key]: value })) | ||
.join(' '); | ||
|
||
const domAttributeProps = Object.fromEntries( | ||
Object.entries({ ...restProps }).filter(([key, _]) => shouldForwardProp(key)) | ||
); | ||
|
||
return createElement(as, { | ||
ref, | ||
children: typeof children === 'string' ? nl2br(children) : children, | ||
domAttributeProps, | ||
className, | ||
}); | ||
}); | ||
(Text as FC).displayName = 'Text'; |
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
Oops, something went wrong.