Skip to content

Commit

Permalink
feat: add default value and clear action
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonpixel committed Aug 21, 2023
1 parent 81085a9 commit 54d63fd
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 222 deletions.
17 changes: 17 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"key": "label",
"label": "Label column name"
},
{
"type": "text",
"key": "defaultValue",
"label": "Default value"
},
{
"type": "boolean",
"key": "multiple",
Expand Down Expand Up @@ -54,6 +59,18 @@
"type": "object"
}
]
},
{
"type": "event",
"label": "On Clear select",
"key": "onClear",
"context": [
{
"label": "Item removed",
"key": "data",
"type": "object"
}
]
}
]
}
Expand Down
35 changes: 23 additions & 12 deletions src/Component.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<script>
import { getContext } from "svelte";
import Select from 'svelte-select';
import { onMount } from "svelte";
import { getContext } from "svelte"
import Select from 'svelte-select'
import { onMount } from "svelte"
const { styleable } = getContext("sdk");
const component = getContext("component");
const { styleable } = getContext("sdk")
const component = getContext("component")
export let multiple;
export let dataProvider
export let label = ''
export let disable
export let selectEvent
export let placeholder
export let placeholderAlwaysShow
export let defaultValue
export let onClear
let items = []
async function fetchData() {
try {
const response = dataProvider;
items = response?.rows?.map((item, index)=>{
console.log(item)
return {
value: item[label],
label: item[label],
Expand All @@ -36,7 +39,6 @@
console.log(label, 'changed value', placeholder)
fetchData()
}
onMount(()=>{
fetchData()
Expand All @@ -46,28 +48,37 @@
const selectedValue = event.detail
let itemSend = []
console.log(multiple)
if(multiple){
const result = selectedValue?.map((item)=>{
return {
...item?.item
}
})
itemSend = result
console.log(result, 'result values')
}else{
itemSend = selectedValue?.item
}
const dataSend = JSON.parse(JSON.stringify(itemSend))
console.log(dataSend)
await selectEvent({
data: dataSend
})
}
async function handleClear(item){
console.log(item.detail)
const dataSend = JSON.parse(JSON.stringify(item.detail))
await onClear({
data: dataSend
})
}
</script>
<div use:styleable={$component.styles}>
<Select disabled={disable} placeholderAlwaysShow={placeholderAlwaysShow} {items} placeholder={placeholder} multiple={multiple} class="foo bar" on:change={handleSelectChange} />
</div>
<Select on:clear={handleClear} value={defaultValue} disabled={disable} placeholderAlwaysShow={placeholderAlwaysShow} {items} placeholder={placeholder} multiple={multiple} class="foo bar" on:change={handleSelectChange} />
</div>
Loading

0 comments on commit 54d63fd

Please sign in to comment.