GithubHelp home page GithubHelp logo

jrowlingson / stencil-tailwind Goto Github PK

View Code? Open in Web Editor NEW
41.0 3.0 10.0 372 KB

TailwindCSS plugin for Stencil

Home Page: https://www.npmjs.com/package/stencil-tailwind

License: MIT License

JavaScript 4.29% CSS 0.49% TypeScript 95.22%
tailwindcss stenciljs stencil tailwind plugin

stencil-tailwind's Introduction

stencil-tailwind

!!! ⚠️ DEPRECATED ⚠️ !!! See https://www.npmjs.com/package/stencil-tailwind-plugin

This package is used in order to integrate with tailwindcss. It provides simple functionality for supporting a utility-first workflow within the Shadow DOM.

Note, this plugin specificially adds support for inline utilities (idiomatic Tailwind). If you find that this is not a requirement for your project you can opt to include Tailwind via @stencil/postcss. This will allow you to use the @apply directive and theme() function within your component's stylesheet. You can get started with the following configuration:

import { Config } from '@stencil/core'
import postcss from '@stencil/postcss'
import tailwind from 'tailwindcss'

export const config: Config = {
  plugins: [
    postcss({
      plugins: [ tailwind() ]
    })
  ]
}

Installation

First, npm install within the project:

npm install stencil-tailwind --save-dev

Next, within the project's stencil.config.js file, import the plugin and add it to the config's plugins config:

stencil.config.ts

import { Config } from '@stencil/core'
import tailwind from 'stencil-tailwind'

export const config: Config = {
  plugins: [
    tailwind()
  ]
}

Note, hot module reloading (hmr) is not yet supported. For local development, you'll need to update reloadStratgy to use the pageReload option:

export const config: Config = {
  devServer: {
    reloadStrategy: 'pageReload'
  }
}

Create your Tailwind config file (optional)

While Tailwind provides a sensible default configuration, it is often desirable to further customize your theme. This default configuration can be used as a starting point for such customizations. To customize your Tailwind installation, you will first need to generate a config file for your project using the included Tailwind CLI utility when you install the stencil-tailwind npm package.

npx tailwindcss init

This will generate a tailwind.config.js file at the root of your project.

Usage

Inline utilities

Utility classes can be used directly within JSX; they will be included in the component's shadow tree.

class MyComponent {
  render() {
    return (
      <div class="p-4 bg-red">
        <p class="text-sm text-white">This is JSX!</p>
      </div>
    );
  }
}

@Styles

Utilities can be conditionally applied using the Styles decorator. This decorator provides a simple wrapper for the classnames npm package.

class MyComponent {
  render() {
    return (
      <button class={this.classNames()}>
        Hello World
      </button>
    );
  }

  @Styles()
  private classNames = () => ({
    'p-4': true,
    'shadow hover:shadow-md': this.floating,
    'rounded-full': this.round
  })
}

Directives

Use the @apply directive to inline any existing utility classes into your external component stylesheet files. This is useful when you want to apply utilities to the shadow host.

:host {
  @apply font-bold py-2 px-4 rounded;
}

DSL (advanced)

A simple, declarative, runtime DSL can be used to provide sugar for conditionally applied utilties based on a Prop value. All classes will be included in the shadow tree at build time.

class MyComponent {

  /** specify the size of the button, defaults to m */
  @Prop({ reflect: true }) size: "s" | "m" | "l" = "m";

  render() {
    return (
      <button class="<px-4 py-3 text-sm> l<px-6 py-4 text-lg> s<px-3 py-2 text-xs>">
        Hello World
      </button>
    );
  }

}

The DSL is described by the following grammer:

class-containerprefix < class-list >

class-listclass-list class

class-listclass

classstring

prefixstring | ''

Options

The following plugin options may be configured:

stencil.config.ts

import tailwindcss from 'tailwindcss'

export const config: Config = {
  plugins: [
    tailwind({
      tailwind: tailwindcss('tailwind.config.js'),
      inputFile: './src/styles/app.css',
      includeTailwindCss: false
    })
  ]
}
  • tailwind: (optional) your own configuration file and version of TailwindCSS to be used.
  • inputFile: (optional) a stylesheet filepath to be used in place of the default.
  • includeTailwindCss: (optional) include global tailwind.css in the bundle (default: true)

stencil-tailwind's People

Contributors

dependabot[bot] avatar dohxis avatar joewoodhouse avatar jrowlingson avatar kstinson14 avatar robbiethewagner avatar ssfinney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stencil-tailwind's Issues

Console warning about `from` option

The following warning appears during dev:

Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.

image

Tailwind 2.0 support

Hi,

Would it be possible for you to update the library to use the latest version of Tailwind? Currently it uses Tailwind 1.2 which is fairly old and doesn't contain many utilities classes found in Tailwind 2.0.

Responsive prefixes not working

Hi!

The package is great, but I noticed a problem with it:
Responsive prefixes are not working.
For example if I am using this:
<div class="w-full sm:w-full md:w-1/3 lg:w-1/4 xl:w-1/6 m-4 text-white">Test</div>
the responsiveness is not working. In my other project (Vue js) it's working nicely.

Can you please make a fix for this?

Thank you!

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.