implement review comments
This commit is contained in:
parent
51f680ebea
commit
2cbf7b4821
|
@ -1,80 +0,0 @@
|
||||||
<script>
|
|
||||||
import { createEventDispatcher } from "svelte"
|
|
||||||
import Picker from "./Picker.svelte"
|
|
||||||
|
|
||||||
export let value = null
|
|
||||||
export let id = null
|
|
||||||
export let selectPlaceholder = "Choose an option"
|
|
||||||
export let autocompletePlaceholder = "Search an option"
|
|
||||||
export let disabled = false
|
|
||||||
export let error = null
|
|
||||||
export let options = []
|
|
||||||
export let getOptionLabel = option => option
|
|
||||||
export let getOptionValue = option => option
|
|
||||||
export let getOptionIcon = () => null
|
|
||||||
export let readonly = false
|
|
||||||
export let quiet = false
|
|
||||||
export let autoWidth = false
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
|
||||||
let open = false
|
|
||||||
$: fieldText = getFieldText(value, options, selectPlaceholder)
|
|
||||||
$: fieldIcon = getFieldIcon(value, options, selectPlaceholder)
|
|
||||||
|
|
||||||
const getFieldText = (value, options, placeholder) => {
|
|
||||||
// Always use placeholder if no value
|
|
||||||
if (value == null || value === "") {
|
|
||||||
return placeholder || "Choose an option"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for options to load if there is a value but no options
|
|
||||||
if (!options?.length) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the label if the selected option is found, otherwise raw value
|
|
||||||
const index = options.findIndex(
|
|
||||||
(option, idx) => getOptionValue(option, idx) === value
|
|
||||||
)
|
|
||||||
return index !== -1 ? getOptionLabel(options[index], index) : value
|
|
||||||
}
|
|
||||||
|
|
||||||
const getFieldIcon = (value, options) => {
|
|
||||||
// Wait for options to load if there is a value but no options
|
|
||||||
if (!options?.length) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
const index = options.findIndex(
|
|
||||||
(option, idx) => getOptionValue(option, idx) === value
|
|
||||||
)
|
|
||||||
return index !== -1 ? getOptionIcon(options[index], index) : null
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectOption = value => {
|
|
||||||
dispatch("change", value)
|
|
||||||
open = false
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<Picker
|
|
||||||
on:click
|
|
||||||
bind:open
|
|
||||||
{quiet}
|
|
||||||
{id}
|
|
||||||
{error}
|
|
||||||
{disabled}
|
|
||||||
{readonly}
|
|
||||||
{fieldText}
|
|
||||||
{options}
|
|
||||||
{autoWidth}
|
|
||||||
{getOptionLabel}
|
|
||||||
{getOptionValue}
|
|
||||||
{getOptionIcon}
|
|
||||||
{fieldIcon}
|
|
||||||
autocomplete={true}
|
|
||||||
isPlaceholder={value == null || value === ""}
|
|
||||||
{autocompletePlaceholder}
|
|
||||||
placeholderOption={selectPlaceholder}
|
|
||||||
isOptionSelected={option => option === value}
|
|
||||||
onSelectOption={selectOption}
|
|
||||||
/>
|
|
|
@ -11,6 +11,7 @@
|
||||||
export let getOptionLabel = option => option
|
export let getOptionLabel = option => option
|
||||||
export let getOptionValue = option => option
|
export let getOptionValue = option => option
|
||||||
export let readonly = false
|
export let readonly = false
|
||||||
|
export let autocomplete = false
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
$: selectedLookupMap = getSelectedLookupMap(value)
|
$: selectedLookupMap = getSelectedLookupMap(value)
|
||||||
|
@ -77,6 +78,7 @@
|
||||||
{fieldText}
|
{fieldText}
|
||||||
{options}
|
{options}
|
||||||
isPlaceholder={!value?.length}
|
isPlaceholder={!value?.length}
|
||||||
|
{autocomplete}
|
||||||
{isOptionSelected}
|
{isOptionSelected}
|
||||||
{getOptionLabel}
|
{getOptionLabel}
|
||||||
{getOptionValue}
|
{getOptionValue}
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
export let fieldIcon = ""
|
export let fieldIcon = ""
|
||||||
export let isPlaceholder = false
|
export let isPlaceholder = false
|
||||||
export let placeholderOption = null
|
export let placeholderOption = null
|
||||||
export let autocompletePlaceholder = ""
|
|
||||||
export let options = []
|
export let options = []
|
||||||
export let isOptionSelected = () => false
|
export let isOptionSelected = () => false
|
||||||
export let onSelectOption = () => {}
|
export let onSelectOption = () => {}
|
||||||
|
@ -120,7 +119,7 @@
|
||||||
on:change={event => (searchTerm = event.detail)}
|
on:change={event => (searchTerm = event.detail)}
|
||||||
updateOnChange="true"
|
updateOnChange="true"
|
||||||
{disabled}
|
{disabled}
|
||||||
placeholder={autocompletePlaceholder}
|
placeholder="Search"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<ul class="spectrum-Menu" role="listbox">
|
<ul class="spectrum-Menu" role="listbox">
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
export let readonly = false
|
export let readonly = false
|
||||||
export let quiet = false
|
export let quiet = false
|
||||||
export let autoWidth = false
|
export let autoWidth = false
|
||||||
|
export let autocomplete = false
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
let open = false
|
let open = false
|
||||||
|
@ -70,6 +71,7 @@
|
||||||
{getOptionValue}
|
{getOptionValue}
|
||||||
{getOptionIcon}
|
{getOptionIcon}
|
||||||
{fieldIcon}
|
{fieldIcon}
|
||||||
|
{autocomplete}
|
||||||
isPlaceholder={value == null || value === ""}
|
isPlaceholder={value == null || value === ""}
|
||||||
placeholderOption={placeholder}
|
placeholderOption={placeholder}
|
||||||
isOptionSelected={option => option === value}
|
isOptionSelected={option => option === value}
|
||||||
|
|
|
@ -9,4 +9,3 @@ export { default as CoreSwitch } from "./Switch.svelte"
|
||||||
export { default as CoreSearch } from "./Search.svelte"
|
export { default as CoreSearch } from "./Search.svelte"
|
||||||
export { default as CoreDatePicker } from "./DatePicker.svelte"
|
export { default as CoreDatePicker } from "./DatePicker.svelte"
|
||||||
export { default as CoreDropzone } from "./Dropzone.svelte"
|
export { default as CoreDropzone } from "./Dropzone.svelte"
|
||||||
export { default as CoreAutocomplete } from "./Autocomplete.svelte"
|
|
||||||
|
|
|
@ -1915,10 +1915,6 @@
|
||||||
"label": "Select",
|
"label": "Select",
|
||||||
"value": "select"
|
"value": "select"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "Autocomplete",
|
|
||||||
"value": "autocomplete"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Radio buttons",
|
"label": "Radio buttons",
|
||||||
"value": "radio"
|
"value": "radio"
|
||||||
|
@ -1930,6 +1926,16 @@
|
||||||
"label": "Default value",
|
"label": "Default value",
|
||||||
"key": "defaultValue"
|
"key": "defaultValue"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"label": "Autocomplete",
|
||||||
|
"key": "autocomplete",
|
||||||
|
"defaultValue": false,
|
||||||
|
"dependsOn": {
|
||||||
|
"setting": "optionsType",
|
||||||
|
"value": "select"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Disabled",
|
"label": "Disabled",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { CoreAutocomplete, CoreSelect, RadioGroup } from "@budibase/bbui"
|
import { CoreSelect, RadioGroup } from "@budibase/bbui"
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
|
|
||||||
export let field
|
export let field
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
export let labelColumn
|
export let labelColumn
|
||||||
export let valueColumn
|
export let valueColumn
|
||||||
export let customOptions
|
export let customOptions
|
||||||
|
export let autocomplete = false
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
@ -85,16 +86,7 @@
|
||||||
on:change={e => fieldApi.setValue(e.detail)}
|
on:change={e => fieldApi.setValue(e.detail)}
|
||||||
getOptionLabel={flatOptions ? x => x : x => x.label}
|
getOptionLabel={flatOptions ? x => x : x => x.label}
|
||||||
getOptionValue={flatOptions ? x => x : x => x.value}
|
getOptionValue={flatOptions ? x => x : x => x.value}
|
||||||
/>
|
{autocomplete}
|
||||||
{:else if optionsType === "autocomplete"}
|
|
||||||
<CoreAutocomplete
|
|
||||||
value={$fieldState.value}
|
|
||||||
id={$fieldState.fieldId}
|
|
||||||
disabled={$fieldState.disabled}
|
|
||||||
error={$fieldState.error}
|
|
||||||
options={fieldSchema?.constraints?.inclusion ?? []}
|
|
||||||
{placeholder}
|
|
||||||
on:change={e => fieldApi.setValue(e.detail)}
|
|
||||||
/>
|
/>
|
||||||
{:else if optionsType === "radio"}
|
{:else if optionsType === "radio"}
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { CoreAutocomplete, CoreSelect, CoreMultiselect } from "@budibase/bbui"
|
import { CoreSelect, CoreMultiselect } from "@budibase/bbui"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
|
|
||||||
|
@ -25,11 +25,7 @@
|
||||||
$: fetchTable(linkedTableId)
|
$: fetchTable(linkedTableId)
|
||||||
$: singleValue = flatten($fieldState?.value)?.[0]
|
$: singleValue = flatten($fieldState?.value)?.[0]
|
||||||
$: multiValue = flatten($fieldState?.value) ?? []
|
$: multiValue = flatten($fieldState?.value) ?? []
|
||||||
$: component = multiselect
|
$: component = multiselect ? CoreMultiselect : CoreSelect
|
||||||
? CoreMultiselect
|
|
||||||
: autocomplete
|
|
||||||
? CoreAutocomplete
|
|
||||||
: CoreSelect
|
|
||||||
|
|
||||||
const fetchTable = async id => {
|
const fetchTable = async id => {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -82,6 +78,7 @@
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={component}
|
this={component}
|
||||||
{options}
|
{options}
|
||||||
|
{autocomplete}
|
||||||
value={multiselect ? multiValue : singleValue}
|
value={multiselect ? multiValue : singleValue}
|
||||||
on:change={multiselect ? multiHandler : singleHandler}
|
on:change={multiselect ? multiHandler : singleHandler}
|
||||||
id={$fieldState.fieldId}
|
id={$fieldState.fieldId}
|
||||||
|
|
Loading…
Reference in New Issue