UNPKG

@carbon/ibm-products-web-components

Version:
82 lines (78 loc) 2.28 kB
/** * Copyright IBM Corp. 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { __decorate } from 'tslib'; import { LitElement, nothing } from 'lit'; import { property } from 'lit/decorators.js'; import { carbonElement } from '@carbon/web-components/es/globals/decorators/carbon-element.js'; import { prefix } from '../../globals/settings.js'; import styles from './checklist.scss.js'; /** * @license * * Copyright IBM Corp. 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const blockClass = `${prefix}--checklist__chart`; /** * Clamps a value between a minimum and maximum. * If the value, min, or max is NaN, the function returns void. * */ const clamp = (value, min, max) => { if (isNaN(value) || isNaN(min) || isNaN(max)) { return; } { value = value <= max ? value : max; } { value = value >= min ? value : min; } return value; }; /** * @element c4p-checklist-chart */ let CDSChecklistChart = class CDSChecklistChart extends LitElement { constructor() { super(...arguments); /** * A number between 0 and 1 which indicates the progress of checklist */ this.value = 0; } connectedCallback() { super.connectedCallback(); this.classList.add(`${blockClass}`); } _updateChart(value) { this.style.setProperty(`--${prefix}-num-degrees`, `${clamp(value * 360, 0, 360)}deg`); } static get observedAttributes() { return ['value']; } attributeChangedCallback(name, oldValue, newValue) { if (name === 'value' && oldValue !== newValue) { this._updateChart(newValue); } } render() { return nothing; } }; CDSChecklistChart.styles = styles; __decorate([ property({ type: Number }) ], CDSChecklistChart.prototype, "value", void 0); CDSChecklistChart = __decorate([ carbonElement(`${prefix}-checklist-chart`) ], CDSChecklistChart); var CDSChecklistChart$1 = CDSChecklistChart; export { CDSChecklistChart$1 as default }; //# sourceMappingURL=checklist-chart.js.map