Update dynamic filter component styles and remove lots of settings

This commit is contained in:
Andrew Kingston 2021-11-23 17:40:49 +00:00
parent 1e360d6873
commit 07d45d8039
3 changed files with 34 additions and 51 deletions

View File

@ -2650,7 +2650,6 @@
"name": "Dynamic Filter", "name": "Dynamic Filter",
"icon": "FilterEdit", "icon": "FilterEdit",
"showSettingsBar": true, "showSettingsBar": true,
"editable": true,
"settings": [ "settings": [
{ {
"type": "dataProvider", "type": "dataProvider",
@ -2669,34 +2668,6 @@
"key": "text", "key": "text",
"defaultValue": "Filter" "defaultValue": "Filter"
}, },
{
"type": "select",
"showInBar": true,
"label": "Button variant",
"key": "type",
"options": [
{
"label": "Primary",
"value": "primary"
}, {
"label": "Secondary",
"value": "secondary"
},
{
"label": "Action",
"value": "cta"
},
{
"label": "Warning",
"value": "warning"
},
{
"label": "Over Background",
"value": "overBackground"
}
],
"defaultValue": "primary"
},
{ {
"type": "select", "type": "select",
"label": "Button size", "label": "Button size",
@ -2721,14 +2692,6 @@
} }
], ],
"defaultValue": "M" "defaultValue": "M"
},
{
"type": "boolean",
"label": "Quiet button",
"key": "quiet",
"showInBar": true,
"barIcon": "VisibilityOff",
"barTitle": "Quiet variant"
} }
] ]
}, },

View File

@ -12,6 +12,10 @@
export let type = "primary" export let type = "primary"
export let quiet = false export let quiet = false
// For internal use only for now - not defined in the manifest
export let icon = null
export let active = false
let node let node
$: $component.editing && node?.focus() $: $component.editing && node?.focus()
@ -35,10 +39,22 @@
{disabled} {disabled}
use:styleable={$component.styles} use:styleable={$component.styles}
on:click={onClick} on:click={onClick}
contenteditable={$component.editing} contenteditable={$component.editing && !icon}
on:blur={$component.editing ? updateText : null} on:blur={$component.editing ? updateText : null}
bind:this={node} bind:this={node}
class:active
> >
{#if icon}
<svg
class:hasText={componentText?.length > 0}
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
focusable="false"
aria-hidden="true"
aria-label={icon}
>
<use xlink:href="#spectrum-icon-18-{icon}" />
</svg>
{/if}
{componentText} {componentText}
</button> </button>
@ -56,4 +72,10 @@
.spectrum-Button::after { .spectrum-Button::after {
display: none; display: none;
} }
.spectrum-Icon.hasText {
margin-right: var(--spectrum-button-primary-icon-gap);
}
.active {
color: var(--spectrum-global-color-blue-600);
}
</style> </style>

View File

@ -10,8 +10,6 @@
export let allowedFields export let allowedFields
export let text = "" export let text = ""
export let size = "M" export let size = "M"
export let type = "primary"
export let quiet = false
const component = getContext("component") const component = getContext("component")
const { builderStore, ActionTypes, getAction } = getContext("sdk") const { builderStore, ActionTypes, getAction } = getContext("sdk")
@ -31,7 +29,7 @@
) )
$: schema = dataProvider?.schema $: schema = dataProvider?.schema
$: schemaFields = getSchemaFields(schema, allowedFields) $: schemaFields = getSchemaFields(schema, allowedFields)
$: buttonText = getButtonText(text, filters) $: buttonText = text || "Filter"
// Add query extension to data provider // Add query extension to data provider
$: { $: {
@ -43,14 +41,6 @@
} }
} }
const getButtonText = (text, filters) => {
let buttonText = text || "Filter"
if (filters?.length) {
buttonText += ` (${filters.length})`
}
return buttonText
}
const getSchemaFields = (schema, allowedFields) => { const getSchemaFields = (schema, allowedFields) => {
let clonedSchema = {} let clonedSchema = {}
if (!allowedFields?.length) { if (!allowedFields?.length) {
@ -80,10 +70,18 @@
}) })
</script> </script>
<Button onClick={openEditor} text={buttonText} {size} {type} {quiet} /> <Button
onClick={openEditor}
icon="Properties"
text={buttonText}
{size}
type="secondary"
quiet
active={filters?.length > 0}
/>
<Modal bind:this={modal}> <Modal bind:this={modal}>
<ModalContent title={text} size="XL" onConfirm={updateQuery}> <ModalContent title={buttonText} size="XL" onConfirm={updateQuery}>
<FilterModal bind:filters={tmpFilters} {schemaFields} /> <FilterModal bind:filters={tmpFilters} {schemaFields} />
</ModalContent> </ModalContent>
</Modal> </Modal>