Giter Site home page Giter Site logo

conan1150 / owl-javascript-tailwind-project-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coding-dodo/owl-javascript-tailwind-project-starter

0.0 0.0 0.0 454 KB

OWL JavaScript Project Starter with Tailwind and postcss

Home Page: https://owl-tailwind-starter.netlify.app

License: MIT License

JavaScript 97.24% HTML 2.12% CSS 0.64%

owl-javascript-tailwind-project-starter's Introduction

OWL Javascript Project Starter

This repo is an example on how to start a JavaScript project with the Odoo OWL framework.

Thanks to @SimonGenin for it's original Starter Project for OWL

Deploy on Netlify

Features

  • OWL v1.4.5
  • Javascript
  • Livereload
  • Rollup.js v2.57.0
  • Tailwind v2.2.15 and PostCSS
  • Tests with Jest v27.2.1

Demo

owl-tailwind-starter.netlify.app

Installation

This repo is a "template repository". It means you can quickly create repositories based on this one, without it being a fork.

Otherwise, you may clone it:

git clone https://github.com/Coding-Dodo/OWL-JavaScript-Tailwind-Project-Starter.git

Install dependencies:

npm install

Dev with livereload:

npm run dev

Production build

npm run build

Run tests

npm run test

Components

It is expected to create components in one file, this is an example DropDown Component present in this repository:

import { Component, useState, tags, hooks } from "@odoo/owl";
const { useExternalListener } = hooks;

const DROPDOWN_TEMPLATE = tags.xml/*xml*/ `
<div class="relative inline-block text-left">
  <div>
    <button type="button" class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500" id="menu-button" aria-expanded="true" aria-haspopup="true" t-on-click.prevent="toggleDropDown">
      <t t-esc="props.buttonText"/>
      <svg class="-mr-1 ml-2 h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
        <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
      </svg>
    </button>
  </div>

  <div t-attf-class="{{state.open ? 'opacity-100' : 'opacity-0'}} transition-opacity {{ props.dropdownLeft ? 'origin-top-left left-0' : 'origin-top-right right-0' }} absolute mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
    <div class="py-1" role="none">
      <t t-foreach="props.menuItems" t-as="menuItem" t-key="menuItem.id">
        <t t-slot="menu-item">
          <a 
            t-on-click.prevent="menuItem.callBack(menuItem)" 
            t-attf-href="{{menuItem.target ? menuItem.target : '#'}}" 
            t-attf-class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm {{ props.selectedMenu and props.selectedMenu.id == menuItem.id ? 'bg-gray-100 text-gray-900': ''}}" 
            role="menuitem" 
            tabindex="-1" 
            t-att-id="menuItem.id"
          >
            <t t-esc="menuItem.name"/>
          </a>
        </t>
      </t>
    </div>
  </div>
</div>

`;

export class DropDown extends Component {
  static template = DROPDOWN_TEMPLATE;
  static props = {
    buttonText: { type: String },
    menuItems: {
      type: Array,
      element: {
        type: Object,
        id: String,
        target: { type: String, optional: true },
        name: String,
        callBack: { type: Function, optional: true },
      },
    },
    selectedMenu: {
      type: Object,
      optional: true,
    },
    dropdownLeft: { type: Boolean, optional: true },
  };
  state = useState({ open: false });

  constructor(...args) {
    super(...args);
    useExternalListener(window, "click", this.closeDropDown);
  }

  closeDropDown(event) {
    if (!this.el.contains(event.target)) {
      Object.assign(this.state, { open: false });
    }
  }

  toggleDropDown() {
    Object.assign(this.state, { open: !this.state.open });
  }
}

See also

If your are searching for the a project starter without Tailwind:

https://github.com/Coding-Dodo/OWL-JavaScript-Project-Starter

owl-javascript-tailwind-project-starter's People

Contributors

phildl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.