From d9ac7047ef10438398c7b9fba9b3baa25e335129 Mon Sep 17 00:00:00 2001 From: simonmilord Date: Mon, 17 Jun 2024 16:52:24 -0400 Subject: [PATCH] added check and getter for custom options --- .../default/lwc/quanticSort/quanticSort.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/quantic/force-app/main/default/lwc/quanticSort/quanticSort.js b/packages/quantic/force-app/main/default/lwc/quanticSort/quanticSort.js index 951f4eba92a..081ea848f9d 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticSort/quanticSort.js +++ b/packages/quantic/force-app/main/default/lwc/quanticSort/quanticSort.js @@ -96,6 +96,10 @@ export default class QuanticSort extends LightningElement { } buildOptions() { + if (this.customSortOptions.length > 0) { + return this.customSortOptions; + } + return [ { label: this.labels.relevancy, @@ -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, + }, + }; + }); + } }