Coder Social home page Coder Social logo

Tailwind 2.0 about tailwind-rn HOT 11 CLOSED

vadimdemedes avatar vadimdemedes commented on August 27, 2024 4
Tailwind 2.0

from tailwind-rn.

Comments (11)

aswinmohanme avatar aswinmohanme commented on August 27, 2024 27

There is an added support for dark theme, it's a prefix that is generated for every color combination. Would that be supported ?

from tailwind-rn.

vadimdemedes avatar vadimdemedes commented on August 27, 2024 5

Sorry for radio silence everyone. I'm working on a major release now in v4 branch, which is going to support the latest Tailwind 3.x with JIT out of the box.

from tailwind-rn.

johhansantana avatar johhansantana commented on August 27, 2024 2

I am guessing this is because the library would need to somehow identify if the device is in dark mode enabled and/or one has manually opted to show dark mode classes.

In react native I see that you could identify if the user has dark mode enabled with:

import { useColorScheme } from 'react-native';
const isDarkMode = useColorScheme() === 'dark';

So I'm guessing one could do some tricks to workaround this.

from tailwind-rn.

christoph-kluge avatar christoph-kluge commented on August 27, 2024 2

If somebody is interessted. I use this with a custom TailwindProvider and custom useTailwind() hook which checks the current appearance of the device and switches between tailwindLight and tailwindDark.

Disclaimer: I use classnames as a dependency to support additional scenarios. Feel free to remove it.

import React from 'react';
import {useColorScheme} from 'react-native-appearance';
import classnames from "classnames";
import {create} from 'tailwind-rn';
import styles from './../../styles.json';

const tw = create({...styles});

const tailwindLight = (...classNames) => {
  const names = classnames(classNames)
    .split(' ')
    .filter(style => !style.startsWith('dark:'))
    .join(' ');

  return tw.tailwind(names);
}

const tailwindDark = (...classNames) => {
  // take all non-dark styles first
  const classNamesDefault = classnames(classNames)
    .split(' ')
    .filter(style => !style.startsWith('dark:'))
    .join(' ')

  // filter all dark-styles to "append" so they can overwrite the light-styles.
  const classNamesDark = classnames(classNames)
    .split(' ')
    .filter(name => name.startsWith('dark:'))
    .map(name => name.replace('dark:', ''))
    .join(' ');

  return tw.tailwind(classNamesDefault + ' ' + classNamesDark);
}

const TailwindContext = React.createContext({isDark: false, tailwind: () => {}});

export const TailwindProvider = ({children}) => {
  const colorScheme = useColorScheme();
  const [isDark, setIsDark] = React.useState(colorScheme === "dark");
  React.useEffect(() => {
    setIsDark(colorScheme === "dark");
  }, [colorScheme]);

  return <TailwindContext.Provider value={{tailwind: isDark ? tailwindDark : tailwindLight}}>
    {children}
  </TailwindContext.Provider>
};

// Export useTailwind() hook,which will give the correct tailwind function depending on the appearance
export const useTailwind = () => React.useContext(TailwindContext).tailwind;

And finally use it almost the same way as before

const FlatListItem = () => {
  const tailwind = useTailwind();

  return <Text style={tailwind('text-black dark:text-white')}>This is a test</Text>
}

from tailwind-rn.

vadimdemedes avatar vadimdemedes commented on August 27, 2024 1

Hi everyone, Tailwind 3.0 is now supported with a fresh v4.0.0 release of tailwind-rn! There's also support for responsive design, dark mode, custom configuration and more!

from tailwind-rn.

vadimdemedes avatar vadimdemedes commented on August 27, 2024

Thanks! Haven't looked into it yet, but this project should of course support the new 2.0 version.

from tailwind-rn.

Natetronn avatar Natetronn commented on August 27, 2024

Here's the release notes, fwiw:

https://blog.tailwindcss.com/tailwindcss-v2

from tailwind-rn.

JamesGelok avatar JamesGelok commented on August 27, 2024

@vadimdemedes need any help getting this project to support 2.0?

from tailwind-rn.

dillingham avatar dillingham commented on August 27, 2024

@JamesGelok looks like it is since 3.0
https://github.com/vadimdemedes/tailwind-rn/releases/tag/v3.0.0

from tailwind-rn.

johhansantana avatar johhansantana commented on August 27, 2024

@JamesGelok looks like it is since 3.0
https://github.com/vadimdemedes/tailwind-rn/releases/tag/v3.0.0

tried running a dark:bg-black or anything with dark prefix doesnt seem to work

from tailwind-rn.

beeman avatar beeman commented on August 27, 2024

Hi everyone, Tailwind 3.0 is now supported with a fresh v4.0.0 release of tailwind-rn! There's also support for responsive design, dark mode, custom configuration and more!

Thanks for pushing out a new release! Going to play with it this week ❤️

from tailwind-rn.

Related Issues (20)

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.