Skip to content

Commit

Permalink
task: implement DisplayMarkdown (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgimen3z committed May 30, 2024
1 parent 4b7c103 commit c61f2f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions demo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ class User(BaseModel):
name: str = Field(title='Name')
dob: date = Field(title='Date of Birth')
enabled: bool | None = None
status_markdown: str | None = Field(default=None, title='Status')


users: list[User] = [
User(id=1, name='John', dob=date(1990, 1, 1), enabled=True),
User(id=2, name='Jane', dob=date(1991, 1, 1), enabled=False),
User(id=1, name='John', dob=date(1990, 1, 1), enabled=True, status_markdown='**Active**'),
User(id=2, name='Jane', dob=date(1991, 1, 1), enabled=False, status_markdown='*Inactive*'),
User(id=3, name='Jack', dob=date(1992, 1, 1)),
]

Expand All @@ -115,6 +116,7 @@ def users_view() -> list[AnyComponent]:
DisplayLookup(field='name', on_click=GoToEvent(url='/table/users/{id}/')),
DisplayLookup(field='dob', mode=DisplayMode.date),
DisplayLookup(field='enabled'),
DisplayLookup(field='status_markdown', mode=DisplayMode.markdown),
],
),
title='Users',
Expand Down
4 changes: 2 additions & 2 deletions src/npm-fastui/src/components/display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AnyComp } from '.'

import { JsonComp } from './Json'
import { LinkRender } from './link'
import MarkdownComp from './MarkdownLazy'

export const DisplayComp: FC<Display> = (props) => {
const CustomRenderComp = useCustomRender(props)
Expand Down Expand Up @@ -206,8 +207,7 @@ const DisplayMarkdown: FC<{ value: JSONPrimitive }> = ({ value }) => {
if (value === null) {
return <DisplayNull />
} else {
// TODO
return <>{value.toString()}</>
return <MarkdownComp text={value.toString()} type="Markdown" />
}
}

Expand Down

1 comment on commit c61f2f7

@bswck
Copy link

@bswck bswck commented on c61f2f7 Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Please sign in to comment.