Skip to content

Commit 47a2c88

Browse files
committed
wip: add back fields/
1 parent 27a9eb9 commit 47a2c88

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/ui/fields/editable.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** An editable value; provides the initial value as well as a callback which (asynchronously) edits the value. */
2+
export interface Editable<T> {
3+
/** The initial value to display. The component should track the current value if it is updated. */
4+
initial: T;
5+
/**
6+
* A callback to update the value in it's original datasource; can optionally provide the expected current value for validation. Returns whether
7+
* the value was successfully updated.
8+
*/
9+
update: (incoming: T, original?: T) => Promise<boolean>;
10+
}

src/ui/fields/select.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useCallback, useState } from "preact/hooks";
2+
import Select from "react-select";
3+
4+
/** @internal Editable component which updates an editable. */
5+
export function RawSelectEditable({
6+
options,
7+
initialValue,
8+
onUpdate
9+
}: {
10+
/** The options you can select from. */
11+
options: (string | number)[];
12+
initialValue: string | string[];
13+
onUpdate: (string | string[]) => void;
14+
}) {
15+
const [value, setValue] = useState(initialValue);
16+
17+
return <Select
18+
classNamePrefix="datacore-selectable"
19+
onChange={onChange}
20+
unstyled
21+
isMulti={config?.multi ?? false}
22+
options={config?.options ?? []}
23+
menuPortalTarget={document.body}
24+
classNames={{
25+
26+
27+
input: (props: any) => "prompt-input",
28+
29+
30+
valueContainer: (props: any) => "suggestion-item value-container",
31+
32+
33+
container: (props: any) => "suggestion-container",
34+
35+
36+
menu: (props: any) => "suggestion-content suggestion-container",
37+
38+
39+
option: (props: any) => `suggestion-item${props.isSelected ? " is-selected" : ""}`,
40+
41+
42+
}}
43+
44+
45+
/>
46+
}

0 commit comments

Comments
 (0)