13
13
import { action } from '@storybook/addon-actions' ;
14
14
import {
15
15
ActionButton ,
16
+ ActionMenu ,
16
17
Cell ,
18
+ Checkbox ,
19
+ CheckboxGroup ,
20
+ ColorArea ,
17
21
Column ,
22
+ ComboBox ,
23
+ ComboBoxItem ,
18
24
Content ,
25
+ DatePicker ,
19
26
Heading ,
20
27
IllustratedMessage ,
21
28
Link ,
22
29
MenuItem ,
23
30
MenuSection ,
31
+ NumberField ,
32
+ Picker ,
33
+ PickerItem ,
34
+ Radio ,
35
+ RadioGroup ,
24
36
Row ,
37
+ Slider ,
38
+ Switch ,
25
39
TableBody ,
26
40
TableHeader ,
27
41
TableView ,
28
42
TableViewProps ,
43
+ Tag ,
44
+ TagGroup ,
29
45
Text ,
30
46
TextField
31
47
} from '../src' ;
@@ -932,21 +948,147 @@ export const ColSpan: StoryObj<typeof ColSpanExample> = {
932
948
}
933
949
} ;
934
950
951
+ let data : { id : string , name : string , description : string , type : string } [ ] = [
952
+ { id : '1' , name : 'Name' , description : 'Who you are' , type : 'text' } ,
953
+ { id : '2' , name : 'Date of birth' , description : 'For horoscopes' , type : 'date' } ,
954
+ { id : '3' , name : 'Favourite colour' , description : 'For your personality' , type : 'combobox' } ,
955
+ { id : '4' , name : 'Pets' , description : 'For your enjoyment' , type : 'picker' } ,
956
+ { id : '5' , name : 'Allowance' , description : 'For your future' , type : 'number' } ,
957
+ { id : '6' , name : 'Height' , description : 'In inches, for your basketball career' , type : 'slider' } ,
958
+ { id : '7' , name : 'Actions' , description : 'To take right now' , type : 'menu' } ,
959
+ { id : '8' , name : 'Checkbox' , description : 'To check' , type : 'checkbox' } ,
960
+ { id : '9' , name : 'Radio' , description : 'To choose' , type : 'radio' } ,
961
+ { id : '10' , name : 'Wall colour' , description : 'So your room sparks joy' , type : 'color' } ,
962
+ { id : '11' , name : 'References' , description : 'Handy link to your favourite website' , type : 'link' } ,
963
+ { id : '12' , name : 'Mythical dogs' , description : 'Which would you adopt' , type : 'tags' } ,
964
+ { id : '13' , name : 'Superstitions enabled' , description : 'Whether or not 13 is bad luck' , type : 'switch' }
965
+ ] ;
966
+
967
+ let dataColumns = [
968
+ { name : 'Name' , id : 'name' , isRowHeader : true , minWidth : 200 } ,
969
+ { name : 'Data' , id : 'editable' , minWidth : 300 } ,
970
+ { name : 'Description' , id : 'description' , minWidth : 200 }
971
+ ] ;
972
+
973
+ let formatOptions : Intl . NumberFormatOptions = {
974
+ style : 'currency' ,
975
+ currency : 'USD'
976
+ } ;
935
977
936
978
export const TableWithTextFields : StoryObj < typeof TableView > = {
937
979
render : ( args ) => (
938
- < TableView aria-label = "Many items table" { ...args } styles = { style ( { width : 800 , height : 400 } ) } >
939
- < TableHeader columns = { manyColumns } >
980
+ < TableView overflowMode = "wrap" aria-label = "Editable fields table" { ...args } styles = { style ( { width : 800 , height : 400 } ) } >
981
+ < TableHeader columns = { dataColumns } >
940
982
{ ( column ) => (
941
- < Column allowsResizing minWidth = { 100 } isRowHeader = { column . name === 'Column 1' } > { column . name } </ Column >
983
+ < Column allowsResizing minWidth = { column . minWidth } isRowHeader = { column . isRowHeader } > { column . name } </ Column >
942
984
) }
943
985
</ TableHeader >
944
- < TableBody items = { manyRows } >
986
+ < TableBody items = { data } >
945
987
{ item => (
946
- < Row id = { item . id } columns = { manyColumns } >
988
+ < Row id = { item . id } columns = { dataColumns } >
947
989
{ ( column ) => {
948
- if ( column . name === 'Column 2' ) {
949
- return < Cell > < div style = { { display : 'flex' } } > < TextField aria-label = { `${ item [ column . id ] } 1` } /> < TextField aria-label = { `${ item [ column . id ] } 2` } /> </ div > </ Cell > ;
990
+ if ( column . name === 'Data' ) {
991
+ switch ( item . type ) {
992
+ case 'text' :
993
+ return < Cell > < div style = { { display : 'flex' , paddingInline : '8px' , gap : '8px' } } > < TextField aria-label = "First name" /> < TextField aria-label = "Last name" /> </ div > </ Cell > ;
994
+ case 'date' :
995
+ return < Cell > < div style = { { display : 'flex' , paddingInline : '8px' } } > < DatePicker aria-label = { item . name } /> </ div > </ Cell > ;
996
+ case 'combobox' :
997
+ return (
998
+ < Cell >
999
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1000
+ < ComboBox aria-label = { item . name } >
1001
+ < ComboBoxItem id = "1" > Red</ ComboBoxItem >
1002
+ < ComboBoxItem id = "2" > Green</ ComboBoxItem >
1003
+ < ComboBoxItem id = "3" > Blue</ ComboBoxItem >
1004
+ </ ComboBox >
1005
+ </ div >
1006
+ </ Cell >
1007
+ ) ;
1008
+ case 'picker' :
1009
+ return (
1010
+ < Cell >
1011
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1012
+ < Picker aria-label = { item . name } >
1013
+ < PickerItem id = "1" > Cat</ PickerItem >
1014
+ < PickerItem id = "2" > Dog</ PickerItem >
1015
+ < PickerItem id = "3" > Bird</ PickerItem >
1016
+ </ Picker >
1017
+ </ div >
1018
+ </ Cell >
1019
+ ) ;
1020
+ case 'number' :
1021
+ return < Cell > < div style = { { display : 'flex' , paddingInline : '8px' } } > < NumberField formatOptions = { formatOptions } aria-label = { item . name } /> </ div > </ Cell > ;
1022
+ case 'slider' :
1023
+ return < Cell > < div style = { { display : 'flex' , paddingInline : '8px' } } > < Slider labelPosition = "side" aria-label = { item . name } minValue = { 0 } maxValue = { 100 } step = { 1 } /> </ div > </ Cell > ;
1024
+ case 'menu' :
1025
+ return (
1026
+ < Cell >
1027
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1028
+ < ActionMenu >
1029
+ < MenuItem > Copy</ MenuItem >
1030
+ < MenuItem > Delete</ MenuItem >
1031
+ </ ActionMenu >
1032
+ </ div >
1033
+ </ Cell >
1034
+ ) ;
1035
+ case 'checkbox' :
1036
+ return (
1037
+ < Cell >
1038
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1039
+ < CheckboxGroup aria-label = "Packing" orientation = "horizontal" >
1040
+ < Checkbox value = "airpods" > Airpods</ Checkbox >
1041
+ < Checkbox value = "kindle" > Kindle</ Checkbox >
1042
+ </ CheckboxGroup >
1043
+ </ div >
1044
+ </ Cell >
1045
+ ) ;
1046
+ case 'radio' :
1047
+ return (
1048
+ < Cell >
1049
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1050
+ < RadioGroup aria-label = "In-flight meal" orientation = "horizontal" >
1051
+ < Radio value = "chicken" > Chicken</ Radio >
1052
+ < Radio value = "veggie" > Veggie</ Radio >
1053
+ </ RadioGroup >
1054
+ </ div >
1055
+ </ Cell >
1056
+ ) ;
1057
+ case 'color' :
1058
+ return (
1059
+ < Cell >
1060
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1061
+ < ColorArea aria-label = { item . name } />
1062
+ </ div >
1063
+ </ Cell >
1064
+ ) ;
1065
+ case 'link' :
1066
+ return (
1067
+ < Cell >
1068
+ < div style = { { display : 'flex' , paddingInline : '8px' } } > < Link href = "https://adobe.com" > Adobe</ Link > </ div >
1069
+ </ Cell >
1070
+ ) ;
1071
+ case 'tags' :
1072
+ return (
1073
+ < Cell >
1074
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1075
+ < TagGroup selectionMode = "multiple" aria-label = { item . name } >
1076
+ < Tag > Cerberus</ Tag >
1077
+ < Tag > Gellert</ Tag >
1078
+ < Tag > Fenris</ Tag >
1079
+ </ TagGroup >
1080
+ </ div >
1081
+ </ Cell >
1082
+ ) ;
1083
+ case 'switch' :
1084
+ return (
1085
+ < Cell >
1086
+ < div style = { { display : 'flex' , paddingInline : '8px' } } >
1087
+ < Switch aria-label = { item . name } />
1088
+ </ div >
1089
+ </ Cell >
1090
+ ) ;
1091
+ }
950
1092
}
951
1093
return < Cell > { item [ column . id ] } </ Cell > ;
952
1094
} }
@@ -958,6 +1100,11 @@ export const TableWithTextFields: StoryObj<typeof TableView> = {
958
1100
args : {
959
1101
...Example . args ,
960
1102
keyboardNavigationBehavior : 'tab'
1103
+ } ,
1104
+ parameters : {
1105
+ docs : {
1106
+ disable : true
1107
+ }
961
1108
}
962
1109
} ;
963
1110
0 commit comments