themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.77k stars 395 forks source link

Flowbite styles in storybook #1293

Closed getblad closed 3 months ago

getblad commented 3 months ago

I have nx/next application with storybook in shared library. How can I configure flowbite, so that I could see it's styles in my storybook? Right now styles are not applied to the component.

SutuSebastian commented 3 months ago
  1. can u describe the hierarchy of the files and folders?
  2. is the storybook installed in a different package (aka ur repo is monorepo setup)
getblad commented 3 months ago

Nextjs application in ./apps/app_name folder. React shared library in ./libs/library_name folder, in the same folder I Installed storybook, so that I run storybook only for this specific library

SutuSebastian commented 3 months ago

I assume u installed storybook using vite? and that flowbite-react is installed in the ./libs/library_name/package.json.

To solve this issue u need to:

  1. install and setup tailwindcss in ur ./libs/library_name/
  2. create a tailwind.config.js
  3. add flowbite-react to the content depending on where flowbite-react is installed in node_modules, it could be in the same folder with the libs/library_name or at the root level of the monorepo.

at the root:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["../../node_modules/flowbite-react/lib/esm/**/*.js"],
  theme: {
    extend: {},
  },
  plugins: [require("flowbite/plugin")],
};

OR

in current directory:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["node_modules/flowbite-react/lib/esm/**/*.js"],
  theme: {
    extend: {},
  },
  plugins: [require("flowbite/plugin")],
};
  1. create a style.css file and add tailwind:
@tailwind base;
@tailwind components;
@tailwind utilities;
  1. now import the style.css inside .storybook/preview.ts
getblad commented 3 months ago

storybook was installed using nx generate nx/next:storybook-configuration command. I assume that it uses vite as this is .storybook/main.ts

import type { StorybookConfig } from '@storybook/react-vite';

import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { mergeConfig } from 'vite';

const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: ['@storybook/addon-essentials'],
framework: {
name: '@storybook/react-vite',
options: {},
},

viteFinal: async (config) =>
mergeConfig(config, {
plugins: [nxViteTsPaths()],
}),
};

export default config;

I did everything you said, and it still doesnt work properly. styles is not applied to the storybook preview.

SutuSebastian commented 3 months ago

I'll need to have to reproduce ur setup 1:1 locally in order to give more insights

MiroslavPetrik commented 3 months ago

I have one SB + flowbite running here https://github.com/form-atoms/flowbite/tree/main/.storybook You might notice something off

just 2 cents

getblad commented 3 months ago

I reinstalled storybook again using @nx/next generator and repeated your guide @SutuSebastian and everything seems to work now. Thank you everyone!

SutuSebastian commented 3 months ago

Wonderful! 🔥