diff --git a/src/components/multi-select/multi-select.mdx b/src/components/multi-select/multi-select.mdx deleted file mode 100644 index 43a9c94c8a..0000000000 --- a/src/components/multi-select/multi-select.mdx +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: Multi Select -route: /multi-select -menu: Components ---- - -# Multi Select - - - -## Example - - diff --git a/src/components/select-multiple/select-multiple.scss b/src/components/select-multiple/select-multiple.scss new file mode 100644 index 0000000000..a4cdd31001 --- /dev/null +++ b/src/components/select-multiple/select-multiple.scss @@ -0,0 +1,22 @@ +@import '../../style/variables'; + +@import '@lime-material-16px/form-field/mdc-form-field'; +@import '@lime-material-16px/checkbox/mdc-checkbox'; +@import "@lime-material-16px/floating-label/mdc-floating-label"; + +.multi-select { + position: relative; + + .multi-select-label { + padding-left: pxToRem(15); + } + + .mdc-form-field { + display: flex; + } + + .mdc-checkbox { + @include mdc-checkbox-ink-color(primary); + @include mdc-checkbox-container-colors(secondary, on-primary, secondary, on-primary); + } +} diff --git a/src/components/select-multiple/select-multiple.tsx b/src/components/select-multiple/select-multiple.tsx new file mode 100644 index 0000000000..dcb44806ba --- /dev/null +++ b/src/components/select-multiple/select-multiple.tsx @@ -0,0 +1,137 @@ +import { MDCCheckbox } from '@lime-material-16px/checkbox'; +import { MDCFormField } from '@lime-material-16px/form-field'; +import { + Component, + Element, + Event, + EventEmitter, + Prop, + State, +} from '@stencil/core'; +import { Option } from '../../interface'; +import { createRandomString } from '../../util/random-string'; + +@Component({ + tag: 'limel-select-multiple', + shadow: true, + styleUrl: 'select-multiple.scss', +}) +export class SelectMultiple { + @Prop({ reflectToAttr: true }) + public disabled = false; + + @Prop({ reflectToAttr: true }) + public label: string; + + @Prop() + public value: Option[] = []; + + @Prop() + public options: Option[] = []; + + @Event() + private change: EventEmitter; + + @Element() + private limelMultiSelect: HTMLElement; + + @State() + private fieldId = createRandomString(); + + @State() + private mdcCheckboxes = []; + + public componentDidLoad() { + const elements = Array.from( + this.limelMultiSelect.shadowRoot.querySelectorAll( + '.multi-select .mdc-form-field' + ) + ); + + elements.forEach(element => { + const formField = new MDCFormField(element); + const checkbox = new MDCCheckbox(element.firstChild); + formField.input = checkbox; + this.mdcCheckboxes.push(checkbox); + }); + + this.onChange(); + } + + public render() { + return ( +
+ { return option.text }).join(', ')}> +
+ {this.options.map((option: Option, index: number) => { + return this.renderCheckbox(index, option); + })} +
+
+
+ ); + } + + private renderCheckbox(index: number, option: Option) { + return ( +
+
+ +
+ + + +
+
+
+ +
+ ); + } + + private isOptionChecked(option: Option) { + return this.value.find(checkedOption => { + return checkedOption.value === option.value; + }); + } + + private onChange = (event?) => { + if (event) { + event.stopPropagation(); + } + + const checked = this.options.filter(option => { + const optionChecked = this.mdcCheckboxes.some(mdcCheckbox => { + return ( + mdcCheckbox.checked && mdcCheckbox.value === option.value + ); + }); + if (optionChecked) { + return option; + } + }); + this.change.emit(checked); + }; +} diff --git a/src/components/select/select.e2e.ts b/src/components/select-single/select-single.e2e.ts similarity index 100% rename from src/components/select/select.e2e.ts rename to src/components/select-single/select-single.e2e.ts diff --git a/src/components/select/select.scss b/src/components/select-single/select-single.scss similarity index 100% rename from src/components/select/select.scss rename to src/components/select-single/select-single.scss diff --git a/src/components/select-single/select-single.tsx b/src/components/select-single/select-single.tsx new file mode 100644 index 0000000000..f0e03ded80 --- /dev/null +++ b/src/components/select-single/select-single.tsx @@ -0,0 +1,135 @@ +import { MDCSelect } from '@lime-material-16px/select'; +import { + Component, + Element, + Event, + EventEmitter, + Prop, + State, + Watch, +} from '@stencil/core'; +import { Option } from '../../interface'; + +@Component({ + tag: 'limel-select-single', + shadow: true, + styleUrl: 'select-single.scss', +}) +export class SelectSingle { + /** + * Set to `true` to disable the input. + */ + @Prop({ reflectToAttr: true }) + public disabled = false; + + /** + * The input label. + */ + @Prop({ reflectToAttr: true }) + public label: string; + + /** + * The currently selected item. + */ + @Prop() + public value: Option; + + @Prop() + public options: Option[] = []; + + @Event() + private change: EventEmitter