File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments