Added MultiSelect Checkboxes
This commit is contained in:
parent
ba0cabacb9
commit
973b04c413
|
@ -0,0 +1,68 @@
|
||||||
|
<script>
|
||||||
|
import "@spectrum-css/fieldgroup/dist/index-vars.css"
|
||||||
|
import "@spectrum-css/radio/dist/index-vars.css"
|
||||||
|
import { createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
|
export let direction = "vertical"
|
||||||
|
export let value = []
|
||||||
|
export let options = []
|
||||||
|
export let error = null
|
||||||
|
export let disabled = false
|
||||||
|
export let getOptionLabel = option => option
|
||||||
|
export let getOptionValue = option => option
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher()
|
||||||
|
const onChange = e => {
|
||||||
|
let tempValue = value
|
||||||
|
let isChecked = e.target.checked
|
||||||
|
if (!tempValue.includes(e.target.value) && isChecked) {
|
||||||
|
tempValue.push(e.target.value)
|
||||||
|
}
|
||||||
|
value = tempValue
|
||||||
|
dispatch(
|
||||||
|
"change",
|
||||||
|
tempValue.filter(val => val !== e.target.value || isChecked)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={`spectrum-FieldGroup spectrum-FieldGroup--${direction}`}>
|
||||||
|
{#if options && Array.isArray(options)}
|
||||||
|
{#each options as option}
|
||||||
|
<div
|
||||||
|
title={getOptionLabel(option)}
|
||||||
|
class="spectrum-Checkbox spectrum-FieldGroup-item"
|
||||||
|
class:is-invalid={!!error}
|
||||||
|
>
|
||||||
|
<label
|
||||||
|
class="spectrum-Checkbox spectrum-Checkbox--sizeM spectrum-FieldGroup-item"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
on:change={onChange}
|
||||||
|
value={getOptionValue(option)}
|
||||||
|
type="checkbox"
|
||||||
|
class="spectrum-Checkbox-input"
|
||||||
|
{disabled}
|
||||||
|
checked={value.includes(getOptionValue(option))}
|
||||||
|
/>
|
||||||
|
<span class="spectrum-Checkbox-box">
|
||||||
|
<svg
|
||||||
|
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Checkbox-checkmark"
|
||||||
|
focusable="false"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<use xlink:href="#spectrum-css-icon-Checkmark100" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
<span class="spectrum-Checkbox-label">{getOptionLabel(option)}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.spectrum-Checkbox-input {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -3,6 +3,7 @@ export { default as CoreSelect } from "./Select.svelte"
|
||||||
export { default as CoreMultiselect } from "./Multiselect.svelte"
|
export { default as CoreMultiselect } from "./Multiselect.svelte"
|
||||||
export { default as CoreCheckbox } from "./Checkbox.svelte"
|
export { default as CoreCheckbox } from "./Checkbox.svelte"
|
||||||
export { default as CoreRadioGroup } from "./RadioGroup.svelte"
|
export { default as CoreRadioGroup } from "./RadioGroup.svelte"
|
||||||
|
export { default as CoreCheckboxGroup } from "./CheckboxGroup.svelte"
|
||||||
export { default as CoreTextArea } from "./TextArea.svelte"
|
export { default as CoreTextArea } from "./TextArea.svelte"
|
||||||
export { default as CoreCombobox } from "./Combobox.svelte"
|
export { default as CoreCombobox } from "./Combobox.svelte"
|
||||||
export { default as CoreSwitch } from "./Switch.svelte"
|
export { default as CoreSwitch } from "./Switch.svelte"
|
||||||
|
|
|
@ -2346,6 +2346,43 @@
|
||||||
"key": "disabled",
|
"key": "disabled",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"label": "Type",
|
||||||
|
"key": "optionsType",
|
||||||
|
"defaultValue": "select",
|
||||||
|
"placeholder": "Pick an options type",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Select",
|
||||||
|
"value": "select"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Checkbox buttons",
|
||||||
|
"value": "checkbox"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"label": "Direction",
|
||||||
|
"key": "direction",
|
||||||
|
"defaultValue": "vertical",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"label": "Horizontal",
|
||||||
|
"value": "horizontal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Vertical",
|
||||||
|
"value": "vertical"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependsOn": {
|
||||||
|
"setting": "optionsType",
|
||||||
|
"value": "checkbox"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "select",
|
"type": "select",
|
||||||
"label": "Options source",
|
"label": "Options source",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { CoreMultiselect } from "@budibase/bbui"
|
import { CoreMultiselect, CoreCheckboxGroup } from "@budibase/bbui"
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
import { getOptions } from "./optionsParser"
|
import { getOptions } from "./optionsParser"
|
||||||
export let field
|
export let field
|
||||||
|
@ -15,6 +15,8 @@
|
||||||
export let customOptions
|
export let customOptions
|
||||||
export let autocomplete = false
|
export let autocomplete = false
|
||||||
export let onChange
|
export let onChange
|
||||||
|
export let optionsType = "select"
|
||||||
|
export let direction = "vertical"
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
@ -61,17 +63,31 @@
|
||||||
bind:fieldSchema
|
bind:fieldSchema
|
||||||
>
|
>
|
||||||
{#if fieldState}
|
{#if fieldState}
|
||||||
<CoreMultiselect
|
{#if !optionsType || optionsType === "select"}
|
||||||
value={fieldState.value || []}
|
<CoreMultiselect
|
||||||
error={fieldState.error}
|
value={fieldState.value || []}
|
||||||
getOptionLabel={flatOptions ? x => x : x => x.label}
|
error={fieldState.error}
|
||||||
getOptionValue={flatOptions ? x => x : x => x.value}
|
getOptionLabel={flatOptions ? x => x : x => x.label}
|
||||||
id={fieldState.fieldId}
|
getOptionValue={flatOptions ? x => x : x => x.value}
|
||||||
disabled={fieldState.disabled}
|
id={fieldState.fieldId}
|
||||||
on:change={handleChange}
|
disabled={fieldState.disabled}
|
||||||
{placeholder}
|
on:change={handleChange}
|
||||||
{options}
|
{placeholder}
|
||||||
{autocomplete}
|
{options}
|
||||||
/>
|
{autocomplete}
|
||||||
|
/>
|
||||||
|
{:else if optionsType === "checkbox"}
|
||||||
|
<CoreCheckboxGroup
|
||||||
|
value={fieldState.value || []}
|
||||||
|
id={fieldState.fieldId}
|
||||||
|
disabled={fieldState.disabled}
|
||||||
|
error={fieldState.error}
|
||||||
|
{options}
|
||||||
|
{direction}
|
||||||
|
on:change={handleChange}
|
||||||
|
getOptionLabel={flatOptions ? x => x : x => x.label}
|
||||||
|
getOptionValue={flatOptions ? x => x : x => x.value}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
Loading…
Reference in New Issue