@pplancq/react-template 1.0.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/.babelrc.js +1 -0
- package/.commitlintrc.js +1 -0
- package/.editorconfig +4 -0
- package/.env +36 -0
- package/.eslintrc.js +1 -0
- package/.gitattributes +1 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.lintstagedrc.js +5 -0
- package/.postcssrc.js +1 -0
- package/.prettierrc.js +1 -0
- package/.stylelintrc.js +1 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/_gitignore +26 -0
- package/package.json +84 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +17 -0
- package/src/api/README.md +64 -0
- package/src/api/demoApi.ts +44 -0
- package/src/assets/README.md +51 -0
- package/src/assets/css/index.ts +2 -0
- package/src/assets/css/mainBody.css +4 -0
- package/src/assets/css/reset.css +131 -0
- package/src/assets/images/logo.png +0 -0
- package/src/assets/images/templatePlugins.png +0 -0
- package/src/bootstrap.tsx +26 -0
- package/src/components/App/App.tsx +18 -0
- package/src/components/App/index.ts +1 -0
- package/src/components/Footer/Footer.module.css +4 -0
- package/src/components/Footer/Footer.tsx +16 -0
- package/src/components/Footer/__tests__/Footer.test.tsx +15 -0
- package/src/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +21 -0
- package/src/components/Footer/index.ts +1 -0
- package/src/components/Header/Header.module.css +7 -0
- package/src/components/Header/Header.tsx +17 -0
- package/src/components/Header/__tests__/Header.test.tsx +15 -0
- package/src/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +35 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/README.md +34 -0
- package/src/components/TextInput/TextInput.tsx +24 -0
- package/src/components/TextInput/index.ts +1 -0
- package/src/config/README.md +61 -0
- package/src/config/index.ts +1 -0
- package/src/config/queryClientConfig.ts +3 -0
- package/src/forms/ProfileForm/ProfileForm.module.scss +10 -0
- package/src/forms/ProfileForm/ProfileForm.tsx +51 -0
- package/src/forms/ProfileForm/index.ts +1 -0
- package/src/forms/README.md +131 -0
- package/src/hooks/README.md +87 -0
- package/src/hooks/api/queryKey.ts +1 -0
- package/src/hooks/api/useDemoApi.ts +16 -0
- package/src/main.ts +3 -0
- package/src/pages/Demo/Demo.module.scss +184 -0
- package/src/pages/Demo/Demo.tsx +237 -0
- package/src/pages/Demo/ReactHookFormDemo/ReactHookFormDemo.module.css +32 -0
- package/src/pages/Demo/ReactHookFormDemo/ReactHookFormDemo.tsx +48 -0
- package/src/pages/Demo/ReactHookFormDemo/index.ts +1 -0
- package/src/pages/Demo/ReactHookFormDemo/routes.tsx +7 -0
- package/src/pages/Demo/ReactQueryDemo/ReactQueryDemo.module.scss +38 -0
- package/src/pages/Demo/ReactQueryDemo/ReactQueryDemo.tsx +55 -0
- package/src/pages/Demo/ReactQueryDemo/index.ts +1 -0
- package/src/pages/Demo/ReactQueryDemo/routes.tsx +7 -0
- package/src/pages/Demo/__tests__/Demo.test.tsx +15 -0
- package/src/pages/Demo/__tests__/__snapshots__/Demo.test.tsx.snap +555 -0
- package/src/pages/Demo/index.ts +1 -0
- package/src/pages/Demo/routes.tsx +8 -0
- package/src/pages/Error/Error.module.css +8 -0
- package/src/pages/Error/Error.tsx +22 -0
- package/src/pages/Error/index.ts +1 -0
- package/src/pages/Layout/Layout.tsx +12 -0
- package/src/pages/Layout/index.ts +1 -0
- package/src/pages/README.md +88 -0
- package/src/providers/QueryClientProvider/QueryClientProvider.tsx +16 -0
- package/src/providers/QueryClientProvider/index.ts +1 -0
- package/src/providers/README.md +115 -0
- package/src/providers/index.ts +1 -0
- package/src/providers/withProviders/index.ts +1 -0
- package/src/providers/withProviders/withProviders.tsx +18 -0
- package/src/react-app-env.d.ts +3 -0
- package/src/routing/README.md +80 -0
- package/src/routing/appRoutes.ts +5 -0
- package/src/routing/routerFactory.ts +10 -0
- package/src/routing/routes.tsx +13 -0
- package/src/types/README.md +61 -0
- package/src/types/demoApi.ts +9 -0
- package/src/types/profileTypes.ts +5 -0
- package/src/ui/README.md +141 -0
- package/src/ui/atoms/Input/Input.module.scss +32 -0
- package/src/ui/atoms/Input/Input.tsx +27 -0
- package/src/ui/atoms/Input/index.ts +1 -0
- package/src/ui/atoms/Logo/Logo.module.css +3 -0
- package/src/ui/atoms/Logo/Logo.tsx +11 -0
- package/src/ui/atoms/Logo/index.ts +1 -0
- package/src/ui/atoms/NavLink/NavLink.tsx +8 -0
- package/src/ui/atoms/NavLink/index.ts +1 -0
- package/src/ui/molecules/Navigation/Navigation.module.css +22 -0
- package/src/ui/molecules/Navigation/Navigation.tsx +25 -0
- package/src/ui/molecules/Navigation/index.ts +1 -0
- package/src/ui/organisms/Footer/Footer.module.css +10 -0
- package/src/ui/organisms/Footer/Footer.tsx +10 -0
- package/src/ui/organisms/Footer/index.ts +1 -0
- package/src/ui/organisms/Header/Header.module.css +17 -0
- package/src/ui/organisms/Header/Header.tsx +16 -0
- package/src/ui/organisms/Header/index.ts +1 -0
- package/src/ui/organisms/MainContent/MainContent.module.css +3 -0
- package/src/ui/organisms/MainContent/MainContent.tsx +6 -0
- package/src/ui/organisms/MainContent/index.ts +1 -0
- package/src/ui/templates/MainTemplate/MainTemplate.module.css +5 -0
- package/src/ui/templates/MainTemplate/MainTemplate.tsx +26 -0
- package/src/ui/templates/MainTemplate/index.ts +1 -0
- package/src/utils/README.md +68 -0
- package/tsconfig.json +32 -0
- package/vitest.config.mts +49 -0
- package/vitest.setup.ts +1 -0
- package/webpack.config.js +22 -0
package/.babelrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: '@pplancq/babel-config' };
|
package/.commitlintrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ['@pplancq/commitlint-config'] };
|
package/.editorconfig
ADDED
package/.env
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# For all environments, the following files are loaded if they exist, with later ones taking precedence over earlier ones:
|
|
2
|
+
|
|
3
|
+
# * .env contains default values for environment variables required by the application.
|
|
4
|
+
# * .env.local allows overwriting environment variables (unversioned file).
|
|
5
|
+
# * .env.<MODE> contains environment-specific variables.
|
|
6
|
+
# * .env.<MODE>.local overwrites environment-specific variables (unversioned file).
|
|
7
|
+
|
|
8
|
+
# <MODE> available by default: development, production, or test.
|
|
9
|
+
|
|
10
|
+
# Real system environment variables take precedence over .env files.
|
|
11
|
+
|
|
12
|
+
# /!\ DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE OR ANY VERSIONED FILE. /!\
|
|
13
|
+
|
|
14
|
+
# Enables/disables launching the browser when npm start is run.
|
|
15
|
+
# Default is false.
|
|
16
|
+
#BROWSER=false
|
|
17
|
+
|
|
18
|
+
# Sets the port for the development web server.
|
|
19
|
+
# Default is 3000.
|
|
20
|
+
#PORT=3000
|
|
21
|
+
|
|
22
|
+
# Allows you to deactivate the stylelint plugin
|
|
23
|
+
# Default is false
|
|
24
|
+
#DISABLE_STYLELINT_PLUGIN=false
|
|
25
|
+
|
|
26
|
+
# Permet de désactiver le plugin eslint
|
|
27
|
+
# Default is false
|
|
28
|
+
#DISABLE_ESLINT_PLUGIN=false
|
|
29
|
+
|
|
30
|
+
# Sets the prefix for environment variables that will be passed to the frontend.
|
|
31
|
+
# Access environment variables using import.meta.env.FRONT_FOO in the code.
|
|
32
|
+
# Default is FRONT_.
|
|
33
|
+
#ENV_PREFIX=FRONT_
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ['@pplancq/eslint-config/react', '@pplancq/eslint-config/vitest'] };
|
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx --no -- commitlint --edit ${1}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx lint-staged
|
package/.lintstagedrc.js
ADDED
package/.postcssrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@pplancq/postcss-config');
|
package/.prettierrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@pplancq/prettier-config');
|
package/.stylelintrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ['@pplancq/stylelint-config'] };
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
## @pplancq/react-template 1.0.0 (2024-02-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **react-template:** add config for end of line to lf ([cc67932](https://github.com/pplancq/dev-tools/commit/cc67932696406b4afaeeaa48515abf58bd716286))
|
|
7
|
+
* **react-template:** add folder structure with documentation ([3d365c2](https://github.com/pplancq/dev-tools/commit/3d365c298ff1ed1abe1516892a52887724b1da7e))
|
|
8
|
+
* **react-template:** add gitignore ([32f453d](https://github.com/pplancq/dev-tools/commit/32f453df6ee2f2c3ef270f4e95b8800f4a803d4e))
|
|
9
|
+
* **react-template:** add linter ([7301361](https://github.com/pplancq/dev-tools/commit/7301361a019926d7c763c74e8f12689046e71e4b))
|
|
10
|
+
* **react-template:** add react-hook-form with demo ([2a05997](https://github.com/pplancq/dev-tools/commit/2a05997bffa14e8fb58960857cbd99ee36df48b3))
|
|
11
|
+
* **react-template:** add react-query with demo ([a205809](https://github.com/pplancq/dev-tools/commit/a205809b1c1ca08d57f36339d09092ccba852d9c))
|
|
12
|
+
* **react-template:** add react-router ([596c3eb](https://github.com/pplancq/dev-tools/commit/596c3eb96accfba3fb08dc9ee487f88030fff0d1))
|
|
13
|
+
* **react-template:** add vitest ([ebafa20](https://github.com/pplancq/dev-tools/commit/ebafa20e3bee41c1df6a56811d64be63e55d477d))
|
|
14
|
+
* **react-template:** init starter with react App ([712d2f9](https://github.com/pplancq/dev-tools/commit/712d2f9e9ef80bc466229ec1c4937dc77e1eb1fa))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
|
|
20
|
+
* **@pplancq/babel-config:** upgraded to 1.0.0
|
|
21
|
+
* **@pplancq/commitlint-config:** upgraded to 1.0.0
|
|
22
|
+
* **@pplancq/eslint-config:** upgraded to 1.0.0
|
|
23
|
+
* **@pplancq/postcss-config:** upgraded to 1.0.0
|
|
24
|
+
* **@pplancq/prettier-config:** upgraded to 1.0.0
|
|
25
|
+
* **@pplancq/stylelint-config:** upgraded to 1.0.0
|
|
26
|
+
* **@pplancq/webpack-config:** upgraded to 1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present pplancq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
## 🚀 <span id="getting-started">Getting Started</span>
|
|
2
|
+
|
|
3
|
+
This project was bootstrapped with [@pplancq/create-react-app](https://github.com/pplancq/dev-tools/tree/main/packages/create-react-app).
|
|
4
|
+
|
|
5
|
+
### 🧾 Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js : [Download here](https://nodejs.org/) (Preferably, use [Volta](https://volta.sh/))
|
|
8
|
+
- npm (Node Package Manager)
|
|
9
|
+
|
|
10
|
+
### 🛠️ Installation
|
|
11
|
+
|
|
12
|
+
1. Clone this repository to your computer.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/votre-utilisateur/mon-projet-awesome.git mon-projet
|
|
16
|
+
cd mon-projet
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Install dependencies.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
In the project directory, you can run the following commands:
|
|
27
|
+
|
|
28
|
+
### `npm start`
|
|
29
|
+
|
|
30
|
+
Launches the application in development mode.
|
|
31
|
+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
|
32
|
+
|
|
33
|
+
The page will reload automatically if you make edits.
|
|
34
|
+
|
|
35
|
+
You will also see lint errors in the console.
|
|
36
|
+
|
|
37
|
+
### `npm test`
|
|
38
|
+
|
|
39
|
+
Launches the test runner in interactive mode.
|
|
40
|
+
|
|
41
|
+
### `npm run build`
|
|
42
|
+
|
|
43
|
+
Builds the application for production in the `build` folder.
|
|
44
|
+
|
|
45
|
+
It correctly bundles React in production mode and optimizes the build for better performance.
|
|
46
|
+
|
|
47
|
+
The build is minified, and the filenames include hashes.
|
|
48
|
+
Your application is ready to be deployed!
|
|
49
|
+
|
|
50
|
+
### `npm run lint`
|
|
51
|
+
|
|
52
|
+
Allows you to see lint errors without fixing them. This command initiates the linting process with three linters: **eslint**, **stylelint**, and **tsc** (TypeScript Compiler).
|
|
53
|
+
|
|
54
|
+
### `npm run eslint:fix`
|
|
55
|
+
|
|
56
|
+
Allows you to fix eslint errors.
|
|
57
|
+
|
|
58
|
+
### `npm run stylelint:fix`
|
|
59
|
+
|
|
60
|
+
Allows you to fix style lint errors.
|
|
61
|
+
|
|
62
|
+
## 🏗 <span id="project-structure">Project Structure</span>
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
📁 my-projet
|
|
66
|
+
├── 📁 src
|
|
67
|
+
│ ├── 📁 ui
|
|
68
|
+
│ │ ├── 📁 Atoms
|
|
69
|
+
│ │ ├── 📁 Molecules
|
|
70
|
+
│ │ ├── 📁 Organisms
|
|
71
|
+
│ │ ├── 📁 Templates
|
|
72
|
+
│ ├── 📁 components
|
|
73
|
+
│ │ ├── 📁 formFields
|
|
74
|
+
│ ├── 📁 providers
|
|
75
|
+
│ ├── 📁 pages
|
|
76
|
+
│ │ ├── 📁 homePage
|
|
77
|
+
│ │ ├── 📁 page1
|
|
78
|
+
│ │ │ ├── 📁 sousPage1
|
|
79
|
+
│ ├── 📁 forms
|
|
80
|
+
│ │ ├── 📁 hooks
|
|
81
|
+
│ │ ├── 📁 risk
|
|
82
|
+
│ │ ├── 📁 contact
|
|
83
|
+
│ ├── 📁 hooks
|
|
84
|
+
│ │ ├── 📁 api
|
|
85
|
+
│ │ ├── 📁 useCustom1
|
|
86
|
+
│ │ ├── 📁 useCustom2
|
|
87
|
+
│ ├── 📁 utils
|
|
88
|
+
│ │ ├── 📁 services
|
|
89
|
+
│ │ ├── 📁 tests
|
|
90
|
+
│ │ ├── 📁 helpers
|
|
91
|
+
│ ├── 📁 routing
|
|
92
|
+
│ ├── 📁 api
|
|
93
|
+
│ ├── 📁 types
|
|
94
|
+
│ ├── 📁 assets
|
|
95
|
+
│ ├── 📁 config
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 📚 Folder Definitions
|
|
99
|
+
|
|
100
|
+
Here is the project folder structure, with a brief description of each folder:
|
|
101
|
+
|
|
102
|
+
| Folder | Description|
|
|
103
|
+
| -------- | -------- |
|
|
104
|
+
| **📁 src** | ***The root directory of the application source code.***
|
|
105
|
+
| [**📁 ui**](./src/ui/README.md) | Contains reusable components designed to be used across projects. Components can be basic (Atoms), more complex (Molecules), higher-level components (Organisms), or page templates (Templates). |
|
|
106
|
+
| [**📁 components**](./src/components/README.md) | Contains project-specific reusable components, for example, form components using React Hook Form. |
|
|
107
|
+
| [**📁 providers**](./src/providers/README.md) | This folder contains context providers or custom hooks that provide data to the entire application. |
|
|
108
|
+
| [**📁 pages**](./src/pages/README.md) | Contains the pages of the application. Each subfolder represents a distinct page or view of the application. |
|
|
109
|
+
| [**📁 forms**](./src/forms/README.md) | Contains the forms of the application, grouping hooks related to forms. |
|
|
110
|
+
| [**📁 hooks**](./src/hooks/README.md) | Includes custom hooks for various application features, such as API calls with React Query. |
|
|
111
|
+
| [**📁 utils**](./src/utils/README.md) | Contains utilities and services such as test files, utility functions, etc. |
|
|
112
|
+
| [**📁 routing**](./src/routing/README.md) | This folder is intended for native API calls using the `fetch`. function. These calls are essential for fetching real-time data from external sources, such as remote servers or web services. |
|
|
113
|
+
| [**📁 types**](./src/types/README.md) | Provides TypeScript type definitions to enhance the robustness of your code. |
|
|
114
|
+
| [**📁 assets**](./src/assets/README.md) | Contains static files such as images, fonts, etc., used in the application. |
|
|
115
|
+
| [**📁 config**](./src/config/README.md) | Contains all the important configurations and utilities needed for our project. |
|
|
116
|
+
|
|
117
|
+
## 🏗 <span id="component-structure">React Component Structure</span>
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
📁 ComponentName
|
|
121
|
+
├── 📁 __tests__
|
|
122
|
+
│ ├── 📄 ComponentName.feature
|
|
123
|
+
│ ├── 📄 ComponantName.steps.tsx
|
|
124
|
+
│ ├── 📄 ComponentName.test.tsx
|
|
125
|
+
├── 📄 index.ts
|
|
126
|
+
├── 📄 ComponentName.tsx
|
|
127
|
+
├── 📄 ComponentName.hook.ts
|
|
128
|
+
├── 📄 ComponentName.module.scss
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 📚 Files Definitions
|
|
132
|
+
|
|
133
|
+
#### 📁 **tests**
|
|
134
|
+
|
|
135
|
+
The tests folder may contain unit tests specific to the package. The idea is to mainly test through functional tests. However, in some cases, it may be useful to test a component in isolation (for example, when developing a package reused between multiple projects).
|
|
136
|
+
|
|
137
|
+
#### 📄 index.ts
|
|
138
|
+
|
|
139
|
+
This file allows exposing the component and avoids having to redo imports if the file implementing the component changes its name.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
export { ComponentName } from './ComponentName';
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
This will allow importing a component like this:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { ComponentName } from '@Front/ComponentName';
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### 📄 ComponentName.tsx
|
|
152
|
+
|
|
153
|
+
Each file contains a single exported component. It will essentially contain the view and very little logic. If the component needs more logic, it is advisable to use a custom hook.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
type ComponentNameProps = {
|
|
157
|
+
foo: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const ComponentName = ({ foo }) => {
|
|
161
|
+
return (
|
|
162
|
+
<div>{foo}</div>
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### 📄 ComponentName.hook.ts
|
|
168
|
+
|
|
169
|
+
A custom hook allows moving the logic specific to a component outside of its view.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
export type UseComponentNameProps = {
|
|
173
|
+
foo: string;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type UseComponentNameReturn = {
|
|
177
|
+
bar: string;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export const useComponentName = ({ foo }: UseComponentNameProps): UseComponentNameReturn => {
|
|
181
|
+
return {
|
|
182
|
+
bar: foo,
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### 📄 ComponentName.module.scss
|
|
189
|
+
|
|
190
|
+
The style specific to the component will be written in module form. This allows scoping the style of the component without overriding global style.
|
|
191
|
+
|
|
192
|
+
```css
|
|
193
|
+
.root {
|
|
194
|
+
background-color: red;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import classes from './ComponentName.module.scss'
|
|
201
|
+
|
|
202
|
+
export const ComponentName = () => {
|
|
203
|
+
return (
|
|
204
|
+
<div className={classes.root}>Foo</div>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
### ❗ Naming Conventions
|
|
209
|
+
|
|
210
|
+
==> Component names, file names, and folder names should follow the **PascalCase** convention.
|
|
211
|
+
|
|
212
|
+
## 🙇 <span id="learnmore">Learn More</span>
|
|
213
|
+
|
|
214
|
+
- React & co
|
|
215
|
+
- [React Documentation.](https://react.dev/).
|
|
216
|
+
- [React Router Documentation.](https://reactrouter.com/en/main).
|
|
217
|
+
- [React Query Documentation.](https://tanstack.com/query/v3/).
|
|
218
|
+
- [React Hook Form Documentation.](https://react-hook-form.com/).
|
|
219
|
+
- Test
|
|
220
|
+
- [Vitest Documentation.](https://vitest.dev/).
|
|
221
|
+
- [Testing Library Documentation.](https://testing-library.com/).
|
package/_gitignore
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.js
|
|
7
|
+
|
|
8
|
+
# testing
|
|
9
|
+
/coverage
|
|
10
|
+
|
|
11
|
+
# production
|
|
12
|
+
/build
|
|
13
|
+
/test-report.xml
|
|
14
|
+
|
|
15
|
+
# misc
|
|
16
|
+
.DS_Store
|
|
17
|
+
.env.local
|
|
18
|
+
.env.development.local
|
|
19
|
+
.env.test.local
|
|
20
|
+
.env.production.local
|
|
21
|
+
|
|
22
|
+
npm-debug.log*
|
|
23
|
+
yarn-debug.log*
|
|
24
|
+
yarn-error.log*
|
|
25
|
+
|
|
26
|
+
/.idea
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pplancq/react-template",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "react template",
|
|
6
|
+
"author": "pplancq <paul.plancq@outlook.fr>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/pplancq/dev-tools",
|
|
10
|
+
"directory": "packages/webpack-config"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "webpack serve",
|
|
14
|
+
"build": "webpack --mode production",
|
|
15
|
+
"test": "vitest",
|
|
16
|
+
"test:ci": "vitest run --coverage",
|
|
17
|
+
"lint": "concurrently --prefix-colors magenta,cyan,green \"npm:eslint\" \"npm:tsc\" \"npm:stylelint\"",
|
|
18
|
+
"eslint": "eslint src --ext js,jsx,ts,tsx",
|
|
19
|
+
"eslint:fix": "eslint src --ext js,jsx,ts,tsx --fix",
|
|
20
|
+
"stylelint": "stylelint \"src/**/*.{scss,css}\"",
|
|
21
|
+
"stylelint:fix": "stylelint \"src**/*.{scss,css}\" --fix",
|
|
22
|
+
"tsc": "tsc --noEmit",
|
|
23
|
+
"_prepare": "husky"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/pplancq/dev-tools/issues"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react",
|
|
30
|
+
"template"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@hookform/resolvers": "^3.3.2",
|
|
34
|
+
"react": "^18.2.0",
|
|
35
|
+
"react-dom": "^18.2.0",
|
|
36
|
+
"react-hook-form": "^7.49.2",
|
|
37
|
+
"react-query": "^3.39.3",
|
|
38
|
+
"react-router-dom": "^6.21.0",
|
|
39
|
+
"yup": "^1.3.3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@pplancq/babel-config": "1.0.0",
|
|
43
|
+
"@pplancq/commitlint-config": "1.0.0",
|
|
44
|
+
"@pplancq/eslint-config": "1.0.0",
|
|
45
|
+
"@pplancq/postcss-config": "1.0.0",
|
|
46
|
+
"@pplancq/prettier-config": "1.0.0",
|
|
47
|
+
"@pplancq/stylelint-config": "1.0.0",
|
|
48
|
+
"@pplancq/webpack-config": "1.0.0",
|
|
49
|
+
"@svgr/webpack": "^8.1.0",
|
|
50
|
+
"@testing-library/jest-dom": "^6.1.5",
|
|
51
|
+
"@testing-library/react": "^14.1.2",
|
|
52
|
+
"@testing-library/user-event": "^14.5.1",
|
|
53
|
+
"@types/react": "^18.2.45",
|
|
54
|
+
"@types/react-dom": "^18.2.18",
|
|
55
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
56
|
+
"@vitest/coverage-v8": "^1.0.4",
|
|
57
|
+
"concurrently": "^8.2.2",
|
|
58
|
+
"husky": "^9.0.7",
|
|
59
|
+
"jsdom": "^24.0.0",
|
|
60
|
+
"lint-staged": "^15.2.0",
|
|
61
|
+
"tsc-files": "^1.1.4",
|
|
62
|
+
"typescript": "^5.3.3",
|
|
63
|
+
"vite-plugin-svgr": "^4.2.0",
|
|
64
|
+
"vite-tsconfig-paths": "^4.2.2",
|
|
65
|
+
"vitest": "^1.0.4",
|
|
66
|
+
"vitest-sonar-reporter": "^1.0.0"
|
|
67
|
+
},
|
|
68
|
+
"volta": {
|
|
69
|
+
"node": "20.10.0",
|
|
70
|
+
"npm": "10.2.5"
|
|
71
|
+
},
|
|
72
|
+
"browserslist": {
|
|
73
|
+
"production": [
|
|
74
|
+
">0.2%",
|
|
75
|
+
"not dead",
|
|
76
|
+
"not op_mini all"
|
|
77
|
+
],
|
|
78
|
+
"development": [
|
|
79
|
+
"last 1 chrome version",
|
|
80
|
+
"last 1 firefox version",
|
|
81
|
+
"last 1 safari version"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="fr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="/favicon.ico" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<meta
|
|
8
|
+
name="description"
|
|
9
|
+
content="Web site created using react-template"
|
|
10
|
+
/>
|
|
11
|
+
<title>React App</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
15
|
+
<app-react></app-react>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# 📁 api
|
|
2
|
+
|
|
3
|
+
The "api" folder is designed to handle calls to native APIs using the fetch function. These calls are essential for retrieving real-time data from external sources, such as remote servers or web services.
|
|
4
|
+
## 📑 Table of Contents
|
|
5
|
+
- [Folder Organization](#folder-organization)
|
|
6
|
+
- [Usage](#usage)
|
|
7
|
+
- [Error Handling](#error-handling)
|
|
8
|
+
- [Security](#security)
|
|
9
|
+
- [Documentation](#documentation)
|
|
10
|
+
- [Testing](#testing)
|
|
11
|
+
- [Best Practice](#best-practice)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## <span id="folder-organization">Folder Organization</span>
|
|
15
|
+
|
|
16
|
+
The "api" folder can be organized as follows :
|
|
17
|
+
|
|
18
|
+
1. **API Endpoints** : Create a separate file for each API you are calling. For example, if you have a user management API and a data retrieval API, you can have the files `users.ts` and `data.ts` to handle these respective calls.
|
|
19
|
+
|
|
20
|
+
2. **Call Functions** : Inside each API file, define dedicated functions to make `fetch` requests to the corresponding endpoints. These functions can also include handling responses and errors.
|
|
21
|
+
|
|
22
|
+
## <span id="usage">🧑🏻💻 Usage</span>
|
|
23
|
+
|
|
24
|
+
When you need to make a call to a native API, import the appropriate function from the "api" folder into your code. For example:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { getUsers } from '@Front/api/users';
|
|
28
|
+
|
|
29
|
+
const users = getUsers();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## <span id="error-handling">Error Handling</span>
|
|
33
|
+
|
|
34
|
+
Ensure proper error handling in your API call functions. You can use error handling mechanisms such as promises or `try/catch` to capture and handle potential errors when making API calls.
|
|
35
|
+
|
|
36
|
+
## <span id="security">Security</span>
|
|
37
|
+
|
|
38
|
+
Be mindful of security when interacting with external APIs. Avoid storing sensitive information, such as API keys, directly in your source code. Use environment variables or external configuration files to manage this sensitive information securely.
|
|
39
|
+
|
|
40
|
+
## <span id="documentation">Documentation</span>
|
|
41
|
+
|
|
42
|
+
Document each API call function, specifying expected parameters, possible responses, and any relevant information about the API itself.
|
|
43
|
+
|
|
44
|
+
## <span id="testing">Testing</span>
|
|
45
|
+
|
|
46
|
+
Whenever possible, write unit tests to validate the behavior of API call functions. This will ensure that API calls work correctly and quickly detect potential issues.
|
|
47
|
+
|
|
48
|
+
## <span id="best-practice">🎖️ Best Practice</span>
|
|
49
|
+
|
|
50
|
+
It is recommended to implement a custom fetch function that serves as an enhancement or override of the default fetch function. This can be particularly useful for incorporating common configurations, such as adding headers like an API token.
|
|
51
|
+
|
|
52
|
+
Consider the following example of a custom fetch function :
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// Custom fetch function with common configurations
|
|
56
|
+
export const fetchApi = (uri, options) => {
|
|
57
|
+
const headers = new Headers(options.headers ?? []);
|
|
58
|
+
headers.append('x-api-key', '<token-api>');
|
|
59
|
+
|
|
60
|
+
return fetch(uri, { ...options, headers });
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In this example, the fetchApi function extends the default fetch function by automatically including an API token in the request header. This practice helps centralize common configurations and promotes consistency across your application.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Users } from '@Front/types/demoApi';
|
|
2
|
+
|
|
3
|
+
const data: Users = [
|
|
4
|
+
{
|
|
5
|
+
id: 1,
|
|
6
|
+
firstName: 'John',
|
|
7
|
+
lastName: 'Doe',
|
|
8
|
+
age: 30,
|
|
9
|
+
email: 'john.doe@example.com',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: 2,
|
|
13
|
+
firstName: 'Jane',
|
|
14
|
+
lastName: 'Smith',
|
|
15
|
+
age: 25,
|
|
16
|
+
email: 'jane.smith@example.com',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 3,
|
|
20
|
+
firstName: 'Alice',
|
|
21
|
+
lastName: 'Johnson',
|
|
22
|
+
age: 28,
|
|
23
|
+
email: 'alice.johnson@example.com',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 4,
|
|
27
|
+
firstName: 'Bob',
|
|
28
|
+
lastName: 'Brown',
|
|
29
|
+
age: 35,
|
|
30
|
+
email: 'bob.brown@example.com',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export const fetchDemoApi = async (): Promise<Users> => {
|
|
35
|
+
return new Promise<Users>((resolve, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
resolve(data);
|
|
39
|
+
}, 3000);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
reject(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# 📁 assets
|
|
2
|
+
|
|
3
|
+
The "assets" folder is a commonly used directory in a React application to store static resources such as images, CSS files, fonts, JSON data files, icons, and other non-JavaScript files used in your application. These resources are typically needed to style and customize the user interface of your application.
|
|
4
|
+
|
|
5
|
+
## 📑 Table of Contents
|
|
6
|
+
- [Why Use an "assets" Folder](#folder-organization)
|
|
7
|
+
- [Usage Example](#usage)
|
|
8
|
+
- [Best Practice](#best-practice)
|
|
9
|
+
|
|
10
|
+
## <span id="folder-organization">Why Use an "assets" Folder?</span>
|
|
11
|
+
|
|
12
|
+
1. **Organization** : By storing your static resources in a separate folder named "assets," you maintain a cleaner and more organized project structure. This clearly separates static content from JavaScript files.
|
|
13
|
+
|
|
14
|
+
2. **Ease of Access** : Files in the "assets" folder can be easily referenced in your code using relative paths. This simplifies the inclusion of images, CSS, fonts, and other resources in your React components.
|
|
15
|
+
|
|
16
|
+
3. **Performance Optimization** : By storing static resources like images in an "assets" folder, you can optimize these files for better performance, for example, by using image compression tools.
|
|
17
|
+
|
|
18
|
+
## <span id="usage">🧑🏻💻 Usage Example </span>
|
|
19
|
+
|
|
20
|
+
To use an image stored in the "assets" folder, you can reference its relative path in your JavaScript or JSX code like this:
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import logo from '@Front/assets/images/logo.png'
|
|
24
|
+
|
|
25
|
+
export const App = () => {
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
<img src={logo} alt="Logo" />
|
|
29
|
+
{/* ... other elements of the application */}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## <span id="best-practice">🎖️ Best Practice</span>
|
|
36
|
+
|
|
37
|
+
When it comes to styling and managing assets, adopting the following practices can enhance maintainability and structure in your project:
|
|
38
|
+
|
|
39
|
+
### - Global CSS Rules
|
|
40
|
+
Define all global CSS rules, such as resets, fonts, and general styling, in a centralized stylesheet (in the css folder under the assets ).
|
|
41
|
+
|
|
42
|
+
This ensures consistency across your entire application.
|
|
43
|
+
|
|
44
|
+
### - CSS Modules
|
|
45
|
+
For component-specific styles, leverage CSS Modules to encapsulate styles within the component scope.
|
|
46
|
+
|
|
47
|
+
This helps prevent unintentional styling conflicts and promotes a modular approach to styling.
|
|
48
|
+
|
|
49
|
+
----------
|
|
50
|
+
***By adhering to these practices, you create a clear separation between global styles and component-specific styles, making your codebase more maintainable and scalable.***
|
|
51
|
+
|