@stokr/components-library 3.0.15 → 3.0.16-alpha.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.
Files changed (3) hide show
  1. package/README.md +262 -203
  2. package/dist/index.js +8154 -8002
  3. package/package.json +3 -4
package/README.md CHANGED
@@ -1,203 +1,262 @@
1
- # @stokr/components-library
2
-
3
- React component library for STOKR applications. Includes modals, forms, buttons, tables, and shared styles.
4
-
5
- ## Table of contents
6
-
7
- - [Installation](#installation)
8
- - [How to start](#how-to-start)
9
- - [Configuration](#configuration)
10
- - [Troubleshooting](#troubleshooting)
11
- - [Development & publishing](#development--publishing)
12
-
13
- ---
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @stokr/components-library
19
- ```
20
-
21
- **Peer dependencies** (install in your app if not already present):
22
-
23
- ```bash
24
- npm install react react-dom styled-components react-router-dom
25
- ```
26
-
27
- - **React** 18 or 19
28
- - **styled-components** 6.x
29
- - **react-router-dom** 6.x (required if you use routing-dependent components)
30
-
31
- ---
32
-
33
- ## How to start
34
-
35
- ### 1. Install the package and peers
36
-
37
- ```bash
38
- npm install @stokr/components-library react react-dom styled-components react-router-dom
39
- ```
40
-
41
- ### 2. Wrap your app with a Router (if you use routing)
42
-
43
- Components that use navigation (e.g. `MainMenu`, `LearnMore`, `HeaderHo`) must live inside a React Router:
44
-
45
- ```jsx
46
- // main.jsx or App.jsx
47
- import { BrowserRouter } from 'react-router-dom'
48
- import App from './App'
49
-
50
- root.render(
51
- <BrowserRouter>
52
- <App />
53
- </BrowserRouter>,
54
- )
55
- ```
56
-
57
- ### 3. (Optional) Add Ionicons for icons
58
-
59
- If you use **Modal**, **ConfirmModal**, **BackButton**, **Select**, **InfoIcon**, etc., add the icon styles once at the root:
60
-
61
- ```jsx
62
- import { IoniconsStyles } from '@stokr/components-library'
63
-
64
- function App() {
65
- return (
66
- <>
67
- <IoniconsStyles />
68
- {/* your app */}
69
- </>
70
- )
71
- }
72
- ```
73
-
74
- You can skip this; the library will inject icon styles when you first use a component that needs them.
75
-
76
- ### 4. Import and use components
77
-
78
- ```jsx
79
- import { ConfirmModal, Button } from '@stokr/components-library'
80
-
81
- function MyPage() {
82
- const [open, setOpen] = useState(false)
83
- return (
84
- <>
85
- <Button onClick={() => setOpen(true)}>Open</Button>
86
- <ConfirmModal isOpen={open} onClose={() => setOpen(false)} onConfirm={() => {}} title="Confirm?" />
87
- </>
88
- )
89
- }
90
- ```
91
-
92
- ---
93
-
94
- ## Configuration
95
-
96
- ### Ionicons
97
-
98
- Components such as **Modal**, **ConfirmModal**, **BackButton**, **InfoIcon**, **Select**, **MainMenu**, and **RegisterLiquidSteps** use [Ionicons](http://ionicons.com/). You can enable them in three ways:
99
-
100
- | Approach | When to use |
101
- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
102
- | **Global injection** | Render `<IoniconsStyles />` once at app root. Full icon set, singleton. |
103
- | **No setup** | Don’t render anything; styles inject on first use of an icon component. |
104
- | **CSS import** | Prefer loading via CSS: `import '@stokr/components-library/styles.css'` or `import '@stokr/components-library/ionicons.css'`. |
105
-
106
- **Global injection example:**
107
-
108
- ```jsx
109
- import { IoniconsStyles } from '@stokr/components-library'
110
-
111
- function App() {
112
- return (
113
- <>
114
- <IoniconsStyles />
115
- {/* your routes, layout, etc. */}
116
- </>
117
- )
118
- }
119
- ```
120
-
121
- If you use **Layout**, **GlobalStyle**, or need **Open Sans**, import the full styles once:
122
-
123
- ```js
124
- import '@stokr/components-library/styles.css'
125
- ```
126
-
127
- ### React Router
128
-
129
- Any component that uses `useNavigate()` or routing must be rendered inside a `Router` from `react-router-dom` (e.g. `BrowserRouter`). See [How to start – step 2](#2-wrap-your-app-with-a-router-if-you-use-routing).
130
-
131
- ---
132
-
133
- ## Troubleshooting
134
-
135
- ### "useNavigate() may be used only in the context of a \<Router\> component"
136
-
137
- Wrap your app with a Router:
138
-
139
- ```jsx
140
- import { BrowserRouter } from 'react-router-dom'
141
-
142
- root.render(
143
- <BrowserRouter>
144
- <App />
145
- </BrowserRouter>,
146
- )
147
- ```
148
-
149
- Install the peer dependency: `npm install react-router-dom`
150
-
151
- ### "Invalid hook call" / "Cannot read properties of null (reading 'use')"
152
-
153
- Your app and the library must use the **same** React instance.
154
-
155
- 1. Install peer dependencies:
156
- `npm install react react-dom styled-components`
157
-
158
- 2. **Vite apps** – add dedupe in `vite.config.js` or `vite.config.ts`:
159
-
160
- ```js
161
- export default defineConfig({
162
- resolve: {
163
- dedupe: ['react', 'react-dom', 'styled-components'],
164
- },
165
- // ...rest of config
166
- })
167
- ```
168
-
169
- 3. Reinstall or refresh the library after updating (e.g. `npm install` or clear cache and reinstall).
170
-
171
- ---
172
-
173
- ## Development & publishing
174
-
175
- ### Run Storybook
176
-
177
- ```bash
178
- npm run storybook
179
- ```
180
-
181
- Use **Story Source** for consumption examples and **Viewport** for different screen sizes.
182
-
183
- ### Build for distribution
184
-
185
- ```bash
186
- npm run build:dist
187
- ```
188
-
189
- This runs `vite build` and copies static assets to `dist/`.
190
-
191
- ### Publish a new version
192
-
193
- 1. Commit your changes.
194
- 2. Update [CHANGELOG.md](CHANGELOG.md) add a new `# vX.Y.Z` section at the top with the list of changes.
195
- 3. Bump the version: `npm version <version>` (e.g. `npm version 3.0.7`).
196
- 4. (ensure you are authenticated) Run `npm login` to log first on NPM package (only needed one time a day)
197
- 5. Run `npm run pub` (will first run `npm run build:dist`).
198
-
199
- Consumers can see what changed in each release in [CHANGELOG.md](CHANGELOG.md).
200
-
201
- ### Reference
202
-
203
- - [How to publish a React component library](https://medium.com/better-programming/how-to-publish-a-react-component-library-c89a07566770)
1
+ # @stokr/components-library
2
+
3
+ React component library for STOKR applications. Includes modals, forms, buttons, tables, and shared styles.
4
+
5
+ ## Table of contents
6
+
7
+ - [Installation](#installation)
8
+ - [How to start](#how-to-start)
9
+ - [Configuration](#configuration)
10
+ - [Runtime config (npm consumers)](#runtime-config)
11
+ - [Ionicons](#ionicons)
12
+ - [React Router](#react-router)
13
+ - [Troubleshooting](#troubleshooting)
14
+ - [Development & publishing](#development--publishing)
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @stokr/components-library
22
+ ```
23
+
24
+ **Peer dependencies** (install in your app if not already present):
25
+
26
+ ```bash
27
+ npm install react react-dom styled-components react-router-dom
28
+ ```
29
+
30
+ - **React** 18 or 19
31
+ - **styled-components** 6.x
32
+ - **react-router-dom** 6.x (required if you use routing-dependent components)
33
+
34
+ ---
35
+
36
+ ## How to start
37
+
38
+ ### 1. Install the package and peers
39
+
40
+ ```bash
41
+ npm install @stokr/components-library react react-dom styled-components react-router-dom
42
+ ```
43
+
44
+ ### 2. Wrap your app with a Router (if you use routing)
45
+
46
+ Components that use navigation (e.g. `MainMenu`, `LearnMore`, `HeaderHo`) must live inside a React Router:
47
+
48
+ ```jsx
49
+ // main.jsx or App.jsx
50
+ import { BrowserRouter } from 'react-router-dom'
51
+ import App from './App'
52
+
53
+ root.render(
54
+ <BrowserRouter>
55
+ <App />
56
+ </BrowserRouter>,
57
+ )
58
+ ```
59
+
60
+ ### 3. (Optional) Add Ionicons for icons
61
+
62
+ If you use **Modal**, **ConfirmModal**, **BackButton**, **Select**, **InfoIcon**, etc., add the icon styles once at the root:
63
+
64
+ ```jsx
65
+ import { IoniconsStyles } from '@stokr/components-library'
66
+
67
+ function App() {
68
+ return (
69
+ <>
70
+ <IoniconsStyles />
71
+ {/* your app */}
72
+ </>
73
+ )
74
+ }
75
+ ```
76
+
77
+ You can skip this; the library will inject icon styles when you first use a component that needs them.
78
+
79
+ ### 4. Import and use components
80
+
81
+ ```jsx
82
+ import { ConfirmModal, Button } from '@stokr/components-library'
83
+
84
+ function MyPage() {
85
+ const [open, setOpen] = useState(false)
86
+ return (
87
+ <>
88
+ <Button onClick={() => setOpen(true)}>Open</Button>
89
+ <ConfirmModal isOpen={open} onClose={() => setOpen(false)} onConfirm={() => {}} title="Confirm?" />
90
+ </>
91
+ )
92
+ }
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Configuration
98
+
99
+ ### Runtime config (required when consuming as npm package) {#runtime-config}
100
+
101
+ Since v3.0.16, the library uses a **runtime config** system. When this package is consumed by an external Vite app, `import.meta.env` values are baked at **library build time** and do not reflect the consuming app's `.env` file. Pass a `config` prop to `<AuthProvider>` so API URLs, Firebase credentials, and cookie domain are resolved from **your** environment:
102
+
103
+ ```jsx
104
+ import { AuthProvider } from '@stokr/components-library'
105
+
106
+ function App() {
107
+ return (
108
+ <AuthProvider
109
+ config={{
110
+ apiUrl: import.meta.env.VITE_API_URL,
111
+ baseUrlPublic: import.meta.env.VITE_BASE_URL_PUBLIC,
112
+ cookieDomain: import.meta.env.VITE_COOKIE_DOMAIN,
113
+ websiteDomain: import.meta.env.VITE_WEBSITE_DOMAIN,
114
+ photoApiUrl: import.meta.env.VITE_PHOTO_API_URL,
115
+ firebase: {
116
+ apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
117
+ authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
118
+ projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
119
+ storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
120
+ messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
121
+ appId: import.meta.env.VITE_FIREBASE_APP_ID,
122
+ measurementId: import.meta.env.VITE_FIREBASE_MEASUREMENT_ID,
123
+ },
124
+ }}
125
+ >
126
+ {/* your app */}
127
+ </AuthProvider>
128
+ )
129
+ }
130
+ ```
131
+
132
+ | Prop key | Env variable it replaces | Purpose |
133
+ | --- | --- | --- |
134
+ | `apiUrl` | `VITE_API_URL` | Backend API base URL |
135
+ | `baseUrlPublic` | `VITE_BASE_URL_PUBLIC` | Public (no-auth) API base URL |
136
+ | `cookieDomain` | `VITE_COOKIE_DOMAIN` | Domain attribute for auth cookies |
137
+ | `websiteDomain` | `VITE_WEBSITE_DOMAIN` | Platform domain (redirects, links) |
138
+ | `photoApiUrl` | `VITE_PHOTO_API_URL` | Photo upload / avatar API URL |
139
+ | `firebase` | `VITE_FIREBASE_*` | Full Firebase config object |
140
+
141
+ > **Why is this needed?** With the old CRA / `react-scripts` build, Webpack re-processed library code through the consuming app's build pipeline, so the app's `.env` values were injected automatically. Vite treats npm packages as pre-built — `import.meta.env` values in the compiled library are frozen at library build time. The `config` prop passes them at runtime instead.
142
+
143
+ If you also need config values **before** `<AuthProvider>` mounts (e.g. for analytics init), you can call `configure()` directly:
144
+
145
+ ```js
146
+ import { configure } from '@stokr/components-library'
147
+
148
+ configure({
149
+ apiUrl: import.meta.env.VITE_API_URL,
150
+ cookieDomain: import.meta.env.VITE_COOKIE_DOMAIN,
151
+ // ...
152
+ })
153
+ ```
154
+
155
+ ### Ionicons
156
+
157
+ Components such as **Modal**, **ConfirmModal**, **BackButton**, **InfoIcon**, **Select**, **MainMenu**, and **RegisterLiquidSteps** use [Ionicons](http://ionicons.com/). You can enable them in three ways:
158
+
159
+ | Approach | When to use |
160
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
161
+ | **Global injection** | Render `<IoniconsStyles />` once at app root. Full icon set, singleton. |
162
+ | **No setup** | Don’t render anything; styles inject on first use of an icon component. |
163
+ | **CSS import** | Prefer loading via CSS: `import '@stokr/components-library/styles.css'` or `import '@stokr/components-library/ionicons.css'`. |
164
+
165
+ **Global injection example:**
166
+
167
+ ```jsx
168
+ import { IoniconsStyles } from '@stokr/components-library'
169
+
170
+ function App() {
171
+ return (
172
+ <>
173
+ <IoniconsStyles />
174
+ {/* your routes, layout, etc. */}
175
+ </>
176
+ )
177
+ }
178
+ ```
179
+
180
+ If you use **Layout**, **GlobalStyle**, or need **Open Sans**, import the full styles once:
181
+
182
+ ```js
183
+ import '@stokr/components-library/styles.css'
184
+ ```
185
+
186
+ ### React Router
187
+
188
+ Any component that uses `useNavigate()` or routing must be rendered inside a `Router` from `react-router-dom` (e.g. `BrowserRouter`). See [How to start – step 2](#2-wrap-your-app-with-a-router-if-you-use-routing).
189
+
190
+ ---
191
+
192
+ ## Troubleshooting
193
+
194
+ ### "useNavigate() may be used only in the context of a \<Router\> component"
195
+
196
+ Wrap your app with a Router:
197
+
198
+ ```jsx
199
+ import { BrowserRouter } from 'react-router-dom'
200
+
201
+ root.render(
202
+ <BrowserRouter>
203
+ <App />
204
+ </BrowserRouter>,
205
+ )
206
+ ```
207
+
208
+ Install the peer dependency: `npm install react-router-dom`
209
+
210
+ ### "Invalid hook call" / "Cannot read properties of null (reading 'use')"
211
+
212
+ Your app and the library must use the **same** React instance.
213
+
214
+ 1. Install peer dependencies:
215
+ `npm install react react-dom styled-components`
216
+
217
+ 2. **Vite apps** – add dedupe in `vite.config.js` or `vite.config.ts`:
218
+
219
+ ```js
220
+ export default defineConfig({
221
+ resolve: {
222
+ dedupe: ['react', 'react-dom', 'styled-components'],
223
+ },
224
+ // ...rest of config
225
+ })
226
+ ```
227
+
228
+ 3. Reinstall or refresh the library after updating (e.g. `npm install` or clear cache and reinstall).
229
+
230
+ ---
231
+
232
+ ## Development & publishing
233
+
234
+ ### Run Storybook
235
+
236
+ ```bash
237
+ npm run storybook
238
+ ```
239
+
240
+ Use **Story Source** for consumption examples and **Viewport** for different screen sizes.
241
+
242
+ ### Build for distribution
243
+
244
+ ```bash
245
+ npm run build:dist
246
+ ```
247
+
248
+ This runs `vite build` and copies static assets to `dist/`.
249
+
250
+ ### Publish a new version
251
+
252
+ 1. Commit your changes.
253
+ 2. Update [CHANGELOG.md](CHANGELOG.md) – add a new `# vX.Y.Z` section at the top with the list of changes.
254
+ 3. Bump the version: `npm version <version>` (e.g. `npm version 3.0.7`).
255
+ 4. (ensure you are authenticated) Run `npm login` to log first on NPM package (only needed one time a day)
256
+ 5. Run `npm run pub` (will first run `npm run build:dist`).
257
+
258
+ Consumers can see what changed in each release in [CHANGELOG.md](CHANGELOG.md).
259
+
260
+ ### Reference
261
+
262
+ - [How to publish a React component library](https://medium.com/better-programming/how-to-publish-a-react-component-library-c89a07566770)