@@ -53,105 +53,121 @@ const data = [
5353 } ,
5454 {
5555 id : 6 ,
56+ prop : "enableTooltip" ,
57+ type : "boolean" ,
58+ default : "false" ,
59+ description :
60+ "When enableTooltip is true, select component renders the <Tooltip> component for the selected value." ,
61+ } ,
62+ {
63+ id : 7 ,
5664 prop : "hasError" ,
5765 type : "boolean" ,
5866 default : "-" ,
5967 description : "If true, error in component." ,
6068 } ,
6169 {
62- id : 7 ,
70+ id : 8 ,
6371 prop : "helperText" ,
6472 type : "string" ,
6573 default : "-" ,
6674 description : "Displays an error message below the component." ,
6775 } ,
6876 {
69- id : 8 ,
77+ id : 9 ,
7078 prop : "hideIfSingleOption" ,
7179 type : "boolean" ,
7280 default : "false" ,
7381 description :
7482 "If there is only one option, and multiple is false, the Select component will not render the dropdown at all when set to true." ,
7583 } ,
7684 {
77- id : 9 ,
85+ id : 10 ,
7886 prop : "label" ,
7987 type : "string" ,
8088 default : "-" ,
8189 description : "Label of the component." ,
8290 } ,
8391 {
84- id : 10 ,
92+ id : 11 ,
8593 prop : "labelKey" ,
8694 type : "string" ,
8795 default : "-" ,
8896 description : "The key in option object to use as the display label." ,
8997 } ,
9098 {
91- id : 11 ,
99+ id : 12 ,
92100 prop : "multiple" ,
93101 type : "boolean" ,
94102 default : "false" ,
95103 description : "If true, multiple selection is enabled." ,
96104 } ,
97105 {
98- id : 12 ,
106+ id : 13 ,
99107 prop : "name" ,
100108 type : "string" ,
101109 default : "-" ,
102110 description : "Name of the component." ,
103111 } ,
104112 {
105- id : 13 ,
113+ id : 14 ,
106114 prop : "options" ,
107115 type : "Option[]" ,
108116 default : "-" ,
109117 description : "Options to pass in the select component." ,
110118 } ,
111119 {
112- id : 14 ,
120+ id : 15 ,
113121 prop : "placeholder" ,
114122 type : "string" ,
115123 default : "-" ,
116124 description : "Placeholder in the component." ,
117125 } ,
118126 {
119- id : 15 ,
127+ id : 16 ,
120128 prop : "showRemoveSelection" ,
121129 type : "boolean" ,
122130 default : "true" ,
123131 description : "If true, icon to remove selected options is visible." ,
124132 } ,
125133 {
126- id : 16 ,
134+ id : 17 ,
135+ prop : "tooltipOptions" ,
136+ type : "TooltipOptions" ,
137+ default : "-" ,
138+ description :
139+ "Options to customize the tooltip’s behavior(example: position, offset)." ,
140+ } ,
141+ {
142+ id : 18 ,
127143 prop : "value" ,
128144 type : "Value" ,
129145 default : "-" ,
130146 description : "Selected values of the component." ,
131147 } ,
132148 {
133- id : 17 ,
149+ id : 19 ,
134150 prop : "valueKey" ,
135151 type : "string" ,
136152 default : "-" ,
137153 description : "The key in option object to use as value." ,
138154 } ,
139155 {
140- id : 18 ,
156+ id : 20 ,
141157 prop : "renderOption" ,
142158 type : "(option: Option[]) => React.ReactNode" ,
143159 default : "-" ,
144160 description : "Function to be called to render custom select options." ,
145161 } ,
146162 {
147- id : 19 ,
163+ id : 21 ,
148164 prop : "renderValue" ,
149165 type : "(value?: Value, options?: Option[]) => React.ReactNode" ,
150166 default : "-" ,
151167 description : "Function to be called to render custom select value." ,
152168 } ,
153169 {
154- id : 20 ,
170+ id : 22 ,
155171 prop : "onChange" ,
156172 type : " (newValue: T | T[]) => void" ,
157173 default : "-" ,
@@ -170,6 +186,7 @@ export const SelectDemo = () => {
170186 const [ renderedValue , setRenderedValue ] = useState < string [ ] > ( [ ] ) ;
171187 const [ renderedOption , setRenderedOption ] = useState < string [ ] > ( [ ] ) ;
172188 const [ value , setValue ] = useState ( "" ) ;
189+ const [ selectedCountries , setSelectedCountries ] = useState < string [ ] > ( [ ] ) ;
173190
174191 const renderSelectedValue = (
175192 value ?: string | string [ ] ,
@@ -183,7 +200,11 @@ export const SelectDemo = () => {
183200 < span className = "selected-labels" >
184201 { value . map ( ( v ) => {
185202 const label = options . find ( ( option ) => option . value === v ) ?. label ;
186- if ( ! label ) return null ;
203+
204+ if ( ! label ) {
205+ return null ;
206+ }
207+
187208 return < Tag key = { v } label = { label } /> ;
188209 } ) }
189210 </ span >
@@ -461,6 +482,56 @@ const [value, setValue] = useState<string>("");
461482 />
462483 </ Section >
463484
485+ < Section title = { t ( "select.usage.withTooltip" ) } >
486+ < Select
487+ label = { t ( "select.label" ) }
488+ name = "select"
489+ options = { [
490+ { label : "France" , value : "FR" } ,
491+ { label : "Germany" , value : "DE" } ,
492+ { disabled : true , label : "Belgium" , value : "BE" } ,
493+ { label : "Nepal" , value : "NP" } ,
494+ { label : "India" , value : "IN" } ,
495+ ] }
496+ value = { selectedCountries }
497+ onChange = { ( value : string [ ] ) => setSelectedCountries ( value ) }
498+ className = "country-selector"
499+ placeholder = { t ( "select.placeholder" ) }
500+ multiple
501+ enableTooltip
502+ tooltipOptions = { {
503+ position : "top" ,
504+ offset : 15 ,
505+ } }
506+ />
507+ < CodeBlock
508+ exampleCode = '
509+ const [selectedCountries, setSelectedCountries] = useState<string[]>([]);
510+
511+ <Select
512+ label={t("select.label")}
513+ name="select"
514+ options={[
515+ { label: "France", value: "FR" },
516+ { label: "Germany", value: "DE" },
517+ { disabled: true, label: "Belgium", value: "BE" },
518+ { label: "Nepal", value: "NP" },
519+ { label: "India", value: "IN" },
520+ ]}
521+ value={selectedCountries}
522+ onChange={(value: string[]) => setSelectedCountries(value)}
523+ className="country-selector"
524+ placeholder={t("select.placeholder")}
525+ multiple
526+ enableTooltip
527+ tooltipOptions={{
528+ position: "top",
529+ offset: 15,
530+ }}
531+ />'
532+ />
533+ </ Section >
534+
464535 < Section title = { t ( "select.usage.invalid" ) } >
465536 < Select
466537 label = { t ( "select.label" ) }
@@ -593,15 +664,22 @@ const [singleSelectValue, setSingleSelectValue] = useState<string>("");
593664
594665 < Section title = "Type" >
595666 < CodeBlock
596- exampleCode = "
667+ exampleCode = '
597668type Option<T extends string | number> = {
598669 disabled?: boolean;
599670 label: string;
600671 value: T;
601672};
602673
603674type Value = string | number | (string | number)[]
604- "
675+
676+ type TooltipOptions = {
677+ delay?: number;
678+ mouseTrack?: boolean;
679+ offset?: number;
680+ position?: "top" | "bottom" | "right" | "left";
681+ }
682+ '
605683 />
606684 </ Section >
607685 </ Page >
0 commit comments