Skip to content

Commit 2b23610

Browse files
committed
feat(MdButton): add md-ripple option to enable/disable the effect
1 parent cad9bf9 commit 2b23610

File tree

3 files changed

+87
-67
lines changed

3 files changed

+87
-67
lines changed

docs/app/pages/Components/Button/Button.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,23 @@
7272
description: 'Create a anchor on the button. In this case the generated tag will be <a>.',
7373
defaults: 'null'
7474
},
75+
{
76+
name: 'type',
77+
type: 'String',
78+
description: 'Apply a type to button - Don\'t affect links.',
79+
defaults: 'button'
80+
},
7581
{
7682
name: 'disabled',
7783
type: 'Boolean',
7884
description: 'Disable the button and prevent his actions.',
7985
defaults: 'false'
8086
},
8187
{
82-
name: 'type',
83-
type: 'String',
84-
description: 'Apply a type to button - Don\'t affect links.',
85-
defaults: 'button'
88+
name: 'md-ripple',
89+
type: 'Boolean',
90+
description: 'Enable/Disable the ripple effect.',
91+
defaults: 'true'
8692
}
8793
]
8894
},

docs/app/pages/Components/Button/examples/RegularButtons.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div>
44
<small>Flat</small>
55
<md-button>Default</md-button>
6+
<md-button :md-ripple="false">Ripple Off</md-button>
67
<md-button class="md-primary">Primary</md-button>
78
<md-button class="md-accent">Accent</md-button>
89
<md-button disabled>Disabled</md-button>
@@ -11,6 +12,7 @@
1112
<div>
1213
<small>Raised</small>
1314
<md-button class="md-raised">Default</md-button>
15+
<md-button class="md-raised" :md-ripple="false">Ripple Off</md-button>
1416
<md-button class="md-raised md-primary">Primary</md-button>
1517
<md-button class="md-raised md-accent">Accent</md-button>
1618
<md-button class="md-raised" disabled>Disabled</md-button>

src/components/mdButton/mdButton.vue

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
<script>
2+
import MdComponent from 'core/MdComponent'
3+
import ripple from 'core/mixins/ripple'
4+
import MdButtonContent from './MdButtonContent'
5+
6+
export default new MdComponent({
7+
name: 'MdButton',
8+
components: {
9+
MdButtonContent
10+
},
11+
mixins: [ripple],
12+
props: {
13+
href: String,
14+
type: {
15+
type: String,
16+
default: 'button'
17+
},
18+
disabled: Boolean,
19+
mdRipple: {
20+
type: Boolean,
21+
default: true
22+
},
23+
to: [String, Object]
24+
},
25+
render (createElement) {
26+
const buttonContent = createElement('md-button-content', {
27+
attrs: {
28+
mdRipple: this.mdRipple,
29+
disabled: this.disabled
30+
}
31+
}, this.$slots.default)
32+
let buttonAttrs = {
33+
staticClass: 'md-button',
34+
class: [
35+
this.$mdActiveTheme,
36+
{
37+
'md-ripple-off': !this.mdRipple
38+
}
39+
],
40+
attrs: {
41+
href: this.href,
42+
disabled: this.disabled,
43+
type: !this.href && (this.type || 'button')
44+
},
45+
on: {
46+
click: ($event) => {
47+
this.$emit('click', $event)
48+
}
49+
}
50+
}
51+
let tag = 'button'
52+
53+
if (this.href) {
54+
tag = 'a'
55+
} else if (this.$router && this.to) {
56+
tag = 'router-link'
57+
buttonAttrs.attrs = {
58+
...this.$options.propsData,
59+
to: this.to
60+
}
61+
}
62+
63+
return createElement(tag, buttonAttrs, [buttonContent])
64+
}
65+
})
66+
</script>
67+
168
<style lang="scss">
269
@import "~components/MdAnimation/variables";
370
@import "~components/MdElevation/mixins";
@@ -73,6 +140,10 @@
73140
opacity: .2;
74141
}
75142
}
143+
144+
&.md-ripple-off:active:before {
145+
opacity: .26;
146+
}
76147
}
77148
78149
&::-moz-focus-inner {
@@ -104,6 +175,10 @@
104175
&:active {
105176
@include md-elevation(8);
106177
}
178+
179+
&.md-ripple-off:active:before {
180+
opacity: .2;
181+
}
107182
}
108183
109184
+ .md-button {
@@ -154,67 +229,4 @@
154229
transition-duration: 1.2s;
155230
}
156231
}
157-
158-
.md-button-content {
159-
position: relative;
160-
z-index: 2;
161-
}
162232
</style>
163-
164-
<script>
165-
import MdComponent from 'core/MdComponent'
166-
import ripple from 'core/mixins/ripple'
167-
import MdButtonContent from './MdButtonContent'
168-
169-
export default new MdComponent({
170-
name: 'MdButton',
171-
components: {
172-
MdButtonContent
173-
},
174-
mixins: [ripple],
175-
props: {
176-
href: String,
177-
type: {
178-
type: String,
179-
default: 'button'
180-
},
181-
disabled: Boolean,
182-
to: [String, Object]
183-
},
184-
render (createElement) {
185-
const buttonContent = createElement('md-button-content', {
186-
attrs: {
187-
mdRipple: this.mdRipple,
188-
disabled: this.disabled
189-
}
190-
}, this.$slots.default)
191-
let buttonAttrs = {
192-
staticClass: 'md-button',
193-
class: [this.$mdActiveTheme],
194-
attrs: {
195-
href: this.href,
196-
disabled: this.disabled,
197-
type: this.type || 'button'
198-
},
199-
on: {
200-
click: ($event) => {
201-
this.$emit('click', $event)
202-
}
203-
}
204-
}
205-
let tag = 'button'
206-
207-
if (this.href) {
208-
tag = 'a'
209-
} else if (this.to) {
210-
tag = 'router-link'
211-
buttonAttrs.attrs = {
212-
...this.$options.propsData,
213-
to: this.to
214-
}
215-
}
216-
217-
return createElement(tag, buttonAttrs, [buttonContent])
218-
}
219-
})
220-
</script>

0 commit comments

Comments
 (0)