From e6185eed50cd10f8f2bf7955739e59822eca902f Mon Sep 17 00:00:00 2001 From: Jin Lee <86632227+jinlee93@users.noreply.github.com> Date: Fri, 22 Oct 2021 11:44:39 -0700 Subject: [PATCH] Enable Tailwind utility and component classes (#675) * feat(tailwind): enable utility classes and add tw- prefix * feat(tailwind): introduces script to add tw- prefix in css files * feat(tailwind): process components css to add tw- prefixes * revert prefixing script and prefixes * revert tw- prefix for tailwind utility classes * feat(tailwind): enable tailwind component classes * docs(tailwind): describe tailwind class usage * docs(tailwind): revise tailwind utility class usage * feat(tailwind): enable tailwind purge * feat(tailwind): enable tailwind jit mode * feat(tailwind): broaden TW purge scope to incl js jsx ts * feat(tailwind): move import tailwind utilities for storybook only * chore(tailwind): move properties to top f tailwind config object * docs(tailwind): update tw custom class with example * docs(tailwind): update tw conflict description Co-authored-by: Annie Hu * docs(tailwind): udpate tw example * fix(tailwind): specify tailwind purge and add related doc Co-authored-by: Annie Hu --- packages/components/.storybook/preview.tsx | 1 + packages/components/README.md | 43 +++++++++++++++++++ packages/components/src/styles/global.css | 4 ++ .../src/styles/tailwindUtilities.css | 11 +++++ packages/components/tailwind.config.js | 5 +++ 5 files changed, 64 insertions(+) create mode 100644 packages/components/src/styles/tailwindUtilities.css diff --git a/packages/components/.storybook/preview.tsx b/packages/components/.storybook/preview.tsx index 011501bb91..2dee9558c4 100644 --- a/packages/components/.storybook/preview.tsx +++ b/packages/components/.storybook/preview.tsx @@ -1,6 +1,7 @@ import "@chanzuckerberg/eds-tokens/lib/css/variables.css"; import "../src/styles/fonts.css"; import "../src/styles/global.css"; +import "../src/styles/tailwindUtilities.css"; import React from "react"; diff --git a/packages/components/README.md b/packages/components/README.md index 2caeef104b..2bf922f195 100644 --- a/packages/components/README.md +++ b/packages/components/README.md @@ -99,3 +99,46 @@ declare var x: AbstractComponent; ``` - Preserve exact-typed objects when possible. If you must make them inexact, add an explicit `...` at the end of the object. + +## Tailwind Utility Classes +EDS Components is configured for TW utility class use in Storybook only. Please configure downstream Tailwind config purge to include app files if necessary. + +Tailwind utility classes can be used with either `@apply` in CSS files such as +```css +div { + @apply rounded border-2; + /* border-radius: 0.25 rem; + border-width: 2px; */ +} +``` +or used directly as class names such as +```jsx +
+``` +Use the [docs](https://tailwindcss.com/docs) to search for appropriate classes. + +### Potential conflicts with other styling libraries (e.g. Bootstrap) + +If you're also using styles from a separate library, conflicts may arise rarely between utility class names. Here are some conflicts we're aware of for **Bootstrap** specifically: + - Most annoying, `.hidden` + - Both Tailwind and Bootstrap have the same styling for `.hidden` but Bootstrap applies the `!important ` property, which can be annoying when trying to utilize Tailwind breakpoints, e.g.: + ```html +