Getting Started with TeakUI Components

This getting started guide assumes you already have TailwindCSS running on your project. If you don't, visit our TailwindCSS setup guide first.

Step 1: Download and Unzip

Download the teakui-[version].zip file and extract it into a new directory.

You should now see a folder named teakui-release.

Inside you'll find a README.md file along with a [version]/components directory, like:

/teakui-release

1.0.0/components/
README.md

Step 2: Locate Component Code

You can browse the component files to find the component code you're looking for. These are organized into groups based on the type of component. To view previews of the components, just visit our TeakUI Components page.

As an example, let's open the components/accordions/accordion.html file in your text editor. You'll see something like the following code. Our example here has been simplified for the purpose of this documentation.

/components/accordions/accordion.html

<!-- BEGIN SCRIPT CODE HERE. PLACE IN HEAD SECTION OF YOUR CODE. -->
<!-- Alpine Collapse Plugin -->
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/[email protected]/dist/cdn.min.js"></script>

<!-- Main AlpineJS script. This is only needed for components that specify "Requires JS". -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
<!-- END SCRIPT CODE HERE -->

<!-- BEGIN COMPONENT CODE HERE -->

<!-- Accordion (Requires AlpineJS Collapse Plugin) -->
<div class="mx-auto">
    <div class="border-b border-b-slate-300" x-data="accordion">
        COMPONENT HTML CODE HERE
    </div>
</div>

<style type="text/css">
        [x-cloak] { display: none !important; }
</style>

<script>
    document.addEventListener('alpine:init', () => {
        Alpine.data('accordion', () => ({
            SCRIPT CODE HERE
        }))
    })
</script>
<!-- /Accordion -->

<!-- END COMPONENT CODE HERE -->

All components follow this basic format.

Step 3: Copy JS Library Code

At the top of the file, you'll find any necessary JavaScript libraries that will need included. Here we have 2 AlpineJS files - the Collapse Plugin comes first and then the main AlpineJS library. These will both need included in this order, in the head of your html code.

<!-- Alpine Collapse Plugin -->
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/[email protected]/dist/cdn.min.js"></script>

<!-- Main AlpineJS script. This is only needed for components that specify "Requires JS". -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>

Note: there are other methods of installing AlpineJS. View our AlpineJS guide for more details.

Step 4: Copy Component Code

After the JavaScript code you'll find the component html code denoted by the <!--BEGIN COMPONENT CODE HERE--> comment. You'll want to copy and paste all of the code below that line into the <body> of your html.

<!-- BEGIN COMPONENT CODE HERE -->

Step 5: Copy x-cloak CSS

For some components, especially those that require AlpineJS, you may find a snippet of css in the component code. This is used to handle hiding certain components before AlpineJS is fully initialized on a page.

<style type="text/css">
        [x-cloak] { display: none !important; }
</style>

You'll want to be sure to include this css code once in your TailwindCSS custom code. You can also include this snipped directly in your html source if needed. See our TailwindCSS setup guide for more details.

Step 6: Copy AlpineJS Script Code

Finally for any components that require AlpineJS, you'll find some code within script tags at the end of the component. This code handles the associated AlpineJS functionality for this component. You can either copy this code directly into your html after the component code or set it up in an external JS file. See our AlpineJS setup guide for more details.

<script>
    document.addEventListener('alpine:init', () => {
        Alpine.data('accordion', () => ({
            SCRIPT CODE HERE
        }))
    })
</script>

That's it!

You're now ready to go with your new component! These components are made to be flexible and easy to modify, so feel free to make any changes you wish to fit your layout.

If you have questions, visit our support page to contact us for help.

Thank you for building with Hey Teak!

TeakUI Components

Page Layouts

Navigation

Copyright © 2024 Hey Teak. A project by @tjwebdev.