@pplancq/react-template 2.8.16 → 2.9.0
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/CHANGELOG.md +43 -0
- package/_README.md +57 -52
- package/mise.toml +2 -2
- package/package.json +28 -27
- package/scripts/removeDemo.cjs +105 -66
- package/src/README.md +81 -0
- package/src/app/App.tsx +18 -0
- package/src/{bootstrap.tsx → app/AppHTMLElement.tsx} +2 -2
- package/src/app/README.md +69 -0
- package/src/{__tests__/bootstraps.test.tsx → app/__tests__/AppHTMLElement.test.tsx} +5 -5
- package/src/app/config/serviceContainer.ts +6 -0
- package/src/app/providers/Providers/Providers.tsx +18 -0
- package/src/{providers → app/providers}/QueryClientProvider/QueryClientProvider.tsx +3 -3
- package/src/app/providers/ServiceProvider/ServiceContext.ts +8 -0
- package/src/app/providers/ServiceProvider/ServiceProvider.tsx +14 -0
- package/src/app/routing/Router.tsx +14 -0
- package/src/app/routing/appRoutes.ts +3 -0
- package/src/app/routing/routes.tsx +9 -0
- package/src/demo/README.md +148 -0
- package/src/demo/application/dtos/ArchitecturePrinciple.ts +5 -0
- package/src/{types/profileTypes.ts → demo/application/dtos/ProfileFormValues.ts} +1 -1
- package/src/demo/application/use-cases/GetArchitecturePrinciplesUseCase.ts +11 -0
- package/src/demo/application/use-cases/GetArchitecturePrinciplesUseCaseInterface.ts +5 -0
- package/src/demo/application/use-cases/GetDemoUsersUseCase.ts +11 -0
- package/src/demo/application/use-cases/GetDemoUsersUseCaseInterface.ts +5 -0
- package/src/demo/domain/entities/DemoUser.ts +7 -0
- package/src/demo/domain/repositories/ArchitecturePrincipleRepositoryInterface.d.ts +5 -0
- package/src/demo/domain/repositories/DemoUserRepositoryInterface.d.ts +5 -0
- package/src/demo/infrastructure/repositories/HttpDemoUserRepository.ts +29 -0
- package/src/demo/infrastructure/repositories/StaticArchitecturePrincipleRepository.ts +33 -0
- package/src/demo/serviceDemo.ts +39 -0
- package/src/demo/serviceIdentifiers.ts +6 -0
- package/src/demo/ui/components/DemoFooter/DemoFooter.tsx +17 -0
- package/src/{components/Footer → demo/ui/components/DemoFooter}/__tests__/Footer.test.tsx +2 -2
- package/src/{components/Footer → demo/ui/components/DemoFooter}/__tests__/__snapshots__/Footer.test.tsx.snap +3 -3
- package/src/demo/ui/components/DemoFooter/index.ts +1 -0
- package/src/demo/ui/components/DemoHeader/DemoHeader.tsx +25 -0
- package/src/{components/Header → demo/ui/components/DemoHeader}/__tests__/Header.test.tsx +2 -2
- package/src/demo/ui/components/DemoHeader/__tests__/__snapshots__/Header.test.tsx.snap +64 -0
- package/src/demo/ui/components/DemoHeader/index.ts +1 -0
- package/src/{ui/molecules/Navigation/Navigation.tsx → demo/ui/components/DemoNavigation/DemoNavigation.tsx} +4 -4
- package/src/demo/ui/components/DemoNavigation/index.ts +1 -0
- package/src/{components → demo/ui/components}/TextInput/TextInput.tsx +3 -3
- package/src/{forms → demo/ui/forms}/ProfileForm/ProfileForm.tsx +7 -7
- package/src/demo/ui/hooks/useDemoUsersQuery/useDemoUsersQuery.ts +13 -0
- package/src/demo/ui/layouts/DemoLayout/DemoLayout.tsx +12 -0
- package/src/demo/ui/layouts/MainTemplate/MainTemplate.module.css +21 -0
- package/src/{ui/templates → demo/ui/layouts}/MainTemplate/MainTemplate.tsx +7 -7
- package/src/demo/ui/pages/DemoHome/DemoHome.tsx +117 -0
- package/src/demo/ui/pages/DependencyInjectionDemo/DependencyInjectionDemo.tsx +47 -0
- package/src/{pages/Demo → demo/ui/pages}/ReactHookFormDemo/ReactHookFormDemo.tsx +7 -7
- package/src/demo/ui/pages/ReactQueryDemo/ReactQueryDemo.module.scss +38 -0
- package/src/{pages/Demo → demo/ui/pages}/ReactQueryDemo/ReactQueryDemo.tsx +5 -4
- package/src/demo/ui/routing/demoAppRoutes.ts +6 -0
- package/src/demo/ui/routing/demoRoutes.tsx +31 -0
- package/src/main.ts +2 -2
- package/src/shared/README.md +53 -0
- package/src/shared/application/README.md +49 -0
- package/src/shared/domain/README.md +52 -0
- package/src/shared/infrastructure/README.md +51 -0
- package/src/{api → shared/infrastructure/http}/fetchApi.ts +1 -1
- package/src/shared/ui/README.md +50 -0
- package/src/shared/ui/hooks/useService/useService.ts +13 -0
- package/tsconfig.json +3 -1
- package/vitest.config.mts +5 -1
- package/src/api/README.md +0 -65
- package/src/api/demoApi.ts +0 -10
- package/src/assets/README.md +0 -54
- package/src/components/App/App.tsx +0 -18
- package/src/components/App/index.ts +0 -1
- package/src/components/Footer/Footer.tsx +0 -16
- package/src/components/Footer/index.ts +0 -1
- package/src/components/Header/Header.tsx +0 -17
- package/src/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +0 -37
- package/src/components/Header/index.ts +0 -1
- package/src/components/README.md +0 -33
- package/src/config/README.md +0 -63
- package/src/config/index.ts +0 -1
- package/src/forms/README.md +0 -142
- package/src/hooks/README.md +0 -83
- package/src/hooks/api/queryKey.ts +0 -1
- package/src/hooks/api/useDemoApi.ts +0 -16
- package/src/pages/Demo/Demo.tsx +0 -236
- package/src/pages/Demo/ReactHookFormDemo/index.ts +0 -1
- package/src/pages/Demo/ReactHookFormDemo/routes.tsx +0 -7
- package/src/pages/Demo/ReactQueryDemo/index.ts +0 -1
- package/src/pages/Demo/ReactQueryDemo/routes.tsx +0 -7
- package/src/pages/Demo/__tests__/Demo.test.tsx +0 -15
- package/src/pages/Demo/__tests__/__snapshots__/Demo.test.tsx.snap +0 -557
- package/src/pages/Demo/index.ts +0 -1
- package/src/pages/Demo/routes.tsx +0 -8
- package/src/pages/Layout/Layout.tsx +0 -12
- package/src/pages/Layout/index.ts +0 -1
- package/src/pages/README.md +0 -91
- package/src/pages/UnexpectedError/UnexpectedError.module.css +0 -8
- package/src/pages/UnexpectedError/UnexpectedError.tsx +0 -22
- package/src/pages/UnexpectedError/index.ts +0 -1
- package/src/providers/QueryClientProvider/index.ts +0 -1
- package/src/providers/README.md +0 -112
- package/src/providers/index.ts +0 -1
- package/src/providers/withProviders/index.ts +0 -1
- package/src/providers/withProviders/withProviders.tsx +0 -18
- package/src/routing/README.md +0 -76
- package/src/routing/appRoutes.ts +0 -5
- package/src/routing/routerFactory.ts +0 -12
- package/src/routing/routes.tsx +0 -13
- package/src/types/README.md +0 -62
- package/src/types/demoApi.ts +0 -25
- package/src/ui/README.md +0 -144
- package/src/ui/molecules/Navigation/index.ts +0 -1
- package/src/ui/organisms/Footer/Footer.module.css +0 -10
- package/src/ui/organisms/Footer/Footer.tsx +0 -10
- package/src/ui/organisms/Footer/index.ts +0 -1
- package/src/ui/organisms/Header/Header.module.css +0 -17
- package/src/ui/organisms/Header/Header.tsx +0 -16
- package/src/ui/organisms/Header/index.ts +0 -1
- package/src/ui/organisms/MainContent/MainContent.module.css +0 -3
- package/src/ui/organisms/MainContent/MainContent.tsx +0 -6
- package/src/ui/organisms/MainContent/index.ts +0 -1
- package/src/ui/templates/MainTemplate/MainTemplate.module.css +0 -5
- package/src/utils/README.md +0 -70
- /package/src/{assets → app/assets}/css/index.ts +0 -0
- /package/src/{assets → app/assets}/css/mainBody.css +0 -0
- /package/src/{assets → app/assets}/css/reset.css +0 -0
- /package/src/{config → app/config}/queryClientConfig.ts +0 -0
- /package/src/{assets → demo/ui/assets}/images/logo.png +0 -0
- /package/src/{assets → demo/ui/assets}/images/templatePlugins.png +0 -0
- /package/src/{components/Footer/Footer.module.css → demo/ui/components/DemoFooter/DemoFooter.module.css} +0 -0
- /package/src/{components/Header/Header.module.css → demo/ui/components/DemoHeader/DemoHeader.module.css} +0 -0
- /package/src/{ui/molecules/Navigation/Navigation.module.css → demo/ui/components/DemoNavigation/DemoNavigation.module.css} +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Input/Input.module.scss +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Input/Input.tsx +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Input/index.ts +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Logo/Logo.module.css +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Logo/Logo.tsx +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Logo/__tests__/Logo.test.tsx +0 -0
- /package/src/{ui/atoms → demo/ui/components}/Logo/index.ts +0 -0
- /package/src/{ui/atoms → demo/ui/components}/NavLink/NavLink.tsx +0 -0
- /package/src/{ui/atoms → demo/ui/components}/NavLink/index.ts +0 -0
- /package/src/{components → demo/ui/components}/TextInput/index.ts +0 -0
- /package/src/{forms → demo/ui/forms}/ProfileForm/ProfileForm.module.scss +0 -0
- /package/src/{forms → demo/ui/forms}/ProfileForm/index.ts +0 -0
- /package/src/{ui/templates → demo/ui/layouts}/MainTemplate/index.ts +0 -0
- /package/src/{pages/Demo/Demo.module.scss → demo/ui/pages/DemoHome/DemoHome.module.scss} +0 -0
- /package/src/{pages/Demo/ReactQueryDemo/ReactQueryDemo.module.scss → demo/ui/pages/DependencyInjectionDemo/DependencyInjectionDemo.module.scss} +0 -0
- /package/src/{pages/Demo/ReactHookFormDemo/ReactHookFormDemo.module.css → demo/ui/pages/ReactHookFormDemo/ReactHookFormDemo.module.scss} +0 -0
- /package/src/{api → shared/infrastructure/http}/constant.ts +0 -0
- /package/src/{types/api.ts → shared/infrastructure/http/fetchApi.type.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { UnexpectedError } from './UnexpectedError';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { QueryClientProvider } from './QueryClientProvider';
|
package/src/providers/README.md
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# 📁 providers
|
|
2
|
-
|
|
3
|
-
The "providers" folder is designed to expose service handlers and custom contexts that provide shared functionality across our entire application. It serves as a centralized way to manage services such as authentication, authorization, translation management, and many others.
|
|
4
|
-
|
|
5
|
-
## 📑 Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Why Use a "providers" Folder?](#folder-organization)
|
|
8
|
-
- [Structure of a "providers" Folder](#structure)
|
|
9
|
-
- [Usage Example](#usage)
|
|
10
|
-
- [Best Practice](#best-practice)
|
|
11
|
-
|
|
12
|
-
## <span id="folder-organization">Why Use a "providers" Folder?</span>
|
|
13
|
-
|
|
14
|
-
1. **Centralization** : By grouping all our service handlers in a "providers" folder, we centralize the management of these services, making configuration and usage simpler.
|
|
15
|
-
|
|
16
|
-
2. **Reusability** : Service handlers and custom contexts exposed in this folder can be reused across different components of our application, promoting code reuse.
|
|
17
|
-
|
|
18
|
-
3. **Better Separation of Concerns** : By separating services from the user interface, we improve code readability and adhere to the separation of concerns principle.
|
|
19
|
-
|
|
20
|
-
## <span id="structure">Structure of a "providers" Folder</span>
|
|
21
|
-
|
|
22
|
-
The structure of a "providers" folder can vary based on your project's needs, but here is a typical structure you might adopt :
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
📁 providers
|
|
26
|
-
├── 📁 AuthProvider
|
|
27
|
-
├── 📁 AuthorizationProvider
|
|
28
|
-
├── 📁 TranslationProvider
|
|
29
|
-
├── 📁 CustomRouterProvider
|
|
30
|
-
├── 📁 CustomContextProvider
|
|
31
|
-
├── 📁 ...
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Each file, such as "AuthProvider.ts" or "TranslationProvider.ts," contains a service handler or custom context intended to be used throughout your application.
|
|
35
|
-
|
|
36
|
-
## <span id="usage">🧑🏻💻Usage Example </span>
|
|
37
|
-
|
|
38
|
-
Suppose we have an authentication service handler "AuthProvider" in our "providers" folder:
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
// AuthProvider.js
|
|
42
|
-
import { createContext, useState } from 'react';
|
|
43
|
-
|
|
44
|
-
export const AuthContext = createContext();
|
|
45
|
-
|
|
46
|
-
export const AuthProvider = ({ children }) => {
|
|
47
|
-
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
48
|
-
|
|
49
|
-
const login = () => {
|
|
50
|
-
setIsAuthenticated(true);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const logout = () => {
|
|
54
|
-
setIsAuthenticated(false);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return <AuthContext.Provider value={{ isAuthenticated, login, logout }}>{children}</AuthContext.Provider>;
|
|
58
|
-
};
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
We can then use this authentication service provider in our components by wrapping our components in the provided context:
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
import { AuthProvider } from '@Front/Providers/AuthProvider';
|
|
65
|
-
|
|
66
|
-
export const App = () => {
|
|
67
|
-
return <AuthProvider>{/* Vos composants React ici */}</AuthProvider>;
|
|
68
|
-
};
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## <span id="best-practice">🎖️ Best Practice</span>
|
|
72
|
-
|
|
73
|
-
A good practice is to set up a Higher Order Component (HOC) "withProvider" that allows injecting all providers at
|
|
74
|
-
once.
|
|
75
|
-
|
|
76
|
-
Example:
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import { ComponentType } from 'react';
|
|
80
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
81
|
-
import { AuthProvider } from '@Front/Providers/AuthProvider';
|
|
82
|
-
import { QueryClientProvider } from '@Front/Providers/QueryClientProvider ';
|
|
83
|
-
|
|
84
|
-
export interface WithRootProps {
|
|
85
|
-
queryClient: QueryClient;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const withProvider = <P extends object>(Component: ComponentType<P>) => {
|
|
89
|
-
const WithProvider = ({ queryClient, ...props }: P & WithRootProps) => (
|
|
90
|
-
<QueryClientProvider client={queryClient}>
|
|
91
|
-
<AuthProvider>
|
|
92
|
-
<Component {...props as P} />
|
|
93
|
-
</AuthProvider>
|
|
94
|
-
</QueryClientProvider>
|
|
95
|
-
);
|
|
96
|
-
WithProvider.displayName = `withProvider(${Component.displayName || Component.name})`
|
|
97
|
-
|
|
98
|
-
return WithProvider
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```javascript
|
|
104
|
-
import { withProvider } from '@Front/Providers/withProvider';
|
|
105
|
-
import { App } from '@Front/components/App';
|
|
106
|
-
|
|
107
|
-
const Root = withProvider(App);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
**_By using a "providers" folder, we centralize the management of services and custom contexts, enhancing code reuse and ease of maintenance._**
|
package/src/providers/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { withProvider } from './withProviders';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { withProvider } from './withProviders';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { QueryClientProvider } from '@Front/providers/QueryClientProvider';
|
|
2
|
-
import type { ComponentProps, ComponentType } from 'react';
|
|
3
|
-
|
|
4
|
-
type WithRootProps = {
|
|
5
|
-
queryClient: ComponentProps<typeof QueryClientProvider>['client'];
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const withProvider = <P extends object>(Component: ComponentType<P>) => {
|
|
9
|
-
const WithProvider = ({ queryClient, ...props }: P & WithRootProps) => (
|
|
10
|
-
<QueryClientProvider client={queryClient}>
|
|
11
|
-
<Component {...(props as P)} />
|
|
12
|
-
</QueryClientProvider>
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
WithProvider.displayName = `withProvider(${Component.displayName || Component.name})`;
|
|
16
|
-
|
|
17
|
-
return WithProvider;
|
|
18
|
-
};
|
package/src/routing/README.md
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# 📁routing
|
|
2
|
-
|
|
3
|
-
The "routing" folder is responsible for managing navigation within the application. We use the `react-router` library to facilitate route creation and navigation between different views of our application.
|
|
4
|
-
|
|
5
|
-
## 📑 Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Folder Organization](#folder-organization)
|
|
8
|
-
- [Using `react-router`](#react-router)
|
|
9
|
-
- [Using `appRoutes.ts`](#using-appRoutes)
|
|
10
|
-
- [Learn More](#learn-more)
|
|
11
|
-
|
|
12
|
-
## <span id="folder-organization">Folder Organization</span>
|
|
13
|
-
|
|
14
|
-
In the "routing" folder, you can find the following files and components:
|
|
15
|
-
|
|
16
|
-
1. **`routesObject.tsx`** : This file contains the configuration of our main router. It declares the various routes of the application and defines the components associated with each route.
|
|
17
|
-
|
|
18
|
-
2. **`routerFactory.ts`** : The `routerFactory.ts` file can contain functions or reusable components related to routing. You can place routing utilities or custom components to facilitate navigation management in our application.
|
|
19
|
-
|
|
20
|
-
3. **`appRoutes.ts`** It contains a simple structure to define the paths of our application.
|
|
21
|
-
|
|
22
|
-
## <span id="react-router">🧑🏻💻 Using `react-router` </span>
|
|
23
|
-
|
|
24
|
-
`react-router` is a library that makes it easy to create routes in a React application. You can import it into the appropriate files to define routes and manage navigation between views. Here's a simple example of its usage:
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
import { createRoot } from 'react-dom/client';
|
|
28
|
-
import { createBrowserRouter, RouterProvider } from 'react-router/dom';
|
|
29
|
-
|
|
30
|
-
const router = createBrowserRouter([
|
|
31
|
-
{
|
|
32
|
-
path: '/',
|
|
33
|
-
element: (
|
|
34
|
-
<div>
|
|
35
|
-
<h1>Hello World</h1>
|
|
36
|
-
<Link to="about">About Us</Link>
|
|
37
|
-
</div>
|
|
38
|
-
),
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
path: 'about',
|
|
42
|
-
element: <div>About</div>,
|
|
43
|
-
},
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
createRoot(document.getElementById('root')).render(<RouterProvider router={router} />);
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## <span id="using-appRoutes">Using `appRoutes.ts`</span>
|
|
50
|
-
|
|
51
|
-
How to define a router with parameters ?
|
|
52
|
-
|
|
53
|
-
The simplest way is to write it with the parameters as `react-router` requires, and when using it in a `NavLink` call the `generatPath` function from `react-router`.
|
|
54
|
-
|
|
55
|
-
For example:
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
// appRoutes.ts
|
|
59
|
-
export const appRoutes = {
|
|
60
|
-
home: '/',
|
|
61
|
-
post: '/post',
|
|
62
|
-
article: '/post/:id',
|
|
63
|
-
};
|
|
64
|
-
// component.tsx
|
|
65
|
-
import { NavLink, generatePath } from 'react-router/dom';
|
|
66
|
-
import { appRoutes } from '@Front/routing/appRoutes';
|
|
67
|
-
export const ComponentName = () => {
|
|
68
|
-
return <NavLink to={generatePath(appRoutes.article, { id: 1 })}>link to article 1</NavLink>;
|
|
69
|
-
};
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
With the `generatePath` function, it is possible to generate URIs with dynamic parameters.
|
|
73
|
-
|
|
74
|
-
## <span id="learn-more">🙇 Learn More</span>
|
|
75
|
-
|
|
76
|
-
- [React Router](https://reactrouter.com/en/main/start/overview)
|
package/src/routing/appRoutes.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createBrowserRouter } from 'react-router';
|
|
2
|
-
import { routeObject } from './routes';
|
|
3
|
-
|
|
4
|
-
interface CreateRouterProps {
|
|
5
|
-
basename?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const createRouter = ({ basename }: CreateRouterProps = {}) => {
|
|
9
|
-
return createBrowserRouter(routeObject, {
|
|
10
|
-
basename,
|
|
11
|
-
});
|
|
12
|
-
};
|
package/src/routing/routes.tsx
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { demoRoutes } from '@Front/pages/Demo';
|
|
2
|
-
import { Layout } from '@Front/pages/Layout';
|
|
3
|
-
import type { RouteObject } from 'react-router';
|
|
4
|
-
import { UnexpectedError } from '@Front/pages/UnexpectedError';
|
|
5
|
-
|
|
6
|
-
export const routeObject: RouteObject[] = [
|
|
7
|
-
{
|
|
8
|
-
path: '/',
|
|
9
|
-
element: <Layout />,
|
|
10
|
-
children: [demoRoutes],
|
|
11
|
-
errorElement: <UnexpectedError />,
|
|
12
|
-
},
|
|
13
|
-
];
|
package/src/types/README.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# 📁 types
|
|
2
|
-
|
|
3
|
-
The "types" folder: since we are using TypeScript, this folder is intended to contain custom type definition files that enhance type checking and auto-completion in your code.
|
|
4
|
-
|
|
5
|
-
## 📑 Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Why use a "types" folder?](#folder-organization)
|
|
8
|
-
- [Structure of a "types" folder](#structure)
|
|
9
|
-
- [Example of usage](#usage)
|
|
10
|
-
|
|
11
|
-
## <span id="folder-organization">Why use a "types" folder?</span>
|
|
12
|
-
|
|
13
|
-
1. **Type Checking** : By defining custom types for our application, we improve type checking, making it easier to detect and prevent typing errors.
|
|
14
|
-
|
|
15
|
-
2. **Better Auto-Completion** : Custom type definition files allow code editors to provide more accurate auto-completion when working with objects, functions, and components.
|
|
16
|
-
|
|
17
|
-
3. **Integrated Documentation** : By creating explicit types, you effectively document your code, making it easier for other developers to understand your components, functions, and data.
|
|
18
|
-
|
|
19
|
-
## <span id="structure">Structure of a "types" folder</span>
|
|
20
|
-
|
|
21
|
-
The structure of a "types" folder can vary based on need, but here's a typical structure you might adopt :
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
📁 src
|
|
25
|
-
📁 types
|
|
26
|
-
├── 📄 customTypes.ts
|
|
27
|
-
├── 📄 apiTypes.ts
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
In this structure, each file, such as "customTypes.ts" or "apiTypes.ts," contains type definitions specific to your application. For example, you might define types for API data, business objects, or component props.
|
|
31
|
-
|
|
32
|
-
## <span id="usage">🧑🏻💻 Example of usage</span>
|
|
33
|
-
|
|
34
|
-
Suppose you have defined a custom type in "customTypes.ts":
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
// customTypes.ts
|
|
38
|
-
export type User = {
|
|
39
|
-
id: number;
|
|
40
|
-
name: string;
|
|
41
|
-
email?: string;
|
|
42
|
-
};
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
You can then use this type in your React components to define props or states, enhancing type checking:
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { User } from '@Front/types/customTypes';
|
|
49
|
-
|
|
50
|
-
type UserProfileProps = {
|
|
51
|
-
user: User;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const UserProfile = ({ user }: UserProfileProps) => {
|
|
55
|
-
return (
|
|
56
|
-
<div id={user.id}>
|
|
57
|
-
<h1>{user.name}</h1>
|
|
58
|
-
{user.email && <p>Email: {user.email}</p>}
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
```
|
package/src/types/demoApi.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type Address = {
|
|
2
|
-
street: string;
|
|
3
|
-
suite: string;
|
|
4
|
-
city: string;
|
|
5
|
-
zipcode: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type Company = {
|
|
9
|
-
name: string;
|
|
10
|
-
catchPhrase: string;
|
|
11
|
-
bs: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type User = {
|
|
15
|
-
id: number;
|
|
16
|
-
name: string;
|
|
17
|
-
username: string;
|
|
18
|
-
email: string;
|
|
19
|
-
address: Address;
|
|
20
|
-
phone: string;
|
|
21
|
-
website: string;
|
|
22
|
-
company: Company;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type Users = User[];
|
package/src/ui/README.md
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
# 📁 ui
|
|
2
|
-
|
|
3
|
-
The "ui" folder is a directory designed to group and organize reusable components.
|
|
4
|
-
|
|
5
|
-
We follow the concept of Atomic design to structure our components into "atoms," "molecules," "organisms," and "templates," ensuring consistent design and maximum reusability.
|
|
6
|
-
|
|
7
|
-
## 📑 Table of Contents
|
|
8
|
-
|
|
9
|
-
- [Why use a "ui" folder with Atomic Design](#folder-organization)
|
|
10
|
-
- [Structure of a "ui" folder according to Atomic Design](#structure)
|
|
11
|
-
- [Usage Example](#usage)
|
|
12
|
-
- [Best Practice](#best-practice)
|
|
13
|
-
|
|
14
|
-
## <span id="folder-organization">Why use a "ui" folder with Atomic Design?</span>
|
|
15
|
-
|
|
16
|
-
1. **Modularity** : Atomic Design divides components into levels of increasing complexity, making it easy to create reusable components at different levels.
|
|
17
|
-
|
|
18
|
-
2. **Visual Consistency** : By following the concept of Atomic Design, we can maintain visual consistency across our entire application by reusing atoms, molecules, and organisms.
|
|
19
|
-
|
|
20
|
-
3. **Productivity** : Creating prefab components in a "ui" folder speeds up development by reducing code duplication.
|
|
21
|
-
|
|
22
|
-
## <span id="structure">Structure of a "ui" folder according to Atomic Design</span>
|
|
23
|
-
|
|
24
|
-
The structure of a "ui" folder can follow the hierarchy of Atomic Design:
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
📁 ui
|
|
28
|
-
├── 📁 atoms
|
|
29
|
-
│ ├──📁 Button
|
|
30
|
-
│ ├──📁 Input
|
|
31
|
-
│ ├── ...
|
|
32
|
-
├── 📁 molecules
|
|
33
|
-
│ ├── 📁 FormField
|
|
34
|
-
│ ├── 📁 SearchBar
|
|
35
|
-
│ ├── ...
|
|
36
|
-
├── 📁 organisms
|
|
37
|
-
│ ├── 📁 Header
|
|
38
|
-
│ ├── 📁 Footer
|
|
39
|
-
│ ├── ...
|
|
40
|
-
├── 📁 templates
|
|
41
|
-
│ ├── 📁 PageTemplate
|
|
42
|
-
│ ├── ...
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Each level (atoms, molecules, organisms, templates) groups components based on their complexity. You can create subfolders to better organize the components.
|
|
46
|
-
|
|
47
|
-
## <span id="usage">🧑🏻💻Example of usage</span>
|
|
48
|
-
|
|
49
|
-
## Using components from Atomic Design
|
|
50
|
-
|
|
51
|
-
In our project, we use Atomic Design to organize our reusable components into levels ranging from "atoms" to "templates." Here's a concrete example of using these components in our application.
|
|
52
|
-
|
|
53
|
-
### Atom - "Button" Component
|
|
54
|
-
|
|
55
|
-
"Atoms" are basic components that don't depend on other components. In our "ui/atoms" folder, we have the "Button" component. It's a simple UI element that we can use as follows:
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
import { Button } from '@Front/ui/atoms/Button';
|
|
59
|
-
|
|
60
|
-
export const MyComponent = () => {
|
|
61
|
-
return (
|
|
62
|
-
<div>
|
|
63
|
-
<Button label="Cliquez-moi" />
|
|
64
|
-
{/* ... other elements of the application */}
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Molecule - "SearchBar" Component
|
|
71
|
-
|
|
72
|
-
"Molecules" are more complex components that group atoms to form a functional set. In our "ui/molecules" folder, we have the "SearchBar" component that uses the atomic "Button":
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
import { SearchBar } from '@Front/ui/molecules/SearchBar';
|
|
76
|
-
|
|
77
|
-
export const MyComponent = () => {
|
|
78
|
-
return (
|
|
79
|
-
<div>
|
|
80
|
-
<SearchBar placeholder="Rechercher..." />
|
|
81
|
-
{/* ... other elements of the application */}
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
The "SearchBar" component is a molecule because it combines the "Button" atom with other atoms.
|
|
88
|
-
|
|
89
|
-
### Organism - "Header" Component
|
|
90
|
-
|
|
91
|
-
"Organisms" are even more complex components that combine molecules and atoms to create self-contained parts of the UI. In our "ui/organisms" folder, we have the "Header" component that might include the molecular "SearchBar":
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
import Header from '@Front/ui/organisms/Header';
|
|
95
|
-
|
|
96
|
-
export const MyComponent = () => {
|
|
97
|
-
return (
|
|
98
|
-
<div>
|
|
99
|
-
<Header />
|
|
100
|
-
{/* ... other elements of the application */}
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
The "Header" component is an organism because it combines the molecular "SearchBar" with other elements to form a self-contained part of the interface.
|
|
107
|
-
|
|
108
|
-
### Templates - "PageTemplate" Component
|
|
109
|
-
|
|
110
|
-
"Templates" are "skeleton" components that define the placement of elements using React's composition ability.
|
|
111
|
-
|
|
112
|
-
In our "ui/templates" folder, we have the "PageTemplate" component that defines the placement of the "topBar," "body," and "footer" to create a complete page:
|
|
113
|
-
|
|
114
|
-
```javascript
|
|
115
|
-
import PageTemplate from '@Front/ui/templates/PageTemplate';
|
|
116
|
-
|
|
117
|
-
export const MyComponent = () => {
|
|
118
|
-
return <PageTemplate topBar={<div>TopBar</div>} body={<div>Boby</div>} footer={<div>Footer</div>} />;
|
|
119
|
-
};
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
The "PageTemplate" component is a template because it incorporates the "Header" organism and other elements to create a complete page.
|
|
123
|
-
|
|
124
|
-
## <span id="best-practice">🎖️ Best Practice</span>
|
|
125
|
-
|
|
126
|
-
When incorporating external component libraries, it is recommended to adhere to the following best practices for the organization of UI components:
|
|
127
|
-
|
|
128
|
-
#### - Export Components via the `ui` Directory
|
|
129
|
-
|
|
130
|
-
Always export UI components from the `ui` directory, even if they are sourced from an external component library.
|
|
131
|
-
|
|
132
|
-
This practice serves as a central point for managing component exports and facilitates handling bugs or breaking changes.
|
|
133
|
-
|
|
134
|
-
#### - Centralized Component Management
|
|
135
|
-
|
|
136
|
-
By exporting components through the ui directory, you establish a centralized location for managing changes or addressing issues related to external components.
|
|
137
|
-
|
|
138
|
-
In the event of a bug or breaking change, modifications can be made at a single location, preventing the need to update multiple parts of the codebase.
|
|
139
|
-
|
|
140
|
-
This approach contributes to better maintainability and ensures that updates to external components are efficiently managed.
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
**_By adopting this practice, you create a clear separation between your custom components and external components, simplifying maintenance and reducing the impact of changes from external dependencies._**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Navigation } from './Navigation';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import classes from './Footer.module.css';
|
|
3
|
-
|
|
4
|
-
type FooterProps = {
|
|
5
|
-
footerContent?: ReactNode;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const Footer = ({ footerContent }: FooterProps) => {
|
|
9
|
-
return <footer className={classes.footer}>{footerContent}</footer>;
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Footer } from './Footer';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
header {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: row;
|
|
4
|
-
flex-grow: 0;
|
|
5
|
-
flex-shrink: 0;
|
|
6
|
-
align-items: center;
|
|
7
|
-
justify-content: space-between;
|
|
8
|
-
background-color: #00008f;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@media screen and (width <= 900px) {
|
|
12
|
-
header {
|
|
13
|
-
display: flex;
|
|
14
|
-
align-items: center;
|
|
15
|
-
justify-content: center;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import classes from './Header.module.css';
|
|
3
|
-
|
|
4
|
-
type HeaderProps = {
|
|
5
|
-
leftComponents?: ReactNode;
|
|
6
|
-
rightComponents?: ReactNode;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const Header = ({ leftComponents, rightComponents }: HeaderProps) => {
|
|
10
|
-
return (
|
|
11
|
-
<header className={classes.header}>
|
|
12
|
-
{leftComponents}
|
|
13
|
-
{rightComponents}
|
|
14
|
-
</header>
|
|
15
|
-
);
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Header } from './Header';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MainContent } from './MainContent';
|
package/src/utils/README.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# 📁 utils
|
|
2
|
-
|
|
3
|
-
The `utils` folder contains reusable utilities and functionalities used across different parts of the application. These utilities are designed to simplify the code, promote reusability, and enhance the maintainability of the project.
|
|
4
|
-
|
|
5
|
-
## 📑 Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Usage Example](#usage)
|
|
8
|
-
- [Best Practice](#best-practice)
|
|
9
|
-
|
|
10
|
-
## <span id="usage">🧑🏻💻 Example of usage</span>
|
|
11
|
-
|
|
12
|
-
### `formatDate.ts`
|
|
13
|
-
|
|
14
|
-
The `formatDate.ts` file contains a utility function to consistently format dates throughout the application. You can use it to display dates in various components.
|
|
15
|
-
|
|
16
|
-
Example of usage:
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
import { formatDate } from '@Front/utils/formatDate';
|
|
20
|
-
|
|
21
|
-
const formattedDate = formatDate(new Date());
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### `apiUtils.ts`
|
|
25
|
-
|
|
26
|
-
The `apiUtils.ts` file contains utility functions to simplify API calls. You can find functions to handle HTTP requests, manipulate responses, and manage errors.
|
|
27
|
-
|
|
28
|
-
Example of usage:
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
31
|
-
import { fetchData, handleResponse } from '@Front/utils/apiUtils';
|
|
32
|
-
|
|
33
|
-
async function fetchDataAndHandleError() {
|
|
34
|
-
try {
|
|
35
|
-
const data = await fetchData('https://api.example.com/data');
|
|
36
|
-
const processedData = handleResponse(data);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error('An error occurred while fetching data:', error);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { formatDate, fetchData, handleResponse } from '@Front/utils';
|
|
45
|
-
// Use the utilities as needed
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
**_By using the "utils" folder, we organize our utilities efficiently for better reuse and simplified management._**
|
|
51
|
-
|
|
52
|
-
## <span id="best-practice">🎖️ Best Practice</span>
|
|
53
|
-
|
|
54
|
-
When dealing with utility functions, especially those sourced from external libraries like `date-fns`, it is advisable to follow these best practices for maintaining a structured codebase:
|
|
55
|
-
|
|
56
|
-
#### - Export Libraries from the `utils` Directory
|
|
57
|
-
|
|
58
|
-
Always export utility libraries, such as `date-fns` or others, from the `utils` directory. This practice provides a central location for managing library imports and ensures consistent usage throughout the codebase.
|
|
59
|
-
|
|
60
|
-
#### - Centralized Library Management
|
|
61
|
-
|
|
62
|
-
Exporting libraries through the `utils` directory establishes a centralized point for managing changes or updates to external libraries.
|
|
63
|
-
|
|
64
|
-
In case of updates, bug fixes, or changes in functionality, modifications can be made at a single location, preventing the need to update multiple parts of the codebase.
|
|
65
|
-
|
|
66
|
-
This approach contributes to better maintainability and ensures that updates to external libraries are efficiently handled.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
**_By adhering to this practice, you create a clear separation between custom utility functions and external libraries, making your codebase more organized and reducing the impact of changes from external dependencies._**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|