Skip to content

Commit

Permalink
feat(select): update select as per MDCWeb 0.37.0
Browse files Browse the repository at this point in the history
Also add support for outlined select
  • Loading branch information
stasson committed Jul 16, 2018
1 parent 80b892b commit cffa49d
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 114 deletions.
14 changes: 8 additions & 6 deletions components/select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
var vm = new Vue({
data() {
return {
selected: '',
};
},
});
selected: ''
}
}
})
```

### mdc-select

| props | Type | Default | Description |
| ---------- | --------------- | ------- | -------------------------------------------- |
| `disabled` | Boolean | false | whether this select is disabled |
| `label` | String | | the selection label (placeholder) |
| `value` | [String, Array] | | bind with v-model (update on `change` event) |
| `disabled` | Boolean | false | whether this select is disabled |
| `box` | Boolean | false | box style |
| `outlined` | Boolean | false | outlined style |

| event | Description |
| -------- | ----------------------- |
Expand All @@ -47,4 +49,4 @@ var vm = new Vue({

### Reference

* <https://material.io/components/web/catalog/input-controls/select-menus>
- <https://material.io/components/web/catalog/input-controls/select-menus>
74 changes: 38 additions & 36 deletions components/select/demo.vue
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
<template>
<div class="mdc-demo mdc-demo--container">
<div>
<mdc-select
v-model="selectedType"
label="Pick up a food type">
<optgroup label="categories">
<option
v-for="type in types"
:value="type"
:key="type">{{ type }}</option>
</optgroup>
</mdc-select>

<mdc-caption tag="p" >Selected Type: {{ selectedType }}</mdc-caption>
<br>
<br><br><br>
<mdc-select
v-if="selectedType"
v-model="selectedValue"
box
label="Pick up a food">
<option
v-for="option of options"
:key="option"
:value="option.toLowerCase()">{{ option }}</option>
</mdc-select>

<mdc-caption
v-if="selectedType"
tag="p">Selected Value: {{ selectedValue }}</mdc-caption>
<br>

</div>
<div class="mdc-demo mdc-demo--container">
<div>
<mdc-select
v-model="selectedType"
label="Pick up a food type">
<optgroup label="categories">
<option
v-for="type in types"
:value="type"
:key="type">{{ type }}</option>
</optgroup>
</mdc-select>

<mdc-caption
v-if="selectedType"
tag="p" >Selected Type: {{ selectedType }}
</mdc-caption>

<br><br><br>
<mdc-select
v-if="selectedType"
v-model="selectedValue"
outlined
label="Pick up a food">
<option
v-for="option of options"
:key="option"
:value="option.toLowerCase()">{{ option }}</option>
</mdc-select>
<mdc-caption
v-if="selectedValue"
tag="p">Selected Value: {{ selectedValue }}
</mdc-caption>

</div>
</div>
</template>

</template>

<script>
export default {
data() {
return {
selectedType: 'Meat',
selectedType: undefined, //'Meat',
selectedValue: undefined,
food: {
Vegetables: ['Spinach', 'Carrots', 'Onions', 'Broccoli'],
Expand Down
43 changes: 43 additions & 0 deletions components/select/mdc-select-label.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<label
:class="labelClasses"
class="mdc-floating-label">
<slot />
</label>
</template>

<script>
import MDCFloatingLabelFoundation from '@material/floating-label/foundation'
export default {
name: 'mdc-select-label',
data() {
return {
labelClasses: {}
}
},
mounted() {
this.foundation = new MDCFloatingLabelFoundation({
addClass: className => {
this.$set(this.labelClasses, className, true)
},
removeClass: className => {
this.$delete(this.labelClasses, className)
},
getWidth: () => this.$el.offsetWidth,
registerInteractionHandler: (evtType, handler) => {
this.$el.addEventListener(evtType, handler)
},
deregisterInteractionHandler: (evtType, handler) => {
this.$el.removeEventListener(evtType, handler)
}
})
this.foundation.init()
},
beforeDestroy() {
let foundation = this.foundation
this.foundation = null
foundation.destroy()
}
}
</script>
48 changes: 48 additions & 0 deletions components/select/mdc-select-line-ripple.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div
:class="lineClasses"
:style="lineStyles"
class="mdc-line-ripple"/>
</template>

<script>
import MDCLineRippleFoundation from '@material/line-ripple/foundation'
export default {
name: 'mdc-select-line-ripple',
data() {
return {
lineClasses: {},
lineStyles: {}
}
},
mounted() {
this.foundation = new MDCLineRippleFoundation({
addClass: className => {
this.$set(this.lineClasses, className, true)
},
removeClass: className => {
this.$delete(this.lineClasses, className)
},
hasClass: className => {
this.$el.classList.contains(className)
},
setStyle: (name, value) => {
this.$set(this.lineStyles, name, value)
},
registerEventHandler: (evtType, handler) => {
this.$el.addEventListener(evtType, handler)
},
deregisterEventHandler: (evtType, handler) => {
this.$el.removeEventListener(evtType, handler)
}
})
this.foundation.init()
},
beforeDestroy() {
let foundation = this.foundation
this.foundation = null
foundation.destroy()
}
}
</script>
57 changes: 57 additions & 0 deletions components/select/mdc-select-notched-outline.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div>
<div
ref="outlined"
:class="outlinedClasses"
class="mdc-notched-outline">
<svg>
<path
ref="outlinedPath"
class="mdc-notched-outline__path"/>
</svg>
</div>
<div
ref="outlinedIdle"
class="mdc-notched-outline__idle"/>
</div>
</template>

<script>
import MDCnotchedOutlineFoundationFoundation from '@material/notched-outline/foundation'
export default {
name: 'mdc-select-notched-outline',
data() {
return {
outlinedClasses: {}
}
},
mounted() {
this.foundation = new MDCnotchedOutlineFoundationFoundation({
getWidth: () => this.$refs.outlined.offsetWidth,
getHeight: () => this.$refs.outlined.offsetHeight,
addClass: className => {
this.$set(this.outlinedClasses, className, true)
},
removeClass: className => {
this.$delete(this.outlinedClasses, className)
},
setOutlinePathAttr: value => {
const path = this.$refs.outlinedPath
path.setAttribute('d', value)
},
getIdleOutlineStyleValue: propertyName => {
return window
.getComputedStyle(this.$refs.outlinedIdle)
.getPropertyValue(propertyName)
}
})
this.foundation.init()
},
beforeDestroy() {
let foundation = this.foundation
this.foundation = null
foundation.destroy()
}
}
</script>
Loading

0 comments on commit cffa49d

Please sign in to comment.