Skip to content

Commit 24680cf

Browse files
committed
allow styling of selector widget from python code + better placeholder when loading
1 parent 03a0919 commit 24680cf

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

app/components/GooeySelect.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
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";
37
import Select, { components } from "react-select";
48
import { useJsonFormInput } from "~/jsonFormInput";
59
import { ClientOnlySuspense } from "~/lazyImports";
@@ -14,8 +18,8 @@ export default function GooeySelect({
1418
onChange: () => void;
1519
state: Record<string, any>;
1620
}) {
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({
1923
defaultValue,
2024
name,
2125
onChange,
@@ -28,7 +32,7 @@ export default function GooeySelect({
2832
}
2933
}, [state, name]);
3034

31-
const onSelectChange = (newValue: any) => {
35+
let onSelectChange = (newValue: any) => {
3236
if (newValue === undefined) return;
3337
if (!newValue) {
3438
setValue(newValue);
@@ -51,7 +55,7 @@ export default function GooeySelect({
5155
}, [args.isMulti, args.options, selectValue, setValue]);
5256

5357
return (
54-
<div className="gui-input gui-input-select">
58+
<div className={`gui-input gui-input-select ${args.className ?? ""}`}>
5559
{label && (
5660
<label htmlFor={name}>
5761
<RenderedMarkdown body={label} />
@@ -60,11 +64,15 @@ export default function GooeySelect({
6064
<JsonFormInput />
6165
<ClientOnlySuspense
6266
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+
/>
6876
</div>
6977
}
7078
>
@@ -73,6 +81,17 @@ export default function GooeySelect({
7381
value={selectValue}
7482
onChange={onSelectChange}
7583
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+
}}
7695
{...args}
7796
/>
7897
)}

0 commit comments

Comments
 (0)