Skip to content

Commit

Permalink
Fix selectable examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 13, 2024
1 parent a5d6c7e commit d082a62
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 31 deletions.
10 changes: 5 additions & 5 deletions panel/lab/components/items/1_list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<k-items :items="items" />
</k-lab-example>
<k-lab-example label="Selectable">
<k-items :items="selectableItems" @select="onSelect" />
<k-items :items="selectableItems" :selectable="true" @select="onSelect" />
<br />
<k-code>Selected: {{ selected.join(", ") }}</k-code>
</k-lab-example>
Expand Down Expand Up @@ -32,11 +32,11 @@ export default {
}
},
methods: {
onSelect(event, item, index) {
if (event.target.checked) {
this.selected.push(index);
} else {
onSelect(item, index) {
if (this.selected.includes(index)) {
this.selected = this.selected.filter((i) => i !== index);
} else {
this.selected.push(index);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions panel/lab/components/items/2_cards/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<k-items :items="items" layout="cards" />
</k-lab-example>
<k-lab-example label="Selectable">
<k-items :items="selectableItems" layout="cards" @select="onSelect" />
<k-items
:items="selectableItems"
:selectable="true"
layout="cards"
@select="onSelect"
/>
<br />
<k-code>Selected: {{ selected.join(", ") }}</k-code>
</k-lab-example>
Expand Down Expand Up @@ -32,11 +37,11 @@ export default {
}
},
methods: {
onSelect(event, item, index) {
if (event.target.checked) {
this.selected.push(index);
} else {
onSelect(item, index) {
if (this.selected.includes(index)) {
this.selected = this.selected.filter((i) => i !== index);
} else {
this.selected.push(index);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions panel/lab/components/items/3_cardlets/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<k-items :items="items" layout="cardlets" />
</k-lab-example>
<k-lab-example label="Selectable">
<k-items :items="selectableItems" layout="cardlets" @select="onSelect" />
<k-items
:items="selectableItems"
:selectable="true"
layout="cardlets"
@select="onSelect"
/>
<br />
<k-code>Selected: {{ selected.join(", ") }}</k-code>
</k-lab-example>
Expand Down Expand Up @@ -32,11 +37,11 @@ export default {
}
},
methods: {
onSelect(event, item, index) {
if (event.target.checked) {
this.selected.push(index);
} else {
onSelect(item, index) {
if (this.selected.includes(index)) {
this.selected = this.selected.filter((i) => i !== index);
} else {
this.selected.push(index);
}
}
}
Expand Down
68 changes: 53 additions & 15 deletions panel/lab/components/items/4_table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,71 @@
<k-lab-examples>
<k-lab-example label="table">
<k-items
:columns="{
image: {
label: '',
type: 'image',
width: 'var(--table-row-height)'
},
text: {
label: 'Text',
type: 'text'
},
info: {
label: 'Info',
type: 'text'
}
}"
:columns="columns"
:items="items"
:sortable="true"
layout="table"
/>
</k-lab-example>
<k-lab-example label="Selectable">
<k-items
:columns="columns"
:items="selectableItems"
:selectable="true"
layout="table"
@select="onSelect"
/>
<br />
<k-code>Selected: {{ selected.join(", ") }}</k-code>
</k-lab-example>
</k-lab-examples>
</template>

<script>
export default {
props: {
items: Array
},
data() {
return {
selected: []
};
},
computed: {
columns() {
return {
image: {
label: "",
type: "image",
width: "var(--table-row-height)"
},
text: {
label: "Text",
type: "text"
},
info: {
label: "Info",
type: "text"
}
};
},
selectableItems() {
return this.items.map((item) => {
return {
...item,
selectable: true
};
});
}
},
methods: {
onSelect(item, index) {
if (this.selected.includes(index)) {
this.selected = this.selected.filter((i) => i !== index);
} else {
this.selected.push(index);
}
}
}
};
</script>
2 changes: 1 addition & 1 deletion panel/lab/components/items/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

return [
'docs' => 'k-items',
'items' => A::map(range(0, 20), function ($item) {
'items' => A::map(range(0, 10), function ($item) {
return [
'text' => 'This is item ' . $item,
'info' => 'Some info text',
Expand Down

0 comments on commit d082a62

Please sign in to comment.