File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed
python-fastui/fastui/components Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ export const DisplayPrimitive: FC<DisplayPrimitiveProps> = (props) => {
135135 case 'json' :
136136 case 'inline_code' :
137137 return < DisplayInlineCode value = { value } />
138+ case 'currency' :
139+ return < DisplayCurrency value = { value } />
138140 default :
139141 unreachable ( 'Unexpected display type' , mode , props )
140142 }
@@ -219,6 +221,18 @@ const DisplayInlineCode: FC<{ value: JSONPrimitive }> = ({ value }) => {
219221 }
220222}
221223
224+ const DisplayCurrency : FC < { value : JSONPrimitive } > = ( { value } ) => {
225+ if ( typeof value === 'boolean' ) {
226+ return value . toString ( )
227+ } else if ( value === null ) {
228+ return < DisplayNull />
229+ } else {
230+ return Intl . NumberFormat ( 'en-US' , { style : 'currency' , currency : 'USD' } ) . format (
231+ typeof value === 'string' ? parseFloat ( value ) : value ,
232+ )
233+ }
234+ }
235+
222236export type DataModel = Record < string , JsonData >
223237
224238export interface DisplayLookupProps extends Omit < Display , 'type' | 'value' > {
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export type DisplayMode =
7171 | 'markdown'
7272 | 'json'
7373 | 'inline_code'
74+ | 'currency'
7475export type SelectOptions = SelectOption [ ] | SelectGroup [ ]
7576
7677/**
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class DisplayMode(str, enum.Enum):
2727 markdown = 'markdown'
2828 json = 'json'
2929 inline_code = 'inline_code'
30+ currency = 'currency'
3031
3132
3233class DisplayBase (BaseModel , ABC , defer_build = True ):
You can’t perform that action at this time.
0 commit comments