@guardian/interactive-component-library 0.1.0-alpha.10
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/LICENSE +39 -0
- package/README.md +103 -0
- package/dist/interactive-component-library.js +2979 -0
- package/dist/interactive-component-library.js.map +1 -0
- package/dist/interactive-component-library.umd.cjs +2977 -0
- package/dist/interactive-component-library.umd.cjs.map +1 -0
- package/dist/style.css +2054 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Copyright (c) [2024] Guardian News and Media
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
The repository is based on this template: https://github.com/IgnacioNMiranda/vite-component-library-template. License included here:
|
|
18
|
+
|
|
19
|
+
MIT License
|
|
20
|
+
|
|
21
|
+
Copyright (c) [2023] [Ignacio Andrés Miranda Figueroa]
|
|
22
|
+
|
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
25
|
+
in the Software without restriction, including without limitation the rights
|
|
26
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
28
|
+
furnished to do so, subject to the following conditions:
|
|
29
|
+
|
|
30
|
+
The above copyright notice and this permission notice shall be included in all
|
|
31
|
+
copies or substantial portions of the Software.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# `@guardian/interactive-component-library`
|
|
2
|
+
|
|
3
|
+
A set of reusable components for use in interactive pages, written in Preact using [Atomic Design](https://bradfrost.com/blog/post/atomic-web-design/) principles.
|
|
4
|
+
|
|
5
|
+
## Install the component library in a new client project
|
|
6
|
+
|
|
7
|
+
From [Github Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry):
|
|
8
|
+
|
|
9
|
+
1. [Create a personal access token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) with `read:packages` scope.
|
|
10
|
+
2. Create a file called `.npmrc` in the root of your new project and add the following:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
@guardian:registry=https://npm.pkg.github.com
|
|
14
|
+
//npm.pkg.github.com/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
3. Install using npm:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm i @guardian/interactive-component-library
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Contributing to this repository
|
|
24
|
+
|
|
25
|
+
> Building the project requires Node v16.18.1 or higher.
|
|
26
|
+
|
|
27
|
+
1. Clone this repository
|
|
28
|
+
2. Run `corepack enable` to enable pnpm
|
|
29
|
+
3. Install dependencies with `pnpm i`
|
|
30
|
+
4. Run `pnpm dev` to start the local Storybook server
|
|
31
|
+
|
|
32
|
+
### Atomic design
|
|
33
|
+
|
|
34
|
+
The component library is structured according to [Atomic Design](https://bradfrost.com/blog/post/atomic-web-design/) principles, using the bottom three levels.
|
|
35
|
+
|
|
36
|
+
1. Particles (renamed from `atoms` for obvious reasons)
|
|
37
|
+
2. Molecules
|
|
38
|
+
3. Organisms
|
|
39
|
+
|
|
40
|
+
Particles are the lowest level components that form the building blocks for everything else, e.g. a Button. Molecules represent more complex components (e.g. a Table) and often depend on particle components. Organisms combine the previous two levels into distinct sections of an interactive page, e.g. KeySeats.
|
|
41
|
+
|
|
42
|
+
Folders use the same naming structure, with `particles`, `molecules` and `organisms` folders in `src/lib/components`, to distinguish between the three different levels.
|
|
43
|
+
|
|
44
|
+
### Adding a new component
|
|
45
|
+
|
|
46
|
+
Create a folder for your new component in the appropriate directory. The name of the folder should be the name of your component in [Kebab case](https://developer.mozilla.org/en-US/docs/Glossary/Kebab_case), i.e. `src/lib/components/particles/my-new-component`.
|
|
47
|
+
|
|
48
|
+
The folder should contain the following:
|
|
49
|
+
|
|
50
|
+
- `index.jsx` containing the code for the actual component
|
|
51
|
+
- `[component-name].stories.jsx` containing examples of how to use the component, written as [Storybook stories](https://storybook.js.org/docs/writing-stories)
|
|
52
|
+
- `docs.mdx` (optional) additional documentation for the component in Storybook
|
|
53
|
+
|
|
54
|
+
### Developing and testing locally
|
|
55
|
+
|
|
56
|
+
During development, you'll often want to see how a component looks in the interactive page that you're working on, without rebuilding and publishing a new version of the component library. To facilitate this workflow, we use [npm-link](https://docs.npmjs.com/cli/v10/commands/npm-link).
|
|
57
|
+
|
|
58
|
+
Here's how to set that up:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
cd ~/projects/interactive-component-library # go into the package directory
|
|
62
|
+
npm link # creates global link
|
|
63
|
+
cd ~/projects/interactive-project # go into your project directory
|
|
64
|
+
npm link @guardian/interactive-component-library # link-install the package
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
After you've done that, run `pnpm build:lib:watch` to package the library and rebuild on file changes.
|
|
68
|
+
|
|
69
|
+
To revert back to the version specified in your project‘s `package.json`:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
npm uninstall --no-save @guardian/interactive-component-library && npm install
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Publishing a new version
|
|
76
|
+
|
|
77
|
+
To publish a new version of the component library, follow these steps:
|
|
78
|
+
|
|
79
|
+
1. Update the version number in `package.json`
|
|
80
|
+
2. [Create a new release](https://github.com/guardian/interactive-component-library/releases/new) on GitHub (don't forget to write some release notes)
|
|
81
|
+
3. Publishing the release [triggers a workflow](https://github.com/guardian/interactive-component-library/actions) to package the library and publish it to Github Packages. If the publish actions fails, you can also trigger it manually
|
|
82
|
+
|
|
83
|
+
## Scripts
|
|
84
|
+
|
|
85
|
+
Always prepending `pnpm`:
|
|
86
|
+
|
|
87
|
+
- `dev`: Start Storybook for local development
|
|
88
|
+
- `build`: Builds the static storybook project
|
|
89
|
+
- `build:lib`: Builds the component library into the **dist** folder
|
|
90
|
+
- `build:lib:watch`: Same as previous command, but it watches `/src` folder and rebuilds on changes
|
|
91
|
+
|
|
92
|
+
## Testing for dark mode in Storybook
|
|
93
|
+
Use the sun/moon button in the toolbar to switch between light and dark mode.
|
|
94
|
+

|
|
95
|
+

|
|
96
|
+
|
|
97
|
+
Enabling dark mode applies `.ios` and `.dark-mode` classes to the `<body>` element, which in turn renders the story preview with dark mode colours (this behaviour can be customised in `.storybook/preview.scss`).
|
|
98
|
+
|
|
99
|
+
> Note that enabling dark mode using this button does not affect the [`prefers-color-scheme` CSS media feature](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). If your component uses `prefers-color-scheme` directly, you will also need to change your system or browser setting to see that styling take effect.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
[Apache 2.0](LICENSE)
|