Giter Club home page Giter Club logo

tailwind's Introduction

@nativescript/tailwind

Warning: โš ๏ธ @nativescript/[email protected] is required for colors to work properly You may see wrong colors on older core versions, because Tailwind CSS v3 uses the RGB/A color notation, which has been implemented for 8.2.0 and prior versions don't support it.

Makes using Tailwind CSS in NativeScript a whole lot easier!

<label
  text="Tailwind CSS is awesome!"
  class="px-2 py-1 text-center text-blue-600 bg-blue-200 rounded-full"
/>

Tailwind CSS is awesome!

Usage

Note: This guide assumes you are using @nativescript/[email protected] as some configuration is done automatically. If you have not upgraded yet, please read the docs below for usage with older @nativescript/webpack versions.

Install @nativescript/tailwind and tailwindcss

npm install --save @nativescript/tailwind tailwindcss

Generate a tailwind.config.js with

npx tailwindcss init

Adjust content, darkMode, corePlugins plus any other settings you need, here are the values we recommend:

// tailwind.config.js
const plugin = require('tailwindcss/plugin');

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './app/**/*.{css,xml,html,vue,svelte,ts,tsx}'
  ],
  // use the .ns-dark class to control dark mode (applied by NativeScript) - since 'media' (default) is not supported.
  darkMode: ['class', '.ns-dark'],
  theme: {
    extend: {},
  },
  plugins: [
    /**
     * A simple inline plugin that adds the ios: and android: variants
     * 
     * Example usage: 
     *
     *   <Label class="android:text-red-500 ios:text-blue-500" />
     *
     */
    plugin(function ({ addVariant }) {
      addVariant('android', '.ns-android &');
      addVariant('ios', '.ns-ios &');
    }),
  ],
  corePlugins: {
    preflight: false // disables browser-specific resets
  }
}

Change your app.css or app.scss to include the tailwind utilities

@tailwind base;
@tailwind components;
@tailwind utilities;

Start using tailwind in your app.

Using a custom PostCSS config

In case you need to customize the postcss configuration, you can create a postcss.config.js (other formats are supported, see https://github.com/webpack-contrib/postcss-loader#config-files) file and add any customizations, for example:

// postcss.config.js

module.exports = {
  plugins: [
    ["tailwindcss", { config: "./tailwind.config.custom.js" }],
    "@nativescript/tailwind",
    "@csstools/postcss-is-pseudo-class"
  ],
};

Note: if you want to apply customizations to tailwindcss or @nativescript/tailwind, you will need to disable autoloading:

ns config set tailwind.autoload false

This is required only if you make changes to either of the 2 plugins - because by default postcss-loader processes the config file first, and then the postcssOptions passed to it. With autoloading enabled, any customizations will be overwritten due to the loading order. Setting tailwind.autoload to false just disables the internal loading of these plugins, and requires you to manually add them to your postcss config in the above order.

Usage with older @nativescript/webpack versions

This usage is considered legacy and will not be supported - however we are documenting it here in case your project is still using older @nativescript/webpack.

See instructions
npm install --save-dev @nativescript/tailwind tailwindcss postcss postcss-loader

Create postcss.config.js with the following:

module.exports = {
  plugins: [
      require('tailwindcss'),
      require('nativescript-tailwind')
  ]
}

Generate a tailwind.config.js with

npx tailwindcss init

Adjust content, darkMode, corePlugins plus any other settings you need, here are the values we recommend:

// tailwind.config.js

module.exports = {
  content: [
    './app/**/*.{css,xml,html,vue,svelte,ts,tsx}'
  ],
  // use .dark to toggle dark mode - since 'media' (default) does not work in NativeScript
  darkMode: 'class',
  theme: {
    extend: {},
  },
  plugins: [],
  corePlugins: {
    preflight: false // disables browser-specific resets
  }
}

Change your app.css or app.scss to include the tailwind utilities

@tailwind base;
@tailwind components;
@tailwind utilities;

Update webpack.config.js to use PostCSS

Find the section of the config that defines the rules/loaders for different file types. To quickly find this block - search for rules: [.

For every css/scss block, append the postcss-loader to the list of loaders, for example:

{
  test: /[\/|\\]app\.css$/,
  use: [
    'nativescript-dev-webpack/style-hot-loader',
    {
      loader: "nativescript-dev-webpack/css2json-loader",
      options: { useForImports: true }
    },
+   'postcss-loader',
  ],
}

Make sure you append postcss-loader to all css/scss rules in the config.

tailwind's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar joshmossas avatar kaanguru avatar lekhmanrus avatar rigor789 avatar sbine avatar vallemar 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tailwind's Issues

support for responsive design?

Hi @rigor789

I wonder if nativescript-tailwind has the same support for responsive design like tailwind?
i.e
<class="justify-start sm:justify-center md:justify-end lg:justify-between xl:justify-around ...">

another question related with the above is how to make the element of the class dynamically.
for example.
I want to change the color dynamically under certain conditions.
from text-red-500 to text-white
what should I do in order to make it work?
Currently a workaround I can think of is to use :color="text_color" instead of using text-red-500 in the class.
Any suggestion?

Regards.

tailwindcss version upgrade

Hi @rigor789 , Any plan to upgrade Tailwindcss and Postcss versions. There is a chance of more supported properties with the latest version of TailwindCSS for example

postcss-nativescript was deprecated

Hello there :)

thanks for this plugin Tailwind !

"postcss-nativescript": "0.0.0",
"postcss": "^8.2.8",

When I try to use the tailwind config with this commande
npx nativescript-tailwind tailwind.config.js

He told me
postcss-nativescript: postcss.plugin was deprecated. for migrate postcss-8

thanks for your help !

oups (I think is that : postcss/postcss#1526)

How to use it?

Hey @rigor789, how must I use this repository? Should I clone it and do npm install or is it a nativescript plugin? How can I use it in combination with vue.js? My favourite setup would be Nativescript + Vue.js + Tailwindcss.

Thanks a lot for all the effort you put into the nativescript vue project!

box-shadow error

when I use the class for example: shadow-xl I get the following error. It seems that a color is passing like unset and it is not accepted

JS: Error: Failed to apply property [box-shadow] with value [0 0 #0000, 0 0 #0000, unset] to StackLayout(5). Error: Invalid color: unset
JS:     at new Color (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\color\color-common.js:33:0)
JS:     at new Color (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\color\index.android.js:2:7)
JS:     at parseCSSShadow (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\styling\css-shadow.js:56:0)
JS:     at valueConverter (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\styling\style-properties.js:1133:29)
JS:     at Style.setCssValue [as css:box-shadow] (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\core\properties\index.js:573:0)
JS:     at CssState.setPropertyValues (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\styling\style-scope.js:537:47)
JS:     at file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\styling\style-scope.js:425:0
JS:     at StackLayout._batchUpdate (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\core\view-base\index.js:286:0)
JS:     at CssState.updateDynamicState (file: app\webpack:\@nativescript\template-blank-vue-ts\node_modules\@nativescript\core\ui\styling\style-scope.js:423:0)

Styles not applied in apk

When I build the apk there are some styles that are lost, an example is this:

Dev mode:
dev

APK mode:
apk

I open this error here and not in NativeScript/tailwind because I think the cause is when you apply a style to a vue component so that it inherits within the component. For example, the following example shows the Steps component that the styles that are applied to the component itself do not seem to be applied

<template>
    <GridLayout rows="*" class="px-3 pt-4">

      <StackLayout height="100%">
        <FlexboxLayout
            class="items-center justify-between p-1">
          <Back horizontalAlignment="left"></Back>
          <FlexboxLayout
              class="bg-secondary rounded-full w-1/2 text-center justify-center items-center box-shadow"
              height="46">
            <Label col="1" text="Reservar Vuelta" class="mx-2 text-xl text-center" verticalAlignment="center"></Label>
            <Label col="2" text=">" class=""></Label>
          </FlexboxLayout>
        </FlexboxLayout>

        <Steps class="w-1/2 mt-8" :steps="3" :current="currentView + 1"></Steps>    <!-- THIS STYLES -->
       </StackLayout>
   </GridLayout>
  </Page>
</template>
// Steps.vue
<template>
  <StackLayout>
    <FlexboxLayout>
      <GridLayout v-for="index in steps"
                  :key="index"
                  height="7"
                  :class="[index <= current ? 'bg-primary' : 'bg-secondary']"
                  class="rounded-full mx-2"></GridLayout>
    </FlexboxLayout>
    <Label class="text-center mt-4 text-secondary" :text="`Step ${current} of ${steps}`"></Label>
  </StackLayout>
</template>

<script setup lang="ts">

const {steps, current} = defineProps({
  steps: Number,
  current: {
    type: Number,
    default: 1
  }
})

</script>

It is also happening to me in this component, the height and width are not applied (this is not tailwind because what I think is something general of the vue components and the styles)

      <Icon @tap="onSettings" verticalAlignment="center" class="mr-2" height="38" widht="38" icon="user-dark"
            :supportDarkMode="false"></Icon>

tailwind.config.js not being used to compile css

Hello

I'm trying to add some custom colors to my tailwind css but when I run npx nativescript-tailwind tailwind.config.js it seems to ignore my config file.

My config file is in the root directory and looks like this...

module.exports = {
  theme: {
    extend: {
      colors: {
        demo: {
          default: '#1ebc3b',
          dark: '#0b601b',
        },
      },
    },
  },
}

Any ideas what I might be doing wrong here?

Thanks

Tailwind only works if "app" folder exists

I looked at this issue but I'm not sure if it's related. I had been trying to integrate Tailwind into my NS 8.6.x project with no luck. I think it's scanning a hard-coded "app" folder for TW CSS class references and only bundling what it finds. Any XML files that exist outside of the "app" folder are not scanned and bundled with the TW CSS. I have two identical projects except the code folder named "app" (working) and "src" (broken). I've also tried naming the folder "app2" and it fails too. You can actually have both folders but only classes found in the "app" folder will be available in the "src" TW references.

WORKING demo using "app" folder

BROKEN demo using "src" folder

If it is hard-coded, at least update the README.md to avoid future issues and headaches. Ideally, it's set to scan all folders for TW references.

BTW, the NS CLI creator puts code into the "src" folder, not the "app" folder which created my problem. E.g. ns create new-project-ts --template @nativescript/template-drawer-navigation-ts.

Unable to apply chain function from: @nativescript/tailwind.

When I compile a project webpack is giving an error from @nativescript/tailwind. Any ideas on what this could be? This project was an upgrade from NS6 to NS8.

> tns build android
Preparing project...
[@nativescript/webpack] Error: 
 Unable to apply chain function from: @nativescript/tailwind.
Error is: TypeError: merge is not a function

Font-Size in app is different from configured `text-base`

Hi @rigor789, and thank you for this incredible plugin. Is it possible to synchronize the app's font size with tailwind.config.js for all elements? Right now when I add the class text-base to a Label, that label gets much bigger.

One solution could be to just add whatever you need to your app.scss:

// app.scss
@layer base {
    Label,Textfield,TextView {
        @apply text-base;
    }
}

Maybe there's a more elegant solution though?

tailwind 8.2 release - question

QUESTIONS ....
I know that there is a plan to include tailwind as part of the 8.2 release. From community video from Nathan.

Is the intent to update theme or this repo for the inclusion?

If we move forward with this repo what would be involved to migrate for 8.2?

Document what can be done and must not be done with tailwind and native

After following up your readme, I installed the plugin without any problem (using step 1 to test).

Then what? Let's try some stuff!

Test color ? Not working. Background color ? Not working.

I finally got something change with border-4 on a button element, proving the library works.

The I saw your default config file: https://github.com/rigor789/nativescript-tailwind/blob/master/tailwind.js

A lot of things are simply deactivated.

Here is a reason? Conflicts with NativeScript? Things to not use because of design?

A bit more documentation about that would be very welcomed. ๐Ÿ‘

background color property is not working on android

Hi @rigor789

Thanks for the great plugin.
It has been must-have part of my development of apps.
I have no problems with it on iOS platform until when I checked it on my Pixel2.
All properties related with bg-xxx-xxx all turned either black or white.
I have followed your instruction in the readme and tried several times but in vain.
Is this a bug?

Screenshot_20200714-101058

how to use @apply directive?

hi, @rigor789

Thanks for this great plugin.
I've tried this plugin in my project, and it seems to work great so far.
To make the layout more concise, I want to put it in the style section like the following. It is said that it is required to add @apply directive in the style section. but unfortunately this doesn't work for nativescript-vue project.
Is there any way to get this problem solved?

<style>
  .btn {
    @apply font-bold py-2 px-4 rounded;
  }
  .btn-blue {
    @apply bg-blue text-white;
  }
  .btn-blue:hover {
    @apply bg-blue-dark;
  }
</style> 

Button text is getting cut off.

Working with Nativescritp Vue
Example:
<Button class="mx-4 text-lg text-green-600 bg-white h-20 rounded-2xl" text="Play"/>
y letter is not fully displayed on screen.
iOS: Screenshot

image

Error: InvalidUnit

hello,
I use "tailwindcss": "^3.1.8" and "@nativescript/tailwind": "^2.0.0",

after angular 14.2.0 upgrade I started having this error below:

ERROR in ./src/app.android.scss Module build failed (from ./node_modules/postcss-loader/dist/cjs.js): Error: InvalidUnit at G:\GitHub\hw\src\app.android.scss:2021:3 at parseSingleAnimationShorthand (G:\GitHub\hw\node_modules\@hookun\parse-animation-shorthand\cjs\parseSingleAnimationShorthand.js:44:23) at Declaration (G:\GitHub\hw\node_modules\@nativescript\tailwind\src\expandAnimations.js:14:24) at LazyResult.visitTick (G:\GitHub\hw\node_modules\postcss\lib\lazy-result.js:502:16) at LazyResult.runAsync (G:\GitHub\hw\node_modules\postcss\lib\lazy-result.js:410:30) at async Object.loader (G:\GitHub\hw\node_modules\postcss-loader\dist\index.js:95:14) @ ./src/main.ts 2:0-28

the app does not run due to the error. The only possible fix that I 'we found is to remove this line from _app-common.scss :

@import '@nativescript/theme/default';

Do you have any other suggestions to fix this? As removing that line mess up my template.

Best Regards,

Tailwind classes are just not working

I tried to create a new NativeScript project with the newest versions exactly like in the documentation and wanted to include tailwind as well. But it's just not working. The css classes are not applied, but I also have no error in the log. It just gets ignored.

Since this is my first try with NativeScript, I have no idea how to debug this situation. Do you have any recommendations for me what I can try?

Thanks in advance!

Tailwind 3 Release

I see that tailwind 3 was released and we upgraded our nx repo with it. Works flawlessly with web, however, because you are depending on version 2 it causes a few issues.

I see that dependabot has a branch, but when I used the branch tag it caused more errors.

https://github.com/NativeScript/tailwind/tree/dependabot/npm_and_yarn/tailwindcss-3.0.22

The actual error I get is from post-css loader Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
But almost certainly positive it's a mismatched object somewhere since Tailwind 3 is different.
TypeError: Cannot read properties of undefined (reading 'config') at getTailwindConfig

dark: not working

Can anyone help me understand this statement in the readme

 // use the .ns-dark class to control dark mode (applied by NativeScript) - since 'media' (default) is not supported.
      darkMode: ['class', '.ns-dark'],

As when i use

bg-teal-500 dark:bg-cyan-700

for example , the styling does not get applied when using dark mode on the phone, only the default bg-teal-500 is ever applied .
I even added it as a plugin in the config

  plugins: [
        plugin(function ({ addVariant }) {
          addVariant('android', '.ns-android &');
          addVariant('ios', '.ns-ios &');
          addVariant('dark','.ns-dark &')
        }),
      ],

still no Joy. What am i doing wrong

Thanks

Custom fonts using Tailwind

I tried to import a local custom font on my nativescript project, but nothing seems to work

Steps to follow :

  • import a custom font in a local folder app/assets/fonts/hello-font.ttf

  • create a fonts.scss file in app/assets/css with :

@font-face
{
    font-family: "hello";
    src: url("app/assets/fonts/hello-font.ttf") format('truetype');
}
  • import file in app/assets/css/app.scss :
@import url('./fonts.scss');

@import '@nativescript/theme/core';
@import '@nativescript/theme/default';

@tailwind base;
@tailwind components;
@tailwind utilities;

.hello
{
    font-family: "hello", 'hello';
}

in Home.vue :

<template>
  <Page actionBarHidden="true" >

    <GridLayout rows="*" columns="*" >

            <Label class="hello" text="Hello World" />

    </GridLayout>

  </Page>
</template>

[ in app.ts ]ย :

import '@/assets/css/app.scss';
import Vue from 'nativescript-vue';
import Template from '@/views/pages/Template.vue';

Vue.config.silent = true;

new Vue( { render: ( h ) => h( 'frame', [ h( Template ) ] ), } ).$start();

Am I missing something ?

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.