Code Monkey home page Code Monkey logo

tailwind-config-viewer's Introduction

Tailwind Config Viewer

Screenshot of UI

Tailwind Config Viewer is a local UI tool for visualizing your Tailwind CSS configuration file. Keep it open during development to quickly reference custom Tailwind values/classes. Easily navigate between sections of the configuration and copy class names to your clipboard by clicking on them.

Demo using the default Tailwind config

Installation

NPX

Run npx tailwind-config-viewer from within the directory that contains your Tailwind configuration file.

Globally

npm i tailwind-config-viewer -g

Locally

npm i tailwind-config-viewer -D

When installing locally, you can add an entry into the package.json scripts field to run and open the viewer:

"scripts": {
  "tailwind-config-viewer": "tailwind-config-viewer -o"
}

Usage

Run the tailwind-config-viewer command from within the directory that contains your Tailwind configuration file.

Commands

serve (default)

The serve command is the default command. Running tailwind-config-viewer is the same as tailwind-config-viewer serve.

Options

Option Default Description
-p, --port 3000 The port to run the viewer on. If occupied it will use next available port.
-o, --open false Open the viewer in default browser
-c, --config tailwind.config.js Path to your Tailwind config file

export

Exports the viewer to a directory that can be uploaded to a static host. It accepts the output directory path as its sole argument.

tailwind-config-viewer export ./output-dir

If an output directory isn't specificied it will be output to tcv-build.

Options

Option Default Description
-c, --config tailwind.config.js Path to your Tailwind config file

Configuration

You can declare a configViewer property in your Tailwind configuration's theme object in order to customize certain aspects of the config viewer.

module.exports = {
  theme: {
    // ...your Tailwind theme config
    configViewer: {
      // ... configViewer Options
    }
  }
}

themeReplacements

In some instances you may want to replace values used in your Tailwind config when it is displayed in the config viewer. One scenario where this is necessary is when you are using CSS variables for your theme values:

module.exports = {
  theme: {
    colors: {
      black: 'var(--color-black)'
    }
  }
}

In order for the config viewer to properly display this color, you need to provide a replacement for it:

module.exports = {
  theme: {
    colors: {
      black: 'var(--color-black)'
    },
    configViewer: {
      themeReplacements: {
        'var(--color-black)': '#000000'
      }
    }
  }
}

You can replace any value in your theme for display in the config viewer by setting the corresponding valueToFind: valueToReplace in the themeReplacements object.

baseFontSize

The config viewer displays the pixel equivalent of any rem values. By default baseFontSize is set to 16 to mirror the default root element font size in most browsers. If you plan on using a different root font size in your project, you should set the value of baseFontSize to match.

module.exports = {
  theme: {
    // ...your Tailwind theme config
    configViewer: {
      baseFontSize: 20 // default is 16
    }
  }
}

typographyExample

You can change the default sentence used in the typography sections (Font Size, Letter Spacing etc.) by setting the typographyExample option:

module.exports = {
  theme: {
    // ...your Tailwind theme config
    configViewer: {
      typographyExample: 'The quick brown fox jumps over the lazy dog.'
    }
  }
}

fonts

You can add custom fonts to the config viewer that are used in your Tailwind config by passing in a font url as a string, or an array of font urls.

Notes

  • If multiple font weights are provided in a single url (see example) only the last weight will be used.
  • If fonts are in your Tailwind theme config but urls are not provided they will not display correctly (currently with no warning).
  • Fonts can only be provided via urls not local files. If this something you need, please open a ticket or a pull request.
module.exports = {
  theme: {
    // ...your Tailwind theme config
    configViewer: {
      // single font
      fonts: "https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"
      // or multiple fonts
      fonts: [
        "https://fonts.googleapis.com/css2?family=Open+Sans&display=swap",
        "https://fonts.googleapis.com/css2?family=Roboto:wght@100;500&display=swap" // <- only 500 will be used
      ]
        }
      ]
    }
  }
}

Usage Tips

  • Shift+Click on the Tailwind class names to copy multiple to your clipboard at once

Roadmap

  • Add static export
  • Add Transition section
  • Dark Mode toggle
  • Add support for loading custom fonts / font family section

tailwind-config-viewer's People

Contributors

hacknug avatar ineshbose avatar jalemy avatar olets avatar pi0 avatar rogden avatar simon-tma avatar sjoertjuh 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tailwind-config-viewer's Issues

Error: Cannot find module '../lib/tailwindConfigUtils'

I found a regression (cli works on version 1.0.0).

tailwind-config-viewer: v1.1.0
os: windows 10

$ npx tailwind-config-viewer
internal/modules/cjs/loader.js:783
    throw err;
    ^

Error: Cannot find module '../lib/tailwindConfigUtils'
Require stack:
- <redacted>\my-project\node_modules\tailwind-config-viewer\server\index.js
- <redacted>\my-project\node_modules\tailwind-config-viewer\cli\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
    at Function.Module._load (internal/modules/cjs/loader.js:685:27)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (<redacted>\my-project\node_modules\tailwind-config-viewer\server\index.js:6:46)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '<redacted>\\my-project\\node_modules\\tailwind-config-viewer\\server\\index.js',
    '<redacted>\\my-project\\node_modules\\tailwind-config-viewer\\cli\\index.js'
  ]
}

Font sizes in weird order

You'd expect font sizes to be ordered by size (either ascending or descending); but they appear unordered. Still trying to figure out why, maybe the default ones appear before custom ones?

Better display for screens

Shortcomings

The information shown by the screens module is not very helpful because:

  • it shows screens as widths so the only way to visualise all of them is if you have a display that's bigger than the biggest
  • the width is restricted by the horizontal viewport so on a smaller window, they all look alike (picture attached)
    Screenshot 2021-12-01 at 12 11 10 PM

Suggestions

I believe the module can be improved by the following changes:

  • making the screens break out of the viewport and scroll (not ideal)
  • hiding the sidebar and making the component full-width; inside
    • hiding screen sizes that are outside the viewport range (helpful to see the current breakpoint of the window)
  • showing the current screen width and breakpoint name

Add ability to inject custom CSS

themeReplacements are a good start for being able to set CSS variable values, but what if the variables have different values in dark/light theme?

:root {
  --color: #fff;
}

:root.dark {
  --color: #000;
}

Thus it would be nice if we could inject custom CSS, even if it has to be CSS-in-JS provided as a string.

Feature request: moving custom colors and styles ahead of Tailwind's built-in stuff, or giving them their own links in the sidebar

Hello,

This is super helpful, I appreciate you taking the time to build it. I found my way here via Craft Link List.

May I recommend an enhancement: either placing custom colors and styles ahead of Tailwind's built-in stuff, or creating links in the sidebar that jump right to one's customizations. It's the custom stuff that can be harder to remember than the built-in stuff.

Theme Replacement support for Custom Properties + color opacity utilities

To get custom colors that are declared with CSS variables working, there is a need to add some configuration.

It's possible to get it working, but I needed to create a new config file especially for the config viewer, and point toward it while running.

My suggestion is to support this out of the box.

I've made a gist with what I did to get it working in a project.

Happy to try and submit a PR if you can point me in the right direction and some sort of contribution reference.

Otherwise, just wanted to say that this is a really helpful project and is awesome!
Thanks for making this @expandtheroom.

nav scrollbar cramps main panel

Super minor and subjective. I'm using tailwind-config-viewer on a screen that is shorter than the nav, so I get a scrollbar. The main content is right up against the scrollbar

without scrollbar with scrollbar
image image

Is it possible to show DaisyUI setup?

Hey Ryan,

Thanks for the really cool plugin! I would like to ask, is it possible to show DaisyUI colors in the list? For example, I chose the default theme on DaisyUI, but the viewer has no change. DaisyUI is one of the popular Tailwind UI Components, so maybe there is a possibility?

Thanks!

cli export should recursively create the the directory

When specifying the export parameter that includes multiple directories the directories should be created recusively

npx tailwind-config-viewer -c ./libs/tailwind-config/src/lib/tailwind.config.js export ./dist/libs/tailwind-config

Current Behavior

Error: ENOENT: no such file or directory, mkdir '/<absolutePathToRepoRedacted>/dist/libs/tailwind-config'

Should create the directory structure specified as the export arg

[Feature Request] Multilingual support or config of example sentences

Thank you for great tool.

By the way, I have a question.
Do you have any plans to support multiple languages or read example sentences from the settings?

I'm software engineer in japan.
Japanese designer I work with told me that would like to check with japanese example sentences.

I'm sorry for my poor English, but I would appreciate if if you could comment.
I would like to cooperate by issuing a Pull Request if possible.

Storybook export?

First of all. Fantastic tool!!

I have the usecase that we do all UX documentation in storybook. Is there any way to link the tool directly to storybook as well?

CLI does not support TypeScript

$ npx tailwind-config-viewer export public
node:internal/modules/cjs/loader:959
  throw err;
  ^
Error: Cannot find module '/tailwind.config.js'
npx tailwind-config-viewer export -c tailwind.config.ts
/Users/Bobik/Sites/vitae-frontend/tailwind.config.ts:1
import { Config } from 'tailwindcss'
^^^^^^

SyntaxError: Cannot use import statement outside a module

When using Taiwind Nuxt module which has viewer embeded TS config works with dev server.

Add support for css custom properties (variables)

if I use these settings in the tailwind configuration:

primary: {
    DEFAULT: 'var(--primary)',
    light: 'var(--primary-light)',
},

they are not displayed on the viewer page. I see only white square

About themeReplacements

Hello, Thanks for your awesome works!

I know you have themeReplacements to replace the postcss variable. I didn't check how do you handle this. But can't you use something like this instead? It will be a bit less configuration even if it's not too much.

getComputedStyle(document.documentElement)
    .getPropertyValue('--my-variable-name'); // #999999

Thank you again!

Support for variables from: root

I noticed that now there is a problem if variables were declared, for example, in ':root'. Is there any solution for this problem now?

Снимок экрана 2020-08-28 в 00 31 06

Tailwind version

It could be useful to display version of tailwind in the viewer...

themeReplacements options not working correctly

see: #17

The current implementation of the themeReplacements option doesn't work unless you specify the expanded key/value pair. For instance:

module.exports = {
  theme: {
    colors: {
      black: 'var(--color-black)'
    },
    configViewer: {
      themeReplacements: {
        colors: {
          black: '#000000'
        }
      }
    }
  }
}

won't result in the black color having the value of #000000 in the config viewer since we are displaying backgroundColor, textColor and borderColor and the replacement happens after the config is resolved.

In order for this to work correctly you would need to specify the following:

module.exports = {
  theme: {
    colors: {
      black: 'var(--color-black)'
    },
    configViewer: {
      themeReplacements: {
        backgroundColor: {
          black: '#000000'
        },
        borderColor: {
          black: '#000000'
        },
        textColor: {
          black: '#000000'
        }
      }
    }
  }
}

Given that the most common scenario for themeReplacements is to replace css variables that are used for values in your tailwind.config file, the following would be a better implementation:

module.exports = {
  theme: {
    colors: {
      black: 'var(--color-black)'
    },
    configViewer: {
      themeReplacements: {
        'var(--color-black)': '#000000'
      }
    }
  }
}

Then a simple find/replace on the resolved config JSON string will handle the replacements.

Unfortunately this will be a small breaking change.

[Feature Request] Add px equivalent to all rem values

Congratulations for the great tool!
Infact I started building the exact same tool some time ago but couldn't find the time to finish it so I will share some of my ideas to you and maybe you can incorporate them here.

The main motivations for me for this tool are two:

  • preview your config with most generated classes as often the config changes quite drastically compared to the default due to design requirements
  • be able to export the changed config and send it to designers for further design work so they know what we already have and not change it when they can reuse existing elements (or send the default config to designers for their reference while creating the design)

What I see here missing from my vision (ofcourse you can disagree) is to display all values which are in rem with pixes too. For example p-4 is 1rem. It will be really good to add 16px next to the rem value so when you are working on a design frontend you can see quite fast the class you need. Obviously you memorise the common classes/sizes but sometimes the larger ones are hard to memorise as you don't use them often.

Adding this to the tool will require a way to change the base font size for the rem->px calculation as it can be replaced in the frontend so adding an option such as --base-font-size=16 will be required.

Export command expects './dist' folder

Thanks for this work, it's a really cool idea 👍

When exporting the viewer to a static site, using tailwind-config-viewer export CLI, it expects your build directory to be ./dist, see

fs.copySync('./dist', outputDir)

If you have any other build dir, say ./public, you get this:

internal/fs/utils.js:269
    throw err;
    ^

Error: ENOENT: no such file or directory, stat './dist'
    at Object.statSync (fs.js:1016:3)
    at Object.statSync (/home/agustin/development/personal-site/node_modules/graceful-fs/polyfills.js:307:34)
    at statSync (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/fs-extra/lib/util/stat.js:10:52)
    at getStatsSync (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/fs-extra/lib/util/stat.js:24:19)
    at Object.checkPathsSync (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/fs-extra/lib/util/stat.js:49:33)
    at Object.copySync (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/fs-extra/lib/copy-sync/copy-sync.js:24:38)
    at module.exports (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/cli/export.js:18:6)
    at Command.<anonymous> (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/cli/index.js:24:24)
    at Command.listener [as _actionHandler] (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/commander/index.js:422:31)
    at Command._parseCommand (/home/agustin/development/personal-site/node_modules/tailwind-config-viewer/node_modules/commander/index.js:975:14) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: './dist'
}

Outdated koa router

warning @nuxtjs/tailwindcss > tailwind-config-viewer > @koa/[email protected]: IMPORTANT 10x+ PERFORMANCE UPGRADE: Please upgrade to v12.0.1+ as we have fixed an issue with debuglog causing 10x slower router benchmark performance, see koajs/router#173

Bump core-js to v3

"core-js": "^2.6.5",

Could you bump core-js to version 3? It's better and version 2 already throws warnings when still being installed:

warning tailwind-config-viewer > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

Section highlight

It would be nice to get a section highlight on the menu to know where one is in the page!

ES Module support

Can you add support for ES Modules? I am using Vite and it is not loading due to require(). Thanks

What about z-index?

I think it would be great if the configuration for z-index could also displayed.

It seems that the tailwind-config-viewer does not support these values right now? I could not find any other issue which is related to z-index.

Thanks in advance.
Btw great project!

eslint warning in stickyEvents

prepublishOnly has this warning:

 warning  in ./src/lib/stickyEvents.js

Module Warning (from ./node_modules/thread-loader/dist/cjs.js):

/Users/home/Sites/olets/tailwind-config-viewer/src/lib/stickyEvents.js
  69:7  error  Unexpected console statement  no-console

The full eslint context is

Module Warning (from ./node_modules/eslint-loader/index.js):
error: Unexpected console statement (no-console) at src/lib/stickyEvents.js:69:7:
  67 |   enableEvents () {
  68 |     if (window.self !== window.top) {
> 69 |       console.warn('StickyEvents: There are issues with using IntersectionObservers in an iframe, canceling initialization. Please see https://github.com/w3c/IntersectionObserver/issues/183')
     |       ^
  70 |
  71 |       return
  72 |     }

The Background Image config isn't shown

This utility is included in Tailwind, but it's not showing.

I've tried adding my own custom config, like this:

module.exports = {
  theme: {
    extend: {
      backgroundImage: () => ({
        "dark-waves": "url('...')",
      }),
    },
  },
};

And this isn't showing either, but it does show in the app I'm building. I've tried changing the config to an object instead of a function, too, but this didn't work.

Support Tailwind CSS 3

Tailwind CSS 3 was officially released yesterday but I couldn't install it on Nuxt because of below:

"peerDependencies": {
  "tailwindcss": "1 || 2 || 2.0.1-compat"
},

When should we expect an update for TCV to support version 3 of Tailwind?

Container queries

Can you add @container queries to the tool similar to what's displayed in the readme here.
It's basically a duplication of max-width since the container uses the same steps but it will be visually better to have it as a separate section.

Possible Bug in Font Sizes

Hi there, I'm currently running

 "tailwind-config-viewer": "^1.5.1",
 "tailwindcss": "^2.1.2",

Things look fine except in the Font Sizes section, where most of the font sizes are not being rendered:

Screen Shot 2021-05-28 at 7 46 20 AM

Looking at the console I'm seeing an error that is firing 15 times - the same number of font sizes that aren't being shown:

Screen Shot 2021-05-28 at 7 45 17 AM

And here is the snippet of fontSize in my tailwind.config.js

module.exports = {
  theme: {
    extend: {
      fontSize: {
        'xxs': ['0.625rem', '1.125rem'],
        'xxs-1': ['0.6875rem', '0.8125rem'],
        'xs-1': '0.8125rem',
        'sm-1': '0.9375rem',
        '1xl': '1.375rem',
        '2xl-1': '1.625rem'
      }
    }
}

===
Update: I thought It may have something to do with how I was specifying the lineHeight values. Looked back at Tailwinds default config file and updated them to match, but it didn't fix the config viewer errors.

module.exports = {
  theme: {
    extend: {
      fontSize: {
        xxs: ['0.625rem', { lineHeight: '1.125rem' }],
        'xxs-1': ['0.6875rem', { lineHeight: '0.8125rem' }],
        'xs-1': '0.8125rem',
        'sm-1': '0.9375rem',
        '1xl': '1.375rem',
        '2xl-1': '1.625rem'
      }
    }
}

===

Thanks, really dig the config viewer.

Suggestion: Edit and export TW config

Firstly, thanks so much for making this tool. it's brilliant.

I was showing this off at work and we all had the collective thought of wouldn't it be great if we could tweak these values in the UI, then re-export the TW config out.

Have you ever considered adding this functionality?

Font size using wrong value

Seems like it used the line height to set the font size value. Possibly related to #45

"tailwind-config-viewer": "^1.6.1"
"tailwindcss": "^2.1.2",

Screen Shot 2021-06-02 at 3 33 05 PM

module.exports = {
    purge: ['src/**/*'],
    important: '.sdk',
    darkMode: false,
    theme: {
        screens: {
            xxs: '280px',
            xs: '480px',
            sm: '600px',
            md: '782px',
            md2: '960px', // admin sidebar auto folds
            lg: '1080px', // adminbar goes big
            xl: '1280px',
            '2xl': '1440px',
            '3xl': '1600px',
        },
        // Extend will add on to TW config, where the above will override and replace
        extend: {
            fontSize: {
                '3xl': ['2rem', '2.5rem'],
            },
            colors: {
                'wp-theme': {
                    500: 'var(--wp-admin-theme-color)',
                    600: 'var(--wp-admin-theme-color-darker-10)',
                    700: 'var(--wp-admin-theme-color-darker-20)',
                },
                wp: {
                    alert: {
                        yellow: '#f0b849',
                        red:    '#cc1818',
                        green:  '#4ab866',
                    },
                },
                gray: {
                    100: '#f0f0f0',
                    150: '#eaeaea', // This wasn't a variable but I saw it on buttons
                    200: '#e0e0e0', // Used sparingly for light borders.
                    300: '#dddddd', // Used for most borders.
                    400: '#cccccc',
                    500: '#cccccc', // WP didn't have a 500 value for some reason so I just copied the 400
                    600: '#949494', // Meets 3:1 UI or large text contrast against white.
                    700: '#757575', // Meets 4.6:1 text contrast against white.
                    900: '#1e1e1e',
                },
            },
            zIndex: {
                high: '1000000',
                max: '2147483647', // Highest the browser allows - don't block WP re-auth modal though
            },
        },
    },
    variants: {
        extend: {},
    },
    plugins: [],
    corePlugins: {
        preflight: false,
        container: false,
    },
}

Wrong css and js paths when viewer is used as sub directory

I want to use tailwind config viewer on a stage environment by using the export functionality. The problem I'm facing is that I want to use tailwind config viewer in a sub directory of my /dist folder. In my dist there is the .html file and also /css and /js directories for my project. When opening the tailwind config index.html which is located in /dist/tailwind-config-viewer it tries to access the .css and .js files from /dist/css and /dist/js becaufe of the relative paths.

It would be good to have a way to tell the config viewer to look in another directory for that.

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.