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

Commit

Permalink
fix(ripple): wrong implementation (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
tychenjiajun authored Jul 29, 2019
1 parent 851f5c4 commit df0d8a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
20 changes: 6 additions & 14 deletions components/ripple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,13 @@ Material Components Vue provides a customized directive `v-ripple` to provide an

### Activate or deactivate using binding value

```html
<template>
<my-button v-ripple.primary="activate">Button</my-button>
</template>

<script>
export default {
mixins: [baseComponentMixin, themeClassMixin],
data () {
return {
activate: false // activate when changed from false to true, otherwise deactivate
}
}
}
</script>
```html
<button ref="ripple">Button</button> <!--ref name can be any string-->
```
```js
this.$refs.ripple.mdcRipple.activated() // activated
this.$refs.ripple.mdcRipple.deactivated() // deactivated
```

Content below is deprecated, which means they may be removed in the future versions.
Expand Down
17 changes: 4 additions & 13 deletions components/ripple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import './styles.scss'

import { initPlugin } from '../'

function setup (el, binding) {
function setupClasses (el, binding) {
const mod = binding.modifiers
mod.customized ? el.classList.remove('mdc-ripple-surface') : el.classList.add('mdc-ripple-surface')
mod.primary ? el.classList.add('mdc-ripple-surface--primary') : el.classList.remove('mdc-ripple-surface--primary')
if (mod.accent) {
el.classList.add('mdc-ripple-surface--accent')
}
return MDCRipple.attachTo(el)
mod.accent ? el.classList.add('mdc-ripple-surface--accent') : el.classList.remove('mdc-ripple-surface--accent')
}

const plugin = {
install (vm) {
vm.component('m-ripple', Ripple)
vm.directive('ripple', {
bind: function (el, binding) {
const mdcRipple = setup(el, binding)
setupClasses(el, binding)
if (!binding.modifiers['css-only']) {
const mdcRipple = MDCRipple.attachTo(el)
Object.defineProperty(el, 'mdcRipple', {
configurable: true,
enumerable: false,
Expand All @@ -29,13 +27,6 @@ const plugin = {
})
}
},
componentUpdated: function (el, binding) {
if (typeof binding.oldValue === 'boolean' && typeof binding.value === 'boolean' && binding.oldValue !== binding.value && binding.value) {
if (el.mdcRipple) el.mdcRipple.activate()
} else {
if (el.mdcRipple) el.mdcRipple.deactivate()
}
},
unbind: function (el) {
if (el.mdcRipple) {
el.mdcRipple.destroy()
Expand Down
9 changes: 3 additions & 6 deletions docs/.vuepress/components/RippleDemo.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div>
<ComponentSection flex-direction="column">
<my-button v-if="checkboxProps[0].value" v-ripple.primary="radioProps[0].value"/>
<button style="width: 100px; height: 40px; background: deepskyblue; outline: none; border: none; color: white; border-radius: 4px;" v-if="checkboxProps[1].value" v-ripple.accent="radioProps[0].value">BUTTON</button>
<my-button v-if="checkboxProps[0].value" v-ripple.primary/>
<button style="width: 100px; height: 40px; background: deepskyblue; outline: none; border: none; color: white; border-radius: 4px;" v-if="checkboxProps[1].value" v-ripple.accent>BUTTON</button>
<my-button v-ripple.primary.css-only v-if="checkboxProps[2].value"/>
</ComponentSection>
<ComponentProps
Expand All @@ -18,10 +18,7 @@
components: { MyButton },
data () {
return {
radioProps: [
{ prop: 'activate', value: false },
{ prop: 'deactivate', value: true }
],
radioProps: [],
checkboxProps: [
{ prop: 'primary', value: false },
{ prop: 'accent', value: true },
Expand Down

0 comments on commit df0d8a5

Please sign in to comment.