From de33d38e1bb1927ababbc90bd542ebf47fa5b0fb Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Mon, 3 Oct 2022 20:33:35 +0800 Subject: [PATCH] ui: share tailwind config across packages --- apps/portal/package.json | 6 +- apps/portal/postcss.config.cjs | 9 +- apps/portal/src/pages/_app.tsx | 1 + apps/portal/src/pages/index.tsx | 10 +- apps/storybook/.gitignore | 1 + apps/storybook/.storybook/preview.js | 1 + apps/storybook/package.json | 1 + apps/storybook/postcss.config.js | 13 ++ apps/storybook/stories/button.stories.tsx | 33 ++++ ....stories.mdx => counterbutton.stories.mdx} | 0 package.json | 4 +- packages/tailwind-config/package.json | 13 ++ .../tailwind-config/tailwind.config.js | 0 packages/ui/package.json | 14 +- packages/ui/src/Button/Button.tsx | 155 ++++++++++++++++++ packages/ui/src/Button/index.ts | 4 + packages/ui/src/CounterButton.tsx | 2 +- packages/ui/src/Spinner/Spinner.tsx | 52 ++++++ packages/ui/src/Spinner/index.ts | 4 + packages/ui/src/index.tsx | 2 + packages/ui/src/styles.css | 3 + packages/ui/tailwind.config.js | 3 + yarn.lock | 58 ++++++- 23 files changed, 374 insertions(+), 15 deletions(-) create mode 100644 apps/storybook/.gitignore create mode 100644 apps/storybook/.storybook/preview.js create mode 100644 apps/storybook/postcss.config.js create mode 100644 apps/storybook/stories/button.stories.tsx rename apps/storybook/stories/{button.stories.mdx => counterbutton.stories.mdx} (100%) create mode 100644 packages/tailwind-config/package.json rename apps/portal/tailwind.config.cjs => packages/tailwind-config/tailwind.config.js (100%) create mode 100644 packages/ui/src/Button/Button.tsx create mode 100644 packages/ui/src/Button/index.ts create mode 100644 packages/ui/src/Spinner/Spinner.tsx create mode 100644 packages/ui/src/Spinner/index.ts create mode 100644 packages/ui/src/styles.css create mode 100644 packages/ui/tailwind.config.js diff --git a/apps/portal/package.json b/apps/portal/package.json index ef80dd06..db44a820 100644 --- a/apps/portal/package.json +++ b/apps/portal/package.json @@ -30,10 +30,7 @@ "zod": "^3.18.0" }, "devDependencies": { - "@tailwindcss/aspect-ratio": "^0.4.2", - "@tailwindcss/forms": "^0.5.3", - "@tailwindcss/line-clamp": "^0.4.2", - "@tailwindcss/typography": "^0.5.7", + "@tih/tailwind-config": "*", "@tih/tsconfig": "*", "@types/node": "^18.0.0", "@types/react": "^18.0.21", @@ -42,7 +39,6 @@ "postcss": "^8.4.16", "prettier-plugin-tailwindcss": "^0.1.13", "prisma": "^4.4.0", - "tailwindcss": "^3.1.8", "typescript": "4.8.3" }, "ct3aMetadata": { diff --git a/apps/portal/postcss.config.cjs b/apps/portal/postcss.config.cjs index 12a703d9..c099299a 100644 --- a/apps/portal/postcss.config.cjs +++ b/apps/portal/postcss.config.cjs @@ -1,6 +1,13 @@ +// If you want to use other PostCSS plugins, see the following: +// https://tailwindcss.com/docs/using-with-preprocessors + +const config = require('@tih/tailwind-config/tailwind.config.js'); + module.exports = { plugins: { - tailwindcss: {}, + // Specifying the config is not necessary in most cases, but it is included + // here to share the same config across the entire monorepo + tailwindcss: { config }, autoprefixer: {}, }, }; diff --git a/apps/portal/src/pages/_app.tsx b/apps/portal/src/pages/_app.tsx index 5de4ac99..e3b9a8ba 100644 --- a/apps/portal/src/pages/_app.tsx +++ b/apps/portal/src/pages/_app.tsx @@ -12,6 +12,7 @@ import AppShell from '~/components/global/AppShell'; import type { AppRouter } from '~/server/router'; import '~/styles/globals.css'; +import '@tih/ui/styles.css'; const MyApp: AppType<{ session: Session | null }> = ({ Component, diff --git a/apps/portal/src/pages/index.tsx b/apps/portal/src/pages/index.tsx index 22a31105..2aa0a8aa 100644 --- a/apps/portal/src/pages/index.tsx +++ b/apps/portal/src/pages/index.tsx @@ -1,8 +1,16 @@ +import { Button, CounterButton } from '@tih/ui'; + export default function HomePage() { return (
-

Homepage

+
+

+ Homepage +

+ +
); diff --git a/apps/storybook/.gitignore b/apps/storybook/.gitignore new file mode 100644 index 00000000..0640db61 --- /dev/null +++ b/apps/storybook/.gitignore @@ -0,0 +1 @@ +storybook-static \ No newline at end of file diff --git a/apps/storybook/.storybook/preview.js b/apps/storybook/.storybook/preview.js new file mode 100644 index 00000000..7f6cf20d --- /dev/null +++ b/apps/storybook/.storybook/preview.js @@ -0,0 +1 @@ +import '@tih/ui/dist/styles.css'; diff --git a/apps/storybook/package.json b/apps/storybook/package.json index d6de10d2..1822c4b2 100644 --- a/apps/storybook/package.json +++ b/apps/storybook/package.json @@ -20,6 +20,7 @@ "@storybook/addon-links": "^6.4.18", "@storybook/builder-vite": "^0.1.33", "@storybook/react": "^6.4.18", + "@tih/tailwind-config": "*", "@tih/tsconfig": "*", "@vitejs/plugin-react": "^1.3.2", "eslint-config-tih": "*", diff --git a/apps/storybook/postcss.config.js b/apps/storybook/postcss.config.js new file mode 100644 index 00000000..c099299a --- /dev/null +++ b/apps/storybook/postcss.config.js @@ -0,0 +1,13 @@ +// If you want to use other PostCSS plugins, see the following: +// https://tailwindcss.com/docs/using-with-preprocessors + +const config = require('@tih/tailwind-config/tailwind.config.js'); + +module.exports = { + plugins: { + // Specifying the config is not necessary in most cases, but it is included + // here to share the same config across the entire monorepo + tailwindcss: { config }, + autoprefixer: {}, + }, +}; diff --git a/apps/storybook/stories/button.stories.tsx b/apps/storybook/stories/button.stories.tsx new file mode 100644 index 00000000..06d89fd3 --- /dev/null +++ b/apps/storybook/stories/button.stories.tsx @@ -0,0 +1,33 @@ +import { ComponentStory, ComponentMeta } from '@storybook/react'; + +import { Button } from '@tih/ui'; +import React from 'react'; + +//๐Ÿ‘‡ This default export determines where your story goes in the story list +export default { + /* ๐Ÿ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/react/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +} as ComponentMeta; + +//๐Ÿ‘‡ We create a โ€œtemplateโ€ of how args map to rendering +const Template: ComponentStory = (args) =>