Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit c2a13f5

Browse files
committed
feat(floating-label): Synchronise with mdc-web v0.32.0 (add component)
1 parent 10c44bc commit c2a13f5

File tree

8 files changed

+119
-56
lines changed

8 files changed

+119
-56
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<label
3+
class="mdc-floating-label"
4+
:class="classes">
5+
<slot/>
6+
</label>
7+
</template>
8+
9+
<script>
10+
import { MDCFloatingLabel } from '@material/floating-label'
11+
12+
export default {
13+
props: {
14+
floatAbove: {
15+
type: Boolean,
16+
default: false
17+
},
18+
shake: {
19+
type: Boolean,
20+
default: false
21+
}
22+
},
23+
data () {
24+
return {
25+
mdcFloatingLabel: null
26+
}
27+
},
28+
computed: {
29+
classes () {
30+
return {
31+
'mdc-floating-label--float-above': this.floatAbove,
32+
'mdc-floating-label--shake': this.shake
33+
}
34+
}
35+
},
36+
mounted () {
37+
this.mdcFloatingLabel = MDCFloatingLabel.attachTo(this.$el)
38+
},
39+
beforeDestroy () {
40+
this.mdcFloatingLabel.destroy()
41+
}
42+
}
43+
</script>

components/floating-label/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## FloatingLabel
2+
3+
### Markup
4+
5+
6+
```html
7+
<m-text-field id="textfield">
8+
<m-floating-label for="textfield">Textfield label</m-floating-label>
9+
<m-line-ripple slot="bottomLine"/>
10+
</m-text-field>
11+
12+
### Props
13+
14+
| Prop | Type | Default | Description |
15+
|------|------|---------|-------------|
16+
| floatAbove | Boolean | false | label is floating above |
17+
| absoluteRight | Boolean | false | shakes the label |
18+
19+
### Slots
20+
21+
| Slot | Description |
22+
|------|-------------|
23+
| default | label content |
24+
25+
### Reference
26+
27+
- https://github.com/material-components/material-components-web/tree/master/packages/mdc-floating-label
28+
29+

components/floating-label/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import FloatingLabel from './FloatingLabel.vue'
2+
import './styles.scss'
3+
4+
import { initPlugin } from '../'
5+
6+
const plugin = {
7+
install (vm) {
8+
vm.component('m-floating-label', FloatingLabel)
9+
}
10+
}
11+
export default plugin
12+
13+
initPlugin(plugin)

components/floating-label/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "@material/floating-label/mdc-floating-label";

components/textfield/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
### Markup
44

55
```html
6-
<m-text-field v-model="text">
7-
Textfield
6+
<m-text-field v-model="text" id="textfield">
7+
<m-floating-label for="textfield">Textfield label</m-floating-label>
88
<m-line-ripple slot="bottomLine"/>
99
</m-text-field>
10-
<m-text-field v-model="pw" type="password" required minlength="8" aria-controls="pw-validation">
11-
Password
10+
<m-text-field v-model="pw" id="passwordfield" type="password" required minlength="8" aria-controls="pw-validation">
11+
<m-floating-label for="passwordfield">Password</m-floating-label>
1212
<m-line-ripple slot="bottomLine"/>
1313
</m-text-field>
1414
<m-text-field-helptext id="pw-validation">
@@ -35,12 +35,10 @@ data() {
3535
| upgraded | Boolean | false | whether the textfield should be upgraded when it already has a value (FOUC) |
3636
| fullWidth | Boolean | false | expand the textfield to max width |
3737
| box | Boolean | false | draws a box around the textfield |
38-
| labelFloat | Boolean | false | whether the label should float above the input field that already has a value (FOUC) |
3938
| outlined | Boolean | false | draws an outer line around input field |
4039
| dense | Boolean | false | whether the textfield should be dense |
4140
| focused | Boolean | false | whether the textfield should be in focus |
4241
| textarea | Boolean | false | whether the textfield should be a textarea |
43-
| shake | Boolean | false | whether the textfield label should shake |
4442

4543
### Slots
4644

components/textfield/Textfield.vue

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
@input="onInput"
1616
v-bind="$attrs"
1717
v-if="textarea"/>
18-
<label
19-
class="mdc-text-field__label"
20-
:class="classesLabel"
21-
v-if="$slots['default'] && !fullWidth">
22-
<slot />
23-
</label>
18+
<slot v-if="$slots['default'] && !fullWidth"/>
2419
<div
2520
v-if="outlined"
2621
class="mdc-text-field__outline">
@@ -62,10 +57,6 @@ export default {
6257
type: Boolean,
6358
default: false
6459
},
65-
labelFloat: {
66-
type: Boolean,
67-
default: false
68-
},
6960
outlined: {
7061
type: Boolean,
7162
default: false
@@ -81,17 +72,12 @@ export default {
8172
textarea: {
8273
type: Boolean,
8374
default: false
84-
},
85-
shake: {
86-
type: Boolean,
87-
default: false
8875
}
8976
},
9077
data () {
9178
return {
9279
mdcTextField: null,
9380
mdcRipple: null,
94-
float: false
9581
}
9682
},
9783
computed: {
@@ -108,17 +94,6 @@ export default {
10894
'mdc-text-field--focused': this.focused,
10995
'mdc-text-field--textarea': this.textarea
11096
}
111-
},
112-
classesLabel () {
113-
return {
114-
'mdc-text-field__label--float-above': this.float,
115-
'mdc-text-field__label--shake': this.shake
116-
}
117-
}
118-
},
119-
watch: {
120-
value () {
121-
this.value === '' ? this.float = false : this.float = true
12297
}
12398
},
12499
mounted () {
@@ -135,7 +110,6 @@ export default {
135110
}
136111
137112
this.mdcTextField = MDCTextField.attachTo(this.$el)
138-
this.float = this.labelFloat
139113
},
140114
beforeDestroy () {
141115
this.mdcTextField.destroy()

demo/views/TextfieldView.vue

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
</m-typo-body>
1010
</m-layout-grid-cell>
1111
<m-layout-grid-cell :span="2">
12-
<m-text-field v-model="text">
13-
Textfield
12+
<m-text-field id="textfield1">
13+
<m-floating-label for="textfield1">Textfield</m-floating-label>
1414
<m-line-ripple slot="bottomLine"/>
1515
</m-text-field>
1616
</m-layout-grid-cell>
1717
<m-layout-grid-cell :span="2">
18-
<m-text-field v-model="pw" type="password" required minlength="8" aria-controls="pw-validation">
19-
Password
18+
<m-text-field type="password" id="textfield2" required minlength="8" aria-controls="pw-validation">
19+
<m-floating-label for="textfield2">Password</m-floating-label>
2020
<m-line-ripple slot="bottomLine"/>
2121
</m-text-field>
2222
<m-text-field-helptext id="pw-validation">
@@ -25,69 +25,73 @@
2525
</m-layout-grid-cell>
2626
<m-layout-grid-cell :span="8" />
2727
<m-layout-grid-cell :span="2">
28-
<m-text-field v-model="text" box>
29-
Textfield
28+
<m-text-field
29+
box
30+
id="textfield3">
31+
<m-floating-label for="textfield3">Textfield</m-floating-label>
3032
</m-text-field>
3133
</m-layout-grid-cell>
3234
<m-layout-grid-cell :span="2">
3335
<m-text-field
34-
v-model="text"
35-
box>
36+
box
37+
id="textfield4">
3638
<m-icon
3739
slot="leadingIcon"
3840
icon="person"/>
39-
Textfield
41+
<m-floating-label for="textfield4">Textfield</m-floating-label>
4042
</m-text-field>
4143
</m-layout-grid-cell>
4244
<m-layout-grid-cell :span="2">
4345
<m-text-field
44-
v-model="text"
45-
box>
46+
box
47+
id="textfield5">
4648
<m-icon
4749
slot="trailingIcon"
4850
icon="person"/>
49-
Textfield
51+
<m-floating-label for="textfield5">Textfield</m-floating-label>
5052
</m-text-field>
5153
</m-layout-grid-cell>
5254
<m-layout-grid-cell :span="12">
53-
<m-text-field v-model="text" placeholder="Fullwidth" full-width>
55+
<m-text-field placeholder="Fullwidth" full-width>
5456
<m-line-ripple slot="bottomLine"/>
5557
</m-text-field>
5658
</m-layout-grid-cell>
5759
<m-layout-grid-cell :span="12">
58-
<m-text-field v-model="text" textarea>
59-
Textarea
60+
<m-text-field
61+
textarea
62+
id="textfield6">
63+
<m-floating-label for ="textfield6">Textarea</m-floating-label>
6064
</m-text-field>
6165
</m-layout-grid-cell>
6266
<m-layout-grid-cell :span="12">
63-
<m-text-field v-model="text" outlined>
64-
Outlined
67+
<m-text-field
68+
outlined
69+
id="textfield7">
70+
<m-floating-label for="textfield7">Outlined</m-floating-label>
6571
</m-text-field>
6672
</m-layout-grid-cell>
6773
</m-layout-grid-inner>
6874
</template>
6975

7076
<script>
7177
import Vue from 'vue'
78+
import FloatingLabel from '../../dist/floating-label'
7279
import LineRipple from '../../dist/line-ripple'
7380
import Icon from '../../dist/icon'
7481
import Textfield from '../../dist/textfield'
7582
83+
Vue.use(FloatingLabel)
7684
Vue.use(LineRipple)
7785
Vue.use(Icon)
7886
Vue.use(Textfield)
7987
8088
export default {
81-
data () {
82-
return {
83-
text: '',
84-
pw: ''
85-
}
86-
}
89+
8790
}
8891
</script>
8992

9093
<style lang="scss">
94+
@import "../../dist/floating-label/styles";
9195
@import "../../dist/line-ripple/styles";
9296
@import "../../dist/textfield/styles";
9397
</style>

webpack.config.lib.common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
drawer: path.resolve(components + '/drawer/index.js'),
1818
elevation: path.resolve(components + '/elevation/index.js'),
1919
fab: path.resolve(components + '/fab/index.js'),
20+
'floating-label': path.resolve(components + '/floating-label/index.js'),
2021
'form-field': path.resolve(components + '/form-field/index.js'),
2122
'grid-list': path.resolve(components + '/grid-list/index.js'),
2223
icon: path.resolve(components + '/icon/index.js'),

0 commit comments

Comments
 (0)