Skip to content

Commit

Permalink
ci: add storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 31, 2023
1 parent b8b3e3c commit 5132f13
Show file tree
Hide file tree
Showing 10 changed files with 27,546 additions and 12,239 deletions.
13 changes: 8 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"presets": [["@babel/preset-env", {}, "@babel/preset-react"]],
"plugins": [
"presets": [
"@babel/preset-env",
[
"@babel/plugin-transform-react-jsx",
"@babel/preset-typescript",
{
"pragmaFrag": "React.Fragment"
"onlyRemoveTypeImports": true,
"allExtensions": true,
"isTSX": true
}
]
],
["@babel/preset-react", { "runtime": "automatic" }]
]
}
21 changes: 21 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { StorybookConfig } from "@storybook/react-webpack5";
// import '@storybook/addon-console';

const config: StorybookConfig = {
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-essentials",
"@storybook/addon-actions",
"@storybook/addon-links",
"@storybook/addon-interactions",
// "@storybook/addon-actions/register",
],
framework: {
name: "@storybook/react-webpack5",
options: {},
},
docs: {
autodocs: false,
},
};
export default config;
16 changes: 16 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^(w+.)*on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
boolean: /(is|show|loaded)/i,
},
},
},
};

export default preview;
3 changes: 2 additions & 1 deletion lib/ts/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getCurrentNormalisedUrlPath } from "../utils";

import type { PreBuiltRecipes, ReactRouterDomWithCustomHistory } from "./types";

export default class UI {
class UI {
private static reactRouterDom: ReactRouterDomWithCustomHistory;
private static reactRouterDomIsV6?: boolean;

Expand Down Expand Up @@ -104,4 +104,5 @@ const getSuperTokensRoutesForReactRouterDom = UI.getSuperTokensRoutesForReactRou
const canHandleRoute = UI.canHandleRoute;
const getRoutingComponent = UI.getRoutingComponent;

export default UI;
export { getSuperTokensRoutesForReactRouterDom, canHandleRoute, getRoutingComponent };
39,084 changes: 26,858 additions & 12,226 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 27 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"npm": ">=8"
},
"devDependencies": {
"@babel/core": "7.12.1",
"@babel/plugin-transform-react-jsx": "^7.16.0",
"@babel/preset-env": "7.12.1",
"@babel/preset-react": "7.12.1",
"@babel/register": "7.12.1",
"@babel/core": "^7.23.2",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/register": "^7.22.15",
"@percy/cli": "^1.16.0",
"@percy/puppeteer": "^2.0.2",
"@rollup/plugin-commonjs": "^23.0.3",
Expand All @@ -21,6 +21,14 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/pluginutils": "^5.0.2",
"@size-limit/preset-small-lib": "^8.1.0",
"@storybook/addon-essentials": "^7.5.2",
"@storybook/addon-interactions": "^7.5.2",
"@storybook/addon-links": "^7.5.2",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/blocks": "^7.5.2",
"@storybook/react": "^7.5.2",
"@storybook/react-webpack5": "^7.5.2",
"@storybook/testing-library": "^0.2.2",
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand All @@ -38,6 +46,7 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-storybook": "^0.6.15",
"eslint-plugin-supertokens-auth-react": "file:eslint",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.3.1",
Expand Down Expand Up @@ -69,13 +78,16 @@
"rollup-plugin-visualizer": "^5.8.3",
"rollup-pluginutils": "^2.8.2",
"size-limit": "^8.1.0",
"storybook": "^7.5.2",
"ts-jest": "^29.0.3",
"ts-prune": "^0.10.3",
"tslib": "^2.4.0",
"typedoc": "^0.22.5",
"typescript": "4.7.3"
},
"dependencies": {
"@babel/preset-typescript": "^7.23.2",
"@storybook/addon-console": "^2.0.0",
"intl-tel-input": "^17.0.19",
"prop-types": "*",
"react-qr-code": "^2.0.12",
Expand Down Expand Up @@ -115,7 +127,9 @@
"set-up-hooks": "cp hooks/pre-commit.sh .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit",
"build-docs": "rm -rf ./docs && npx typedoc --out ./docs --tsconfig ./lib/tsconfig.json ./lib/ts/index.ts ./lib/ts/**/index.ts ./lib/ts/**/*/index.ts",
"size": "size-limit",
"check-circular-dependencies": "npx madge --circular --extensions js ./lib/build/"
"check-circular-dependencies": "npx madge --circular --extensions js ./lib/build/",
"storybook": "TEST_MODE=testing storybook dev -p 6006",
"build-storybook": "TEST_MODE=testing storybook build"
},
"size-limit": [
{
Expand Down Expand Up @@ -222,5 +236,11 @@
"bugs": {
"url": "https://github.com/supertokens/supertokens-auth-react/issues"
},
"homepage": "https://github.com/supertokens/supertokens-auth-react#readme"
"homepage": "https://github.com/supertokens/supertokens-auth-react#readme",
"eslintConfig": {
"extends": [
"plugin:storybook/recommended",
"plugin:storybook/recommended"
]
}
}
98 changes: 98 additions & 0 deletions stories/factorChooser.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import type { Meta, StoryObj } from "@storybook/react";

import Page from "../lib/ts/recipe/multifactorauth/components/themes/factorChooser";
import React from "react";
import { defaultTranslationsMultiFactorAuth } from "../lib/ts/recipe/multifactorauth/components/themes/translations";
import { WindowHandlerReference } from "supertokens-web-js/utils/windowHandler";
import { TranslationContextProvider } from "../lib/ts/translation/translationContext";
import { ComponentOverrideContext } from "../lib/ts/components/componentOverride/componentOverrideContext";
import { resetAndInitST } from "./utils";
import { SessionContext } from "../lib/ts/recipe/session";
import { otpEmailFactor, otpPhoneFactor } from "../lib/ts/recipe/passwordless/recipe";
import { totpFactor } from "../lib/ts/recipe/totp/recipe";

function noop() {}
WindowHandlerReference.init((oI) => ({ ...oI }));

const factors = [otpEmailFactor, otpPhoneFactor, totpFactor];

const defaultSessionContext = {
loading: false,
doesSessionExist: true,
invalidClaims: [],
accessTokenPayload: {},
userId: "test-user",
};
const meta: Meta<typeof Page> = {
title: "MFA/chooser",
decorators: [
(Story, context) => {
return (
<SessionContext.Provider value={context.loaded.session ?? defaultSessionContext}>
<ComponentOverrideContext.Provider value={{}}>
<TranslationContextProvider
translationControlEventSource={{ on: noop, off: noop }}
defaultLanguage="en"
defaultStore={defaultTranslationsMultiFactorAuth}>
<Story />
</TranslationContextProvider>
</ComponentOverrideContext.Provider>
</SessionContext.Provider>
);
},
],
component: Page,
render: (args) => {
resetAndInitST();
return (
<Page
{...args}
availableFactors={(args.availableFactors as any).map((id) =>
factors.find((factor) => factor.id === id)
)}
/>
);
},
argTypes: {
availableFactors: { control: "check", options: ["otp-email", "otp-phone", "totp"] },
navigateToFactor: { action: "navigateToFactor" },
userContext: {
table: {
disable: true,
},
},
},
args: {
availableFactors: [],
showBackButton: false,
config: {
factorChooserScreen: {
style: "",
},
firstFactors: [],
rootStyle: "",
useShadowDom: false,
},
},
};

export default meta;
type Story = StoryObj<typeof Page>;

export const NoFactors: Story = {
args: {
availableFactors: [],
},
};

export const SingleFactor: Story = {
args: {
availableFactors: ["otp-email"],
},
};

export const MultipleFactors: Story = {
args: {
availableFactors: ["otp-email", "otp-phone", "totp"],
},
};
Loading

0 comments on commit 5132f13

Please sign in to comment.