adding label for selected counter, adding selected default

main
HerrHase 6 days ago
parent 680ab8b152
commit 4d9be381d1

@ -42,6 +42,7 @@ Default Options for Start
import observable from '@riotjs/observable' import observable from '@riotjs/observable'
let store = observable({ let store = observable({
locations: [{ locations: [{
'label' : 'A', 'label' : 'A',
'value' : 'a' 'value' : 'a'
@ -74,23 +75,35 @@ let store = observable({
'value' : 'j' 'value' : 'j'
}], }],
query(value) { queryOptions(value) {
if (value !== undefined) { if (value !== undefined) {
const results = [] const results = []
// run through locations and check string contains value
for (let i = 0; i < this.locations.length; i++) { for (let i = 0; i < this.locations.length; i++) {
if (this.locations[i].value.includes(value)) { if (this.locations[i].value.includes(value)) {
results.push(this.locations[i]) results.push(this.locations[i])
} }
} }
this.trigger('update', results) this.trigger('update.options', results)
} else { } else {
this.trigger('update.options', this.locations)
}
},
querySelected(values) {
const results = []
// if value is undefined, adding all locations for (let i = 0; i < values.length; i++) {
this.trigger('update', this.locations) for (let j = 0; j < this.locations.length; j++) {
if (this.locations[j].value === values[i]) {
results.push(this.locations[j])
}
}
} }
this.trigger('update.selected', results)
} }
}) })
``` ```

@ -1,5 +1,5 @@
{ {
"/example/js/spritemap.js": "/example/js/spritemap.js?version=7ce719c9e00cdc31c694d971b9a5e812", "/example/js/spritemap.js": "/example/js/spritemap.js?version=7ce719c9e00cdc31c694d971b9a5e812",
"/example/js/example.js": "/example/js/example.js?version=2451e89d416b448c318a4c3866f1ebf8", "/example/js/example.js": "/example/js/example.js?version=d36f184da8866862da78caa577eeac1b",
"/example/css/styles.css": "/example/css/styles.css?version=aa01e6a7dccff39e3f40dcf35c9e9576" "/example/css/styles.css": "/example/css/styles.css?version=ba6581d3fd3989f7bda152d185e7a2ef"
} }

@ -2266,6 +2266,10 @@ svg.field-choice__checked {
* *
*/ */
.justify-content-end {
justify-content: end;
}
.field-select__options-panel { .field-select__options-panel {
overflow-x: scroll; overflow-x: scroll;
max-height: 15vh; max-height: 15vh;

@ -47,7 +47,13 @@
<div class="field-group"> <div class="field-group">
<label class="field-label"> <label class="field-label">
Locations (Multiple + Filter) Locations (Multiple + Filter)
<tiny-field-select-api multiple searchable name="location" placeholder-filter="Filter Items"></tiny-field-select-api> <tiny-field-select-api multiple searchable name="location"></tiny-field-select-api>
</label>
</div>
<div class="field-group">
<label class="field-label">
Locations (Multiple + Default)
<tiny-field-select-default multiple name="location"></tiny-field-select-default>
</label> </label>
</div> </div>
</form> </form>
@ -94,6 +100,11 @@
riot.mount('tiny-field-select-api', { riot.mount('tiny-field-select-api', {
store: LocationStore store: LocationStore
}) })
riot.mount('tiny-field-select-default', {
store: LocationDefaultStore,
selected: [ 'f', 'd' ]
})
}) })
</script> </script>

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{ {
"name": "@tiny-components/select", "name": "@tiny-components/select",
"version": "0.1.0", "version": "0.2.0",
"description": "Select with filter for Desktop and Mobile", "description": "Select with filter for Desktop and Mobile",
"repository": { "repository": {
"type": "git", "type": "git",

@ -37,7 +37,7 @@ window.LocationStore = observable({
'value' : 'j' 'value' : 'j'
}], }],
query(value) { queryOptions(value) {
if (value !== undefined) { if (value !== undefined) {
const results = [] const results = []
@ -47,12 +47,94 @@ window.LocationStore = observable({
} }
} }
this.trigger('update', results) this.trigger('update.options', results)
} else { } else {
this.trigger('update', this.locations) this.trigger('update.options', this.locations)
} }
},
querySelected(values) {
const results = []
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < this.locations.length; j++) {
if (this.locations[j].value === values[i]) {
results.push(this.locations[j])
}
}
}
this.trigger('update.selected', results)
}
})
window.LocationDefaultStore = observable({
locations: [{
'label' : 'A',
'value' : 'a'
},{
'label' : 'B',
'value' : 'b'
},{
'label' : 'C',
'value' : 'c'
},{
'label' : 'D',
'value' : 'd'
},{
'label' : 'E',
'value' : 'e'
},{
'label' : 'F',
'value' : 'f'
},{
'label' : 'G',
'value' : 'g'
},{
'label' : 'H',
'value' : 'h'
},{
'label' : 'I',
'value' : 'i'
},{
'label' : 'J',
'value' : 'j'
}],
queryOptions(value) {
if (value !== undefined) {
const results = []
for (let i = 0; i < this.locations.length; i++) {
if (this.locations[i].value.includes(value)) {
results.push(this.locations[i])
}
}
this.trigger('update.options', results)
} else {
this.trigger('update.options', this.locations)
}
},
querySelected(values) {
const results = []
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < this.locations.length; j++) {
if (this.locations[j].value === values[i]) {
results.push(this.locations[j])
}
}
}
this.trigger('update.selected', results)
} }
}) })
riot.register('tiny-field-select', Select) riot.register('tiny-field-select', Select)
riot.register('tiny-field-select-api', Select) riot.register('tiny-field-select-api', Select)
riot.register('tiny-field-select-default', Select)

@ -13,6 +13,11 @@
</button> </button>
</div> </div>
<div class="panel"> <div class="panel">
<div class="bar justify-content-end">
<div class="bar__end">
{ state.selected.length } / { state.options.length } &#128455;
</div>
</div>
<div class="field-select__options-panel"> <div class="field-select__options-panel">
<ul class="field-select__options-list"> <ul class="field-select__options-list">
<li class="{ getItemClasses(['field-select__options-item'], option) }" each={ option in state.options } onclick={ (event) => { handleToggle(event, option) } }> <li class="{ getItemClasses(['field-select__options-item'], option) }" each={ option in state.options } onclick={ (event) => { handleToggle(event, option) } }>
@ -81,7 +86,7 @@
// if store update, add data to options // if store update, add data to options
if (this.props.store) { if (this.props.store) {
this.props.store.on('update', (data) => { this.props.store.on('update.options', (data) => {
if (this.state.selected.length > 0) { if (this.state.selected.length > 0) {
for (let i = 0; i < this.state.selected.length; i++) { for (let i = 0; i < this.state.selected.length; i++) {
@ -104,7 +109,16 @@
this.update() this.update()
}) })
this.props.store.query() this.props.store.queryOptions()
if (this.props.selected) {
this.props.store.on('update.selected', (data) => {
this.state.selected = data
this.update()
})
this.props.store.querySelected(this.props.selected)
}
} }
// getting closet form-element and add reset // getting closet form-element and add reset
@ -134,7 +148,7 @@
handleResetSearchable(event) { handleResetSearchable(event) {
event.target.previousElementSibling.value = '' event.target.previousElementSibling.value = ''
this.state.query = '' this.state.query = ''
this.props.store.query(this.state.query) this.props.store.queryOptions(this.state.query)
}, },
/** /**
@ -143,7 +157,7 @@
*/ */
handleOnKeyUp(event) { handleOnKeyUp(event) {
this.state.query = event.target.value.trim() this.state.query = event.target.value.trim()
this.props.store.query(this.state.query) this.props.store.queryOptions(this.state.query)
}, },
/** /**

@ -1,3 +1,7 @@
.justify-content-end {
justify-content: end;
}
.field-select { .field-select {
&__options-panel { &__options-panel {

Loading…
Cancel
Save