From 8ad8c506748c78782c953216c3571657309cb9d2 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Wed, 20 Mar 2019 06:55:03 -0600 Subject: [PATCH] In-progress: use custom events for inputs --- .../custom-plan-feature.tsx | 11 +++-- src/components/custom-plan-feature/readme.md | 11 ++--- src/components/mf-select/mf-select.tsx | 18 +++++-- src/components/mf-select/readme.md | 9 +++- src/components/mf-slider/mf-slider.tsx | 25 ++++++---- src/components/mf-slider/readme.md | 9 +++- src/components/mf-toggle/mf-toggle.tsx | 19 ++++++-- src/components/mf-toggle/readme.md | 8 ++++ src/components/plan-details/plan-details.tsx | 47 ++++++++++++++++--- src/global/events.ts | 1 + tsconfig.json | 2 +- 11 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 src/global/events.ts diff --git a/src/components/custom-plan-feature/custom-plan-feature.tsx b/src/components/custom-plan-feature/custom-plan-feature.tsx index 558f34a93..1bdb55409 100644 --- a/src/components/custom-plan-feature/custom-plan-feature.tsx +++ b/src/components/custom-plan-feature/custom-plan-feature.tsx @@ -1,4 +1,5 @@ import { Component, Prop, FunctionalComponent } from '@stencil/core'; +import { FEATURE_CHANGE } from '../../global/events'; import { $ } from '../../utils/currency'; const STRING = 'string'; @@ -49,11 +50,11 @@ const Toggle: FunctionalComponent = () => { }) export class CustomPlanFeature { @Prop() feature: Catalog.ExpandedFeature; - @Prop() selectedValue: string; + @Prop() selectedValue?: string; @Prop() planLabel: string = ''; get featureID() { - return `plan-${this.planLabel}-feature-${this.feature.label}`; + return this.feature.label; } render() { @@ -61,11 +62,11 @@ export class CustomPlanFeature { switch (this.feature.type) { case STRING: - return ; + return ; case NUMBER: - return ; + return ; case BOOLEAN: - return ; + return ; default: return null; } diff --git a/src/components/custom-plan-feature/readme.md b/src/components/custom-plan-feature/readme.md index 197d15750..8afd41eab 100644 --- a/src/components/custom-plan-feature/readme.md +++ b/src/components/custom-plan-feature/readme.md @@ -7,12 +7,11 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| --------------- | ---------------- | ----------- | ---------------------------------------- | ----------- | -| `feature` | -- | | `ExpandedFeature` | `undefined` | -| `planLabel` | `plan-label` | | `string` | `''` | -| `selectedValue` | `selected-value` | | `string` | `undefined` | -| `setFeature` | -- | | `(label: string, value: string) => void` | `undefined` | +| Property | Attribute | Description | Type | Default | +| --------------- | ---------------- | ----------- | ----------------- | ----------- | +| `feature` | -- | | `ExpandedFeature` | `undefined` | +| `planLabel` | `plan-label` | | `string` | `''` | +| `selectedValue` | `selected-value` | | `string` | `undefined` | ---------------------------------------------- diff --git a/src/components/mf-select/mf-select.tsx b/src/components/mf-select/mf-select.tsx index 3304daae6..2793583d5 100644 --- a/src/components/mf-select/mf-select.tsx +++ b/src/components/mf-select/mf-select.tsx @@ -1,4 +1,4 @@ -import { Component, Prop } from '@stencil/core'; +import { Component, Prop, Event, EventEmitter } from '@stencil/core'; import { Option, Value } from 'types/Select'; @Component({ @@ -7,15 +7,23 @@ import { Option, Value } from 'types/Select'; scoped: true, }) export class MfSelect { - @Prop() options: Option[] = []; - @Prop() selectedValue?: Value; + @Prop() eventName?: string; @Prop() name: string; + @Prop() options: Option[] = []; @Prop() required?: boolean; - @Prop() onChange: (e: UIEvent) => void; + @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 }); + } render() { return ( - {this.options.map(({ label, value }) => (