Use BBUI checkbox in standard components
This commit is contained in:
parent
4d84e063dd
commit
9a2385e4b2
|
@ -1,4 +1,4 @@
|
||||||
export { default as CoreTextField } from "./TextField.svelte"
|
export { default as CoreTextField } from "./TextField.svelte"
|
||||||
export { default as CoreSelect } from "./Select.svelte"
|
export { default as CoreSelect } from "./Select.svelte"
|
||||||
export { default as CoreMultiselect } from "./Multiselect.svelte"
|
export { default as CoreMultiselect } from "./Multiselect.svelte"
|
||||||
export { default as Checkbox } from "./Checkbox.svelte"
|
export { default as CoreCheckbox } from "./Checkbox.svelte"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import "@spectrum-css/checkbox/dist/index-vars.css"
|
import { CoreCheckbox } from "@budibase/bbui"
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
|
|
||||||
export let field
|
export let field
|
||||||
|
@ -9,10 +9,6 @@
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
|
||||||
const onChange = event => {
|
|
||||||
fieldApi.setValue(event.target.checked)
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
|
@ -24,37 +20,12 @@
|
||||||
bind:fieldApi
|
bind:fieldApi
|
||||||
defaultValue={false}>
|
defaultValue={false}>
|
||||||
{#if fieldState}
|
{#if fieldState}
|
||||||
<div class="spectrum-FieldGroup spectrum-FieldGroup--horizontal">
|
<CoreCheckbox
|
||||||
<label class="spectrum-Checkbox" class:is-invalid={!$fieldState.valid}>
|
value={$fieldState.value}
|
||||||
<input
|
disabled={$fieldState.disabled}
|
||||||
checked={$fieldState.value}
|
error={$fieldState.error}
|
||||||
disabled={$fieldState.disabled}
|
fieldId={$fieldState.fieldId}
|
||||||
on:change={onChange}
|
on:change={e => fieldApi.setValue(e.detail)}
|
||||||
type="checkbox"
|
{text} />
|
||||||
class="spectrum-Checkbox-input"
|
|
||||||
id={$fieldState.fieldId} />
|
|
||||||
<span class="spectrum-Checkbox-box">
|
|
||||||
<svg
|
|
||||||
class="spectrum-Icon spectrum-UIIcon-Checkmark75 spectrum-Checkbox-checkmark"
|
|
||||||
focusable="false"
|
|
||||||
aria-hidden="true">
|
|
||||||
<use xlink:href="#spectrum-css-icon-Checkmark75" />
|
|
||||||
</svg>
|
|
||||||
<svg
|
|
||||||
class="spectrum-Icon spectrum-UIIcon-Dash75 spectrum-Checkbox-partialCheckmark"
|
|
||||||
focusable="false"
|
|
||||||
aria-hidden="true">
|
|
||||||
<use xlink:href="#spectrum-css-icon-Dash75" />
|
|
||||||
</svg>
|
|
||||||
</span>
|
|
||||||
<span class="spectrum-Checkbox-label">{text || 'Checkbox'}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
<style>
|
|
||||||
.spectrum-Checkbox {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
$: linkedTableId = fieldSchema?.tableId
|
$: linkedTableId = fieldSchema?.tableId
|
||||||
$: fetchRows(linkedTableId)
|
$: fetchRows(linkedTableId)
|
||||||
$: fetchTable(linkedTableId)
|
$: fetchTable(linkedTableId)
|
||||||
|
$: singleValue = flatten($fieldState?.value)?.[0]
|
||||||
|
$: multiValue = flatten($fieldState?.value) ?? []
|
||||||
|
|
||||||
const fetchTable = async id => {
|
const fetchTable = async id => {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -38,6 +40,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const flatten = values => {
|
||||||
|
if (!values) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return values.map(value => (typeof value === "object" ? value._id : value))
|
||||||
|
}
|
||||||
|
|
||||||
const getDisplayName = row => {
|
const getDisplayName = row => {
|
||||||
return row?.[tableDefinition?.primaryDisplay || "_id"] || "-"
|
return row?.[tableDefinition?.primaryDisplay || "_id"] || "-"
|
||||||
}
|
}
|
||||||
|
@ -64,7 +73,7 @@
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={multiselect ? CoreMultiselect : CoreSelect}
|
this={multiselect ? CoreMultiselect : CoreSelect}
|
||||||
{options}
|
{options}
|
||||||
value={multiselect ? $fieldState.value : $fieldState.value?.[0]}
|
value={multiselect ? multiValue : singleValue}
|
||||||
on:change={multiselect ? multiHandler : singleHandler}
|
on:change={multiselect ? multiHandler : singleHandler}
|
||||||
fieldId={$fieldState.fieldId}
|
fieldId={$fieldState.fieldId}
|
||||||
disabled={$fieldState.disabled}
|
disabled={$fieldState.disabled}
|
||||||
|
|
Loading…
Reference in New Issue