Skip to content

Commit

Permalink
added check and getter for custom options
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMilord committed Jun 17, 2024
1 parent b8c10fe commit d9ac704
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export default class QuanticSort extends LightningElement {
}

buildOptions() {
if (this.customSortOptions.length > 0) {
return this.customSortOptions;
}

return [
{
label: this.labels.relevancy,
Expand Down Expand Up @@ -150,4 +154,31 @@ export default class QuanticSort extends LightningElement {
get value() {
return this.state?.sortCriteria;
}

/**
* Returns an array of custom sort options passed via slots.
* @returns {SortOption[]} The specified custom sort options.
*/
get customSortOptions() {
const elements = Array.from(this.querySelectorAll('c-quantic-sort-option'));
if (elements.length === 0) {
return [];
}
return elements.map((element) => {
return {
// @ts-ignore
label: element.label,
// @ts-ignore
value: element.value,
criterion: {
// @ts-ignore
by: element.criterion.by,
// @ts-ignore
order: element.criterion.order,
// @ts-ignore
field: element.criterion.field,
},
};
});
}
}

0 comments on commit d9ac704

Please sign in to comment.