import {attribute, ChildrenSet, ComponentBase} from '../ComponentBase'; import {DomRender, DomRenderRunConfig} from '../../DomRender'; import {RawSet} from '../../rawsets/RawSet'; import {OnCreateRenderData} from '../../lifecycle/OnCreateRenderData'; import {OnInitRender} from '../../lifecycle/OnInitRender'; import {OnDestroyRender} from '../../lifecycle/OnDestroyRender'; import {EventUtils} from '@dooboostore/core-web'; import {type Subscription} from '@dooboostore/core'; import {ValidUtils} from '@dooboostore/core-web'; import {DomRenderNoProxy} from '../../decorators/DomRenderNoProxy'; import {OnCreateRender} from '../../lifecycle/OnCreateRender'; import {DomRenderConfig} from '../../configs/DomRenderConfig'; import {WindowUtils} from '@dooboostore/core-web'; import {OnRawSetRenderedOtherData} from '../../lifecycle'; /** 사용법
카드사별 사용처 안내 페이지 선택
${@this@.selectedCard?.name}$
${#it#.name}$
*/ export namespace Select { export const selector = 'dr-select'; // Base for simple hide/show components class StateComponent extends ComponentBase { public hidden = true; public value: string | null = null; constructor(config: any) { super(config); } setValue(value: string | null) { this.value = value; } } // --- Option Child Components --- export class OptionSelected extends StateComponent { constructor() { super({onlyParentType: Option}); } } export class OptionUnselected extends StateComponent { constructor() { super({onlyParentType: Option}); } } export class OptionDisabled extends StateComponent { constructor() { super({onlyParentType: Option}); } } // --- Summary Child Components --- export class SummaryPlaceholder extends StateComponent { constructor() { super({onlyParentType: Summary}); } } export class SummarySelected extends StateComponent { private selectedOptions: Select.Option[] = []; constructor() { super({onlyParentType: Summary}); } setOptions(options: Option[] = []) { this.selectedOptions = options.filter(it => it.selected); } } export class SummaryDisabled extends StateComponent { private selectedOptions: Select.Option[] = []; constructor() { super({onlyParentType: Summary}); } setOptions(options: Option[] = []) { this.selectedOptions = options.filter(it => it.selected); } } // --- Select Body Component --- export type SelectBodyAttribute = { float?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'; class?: string; } // --- Option Component --- export type OptionAttribute = { value: string; selected?: boolean | null; disabled?: boolean | null; class?: string; }; export class Option extends ComponentBase implements OnInitRender { public hidden = true; @attribute({name: 'value'}) public value: string | null = null; @attribute({name: 'selected', converter: v => v !== null && v === true}) public selected = false; @attribute({name: 'disabled', converter: v => v !== null && v === true}) public disabled = false; @attribute({name: 'class', converter: v => (v ? v : null)}) public classAttr: string | null = null; // public status: 'selected' | 'unselected' | 'disabled' = 'unselected'; constructor() { super({onlyParentType: SelectBody}); } async onInitRender(param: any, rawSet: RawSet) { await super.onInitRender(param, rawSet); // console.log('-----', this.value, this.selected) // this.getElement()?.addEventListener('click', (e) => { // e.stopPropagation(); // if (!this.disabled) { // this.getParentThis().toggle(); // }); } onInitSummaryElement(element: HTMLElement, event: Event) { this.element = element; } updateView(hasSelection: boolean) { this.getChildren(SummaryPlaceholder).forEach(c => (c.hidden = hasSelection)); this.getChildren(SummarySelected).forEach(c => (c.hidden = !hasSelection)); } // onCreatedThisChild(child: any, data: OnCreateRenderDataParams) { // super.onCreatedThisChild(child, data); // } // async onRawSetRendered(rawSet: RawSet, otherData: OnRawSetRenderedOtherData): Promise { // await super.onRawSetRendered(rawSet, otherData); // } onCreatedThisChildDebounce(childrenSet: ChildrenSet[]) { super.onCreatedThisChildDebounce(childrenSet); this.updateView(this.getParentThis()?.disabled) { event.stopPropagation(); event.preventDefault(); return; } } } export class SelectBody extends ComponentBase { @attribute({name: 'class', converter: v => (v === '' ? null : v)}) public classAttr: string | null = null; @attribute({name: 'float'}) public float: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | null = null; constructor() { super({onlyParentType: Select}); } async onRawSetRendered(rawSet: RawSet, otherData: OnRawSetRenderedOtherData): Promise { await super.onRawSetRendered(rawSet, otherData); // } // onCreatedThisChildDebounce(childrenSet: ChildrenSet[]) { // super.onCreatedThisChildDebounce(childrenSet); this.changeOptionState(); } changeOptionState(option?: Option) { const options = this.getChildren(Option); const select = this.getParentThis\n' + ' \n' + '', objFactory: (e, o, r2, constructorParam) => DomRender.run({rootObject: new Select.Select(config), config}) }); }, selectSummary: (config?: DomRenderRunConfig) => { return RawSet.createComponentTargetElement({ name: `${Select.selector}-summary`, template: '\n' + '#innerHTML#\n' + '', objFactory: (e, o, r2, constructorParam) => DomRender.run({rootObject: new Select.Summary(), config}) }); }, selectSummaryPlaceholder: stateComponentFactory(`${Select.selector}-summary-placeholder`, Select.SummaryPlaceholder), selectSummarySelected: stateComponentFactory(`${Select.selector}-summary-selected`, Select.SummarySelected), selectSummaryDisabled: stateComponentFactory(`${Select.selector}-summary-disabled`, Select.SummaryDisabled), selectBody: (config?: DomRenderRunConfig) => { // New export return RawSet.createComponentTargetElement({ name: `${Select.selector}-body`, template: '
#innerHTML#
', objFactory: (e, o, r2, constructorParam) => { return DomRender.run({rootObject: new Select.SelectBody(), config: config}); } }) }, selectOption: (config?: DomRenderRunConfig) => { return RawSet.createComponentTargetElement({ name: `${Select.selector}-option`, template: '#innerHTML#\n', objFactory: (e, o, r2, constructorParam) => DomRender.run({rootObject: new Select.Option(), config}) }); }, selectOptionSelected: stateComponentFactory(`${Select.selector}-option-selected`, Select.OptionSelected), selectOptionUnselected: stateComponentFactory(`${Select.selector}-option-unselected`, Select.OptionUnselected), selectOptionDisabled: stateComponentFactory(`${Select.selector}-option-disabled`, Select.OptionDisabled), };