This commit is contained in:
Peter Clement 2025-01-24 13:48:00 +00:00
parent 20de1b7492
commit 7c52166d0d
10 changed files with 226 additions and 176 deletions

View File

@ -1,4 +1,4 @@
<script> <script lang="ts">
import "@spectrum-css/picker/dist/index-vars.css" import "@spectrum-css/picker/dist/index-vars.css"
import "@spectrum-css/popover/dist/index-vars.css" import "@spectrum-css/popover/dist/index-vars.css"
import "@spectrum-css/menu/dist/index-vars.css" import "@spectrum-css/menu/dist/index-vars.css"
@ -11,43 +11,61 @@
import Tags from "../../Tags/Tags.svelte" import Tags from "../../Tags/Tags.svelte"
import Tag from "../../Tags/Tag.svelte" import Tag from "../../Tags/Tag.svelte"
import ProgressCircle from "../../ProgressCircle/ProgressCircle.svelte" import ProgressCircle from "../../ProgressCircle/ProgressCircle.svelte"
import { PopoverAlignment } from "../../constants"
export let id = null export let id: string | undefined = undefined
export let disabled = false export let disabled: boolean = false
export let fieldText = "" export let fieldText: string = ""
export let fieldIcon = "" export let fieldIcon: string = ""
export let fieldColour = "" export let fieldColour: string = ""
export let isPlaceholder = false export let isPlaceholder: boolean = false
export let placeholderOption = null export let placeholderOption: string | undefined | boolean = undefined
export let options = [] export let options: any[] = []
export let isOptionSelected = () => false export let isOptionSelected = (_value: any) => false
export let isOptionEnabled = () => true export let isOptionEnabled = (_value: any) => true
export let onSelectOption = () => {} export let onSelectOption: (_value: any) => void = () => {}
export let getOptionLabel = option => option export let getOptionLabel: (_option: any, _idx?: number) => string = option =>
export let getOptionValue = option => option option
export let getOptionIcon = () => null export let getOptionValue: (_option: any, _idx?: number) => any = option =>
option
export let getOptionIcon: (
_option: any,
_idx?: number
) => string | undefined = () => undefined
export let useOptionIconImage = false export let useOptionIconImage = false
export let getOptionColour = () => null export let getOptionColour: (
export let getOptionSubtitle = () => null _option: any,
export let open = false _idx?: number
export let readonly = false ) => string | undefined = () => undefined
export let quiet = false export let getOptionSubtitle: (
export let autoWidth = false _option: any,
export let autocomplete = false _idx?: number
export let sort = false ) => string | undefined = () => undefined
export let searchTerm = null export let open: boolean = false
export let customPopoverHeight export let readonly: boolean = false
export let align = "left" export let quiet: boolean = false
export let footer = null export let autoWidth: boolean | undefined = false
export let customAnchor = null export let autocomplete: boolean = false
export let loading export let sort: boolean = false
export let onOptionMouseenter = () => {} export let searchTerm: string | null = null
export let onOptionMouseleave = () => {} export let customPopoverHeight: string | undefined = undefined
export let align: PopoverAlignment | undefined = PopoverAlignment.Left
export let footer: string | undefined = undefined
export let customAnchor: HTMLElement | undefined = undefined
export let loading: boolean = false
export let onOptionMouseenter: (
_e: MouseEvent,
_option: any
) => void = () => {}
export let onOptionMouseleave: (
_e: MouseEvent,
_option: any
) => void = () => {}
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let button let button: any
let component let component: any
$: sortedOptions = getSortedOptions(options, getOptionLabel, sort) $: sortedOptions = getSortedOptions(options, getOptionLabel, sort)
$: filteredOptions = getFilteredOptions( $: filteredOptions = getFilteredOptions(
@ -56,7 +74,7 @@
getOptionLabel getOptionLabel
) )
const onClick = e => { const onClick = (e: MouseEvent) => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
dispatch("click") dispatch("click")
@ -67,7 +85,11 @@
open = !open open = !open
} }
const getSortedOptions = (options, getLabel, sort) => { const getSortedOptions = (
options: any[],
getLabel: (_option: any) => string,
sort: boolean
) => {
if (!options?.length || !Array.isArray(options)) { if (!options?.length || !Array.isArray(options)) {
return [] return []
} }
@ -81,17 +103,21 @@
}) })
} }
const getFilteredOptions = (options, term, getLabel) => { const getFilteredOptions = (
options: any[],
term: string | null,
getLabel: (_option: any) => string
) => {
if (autocomplete && term) { if (autocomplete && term) {
const lowerCaseTerm = term.toLowerCase() const lowerCaseTerm = term.toLowerCase()
return options.filter(option => { return options.filter((option: any) => {
return `${getLabel(option)}`.toLowerCase().includes(lowerCaseTerm) return `${getLabel(option)}`.toLowerCase().includes(lowerCaseTerm)
}) })
} }
return options return options
} }
const onScroll = e => { const onScroll = (e: any) => {
const scrollPxThreshold = 100 const scrollPxThreshold = 100
const scrollPositionFromBottom = const scrollPositionFromBottom =
e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop
@ -151,18 +177,20 @@
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<Popover <Popover
anchor={customAnchor ? customAnchor : button} anchor={customAnchor ? customAnchor : button}
align={align || "left"} align={align || PopoverAlignment.Left}
{open} {open}
on:close={() => (open = false)} on:close={() => (open = false)}
useAnchorWidth={!autoWidth} useAnchorWidth={!autoWidth}
maxWidth={autoWidth ? 400 : null} maxWidth={autoWidth ? 400 : undefined}
customHeight={customPopoverHeight} customHeight={customPopoverHeight}
maxHeight={360} maxHeight={360}
> >
<div <div
class="popover-content" class="popover-content"
class:auto-width={autoWidth} class:auto-width={autoWidth}
use:clickOutside={() => (open = false)} use:clickOutside={() => {
open = false
}}
> >
{#if autocomplete} {#if autocomplete}
<Search <Search

View File

@ -1,19 +1,19 @@
<script> <script lang="ts">
import "@spectrum-css/search/dist/index-vars.css" import "@spectrum-css/search/dist/index-vars.css"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
export let value = null export let value: any = null
export let placeholder = null export let placeholder: string | undefined = undefined
export let disabled = false export let disabled = false
export let id = null export let id = null
export let updateOnChange = true export let updateOnChange = true
export let quiet = false export let quiet = false
export let inputRef export let inputRef: HTMLInputElement | undefined = undefined
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let focus = false let focus = false
const updateValue = value => { const updateValue = (value: any) => {
dispatch("change", value) dispatch("change", value)
} }
@ -21,19 +21,19 @@
focus = true focus = true
} }
const onBlur = event => { const onBlur = (event: any) => {
focus = false focus = false
updateValue(event.target.value) updateValue(event.target.value)
} }
const onInput = event => { const onInput = (event: any) => {
if (!updateOnChange) { if (!updateOnChange) {
return return
} }
updateValue(event.target.value) updateValue(event.target.value)
} }
const updateValueOnEnter = event => { const updateValueOnEnter = (event: any) => {
if (event.key === "Enter") { if (event.key === "Enter") {
updateValue(event.target.value) updateValue(event.target.value)
} }

View File

@ -1,33 +1,43 @@
<script> <script lang="ts">
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import Picker from "./Picker.svelte" import Picker from "./Picker.svelte"
import { PopoverAlignment } from "../../constants"
export let value = null export let value: any = null
export let id = null export let id: string | undefined = undefined
export let placeholder = "Choose an option" export let placeholder: string | boolean = "Choose an option"
export let disabled = false export let disabled: boolean = false
export let options = [] export let options: any[] = []
export let getOptionLabel = option => option export let getOptionLabel = (option: any) => option
export let getOptionValue = option => option export let getOptionValue = (_option: any, _idx: number | undefined) =>
export let getOptionIcon = () => null _option
export let getOptionColour = () => null export let getOptionIcon: (
export let getOptionSubtitle = () => null _option: any,
export let compare = null _idx?: number
) => string | undefined = () => undefined
export let getOptionColour: (
_option: any,
_idx?: number
) => string | undefined = () => undefined
export let getOptionSubtitle: (
_option: any,
_idx?: number
) => string | undefined = () => undefined
export let compare: any = null
export let useOptionIconImage = false export let useOptionIconImage = false
export let isOptionEnabled export let isOptionEnabled
export let readonly = false export let readonly: boolean = false
export let quiet = false export let quiet: boolean = false
export let autoWidth = false export let autoWidth: boolean = false
export let autocomplete = false export let autocomplete: boolean = false
export let sort = false export let sort: boolean = false
export let align export let align: PopoverAlignment | undefined = PopoverAlignment.Left
export let footer = null export let footer: string | undefined = undefined
export let open = false export let open: boolean = false
export let tag = null export let searchTerm: string | undefined = undefined
export let searchTerm = null export let loading: boolean | undefined = undefined
export let loading
export let onOptionMouseenter = () => {} export let onOptionMouseenter = () => {}
export let onOptionMouseleave = () => {} export let onOptionMouseleave = () => {}
export let customPopoverHeight: string | undefined = undefined
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -35,24 +45,28 @@
$: fieldIcon = getFieldAttribute(getOptionIcon, value, options) $: fieldIcon = getFieldAttribute(getOptionIcon, value, options)
$: fieldColour = getFieldAttribute(getOptionColour, value, options) $: fieldColour = getFieldAttribute(getOptionColour, value, options)
function compareOptionAndValue(option, value) { function compareOptionAndValue(option: any, value: any) {
return typeof compare === "function" return typeof compare === "function"
? compare(option, value) ? compare(option, value)
: option === value : option === value
} }
const getFieldAttribute = (getAttribute, value, options) => { const getFieldAttribute = (getAttribute: any, value: any, options: any) => {
// Wait for options to load if there is a value but no options // Wait for options to load if there is a value but no options
if (!options?.length) { if (!options?.length) {
return "" return ""
} }
const index = options.findIndex((option, idx) => const index = options.findIndex((option: any, idx: number) =>
compareOptionAndValue(getOptionValue(option, idx), value) compareOptionAndValue(getOptionValue(option, idx), value)
) )
return index !== -1 ? getAttribute(options[index], index) : null return index !== -1 ? getAttribute(options[index], index) : null
} }
const getFieldText = (value, options, placeholder) => { const getFieldText = (
value: any,
options: any,
placeholder: boolean | string
) => {
if (value == null || value === "") { if (value == null || value === "") {
// Explicit false means use no placeholder and allow an empty fields // Explicit false means use no placeholder and allow an empty fields
if (placeholder === false) { if (placeholder === false) {
@ -67,7 +81,7 @@
) )
} }
const selectOption = value => { const selectOption = (value: any) => {
dispatch("change", value) dispatch("change", value)
open = false open = false
} }
@ -98,14 +112,14 @@
{isOptionEnabled} {isOptionEnabled}
{autocomplete} {autocomplete}
{sort} {sort}
{tag}
{onOptionMouseenter} {onOptionMouseenter}
{onOptionMouseleave} {onOptionMouseleave}
isPlaceholder={value == null || value === ""} isPlaceholder={value == null || value === ""}
placeholderOption={placeholder === false placeholderOption={placeholder === false
? null ? undefined
: placeholder || "Choose an option"} : placeholder || "Choose an option"}
isOptionSelected={option => compareOptionAndValue(option, value)} isOptionSelected={option => compareOptionAndValue(option, value)}
onSelectOption={selectOption} onSelectOption={selectOption}
{loading} {loading}
{customPopoverHeight}
/> />

View File

@ -1,25 +1,25 @@
<script> <script lang="ts">
import "@spectrum-css/textfield/dist/index-vars.css" import "@spectrum-css/textfield/dist/index-vars.css"
import { createEventDispatcher, onMount, tick } from "svelte" import { createEventDispatcher, onMount, tick } from "svelte"
export let value = null export let value = null
export let placeholder = null export let placeholder: string | undefined = undefined
export let type = "text" export let type = "text"
export let disabled = false export let disabled = false
export let id = null export let id = null
export let readonly = false export let readonly = false
export let updateOnChange = true export let updateOnChange = true
export let quiet = false export let quiet = false
export let align export let align: "left" | "right" | "center" | undefined = undefined
export let autofocus = false export let autofocus = false
export let autocomplete = null export let autocomplete: boolean | undefined
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let field let field: any
let focus = false let focus = false
const updateValue = newValue => { const updateValue = (newValue: any) => {
if (readonly || disabled) { if (readonly || disabled) {
return return
} }
@ -37,7 +37,7 @@
focus = true focus = true
} }
const onBlur = event => { const onBlur = (event: any) => {
if (readonly || disabled) { if (readonly || disabled) {
return return
} }
@ -45,14 +45,14 @@
updateValue(event.target.value) updateValue(event.target.value)
} }
const onInput = event => { const onInput = (event: any) => {
if (readonly || !updateOnChange || disabled) { if (readonly || !updateOnChange || disabled) {
return return
} }
updateValue(event.target.value) updateValue(event.target.value)
} }
const updateValueOnEnter = event => { const updateValueOnEnter = (event: any) => {
if (readonly || disabled) { if (readonly || disabled) {
return return
} }
@ -61,13 +61,20 @@
} }
} }
const getInputMode = type => { const getInputMode = (type: any) => {
if (type === "bigint") { if (type === "bigint") {
return "numeric" return "numeric"
} }
return type === "number" ? "decimal" : "text" return type === "number" ? "decimal" : "text"
} }
$: autocompleteValue =
typeof autocomplete === "boolean"
? autocomplete
? "on"
: "off"
: undefined
onMount(async () => { onMount(async () => {
if (disabled) return if (disabled) return
focus = autofocus focus = autofocus
@ -104,7 +111,7 @@
class="spectrum-Textfield-input" class="spectrum-Textfield-input"
style={align ? `text-align: ${align};` : ""} style={align ? `text-align: ${align};` : ""}
inputmode={getInputMode(type)} inputmode={getInputMode(type)}
{autocomplete} autocomplete={autocompleteValue}
/> />
</div> </div>

View File

@ -1,14 +1,14 @@
<script> <script lang="ts">
import "@spectrum-css/fieldlabel/dist/index-vars.css" import "@spectrum-css/fieldlabel/dist/index-vars.css"
import FieldLabel from "./FieldLabel.svelte" import FieldLabel from "./FieldLabel.svelte"
import Icon from "../Icon/Icon.svelte" import Icon from "../Icon/Icon.svelte"
export let id = null export let id: string | undefined = undefined
export let label = null export let label: string | undefined = undefined
export let labelPosition = "above" export let labelPosition: string = "above"
export let error = null export let error: string | undefined = undefined
export let helpText = null export let helpText: string | undefined = undefined
export let tooltip = "" export let tooltip: string | undefined = undefined
</script> </script>
<div class="spectrum-Form-item" class:above={labelPosition === "above"}> <div class="spectrum-Form-item" class:above={labelPosition === "above"}>

View File

@ -1,24 +1,24 @@
<script> <script lang="ts">
import Field from "./Field.svelte" import Field from "./Field.svelte"
import TextField from "./Core/TextField.svelte" import TextField from "./Core/TextField.svelte"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
export let value = null export let value: any = undefined
export let label = null export let label: string | undefined = undefined
export let labelPosition = "above" export let labelPosition = "above"
export let placeholder = null export let placeholder: string | undefined = undefined
export let type = "text" export let type = "text"
export let disabled = false export let disabled = false
export let readonly = false export let readonly = false
export let error = null export let error = null
export let updateOnChange = true export let updateOnChange = true
export let quiet = false export let quiet = false
export let autofocus export let autofocus: boolean | undefined = undefined
export let autocomplete export let autocomplete: boolean | undefined = undefined
export let helpText = null export let helpText = null
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = (e: any) => {
value = e.detail value = e.detail
dispatch("change", e.detail) dispatch("change", e.detail)
} }
@ -27,7 +27,6 @@
<Field {helpText} {label} {labelPosition} {error}> <Field {helpText} {label} {labelPosition} {error}>
<TextField <TextField
{updateOnChange} {updateOnChange}
{error}
{disabled} {disabled}
{readonly} {readonly}
{value} {value}

View File

@ -1,44 +1,44 @@
<script> <script lang="ts">
import Field from "./Field.svelte" import Field from "./Field.svelte"
import Select from "./Core/Select.svelte" import Select from "./Core/Select.svelte"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { PopoverAlignment } from "../constants"
export let value = null export let value: string | undefined = undefined
export let label = undefined export let label: string | undefined = undefined
export let disabled = false export let disabled: boolean = false
export let readonly = false export let readonly: boolean = false
export let labelPosition = "above" export let labelPosition: string = "above"
export let error = null export let error: string | undefined = undefined
export let placeholder = "Choose an option" export let placeholder: string = "Choose an option"
export let options = [] export let options: any[] = []
export let getOptionLabel = option => extractProperty(option, "label") export let getOptionLabel = (option: any) => extractProperty(option, "label")
export let getOptionValue = option => extractProperty(option, "value") export let getOptionValue = (option: any) => extractProperty(option, "value")
export let getOptionSubtitle = option => option?.subtitle export let getOptionSubtitle = (option: any) => option?.subtitle
export let getOptionIcon = option => option?.icon export let getOptionIcon = (option: any) => option?.icon
export let getOptionColour = option => option?.colour export let getOptionColour = (option: any) => option?.colour
export let useOptionIconImage = false export let useOptionIconImage = false
export let isOptionEnabled = undefined export let isOptionEnabled = undefined
export let quiet = false export let quiet: boolean = false
export let autoWidth = false export let autoWidth: boolean = false
export let sort = false export let sort: boolean = false
export let tooltip = "" export let tooltip: string | undefined = undefined
export let autocomplete = false export let autocomplete: boolean = false
export let customPopoverHeight = undefined export let customPopoverHeight: string | undefined = undefined
export let align = undefined export let align: PopoverAlignment | undefined = PopoverAlignment.Left
export let footer = null export let footer: string | undefined = undefined
export let tag = null export let helpText: string | undefined = undefined
export let helpText = null export let compare: any = undefined
export let compare = undefined
export let onOptionMouseenter = () => {} export let onOptionMouseenter = () => {}
export let onOptionMouseleave = () => {} export let onOptionMouseleave = () => {}
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = (e: any) => {
value = e.detail value = e.detail
dispatch("change", e.detail) dispatch("change", e.detail)
} }
const extractProperty = (value, property) => { const extractProperty = (value: any, property: any) => {
if (value && typeof value === "object") { if (value && typeof value === "object") {
return value[property] return value[property]
} }
@ -49,7 +49,6 @@
<Field {helpText} {label} {labelPosition} {error} {tooltip}> <Field {helpText} {label} {labelPosition} {error} {tooltip}>
<Select <Select
{quiet} {quiet}
{error}
{disabled} {disabled}
{readonly} {readonly}
{value} {value}
@ -68,7 +67,6 @@
{isOptionEnabled} {isOptionEnabled}
{autocomplete} {autocomplete}
{customPopoverHeight} {customPopoverHeight}
{tag}
{compare} {compare}
{onOptionMouseenter} {onOptionMouseenter}
{onOptionMouseleave} {onOptionMouseleave}

View File

@ -1,25 +1,25 @@
<script> <script lang="ts">
import "@spectrum-css/statuslight" import "@spectrum-css/statuslight"
export let size = "M" export let size: string = "M"
export let celery = false export let celery: boolean = false
export let yellow = false export let yellow: boolean = false
export let fuchsia = false export let fuchsia: boolean = false
export let indigo = false export let indigo: boolean = false
export let seafoam = false export let seafoam: boolean = false
export let chartreuse = false export let chartreuse: boolean = false
export let magenta = false export let magenta: boolean = false
export let purple = false export let purple: boolean = false
export let neutral = false export let neutral: boolean = false
export let info = false export let info: boolean = false
export let positive = false export let positive: boolean = false
export let notice = false export let notice: boolean = false
export let negative = false export let negative: boolean = false
export let disabled = false export let disabled: boolean = false
export let active = false export let active: boolean = false
export let color = null export let color: string | undefined = undefined
export let square = false export let square: boolean = false
export let hoverable = false export let hoverable: boolean = false
</script> </script>
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->

View File

@ -1,4 +1,4 @@
<script> <script lang="ts">
import { Icon, Input, Drawer, Button } from "@budibase/bbui" import { Icon, Input, Drawer, Button } from "@budibase/bbui"
import { import {
readableToRuntimeBinding, readableToRuntimeBinding,
@ -10,25 +10,25 @@
import { builderStore } from "@/stores/builder" import { builderStore } from "@/stores/builder"
export let panel = ClientBindingPanel export let panel = ClientBindingPanel
export let value = "" export let value: any = ""
export let bindings = [] export let bindings: any[] = []
export let title export let title: string | undefined = undefined
export let placeholder export let placeholder: string | undefined = undefined
export let label export let label: string | undefined = undefined
export let disabled = false export let disabled: boolean = false
export let allowHBS = true export let allowHBS: boolean = true
export let allowJS = true export let allowJS: boolean = true
export let allowHelpers = true export let allowHelpers: boolean = true
export let updateOnChange = true export let updateOnChange: boolean = true
export let key export let key: string | null = null
export let disableBindings = false export let disableBindings: boolean = false
export let forceModal = false export let forceModal: boolean = false
export let context = null export let context = null
export let autocomplete export let autocomplete: boolean | undefined = undefined
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let bindingDrawer let bindingDrawer: any
let currentVal = value let currentVal = value
$: readableValue = runtimeToReadableBinding(bindings, value) $: readableValue = runtimeToReadableBinding(bindings, value)
@ -38,7 +38,7 @@
const saveBinding = () => { const saveBinding = () => {
onChange(tempValue) onChange(tempValue)
onBlur() onBlur()
builderStore.propertyFocus() builderStore.propertyFocus(null)
bindingDrawer.hide() bindingDrawer.hide()
} }
@ -46,7 +46,7 @@
save: saveBinding, save: saveBinding,
}) })
const onChange = value => { const onChange = (value: any) => {
currentVal = readableToRuntimeBinding(bindings, value) currentVal = readableToRuntimeBinding(bindings, value)
dispatch("change", currentVal) dispatch("change", currentVal)
} }
@ -55,8 +55,8 @@
dispatch("blur", currentVal) dispatch("blur", currentVal)
} }
const onDrawerHide = e => { const onDrawerHide = (e: any) => {
builderStore.propertyFocus() builderStore.propertyFocus(null)
dispatch("drawerHide", e.detail) dispatch("drawerHide", e.detail)
} }
</script> </script>

View File

@ -265,7 +265,7 @@
</div> </div>
</div> </div>
{/if} {/if}
<div style="opacity: 0.5; "> <div class="link-opacity">
<Link <Link
href="https://docs.budibase.com/docs/app-state" href="https://docs.budibase.com/docs/app-state"
target="_blank" target="_blank"
@ -329,4 +329,8 @@
align-items: flex-start; align-items: flex-start;
gap: var(--spacing-xs); gap: var(--spacing-xs);
} }
.link-opacity {
opacity: 0.5;
}
</style> </style>