File tree 3 files changed +16
-0
lines changed
python-fastui/fastui/components
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) => {
135
135
case 'json' :
136
136
case 'inline_code' :
137
137
return < DisplayInlineCode value = { value } />
138
+ case 'currency' :
139
+ return < DisplayCurrency value = { value } />
138
140
default :
139
141
unreachable ( 'Unexpected display type' , mode , props )
140
142
}
@@ -219,6 +221,18 @@ const DisplayInlineCode: FC<{ value: JSONPrimitive }> = ({ value }) => {
219
221
}
220
222
}
221
223
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
+
222
236
export type DataModel = Record < string , JsonData >
223
237
224
238
export interface DisplayLookupProps extends Omit < Display , 'type' | 'value' > {
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export type DisplayMode =
71
71
| 'markdown'
72
72
| 'json'
73
73
| 'inline_code'
74
+ | 'currency'
74
75
export type SelectOptions = SelectOption [ ] | SelectGroup [ ]
75
76
76
77
/**
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class DisplayMode(str, enum.Enum):
27
27
markdown = 'markdown'
28
28
json = 'json'
29
29
inline_code = 'inline_code'
30
+ currency = 'currency'
30
31
31
32
32
33
class DisplayBase (BaseModel , ABC , defer_build = True ):
You can’t perform that action at this time.
0 commit comments