@schukai/monster
Version:
Monster is a simple library for creating fast, robust and lightweight websites.
114 lines (105 loc) • 2.79 kB
JavaScript
/**
* Copyright © Volker Schukai and all contributing authors, {{copyRightYear}}. All rights reserved.
* Node module: @schukai/monster
*
* This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
* The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
*
* For those who do not wish to adhere to the AGPLv3, a commercial license is available.
* Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
* For more information about purchasing a commercial license, please contact Volker Schukai.
*
* SPDX-License-Identifier: AGPL-3.0
*/
import { instanceSymbol } from "../../constants.mjs";
import { registerCustomElement } from "../../dom/customelement.mjs";
import { FilterButtonStyleSheet } from "./stylesheet/filter-button.mjs";
import { ToggleButton } from "../host/toggle-button.mjs";
import { getLocaleOfDocument } from "../../dom/locale.mjs";
export { FilterButton };
/**
* A FilterButton is a button that can be used to show the filter.
*
* @copyright Volker Schukai
* @summary A Button that can be used to show the filter.
*/
class FilterButton extends ToggleButton {
/**
* This method is called by the `instanceof` operator.
* @return {symbol}
*/
static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/components/filter-button@@instance");
}
/**
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
*
* The individual configuration values can be found in the table.
*
* @property {Object} templates Template definitions
* @property {string} templates.main Main template
*/
get defaults() {
return Object.assign({}, super.defaults, {
labels: getTranslations(),
});
}
/**
* @return {string}
*/
static getTag() {
return "monster-datatable-filter-button";
}
/**
* @return {CSSStyleSheet[]}
*/
static getCSSStyleSheet() {
const styles = super.getCSSStyleSheet();
styles.push(FilterButtonStyleSheet);
return styles;
}
}
function getTranslations() {
const locale = getLocaleOfDocument();
switch (locale.language) {
case "de":
return {
button: "Filtern",
};
case "fr":
return {
button: "Filtrer",
};
case "sp":
return {
button: "Filtrar",
};
case "it":
return {
button: "Filtra",
};
case "pl":
return {
button: "Filtruj",
};
case "no":
return {
button: "Filtrer",
};
case "dk":
return {
button: "Filtrér",
};
case "sw":
return {
button: "Filtrera",
};
default:
case "en":
return {
button: "Filter",
};
}
}
registerCustomElement(FilterButton);