Skip to content

Commit 7afe3b3

Browse files
committed
refactor: upgrade Storybook to its v8
This commit introduces the breaking changes from the Storybook tool which defines the alterations to the MDX files. Reference: https://storybook.js.org/docs/migration-guide
1 parent 268d7be commit 7afe3b3

File tree

66 files changed

+746
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+746
-325
lines changed

apps/storybook/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
storybook.log*

apps/storybook/.storybook/main.ts

+45-31
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
import * as path from 'node:path'
22

3-
import type { StorybookConfig } from '@storybook/nextjs'
4-
5-
/**
6-
* The `getAbsolutePath()` function is used to resolve the absolute path of a
7-
* given package name. It points to the `package.json` file of the package.
8-
*
9-
* This function is particularly useful when we're running the Storybook in
10-
* monorepo mode, and we want to resolve the absolute path of a package while
11-
* starting up the Storybook with [Yarn](https://yarnpkg.com/).
12-
*
13-
* As we're using Bun Workspaces and it is still in the experimental phase, we
14-
* need to resolve the absolute path of the package to make sure that the
15-
* Storybook can find the package and its `package.json` file. Let's avoid some
16-
* headaches for now.
17-
*/
18-
function getAbsolutePath(value: string) {
19-
return path.dirname(require.resolve(path.join(value, 'package.json')))
20-
}
3+
import remarkGfm from 'remark-gfm'
214

225
/**
236
* The constant `WORKSPACE_ROOT` is used to define the root of the workspace
@@ -29,26 +12,37 @@ const WORKSPACE_ROOT = '../../..' as const
2912
* The constant `STORYBOOK_FILENAME_ANNOTATION` is used to define the annotation
3013
* for the storybook files. It uses the glob pattern to find the files.
3114
*/
32-
const STORYBOOK_FILENAME_ANNOTATION = '@(stories|docs)' as const
15+
const STORYBOOK_FILENAME_ANNOTATION = 'stories' as const
3316

3417
/**
3518
* The constant `STORYBOOK_FILE_EXTENSIONS` is used to define the file
3619
* extensions for the storybook files. It uses the glob pattern to find the
3720
* files.
3821
*/
39-
const STORYBOOK_FILE_EXTENSIONS = '@(ts|tsx|mdx)' as const
22+
const STORYBOOK_FILE_EXTENSIONS = '@(ts|tsx)' as const
4023

4124
/**
4225
* The `getStoriesGlob()` function is used to define the location of the stories
43-
* and documentation files. It uses the glob pattern to find the files.
26+
* files. It uses the glob pattern to find the files.
4427
*
4528
* It uses the given `pathname` parameter from the `WORKSPACE_ROOT` to find the
46-
* stories and documentation files.
29+
* stories files.
4730
*/
48-
function getStoriesGlob(pathname: string) {
31+
function getStoriesGlob(pathname) {
4932
return `${WORKSPACE_ROOT}/${pathname}/*.${STORYBOOK_FILENAME_ANNOTATION}.${STORYBOOK_FILE_EXTENSIONS}`
5033
}
5134

35+
/**
36+
* The `getDocumentationGlob()` function is used to define the location of the
37+
* documentation files. It uses the glob pattern to find the files.
38+
*
39+
* It uses the given `pathname` parameter from the `WORKSPACE_ROOT` to find the
40+
* documentation files.
41+
*/
42+
function getDocumentationGlob(pathname: string) {
43+
return `${WORKSPACE_ROOT}/${pathname}/*.docs.mdx`
44+
}
45+
5246
/**
5347
* The constant `stories` is used to define the location of the stories and
5448
* documentation files. It uses the glob pattern to find the files.
@@ -58,25 +52,43 @@ const stories = [
5852
getStoriesGlob('apps/storybook/stories'),
5953
getStoriesGlob('apps/www/src/components'),
6054
getStoriesGlob('apps/www/src/domains/**'),
55+
getDocumentationGlob('packages/**/**'),
56+
getDocumentationGlob('apps/storybook/stories'),
57+
getDocumentationGlob('apps/www/src/components'),
58+
getDocumentationGlob('apps/www/src/domains/**'),
6159
]
6260

63-
const config: StorybookConfig = {
61+
/**
62+
* @type {require('@storybook/nextjs').StorybookConfig}
63+
*/
64+
const config = {
6465
stories,
6566
addons: [
66-
getAbsolutePath('@storybook/addon-links'),
67-
getAbsolutePath('@storybook/addon-essentials'),
68-
getAbsolutePath('@storybook/addon-interactions'),
67+
'@storybook/addon-links',
68+
'@storybook/addon-essentials',
69+
'@storybook/addon-interactions',
6970
{
70-
name: getAbsolutePath('@storybook/addon-postcss'),
71+
name: '@storybook/addon-postcss',
7172
options: {
7273
postcssLoaderOptions: {
7374
implementation: require('postcss'),
7475
},
7576
},
7677
},
78+
{
79+
name: '@storybook/addon-docs',
80+
options: {
81+
mdxPluginOptions: {
82+
mdxCompileOptions: {
83+
remarkPlugins: [remarkGfm],
84+
},
85+
},
86+
},
87+
},
88+
'@storybook/addon-mdx-gfm',
7789
],
7890
framework: {
79-
name: getAbsolutePath('@storybook/nextjs') as '@storybook/nextjs',
91+
name: '@storybook/nextjs',
8092
options: {
8193
// builder: {
8294
// fsCache: true,
@@ -138,7 +150,9 @@ const config: StorybookConfig = {
138150
},
139151

140152
docs: {
141-
autodocs: false,
153+
autodocs: 'tag',
154+
defaultName: 'Documentation',
142155
},
143156
}
144-
export default config
157+
158+
module.exports = config

apps/storybook/.storybook/preview.tsx

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,18 @@ window.getEmbedNamespace = () => {
2121
return namespace
2222
}
2323

24+
/**
25+
* The `preview` object is used to define the parameters for the storybook
26+
* preview.
27+
*/
2428
const preview: Preview = {
2529
parameters: {
2630
actions: {
2731
argTypesRegex: '^on[A-Z].*',
2832
},
2933
layout: 'centered',
30-
previewTabs: {
31-
previewTabs: {
32-
'storybook/docs/panel': {
33-
index: -1,
34-
},
35-
},
36-
},
3734
docs: {
3835
container: DocsContainer,
39-
disabled: true,
4036

4137
// 👇 NOTE: Enable the Table of Contents. See further detail on the
4238
// Storybook documentation at:
@@ -52,7 +48,6 @@ const preview: Preview = {
5248
},
5349
},
5450
},
55-
5651
controls: {
5752
expanded: true,
5853
matchers: {
@@ -61,15 +56,14 @@ const preview: Preview = {
6156
},
6257
exclude: ['style'],
6358
},
64-
6559
nextjs: {
6660
appDirectory: true,
6761
},
6862
},
6963
decorators: [
7064
(Story) => (
7165
<ThemeProvider>
72-
<div className="max-w-[min(480px,_100vw)] mx-auto mt-[12vh] pb-[20vh]">{Story()}</div>
66+
<div className="mx-[6vw] mt-[12vh] pb-[20vh]">{Story()}</div>
7367
</ThemeProvider>
7468
),
7569
],

apps/storybook/_/styles/prismjs.css

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pre.prismjs {
1212
pre.prismjs,
1313
code.prismjs,
1414
div[class*="language-"] .token,
15+
div[class*="language-"] > *,
1516
.docblock-source {
1617
font-family: "Menlo", "SF Mono", "JetBrains Mono", "Menlo", "Monaco", "Consolas", "Courier New", monospace !important;
1718
font-size: 1.125rem;

apps/storybook/local-addons/github-repo-path-link.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { type JSX } from 'react'
1+
import type { JSX } from 'react'
22

33
import Link from 'next/link'
44

55
import getGitHubRepositoryPath from '@louffee/lib/get-github-repository-path'
6-
import Icon from '@louffee/ui/icon'
76

87
interface GitHubRepoPathLinkProps {
98
/**
@@ -13,17 +12,16 @@ interface GitHubRepoPathLinkProps {
1312
}
1413

1514
function GitHubRepoPathLink({ path }: GitHubRepoPathLinkProps): JSX.Element {
15+
const href = getGitHubRepositoryPath(path)
16+
1617
return (
1718
<div
1819
style={{
19-
position: 'absolute',
20-
top: '6vh',
21-
right: '30vw',
2220
cursor: 'pointer',
2321
zIndex: 1,
2422
}}>
25-
<Link href={getGitHubRepositoryPath(path)} target="_blank" title="See it on GitHub">
26-
<Icon name="GitHubLogo" className="text-black" height={24} width={24} aria-hidden="true" />
23+
<Link href={href} target="_blank" title="See it on GitHub">
24+
Source code
2725
</Link>
2826
</div>
2927
)

apps/storybook/package.json

+23-21
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,41 @@
77
"homepage": "https://github.com/louffee/louffee.co/tree/main/apps/storybook",
88
"scripts": {
99
"storybook": "storybook dev -p 6006 --ci",
10+
"storybook:debug": "storybook dev -p 6006 --ci --debug-webpack",
1011
"build-storybook:docs": "storybook build --docs",
1112
"build-storybook": "storybook build",
12-
"test": "test-storybook"
13+
"test": "test-storybook",
14+
"doctor": "storybook doctor"
1315
},
1416
"dependencies": {
15-
"@louffee/ui": "*",
16-
"@louffee/lib": "*",
17-
"@radix-ui/react-slot": "^1",
17+
"@louffee/lib": "workspace:*",
18+
"@louffee/ui": "workspace:*",
1819
"@radix-ui/react-icons": "^1",
19-
"clsx": "^2.1.0",
20+
"@radix-ui/react-slot": "^1",
21+
"@storybook/test": "^8",
2022
"class-variance-authority": "^0.7.0",
21-
"tailwind-merge": "^2.2.1",
23+
"clsx": "^2.1.0",
2224
"next": "^14",
2325
"react": "^18",
2426
"react-dom": "^18",
25-
"sonner": "^1.4.2"
27+
"sonner": "^1.4.2",
28+
"tailwind-merge": "^2.2.1"
2629
},
2730
"devDependencies": {
2831
"@babel/core": "^7",
29-
"@storybook/addon-actions": "^7",
30-
"@storybook/addon-designs": "^7",
31-
"@storybook/addon-docs": "^7",
32-
"@storybook/addon-essentials": "^7",
33-
"@storybook/addon-interactions": "^7",
34-
"@storybook/addon-links": "^7",
32+
"@storybook/addon-actions": "^8",
33+
"@storybook/addon-designs": "^8",
34+
"@storybook/addon-docs": "^8",
35+
"@storybook/addon-essentials": "^8",
36+
"@storybook/addon-interactions": "^8",
37+
"@storybook/addon-links": "^8",
38+
"@storybook/addon-mdx-gfm": "^8",
3539
"@storybook/addon-styling": "^1",
36-
"@storybook/blocks": "^7",
37-
"@storybook/nextjs": "^7",
38-
"@storybook/preview-api": "^7",
39-
"@storybook/react": "^7",
40-
"@storybook/test-runner": "^0.16.0",
41-
"@storybook/testing-library": "^0.2.2",
42-
"@storybook/jest": "^0.2.3",
40+
"@storybook/blocks": "^8",
41+
"@storybook/nextjs": "^8",
42+
"@storybook/preview-api": "^8",
43+
"@storybook/react": "^8",
44+
"@storybook/test-runner": "^0",
4345
"@types/react": "^18",
4446
"@types/react-dom": "^18",
4547
"@vitejs/plugin-react": "^2.2.0",
@@ -50,7 +52,7 @@
5052
"postcss-pseudo-companion-classes": "^0.1.1",
5153
"remark-gfm": "^4.0.0",
5254
"rollup-plugin-polyfill-node": "^0.10.2",
53-
"storybook": "^7",
55+
"storybook": "^8",
5456
"tailwindcss": "^3.4.1",
5557
"tailwindcss-animate": "^1.0.7",
5658
"tailwindcss-radix": "^2.8.0",

apps/www/next.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const defaultConfiguration = require('@louffee/next-config/next.config')
55
*/
66
const configuration = {
77
...defaultConfiguration,
8+
async redirects() {
9+
return [
10+
{
11+
source: '/:lang/terms',
12+
destination: '/:lang/terms-and-conditions',
13+
permanent: true,
14+
},
15+
]
16+
},
817
}
918

1019
module.exports = configuration

bun.lockb

-2.14 KB
Binary file not shown.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
"format": "bun x @biomejs/biome format ./{packages,apps}/* --write",
2828
"clean:node_modules": "rm -rf ./node_modules bun.lockb",
2929
"storybook": "( cd apps/storybook && bun run storybook )",
30+
"storybook:debug": "( cd apps/storybook && bun run storybook:debug )",
3031
"sb": "( cd apps/storybook && bun run storybook )",
32+
"sb:debug": "( cd apps/storybook && bun run storybook:debug )",
3133
"test": "vitest --config vitest.config.ts",
3234
"docker:up": "docker compose -f .docker/docker-compose.yaml up -d",
3335
"docker:down": "docker compose -f ./.docker/docker-compose.yaml down",
3436
"db:studio": "( cd packages/drizzle && bun run db:studio )",
3537
"db:generate": "( cd packages/drizzle && bun run db:generate )",
3638
"db:migration": "( cd packages/drizzle && bun run db:migration )",
3739
"db:seed": "( cd packages/drizzle && bun run db:seed )",
38-
"build": "turbo run build"
40+
"build": "turbo run build",
41+
"mdx:issue-checker": "npx @hipster/mdx2-issue-checker"
3942
},
4043
"peerDependencies": {
4144
"typescript": "^5"

packages/ui/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"./danger-icon": "./src/danger-icon/danger-icon.tsx",
1010
"./merge": "./src/engine/merge.ts",
1111
"./styled": "./src/engine/styled.ts",
12+
"./focus-grid": "./src/focus-grid/focus-grid.tsx",
1213
"./footer": "./src/footer/footer.tsx",
1314
"./footer-link": "./src/footer-link/footer-link.tsx",
1415
"./footer-navigation": "./src/footer-navigation/footer-navigation.tsx",
@@ -18,6 +19,7 @@
1819
"./info-icon": "./src/info-icon/info-icon.tsx",
1920
"./image": "./src/image/image.tsx",
2021
"./input": "./src/input/input.tsx",
22+
"./label": "./src/label/label.tsx",
2123
"./logo": "./src/logo/logo.tsx",
2224
"./semantic-icon": "./src/semantic-icon/semantic-icon.tsx",
2325
"./spinner": "./src/spinner/spinner.tsx",

0 commit comments

Comments
 (0)