Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 7257dc1

Browse files
committed
chore: update documentation
Split off development docs from README.md to DEVELOPMENT.md.
1 parent 710b7bf commit 7257dc1

File tree

3 files changed

+91
-118
lines changed

3 files changed

+91
-118
lines changed

DEVELOPMENT.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Development
2+
3+
Package management requires latest (stable) versions of yarn and node.
4+
5+
## Components
6+
7+
The React components are kept in one folder per component, containing an
8+
`index.tsx` file. The former contains the actual component implementation, while
9+
the latter documents and showcases the component, where you can see and interact
10+
with the component.
11+
12+
To create a new component:
13+
14+
- create a folder with the component name
15+
- add an `index.tsx` file which exports the component and any other
16+
related components and/or utilities (types, hooks, etc...). Do _not_
17+
create any default exports
18+
19+
## Icons
20+
21+
To add new icons to the library, put the SVG-file into the `packages/icons/src`
22+
folder and execute `yarn build:icons`. The command re-generates `tsx` files for
23+
all SVGs in the `packages/icons/src/__generated__` together with a barrel-file
24+
to export them all. The name of the generated icon is Pascal-cased and
25+
post-fixed with `Icon`. Note that some `fill` and `stroke` colors might have to
26+
be removed or replaced in the original SVG with the value `currentColor` in
27+
order for the theming to work properly.
28+
29+
### How to optimize svg
30+
31+
1. Make sure that the svg file has only **one** path between `<svg>` tag and that its viewBox is `24px` box.
32+
33+
An example:
34+
35+
```
36+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
37+
<path d="M17 13h-4v4a1 1 0 01-2 0v-4H7a1 1 0 010-2h4V7a1 1 0 012 0v4h4a1 1 0 010 2z" />
38+
</svg>
39+
```
40+
41+
2. If it satisfies **1**, go to **10**.
42+
If not, you should optimize the file with all following steps.
43+
3. Remove extra tag or unnecessary styles/attributes in [SVGOMG - SVGO's Missing GUI](https://jakearchibald.github.io/svgomg/).
44+
4. Open the file in [Inkscape](https://inkscape.org/).
45+
5. Ungroup the paths if they are grouped.
46+
6. Remove extra path and rect.
47+
7. Change stroke to path. (Select the element + F2)
48+
8. Select all paths and combine all paths. (Combine or Union)
49+
9. Export it as optimized svg.
50+
10. Copy the code and paste it on input in [Playground - SVGR](https://react-svgr.com/playground/).
51+
11. Copy the `<path>` on the output and replace with the original `<path>`.
52+
12. Run `yarn build:icons` and check the icon on docs.
53+
54+
## Performance - best practices
55+
56+
### General memoization
57+
58+
[Link to React Docs](https://reactjs.org/docs/react-api.html#reactmemo)
59+
60+
_If your function component renders the same result given the same props, you
61+
can wrap it in a call to React.memo for a performance boost in some cases by
62+
memoizing the result. This means that React will skip rendering the component,
63+
and reuse the last rendered result._
64+
65+
**Caveat: Mounting the component in the DOM takes longer, thus this method is
66+
not always an good idea. Use where the component might re-render alot due
67+
changes in parent, etc.**
68+
69+
### Styled-components - What to know
70+
71+
1. `Styled-components` are heavy, they take quite some time to mount.
72+
2. When performance is slow due to large number of components & DOM elements,
73+
create custom, light and fast, sub components adapted for their intended
74+
context of use. (i.e not having unused logic/code in it)
75+
3. The best component is the non-existing. Can the contents be mounted inside
76+
another already existing component?
77+
78+
### CSS
79+
80+
[CSS/JS - Performance 101](https://www.viget.com/articles/animation-performance-101-browser-under-the-hood/)
81+
82+
CSS is fast, animating anything but `opacity` & `transform` is slow.
83+
84+
Replacing `.svg` with pure CSS is faster.

README.md

Lines changed: 5 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ yarn add practical-react-components-core
1111
This contains all the core components. All the icons are located in a separate
1212
`practical-react-components-icons` package.
1313

14-
### Dependencies
14+
## Dependencies
1515

1616
Practical react components is dependent on some packages, in addition to `react`
17-
and `react-dom`, that needs to be installed for it to work. Make sure the
17+
and `react-dom`, that need to be installed for it to work. Make sure the
1818
following packages are installed:
1919

2020
```shell
@@ -30,7 +30,7 @@ the following packages are installed:
3030
yarn add formik
3131
```
3232

33-
### Typescript (only if using typescript)
33+
### Typescript
3434

3535
Install additional typings:
3636

@@ -62,7 +62,7 @@ styled components.
6262
Make sure this file is included in your `tsconfig.json` files, e.g.
6363
`"include": ["src/styled-components.d.ts", "./src/index.ts"]`.
6464

65-
### Electron (only if using electron)
65+
### Electron
6666

6767
If you are using Practical react components with an Electron app you might have
6868
to add the following lines in the root of you `package.json` file.
@@ -115,115 +115,4 @@ export const App: React.FC = () => {
115115
```
116116

117117
For more information on what components are available and how to use them
118-
please visit the [documentation](https://github.com/AxisCommunications/practical-react-components).
119-
120-
## Components
121-
122-
The React components are kept in one folder per component, containing an
123-
`index.tsx` and `index.mdx` file. The former contains the actual component
124-
implementation, while the latter documents and showcases the component, where
125-
you can see and interact with the component.
126-
127-
To create a new component:
128-
129-
- create a folder with the component name
130-
- add an `index.tsx` file which exports the component and any other
131-
related components and/or utilities (types, hooks, etc...). Do _not_
132-
create any default exports
133-
134-
## Icons
135-
136-
To add new icons to the library, put the SVG-file into the `packages/icons/src`
137-
folder and execute `yarn build:icons`. The command re-generates `tsx` files for
138-
all SVGs in the `packages/icons/src/__generated__` together with a barrel-file
139-
to export them all. The name of the generated icon is Pascal-cased and
140-
post-fixed with `Icon`. Note that some `fill` and `stroke` colors might have to
141-
be removed or replaced in the original SVG with the value `currentColor` in
142-
order for the theming to work properly.
143-
144-
### How to optimize svg
145-
146-
1. Make sure that the svg file has only **one** path between `<svg>` tag and that its viewBox is `24px` box.
147-
148-
An example:
149-
150-
```
151-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
152-
<path d="M17 13h-4v4a1 1 0 01-2 0v-4H7a1 1 0 010-2h4V7a1 1 0 012 0v4h4a1 1 0 010 2z" />
153-
</svg>
154-
```
155-
156-
2. If it satisfies **1**, go to **10**.
157-
If not, you should optimize the file with all following steps.
158-
3. Remove extra tag or unnecessary styles/attributes in [SVGOMG - SVGO's Missing GUI](https://jakearchibald.github.io/svgomg/).
159-
4. Open the file in [Inkscape](https://inkscape.org/).
160-
5. Ungroup the paths if they are grouped.
161-
6. Remove extra path and rect.
162-
7. Change stroke to path. (Select the element + F2)
163-
8. Select all paths and combine all paths. (Combine or Union)
164-
9. Export it as optimized svg.
165-
10. Copy the code and paste it on input in [Playground - SVGR](https://react-svgr.com/playground/).
166-
11. Copy the `<path>` on the output and replace with the original `<path>`.
167-
12. Run `yarn build:icons` and check the icon on docs.
168-
169-
## Performance - best practices
170-
171-
### General memoization
172-
173-
[Link to React Docs](https://reactjs.org/docs/react-api.html#reactmemo)
174-
175-
_If your function component renders the same result given the same props, you
176-
can wrap it in a call to React.memo for a performance boost in some cases by
177-
memoizing the result. This means that React will skip rendering the component,
178-
and reuse the last rendered result._
179-
180-
**Caveat: Mounting the component in the DOM takes longer, thus this method is
181-
not always an good idea. Use where the component might re-render alot due
182-
changes in parent, etc.**
183-
184-
### Styled-components - What to know
185-
186-
1. `Styled-components` are heavy, they take quite some time to mount.
187-
2. When performance is slow due to large number of components & DOM elements,
188-
create custom, light and fast, sub components adapted for their intended
189-
context of use. (i.e not having unused logic/code in it)
190-
3. The best component is the non-existing. Can the contents be mounted inside
191-
another already existing component?
192-
193-
### CSS
194-
195-
[CSS/JS - Performance 101](https://www.viget.com/articles/animation-performance-101-browser-under-the-hood/)
196-
197-
CSS is fast, animating anything but `opacity` & `transform` is slow.
198-
199-
Replacing `.svg` with pure CSS is faster.
200-
201-
## Release
202-
203-
Instructions on how to do a new release for the main branch.
204-
205-
1. Make sure you have permissions to push to main
206-
2. Get latest main
207-
```shell
208-
git checkout main
209-
git pull --ff-only upstream main
210-
```
211-
3. Get all tags
212-
```shell
213-
git fetch --all --tags
214-
```
215-
4. Create a new version commit
216-
```shell
217-
yarn release [increment]
218-
```
219-
where `increment` is a semver specification of the increment you want
220-
for the release (`prerelease` is used if nothing is specified).
221-
5. Check the commit of the newly generated tag and make sure only the changes
222-
between latest tag and this one are included in the CHANGELOG.md file.
223-
6. Push new version to main
224-
```shell
225-
git push upstream main <new_tag>
226-
```
227-
7. Copy changes from CHANGELOG.md file, add them for your tag on **tags**
228-
page and make sure that changes are displayed on the **releases** page.
229-
8. Done
118+
please visit the [documentation](https://axiscommunications.github.io/practical-react-components).

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"homepage": "https://github.com/AxisCommunications/practical-react-components",
77
"license": "MIT",
88
"engines": {
9-
"node": ">=10.11.0",
10-
"yarn": ">=1.12.3"
9+
"node": ">=14.0.0",
10+
"yarn": ">=1.21.1"
1111
},
1212
"workspaces": [
1313
"packages/*"

0 commit comments

Comments
 (0)