Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend ShadCN initialization #13347

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1a5a98c
feat: initialize shadCN setup
TylerAPfledderer Jul 5, 2024
1893c0d
feat: add next-themes for color mode
TylerAPfledderer Jul 5, 2024
f30e52f
refactor(.storybook): update configuration for Tailwind
TylerAPfledderer Jul 5, 2024
d1dde72
feat(global.css): set color tokens
TylerAPfledderer Jul 6, 2024
b051c50
refactor(global.css): complete update of foundation styles
TylerAPfledderer Jul 6, 2024
9f06e0f
refactor: update accordion component
TylerAPfledderer Jul 6, 2024
4a68d63
feat: extend shadcn initialization
TylerAPfledderer Jul 7, 2024
5656859
chore: move tailwind styles to `main.css`
TylerAPfledderer Jul 7, 2024
f527b54
revert(components/ui): remove `eth-` utility prefix
TylerAPfledderer Jul 7, 2024
c3da52f
refactor: create isolated storybook config for tailwind
TylerAPfledderer Jul 7, 2024
d9ec82a
chore(tailwind.config): update content paths
TylerAPfledderer Jul 7, 2024
0245dd1
refactor(tailwind/ui/accordion): apply icon from react-icons
TylerAPfledderer Jul 7, 2024
6f80922
chore(tailwind/ui/stories): remove test story
TylerAPfledderer Jul 7, 2024
e351988
chore(components.json): set `rsc` to false
TylerAPfledderer Jul 7, 2024
7fcb255
chore(tailwind/.storybook): update breakpoint set for viewports
TylerAPfledderer Jul 7, 2024
c8d89cd
chore: bump prettier to v3
TylerAPfledderer Jul 7, 2024
d0e4956
refactor: update next theme provider usage
TylerAPfledderer Jul 7, 2024
d07e666
fix(tailwind/stories): fix type errors for accordion
TylerAPfledderer Jul 7, 2024
c790d14
chore: remove carousel component ui
TylerAPfledderer Jul 7, 2024
e95298b
fix(tailwind/ui): fix accordion collapse animation
TylerAPfledderer Jul 7, 2024
675492d
feat(tailwind/ui): create stack components
TylerAPfledderer Jul 8, 2024
24ca478
Merge branch 'shadcn-initial-setup' into feat/shadcn-extend-initializ…
TylerAPfledderer Jul 8, 2024
a680d58
chore(.prettierignore): remove tailwind config
TylerAPfledderer Jul 8, 2024
7236038
refactor(.storybook): update root conifg decorator
TylerAPfledderer Jul 8, 2024
a066d37
chore: remove generated radix components
TylerAPfledderer Jul 8, 2024
7ee19ac
fix(HubHero): fix RTL position of content container
TylerAPfledderer Jul 8, 2024
94e4d1a
revert: add back radix nav menu package
TylerAPfledderer Jul 8, 2024
91b9185
chore: rename css files
TylerAPfledderer Jul 9, 2024
4fcc57c
chore(global.css): flip pascalCase naming to kebab-case
TylerAPfledderer Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ yarn.lock
package-lock.json
public
build
!tailwind.config.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? (on the other hand, its a .ts, .js)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! Had issues earlier with prettier. This should be removed

7 changes: 5 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}
"trailingComma": "es5",
"plugins": [
"prettier-plugin-tailwindcss"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! very handy

]
}
3 changes: 2 additions & 1 deletion .storybook/ChakraDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useMemo, useState } from "react"
import {
ChakraBaseProvider,
extendBaseTheme,
Expand All @@ -6,7 +7,7 @@ import {
import type { Decorator } from "@storybook/react"

import theme from "../src/@chakra-ui/theme"
import { useEffect, useMemo, useState } from "react"

import i18n from "./i18next"

type DecoratorProps = Parameters<Decorator>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { StorybookConfig } from "@storybook/nextjs"
*/

const config: StorybookConfig = {
stories: ["../src/components/**/*.stories.{ts,tsx}"],
stories: ["../src/components/**/*.stories.tsx"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
Expand Down
4 changes: 2 additions & 2 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Preview } from "@storybook/react"
import isChromatic from "chromatic/isChromatic"
import { MotionGlobalConfig } from "framer-motion"
import type { Preview } from "@storybook/react"

import theme from "../src/@chakra-ui/theme"

import { ChakraDecorator } from "./ChakraDecorator"
import i18n, { baseLocales } from "./i18next"

import "../src/styles/global.css"
import { MotionGlobalConfig } from "framer-motion"

MotionGlobalConfig.skipAnimations = isChromatic()

Expand Down
4 changes: 2 additions & 2 deletions .storybook/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ArgTypes } from "@storybook/react"
import type { ThemingProps } from "@chakra-ui/react"
import type { ArgTypes } from "@storybook/react"

// Type declarations below pulled directly from `@chakra-ui/storybook-addon`
// with some alteration
Expand Down Expand Up @@ -49,7 +49,7 @@ export type ThemingArgTypeKey = "variant" | "size"
* @param componentName component name to create the ArgTypes for
*/
export function getThemingArgTypes<
Theme extends Record<string, any>,
Theme extends Record<string, unknown>,
ComponentName extends KeyOf<Theme["components"]>
>(theme: Theme, componentName: ComponentName) {
const component = theme.components[componentName]
Expand Down
30 changes: 28 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"preversion": "bash ./src/scripts/updatePublishDate.sh",
"crowdin-contributors": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/crowdin/getCrowdinContributors.ts",
"storybook": "storybook dev -p 6006",
"storybook:tw": "storybook dev -p 6007 -c ./tailwind/.storybook",
"build-storybook": "storybook build",
"build-storybook:chromatic": "storybook build --test",
"chromatic": "chromatic --project-token fee8e66c9916",
Expand All @@ -32,7 +33,27 @@
"@docsearch/react": "^3.5.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@hookform/resolvers": "^3.8.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-hover-card": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-navigation-menu": "^1.2.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-radio-group": "^1.2.0",
"@radix-ui/react-scroll-area": "^1.1.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@socialgouv/matomo-next": "^1.8.0",
"chart.js": "^4.4.2",
"chartjs-plugin-datalabels": "^2.2.0",
Expand All @@ -47,6 +68,7 @@
"lodash.merge": "^4.6.2",
"lodash.shuffle": "^4.2.0",
"lodash.union": "^4.6.0",
"lucide-react": "^0.400.0",
"next": "^14.2.3",
"next-i18next": "^14.0.3",
"next-mdx-remote": "^3.0.8",
Expand All @@ -58,6 +80,7 @@
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-emoji-render": "^2.0.1",
"react-hook-form": "^7.52.1",
"react-i18next": "^13.3.1",
"react-icons": "^4.10.1",
"react-lite-youtube-embed": "^2.4.0",
Expand All @@ -75,6 +98,7 @@
"@storybook/addon-essentials": "8.1.10",
"@storybook/addon-interactions": "8.1.10",
"@storybook/addon-links": "8.1.10",
"@storybook/addon-themes": "^8.1.11",
"@storybook/nextjs": "^8.1.10",
"@storybook/react": "8.1.10",
"@storybook/test": "8.1.10",
Expand All @@ -91,7 +115,7 @@
"decompress": "^4.2.1",
"eslint": "^8.45.0",
"eslint-config-next": "^14.2.2",
"eslint-config-prettier": "^9.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-storybook": "0.8.0",
"eslint-plugin-unused-imports": "^3.0.0",
Expand All @@ -103,6 +127,8 @@
"plaiceholder": "^3.0.0",
"polished": "^4.2.2",
"postcss": "^8.4.39",
"prettier": "3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"raw-loader": "^4.0.2",
"storybook": "8.1.10",
"storybook-react-i18next": "3.1.1",
Expand Down
27 changes: 27 additions & 0 deletions src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ThemeProvider as NextThemesProvider } from "next-themes"
import type { ThemeProviderProps } from "next-themes/dist/types"

export const STORAGE_KEY = "theme"

/**
* Primary theming wrapper for use with color mode. Uses the theme provider
* from `next-themes`.
*
* Applied to _app.tsx as the main provider for the project, and supplied as the
* primary decorator to Storybook.
*/
const ThemeProvider = ({ children }: Pick<ThemeProviderProps, "children">) => {
return (
<NextThemesProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both providers in one reusable component helps with the sync with Storybook and prod.

Also note here that I added the style tag in here with the CSS vars for the fonts for the same reason as above. See that TODO comment also

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better 👍🏼

attribute="data-theme"
defaultTheme="system"
enableSystem
disableTransitionOnChange
storageKey={STORAGE_KEY}
>
{children}
</NextThemesProvider>
)
}

export default ThemeProvider
6 changes: 6 additions & 0 deletions src/lib/utils/**/*.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 hmm why this file name/route? don't like it honestly. I think we can make it simpler by just following the conventions we have with the other utils, or am I missing something? are you expecting to add more things in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I frankly don't really understand how defining the alias in components.json is different than defining it in the tsconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not anticipating other utilities to be created, but since the cn() is in it's own file in a utils folder instead of a utils file, I figured that would be the better approach.

I still go back to my initial comment above though 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get the idea of what this files does haha. Can we remove it since it is currently duplicating the cn function?

Not sure if this is adding a benefit or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about confusion with the components.json file? Used for configuration when adding components via the cli

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about confusion with the components.json file? Used for configuration when adding components via the cli

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry. I'm taking about the filename **/*.ts. On the base branch, I've already created a cn.ts file. Was wondering if we could remove one to avoid the duplication.

I frankly don't really understand how defining the alias in components.json is different than defining it in the tsconfig.

Me neither xD

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
14 changes: 4 additions & 10 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect } from "react"
import { appWithTranslation } from "next-i18next"
import { ThemeProvider as NextThemesProvider } from "next-themes"
import { init } from "@socialgouv/matomo-next"

import { AppPropsWithLayout } from "@/lib/types"

import ChakraThemeProvider from "@/components/ChakraThemeProvider"
import NextThemeProvider from '@/components/ThemeProvider'

import "@/styles/global.css"
import "@/styles/main.css"
Expand Down Expand Up @@ -39,23 +39,17 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => {
}
`}
</style>
<NextThemesProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
storageKey={STORAGE_KEY}
>
<NextThemeProvider>
<ChakraThemeProvider>
<RootLayout
contentIsOutdated={!!pageProps.frontmatter?.isOutdated}
contentNotTranslated={pageProps.contentNotTranslated}
lastDeployLocaleTimestamp={pageProps.lastDeployLocaleTimestamp}
>
>
{getLayout(<Component {...pageProps} />)}
</RootLayout>
</ChakraThemeProvider>
</NextThemesProvider>
</NextThemeProvider>
</>
)
}
Expand Down
15 changes: 14 additions & 1 deletion src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F,
U+FE2E-FE2F;
}

/* cyrillic */
@font-face {
font-family: "Inter";
Expand All @@ -19,6 +20,7 @@
src: url(/fonts/inter/cyrillic.woff2) format("woff2");
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* greek-ext */
@font-face {
font-family: "Inter";
Expand All @@ -28,6 +30,7 @@
src: url(/fonts/inter/greek-ext.woff2) format("woff2");
unicode-range: U+1F00-1FFF;
}

/* greek */
@font-face {
font-family: "Inter";
Expand All @@ -38,6 +41,7 @@
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1,
U+03A3-03FF;
}

/* vietnamese */
@font-face {
font-family: "Inter";
Expand All @@ -49,6 +53,7 @@
U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329,
U+1EA0-1EF9, U+20AB;
}

/* latin-ext */
@font-face {
font-family: "Inter";
Expand All @@ -59,6 +64,7 @@
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* latin */
@font-face {
font-family: "Inter";
Expand All @@ -70,6 +76,7 @@
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* cyrillic-ext */
@font-face {
font-family: "Inter";
Expand All @@ -80,6 +87,7 @@
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F,
U+FE2E-FE2F;
}

/* cyrillic */
@font-face {
font-family: "Inter";
Expand All @@ -89,6 +97,7 @@
src: url(/fonts/inter/cyrillic.woff2) format("woff2");
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* greek-ext */
@font-face {
font-family: "Inter";
Expand All @@ -98,6 +107,7 @@
src: url(/fonts/inter/greek-ext.woff2) format("woff2");
unicode-range: U+1F00-1FFF;
}

/* greek */
@font-face {
font-family: "Inter";
Expand All @@ -108,6 +118,7 @@
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1,
U+03A3-03FF;
}

/* vietnamese */
@font-face {
font-family: "Inter";
Expand All @@ -119,6 +130,7 @@
U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329,
U+1EA0-1EF9, U+20AB;
}

/* latin-ext */
@font-face {
font-family: "Inter";
Expand All @@ -129,6 +141,7 @@
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* latin */
@font-face {
font-family: "Inter";
Expand All @@ -139,4 +152,4 @@
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
}
Loading
Loading