Skip to content

Commit

Permalink
chore: move storybooks to package
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas committed Feb 5, 2025
1 parent 5b61c7b commit 5c5e826
Show file tree
Hide file tree
Showing 94 changed files with 185 additions and 219 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN_ELEMENTS_REACT }}
exitOnceUploaded: true
workingDir: packages/elements-react-stories
workingDir: packages/elements-react
storybookBuildDir: storybook-static
onlyChanged: true
externals: packages/elements-react/**
8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const config = tseslint.config([
{
ignores: [
"**/assets/*.js",
"!.storybook",
"**/.storybook/**",
"**/dist/**",
"**/storybook-static/**",
"**/*.config.{js,mjs,cjs,ts}",
Expand Down Expand Up @@ -217,6 +217,12 @@ const config = tseslint.config([
},
},
},
{
files: ["packages/elements-react/stories/**/*.{js,jsx,ts,tsx}"],
rules: {
"@typescript-eslint/no-require-imports": "off",
},
}
])

export default config
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"vite-plugin-dts": "4.1.0",
"vite-plugin-require": "1.2.14",
"vite-plugin-static-copy": "1.0.6",
"vite-plugin-svgr": "4.3.0",
"vite-tsconfig-paths": "5.0.1",
"which-builtin-type": "1.1.4"
},
Expand Down
37 changes: 0 additions & 37 deletions packages/elements-react-stories/.storybook/main.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/elements-react-stories/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/elements-react-stories/project.json

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
35 changes: 0 additions & 35 deletions packages/elements-react-stories/tsconfig.json

This file was deleted.

38 changes: 0 additions & 38 deletions packages/elements-react-stories/tsconfig.storybook.json

This file was deleted.

51 changes: 51 additions & 0 deletions packages/elements-react/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

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

import path from "path"
import { mergeConfig } from "vite"
import vitePluginRequire from "vite-plugin-require"
import svgr from "vite-plugin-svgr"

const config: StorybookConfig = {
stories: ["../**/*.stories.@(ts|tsx)"],
addons: ["@storybook/addon-essentials", "@storybook/addon-interactions"],
framework: {
name: "@storybook/react-vite",
options: {},
},
staticDirs: ["./public"],

viteFinal: (config) => {
console.log(path.resolve(__dirname, "../src"))
return mergeConfig(config, {
plugins: [vitePluginRequire(), svgr({ include: "**/*.svg" })],
build: {
rollupOptions: {
onwarn(warning, warn) {
// Suppress "Module level directives cause errors when bundled" warnings
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return
}
warn(warning)
},
},
},
resolve: {
alias: [
{
find: "$snapshots",
replacement: path.resolve(__dirname, "../.stub-responses"),
},
{
find: "@ory/elements-react",
replacement: path.resolve(__dirname, "../src"),
},
],
},
})
},
}

export default config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import "@ory/elements-react/theme/styles.css"
import type { Decorator, Preview } from "@storybook/react"
import { merge } from "lodash"
import "./global.css"
Expand Down
2 changes: 1 addition & 1 deletion packages/elements-react/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { PropsWithChildren } from "react"
import { OryCardFooter } from "."
import { OryCardFooter } from "./footer"
import { useComponents } from "../../context"
import { OryCardContent } from "./content"
import { OryCardHeader } from "./header"
Expand Down
9 changes: 5 additions & 4 deletions packages/elements-react/src/context/intl-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { PropsWithChildren } from "react"
import { IntlProvider as OriginalIntlProvider } from "react-intl"
import { LocaleMap, locales } from "../locales"
import { OryLocales } from ".."
import { LocaleMap } from "../locales"

// ISO 639-1 language codes
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Expand Down Expand Up @@ -146,7 +147,7 @@ export const LanguageCodes = [
"zu",
] as const

export type Locale = keyof typeof locales
export type Locale = keyof typeof OryLocales

export type IntlContextProps = {
locale: Locale
Expand All @@ -155,9 +156,9 @@ export type IntlContextProps = {

function mergeTranslations(customTranslations: Partial<LocaleMap>) {
return Object.keys(customTranslations).reduce((acc, key) => {
acc[key] = { ...locales[key], ...customTranslations[key] }
acc[key] = { ...OryLocales[key], ...customTranslations[key] }
return acc
}, locales)
}, OryLocales)
}

export const IntlProvider = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/elements-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export type * from "./types"
export * from "./components"
export * from "./context"
export * from "./util"
export { locales as OryLocales } from "./locales"
export { OryLocales } from "./locales"
2 changes: 1 addition & 1 deletion packages/elements-react/src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { default as sv } from "./sv.json"
// A potential workaround is to have some code generation tool, that runs after the message extraction and produces a dts file containing all known keys.
export type LocaleMap = Record<string, Record<string, string>>

export const locales: LocaleMap = {
export const OryLocales: LocaleMap = {
en,
de,
es,
Expand Down
2 changes: 1 addition & 1 deletion packages/elements-react/src/util/ui/__test__/ui.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import allMethodsInitialForm from "../../../../../elements-react-stories/src/elements-react/.stub-responses/login/1fa/all-methods/initial-form.json"
import allMethodsInitialForm from "$stories/.stub-responses/login/1fa/all-methods/initial-form.json"

import { useNodesGroups } from ".."
import { UiNode } from "@ory/client-fetch"
Expand Down
Loading

0 comments on commit 5c5e826

Please sign in to comment.