// content automatically generated by `generate-icons.js` begins import { Component, Prop, h, Watch, State } from '@stencil/core'; import { IconWithColour } from './icon.interface'; import { IconSize, IconColour, IconColours } from './icon.types'; import { ConsoleMessageClass } from '../../utils/console-message/console-message'; import { validateValueAgainstArray } from '../../utils/validation/validation-functions'; import validateColor from 'validate-color'; @Component({ tag: 'ontario-icon-timer', styleUrl: 'ontario-icon.scss', shadow: true, }) export class OntarioIconTimer implements IconWithColour { /** * The icon width will autogenerate the height since the icons are in square format, thus preserving * the aspect ratio. */ @Prop() iconWidth: IconSize = 24; /** * Mutable variable, for internal use only. * Set the icon's width depending on validation result. */ @State() iconWidthState: number; /** * Whether the icon is decorative and should be hidden from assistive technologies. * When set to true, the icon will have aria-hidden="true" and role="img" will be removed from the SVG element. * When set to false (default), the icon is exposed to assistive technologies with role="img". * * @default false */ @Prop() isDecorative: boolean = false; /** * Watch for changes in the `iconWidth` variable for validation purpose. * If the user input is not a number or is a negative number then `iconWidth` will be set to its default (24). */ @Watch('iconWidth') validateWidth() { if (isNaN(this.iconWidth) || (!isNaN(this.iconWidth) && this.iconWidth <= 0)) { const message = new ConsoleMessageClass(); message .addDesignSystemTag() .addMonospaceText(' icon-width ') .addRegularText('on') .addMonospaceText(' ') .addRegularText( `${isNaN(this.iconWidth) ? 'was set to a non-numeric value' : 'was set to a negative number'}; only a positive number is allowed. The default size of`, ) .addMonospaceText(' 24px ') .addRegularText('was assumed.') .printMessage(); this.iconWidthState = 24; } else { this.iconWidthState = this.iconWidth; } } /** * Set the icon's colour. */ @Prop() colour: IconColour = 'black'; /** * Mutable variable, for internal use only. * Set the icon's colour based on validation result. */ @State() iconColourState: string; /** * Mutable variable, for internal use only. * Set the icon's colour based on validation result. */ @State() iconCustomColourState: string; /** * Watch for changes in the `colour` variable for validation purpose. * If the user input doesn't match one of the enum values then `colour` will be set to its default (`black`). * If a match is found in one of the enum values then `colour` will be set to the matching enum value. */ @Watch('colour') validateColour() { const isValid = validateValueAgainstArray(this.colour, IconColours); if (isValid) { this.iconColourState = this.colour; } else { if (validateColor(this.colour)) { this.iconCustomColourState = this.colour; } else { this.iconColourState = this.warnDefaultColour(); } } } /** * Print the invalid colour warning message * @returns default colour (black) */ private warnDefaultColour(): IconColour { const message = new ConsoleMessageClass(); message .addDesignSystemTag() .addMonospaceText(' colour ') .addRegularText('on') .addMonospaceText(' ') .addRegularText('was set to an invalid colour; only') .addMonospaceText(' black, blue, grey or white ') .addRegularText('are supported. The default colour') .addMonospaceText(' black ') .addRegularText('is assumed.') .printMessage(); return 'black'; } /** * Stencil component lifecycle method that is called once after the component is first connected to the DOM. */ componentWillLoad() { this.validateColour(); this.validateWidth(); } /** * Returns the HTML code to be rendered into a custom element. */ render() { return (
); } } // content automatically generated by `generate-icons.js` ends