# Web Component

As an alternative to using the `Tebex.checkout` JavaScript API, Tebex.js also provides a `tebex-checkout` [Web Component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).&#x20;

With this, you can embed a Tebex Checkout into your page by placing the `<tebex-checkout></tebex-checkout>` HTML tag anywhere in your page's `<body>`, so long as Tebex.js is also loaded into the page:

```html
<html>
    <head>
        <script defer src="https://js.tebex.io/v/1.js"></script>
    </head>
    <body>
        <tebex-checkout></tebex-checkout>
    </body>
</html>
```

{% hint style="info" %}
Due to Web Component quirks, you must include both opening and closing HTML tags (like `<tebex-checkout></tebex-checkout>`). Using a self-closing tag (`<tebex-checkout/>`) is not valid.
{% endhint %}

### Modes

Two modes are available for `tebex-checkout`:

#### Popup Mode

This is the default mode. The component will display nothing initially, but will launch the checkout as a popup when activated, akin to [`Tebex.checkout.launch()`](#launch).&#x20;

The simplest way to achieve this is by placing a button inside the `<tebex-checkout>` and `</tebex-checkout>` tags. Tebex.js will automatically attach handlers so that clicking the button will launch the checkout:

```html
<tebex-checkout ident="...">
    <button>Open Checkout</button>
</tebex-checkout>
```

{% hint style="info" %}
You don't have to use a button here, it could be any HTML - styled however you see fit - as long as it's clickable!
{% endhint %}

Alternatively, if you would prefer to open the checkout from your code (i.e. instead of having a user click something), you can leave the `tebex-checkout` empty and add the `open` attribute to it whenever you are ready for it to launch:

```html
<script>
    function openCheckout() {
        const checkout = document.getElementById("checkout");
        checkout.setAttribute("open", "true");
    }
    // call openCheckout() when you want the checkout to launch...
</script>

<tebex-checkout id="checkout" ident="..."></tebex-checkout>
```

#### Inline Mode

By adding the `inline` attribute to the checkout element, the element will instead be rendered inline within the rest of the page, in a similar way to [`Tebex.checkout.render()`](#custom-render-location).

It will automatically take up 100% of the width of its container and set its height to a sane default for  displaying the iframe checkout content, but you can use the `height` attribute to manually set the height, in CSS pixels:

```html
<tebex-checkout inline ident="..." height="800"></tebex-checkout>
```

### Common Attributes

HTML attributes take the place of [`Tebex.checkout.init()`](#config)'s config options, along with a couple of extra options:

<table><thead><tr><th width="241">Attribute</th><th width="502">Details</th></tr></thead><tbody><tr><td><code>ident</code></td><td><strong>Required.</strong> This should be the checkout request ident received via the <a href="../../headless-api">Headless API </a>or <a href="../../checkout-api">Checkout API</a>.</td></tr><tr><td><code>locale</code></td><td>Default language for checkout text. Specified as an ISO locale code, e.g. <code>"en_US"</code> for American English, <code>"de_DE"</code> for German, etc. Users can change the language from within the checkout panel UI.</td></tr><tr><td><code>theme</code></td><td><p>Checkout color theme. Must be one of the following options:</p><ul><li><code>"light"</code></li><li><code>"dark"</code></li><li><code>"auto"</code> - applies the theme based on the user's light/dark mode system preference.</li><li><code>"default"</code> - applies the theme option you have selected in your store's settings.</li></ul></td></tr><tr><td><code>color-primary</code></td><td>Checkout primary brand color.</td></tr><tr><td><code>color-secondary</code></td><td>Checkout secondary brand color.</td></tr><tr><td><code>popup-on-mobile</code></td><td>If set, when in popup mode, the checkout will always launch in the current browser window rather than opening a new page, even on mobile devices.</td></tr><tr><td><code>redirect-on-complete</code></td><td>If set to a URL, the user will be redirected to this page once the payment has completed.</td></tr></tbody></table>

For example:

```html
<tebex-checkout theme="dark" color-primary="#ff0000"></tebex-checkout>
```

### Framework Integration

Web Components such as `tebex-checkout` integrate seamlessly with most modern frontend frameworks without needing any special setup. However, if you are using **Vue**, please note that you may need to adjust your config to [**skip component resolution**](https://vuejs.org/guide/extras/web-components#skipping-component-resolution) for `tebex-checkout`.

#### Example

In Vue, this is how you could include an inline `tebex-checkout` component and call a function when the payment complete event fires:

```html
<script setup>
   import "@tebexio/tebex.js";

    const ident = ref("");

    // something to fetch the ident here
    
    function onPaymentComplete() {
        console.log("payment completed");
    }
</script>

<template>
    <tebex-checkout inline :ident="ident" @payment:complete="onPaymentComplete"></tebex-checkout>
</template>
```
