feature/storybook #2

Merged
behnam merged 7 commits from feature/storybook into develop 2024-11-26 15:42:17 +00:00
8 changed files with 143 additions and 73 deletions
Showing only changes of commit f677d0e797 - Show all commits

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
tailwind.config.ts

View File

@ -15,7 +15,7 @@
"rules": { "rules": {
"react/jsx-props-no-spreading": "off" "react/jsx-props-no-spreading": "off"
} }
}, }
], ],
"settings": { "settings": {
"react": { "react": {
@ -58,6 +58,17 @@
"no-promise-executor-return": "off", "no-promise-executor-return": "off",
"@typescript-eslint/no-shadow": "off", "@typescript-eslint/no-shadow": "off",
"react/require-default-props": "off", "react/require-default-props": "off",
"import/order": [
"error",
{
"pathGroups": [
{
"pattern": "@/**",
"group": "external"
}
]
}
],
"no-shadow": "off", "no-shadow": "off",
"prettier/prettier": [ "prettier/prettier": [
"warn", "warn",

View File

@ -87,6 +87,9 @@ const preview = {
light: { ...themes.normal, appBg: 'red' }, light: { ...themes.normal, appBg: 'red' },
}, },
parameters: { parameters: {
nextjs: {
appDirectory: true,
},
controls: { controls: {
matchers: { matchers: {
color: /(background|color)$/i, color: /(background|color)$/i,

View File

@ -1,7 +1,7 @@
import dashboardAppModule from "@/app/[lang]/dashboard/module/dashboard-app-module";
import CreateRandomInvoiceButtonVM from "@/app/[lang]/dashboard/vm/create-random-invoice-button-vm"; import CreateRandomInvoiceButtonVM from "@/app/[lang]/dashboard/vm/create-random-invoice-button-vm";
import Button from "@/app/components/button/button"; import Button from "@/app/components/button/button";
import { DiContext, useDI } from "@/bootstrap/di/di-context"; import { DiContext, useDI } from "@/bootstrap/di/di-context";
import mockedModuleDi from "@/bootstrap/di/mocked-module-di";
import Story from "@/bootstrap/helpers/view/storybook-base-template-type"; import Story from "@/bootstrap/helpers/view/storybook-base-template-type";
import getArgVM from "@/bootstrap/helpers/view/storybook-with-arg-vm"; import getArgVM from "@/bootstrap/helpers/view/storybook-with-arg-vm";
import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice-usecase"; import createInvoiceUsecase from "@/feature/core/invoice/domain/usecase/create-invoice-usecase";
@ -28,23 +28,38 @@ export const Primary: Story = {
"vm.props.isDisable": false, "vm.props.isDisable": false,
}, },
render: (_props, globalData) => { render: (_props, globalData) => {
const vm = getArgVM(globalData.parsedProps.vm)// You can use parsed props to access your vm properties. const vm = getArgVM(globalData.parsedProps.vm); // You can use parsed props to access your vm properties.
return <Button vm={vm} memoizedByVM={false} /> return <Button vm={vm} memoizedByVM={false} />;
} },
}; };
// export const WithVM: Story = { export const WithVM: Story = {
// decorators: [ decorators: [
// (Story) => { (Story) => {
// return <Story /> const di = mockedModuleDi([
// } {
// ], token: CreateRandomInvoiceButtonVM,
// render: () => { provider: CreateRandomInvoiceButtonVM,
// const Child = () => { },
// const di = useDI(); {
// const vm = useRef(di.resolve(CreateRandomInvoiceButtonVM)); token: createInvoiceUsecase.name,
// return <Button vm={vm.current} memoizedByVM={false} /> // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-console
// } provider: (args: any) => console.log("clicked", args),
// return (<DiContext.Provider value={dashboardAppModule()}> <Child /> </ DiContext.Provider>) },
// } ]);
// } return <Story di={di} />;
},
],
render: (_, globalProps) => {
function Child() {
const di = useDI();
const vm = useRef(di.resolve(CreateRandomInvoiceButtonVM));
return <Button vm={vm.current} memoizedByVM={false} />;
}
return (
<DiContext.Provider value={globalProps.di}>
<Child />
</DiContext.Provider>
);
},
};

View File

@ -0,0 +1,33 @@
import { container, DependencyContainer } from "tsyringe";
import { InjectionToken } from "tsyringe/dist/typings/providers";
import constructor from "tsyringe/dist/typings/types/constructor";
import { isClass } from "../helpers/global-helpers";
/**
* Provides mocked di for test cases and using instead of real di
* @param providers List of providers
* @returns Mocked di with registered providers
*/
const mockedModuleDi = (
providers: {
token: InjectionToken<unknown>;
provider: unknown | constructor<unknown>;
}[],
): DependencyContainer => {
const di = container.createChildContainer();
providers.forEach((provider) => {
if (isClass(provider.provider)) {
di.register(provider.token, provider.provider);
return;
}
di.register(provider.token, {
useValue: provider.provider,
});
});
return di;
};
export default mockedModuleDi;

View File

@ -1 +1,8 @@
import { constructor } from "tsyringe/dist/typings/types";
export const isServer = typeof window === "undefined"; export const isServer = typeof window === "undefined";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isClass(fn: any): fn is constructor<unknown> {
return typeof fn === "function" && /^(class|function [A-Z])/.test(fn);
}

View File

@ -11,11 +11,11 @@ export default function useThrottle<T extends () => unknown>(
callback: T, callback: T,
time: number = 2000, time: number = 2000,
) { ) {
const lastRun = useRef(Date.now()); const lastRun = useRef<number>();
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
return function () { return function () {
if (Date.now() - lastRun.current <= time) return; if (lastRun.current && Date.now() - lastRun.current <= time) return;
lastRun.current = Date.now(); lastRun.current = Date.now();
callback(); callback();
}; };

View File

@ -2,62 +2,62 @@
import type { Config } from "tailwindcss"; import type { Config } from "tailwindcss";
const config: Config = { const config: Config = {
darkMode: ["class"], darkMode: ["class"],
content: [ content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}", "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}", "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}", "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
], ],
theme: { theme: {
extend: { extend: {
colors: { colors: {
background: 'hsl(var(--background))', background: "hsl(var(--background))",
foreground: 'hsl(var(--foreground))', foreground: "hsl(var(--foreground))",
card: { card: {
DEFAULT: 'hsl(var(--card))', DEFAULT: "hsl(var(--card))",
foreground: 'hsl(var(--card-foreground))' foreground: "hsl(var(--card-foreground))",
}, },
popover: { popover: {
DEFAULT: 'hsl(var(--popover))', DEFAULT: "hsl(var(--popover))",
foreground: 'hsl(var(--popover-foreground))' foreground: "hsl(var(--popover-foreground))",
}, },
primary: { primary: {
DEFAULT: 'hsl(var(--primary))', DEFAULT: "hsl(var(--primary))",
foreground: 'hsl(var(--primary-foreground))' foreground: "hsl(var(--primary-foreground))",
}, },
secondary: { secondary: {
DEFAULT: 'hsl(var(--secondary))', DEFAULT: "hsl(var(--secondary))",
foreground: 'hsl(var(--secondary-foreground))' foreground: "hsl(var(--secondary-foreground))",
}, },
muted: { muted: {
DEFAULT: 'hsl(var(--muted))', DEFAULT: "hsl(var(--muted))",
foreground: 'hsl(var(--muted-foreground))' foreground: "hsl(var(--muted-foreground))",
}, },
accent: { accent: {
DEFAULT: 'hsl(var(--accent))', DEFAULT: "hsl(var(--accent))",
foreground: 'hsl(var(--accent-foreground))' foreground: "hsl(var(--accent-foreground))",
}, },
destructive: { destructive: {
DEFAULT: 'hsl(var(--destructive))', DEFAULT: "hsl(var(--destructive))",
foreground: 'hsl(var(--destructive-foreground))' foreground: "hsl(var(--destructive-foreground))",
}, },
border: 'hsl(var(--border))', border: "hsl(var(--border))",
input: 'hsl(var(--input))', input: "hsl(var(--input))",
ring: 'hsl(var(--ring))', ring: "hsl(var(--ring))",
chart: { chart: {
'1': 'hsl(var(--chart-1))', "1": "hsl(var(--chart-1))",
'2': 'hsl(var(--chart-2))', "2": "hsl(var(--chart-2))",
'3': 'hsl(var(--chart-3))', "3": "hsl(var(--chart-3))",
'4': 'hsl(var(--chart-4))', "4": "hsl(var(--chart-4))",
'5': 'hsl(var(--chart-5))' "5": "hsl(var(--chart-5))",
} },
}, },
borderRadius: { borderRadius: {
lg: 'var(--radius)', lg: "var(--radius)",
md: 'calc(var(--radius) - 2px)', md: "calc(var(--radius) - 2px)",
sm: 'calc(var(--radius) - 4px)' sm: "calc(var(--radius) - 4px)",
} },
} },
}, },
plugins: [require("tailwindcss-animate")], plugins: [require("tailwindcss-animate")],
}; };