diff --git a/src/components.d.ts b/src/components.d.ts index 0895eb47a..f4e2b760d 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -16,23 +16,11 @@ import { } from 'types/Service'; import { Option, - Value, } from 'types/Select'; export namespace Components { - interface CustomPlanFeature { - 'feature': Catalog.ExpandedFeature; - 'planLabel': string; - 'selectedValue': string; - } - interface CustomPlanFeatureAttributes extends StencilHTMLAttributes { - 'feature'?: Catalog.ExpandedFeature; - 'planLabel'?: string; - 'selectedValue'?: string; - } - interface FeaturedService { 'logo': string; 'name': string; @@ -167,52 +155,53 @@ export namespace Components { } interface MfSelect { + 'defaultValue'?: string; 'name': string; - 'onChange': (e: UIEvent) => void; 'options': Option[]; 'required'?: boolean; - 'selectedValue'?: Value; } interface MfSelectAttributes extends StencilHTMLAttributes { + 'defaultValue'?: string; 'name'?: string; - 'onChange'?: (e: UIEvent) => void; + 'onOnInputChange'?: (event: CustomEvent) => void; 'options'?: Option[]; 'required'?: boolean; - 'selectedValue'?: Value; } interface MfSlider { + 'defaultValue'?: number; 'error'?: string; 'increment': number; 'max': number; 'min': number; 'name': string; - 'onChange': (e: Event) => void; - 'selectedValue': number; 'suffix': string; } interface MfSliderAttributes extends StencilHTMLAttributes { + 'defaultValue'?: number; 'error'?: string; 'increment'?: number; 'max'?: number; 'min'?: number; 'name'?: string; - 'onChange'?: (e: Event) => void; - 'selectedValue'?: number; + 'onOnInputChange'?: (event: CustomEvent) => void; 'suffix'?: string; } interface MfToggle { 'ariaLabelledby'?: string; + 'defaultValue'?: boolean; 'disabled'?: boolean; 'label'?: string; 'name': string; } interface MfToggleAttributes extends StencilHTMLAttributes { 'ariaLabelledby'?: string; + 'defaultValue'?: boolean; 'disabled'?: boolean; 'label'?: string; 'name'?: string; + 'onOnInputChange'?: (event: CustomEvent) => void; } interface PlanDetails { @@ -291,7 +280,6 @@ export namespace Components { declare global { interface StencilElementInterfaces { - 'CustomPlanFeature': Components.CustomPlanFeature; 'FeaturedService': Components.FeaturedService; 'ImageGallery': Components.ImageGallery; 'LinkButton': Components.LinkButton; @@ -317,7 +305,6 @@ declare global { } interface StencilIntrinsicElements { - 'custom-plan-feature': Components.CustomPlanFeatureAttributes; 'featured-service': Components.FeaturedServiceAttributes; 'image-gallery': Components.ImageGalleryAttributes; 'link-button': Components.LinkButtonAttributes; @@ -343,12 +330,6 @@ declare global { } - interface HTMLCustomPlanFeatureElement extends Components.CustomPlanFeature, HTMLStencilElement {} - var HTMLCustomPlanFeatureElement: { - prototype: HTMLCustomPlanFeatureElement; - new (): HTMLCustomPlanFeatureElement; - }; - interface HTMLFeaturedServiceElement extends Components.FeaturedService, HTMLStencilElement {} var HTMLFeaturedServiceElement: { prototype: HTMLFeaturedServiceElement; @@ -482,7 +463,6 @@ declare global { }; interface HTMLElementTagNameMap { - 'custom-plan-feature': HTMLCustomPlanFeatureElement 'featured-service': HTMLFeaturedServiceElement 'image-gallery': HTMLImageGalleryElement 'link-button': HTMLLinkButtonElement @@ -508,7 +488,6 @@ declare global { } interface ElementTagNameMap { - 'custom-plan-feature': HTMLCustomPlanFeatureElement; 'featured-service': HTMLFeaturedServiceElement; 'image-gallery': HTMLImageGalleryElement; 'link-button': HTMLLinkButtonElement; diff --git a/src/components/custom-plan-feature/custom-plan-feature.tsx b/src/components/custom-plan-feature/custom-plan-feature.tsx deleted file mode 100644 index 1bdb55409..000000000 --- a/src/components/custom-plan-feature/custom-plan-feature.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { Component, Prop, FunctionalComponent } from '@stencil/core'; -import { FEATURE_CHANGE } from '../../global/events'; -import { $ } from '../../utils/currency'; - -const STRING = 'string'; -const NUMBER = 'number'; -const BOOLEAN = 'boolean'; - -interface DropdownProps { - name: string; - values?: Catalog.FeatureValueDetails[]; -} - -interface ToggleProps { - name: string; - values: Catalog.FeatureValueDetails[]; -} - -interface SliderProps { - name: string; - value?: Catalog.FeatureValueDetails; -} - -const Dropdown: FunctionalComponent = ({ name, values }) => { - const options = Array.isArray(values) - ? values.map(({ cost, label, name: optionName }) => ({ - label: `${optionName} (${cost ? $(cost) : 'Included'})`, - value: label, - })) - : []; - - return ; -}; - -const Slider: FunctionalComponent = ({ value, name }) => { - let details: Catalog.FeatureNumericDetails = {}; - if (value && value.numeric_details) details = value.numeric_details; - const { min, max, increment, suffix } = details; - return ; -}; - -const Toggle: FunctionalComponent = () => { - // TODO refactor options into props - return ; -}; - -@Component({ - tag: 'custom-plan-feature', - scoped: true, -}) -export class CustomPlanFeature { - @Prop() feature: Catalog.ExpandedFeature; - @Prop() selectedValue?: string; - @Prop() planLabel: string = ''; - - get featureID() { - return this.feature.label; - } - - render() { - const { values = [], value } = this.feature; - - switch (this.feature.type) { - case STRING: - return ; - case NUMBER: - return ; - case BOOLEAN: - return ; - default: - return null; - } - } -} diff --git a/src/components/custom-plan-feature/readme.md b/src/components/custom-plan-feature/readme.md deleted file mode 100644 index 8afd41eab..000000000 --- a/src/components/custom-plan-feature/readme.md +++ /dev/null @@ -1,19 +0,0 @@ -# custom-plan-feature - - - - - - -## Properties - -| Property | Attribute | Description | Type | Default | -| --------------- | ---------------- | ----------- | ----------------- | ----------- | -| `feature` | -- | | `ExpandedFeature` | `undefined` | -| `planLabel` | `plan-label` | | `string` | `''` | -| `selectedValue` | `selected-value` | | `string` | `undefined` | - - ----------------------------------------------- - -*Built with [StencilJS](https://stenciljs.com/)* diff --git a/src/components/mf-select/mf-select.tsx b/src/components/mf-select/mf-select.tsx index 2793583d5..b20d097db 100644 --- a/src/components/mf-select/mf-select.tsx +++ b/src/components/mf-select/mf-select.tsx @@ -1,5 +1,5 @@ -import { Component, Prop, Event, EventEmitter } from '@stencil/core'; -import { Option, Value } from 'types/Select'; +import { Component, Prop, Event, EventEmitter, Watch } from '@stencil/core'; +import { Option } from 'types/Select'; @Component({ tag: 'mf-select', @@ -7,25 +7,26 @@ import { Option, Value } from 'types/Select'; scoped: true, }) export class MfSelect { - @Prop() eventName?: string; + @Prop() defaultValue?: string; @Prop() name: string; @Prop() options: Option[] = []; @Prop() required?: boolean; - @Prop() selectedValue?: Value; - @Event({ eventName: this.eventName }) onChange: EventEmitter; - - private onChangeHandler(e: Event) { - console.log('changed'); - if (!e.target || !this.eventName) return; - const el = e.target as HTMLSelectElement; - this.onChange.emit({ name: el.getAttribute('name'), value: el.value }); + @Event() onInputChange: EventEmitter; + @Watch('defaultValue') watchHandler(newVal: string) { + this.onInputChange.emit({ name: this.name, value: newVal }); } + onChangeHandler = (e: Event) => { + if (!e.target) return; + const { value } = e.target as HTMLSelectElement; + this.onInputChange.emit({ name: this.name, value }); + }; + render() { return (