Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Major improvements v1.0.0 #120

Merged
merged 14 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: implement flexible stripe elements
  • Loading branch information
softbeehive committed Mar 27, 2021
commit 9ccc2323311225dd14e74a13b124ea0b6290a2d7
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-stripe-elements-plus",
"version": "0.4.0",
"version": "1.0.0",
"description": "Stripe Elements components for Vue",
"main": "./dist/index.js",
"scripts": {
Expand All @@ -19,7 +19,7 @@
],
"author": {
"name": "Oleksandr Bystrikov",
"url": "https://github.com/ectoflow"
"url": "https://softbeehive.com"
},
"license": "MIT",
"bugs": {
Expand Down
28 changes: 0 additions & 28 deletions src/Card.vue

This file was deleted.

28 changes: 0 additions & 28 deletions src/CardCvc.vue

This file was deleted.

28 changes: 0 additions & 28 deletions src/CardExpiry.vue

This file was deleted.

28 changes: 0 additions & 28 deletions src/CardNumber.vue

This file was deleted.

29 changes: 0 additions & 29 deletions src/PostalCode.vue

This file was deleted.

40 changes: 0 additions & 40 deletions src/StripeElement.vue

This file was deleted.

14 changes: 14 additions & 0 deletions src/components/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<stripe-element v-bind="[$props, $attrs, $listeners]" type="card" />
</template>

<script>
import props from './props'
import StripeElement from './StripeElement'

export default {
name: 'Card',
components: { StripeElement },
props,
}
</script>
14 changes: 14 additions & 0 deletions src/components/CardCvc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<stripe-element v-bind="[$props, $attrs, $listeners]" type="cardCvc" />
</template>

<script>
import props from './props'
import StripeElement from './StripeElement'

export default {
name: 'CardCvc',
components: { StripeElement },
props,
}
</script>
14 changes: 14 additions & 0 deletions src/components/CardExpiry.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<stripe-element v-bind="[$props, $attrs, $listeners]" type="cardExpiry" />
</template>

<script>
import props from './props'
import StripeElement from './StripeElement'

export default {
name: 'CardExpiry',
components: { StripeElement },
props,
}
</script>
14 changes: 14 additions & 0 deletions src/components/CardNumber.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<stripe-element v-bind="[$props, $attrs, $listeners]" type="cardNumber" />
</template>

<script>
import props from './props'
import StripeElement from './StripeElement'

export default {
name: 'CardNumber',
components: { StripeElement },
props,
}
</script>
76 changes: 76 additions & 0 deletions src/components/StripeElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template>
<div></div>
</template>

<script>
import props from './props'
import { createElement, destroy } from '../stripeElements'

export default {
name: 'StripeElement',
props,

data() {
return {
stripeElement: undefined,
domElement: document.createElement('div'),
}
},

computed: {
elementsUsable() {
const elms = this.elements
if (!elms) return false
return Object.keys(this.elements).length > 0
},
},

watch: {
options: {
handler(opts) {
if (opts && this.stripeElement) {
this.stripeElement.update(opts)
}
},
deep: true,
},
},

beforeDestroy() {
if (this.stripeElement) {
this.stripeElement.unmount()
this.stripeElement.destroy()
}
},

mounted() {
if (this.elementsUsable) {
this.mountElement()
this.handleEvents()
}
},

methods: {
mountElement() {
const domEl = this.domElement
this.stripeElement = createElement(this.elements, this.type, this.options)
this.stripeElement.mount(domEl)
this.$el.appendChild(domEl)

return this.stripeElement
},

handleEvents() {
// See stripe element events: https://stripe.com/docs/js/element/events
const eventTypes = ['change', 'ready', 'focus', 'blur', 'escape']
eventTypes.forEach((type) => {
this.stripeElement.on(type, this.eventHandler.bind(this, type))
})
},

eventHandler(type, e) {
return this.$emit(type, e)
},
},
}
</script>
Loading