{"version":3,"file":"windows-plus-form-fields-custom-select.mjs","sources":["../../../projects/windows-plus-form-fields/custom-select/components/custom-select/custom-select.component.ts","../../../projects/windows-plus-form-fields/custom-select/components/custom-select/custom-select.component.html","../../../projects/windows-plus-form-fields/custom-select/custom-select.module.ts","../../../projects/windows-plus-form-fields/custom-select/public-api.ts","../../../projects/windows-plus-form-fields/custom-select/windows-plus-form-fields-custom-select.ts"],"sourcesContent":["import { Component, Input, OnInit, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core'\r\nimport { FormControl } from '@angular/forms'\r\nimport { CustomSelectOption } from './../../util/interface/custom-select-option/custom-select-option.interface'\r\n\r\n@Component({\r\n  selector: 'wp-custom-select',\r\n  templateUrl: './custom-select.component.html',\r\n  styleUrls: ['./custom-select.component.sass']\r\n})\r\n/**\r\n * @author Alex Hodson\r\n * @description the custom select component provides the functionality for interacting with a custom select HTML element\r\n */\r\nexport class CustomSelectComponent implements OnChanges {\r\n\t/**\r\n\t * @description the identifier of the HTML element\r\n\t */\r\n\t@Input({ required: true }) id: string\r\n\t/**\r\n\t * @description an object which contains the configuration for the custom select element\r\n\t */\r\n\t@Input({ required: true }) options: CustomSelectOption[]\r\n\t/**\r\n\t * @description the value of the select element\r\n\t */\r\n\t@Input({ required: true }) value: FormControl\r\n\t/**\r\n\t * @description the select elements label\r\n\t */\r\n\t@Input() label?: string\r\n\t/**\r\n\t * @description the name of the select element\r\n\t */\r\n\t@Input() name?: string\r\n\t/**\r\n\t * @description whether the select element is disabled\r\n\t */\r\n\t@Input() disabled?: boolean\r\n\t/**\r\n\t * @description whether the select element is has grouped options\r\n\t */\r\n\t@Input() hasGroups?: boolean\r\n\t/**\r\n\t * @description handles a change in the select elements value\r\n\t */\r\n\t@Output() handleChange: EventEmitter<CustomSelectOption> = new EventEmitter<CustomSelectOption>()\r\n\t/**\r\n\t * @description an error message to be displayed\r\n\t */\r\n\t@Input() errorMessage?: string\r\n\t/**\r\n\t * @description an object containing the grouped select options\r\n\t */\r\n\tgroupedOptions: {[key: string]: CustomSelectOption[]} = {}\r\n\t/**\r\n\t * @author Alex Hodson\r\n\t * @description class constructor specifying the required services and properties for the component\r\n\t */\r\n  constructor() {\r\n\t}\r\n\t/**\r\n\t * @author Alex Hodson\r\n\t * @description the method to be called when the component properties are changed\r\n\t */\r\n\tngOnChanges(changes: SimpleChanges): void {\r\n\t\tthis.disabled || this.options.length === 0 ? this.value.disable() : this.value.enable()\r\n\t\t\r\n\t\tif (changes['options']) {\r\n\t\t\tthis.determineGroupedOptions()\r\n\t\t}\r\n\t}\r\n\r\n\tdetermineGroupedOptions(): void {\r\n\t\tif (this.hasGroups) {\r\n\t\t\tthis.groupedOptions = this.options.reduce((acc: {[key: string]: CustomSelectOption[]}, cur: CustomSelectOption): {[key: string]: CustomSelectOption[]} => {\r\n\t\t\t\tconst output = { ...acc }\r\n\t\t\t\tconst groupName = cur.groupName || 'other'\r\n\t\t\t\tif (!Object.hasOwn(output, groupName)) { output[groupName] = [] }\r\n\t\t\t\toutput[groupName].push(cur)\r\n\t\t\t\treturn output\r\n\t\t\t}, {})\r\n\t\t}\r\n\t}\r\n\t/**\r\n\t * @author Alex Hodson\r\n\t * @description handles the selection of a custom select option. If the option has been set to automatically clear, the value is cleared and then the options\r\n\t * callback is made\r\n\t */\r\n\thandleClick() {\r\n\t\tconst index = this.options.findIndex(element => element.label === this.value?.value)\r\n\t\tconst element = this.options[index]\r\n\r\n\t\tif (element.autoClear) { this.value?.setValue('') }\r\n\r\n\t\tif (element.handleClick) element.handleClick(element.value)\r\n\r\n\t\tif (this.handleChange.observed) this.handleChange.emit(element)\r\n\t}\r\n\t/**\r\n\t * @author Alex Hodson\r\n\t * @description returns a number to preserve the iteration order\r\n\t * @returns a number to preserve the iteration order\r\n\t */\r\n\tkeepOrder(): number {\r\n\t\treturn 0\r\n\t}\r\n}\r\n","<label \r\n\tclass=\"custom-label text-truncate\"\r\n\t[ngClass]=\"{'text-red': errorMessage}\"\r\n\t*ngIf=\"label\"\r\n>\r\n\t{{label}}\r\n</label>\r\n<select \r\n\t[id]=\"id\"\r\n\tclass=\"form-select text-grey\"\r\n\taria-label=\"customSelect\"\r\n\tname=\"name\"\r\n\t[formControl]=\"value\"\r\n\t(change)=\"handleClick()\"\r\n>\r\n\t<option hidden disabled value>Please select an option</option>\r\n\t<ng-container *ngIf=\"!hasGroups\">\r\n\t\t<option \r\n\t\t\t*ngFor=\"let option of options; index as i\"\r\n\t\t\t[ngValue]=\"option.label\"\r\n\t\t\t[selected]=\"option.label === value?.value\"\r\n\t\t>{{option.label}}</option>\r\n\t</ng-container>\r\n\t<ng-container *ngIf=\"hasGroups\">\r\n\t\t<optgroup \r\n\t\t\t*ngFor=\"let element of groupedOptions | keyvalue : keepOrder\"\r\n\t\t\t[label]=\"element.key\"\r\n\t\t>\r\n\t\t\t<option \r\n\t\t\t\t*ngFor=\"let option of element.value; index as i\"\r\n\t\t\t\t[value]=\"option.label\"\r\n\t\t\t\t[selected]=\"option.label === value?.value\"\r\n\t\t\t>{{option.label}}</option>\r\n\t\t</optgroup>\r\n\t</ng-container>\r\n</select>\r\n<div *ngIf=\"errorMessage\">\r\n\t<span id=\"{{id + '-error-message'}}\" class=\"text-red\">{{errorMessage}}</span>\r\n</div>","import { NgModule } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\nimport { CustomSelectComponent } from './components/custom-select/custom-select.component';\r\nimport { ReactiveFormsModule } from '@angular/forms'\r\n\r\n\r\n\r\n@NgModule({\r\n  declarations: [\r\n    CustomSelectComponent\r\n  ],\r\n  imports: [\r\n    CommonModule,\r\n\t\tReactiveFormsModule\r\n  ],\r\n  exports: [\r\n    CustomSelectComponent\r\n  ]\r\n})\r\nexport class CustomSelectModule { }\r\n","/*\r\n * Public API Surface of windows-plus-form-fields\r\n */\r\n\r\nexport * from './custom-select.module'\r\n\r\nexport * from './components/custom-select/custom-select.component'\r\nexport * from './util/interface/custom-select/custom-select.interface'\r\nexport * from './util/interface/custom-select-option/custom-select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