UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

162 lines (145 loc) 4.19 kB
/** * Copyright © schukai GmbH 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 schukai GmbH. */ import { instanceSymbol } from "../../../constants.mjs"; import { addAttributeToken } from "../../../dom/attributes.mjs"; import { ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_ROLE, } from "../../../dom/constants.mjs"; import { CustomControl } from "../../../dom/customcontrol.mjs"; import { CustomElement, initMethodSymbol, } from "../../../dom/customelement.mjs"; import { assembleMethodSymbol, registerCustomElement, } from "../../../dom/customelement.mjs"; import { findTargetElementFromEvent } from "../../../dom/events.mjs"; import { isFunction } from "../../../types/is.mjs"; import { SegmentStyleSheet } from "./stylesheet/segment.mjs"; import { fireCustomEvent } from "../../../dom/events.mjs"; import { getLocaleOfDocument } from "../../../dom/locale.mjs"; import { addErrorAttribute } from "../../../dom/error.mjs"; export { Segment }; /** * @private * @type {symbol} */ const controlElementSymbol = Symbol("calendarElement"); /** * A Calendar segment is a part of the calendar that represents a single appointment. * * @fragments /fragments/components/time/timeline/segment * * @example /examples/components/time/timeline/segment-simple * * @since 3.112.0 * @copyright schukai GmbH * @summary A calendar segment is a part of the calendar that represents a single appointment. */ class Segment extends CustomElement { /** * This method is called by the `instanceof` operator. * @returns {symbol} */ static get [instanceSymbol]() { return Symbol.for( "@schukai/monster/components/time/appointment/segment@@instance", ); } /** * * @return {Components.Time.Calendar */ [assembleMethodSymbol]() { super[assembleMethodSymbol](); initControlReferences.call(this); initEventHandler.call(this); return this; } /** * 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 * @property {Object} labels Label definitions * @property {Object} actions Callbacks * @property {string} actions.click="throw Error" Callback when clicked * @property {Object} features Features * @property {Object} classes CSS classes * @property {boolean} disabled=false Disabled state */ get defaults() { return Object.assign({}, super.defaults, { templates: { main: getTemplate(), }, labels: { text: "Appointment", }, classes: {}, disabled: false, features: {}, actions: {}, startDate: "", calendarDays: [], calendarWeekdays: [], }); } /** * @return {string} */ static getTag() { return "monster-appointment-segment"; } /** * @return {CSSStyleSheet[]} */ static getCSSStyleSheet() { return [SegmentStyleSheet]; } } /** * @private * @return {initEventHandler} * @fires monster-calendar-clicked */ function initEventHandler() { const self = this; return this; } /** * @private * @return {void} */ function initControlReferences() { this[controlElementSymbol] = this.shadowRoot.querySelector( `[${ATTRIBUTE_ROLE}="control"]`, ); } /** * @private * @return {string} */ function getTemplate() { // language=HTML return ` <div data-monster-role="control" part="control"> <div data-monster-role="appointment" data-monster-replace="path:labels.text" part="appointment"></div> </div> `; } registerCustomElement(Segment);