<div id="top"></div>
 
<br />
<div align="center">
     <a href="https://salla.dev">
        <img src="https://salla.dev/wp-content/uploads/2023/03/1-Light.png" alt="Logo">
     </a>
     <h1 align="center">Twilight JS Web Components</h1>
     <p align="center">
         A ready-designed and styled set of js web components for Salla stores. 
          <br />
          <a href="https://salla.dev/"><strong>Explore our blogs »</strong></a>
          <br />
          <br />
          <a href="https://github.com/SallaApp/Salla-CLI/issues/new">Report Bug</a> ·
          <a href="https://github.com/SallaApp/Salla-CLI/discussions/new">Request Feature</a> . 
          <a href="https://t.me/salladev">&lt;/Salla Developers&gt;</a> .
          <a href="https://docs.salla.dev/doc-422053/?nav=01HNFTD5Y5ESFQS3P9MJ0721VM">Offical Documentation</a>
     </p>
</div>

<!-- TABLE OF CONTENTS -->
<details open>
     <summary>Table of Contents</summary>
     <ol>
          <li>
               <a href="#overview">Overview</a>
          </li>
          <li>
               <a href="#getting-started">Getting Started</a>
               <ul>
               <li><a href="#benefits">List of Twilight JS Web Components</a></li>
              <li><a href="#benefits">Benefits</a></li>
               </ul>
          <li><a href="#installation">Installation</a></li>
          <li><a href="#usage">Usage</a></li>
          <li><a href="#events">Events</a></li>
          <li><a href="#support">Support</a></li>
          <li><a href="#contributing">Contributing</a></li>
          <li><a href="#credits">Credits</a></li>
          <li><a href="#license">License</a></li>
          </li>
     </ol>
</details>
<!-- Overview -->

## Overview

**Twilight** comes with a ready-designed and styled set of web components for Salla stores. For example, ready components to display the login form, product availability section, search bar, localization menu, and many more. **Twilight JS Web Components** are a collection of high-level building blocks and reusable web components that can be built together to swiftly develop the UI for custom Salla Themes, governed by clear guidelines.


<br/>

## Getting Started

**JS Web Components** were built from the ground up to be simple to learn and use, with various thoughtfully constructed user interface components. Its complete compatibility with the themes' structure and architecture makes it easy to customize, as the documentation explains.

### List of Twilight JS Web Components

Below is a list of the ready-made Twilight JS Web Components which can be used easily. Following, in this part of the document, each component is explained in detail.

Every web component comes with a list of **properties and events** that make that component customizable. Besides, each web component uses methods from the [**Twilight JS SDK**](https://docs.salla.dev/doc-422610/?nav=01HNFTDZPB31Y2E120R84YXKCX) to fetch any needed data from the backend.


| Component                                                                                | Code Tag                     | Description                                                                                                                                      |
| ---------------------------------------------------------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Advertisement](https://docs.salla.dev/doc-478502/?nav=01HNFTE06J4QC24T0D5BPRYKMD)       | `salla-advertisement       ` | Shows all the details about product advertisements.                                                                                              |
| [Apps Icons](https://docs.salla.dev/doc-478518/?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-apps-icons          ` | Shows clickable labels of Google Play Store and Apple Store for the Store's application.                                                         |
| [Add Product](https://docs.salla.dev/doc-422692?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-add-product-button  ` | Allows controllability over button text labels and behaviors based on the product-status and product-type properties.                            |
| [Breadcrumb](https://docs.salla.dev/doc-482370/?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-breadcrumb          ` | Helps users navigate by showing their path through pages, allowing them to easily go back by clicking on links.                                  |
| [Button](https://docs.salla.dev/doc-422694?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-button              ` | Shows a customizable button, in terms of size, color, style, status, position, etc.                                                              |
| [Cart Summary](https://docs.salla.dev/doc-422695?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-cart-summary        ` | Shows the icon of the shopping cart with a small circle badge indicating the number of items in the cart.                                        |
| [Color Picker](https://docs.salla.dev/doc-422696?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-color-picker        ` | Allows selection of a color using a variety of input methods.                                                                                    |
| [Comments](https://docs.salla.dev/doc-422697?nav=01HNFTE06J4QC24T0D5BPRYKMD)             | `salla-comments            ` | Displays a comment form for specific products or pages.                                                                                          |
| [Contacts](https://docs.salla.dev/doc-478494/?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-contacts            ` | Shows the store's contact information details.                                                                                                   |
| [Conditional Fields](https://docs.salla.dev/doc-422699?nav=01HNFTE06J4QC24T0D5BPRYKMD)   | `salla-conditional-fields  ` | Allows for hiding/displaying certain features in a product, such as size.                                                                        |
| [Conditional Offer](https://docs.salla.dev/doc-537931/?nav=01HNFTE06J4QC24T0D5BPRYKMD)   | `salla-conditional-offer   ` | Enables dynamic presentation of offers and discounts based on the customer's cart status.                                                        |
| [Count Down](https://docs.salla.dev/doc-422701?nav=01HNFTE06J4QC24T0D5BPRYKMD)           | `salla-count-down          ` | Shows the amount of time left until a given date.                                                                                                |
| [Datetime Picker](https://docs.salla.dev/doc-422702?nav=01HNFTE06J4QC24T0D5BPRYKMD)      | `salla-datetime-picker     ` | Allows users to select both date and time with the same control.                                                                                 |
| [File Upload](https://docs.salla.dev/doc-422703?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-file-upload         ` | Allows the user to upload a file or a number of files.                                                                                           |
| [Filters](https://docs.salla.dev/doc-422704?nav=01HNFTE06J4QC24T0D5BPRYKMD)              | `salla-filters             ` | Allows the user to filter the data in a variety of ways.                                                                                         |
| [Gifting](https://docs.salla.dev/doc-422705?nav=01HNFTE06J4QC24T0D5BPRYKMD)              | `salla-gifting             ` | Displays items as gifts, which can be used after the customer has completed a purchase.                                                          |
| [Infinite Scroll](https://docs.salla.dev/doc-422706?nav=01HNFTE06J4QC24T0D5BPRYKMD)      | `salla-infinite-scroll     ` | Allows for infinite scrolling to load content continuously as the user scrolls down a page.                                                      |
| [Installment](https://docs.salla.dev/doc-422707?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-installment         ` | Shows a block area for the available installment payment options provided for a specific product.                                                |
| [List Tile](https://docs.salla.dev/doc-422708?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-list-tile           ` | Used to display listing items in a tile form.                                                                                                    |
| [Loading](https://docs.salla.dev/doc-422709?nav=01HNFTE06J4QC24T0D5BPRYKMD)              | `salla-loading             ` | Used to convey that some data is currently loading to the user.                                                                                  |
| [Localization](https://docs.salla.dev/doc-422710?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-localization-modal  ` | Shows the menu for the store's available languages and currencies.                                                                               |
| [Login](https://docs.salla.dev/doc-422711?nav=01HNFTE06J4QC24T0D5BPRYKMD)                | `salla-login-modal         ` | Displays the login form, which prompts a user for their credentials in order to authenticate their access.                                       |
| [Loyalty](https://docs.salla.dev/doc-422712?nav=01HNFTE06J4QC24T0D5BPRYKMD)              | `salla-loyalty             ` | Displays a popup that represents the Loyalty program.                                                                                            |
| [Map](https://docs.salla.dev/doc-422713?nav=01HNFTE06J4QC24T0D5BPRYKMD)                  | `salla-map                 ` | Displays geographical maps from various sources with multiple layers and interaction through events.                                             |
| [Menu](https://docs.salla.dev/doc-478492/?nav=01HNFTE06J4QC24T0D5BPRYKMD)                | `salla-menu                ` | Shows nested list items that either appear on the header section or footer section.                                                              |
| [Metadata](https://docs.salla.dev/doc-464599/?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-metadata            ` | Shows detailed specifications for a product, displaying one or multiple sections of information like links, and text, etc.                       |
| [Modal](https://docs.salla.dev/doc-422714?nav=01HNFTE06J4QC24T0D5BPRYKMD)                | `salla-modal               ` | Displays a dialog box or pop-up window on top of the current page.                                                                               |
| [Offer](https://docs.salla.dev/doc-440408?nav=01HNFTE06J4QC24T0D5BPRYKMD)                | `salla-offer               ` | Displays offers, categories, products, banks, and discount information.                                                                          |
| [Offer Modal](https://docs.salla.dev/doc-422715?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-offer-modal         ` | Shows a list of products with an offer given by the store admin.                                                                                 |
| [Orders](https://docs.salla.dev/doc-508225/?nav=01HNFTE06J4QC24T0D5BPRYKMD)              | `salla-orders              ` | Shows a table with order details, such as order ID, product total, order status, and more.                                                       |
| [Payments](https://docs.salla.dev/doc-478374/?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-payments            ` | Shows the available payment options as labeled footer items.                                                                                     |
| [Placeholder](https://docs.salla.dev/doc-422716?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-placeholder         ` | Reserves space for content that soon will appear in a layout.                                                                                    |
| [Product Availability](https://docs.salla.dev/doc-422717?nav=01HNFTE06J4QC24T0D5BPRYKMD) | `salla-product-availability` | Shows the "Notify availability" option as a button for the registered customer.                                                                  |
| [Product Card](https://docs.salla.dev/doc-422718?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-product-card        ` | Contains content and actions about a single subject in a card display mode.                                                                      |
| [Product List](https://docs.salla.dev/doc-422719?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-product-list        ` | Displays a group of related products with some information, such as products' names, prices, and other relevant information in an organized way. |
| [Product Options](https://docs.salla.dev/doc-422720?nav=01HNFTE06J4QC24T0D5BPRYKMD)      | `salla-product-options     ` | Shows customizable product fields before proceeding to ordering.                                                                                 |
| [Product Size Guide](https://docs.salla.dev/doc-422721?nav=01HNFTE06J4QC24T0D5BPRYKMD)   | `salla-product-size-guide  ` | Enables the merchant to add product measurements of height, weight, depth and other metrics.                                                     |
| [Products Slider](https://docs.salla.dev/doc-422722?nav=01HNFTE06J4QC24T0D5BPRYKMD)      | `salla-products-slider     ` | Navigates horizontally through a group of related products.                                                                                      |
| [Progress Bar](https://docs.salla.dev/doc-422723?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-progress-bar        ` | Displays a progress bar indicating that data processing is underway.                                                                             |
| [Quantity Input](https://docs.salla.dev/doc-422724?nav=01HNFTE06J4QC24T0D5BPRYKMD)       | `salla-quantity-input      ` | Allows the customer to use a counter to specify the needed quantity of a specific product.                                                       |
| [Quick Buy](https://docs.salla.dev/doc-422725?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-quick-buy           ` | Allows for placing the Quick Buy button for a quickly checkout and pay for products.                                                             |
| [Quick Order](https://docs.salla.dev/doc-422726?nav=01HNFTE06J4QC24T0D5BPRYKMD)          | `salla-quick-order         ` | Allows the customer to quickly checkout and pay for products.                                                                                    |
| [Rating Stars](https://docs.salla.dev/doc-422727?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-rating-stars        ` | Displays a form of rating scale using a star glyph.                                                                                              |
| [Rating Modal](https://docs.salla.dev/doc-422728?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-rating-modal        ` | Displays the rating scale for a store, product, or shipping company.                                                                             |
| [Reviews](https://docs.salla.dev/doc-508226/?nav=01HNFTE06J4QC24T0D5BPRYKMD)             | `salla-reviews             ` | Displays vertically scrollable reviews, which can its data source can be customized.                                                           |
| [Reviews Summary](https://docs.salla.dev/doc-602149/?nav=01HNFTE06J4QC24T0D5BPRYKMD)     | `salla-reviews-summary     ` | Allows users to display the general rating out of 5 stars on the product details page.                                                           |
| [Scopes (Branches)](https://docs.salla.dev/doc-422729?nav=01HNFTE06J4QC24T0D5BPRYKMD)    | `salla-scopes              ` | Shows a list of scopes (branches) owned by the store.                                                                                            |
| [Search](https://docs.salla.dev/doc-422730?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-search              ` | Shows a search box, field, or bar.                                                                                                               |
| [Sheet](https://docs.salla.dev/doc-422733?nav=01HNFTE06J4QC24T0D5BPRYKMD)                | `salla-sheet               ` | Baseline layout foundation for other components to be set on.                                                                                    |
| [Skeleton](https://docs.salla.dev/doc-422731?nav=01HNFTE06J4QC24T0D5BPRYKMD)             | `salla-skeleton            ` | Displays an indication to the user that something is coming but not yet available.                                                               |
| [Slider](https://docs.salla.dev/doc-422735?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-slider              ` | Gathers numerical user data by reflecting a range of values along a bar.                                                                         |
| [Social](https://docs.salla.dev/doc-499802?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-social              ` | Displays a list of the store's social media account.                                                                                             |
| [Social-share](https://docs.salla.dev/doc-422736?nav=01HNFTE06J4QC24T0D5BPRYKMD)         | `salla-social-share        ` | Displays a menu with social media platforms.                                                                                                     |
| [Swiper](https://docs.salla.dev/doc-422737?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-swiper              ` | Modern touch slider to display a list of items.                                                                                                  |
| [Tabs](https://docs.salla.dev/doc-422738?nav=01HNFTE06J4QC24T0D5BPRYKMD)                 | `salla-tabs                ` | Makes it possible to have several panes inside a single view.                                                                                    |
| [Tel Input](https://docs.salla.dev/doc-422739?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-tel-input           ` | Shows a field for entering a telephone number, with country key/code prefix.                                                                     |
| [User Menu](https://docs.salla.dev/doc-422740?nav=01HNFTE06J4QC24T0D5BPRYKMD)            | `salla-user-menu           ` | Shows a navigation menu list with links.                                                                                                         |
| [User Profile](https://docs.salla.dev/doc-482367/?nav=01HNFTE06J4QC24T0D5BPRYKMD)        | `salla-userprofile         ` | Displays user profile detailed information.                                                                                                      |
| [User Settings](https://docs.salla.dev/doc-422741?nav=01HNFTE06J4QC24T0D5BPRYKMD)        | `salla-user-settings       ` | Allows the user to manage their account settings.                                                                                                |
| [Verify](https://docs.salla.dev/doc-422742?nav=01HNFTE06J4QC24T0D5BPRYKMD)               | `salla-verify              ` | Shows fields for verifying email/mobile of users by sending OTP verification code.                                                               |

<p align="right">(<a href="#top">back to top</a>)</p>

### Benefits

#### Clean, simple, and standardized.
Developers will follow standards and let users fall in love with the user experience with ready-made components and beautiful (yet changeable) themes. Developers can use a stylistic guideline and functional designs to create huge Themes with UI Component modules.

#### Using Twilight JS SDK

Twilight Web Components are using the [**Twilight JS SDK**](https://salla.stoplight.io/docs/twilight-themes-documentation/3ac843cae76a2-overview), which allows communication between the frontend and backend using specific REST API.

#### Ecosystem

Twilight Web Components are maintained by a full-time core team and a large community of developers and contributors. This is because Twilight helps developers collaborate.

<p align="right">(<a href="#top">back to top</a>)</p>

> #### Things to know:
> It's worth noting that the [Tailwind CSS Framework](https://tailwindcss.com/) is the default foundation for the **Twilight web components**.There is a possibility that future plans may include other CSS frameworks.

## Installation
To use the components, developers need to load a CSS file and some JavaScript. The CSS file includes the fonts and design tokens.

#### Twilight Themes

In case of using the **Twilight web components** inside the Twilight themes, the developer doesn't need to includes the **Twilight web components** in your bundle or inside the html, **Twilight theme engine** will inject the latest version of **Twilight web components** in the page

#### Bundler/ES modules
The developer needs to install both of the [node.js](https://nodejs.org/) and [Tailwind CSS](https://tailwindcss.com/), then installing the Twiligh web components by performing one of the following commands:

```npm title="NPM Installation Command"
npm install @salla.sa/twilight-components --save
```

```yarn title="Yarn Installation Command"
yarn add @salla.sa/twilight-components
```

After that, inside the javascript codebase, developer may do import as follows:

```JS title="Import Command"
import {
  applyPolyfills, 
  defineCustomElements as TwilightWebComponents
} from '@salla.sa/twilight-components/loader';

applyPolyfills().then(() => {
    TwilightWebComponents(window);
});
```

#### HTML/CDN

Another approach for loading the Twilight Web Components isby using the version hosted on the CDN. The components can be loaded via `<script>` tags in the head of the HTML document

```html title="Code Snippet"
<script
  type="module"
  src="https://unpkg.com/@salla.sa/twilight-components@latest/dist/twilight-components/twilight-components.esm.js"
></script>
```
<!-- type: tab-end -->

### JIT Enabled

**Tailwind** added a [just-in-time compiler](https://v2.tailwindcss.com/docs/just-in-time-mode), which generates styles as the developer writes the theme rather than generating everything in advance at initial build time.

Since JIT mode generates your CSS on-demand by scanning your template files, it’s crucial that you configure the `content` option in your `tailwind.config.d.ts` file with all of your template paths, otherwise your CSS will be empty


```js title="tailwind.config.d.ts"
...
  content: [
    // theme views
    "views/**/*.twig",
    // list of classes which required by twilight web components
    "node_modules/@salla.sa/twilight-tailwind-theme/safe-list-css.txt"
  ],
...
```

> Previously, as [mentioned](https://docs.salla.dev/doc-422053/?nav=01HNFTD5Y5ESFQS3P9MJ0721VM) that the file `tailwind.config.d.ts` is already bundled with the **Twilight starter theme** files.

<!-- type: tab-end -->
<p align="right">(<a href="#top">back to top</a>)</p>

## Usage


After installation, Components can be easily added in the basic HTML markup, as shown in the following example:

```html title="Salla Button Configs"
// Salla Button component
<salla-button fill="outline" color="dark">Hello World 👋</salla-button>

// Salla Telephone Input component
<salla-tel-input onclick="telInput.isValid()" country-code="sa"
   country-key="+966" mobile="555555555">

// Salla Product Availability component
<salla-product-availability channels="sms,mobile,email" is-subscribed="false">
</salla-product-availability>
```


## Events

We recommend using DOM events, but we also provide custom events to help with specific event kinds. All custom events are always documented on their own documentation page for each component.

```js title="Modal Event Initialization"
// Save reference to the modal component below
var modal = document.querySelector("salla-modal");

// Listen for open events
modal.addEventListener("modalVisibilityChanged", function (isOpened) {
    console.log("Modal Opened");
});
```

Moreover, developers can detect when a component has been loaded, as Twilight registers its components using the standard Web Components API's CustomElementsRegistry object. This object also provides a `whenDefined` function, which takes a component name and returns a promise. When the component is defined, the promise will be fulfilled:

```js title="Window Custom Element Configs"
window.customElements.whenDefined("salla-button").then(() => {
    console.log("Salla Button is defined!");
});
```

<p align="right">(<a href="#top">back to top</a>)</p>

## Support

The team is always here to help you. Happen to face an issue? Want to report a bug? You can submit one here on Github using the [Issue Tracker](https://github.com/SallaApp/twilight-vscode-extension/issues/new). If you still have any questions, please contact us via the [Telegram Bot](https://t.me/SallaSupportBot) or join in the Global Developer Community on [Telegram](https://t.me/salladev).

<p align="right">(<a href="#top">back to top</a>)</p>

## Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create.
Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request.
You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

<p align="right">(<a href="#top">back to top</a>)</p>

## Credits

- [Salla](https://github.com/sallaApp)
- [All Contributors](../../contributors)

<p align="right">(<a href="#top">back to top</a>)</p>

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

<p align="right">(<a href="#top">back to top</a>)</p>

