1
1
import { useEffect } from "react" ;
2
- import type { OptionProps , SingleValueProps } from "react-select" ;
2
+ import type {
3
+ CSSObjectWithLabel ,
4
+ OptionProps ,
5
+ SingleValueProps ,
6
+ } from "react-select" ;
3
7
import Select , { components } from "react-select" ;
4
8
import { useJsonFormInput } from "~/jsonFormInput" ;
5
9
import { ClientOnlySuspense } from "~/lazyImports" ;
@@ -14,8 +18,8 @@ export default function GooeySelect({
14
18
onChange : ( ) => void ;
15
19
state : Record < string , any > ;
16
20
} ) {
17
- const { defaultValue, name, label, ...args } = props ;
18
- const [ JsonFormInput , value , setValue ] = useJsonFormInput ( {
21
+ let { defaultValue, name, label, styles , ...args } = props ;
22
+ let [ JsonFormInput , value , setValue ] = useJsonFormInput ( {
19
23
defaultValue,
20
24
name,
21
25
onChange,
@@ -28,7 +32,7 @@ export default function GooeySelect({
28
32
}
29
33
} , [ state , name ] ) ;
30
34
31
- const onSelectChange = ( newValue : any ) => {
35
+ let onSelectChange = ( newValue : any ) => {
32
36
if ( newValue === undefined ) return ;
33
37
if ( ! newValue ) {
34
38
setValue ( newValue ) ;
@@ -51,7 +55,7 @@ export default function GooeySelect({
51
55
} , [ args . isMulti , args . options , selectValue , setValue ] ) ;
52
56
53
57
return (
54
- < div className = " gui-input gui-input-select" >
58
+ < div className = { ` gui-input gui-input-select ${ args . className ?? "" } ` } >
55
59
{ label && (
56
60
< label htmlFor = { name } >
57
61
< RenderedMarkdown body = { label } />
@@ -60,11 +64,15 @@ export default function GooeySelect({
60
64
< JsonFormInput />
61
65
< ClientOnlySuspense
62
66
fallback = {
63
- < div
64
- className = "d-flex align-items-center justify-content-center border rounded"
65
- style = { { height : "38px" } }
66
- >
67
- Loading...
67
+ < div className = "d-flex align-items-center" style = { { height : "38px" } } >
68
+ < RenderedMarkdown
69
+ body = {
70
+ ( selectValue &&
71
+ selectValue . map ( ( it : any ) => it . label ) . join ( " | " ) ) ||
72
+ "Loading..."
73
+ }
74
+ className = "container-margin-reset"
75
+ />
68
76
</ div >
69
77
}
70
78
>
@@ -73,6 +81,17 @@ export default function GooeySelect({
73
81
value = { selectValue }
74
82
onChange = { onSelectChange }
75
83
components = { { Option, SingleValue } }
84
+ styles = { {
85
+ ...Object . fromEntries (
86
+ Object . entries ( styles ?? { } ) . map ( ( [ key , style ] ) => {
87
+ if ( ! style ) return [ key , undefined ] ;
88
+ return [
89
+ key ,
90
+ ( base : CSSObjectWithLabel ) => ( { ...base , ...style } ) ,
91
+ ] ;
92
+ } )
93
+ ) ,
94
+ } }
76
95
{ ...args }
77
96
/>
78
97
) }
0 commit comments