techsbcn-storybook 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,140 +1,140 @@
1
- # techsbcn-storybook
2
-
3
- A React component library built by [TechsBCN](https://techsbcn.com) on top of Material UI. It provides a set of ready-to-use components — form fields, tables, layouts, navigation, modals and wrappers — designed to be consumed across internal projects with a consistent look and feel.
4
-
5
- Components are developed and documented in [Storybook](https://storybook.js.org/) and shipped as an npm package.
6
-
7
- ## Requirements
8
-
9
- - **Node.js** `>= 18`
10
- - **React** `>= 18` (declared as a peer dependency)
11
- - **Yarn** (the repository is pinned to Yarn 4 via `packageManager`)
12
-
13
- ## Installation
14
-
15
- ```bash
16
- yarn add techsbcn-storybook
17
- ```
18
-
19
- or
20
-
21
- ```bash
22
- npm install techsbcn-storybook
23
- ```
24
-
25
- Because MUI, Emotion, React Hook Form, Yup, i18next, dayjs and Font Awesome are runtime dependencies of this library, they are installed automatically.
26
-
27
- ## Usage
28
-
29
- Import components directly from the package root:
30
-
31
- ```tsx
32
- import { TextFieldComponent, ButtonComponent, TableComponent } from 'techsbcn-storybook';
33
-
34
- export const Example = () => (
35
- <>
36
- <TextFieldComponent name="email" label="Email" />
37
- <ButtonComponent onClick={() => console.log('clicked')}>Send</ButtonComponent>
38
- </>
39
- );
40
- ```
41
-
42
- ### Available component groups
43
-
44
- | Group | Components |
45
- | --- | --- |
46
- | **Fields** | `ButtonComponent`, `TextFieldComponent`, `TextSimpleComponent`, `SelectField`, `SelectAsyncField`, `DatePickerComponent` |
47
- | **Forms** | `LoginForm`, `ChangePasswordForm`, `ResetPasswordForm` |
48
- | **Tables** | `TableComponent`, `SimpleTableComponent`, `SearchComponent` |
49
- | **Layouts** | `MainLayoutSimple`, `AppHeader`, `AppSidebar`, `DrawerSidebar` |
50
- | **Navigation** | `VerticalNav`, `UserInfo` |
51
- | **Modals** | `ModalComponent` |
52
- | **Wrappers** | `MainWrapperComponent`, `PublicFormWrapper`, `TabsComponent`, `LinearProgressComponent`, `CardComponent` |
53
-
54
- See the Storybook documentation for the full API of each component.
55
-
56
- ## Development
57
-
58
- ### Getting started
59
-
60
- ```bash
61
- yarn install
62
- yarn storybook
63
- ```
64
-
65
- Storybook runs on [http://localhost:6006](http://localhost:6006) and hot-reloads on changes inside `src/`.
66
-
67
- ### Project structure
68
-
69
- ```txt
70
- src/
71
- components/ # Library source — grouped by category
72
- fields/
73
- forms/
74
- layouts/
75
- modals/
76
- navigation/
77
- tables/
78
- wrappers/
79
- content/ # Static assets (images, icons) used by stories
80
- data/ # Mock data and enums used only by stories
81
- helpers/ # Shared utilities and hooks
82
- interfaces/ # Shared TypeScript interfaces
83
- stories/ # Storybook stories
84
- i18n.tsx # Storybook-only i18n bootstrap
85
- index.tsx # Public entry point (barrel of every exported component)
86
- .storybook/ # Storybook configuration
87
- tsup.config.ts # Build configuration (JS bundles)
88
- tsconfig.build.json # Build configuration (type declarations)
89
- ```
90
-
91
- Only files under `src/components/` are shipped in the published package. Stories, mock data and the Storybook i18n bootstrap are excluded from the build.
92
-
93
- ### Scripts
94
-
95
- | Script | Description |
96
- | --- | --- |
97
- | `yarn start` | Runs `tsup` in watch mode (rebuilds `dist/` on every change) |
98
- | `yarn build` | Produces the distributable output in `dist/`: CJS + ESM bundles, sourcemaps and type declarations |
99
- | `yarn storybook` | Starts Storybook in development mode |
100
- | `yarn build-storybook` | Builds the static Storybook site |
101
- | `yarn lint` | Runs ESLint with autofix over the codebase |
102
- | `yarn test` | Runs the Jest test suite |
103
- | `yarn size` | Reports the bundle size using [size-limit](https://github.com/ai/size-limit) |
104
- | `yarn analyze` | Opens the size-limit visual report |
105
-
106
- ## Build pipeline
107
-
108
- The library is built in three steps, wired together in the `build` script:
109
-
110
- 1. **`tsup`** bundles `src/index.tsx` into CommonJS (`dist/index.js`) and ES Modules (`dist/index.mjs`) using esbuild, with SCSS compiled through `esbuild-sass-plugin` and static assets (SVG/PNG) emitted as separate files.
111
- 2. **`tsc -p tsconfig.build.json`** emits `.d.ts` declarations for the public API, excluding stories, tests, mock data and the Storybook i18n bootstrap.
112
- 3. **`node strip-asset-imports-dts.mjs`** post-processes the emitted declarations to remove side-effect imports of `.scss`, `.css`, `.svg` and `.png` files, so consumers do not need loaders for those assets.
113
-
114
- ## Tech stack
115
-
116
- - **UI**: React 19, Material UI 9, Emotion, Font Awesome 7
117
- - **Forms & validation**: React Hook Form 7, Yup 1, `@hookform/resolvers`
118
- - **Dates**: `@mui/x-date-pickers`, `dayjs`
119
- - **i18n**: `i18next`, `react-i18next`, `i18next-browser-languagedetector`
120
- - **Routing (form components)**: `react-router` 8
121
- - **Language & tooling**: TypeScript 6, ESLint 9 (flat config), Prettier 3, Jest 30, Storybook 10, tsup 8
122
-
123
- ## Publishing
124
-
125
- The package is published to npm with only the `dist/` folder included (whitelisted through the `files` field in `package.json`). Before publishing, you can preview the tarball contents with:
126
-
127
- ```bash
128
- npm pack --dry-run
129
- ```
130
-
131
- To publish a new version:
132
-
133
- ```bash
134
- yarn build
135
- yarn npm publish
136
- ```
137
-
138
- ## License
139
-
140
- [MIT](./LICENSE) © TechsBCN
1
+ # techsbcn-storybook
2
+
3
+ A React component library built by [TechsBCN](https://techsbcn.com) on top of Material UI. It provides a set of ready-to-use components — form fields, tables, layouts, navigation, modals and wrappers — designed to be consumed across internal projects with a consistent look and feel.
4
+
5
+ Components are developed and documented in [Storybook](https://storybook.js.org/) and shipped as an npm package.
6
+
7
+ ## Requirements
8
+
9
+ - **Node.js** `>= 18`
10
+ - **React** `>= 18` (declared as a peer dependency)
11
+ - **Yarn** (the repository is pinned to Yarn 4 via `packageManager`)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ yarn add techsbcn-storybook
17
+ ```
18
+
19
+ or
20
+
21
+ ```bash
22
+ npm install techsbcn-storybook
23
+ ```
24
+
25
+ Because MUI, Emotion, React Hook Form, Yup, i18next, dayjs and Font Awesome are runtime dependencies of this library, they are installed automatically.
26
+
27
+ ## Usage
28
+
29
+ Import components directly from the package root:
30
+
31
+ ```tsx
32
+ import { TextFieldComponent, ButtonComponent, TableComponent } from 'techsbcn-storybook';
33
+
34
+ export const Example = () => (
35
+ <>
36
+ <TextFieldComponent name="email" label="Email" />
37
+ <ButtonComponent onClick={() => console.log('clicked')}>Send</ButtonComponent>
38
+ </>
39
+ );
40
+ ```
41
+
42
+ ### Available component groups
43
+
44
+ | Group | Components |
45
+ | --- | --- |
46
+ | **Fields** | `ButtonComponent`, `TextFieldComponent`, `TextSimpleComponent`, `SelectField`, `SelectAsyncField`, `DatePickerComponent` |
47
+ | **Forms** | `LoginForm`, `ChangePasswordForm`, `ResetPasswordForm` |
48
+ | **Tables** | `TableComponent`, `SimpleTableComponent`, `SearchComponent` |
49
+ | **Layouts** | `MainLayoutSimple`, `AppHeader`, `AppSidebar`, `DrawerSidebar` |
50
+ | **Navigation** | `VerticalNav`, `UserInfo` |
51
+ | **Modals** | `ModalComponent` |
52
+ | **Wrappers** | `MainWrapperComponent`, `PublicFormWrapper`, `TabsComponent`, `LinearProgressComponent`, `CardComponent` |
53
+
54
+ See the Storybook documentation for the full API of each component.
55
+
56
+ ## Development
57
+
58
+ ### Getting started
59
+
60
+ ```bash
61
+ yarn install
62
+ yarn storybook
63
+ ```
64
+
65
+ Storybook runs on [http://localhost:6006](http://localhost:6006) and hot-reloads on changes inside `src/`.
66
+
67
+ ### Project structure
68
+
69
+ ```txt
70
+ src/
71
+ components/ # Library source — grouped by category
72
+ fields/
73
+ forms/
74
+ layouts/
75
+ modals/
76
+ navigation/
77
+ tables/
78
+ wrappers/
79
+ content/ # Static assets (images, icons) used by stories
80
+ data/ # Mock data and enums used only by stories
81
+ helpers/ # Shared utilities and hooks
82
+ interfaces/ # Shared TypeScript interfaces
83
+ stories/ # Storybook stories
84
+ i18n.tsx # Storybook-only i18n bootstrap
85
+ index.tsx # Public entry point (barrel of every exported component)
86
+ .storybook/ # Storybook configuration
87
+ tsup.config.ts # Build configuration (JS bundles)
88
+ tsconfig.build.json # Build configuration (type declarations)
89
+ ```
90
+
91
+ Only files under `src/components/` are shipped in the published package. Stories, mock data and the Storybook i18n bootstrap are excluded from the build.
92
+
93
+ ### Scripts
94
+
95
+ | Script | Description |
96
+ | --- | --- |
97
+ | `yarn start` | Runs `tsup` in watch mode (rebuilds `dist/` on every change) |
98
+ | `yarn build` | Produces the distributable output in `dist/`: CJS + ESM bundles, sourcemaps and type declarations |
99
+ | `yarn storybook` | Starts Storybook in development mode |
100
+ | `yarn build-storybook` | Builds the static Storybook site |
101
+ | `yarn lint` | Runs ESLint with autofix over the codebase |
102
+ | `yarn test` | Runs the Jest test suite |
103
+ | `yarn size` | Reports the bundle size using [size-limit](https://github.com/ai/size-limit) |
104
+ | `yarn analyze` | Opens the size-limit visual report |
105
+
106
+ ## Build pipeline
107
+
108
+ The library is built in three steps, wired together in the `build` script:
109
+
110
+ 1. **`tsup`** bundles `src/index.tsx` into CommonJS (`dist/index.js`) and ES Modules (`dist/index.mjs`) using esbuild, with SCSS compiled through `esbuild-sass-plugin` and static assets (SVG/PNG) emitted as separate files.
111
+ 2. **`tsc -p tsconfig.build.json`** emits `.d.ts` declarations for the public API, excluding stories, tests, mock data and the Storybook i18n bootstrap.
112
+ 3. **`node strip-asset-imports-dts.mjs`** post-processes the emitted declarations to remove side-effect imports of `.scss`, `.css`, `.svg` and `.png` files, so consumers do not need loaders for those assets.
113
+
114
+ ## Tech stack
115
+
116
+ - **UI**: React 19, Material UI 9, Emotion, Font Awesome 7
117
+ - **Forms & validation**: React Hook Form 7, Yup 1, `@hookform/resolvers`
118
+ - **Dates**: `@mui/x-date-pickers`, `dayjs`
119
+ - **i18n**: `i18next`, `react-i18next`, `i18next-browser-languagedetector`
120
+ - **Routing (form components)**: `react-router` 8
121
+ - **Language & tooling**: TypeScript 6, ESLint 9 (flat config), Prettier 3, Jest 30, Storybook 10, tsup 8
122
+
123
+ ## Publishing
124
+
125
+ The package is published to npm with only the `dist/` folder included (whitelisted through the `files` field in `package.json`). Before publishing, you can preview the tarball contents with:
126
+
127
+ ```bash
128
+ npm pack --dry-run
129
+ ```
130
+
131
+ To publish a new version:
132
+
133
+ ```bash
134
+ yarn build
135
+ yarn npm publish
136
+ ```
137
+
138
+ ## License
139
+
140
+ [MIT](./LICENSE) © TechsBCN
@@ -0,0 +1,7 @@
1
+ export interface Session {
2
+ nameidentifier: string;
3
+ role: string[];
4
+ }
5
+ export declare const getSession: () => Session | null;
6
+ export declare const saveSession: (jwt: string) => void;
7
+ export declare const clearSession: () => void;
@@ -1,3 +1,4 @@
1
+ export * from './AuthHelper';
1
2
  export * from './CheckPermission';
2
3
  export * from './GroupBy';
3
4
  export * from './FileDownloader';
package/dist/index.d.ts CHANGED
@@ -23,3 +23,4 @@ export * from './components/wrappers/TabsComponent/TabsComponent';
23
23
  export * from './components/wrappers/LinearProgressComponent/LinearProgressComponent';
24
24
  export * from './components/fields/DatePickerComponent/DatePickerComponent';
25
25
  export * from './components/wrappers/CardComponent/CardComponent';
26
+ export * from './helpers/index';
package/dist/index.js CHANGED
@@ -594,6 +594,51 @@ var TextFieldComponent = ({
594
594
  ));
595
595
  };
596
596
 
597
+ // src/helpers/AuthHelper.tsx
598
+ var AUTH_COOKIE_NAME = "auth_token";
599
+ var NAME_IDENTIFIER_CLAIM = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
600
+ var ROLE_CLAIM = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
601
+ var getCookie = (name) => {
602
+ if (typeof document === "undefined") return null;
603
+ const cookie = document.cookie.split("; ").find((c) => c.startsWith(`${name}=`));
604
+ return cookie ? decodeURIComponent(cookie.substring(name.length + 1)) : null;
605
+ };
606
+ var decodeJwtPayload = (jwt) => {
607
+ try {
608
+ const payload = jwt.split(".")[1];
609
+ if (!payload) return null;
610
+ const base64 = payload.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(payload.length / 4) * 4, "=");
611
+ const binary = window.atob(base64);
612
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
613
+ return JSON.parse(new TextDecoder().decode(bytes));
614
+ } catch {
615
+ return null;
616
+ }
617
+ };
618
+ var getSession = () => {
619
+ const jwt = getCookie(AUTH_COOKIE_NAME);
620
+ if (!jwt) return null;
621
+ const payload = decodeJwtPayload(jwt);
622
+ if (!payload) return null;
623
+ if (typeof payload.exp === "number" && payload.exp * 1e3 <= Date.now()) return null;
624
+ const roles = payload[ROLE_CLAIM];
625
+ return {
626
+ nameidentifier: payload[NAME_IDENTIFIER_CLAIM],
627
+ role: roles === void 0 || roles === null ? [] : Array.isArray(roles) ? roles : [roles]
628
+ };
629
+ };
630
+ var saveSession = (jwt) => {
631
+ if (typeof document === "undefined") return;
632
+ const payload = decodeJwtPayload(jwt);
633
+ const expires = typeof payload?.exp === "number" ? `; expires=${new Date(payload.exp * 1e3).toUTCString()}` : "";
634
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
635
+ document.cookie = `${AUTH_COOKIE_NAME}=${encodeURIComponent(jwt)}${expires}; path=/; SameSite=Lax${secure}`;
636
+ };
637
+ var clearSession = () => {
638
+ if (typeof document === "undefined") return;
639
+ document.cookie = `${AUTH_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax`;
640
+ };
641
+
597
642
  // src/helpers/CheckPermission.tsx
598
643
  var checkPermission = (persmisionAvailable, userRoles) => {
599
644
  if (persmisionAvailable === null || persmisionAvailable === void 0 || persmisionAvailable.length === 0) {
@@ -614,6 +659,46 @@ var checkPermission = (persmisionAvailable, userRoles) => {
614
659
  }
615
660
  return userRoles.indexOf(persmisionAvailable) >= 0;
616
661
  };
662
+
663
+ // src/helpers/GroupBy.tsx
664
+ var GroupBy = (xs, f) => {
665
+ return xs.reduce((r, v, _i, _a, k = f(v)) => {
666
+ (r[k] || (r[k] = [])).push(v);
667
+ return r;
668
+ }, {});
669
+ };
670
+
671
+ // src/helpers/FileDownloader.tsx
672
+ var downloadFileBlob = (binaryString) => {
673
+ const data = window.URL.createObjectURL(new Blob([binaryString.blob]));
674
+ const fileName = binaryString.contentDisposition.split("filename=")[1];
675
+ redirectDownload(data, fileName);
676
+ };
677
+ var redirectDownload = (url, fileName) => {
678
+ const a = document.createElement("a");
679
+ a.setAttribute("href", url);
680
+ a.setAttribute("download", fileName);
681
+ a.style.visibility = "hidden";
682
+ document.body.appendChild(a);
683
+ a.click();
684
+ document.body.removeChild(a);
685
+ };
686
+ var getImageByBlob = (binaryString) => {
687
+ return URL.createObjectURL(new Blob([binaryString.blob])).toString();
688
+ };
689
+ var getImageByBase64 = (content) => {
690
+ const binaryString = window.atob(content);
691
+ const blob = new Uint8Array(binaryString.length).map((_byte, i) => binaryString.charCodeAt(i));
692
+ return URL.createObjectURL(new Blob([blob])).toString();
693
+ };
694
+ var toBase64 = (file) => {
695
+ return new Promise((resolve, reject) => {
696
+ const reader = new FileReader();
697
+ reader.readAsDataURL(file);
698
+ reader.onload = () => reader.result && resolve(reader.result.toString());
699
+ reader.onerror = (error) => reject(error);
700
+ });
701
+ };
617
702
  var usePrevious = (value) => {
618
703
  const ref2 = React7.useRef(void 0);
619
704
  React7.useEffect(() => {
@@ -2682,6 +2767,7 @@ exports.CardComponent = CardComponent;
2682
2767
  exports.ChangePasswordForm = ChangePasswordForm;
2683
2768
  exports.DatePickerComponent = DatePickerComponent;
2684
2769
  exports.DrawerSidebar = DrawerSidebar;
2770
+ exports.GroupBy = GroupBy;
2685
2771
  exports.LinearProgressComponent = LinearProgressComponent;
2686
2772
  exports.LoginForm = LoginForm;
2687
2773
  exports.MainLayoutSimple = MainLayoutSimple;
@@ -2701,5 +2787,16 @@ exports.TextFieldComponent = TextFieldComponent;
2701
2787
  exports.TextSimpleComponent = TextSimpleComponent;
2702
2788
  exports.UserInfo = UserInfo;
2703
2789
  exports.VerticalNav = VerticalNav;
2790
+ exports.checkPermission = checkPermission;
2791
+ exports.clearSession = clearSession;
2792
+ exports.downloadFileBlob = downloadFileBlob;
2793
+ exports.getImageByBase64 = getImageByBase64;
2794
+ exports.getImageByBlob = getImageByBlob;
2795
+ exports.getSession = getSession;
2796
+ exports.redirectDownload = redirectDownload;
2797
+ exports.saveSession = saveSession;
2798
+ exports.toBase64 = toBase64;
2799
+ exports.useIsMounted = useIsMounted;
2800
+ exports.usePrevious = usePrevious;
2704
2801
  //# sourceMappingURL=index.js.map
2705
2802
  //# sourceMappingURL=index.js.map