added select readonly prop and updated the disabled schema field state

This commit is contained in:
Gani Georgiev 2023-04-26 18:35:34 +03:00
parent 1967dcfeba
commit bfb38ab51e
7 changed files with 41 additions and 17 deletions

View File

@ -11,6 +11,7 @@
export let items = []; export let items = [];
export let multiple = false; export let multiple = false;
export let disabled = false; export let disabled = false;
export let readonly = false;
export let selected = multiple ? [] : undefined; export let selected = multiple ? [] : undefined;
export let toggle = multiple; // toggle option on click export let toggle = multiple; // toggle option on click
export let closable = true; // close the dropdown on option select/deselect export let closable = true; // close the dropdown on option select/deselect
@ -177,7 +178,7 @@
function onLabelClick(e) { function onLabelClick(e) {
e.stopPropagation(); e.stopPropagation();
!disabled && toggler?.toggle(); !readonly && !disabled && toggler?.toggle();
} }
onMount(() => { onMount(() => {
@ -195,9 +196,15 @@
}); });
</script> </script>
<div bind:this={container} class="select {classes}" class:multiple class:disabled> <div bind:this={container} class="select {classes}" class:multiple class:disabled class:readonly>
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div bind:this={labelDiv} tabindex={disabled ? "-1" : "0"} class="selected-container" class:disabled> <div
bind:this={labelDiv}
tabindex={disabled || readonly ? "-1" : "0"}
class="selected-container"
class:disabled
class:readonly
>
{#each CommonHelper.toArray(selected) as item, i} {#each CommonHelper.toArray(selected) as item, i}
<div class="option"> <div class="option">
{#if labelComponent} {#if labelComponent}
@ -218,13 +225,13 @@
{/if} {/if}
</div> </div>
{:else} {:else}
<div class="block txt-placeholder" class:link-hint={!disabled}> <div class="block txt-placeholder" class:link-hint={!disabled && !readonly}>
{selectPlaceholder} {selectPlaceholder}
</div> </div>
{/each} {/each}
</div> </div>
{#if !disabled} {#if !disabled && !readonly}
<Toggler <Toggler
bind:this={toggler} bind:this={toggler}
class="dropdown dropdown-block options-dropdown dropdown-left" class="dropdown dropdown-block options-dropdown dropdown-left"

View File

@ -120,7 +120,8 @@
draggable={true} draggable={true}
class="schema-field" class="schema-field"
class:required={field.required} class:required={field.required}
class:expanded={showOptions} class:expanded={interactive && showOptions}
class:deleted={field.toDelete}
class:drag-over={isDragOver} class:drag-over={isDragOver}
transition:slide|local={{ duration: 150 }} transition:slide|local={{ duration: 150 }}
on:dragstart={(e) => { on:dragstart={(e) => {

View File

@ -85,14 +85,14 @@
<div class="separator" /> <div class="separator" />
<Field <Field
class="form-field form-field-single-multiple-select {!interactive ? 'disabled' : ''}" class="form-field form-field-single-multiple-select {!interactive ? 'readonly' : ''}"
inlineError inlineError
let:uniqueId let:uniqueId
> >
<ObjectSelect <ObjectSelect
id={uniqueId} id={uniqueId}
items={isSingleOptions} items={isSingleOptions}
disabled={!interactive} readonly={!interactive}
bind:keyOfSelected={isSingle} bind:keyOfSelected={isSingle}
/> />
</Field> </Field>

View File

@ -116,7 +116,7 @@
noOptionsText="No collections found" noOptionsText="No collections found"
selectionKey="id" selectionKey="id"
items={$collections} items={$collections}
disabled={!interactive || field.id} readonly={!interactive || field.id}
bind:keyOfSelected={field.options.collectionId} bind:keyOfSelected={field.options.collectionId}
> >
<svelte:fragment slot="afterOptions"> <svelte:fragment slot="afterOptions">
@ -136,14 +136,14 @@
<div class="separator" /> <div class="separator" />
<Field <Field
class="form-field form-field-single-multiple-select {!interactive ? 'disabled' : ''}" class="form-field form-field-single-multiple-select {!interactive ? 'readonly' : ''}"
inlineError inlineError
let:uniqueId let:uniqueId
> >
<ObjectSelect <ObjectSelect
id={uniqueId} id={uniqueId}
items={isSingleOptions} items={isSingleOptions}
disabled={!interactive} readonly={!interactive}
bind:keyOfSelected={isSingle} bind:keyOfSelected={isSingle}
/> />
</Field> </Field>

View File

@ -55,7 +55,7 @@
<div class="separator" /> <div class="separator" />
<Field <Field
class="form-field required {!interactive ? 'disabled' : ''}" class="form-field required {!interactive ? 'readonly' : ''}"
inlineError inlineError
name="schema.{key}.options.values" name="schema.{key}.options.values"
let:uniqueId let:uniqueId
@ -65,7 +65,7 @@
id={uniqueId} id={uniqueId}
placeholder="Choices: eg. optionA, optionB" placeholder="Choices: eg. optionA, optionB"
required required
disabled={!interactive} readonly={!interactive}
bind:value={field.options.values} bind:value={field.options.values}
/> />
</div> </div>
@ -74,14 +74,14 @@
<div class="separator" /> <div class="separator" />
<Field <Field
class="form-field form-field-single-multiple-select {!interactive ? 'disabled' : ''}" class="form-field form-field-single-multiple-select {!interactive ? 'readonly' : ''}"
inlineError inlineError
let:uniqueId let:uniqueId
> >
<ObjectSelect <ObjectSelect
id={uniqueId} id={uniqueId}
items={isSingleOptions} items={isSingleOptions}
disabled={!interactive} readonly={!interactive}
bind:keyOfSelected={isSingle} bind:keyOfSelected={isSingle}
/> />
</Field> </Field>

View File

@ -955,6 +955,7 @@ select {
&:not(.disabled) .selected-container:hover { &:not(.disabled) .selected-container:hover {
cursor: pointer; cursor: pointer;
} }
&.readonly,
&.disabled { &.disabled {
color: var(--txtHintColor); color: var(--txtHintColor);
pointer-events: none; pointer-events: none;
@ -978,6 +979,9 @@ select {
} }
} }
} }
&.disabled {
color: var(--txtDisabledColor);
}
// dropdown // dropdown
.txt-missing { .txt-missing {

View File

@ -30,7 +30,7 @@
.separator { .separator {
width: 1px; width: 1px;
height: $minHeight; height: $minHeight;
background: var(--baseAlt2Color); background: rgba(#000, 0.06);
} }
.drag-handle-wrapper { .drag-handle-wrapper {
position: absolute; position: absolute;
@ -81,7 +81,6 @@
@include show(); @include show();
} }
} }
} }
.schema-field-options { .schema-field-options {
@ -111,4 +110,17 @@
} }
} }
} }
&.deleted {
.schema-field-header {
background: var(--bodyColor);
}
.markers,
.separator {
opacity: 0.5;
}
%input {
background: none;
box-shadow: none;
}
}
} }