Giter Site home page Giter Site logo

sass-tailwind-functions's Introduction

Sass Tailwind functions

A Sass plugin that provides the TailwindCSS theme and screen functions to Sass files. Makes using tailwind with Sass a bit easier.

Setup

npm i sass-tailwind-functions

Configuring sass plugins requires using the API directly (sorry no CLI support).

If using Sass directly:

const createFunctions = require('sass-tailwind-functions')

const tailwindFunctions = createFunctions(sass, 'path/to/tailwind.config.js')

const result = sass.renderSync({
  ...,
  functions: {
    ...tailwindFunctions
  }
})

bundlers like webpack, et all also allow passing options to sass, follow specific instuctions for each tool (e.g. sass-loader)

The base export works with both the modern and legacy sass APIs. You can also specify the one you need:

const legacyFunctions = require('sass-tailwind-functions/legacy');
const modernFunctions = require('sass-tailwind-functions/modern');

Usage

If configured correctly both the theme, screen and e functions will be globally available in your sass files.

@media #{screen(md)} {
  .btn {
    width: theme('padding.2');
  }
}

Just like with Tailwind, the theme accepts an optional default value if the key is missing:

.btn {
  width: theme('padding.nope', 3px);
}

Because the functions are Sass plugins, values returned from theme can be used in calculations, or mixed with other sass functions:

$hover-color: adjust-color(theme('colors.blue.400'), $alpha: 0.5);

$height: theme('padding.3') * 2;

Escaping

Since tailwind classes tend to require escaping (e.g. .p-0\.5) it can be a bit of a pain using some of the tailwind keys like the loop above. To make that easier, a e() function is also included (since Sass doesn't have an escape built in).

@each $name, $value in theme('spacing') {
  .square-#{e($name)} {
    width: $value;
    height: $height;
  }
}

sass-tailwind-functions's People

Contributors

dawaltconley avatar jquense avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.