Skip to content

Commit

Permalink
fix(stripePricingTable): vue component warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed May 7, 2024
1 parent 6b98630 commit 6d038fa
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/runtime/components/ScriptStripePricingTable.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref } from 'vue'
import type { ElementScriptTrigger } from '../composables/useElementScriptTrigger'
import { useElementScriptTrigger, useScript } from '#imports'
import { onBeforeUnmount, useElementScriptTrigger, useScript } from '#imports'
const props = withDefaults(defineProps<{
trigger?: ElementScriptTrigger
Expand All @@ -18,28 +18,37 @@ const emit = defineEmits<{
ready: []
}>()
const rootEl = ref()
const rootEl = ref<HTMLDivElement | undefined>()
const containerEl = ref<HTMLDivElement | undefined>()
const { $script } = useScript(`https://js.stripe.com/v3/pricing-table.js`, {
trigger: useElementScriptTrigger({ trigger: props.trigger, el: rootEl }),
})
const pricingTable = ref<HTMLElement | undefined>()
$script.then(() => {
const StripePricingTable = window.customElements.get('stripe-pricing-table')!
const stripePricingTable = new StripePricingTable()
stripePricingTable.setAttribute('publishable-key', props.publishableKey)
stripePricingTable.setAttribute('pricing-table-id', props.pricingTableId)
if (props.clientReferenceId)
stripePricingTable.setAttribute('client-reference-id', props.clientReferenceId)
if (props.customerEmail)
stripePricingTable.setAttribute('customer-email', props.customerEmail)
if (props.customerSessionClientSecret)
stripePricingTable.setAttribute('customer-session-client-secret', props.customerSessionClientSecret)
pricingTable.value = stripePricingTable
rootEl.value!.appendChild(stripePricingTable)
emit('ready')
})
onBeforeUnmount(() => {
pricingTable.value?.remove()
})
</script>

<template>
<div ref="rootEl">
<ClientOnly>
<stripe-pricing-table
v-bind="$attrs"
:publishable-key="publishableKey"
:pricing-table-id="pricingTableId"
:client-reference-id="clientReferenceId"
:customer-email="customerEmail"
:customer-session-client-secret="customerSessionClientSecret"
/>
</ClientOnly>
<div ref="containerEl" />
<slot v-if="$script.status.value === 'loading'" name="loading" />
<slot v-if="$script.status.value === 'awaitingLoad'" name="awaitingLoad" />
<slot />
Expand Down

0 comments on commit 6d038fa

Please sign in to comment.