forked from openai/chatkit-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.py
More file actions
1044 lines (859 loc) · 37.9 KB
/
Copy pathwidgets.py
File metadata and controls
1044 lines (859 loc) · 37.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from datetime import datetime
from typing import (
Annotated,
Literal,
)
from pydantic import (
BaseModel,
ConfigDict,
Field,
model_serializer,
)
from typing_extensions import NotRequired, TypedDict
from .actions import ActionConfig
from .icons import IconName
class ThemeColor(TypedDict):
"""Color values for light and dark themes."""
dark: str
"""Color to use when the theme is dark."""
light: str
"""Color to use when the theme is light."""
class Spacing(TypedDict):
"""Shorthand spacing values applied to a widget."""
top: NotRequired[float | str]
"""Top spacing; accepts a spacing unit or CSS string."""
right: NotRequired[float | str]
"""Right spacing; accepts a spacing unit or CSS string."""
bottom: NotRequired[float | str]
"""Bottom spacing; accepts a spacing unit or CSS string."""
left: NotRequired[float | str]
"""Left spacing; accepts a spacing unit or CSS string."""
x: NotRequired[float | str]
"""Horizontal spacing; accepts a spacing unit or CSS string."""
y: NotRequired[float | str]
"""Vertical spacing; accepts a spacing unit or CSS string."""
class Border(TypedDict):
"""Border style definition for an edge."""
size: int
"""Thickness of the border in px."""
color: NotRequired[str | ThemeColor]
"""Border color; accepts border color token, a primitive color token, a CSS string, or theme-aware `{ light, dark }`.
Valid tokens: `default` `subtle` `strong`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
style: NotRequired[
Literal[
"solid", "dashed", "dotted", "double", "groove", "ridge", "inset", "outset"
]
]
"""Border line style."""
class Borders(TypedDict):
"""Composite border configuration applied across edges."""
top: NotRequired[int | Border]
"""Top border or thickness in px."""
right: NotRequired[int | Border]
"""Right border or thickness in px."""
bottom: NotRequired[int | Border]
"""Bottom border or thickness in px."""
left: NotRequired[int | Border]
"""Left border or thickness in px."""
x: NotRequired[int | Border]
"""Horizontal borders or thickness in px."""
y: NotRequired[int | Border]
"""Vertical borders or thickness in px."""
class MinMax(TypedDict):
"""Integer minimum/maximum bounds."""
min: NotRequired[int]
"""Minimum value (inclusive)."""
max: NotRequired[int]
"""Maximum value (inclusive)."""
class EditableProps(TypedDict):
"""Editable field options for text widgets."""
name: str
"""The name of the form control field used when submitting forms."""
autoFocus: NotRequired[bool]
"""Autofocus the editable input when it appears."""
autoSelect: NotRequired[bool]
"""Select all text on focus."""
autoComplete: NotRequired[str]
"""Native autocomplete hint for the input."""
allowAutofillExtensions: NotRequired[bool]
"""Allow browser password/autofill extensions."""
pattern: NotRequired[str]
"""Regex pattern for input validation."""
placeholder: NotRequired[str]
"""Placeholder text for the editable input."""
required: NotRequired[bool]
"""Mark the editable input as required."""
RadiusValue = Literal[
"2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl", "4xl", "full", "100%", "none"
]
"""Allowed corner radius tokens."""
TextAlign = Literal["start", "center", "end"]
"""Horizontal text alignment options."""
TextSize = Literal["xs", "sm", "md", "lg", "xl"]
"""Body text size tokens."""
IconSize = Literal["xs", "sm", "md", "lg", "xl", "2xl", "3xl"]
"""Icon size tokens."""
TitleSize = Literal["sm", "md", "lg", "xl", "2xl", "3xl", "4xl", "5xl"]
"""Title text size tokens."""
CaptionSize = Literal["sm", "md", "lg"]
"""Caption text size tokens."""
Alignment = Literal["start", "center", "end", "baseline", "stretch"]
"""Flexbox alignment options."""
Justification = Literal[
"start", "center", "end", "between", "around", "evenly", "stretch"
]
"""Flexbox justification options."""
ControlVariant = Literal["solid", "soft", "outline", "ghost"]
"""Button and input style variants."""
ControlSize = Literal["3xs", "2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"]
"""Button and input size variants."""
def _drop_none(x):
"""Recursively remove ``None`` values when serializing widgets."""
if isinstance(x, dict):
return {
k: _drop_none(v) for k, v in x.items() if k == "children" or v is not None
}
if isinstance(x, list):
return [_drop_none(v) for v in x if v is not None]
return x
class WidgetComponentBase(BaseModel):
"""Base Pydantic model for all ChatKit widget components."""
model_config = ConfigDict(serialize_by_alias=True)
key: str | None = None
id: str | None = None
type: str = Field(...)
# For nested model dumps (e.g. if Widget is not the top-level model)
@model_serializer(mode="wrap")
def serialize(self, next_):
dumped = next_(self)
# Recursively filter out None values when serialized.
# Do this explicitly instead of overriding model_dump_json and model_dump;
# the overrides will not be invoked unless the widget is the top-level model.
dumped = _drop_none(dumped)
# include type even when exlude_defaults is True
if isinstance(dumped, dict):
dumped["type"] = self.type
return dumped
class WidgetStatusWithFavicon(TypedDict):
"""Widget status representation using a favicon."""
text: str
"""Status text to display."""
favicon: NotRequired[str]
"""URL of a favicon to render at the start of the status."""
frame: NotRequired[bool]
"""Show a frame around the favicon for contrast."""
class WidgetStatusWithIcon(TypedDict):
"""Widget status representation using an icon."""
text: str
"""Status text to display."""
icon: NotRequired[WidgetIcon]
"""Icon to render at the start of the status."""
WidgetStatus = WidgetStatusWithFavicon | WidgetStatusWithIcon
"""Union for representing widget status messaging."""
class ListViewItem(WidgetComponentBase):
"""Single row inside a ``ListView`` component."""
type: Literal["ListViewItem"] = Field(default="ListViewItem", frozen=True) # pyright: ignore
children: list["WidgetComponent"]
"""Content for the list item."""
onClickAction: ActionConfig | None = None
"""Optional action triggered when the list item is clicked."""
gap: int | str | None = None
"""Gap between children within the list item; spacing unit or CSS string."""
align: Alignment | None = None
"""Y-axis alignment for content within the list item."""
class ListView(WidgetComponentBase):
"""Container component for rendering collections of list items."""
type: Literal["ListView"] = Field(default="ListView", frozen=True) # pyright: ignore
children: list[ListViewItem]
"""Items to render in the list."""
limit: int | Literal["auto"] | None = None
"""Max number of items to show before a "Show more" control."""
status: WidgetStatus | None = None
"""Optional status header displayed above the list."""
theme: Literal["light", "dark"] | None = None
"""Force light or dark theme for this subtree."""
class CardAction(TypedDict):
"""Configuration for confirm/cancel actions within a card."""
label: str
"""Button label shown in the card footer."""
action: ActionConfig
"""Declarative action dispatched to the host application."""
class Card(WidgetComponentBase):
"""Versatile container used for structuring widget content."""
type: Literal["Card"] = Field(default="Card", frozen=True) # pyright: ignore
asForm: bool | None = None
"""Treat the card as an HTML form so confirm/cancel capture form data."""
children: list["WidgetComponent"]
"""Child components rendered inside the card."""
background: str | ThemeColor | None = None
"""Background color; accepts background color token, a primitive color token, a CSS string, or theme-aware `{ light, dark }`.
Valid tokens: `surface` `surface-secondary` `surface-tertiary` `surface-elevated` `surface-elevated-secondary`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
size: Literal["sm", "md", "lg", "full"] | None = None
"""Visual size of the card; accepts a size token. No preset default is documented."""
padding: float | str | Spacing | None = None
"""Inner spacing of the card; spacing unit, CSS string, or padding object."""
status: WidgetStatus | None = None
"""Optional status header displayed above the card."""
collapsed: bool | None = None
"""Collapse card body after the main action has completed."""
confirm: CardAction | None = None
"""Confirmation action button shown in the card footer."""
cancel: CardAction | None = None
"""Cancel action button shown in the card footer."""
theme: Literal["light", "dark"] | None = None
"""Force light or dark theme for this subtree."""
class Markdown(WidgetComponentBase):
"""Widget rendering Markdown content, optionally streamed."""
type: Literal["Markdown"] = Field(default="Markdown", frozen=True) # pyright: ignore
value: str
"""Markdown source string to render."""
streaming: bool | None = None
"""Applies streaming-friendly transitions for incremental updates."""
class Text(WidgetComponentBase):
"""Widget rendering plain text with typography controls."""
type: Literal["Text"] = Field(default="Text", frozen=True) # pyright: ignore
value: str
"""Text content to display."""
streaming: bool | None = None
"""Enables streaming-friendly transitions for incremental updates."""
italic: bool | None = None
"""Render text in italic style."""
lineThrough: bool | None = None
"""Render text with a line-through decoration."""
color: str | ThemeColor | None = None
"""
Text color; accepts a text color token, a primitive color token, a CSS color string, or a theme-aware `{ light, dark }`.
Text color tokens: `prose` `primary` `emphasis` `secondary` `tertiary` `success` `warning` `danger`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
weight: Literal["normal", "medium", "semibold", "bold"] | None = None
"""Font weight; accepts a font weight token."""
width: float | str | None = None
"""Constrain the text container width; px or CSS string."""
size: TextSize | None = None
"""Size of the text; accepts a text size token."""
textAlign: TextAlign | None = None
"""Horizontal text alignment."""
truncate: bool | None = None
"""Truncate overflow with ellipsis."""
minLines: int | None = None
"""Reserve space for a minimum number of lines."""
maxLines: int | None = None
"""Limit text to a maximum number of lines (line clamp)."""
editable: Literal[False] | EditableProps | None = None
"""Enable inline editing for this text node."""
class Title(WidgetComponentBase):
"""Widget rendering prominent headline text."""
type: Literal["Title"] = Field(default="Title", frozen=True) # pyright: ignore
value: str
"""Text content to display."""
color: str | ThemeColor | None = None
"""
Text color; accepts a text color token, a primitive color token, a CSS color string, or a theme-aware `{ light, dark }`.
Text color tokens: `prose` `primary` `emphasis` `secondary` `tertiary` `success` `warning` `danger`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
weight: Literal["normal", "medium", "semibold", "bold"] | None = None
"""Font weight; accepts a font weight token."""
size: TitleSize | None = None
"""Size of the title text; accepts a title size token."""
textAlign: TextAlign | None = None
"""Horizontal text alignment."""
truncate: bool | None = None
"""Truncate overflow with ellipsis."""
maxLines: int | None = None
"""Limit text to a maximum number of lines (line clamp)."""
class Caption(WidgetComponentBase):
"""Widget rendering supporting caption text."""
type: Literal["Caption"] = Field(default="Caption", frozen=True) # pyright: ignore
value: str
"""Text content to display."""
color: str | ThemeColor | None = None
"""
Text color; accepts a text color token, a primitive color token, a CSS color string, or a theme-aware `{ light, dark }`.
Text color tokens: `prose` `primary` `emphasis` `secondary` `tertiary` `success` `warning` `danger`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
weight: Literal["normal", "medium", "semibold", "bold"] | None = None
"""Font weight; accepts a font weight token."""
size: CaptionSize | None = None
"""Size of the caption text; accepts a caption size token."""
textAlign: TextAlign | None = None
"""Horizontal text alignment."""
truncate: bool | None = None
"""Truncate overflow with ellipsis."""
maxLines: int | None = None
"""Limit text to a maximum number of lines (line clamp)."""
class Badge(WidgetComponentBase):
"""Small badge indicating status or categorization."""
type: Literal["Badge"] = Field(default="Badge", frozen=True) # pyright: ignore
label: str
"""Text to display inside the badge."""
color: (
Literal["secondary", "success", "danger", "warning", "info", "discovery"] | None
) = None
"""Color of the badge; accepts a badge color token."""
variant: Literal["solid", "soft", "outline"] | None = None
"""Visual style of the badge."""
size: Literal["sm", "md", "lg"] | None = None
"""Size of the badge."""
pill: bool | None = None
"""Determines if the badge should be fully rounded (pill)."""
class BoxBase(BaseModel):
"""Shared layout props for flexible container widgets."""
children: list["WidgetComponent"] | None = None
"""Child components to render inside the container."""
align: Alignment | None = None
"""Cross-axis alignment of children."""
justify: Justification | None = None
"""Main-axis distribution of children."""
wrap: Literal["nowrap", "wrap", "wrap-reverse"] | None = None
"""Wrap behavior for flex items."""
flex: int | str | None = None
"""Flex growth/shrink factor."""
gap: int | str | None = None
"""Gap between direct children; spacing unit or CSS string."""
height: float | str | None = None
"""Explicit height; px or CSS string."""
width: float | str | None = None
"""Explicit width; px or CSS string."""
size: float | str | None = None
"""Shorthand to set both width and height; px or CSS string."""
minHeight: int | str | None = None
"""Minimum height; px or CSS string."""
minWidth: int | str | None = None
"""Minimum width; px or CSS string."""
minSize: int | str | None = None
"""Shorthand to set both minWidth and minHeight; px or CSS string."""
maxHeight: int | str | None = None
"""Maximum height; px or CSS string."""
maxWidth: int | str | None = None
"""Maximum width; px or CSS string."""
maxSize: int | str | None = None
"""Shorthand to set both maxWidth and maxHeight; px or CSS string."""
padding: float | str | Spacing | None = None
"""Inner padding; spacing unit, CSS string, or padding object."""
margin: float | str | Spacing | None = None
"""Outer margin; spacing unit, CSS string, or margin object."""
border: int | Border | Borders | None = None
"""Border applied to the container; px or border object/shorthand."""
radius: RadiusValue | None = None
"""Border radius; accepts a radius token."""
background: str | ThemeColor | None = None
"""Background color; accepts background color token, a primitive color token, a CSS string, or theme-aware `{ light, dark }`.
Valid tokens: `surface` `surface-secondary` `surface-tertiary` `surface-elevated` `surface-elevated-secondary`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
aspectRatio: float | str | None = None
"""Aspect ratio of the box (e.g., 16/9); number or CSS string."""
class Box(WidgetComponentBase, BoxBase):
"""Generic flex container with direction control."""
type: Literal["Box"] = Field(default="Box", frozen=True) # pyright: ignore
direction: Literal["row", "col"] | None = None
"""Flex direction for content within this container."""
class Row(WidgetComponentBase, BoxBase):
"""Horizontal flex container."""
type: Literal["Row"] = Field(default="Row", frozen=True) # pyright: ignore
class Col(WidgetComponentBase, BoxBase):
"""Vertical flex container."""
type: Literal["Col"] = Field(default="Col", frozen=True) # pyright: ignore
class Form(WidgetComponentBase, BoxBase):
"""Form wrapper capable of submitting ``onSubmitAction``."""
type: Literal["Form"] = Field(default="Form", frozen=True) # pyright: ignore
onSubmitAction: ActionConfig | None = None
"""Action dispatched when the form is submitted."""
direction: Literal["row", "col"] | None = None
"""Flex direction for laying out form children."""
class Divider(WidgetComponentBase):
"""Visual divider separating content sections."""
type: Literal["Divider"] = Field(default="Divider", frozen=True) # pyright: ignore
color: str | ThemeColor | None = None
"""Divider color; accepts border color token, a primitive color token, a CSS string, or theme-aware `{ light, dark }`.
Valid tokens: `default` `subtle` `strong`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
size: int | str | None = None
"""Thickness of the divider line; px or CSS string."""
spacing: int | str | None = None
"""Outer spacing above and below the divider; spacing unit or CSS string."""
flush: bool | None = None
"""Flush the divider to the container edge, removing surrounding padding."""
class Icon(WidgetComponentBase):
"""Icon component referencing a built-in icon name."""
type: Literal["Icon"] = Field(default="Icon", frozen=True) # pyright: ignore
name: WidgetIcon
"""Name of the icon to display."""
color: str | ThemeColor | None = None
"""
Icon color; accepts a text color token, a primitive color token, a CSS color string, or a theme-aware `{ light, dark }`.
Text color tokens: `prose` `primary` `emphasis` `secondary` `tertiary` `success` `warning` `danger`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
size: IconSize | None = None
"""Size of the icon; accepts an icon size token."""
class Image(WidgetComponentBase):
"""Image component with sizing and fitting controls."""
type: Literal["Image"] = Field(default="Image", frozen=True) # pyright: ignore
src: str
"""Image URL source."""
alt: str | None = None
"""Alternate text for accessibility."""
fit: Literal["cover", "contain", "fill", "scale-down", "none"] | None = None
"""How the image should fit within the container."""
position: (
Literal[
"top left",
"top",
"top right",
"left",
"center",
"right",
"bottom left",
"bottom",
"bottom right",
]
| None
) = None
"""Focal position of the image within the container."""
radius: RadiusValue | None = None
"""Border radius; accepts a radius token."""
frame: bool | None = None
"""Draw a subtle frame around the image."""
flush: bool | None = None
"""Flush the image to the container edge, removing surrounding padding."""
height: int | str | None = None
"""Explicit height; px or CSS string."""
width: int | str | None = None
"""Explicit width; px or CSS string."""
size: int | str | None = None
"""Shorthand to set both width and height; px or CSS string."""
minHeight: int | str | None = None
"""Minimum height; px or CSS string."""
minWidth: int | str | None = None
"""Minimum width; px or CSS string."""
minSize: int | str | None = None
"""Shorthand to set both minWidth and minHeight; px or CSS string."""
maxHeight: int | str | None = None
"""Maximum height; px or CSS string."""
maxWidth: int | str | None = None
"""Maximum width; px or CSS string."""
maxSize: int | str | None = None
"""Shorthand to set both maxWidth and maxHeight; px or CSS string."""
margin: int | str | Spacing | None = None
"""Outer margin; spacing unit, CSS string, or margin object."""
background: str | ThemeColor | None = None
"""Background color; accepts background color token, a primitive color token, a CSS string, or theme-aware `{ light, dark }`.
Valid tokens: `surface` `surface-secondary` `surface-tertiary` `surface-elevated` `surface-elevated-secondary`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
aspectRatio: float | str | None = None
"""Aspect ratio of the box (e.g., 16/9); number or CSS string."""
flex: int | str | None = None
"""Flex growth/shrink factor."""
class Button(WidgetComponentBase):
"""Button component optionally wired to an action."""
type: Literal["Button"] = Field(default="Button", frozen=True) # pyright: ignore
submit: bool | None = None
"""Configure the button as a submit button for the nearest form."""
label: str | None = None
"""Text to display inside the button."""
onClickAction: ActionConfig | None = None
"""Action dispatched on click."""
iconStart: WidgetIcon | None = None
"""Icon shown before the label; can be used for icon-only buttons."""
iconEnd: WidgetIcon | None = None
"""Optional icon shown after the label."""
style: Literal["primary", "secondary"] | None = None
"""Convenience preset for button style."""
iconSize: Literal["sm", "md", "lg", "xl", "2xl"] | None = None
"""Controls the size of icons within the button; accepts an icon size token."""
color: (
Literal[
"primary",
"secondary",
"info",
"discovery",
"success",
"caution",
"warning",
"danger",
]
| None
) = None
"""Color of the button; accepts a button color token."""
variant: ControlVariant | None = None
"""Visual variant of the button; accepts a control variant token."""
size: ControlSize | None = None
"""Controls the overall size of the button."""
pill: bool | None = None
"""Determines if the button should be fully rounded (pill)."""
uniform: bool | None = None
"""Determines if the button should have matching width and height."""
block: bool | None = None
"""Extend the button to 100% of the available width."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
class Spacer(WidgetComponentBase):
"""Flexible spacer used to push content apart."""
type: Literal["Spacer"] = Field(default="Spacer", frozen=True) # pyright: ignore
minSize: int | str | None = None
"""Minimum size the spacer should occupy along the flex direction."""
class SelectOption(TypedDict):
"""Selectable option used by the ``Select`` widget."""
value: str
"""Option value submitted with the form."""
label: str
"""Human-readable label for the option."""
disabled: NotRequired[bool]
"""Disable the option."""
description: NotRequired[str]
"""Displayed as secondary text below the option `label`."""
class Select(WidgetComponentBase):
"""Select dropdown component."""
type: Literal["Select"] = Field(default="Select", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
options: list[SelectOption]
"""List of selectable options."""
onChangeAction: ActionConfig | None = None
"""Action dispatched when the value changes."""
placeholder: str | None = None
"""Placeholder text shown when no value is selected."""
defaultValue: str | None = None
"""Initial value of the select."""
variant: ControlVariant | None = None
"""Visual style of the select; accepts a control variant token."""
size: ControlSize | None = None
"""Controls the size of the select control."""
pill: bool | None = None
"""Determines if the select should be fully rounded (pill)."""
block: bool | None = None
"""Extend the select to 100% of the available width."""
clearable: bool | None = None
"""Show a clear control to unset the value."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
class DatePicker(WidgetComponentBase):
"""Date picker input component."""
type: Literal["DatePicker"] = Field(default="DatePicker", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
onChangeAction: ActionConfig | None = None
"""Action dispatched when the date value changes."""
placeholder: str | None = None
"""Placeholder text shown when no date is selected."""
defaultValue: datetime | None = None
"""Initial value of the date picker."""
min: datetime | None = None
"""Earliest selectable date (inclusive)."""
max: datetime | None = None
"""Latest selectable date (inclusive)."""
variant: ControlVariant | None = None
"""Visual variant of the datepicker control."""
size: ControlSize | None = None
"""Controls the size of the datepicker control."""
side: Literal["top", "bottom", "left", "right"] | None = None
"""Preferred side to render the calendar."""
align: Literal["start", "center", "end"] | None = None
"""Preferred alignment of the calendar relative to the control."""
pill: bool | None = None
"""Determines if the datepicker should be fully rounded (pill)."""
block: bool | None = None
"""Extend the datepicker to 100% of the available width."""
clearable: bool | None = None
"""Show a clear control to unset the value."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
class Checkbox(WidgetComponentBase):
"""Checkbox input component."""
type: Literal["Checkbox"] = Field(default="Checkbox", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
label: str | None = None
"""Optional label text rendered next to the checkbox."""
defaultChecked: str | None = None
"""The initial checked state of the checkbox."""
onChangeAction: ActionConfig | None = None
"""Action dispatched when the checked state changes."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
required: bool | None = None
"""Mark the checkbox as required for form submission."""
class Input(WidgetComponentBase):
"""Single-line text input component."""
type: Literal["Input"] = Field(default="Input", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
inputType: Literal["number", "email", "text", "password", "tel", "url"] | None = (
None
)
"""Native input type."""
defaultValue: str | None = None
"""Initial value of the input."""
required: bool | None = None
"""Mark the input as required for form submission."""
pattern: str | None = None
"""Regex pattern for input validation."""
placeholder: str | None = None
"""Placeholder text shown when empty."""
allowAutofillExtensions: bool | None = None
"""Allow password managers / autofill extensions to appear."""
autoSelect: bool | None = None
"""Select all contents of the input when it mounts."""
autoFocus: bool | None = None
"""Autofocus the input when it mounts."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
variant: Literal["soft", "outline"] | None = None
"""Visual style of the input."""
size: ControlSize | None = None
"""Controls the size of the input control."""
gutterSize: Literal["2xs", "xs", "sm", "md", "lg", "xl"] | None = None
"""Controls gutter on the edges of the input; overrides value from `size`."""
pill: bool | None = None
"""Determines if the input should be fully rounded (pill)."""
class Label(WidgetComponentBase):
"""Form label associated with a field."""
type: Literal["Label"] = Field(default="Label", frozen=True) # pyright: ignore
value: str
"""Text content of the label."""
fieldName: str
"""Name of the field this label describes."""
size: TextSize | None = None
"""Size of the label text; accepts a text size token."""
weight: Literal["normal", "medium", "semibold", "bold"] | None = None
"""Font weight; accepts a font weight token."""
textAlign: TextAlign | None = None
"""Horizontal text alignment."""
color: str | ThemeColor | None = None
"""
Text color; accepts a text color token, a primitive color token, a CSS color string, or a theme-aware `{ light, dark }`.
Text color tokens: `prose` `primary` `emphasis` `secondary` `tertiary` `success` `warning` `danger`
Primitive color token: e.g. `red-100`, `blue-900`, `gray-500`
"""
class RadioOption(TypedDict):
"""Option inside a ``RadioGroup`` widget."""
label: str
"""Label displayed next to the radio option."""
value: str
"""Value submitted when the radio option is selected."""
disabled: NotRequired[bool]
"""Disables a specific radio option."""
class RadioGroup(WidgetComponentBase):
"""Grouped radio input control."""
type: Literal["RadioGroup"] = Field(default="RadioGroup", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
options: list[RadioOption] | None = None
"""Array of options to render as radio items."""
ariaLabel: str | None = None
"""Accessible label for the radio group; falls back to `name`."""
onChangeAction: ActionConfig | None = None
"""Action dispatched when the selected value changes."""
defaultValue: str | None = None
"""Initial selected value of the radio group."""
direction: Literal["row", "col"] | None = None
"""Layout direction of the radio items."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles for the entire group."""
required: bool | None = None
"""Mark the group as required for form submission."""
class Textarea(WidgetComponentBase):
"""Multiline text input component."""
type: Literal["Textarea"] = Field(default="Textarea", frozen=True) # pyright: ignore
name: str
"""The name of the form control field used when submitting forms."""
defaultValue: str | None = None
"""Initial value of the textarea."""
required: bool | None = None
"""Mark the textarea as required for form submission."""
pattern: str | None = None
"""Regex pattern for input validation."""
placeholder: str | None = None
"""Placeholder text shown when empty."""
autoSelect: bool | None = None
"""Select all contents of the textarea when it mounts."""
autoFocus: bool | None = None
"""Autofocus the textarea when it mounts."""
disabled: bool | None = None
"""Disable interactions and apply disabled styles."""
variant: Literal["soft", "outline"] | None = None
"""Visual style of the textarea."""
size: ControlSize | None = None
"""Controls the size of the textarea control."""
gutterSize: Literal["2xs", "xs", "sm", "md", "lg", "xl"] | None = None
"""Controls gutter on the edges of the textarea; overrides value from `size`."""
rows: int | None = None
"""Initial number of visible rows."""
autoResize: bool | None = None
"""Automatically grow/shrink to fit content."""
maxRows: int | None = None
"""Maximum number of rows when auto-resizing."""
allowAutofillExtensions: bool | None = None
"""Allow password managers / autofill extensions to appear."""
class Transition(WidgetComponentBase):
"""Wrapper enabling transitions for a child component."""
type: Literal["Transition"] = Field(default="Transition", frozen=True) # pyright: ignore
children: WidgetComponent | None
"""The child component to animate layout changes for."""
class Chart(WidgetComponentBase):
"""Data visualization component for simple bar/line/area charts."""
type: Literal["Chart"] = Field(default="Chart", frozen=True) # pyright: ignore
data: list[dict[str, str | int | float]]
"""Tabular data for the chart, where each row maps field names to values."""
series: list[Series]
"""One or more series definitions that describe how to visualize data fields."""
xAxis: str | XAxisConfig
"""X-axis configuration; either a `dataKey` string or a config object."""
showYAxis: bool | None = None
"""Controls whether the Y axis is rendered."""
showLegend: bool | None = None
"""Controls whether a legend is rendered."""
showTooltip: bool | None = None
"""Controls whether a tooltip is rendered when hovering over a datapoint."""
barGap: int | None = None
"""Gap between bars within the same category (in px)."""
barCategoryGap: int | None = None
"""Gap between bar categories/groups (in px)."""
flex: int | str | None = None
"""Flex growth/shrink factor for layout."""
height: int | str | None = None
"""Explicit height; px or CSS string."""
width: int | str | None = None
"""Explicit width; px or CSS string."""
size: int | str | None = None
"""Shorthand to set both width and height; px or CSS string."""
minHeight: int | str | None = None
"""Minimum height; px or CSS string."""
minWidth: int | str | None = None
"""Minimum width; px or CSS string."""
minSize: int | str | None = None
"""Shorthand to set both minWidth and minHeight; px or CSS string."""
maxHeight: int | str | None = None
"""Maximum height; px or CSS string."""
maxWidth: int | str | None = None
"""Maximum width; px or CSS string."""
maxSize: int | str | None = None
"""Shorthand to set both maxWidth and maxHeight; px or CSS string."""
aspectRatio: float | str | None = None
"""Aspect ratio of the chart area (e.g., 16/9); number or CSS string."""
class XAxisConfig(TypedDict):
"""Configuration object for the X axis."""
dataKey: str
"""Field name from each data row to use for X-axis categories."""
hide: NotRequired[bool]
"""Hide the X axis line, ticks, and labels when true."""
labels: NotRequired[dict[str, str]]
"""Custom mapping of tick values to display labels."""
CurveType = Literal[
"basis",
"basisClosed",
"basisOpen",
"bumpX",
"bumpY",
"bump",
"linear",
"linearClosed",
"natural",
"monotoneX",
"monotoneY",
"monotone",
"step",
"stepBefore",
"stepAfter",
]
"""Interpolation curve types for `area` and `line` series."""
class BarSeries(BaseModel):
"""A bar series plotted from a numeric `dataKey`. Supports stacking."""
type: Literal["bar"] = Field(default="bar", frozen=True)
label: str | None
"""Legend label for the series."""
dataKey: str
"""Field name from each data row that contains the numeric value."""
stack: str | None = None
"""Optional stack group ID. Series with the same ID stack together."""
color: str | ThemeColor | None = None
"""
Color for the series; accepts chart color token, a primitive color token, a CSS string, or theme-aware { light, dark }.
Chart color tokens: `blue` `purple` `orange` `green` `red` `yellow` `pink`
Primitive color token, e.g., `red-100`, `blue-900`, `gray-500`
Note: By default, a color will be sequentially assigned from the chart series colors.
"""
class AreaSeries(BaseModel):
"""An area series plotted from a numeric `dataKey`. Supports stacking and curves."""
type: Literal["area"] = Field(default="area", frozen=True)
label: str | None
"""Legend label for the series."""
dataKey: str
"""Field name from each data row that contains the numeric value."""
stack: str | None = None
"""Optional stack group ID. Series with the same ID stack together."""
color: str | ThemeColor | None = None
"""
Color for the series; accepts chart color token, a primitive color token, a CSS string, or theme-aware { light, dark }.
Chart color tokens: `blue` `purple` `orange` `green` `red` `yellow` `pink`
Primitive color token, e.g., `red-100`, `blue-900`, `gray-500`
Note: By default, a color will be sequentially assigned from the chart series colors.
"""
curveType: None | Literal[CurveType] = None
"""Interpolation curve type used to connect points."""
class LineSeries(BaseModel):
"""A line series plotted from a numeric `dataKey`. Supports curves."""
type: Literal["line"] = Field(default="line", frozen=True)
label: str | None
"""Legend label for the series."""
dataKey: str
"""Field name from each data row that contains the numeric value."""
color: str | ThemeColor | None = None
"""
Color for the series; accepts chart color token, a primitive color token, a CSS string, or theme-aware { light, dark }.
Chart color tokens: `blue` `purple` `orange` `green` `red` `yellow` `pink`
Primitive color token, e.g., `red-100`, `blue-900`, `gray-500`
Note: By default, a color will be sequentially assigned from the chart series colors.
"""
curveType: None | Literal[CurveType] = None
"""Interpolation curve type used to connect points."""