1.0.24 • Published 11 months ago

types-woocommerce v1.0.24

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

types-woocommerce

Install:

bun install types-woocommerce -D

global.d.ts

/// <reference types="types-woocommerce" />

Usage example

import { registerPaymentMethod } from '@woocommerce/blocks-registry'
import { getSetting } from '@woocommerce/settings'
import type {
    PaymentMethodBaseProps,
    PaymentMethodConfiguration,
    PaymentMethodProps,
} from '@woocommerce/types/payments'
import { decodeEntities } from '@wordpress/html-entities'
import * as React from 'react'

type Settings = {
    title: string
    description: string
    supports: string[]
}

document.addEventListener('DOMContentLoaded', function() {
    if (!window.wc || !window.wc.wcBlocksRegistry || !window.wc.wcSettings)
        return
    const PAYMENT_METHOD_NAME = window.TOKENPAY_SETTINGS.gatewayId
    const settings = getSetting<Partial<Settings>>(
        `${PAYMENT_METHOD_NAME}_data`,
        {},
    )
    const title = decodeEntities(settings.title ?? '')
    const description = decodeEntities(settings.description ?? '')

    const Label: React.FC<PaymentMethodBaseProps> = ({ components }) => {
        const { PaymentMethodLabel } = components
        return (
            <PaymentMethodLabel
                icon={''}
                text={title}
            />
        )
    }

    const Content: React.FC<PaymentMethodProps> = () => {
        return <div>{description}</div>
    }

    const paymentMethod: PaymentMethodConfiguration = {
        ariaLabel: title,
        canMakePayment: () => true,
        content: React.createElement(Content),
        edit: React.createElement(Content),
        label: React.createElement(Label),
        name: PAYMENT_METHOD_NAME,
        supports: {
            features: settings.supports,
        },
    }
    registerPaymentMethod(paymentMethod)
})

Vite

To replace these aliases in vite, use the rollup-plugin-woocommerce-dependency-extraction plugin

1.0.24

11 months ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago