This repository was archived by the owner on Jun 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
add FormattedText component #72
Open
alonmar
wants to merge
7
commits into
pydantic:main
Choose a base branch
from
alonmar:FormattedText-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bef4392
add FormattedText component
5f76caa
fix '|' to _t.Union[]
6c6e9a5
update text type Button & Paragraph
bc87be2
update demo FormattedText
975d48e
update Paragraph, Button & Text support just str
c96b1d6
update FormattedText.tsx
6d1c386
fix demo FormattedText
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 { FC } from 'react' | ||
|
|
||
| import { ClassName } from '../hooks/className' | ||
|
|
||
| export interface FormattedTextProps { | ||
| type: 'FormattedText' | ||
| text: string | ||
| textFormat?: 'bold' | 'italic' | 'underline' | 'strikethrough' | ||
| color?: string | ||
| backgroundColor?: string | ||
| className?: ClassName | ||
| } | ||
|
|
||
| export const FormattedTextComp: FC<FormattedTextProps> = (props) => { | ||
| const { text, textFormat, color, backgroundColor } = props | ||
|
|
||
| const style = { | ||
| backgroundColor, | ||
| color, | ||
| fontWeight: textFormat === 'bold' ? 'bold' : 'normal', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably be omitted, not |
||
| fontStyle: textFormat === 'italic' ? 'italic' : 'normal', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. |
||
| textDecoration: | ||
| textFormat === 'underline' ? 'underline' : textFormat === 'strikethrough' ? 'line-through' : 'none', | ||
| } | ||
|
|
||
| return <span style={style}>{text}</span> | ||
| } | ||
This file contains hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,7 +56,7 @@ class Text(pydantic.BaseModel, extra='forbid'): | |||||
|
|
||||||
|
|
||||||
| class Paragraph(pydantic.BaseModel, extra='forbid'): | ||||||
| text: str | ||||||
| text: '_t.List[_t.Union[str, FormattedText, Link]]' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
you need to support just Then you need to update I guess |
||||||
| type: _t.Literal['Paragraph'] = 'Paragraph' | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -114,7 +114,7 @@ class Code(pydantic.BaseModel, extra='forbid'): | |||||
|
|
||||||
|
|
||||||
| class Button(pydantic.BaseModel, extra='forbid'): | ||||||
| text: str | ||||||
| text: '_t.List[_t.Union[str, FormattedText, Link]]' | ||||||
| on_click: _t.Union[events.AnyEvent, None] = pydantic.Field(default=None, serialization_alias='onClick') | ||||||
| html_type: _t.Union[_t.Literal['button', 'submit', 'reset'], None] = pydantic.Field( | ||||||
| default=None, serialization_alias='htmlType' | ||||||
|
|
@@ -202,6 +202,17 @@ class Iframe(pydantic.BaseModel, extra='forbid'): | |||||
| type: _t.Literal['Iframe'] = 'Iframe' | ||||||
|
|
||||||
|
|
||||||
| class FormattedText(pydantic.BaseModel, extra='forbid'): | ||||||
| text: str | ||||||
| text_format: _t.Union[_t.Literal['bold', 'italic', 'underline', 'strikethrough'], None] = pydantic.Field( | ||||||
| None, serialization_alias='textFormat' | ||||||
| ) | ||||||
| # TODO, use pydantic-extra-types Color? | ||||||
| text_color: _t.Union[str, None] = pydantic.Field(None, serialization_alias='color') | ||||||
| background_color: _t.Union[str, None] = pydantic.Field(None, serialization_alias='backgroundColor') | ||||||
| type: _t.Literal['FormattedText'] = 'FormattedText' | ||||||
|
|
||||||
|
|
||||||
| AnyComponent = _te.Annotated[ | ||||||
| _t.Union[ | ||||||
| Text, | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add something like