@sparkstudio/common-ui 1.0.11 → 1.0.13

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/dist/index.cjs CHANGED
@@ -30,7 +30,10 @@ __export(index_exports, {
30
30
  LayoutWrapper: () => LayoutWrapper,
31
31
  Navigation: () => Navigation,
32
32
  NavigationItem: () => NavigationItem,
33
- NpmBadge: () => NpmBadge
33
+ Notifications: () => Notifications,
34
+ NotificationsProvider: () => NotificationsProvider,
35
+ NpmBadge: () => NpmBadge,
36
+ UseNotifications: () => UseNotifications
34
37
  });
35
38
  module.exports = __toCommonJS(index_exports);
36
39
 
@@ -40,7 +43,7 @@ function Body({ title, description, children }) {
40
43
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { className: "col p-4", children: [
41
44
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: title }),
42
45
  description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: description }),
43
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "card mt-3", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "card-body", children }) })
46
+ children
44
47
  ] });
45
48
  }
46
49
 
@@ -152,22 +155,135 @@ function NavigationItem({ title, type, active, onClick }) {
152
155
  ) });
153
156
  }
154
157
 
155
- // src/components/wrappers/ContentContainer.tsx
158
+ // src/components/notifications/Notifications.tsx
159
+ var import_react2 = require("react");
156
160
  var import_jsx_runtime9 = require("react/jsx-runtime");
161
+ function Notifications({ notifications, onClose }) {
162
+ (0, import_react2.useEffect)(() => {
163
+ notifications.forEach((n) => {
164
+ if (!n.autoCloseMs) return;
165
+ const timer = setTimeout(() => onClose(n.id), n.autoCloseMs);
166
+ return () => clearTimeout(timer);
167
+ });
168
+ }, [notifications, onClose]);
169
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
170
+ "div",
171
+ {
172
+ className: "position-fixed top-0 end-0 p-3",
173
+ style: { zIndex: 1080, width: 340 },
174
+ children: notifications.map((n) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
175
+ "div",
176
+ {
177
+ className: `alert alert-${n.type ?? "info"} alert-dismissible fade show shadow-sm mb-2`,
178
+ role: "alert",
179
+ children: [
180
+ n.message,
181
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
182
+ "button",
183
+ {
184
+ type: "button",
185
+ className: "btn-close",
186
+ "aria-label": "Close",
187
+ onClick: () => onClose(n.id)
188
+ }
189
+ )
190
+ ]
191
+ },
192
+ n.id
193
+ ))
194
+ }
195
+ );
196
+ }
197
+
198
+ // src/components/notifications/NotificationsProvider.tsx
199
+ var import_react3 = require("react");
200
+ var import_jsx_runtime10 = require("react/jsx-runtime");
201
+ var NotificationsContext = (0, import_react3.createContext)(
202
+ void 0
203
+ );
204
+ function NotificationsProvider({ children }) {
205
+ const [notifications, setNotifications] = (0, import_react3.useState)([]);
206
+ const push = (0, import_react3.useCallback)(
207
+ (message, type = "info", autoCloseMs = 4e3) => {
208
+ setNotifications((prev) => [
209
+ ...prev,
210
+ {
211
+ id: crypto.randomUUID(),
212
+ message,
213
+ type,
214
+ autoCloseMs
215
+ }
216
+ ]);
217
+ },
218
+ []
219
+ );
220
+ const close = (0, import_react3.useCallback)((id) => {
221
+ setNotifications((list) => list.filter((n) => n.id !== id));
222
+ }, []);
223
+ (0, import_react3.useEffect)(() => {
224
+ const timers = notifications.map((n) => {
225
+ if (!n.autoCloseMs) return null;
226
+ return setTimeout(() => close(n.id), n.autoCloseMs);
227
+ });
228
+ return () => {
229
+ timers.forEach((t) => t && clearTimeout(t));
230
+ };
231
+ }, [notifications, close]);
232
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(NotificationsContext.Provider, { value: { push }, children: [
233
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
234
+ "div",
235
+ {
236
+ className: "position-fixed top-0 end-0 p-3",
237
+ style: { zIndex: 1080, width: 340 },
238
+ children: notifications.map((n) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
239
+ "div",
240
+ {
241
+ className: `alert alert-${n.type ?? "info"} alert-dismissible fade show shadow-sm mb-2`,
242
+ role: "alert",
243
+ children: [
244
+ n.message,
245
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
246
+ "button",
247
+ {
248
+ type: "button",
249
+ className: "btn-close",
250
+ "aria-label": "Close",
251
+ onClick: () => close(n.id)
252
+ }
253
+ )
254
+ ]
255
+ },
256
+ n.id
257
+ ))
258
+ }
259
+ ),
260
+ children
261
+ ] });
262
+ }
263
+ function UseNotifications() {
264
+ const ctx = (0, import_react3.useContext)(NotificationsContext);
265
+ if (!ctx) {
266
+ throw new Error("useNotifications must be used within a NotificationsProvider");
267
+ }
268
+ return ctx;
269
+ }
270
+
271
+ // src/components/wrappers/ContentContainer.tsx
272
+ var import_jsx_runtime11 = require("react/jsx-runtime");
157
273
  function ContentContainer({ children }) {
158
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "container-fluid flex-grow-1", children });
274
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "container-fluid flex-grow-1", children });
159
275
  }
160
276
 
161
277
  // src/components/wrappers/ContentRow.tsx
162
- var import_jsx_runtime10 = require("react/jsx-runtime");
278
+ var import_jsx_runtime12 = require("react/jsx-runtime");
163
279
  function ContentRow({ children }) {
164
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "row h-100 flex-nowrap", children });
280
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "row h-100 flex-nowrap", children });
165
281
  }
166
282
 
167
283
  // src/components/wrappers/LayoutWrapper.tsx
168
- var import_jsx_runtime11 = require("react/jsx-runtime");
284
+ var import_jsx_runtime13 = require("react/jsx-runtime");
169
285
  function LayoutWrapper({ children }) {
170
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "d-flex flex-column min-vh-100", children });
286
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "d-flex flex-column min-vh-100", children });
171
287
  }
172
288
  // Annotate the CommonJS export names for ESM import in node:
173
289
  0 && (module.exports = {
@@ -181,6 +297,9 @@ function LayoutWrapper({ children }) {
181
297
  LayoutWrapper,
182
298
  Navigation,
183
299
  NavigationItem,
184
- NpmBadge
300
+ Notifications,
301
+ NotificationsProvider,
302
+ NpmBadge,
303
+ UseNotifications
185
304
  });
186
305
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/components/Body.tsx","../src/components/Button.tsx","../src/components/Footer.tsx","../src/components/Header.tsx","../src/components/HeaderText.tsx","../src/components/NpmBadge.tsx","../src/components/navigation/Navigation.tsx","../src/components/navigation/NavigationItem.tsx","../src/components/wrappers/ContentContainer.tsx","../src/components/wrappers/ContentRow.tsx","../src/components/wrappers/LayoutWrapper.tsx"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/Body\";\nexport * from \"./components/Button\";\nexport * from \"./components/Footer\";\nexport * from \"./components/Header\";\nexport * from \"./components/HeaderText\";\nexport * from \"./components/NpmBadge\";\nexport * from \"./components/navigation/Navigation\";\nexport * from \"./components/navigation/NavigationItem\";\nexport * from \"./components/wrappers/ContentContainer\";\nexport * from \"./components/wrappers/ContentRow\";\nexport * from \"./components/wrappers/LayoutWrapper\";\n","import type { ReactNode } from \"react\";\r\n\r\ninterface BodyProps {\r\n title: ReactNode;\r\n description?: ReactNode;\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Body({ title, description, children }: BodyProps) {\r\n return (\r\n <main className=\"col p-4\">\r\n <h2>{title}</h2>\r\n\r\n {description && <p>{description}</p>}\r\n\r\n <div className=\"card mt-3\">\r\n <div className=\"card-body\">\r\n {children}\r\n </div>\r\n </div>\r\n </main>\r\n );\r\n}\r\n","import { useState, type ReactNode, type MouseEvent } from \"react\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface FooterProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Footer({ children }: FooterProps) {\r\n return (\r\n <footer className=\"bg-dark text-white text-center py-2 mt-auto\">\r\n {children ?? \"© 2025 Your Site — All rights reserved\"}\r\n </footer>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Header({ children }: HeaderProps) {\r\n return (\r\n <nav className=\"navbar navbar-dark bg-dark px-3 sticky-top\">\r\n {children ?? (\r\n <span className=\"navbar-brand mb-0 h4\">My Website</span>\r\n )}\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderBrandProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function HeaderText({ children }: HeaderBrandProps) {\r\n return (\r\n <span className=\"navbar-brand mb-0 h4\">\r\n {children}\r\n </span>\r\n );\r\n}\r\n","// components/NpmBadge.tsx\r\ninterface NpmBadgeProps {\r\n packageLabel: string;\r\n packageName: string;\r\n packageUrl: string; // e.g. \"@sparkstudio/authentication-ui\"\r\n color?: string; // optional (default black)\r\n height?: number; // optional (default 22)\r\n}\r\n\r\nexport function NpmBadge({ packageName, packageLabel, packageUrl, color = \"black\", height = 22 }: NpmBadgeProps) {\r\n const encodedLabel = encodeURIComponent(packageLabel);\r\n const badgeUrl = `https://img.shields.io/npm/v/${packageName}?logo=npm&label=${encodedLabel}&color=${color}`;\r\n const npmUrl = packageUrl;\r\n\r\n return (\r\n <a href={npmUrl} target=\"_blank\" rel=\"noopener noreferrer\">\r\n <img src={badgeUrl} alt={`${packageName} version`} style={{ height }} />\r\n </a>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationProps {\r\n title?: ReactNode;\r\n children: ReactNode;\r\n}\r\n\r\nexport function Navigation({ title = \"Navigation\", children }: NavigationProps) {\r\n return (\r\n <nav className=\"col-auto p-3 h-100 d-flex flex-column\">\r\n <h6 className=\"text-muted text-uppercase\">{title}</h6>\r\n\r\n <ul className=\"nav nav-pills flex-column gap-2 mt-3\">\r\n {children}\r\n </ul>\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationItemProps {\r\n title: ReactNode;\r\n type: string;\r\n active?: boolean;\r\n onClick?: (type: string) => void;\r\n}\r\n\r\nexport function NavigationItem({ title, type, active, onClick }: NavigationItemProps) {\r\n return (\r\n <li className=\"nav-item\">\r\n <button\r\n type=\"button\"\r\n className={`nav-link text-start w-100 ${active ? \"active\" : \"\"}`}\r\n onClick={() => onClick?.(type)}\r\n >\r\n {title}\r\n </button>\r\n </li>\r\n );\r\n}\r\n","export function ContentContainer({ children }: React.PropsWithChildren) {\r\n return <div className=\"container-fluid flex-grow-1\">{children}</div>;\r\n}\r\n","export function ContentRow({ children }: React.PropsWithChildren) {\r\n return <div className=\"row h-100 flex-nowrap\">{children}</div>;\r\n}\r\n","export function LayoutWrapper({ children }: React.PropsWithChildren) {\r\n return <div className=\"d-flex flex-column min-vh-100\">{children}</div>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUI;AAFG,SAAS,KAAK,EAAE,OAAO,aAAa,SAAS,GAAc;AAChE,SACE,6CAAC,UAAK,WAAU,WACd;AAAA,gDAAC,QAAI,iBAAM;AAAA,IAEV,eAAe,4CAAC,OAAG,uBAAY;AAAA,IAEhC,4CAAC,SAAI,WAAU,aACb,sDAAC,SAAI,WAAU,aACZ,UACH,GACF;AAAA,KACF;AAEJ;;;ACtBA,mBAA0D;AA0EhD,IAAAA,sBAAA;AAnDH,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAA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,GAAG,GAAkB;AAC/G,QAAM,eAAe,mBAAmB,YAAY;AACpD,QAAM,WAAW,gCAAgC,WAAW,mBAAmB,YAAY,UAAU,KAAK;AAC1G,QAAM,SAAS;AAEf,SACE,6CAAC,OAAE,MAAM,QAAQ,QAAO,UAAS,KAAI,uBACnC,uDAAC,SAAI,KAAK,UAAU,KAAK,GAAG,WAAW,YAAY,OAAO,EAAE,OAAO,GAAG,GACxE;AAEJ;;;ACVI,IAAAC,sBAAA;AAFG,SAAS,WAAW,EAAE,QAAQ,cAAc,SAAS,GAAoB;AAC9E,SACE,8CAAC,SAAI,WAAU,yCACb;AAAA,iDAAC,QAAG,WAAU,6BAA6B,iBAAM;AAAA,IAEjD,6CAAC,QAAG,WAAU,wCACX,UACH;AAAA,KACF;AAEJ;;;ACLM,IAAAC,sBAAA;AAHC,SAAS,eAAe,EAAE,OAAO,MAAM,QAAQ,QAAQ,GAAwB;AACpF,SACE,6CAAC,QAAG,WAAU,YACZ;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,WAAW,6BAA6B,SAAS,WAAW,EAAE;AAAA,MAC9D,SAAS,MAAM,UAAU,IAAI;AAAA,MAE5B;AAAA;AAAA,EACH,GACF;AAEJ;;;ACpBS,IAAAC,sBAAA;AADF,SAAS,iBAAiB,EAAE,SAAS,GAA4B;AACtE,SAAO,6CAAC,SAAI,WAAU,+BAA+B,UAAS;AAChE;;;ACDS,IAAAC,uBAAA;AADF,SAAS,WAAW,EAAE,SAAS,GAA4B;AAChE,SAAO,8CAAC,SAAI,WAAU,yBAAyB,UAAS;AAC1D;;;ACDS,IAAAC,uBAAA;AADF,SAAS,cAAc,EAAE,SAAS,GAA4B;AACnE,SAAO,8CAAC,SAAI,WAAU,iCAAiC,UAAS;AAClE;","names":["import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/components/Body.tsx","../src/components/Button.tsx","../src/components/Footer.tsx","../src/components/Header.tsx","../src/components/HeaderText.tsx","../src/components/NpmBadge.tsx","../src/components/navigation/Navigation.tsx","../src/components/navigation/NavigationItem.tsx","../src/components/notifications/Notifications.tsx","../src/components/notifications/NotificationsProvider.tsx","../src/components/wrappers/ContentContainer.tsx","../src/components/wrappers/ContentRow.tsx","../src/components/wrappers/LayoutWrapper.tsx"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/Body\";\nexport * from \"./components/Button\";\nexport * from \"./components/Footer\";\nexport * from \"./components/Header\";\nexport * from \"./components/HeaderText\";\nexport * from \"./components/NpmBadge\";\nexport * from \"./components/navigation/Navigation\";\nexport * from \"./components/navigation/NavigationItem\";\nexport * from \"./components/notifications/Notifications\";\nexport * from \"./components/notifications/NotificationsProvider\";\nexport * from \"./components/wrappers/ContentContainer\";\nexport * from \"./components/wrappers/ContentRow\";\nexport * from \"./components/wrappers/LayoutWrapper\";\n","import type { ReactNode } from \"react\";\r\n\r\ninterface BodyProps {\r\n title: ReactNode;\r\n description?: ReactNode;\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Body({ title, description, children }: BodyProps) {\r\n return (\r\n <main className=\"col p-4\">\r\n <h2>{title}</h2>\r\n\r\n {description && <p>{description}</p>}\r\n {children}\r\n </main>\r\n );\r\n}\r\n","import { useState, type ReactNode, type MouseEvent } from \"react\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface FooterProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Footer({ children }: FooterProps) {\r\n return (\r\n <footer className=\"bg-dark text-white text-center py-2 mt-auto\">\r\n {children ?? \"© 2025 Your Site — All rights reserved\"}\r\n </footer>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Header({ children }: HeaderProps) {\r\n return (\r\n <nav className=\"navbar navbar-dark bg-dark px-3 sticky-top\">\r\n {children ?? (\r\n <span className=\"navbar-brand mb-0 h4\">My Website</span>\r\n )}\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderBrandProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function HeaderText({ children }: HeaderBrandProps) {\r\n return (\r\n <span className=\"navbar-brand mb-0 h4\">\r\n {children}\r\n </span>\r\n );\r\n}\r\n","// components/NpmBadge.tsx\r\ninterface NpmBadgeProps {\r\n packageLabel: string;\r\n packageName: string;\r\n packageUrl: string; // e.g. \"@sparkstudio/authentication-ui\"\r\n color?: string; // optional (default black)\r\n height?: number; // optional (default 22)\r\n}\r\n\r\nexport function NpmBadge({ packageName, packageLabel, packageUrl, color = \"black\", height = 22 }: NpmBadgeProps) {\r\n const encodedLabel = encodeURIComponent(packageLabel);\r\n const badgeUrl = `https://img.shields.io/npm/v/${packageName}?logo=npm&label=${encodedLabel}&color=${color}`;\r\n const npmUrl = packageUrl;\r\n\r\n return (\r\n <a href={npmUrl} target=\"_blank\" rel=\"noopener noreferrer\">\r\n <img src={badgeUrl} alt={`${packageName} version`} style={{ height }} />\r\n </a>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationProps {\r\n title?: ReactNode;\r\n children: ReactNode;\r\n}\r\n\r\nexport function Navigation({ title = \"Navigation\", children }: NavigationProps) {\r\n return (\r\n <nav className=\"col-auto p-3 h-100 d-flex flex-column\">\r\n <h6 className=\"text-muted text-uppercase\">{title}</h6>\r\n\r\n <ul className=\"nav nav-pills flex-column gap-2 mt-3\">\r\n {children}\r\n </ul>\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationItemProps {\r\n title: ReactNode;\r\n type: string;\r\n active?: boolean;\r\n onClick?: (type: string) => void;\r\n}\r\n\r\nexport function NavigationItem({ title, type, active, onClick }: NavigationItemProps) {\r\n return (\r\n <li className=\"nav-item\">\r\n <button\r\n type=\"button\"\r\n className={`nav-link text-start w-100 ${active ? \"active\" : \"\"}`}\r\n onClick={() => onClick?.(type)}\r\n >\r\n {title}\r\n </button>\r\n </li>\r\n );\r\n}\r\n","import { useEffect } from \"react\";\r\n\r\nexport type NotificationType = \"success\" | \"info\" | \"warning\" | \"danger\";\r\n\r\nexport interface Notification {\r\n id: string;\r\n message: string;\r\n type?: NotificationType;\r\n autoCloseMs?: number;\r\n}\r\n\r\ninterface NotificationsProps {\r\n notifications: Notification[];\r\n onClose: (id: string) => void;\r\n}\r\n\r\nexport function Notifications({ notifications, onClose }: NotificationsProps) {\r\n useEffect(() => {\r\n notifications.forEach((n) => {\r\n if (!n.autoCloseMs) return;\r\n\r\n const timer = setTimeout(() => onClose(n.id), n.autoCloseMs);\r\n return () => clearTimeout(timer);\r\n });\r\n }, [notifications, onClose]);\r\n\r\n return (\r\n <div\r\n className=\"position-fixed top-0 end-0 p-3\"\r\n style={{ zIndex: 1080, width: 340 }}\r\n >\r\n {notifications.map((n) => (\r\n <div\r\n key={n.id}\r\n className={`alert alert-${n.type ?? \"info\"} alert-dismissible fade show shadow-sm mb-2`}\r\n role=\"alert\"\r\n >\r\n {n.message}\r\n\r\n <button\r\n type=\"button\"\r\n className=\"btn-close\"\r\n aria-label=\"Close\"\r\n onClick={() => onClose(n.id)}\r\n />\r\n </div>\r\n ))}\r\n </div>\r\n );\r\n}\r\n","import {\r\n createContext,\r\n useCallback,\r\n useContext,\r\n useEffect,\r\n useState,\r\n type ReactNode,\r\n} from \"react\";\r\n\r\nexport type NotificationType = \"success\" | \"info\" | \"warning\" | \"danger\";\r\n\r\n// Rename to avoid conflict with browser Notification type\r\nexport interface AppNotification {\r\n id: string;\r\n message: string;\r\n type?: NotificationType;\r\n autoCloseMs?: number;\r\n}\r\n\r\ninterface NotificationsContextValue {\r\n push: (message: string, type?: NotificationType, autoCloseMs?: number) => void;\r\n}\r\n\r\nconst NotificationsContext = createContext<NotificationsContextValue | undefined>(\r\n undefined\r\n);\r\n\r\ninterface NotificationsProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function NotificationsProvider({ children }: NotificationsProviderProps) {\r\n const [notifications, setNotifications] = useState<AppNotification[]>([]);\r\n\r\n const push = useCallback(\r\n (message: string, type: NotificationType = \"info\", autoCloseMs = 4000) => {\r\n setNotifications((prev) => [\r\n ...prev,\r\n {\r\n id: crypto.randomUUID(),\r\n message,\r\n type,\r\n autoCloseMs,\r\n },\r\n ]);\r\n },\r\n []\r\n );\r\n\r\n const close = useCallback((id: string) => {\r\n setNotifications((list) => list.filter((n) => n.id !== id));\r\n }, []);\r\n\r\n // Handle auto close timers\r\n useEffect(() => {\r\n const timers = notifications.map((n) => {\r\n if (!n.autoCloseMs) return null;\r\n return setTimeout(() => close(n.id), n.autoCloseMs);\r\n });\r\n\r\n return () => {\r\n timers.forEach((t) => t && clearTimeout(t));\r\n };\r\n }, [notifications, close]);\r\n\r\n return (\r\n <NotificationsContext.Provider value={{ push }}>\r\n {/* overlay renderer */}\r\n <div\r\n className=\"position-fixed top-0 end-0 p-3\"\r\n style={{ zIndex: 1080, width: 340 }}\r\n >\r\n {notifications.map((n) => (\r\n <div\r\n key={n.id}\r\n className={`alert alert-${n.type ?? \"info\"} alert-dismissible fade show shadow-sm mb-2`}\r\n role=\"alert\"\r\n >\r\n {n.message}\r\n <button\r\n type=\"button\"\r\n className=\"btn-close\"\r\n aria-label=\"Close\"\r\n onClick={() => close(n.id)}\r\n />\r\n </div>\r\n ))}\r\n </div>\r\n\r\n {children}\r\n </NotificationsContext.Provider>\r\n );\r\n}\r\n\r\nexport function UseNotifications(): NotificationsContextValue {\r\n const ctx = useContext(NotificationsContext);\r\n if (!ctx) {\r\n throw new Error(\"useNotifications must be used within a NotificationsProvider\");\r\n }\r\n return ctx;\r\n}\r\n","export function ContentContainer({ children }: React.PropsWithChildren) {\r\n return <div className=\"container-fluid flex-grow-1\">{children}</div>;\r\n}\r\n","export function ContentRow({ children }: React.PropsWithChildren) {\r\n return <div className=\"row h-100 flex-nowrap\">{children}</div>;\r\n}\r\n","export function LayoutWrapper({ children }: React.PropsWithChildren) {\r\n return <div className=\"d-flex flex-column min-vh-100\">{children}</div>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUI;AAFG,SAAS,KAAK,EAAE,OAAO,aAAa,SAAS,GAAc;AAChE,SACE,6CAAC,UAAK,WAAU,WACd;AAAA,gDAAC,QAAI,iBAAM;AAAA,IAEV,eAAe,4CAAC,OAAG,uBAAY;AAAA,IAC/B;AAAA,KACH;AAEJ;;;ACjBA,mBAA0D;AA0EhD,IAAAA,sBAAA;AAnDH,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AAAA,EACd,cAAc;AAChB,GAAgB;AACd,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,KAAK;AAE5C,QAAM,cAAc,OAAO,UAAyC;AAClE,QAAI,QAAS;AAEb,cAAU,KAAK;AACf,QAAI,MAAM,iBAAkB;AAC5B,QAAI,CAAC,SAAU;AAEf,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,SAAS,MAAM,SAAS;AAC9B,eAAS,MAAM;AAAA,IACjB,SAAS,OAAO;AACd,gBAAU,KAAK;AAAA,IACjB,UAAE;AACA,iBAAW,KAAK;AAChB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,eAAe,IAAI,UAAU,uBAAuB,EAAE;AAAA,MACpE,SAAS;AAAA,MACT,UAAU,YAAY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W,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AACA,SAAO;AACT;;;ACnGS,IAAAC,uBAAA;AADF,SAAS,iBAAiB,EAAE,SAAS,GAA4B;AACtE,SAAO,8CAAC,SAAI,WAAU,+BAA+B,UAAS;AAChE;;;ACDS,IAAAC,uBAAA;AADF,SAAS,WAAW,EAAE,SAAS,GAA4B;AAChE,SAAO,8CAAC,SAAI,WAAU,yBAAyB,UAAS;AAC1D;;;ACDS,IAAAC,uBAAA;AADF,SAAS,cAAc,EAAE,SAAS,GAA4B;AACnE,SAAO,8CAAC,SAAI,WAAU,iCAAiC,UAAS;AAClE;","names":["import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime"]}
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ function Body({ title, description, children }) {
4
4
  return /* @__PURE__ */ jsxs("main", { className: "col p-4", children: [
5
5
  /* @__PURE__ */ jsx("h2", { children: title }),
6
6
  description && /* @__PURE__ */ jsx("p", { children: description }),
7
- /* @__PURE__ */ jsx("div", { className: "card mt-3", children: /* @__PURE__ */ jsx("div", { className: "card-body", children }) })
7
+ children
8
8
  ] });
9
9
  }
10
10
 
@@ -116,22 +116,141 @@ function NavigationItem({ title, type, active, onClick }) {
116
116
  ) });
117
117
  }
118
118
 
119
+ // src/components/notifications/Notifications.tsx
120
+ import { useEffect } from "react";
121
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
122
+ function Notifications({ notifications, onClose }) {
123
+ useEffect(() => {
124
+ notifications.forEach((n) => {
125
+ if (!n.autoCloseMs) return;
126
+ const timer = setTimeout(() => onClose(n.id), n.autoCloseMs);
127
+ return () => clearTimeout(timer);
128
+ });
129
+ }, [notifications, onClose]);
130
+ return /* @__PURE__ */ jsx9(
131
+ "div",
132
+ {
133
+ className: "position-fixed top-0 end-0 p-3",
134
+ style: { zIndex: 1080, width: 340 },
135
+ children: notifications.map((n) => /* @__PURE__ */ jsxs4(
136
+ "div",
137
+ {
138
+ className: `alert alert-${n.type ?? "info"} alert-dismissible fade show shadow-sm mb-2`,
139
+ role: "alert",
140
+ children: [
141
+ n.message,
142
+ /* @__PURE__ */ jsx9(
143
+ "button",
144
+ {
145
+ type: "button",
146
+ className: "btn-close",
147
+ "aria-label": "Close",
148
+ onClick: () => onClose(n.id)
149
+ }
150
+ )
151
+ ]
152
+ },
153
+ n.id
154
+ ))
155
+ }
156
+ );
157
+ }
158
+
159
+ // src/components/notifications/NotificationsProvider.tsx
160
+ import {
161
+ createContext,
162
+ useCallback,
163
+ useContext,
164
+ useEffect as useEffect2,
165
+ useState as useState2
166
+ } from "react";
167
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
168
+ var NotificationsContext = createContext(
169
+ void 0
170
+ );
171
+ function NotificationsProvider({ children }) {
172
+ const [notifications, setNotifications] = useState2([]);
173
+ const push = useCallback(
174
+ (message, type = "info", autoCloseMs = 4e3) => {
175
+ setNotifications((prev) => [
176
+ ...prev,
177
+ {
178
+ id: crypto.randomUUID(),
179
+ message,
180
+ type,
181
+ autoCloseMs
182
+ }
183
+ ]);
184
+ },
185
+ []
186
+ );
187
+ const close = useCallback((id) => {
188
+ setNotifications((list) => list.filter((n) => n.id !== id));
189
+ }, []);
190
+ useEffect2(() => {
191
+ const timers = notifications.map((n) => {
192
+ if (!n.autoCloseMs) return null;
193
+ return setTimeout(() => close(n.id), n.autoCloseMs);
194
+ });
195
+ return () => {
196
+ timers.forEach((t) => t && clearTimeout(t));
197
+ };
198
+ }, [notifications, close]);
199
+ return /* @__PURE__ */ jsxs5(NotificationsContext.Provider, { value: { push }, children: [
200
+ /* @__PURE__ */ jsx10(
201
+ "div",
202
+ {
203
+ className: "position-fixed top-0 end-0 p-3",
204
+ style: { zIndex: 1080, width: 340 },
205
+ children: notifications.map((n) => /* @__PURE__ */ jsxs5(
206
+ "div",
207
+ {
208
+ className: `alert alert-${n.type ?? "info"} alert-dismissible fade show shadow-sm mb-2`,
209
+ role: "alert",
210
+ children: [
211
+ n.message,
212
+ /* @__PURE__ */ jsx10(
213
+ "button",
214
+ {
215
+ type: "button",
216
+ className: "btn-close",
217
+ "aria-label": "Close",
218
+ onClick: () => close(n.id)
219
+ }
220
+ )
221
+ ]
222
+ },
223
+ n.id
224
+ ))
225
+ }
226
+ ),
227
+ children
228
+ ] });
229
+ }
230
+ function UseNotifications() {
231
+ const ctx = useContext(NotificationsContext);
232
+ if (!ctx) {
233
+ throw new Error("useNotifications must be used within a NotificationsProvider");
234
+ }
235
+ return ctx;
236
+ }
237
+
119
238
  // src/components/wrappers/ContentContainer.tsx
120
- import { jsx as jsx9 } from "react/jsx-runtime";
239
+ import { jsx as jsx11 } from "react/jsx-runtime";
121
240
  function ContentContainer({ children }) {
122
- return /* @__PURE__ */ jsx9("div", { className: "container-fluid flex-grow-1", children });
241
+ return /* @__PURE__ */ jsx11("div", { className: "container-fluid flex-grow-1", children });
123
242
  }
124
243
 
125
244
  // src/components/wrappers/ContentRow.tsx
126
- import { jsx as jsx10 } from "react/jsx-runtime";
245
+ import { jsx as jsx12 } from "react/jsx-runtime";
127
246
  function ContentRow({ children }) {
128
- return /* @__PURE__ */ jsx10("div", { className: "row h-100 flex-nowrap", children });
247
+ return /* @__PURE__ */ jsx12("div", { className: "row h-100 flex-nowrap", children });
129
248
  }
130
249
 
131
250
  // src/components/wrappers/LayoutWrapper.tsx
132
- import { jsx as jsx11 } from "react/jsx-runtime";
251
+ import { jsx as jsx13 } from "react/jsx-runtime";
133
252
  function LayoutWrapper({ children }) {
134
- return /* @__PURE__ */ jsx11("div", { className: "d-flex flex-column min-vh-100", children });
253
+ return /* @__PURE__ */ jsx13("div", { className: "d-flex flex-column min-vh-100", children });
135
254
  }
136
255
  export {
137
256
  Body,
@@ -144,6 +263,9 @@ export {
144
263
  LayoutWrapper,
145
264
  Navigation,
146
265
  NavigationItem,
147
- NpmBadge
266
+ Notifications,
267
+ NotificationsProvider,
268
+ NpmBadge,
269
+ UseNotifications
148
270
  };
149
271
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Body.tsx","../src/components/Button.tsx","../src/components/Footer.tsx","../src/components/Header.tsx","../src/components/HeaderText.tsx","../src/components/NpmBadge.tsx","../src/components/navigation/Navigation.tsx","../src/components/navigation/NavigationItem.tsx","../src/components/wrappers/ContentContainer.tsx","../src/components/wrappers/ContentRow.tsx","../src/components/wrappers/LayoutWrapper.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\r\n\r\ninterface BodyProps {\r\n title: ReactNode;\r\n description?: ReactNode;\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Body({ title, description, children }: BodyProps) {\r\n return (\r\n <main className=\"col p-4\">\r\n <h2>{title}</h2>\r\n\r\n {description && <p>{description}</p>}\r\n\r\n <div className=\"card mt-3\">\r\n <div className=\"card-body\">\r\n {children}\r\n </div>\r\n </div>\r\n </main>\r\n );\r\n}\r\n","import { useState, type ReactNode, type MouseEvent } from \"react\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface FooterProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Footer({ children }: FooterProps) {\r\n return (\r\n <footer className=\"bg-dark text-white text-center py-2 mt-auto\">\r\n {children ?? \"© 2025 Your Site — All rights reserved\"}\r\n </footer>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Header({ children }: HeaderProps) {\r\n return (\r\n <nav className=\"navbar navbar-dark bg-dark px-3 sticky-top\">\r\n {children ?? (\r\n <span className=\"navbar-brand mb-0 h4\">My Website</span>\r\n )}\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderBrandProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function HeaderText({ children }: HeaderBrandProps) {\r\n return (\r\n <span className=\"navbar-brand mb-0 h4\">\r\n {children}\r\n </span>\r\n );\r\n}\r\n","// components/NpmBadge.tsx\r\ninterface NpmBadgeProps {\r\n packageLabel: string;\r\n packageName: string;\r\n packageUrl: string; // e.g. \"@sparkstudio/authentication-ui\"\r\n color?: string; // optional (default black)\r\n height?: number; // optional (default 22)\r\n}\r\n\r\nexport function NpmBadge({ packageName, packageLabel, packageUrl, color = \"black\", height = 22 }: NpmBadgeProps) {\r\n const encodedLabel = encodeURIComponent(packageLabel);\r\n const badgeUrl = `https://img.shields.io/npm/v/${packageName}?logo=npm&label=${encodedLabel}&color=${color}`;\r\n const npmUrl = packageUrl;\r\n\r\n return (\r\n <a href={npmUrl} target=\"_blank\" rel=\"noopener noreferrer\">\r\n <img src={badgeUrl} alt={`${packageName} version`} style={{ height }} />\r\n </a>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationProps {\r\n title?: ReactNode;\r\n children: ReactNode;\r\n}\r\n\r\nexport function Navigation({ title = \"Navigation\", children }: NavigationProps) {\r\n return (\r\n <nav className=\"col-auto p-3 h-100 d-flex flex-column\">\r\n <h6 className=\"text-muted text-uppercase\">{title}</h6>\r\n\r\n <ul className=\"nav nav-pills flex-column gap-2 mt-3\">\r\n {children}\r\n </ul>\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationItemProps {\r\n title: ReactNode;\r\n type: string;\r\n active?: boolean;\r\n onClick?: (type: string) => void;\r\n}\r\n\r\nexport function NavigationItem({ title, type, active, onClick }: NavigationItemProps) {\r\n return (\r\n <li className=\"nav-item\">\r\n <button\r\n type=\"button\"\r\n className={`nav-link text-start w-100 ${active ? \"active\" : \"\"}`}\r\n onClick={() => onClick?.(type)}\r\n >\r\n {title}\r\n </button>\r\n </li>\r\n );\r\n}\r\n","export function ContentContainer({ children }: React.PropsWithChildren) {\r\n return <div className=\"container-fluid flex-grow-1\">{children}</div>;\r\n}\r\n","export function ContentRow({ children }: React.PropsWithChildren) {\r\n return <div className=\"row h-100 flex-nowrap\">{children}</div>;\r\n}\r\n","export function LayoutWrapper({ children }: React.PropsWithChildren) {\r\n return <div className=\"d-flex flex-column min-vh-100\">{children}</div>;\r\n}\r\n"],"mappings":";AAUI,SACE,KADF;AAFG,SAAS,KAAK,EAAE,OAAO,aAAa,SAAS,GAAc;AAChE,SACE,qBAAC,UAAK,WAAU,WACd;AAAA,wBAAC,QAAI,iBAAM;AAAA,IAEV,eAAe,oBAAC,OAAG,uBAAY;AAAA,IAEhC,oBAAC,SAAI,WAAU,aACb,8BAAC,SAAI,WAAU,aACZ,UACH,GACF;AAAA,KACF;AAEJ;;;ACtBA,SAAS,gBAAiD;AA0EhD,mBAEI,OAAAA,MAFJ,QAAAC,aAAA;AAnDH,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AAAA,EACd,cAAc;AAChB,GAAgB;AACd,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,cAAc,OAAO,UAAyC;AAClE,QAAI,QAAS;AAEb,cAAU,KAAK;AACf,QAAI,MAAM,iBAAkB;AAC5B,QAAI,CAAC,SAAU;AAEf,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,SAAS,MAAM,SAAS;AAC9B,eAAS,MAAM;AAAA,IACjB,SAAS,OAAO;AACd,gBAAU,KAAK;AAAA,IACjB,UAAE;AACA,iBAAW,KAAK;AAChB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,SACE,gBAAAD;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,eAAe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C,QAAG,WAAU,6BAA6B,iBAAM;AAAA,IAEjD,gBAAAA,KAAC,QAAG,WAAU,wCACX,UACH;AAAA,KACF;AAEJ;;;ACLM,gBAAAE,YAAA;AAHC,SAAS,eAAe,EAAE,OAAO,MAAM,QAAQ,QAAQ,GAAwB;AACpF,SACE,gBAAAA,KAAC,QAAG,WAAU,YACZ,0BAAAA;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,WAAW,6BAA6B,SAAS,WAAW,EAAE;AAAA,MAC9D,SAAS,MAAM,UAAU,IAAI;AAAA,MAE5B;AAAA;AAAA,EACH,GACF;AAEJ;;;ACpBS,gBAAAC,YAAA;AADF,SAAS,iBAAiB,EAAE,SAAS,GAA4B;AACtE,SAAO,gBAAAA,KAAC,SAAI,WAAU,+BAA+B,UAAS;AAChE;;;ACDS,gBAAAC,aAAA;AADF,SAAS,WAAW,EAAE,SAAS,GAA4B;AAChE,SAAO,gBAAAA,MAAC,SAAI,WAAU,yBAAyB,UAAS;AAC1D;;;ACDS,gBAAAC,aAAA;AADF,SAAS,cAAc,EAAE,SAAS,GAA4B;AACnE,SAAO,gBAAAA,MAAC,SAAI,WAAU,iCAAiC,UAAS;AAClE;","names":["jsx","jsxs","jsx","jsx","jsx","jsx","jsx","jsxs","jsx","jsx","jsx","jsx"]}
1
+ {"version":3,"sources":["../src/components/Body.tsx","../src/components/Button.tsx","../src/components/Footer.tsx","../src/components/Header.tsx","../src/components/HeaderText.tsx","../src/components/NpmBadge.tsx","../src/components/navigation/Navigation.tsx","../src/components/navigation/NavigationItem.tsx","../src/components/notifications/Notifications.tsx","../src/components/notifications/NotificationsProvider.tsx","../src/components/wrappers/ContentContainer.tsx","../src/components/wrappers/ContentRow.tsx","../src/components/wrappers/LayoutWrapper.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\r\n\r\ninterface BodyProps {\r\n title: ReactNode;\r\n description?: ReactNode;\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Body({ title, description, children }: BodyProps) {\r\n return (\r\n <main className=\"col p-4\">\r\n <h2>{title}</h2>\r\n\r\n {description && <p>{description}</p>}\r\n {children}\r\n </main>\r\n );\r\n}\r\n","import { useState, type ReactNode, type MouseEvent } from \"react\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface FooterProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Footer({ children }: FooterProps) {\r\n return (\r\n <footer className=\"bg-dark text-white text-center py-2 mt-auto\">\r\n {children ?? \"© 2025 Your Site — All rights reserved\"}\r\n </footer>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderProps {\r\n children?: ReactNode;\r\n}\r\n\r\nexport function Header({ children }: HeaderProps) {\r\n return (\r\n <nav className=\"navbar navbar-dark bg-dark px-3 sticky-top\">\r\n {children ?? (\r\n <span className=\"navbar-brand mb-0 h4\">My Website</span>\r\n )}\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface HeaderBrandProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function HeaderText({ children }: HeaderBrandProps) {\r\n return (\r\n <span className=\"navbar-brand mb-0 h4\">\r\n {children}\r\n </span>\r\n );\r\n}\r\n","// components/NpmBadge.tsx\r\ninterface NpmBadgeProps {\r\n packageLabel: string;\r\n packageName: string;\r\n packageUrl: string; // e.g. \"@sparkstudio/authentication-ui\"\r\n color?: string; // optional (default black)\r\n height?: number; // optional (default 22)\r\n}\r\n\r\nexport function NpmBadge({ packageName, packageLabel, packageUrl, color = \"black\", height = 22 }: NpmBadgeProps) {\r\n const encodedLabel = encodeURIComponent(packageLabel);\r\n const badgeUrl = `https://img.shields.io/npm/v/${packageName}?logo=npm&label=${encodedLabel}&color=${color}`;\r\n const npmUrl = packageUrl;\r\n\r\n return (\r\n <a href={npmUrl} target=\"_blank\" rel=\"noopener noreferrer\">\r\n <img src={badgeUrl} alt={`${packageName} version`} style={{ height }} />\r\n </a>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationProps {\r\n title?: ReactNode;\r\n children: ReactNode;\r\n}\r\n\r\nexport function Navigation({ title = \"Navigation\", children }: NavigationProps) {\r\n return (\r\n <nav className=\"col-auto p-3 h-100 d-flex flex-column\">\r\n <h6 className=\"text-muted text-uppercase\">{title}</h6>\r\n\r\n <ul className=\"nav nav-pills flex-column gap-2 mt-3\">\r\n {children}\r\n </ul>\r\n </nav>\r\n );\r\n}\r\n","import type { ReactNode } from \"react\";\r\n\r\ninterface NavigationItemProps {\r\n title: ReactNode;\r\n type: string;\r\n active?: boolean;\r\n onClick?: (type: string) => void;\r\n}\r\n\r\nexport function NavigationItem({ title, type, active, onClick }: NavigationItemProps) {\r\n return (\r\n <li className=\"nav-item\">\r\n <button\r\n type=\"button\"\r\n className={`nav-link text-start w-100 ${active ? \"active\" : \"\"}`}\r\n onClick={() => onClick?.(type)}\r\n >\r\n {title}\r\n </button>\r\n </li>\r\n );\r\n}\r\n","import { useEffect } from \"react\";\r\n\r\nexport type NotificationType = \"success\" | \"info\" | \"warning\" | \"danger\";\r\n\r\nexport interface Notification {\r\n id: string;\r\n message: string;\r\n type?: NotificationType;\r\n autoCloseMs?: number;\r\n}\r\n\r\ninterface NotificationsProps {\r\n notifications: Notification[];\r\n onClose: (id: string) => void;\r\n}\r\n\r\nexport function Notifications({ notifications, onClose }: NotificationsProps) {\r\n useEffect(() => {\r\n notifications.forEach((n) => {\r\n if (!n.autoCloseMs) return;\r\n\r\n const timer = setTimeout(() => onClose(n.id), n.autoCloseMs);\r\n return () => clearTimeout(timer);\r\n });\r\n }, [notifications, onClose]);\r\n\r\n return (\r\n <div\r\n className=\"position-fixed top-0 end-0 p-3\"\r\n style={{ zIndex: 1080, width: 340 }}\r\n >\r\n {notifications.map((n) => (\r\n <div\r\n key={n.id}\r\n className={`alert alert-${n.type ?? \"info\"} alert-dismissible fade show shadow-sm mb-2`}\r\n role=\"alert\"\r\n >\r\n {n.message}\r\n\r\n <button\r\n type=\"button\"\r\n className=\"btn-close\"\r\n aria-label=\"Close\"\r\n onClick={() => onClose(n.id)}\r\n />\r\n </div>\r\n ))}\r\n </div>\r\n );\r\n}\r\n","import {\r\n createContext,\r\n useCallback,\r\n useContext,\r\n useEffect,\r\n useState,\r\n type ReactNode,\r\n} from \"react\";\r\n\r\nexport type NotificationType = \"success\" | \"info\" | \"warning\" | \"danger\";\r\n\r\n// Rename to avoid conflict with browser Notification type\r\nexport interface AppNotification {\r\n id: string;\r\n message: string;\r\n type?: NotificationType;\r\n autoCloseMs?: number;\r\n}\r\n\r\ninterface NotificationsContextValue {\r\n push: (message: string, type?: NotificationType, autoCloseMs?: number) => void;\r\n}\r\n\r\nconst NotificationsContext = createContext<NotificationsContextValue | undefined>(\r\n undefined\r\n);\r\n\r\ninterface NotificationsProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\nexport function NotificationsProvider({ children }: NotificationsProviderProps) {\r\n const [notifications, setNotifications] = useState<AppNotification[]>([]);\r\n\r\n const push = useCallback(\r\n (message: string, type: NotificationType = \"info\", autoCloseMs = 4000) => {\r\n setNotifications((prev) => [\r\n ...prev,\r\n {\r\n id: crypto.randomUUID(),\r\n message,\r\n type,\r\n autoCloseMs,\r\n },\r\n ]);\r\n },\r\n []\r\n );\r\n\r\n const close = useCallback((id: string) => {\r\n setNotifications((list) => list.filter((n) => n.id !== id));\r\n }, []);\r\n\r\n // Handle auto close timers\r\n useEffect(() => {\r\n const timers = notifications.map((n) => {\r\n if (!n.autoCloseMs) return null;\r\n return setTimeout(() => close(n.id), n.autoCloseMs);\r\n });\r\n\r\n return () => {\r\n timers.forEach((t) => t && clearTimeout(t));\r\n };\r\n }, [notifications, close]);\r\n\r\n return (\r\n <NotificationsContext.Provider value={{ push }}>\r\n {/* overlay renderer */}\r\n <div\r\n className=\"position-fixed top-0 end-0 p-3\"\r\n style={{ zIndex: 1080, width: 340 }}\r\n >\r\n {notifications.map((n) => (\r\n <div\r\n key={n.id}\r\n className={`alert alert-${n.type ?? \"info\"} alert-dismissible fade show shadow-sm mb-2`}\r\n role=\"alert\"\r\n >\r\n {n.message}\r\n <button\r\n type=\"button\"\r\n className=\"btn-close\"\r\n aria-label=\"Close\"\r\n onClick={() => close(n.id)}\r\n />\r\n </div>\r\n ))}\r\n </div>\r\n\r\n {children}\r\n </NotificationsContext.Provider>\r\n );\r\n}\r\n\r\nexport function UseNotifications(): NotificationsContextValue {\r\n const ctx = useContext(NotificationsContext);\r\n if (!ctx) {\r\n throw new Error(\"useNotifications must be used within a NotificationsProvider\");\r\n }\r\n return ctx;\r\n}\r\n","export function ContentContainer({ children }: React.PropsWithChildren) {\r\n return <div className=\"container-fluid flex-grow-1\">{children}</div>;\r\n}\r\n","export function ContentRow({ children }: React.PropsWithChildren) {\r\n return <div className=\"row h-100 flex-nowrap\">{children}</div>;\r\n}\r\n","export function LayoutWrapper({ children }: React.PropsWithChildren) {\r\n return <div className=\"d-flex flex-column min-vh-100\">{children}</div>;\r\n}\r\n"],"mappings":";AAUI,SACE,KADF;AAFG,SAAS,KAAK,EAAE,OAAO,aAAa,SAAS,GAAc;AAChE,SACE,qBAAC,UAAK,WAAU,WACd;AAAA,wBAAC,QAAI,iBAAM;AAAA,IAEV,eAAe,oBAAC,OAAG,uBAAY;AAAA,IAC/B;AAAA,KACH;AAEJ;;;ACjBA,SAAS,gBAAiD;AA0EhD,mBAEI,OAAAA,MAFJ,QAAAC,aAAA;AAnDH,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AAAA,EACd,cAAc;AAChB,GAAgB;AACd,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,cAAc,OAAO,UAAyC;AAClE,QAAI,QAAS;AAEb,cAAU,KAAK;AACf,QAAI,MA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@
1
1
  {
2
2
  "name": "@sparkstudio/common-ui",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
package/dist/index.css DELETED
@@ -1,3 +0,0 @@
1
- @import "/node_modules/bootstrap/dist/css/bootstrap.css";
2
-
3
- /*# sourceMappingURL=index.css.map */
@@ -1 +0,0 @@
1
- {"version":3,"sourceRoot":"","sources":["../src/index.scss"],"names":[],"mappings":"AAAQ","file":"index.css"}
package/dist/index.d.cts DELETED
@@ -1,73 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, MouseEvent } from 'react';
3
-
4
- interface BodyProps {
5
- title: ReactNode;
6
- description?: ReactNode;
7
- children?: ReactNode;
8
- }
9
- declare function Body({ title, description, children }: BodyProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface ButtonProps {
12
- buttonClassName?: string;
13
- type?: "button" | "submit" | "reset";
14
- disabled?: boolean;
15
- onAction?: () => Promise<unknown>;
16
- onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
17
- onDone?: (result: unknown) => void;
18
- onError?: (error: unknown) => void;
19
- onFinally?: () => void;
20
- children?: ReactNode;
21
- loadingChildren?: ReactNode;
22
- renderContent?: () => ReactNode;
23
- renderLoading?: () => ReactNode;
24
- loadingText?: string;
25
- showSpinner?: boolean;
26
- }
27
- declare function Button({ buttonClassName, type, disabled, onAction, onClick, onDone, onError, onFinally, children, loadingChildren, renderContent, renderLoading, loadingText, showSpinner, }: ButtonProps): react_jsx_runtime.JSX.Element;
28
-
29
- interface FooterProps {
30
- children?: ReactNode;
31
- }
32
- declare function Footer({ children }: FooterProps): react_jsx_runtime.JSX.Element;
33
-
34
- interface HeaderProps {
35
- children?: ReactNode;
36
- }
37
- declare function Header({ children }: HeaderProps): react_jsx_runtime.JSX.Element;
38
-
39
- interface HeaderBrandProps {
40
- children: ReactNode;
41
- }
42
- declare function HeaderText({ children }: HeaderBrandProps): react_jsx_runtime.JSX.Element;
43
-
44
- interface NpmBadgeProps {
45
- packageLabel: string;
46
- packageName: string;
47
- packageUrl: string;
48
- color?: string;
49
- height?: number;
50
- }
51
- declare function NpmBadge({ packageName, packageLabel, packageUrl, color, height }: NpmBadgeProps): react_jsx_runtime.JSX.Element;
52
-
53
- interface NavigationProps {
54
- title?: ReactNode;
55
- children: ReactNode;
56
- }
57
- declare function Navigation({ title, children }: NavigationProps): react_jsx_runtime.JSX.Element;
58
-
59
- interface NavigationItemProps {
60
- title: ReactNode;
61
- type: string;
62
- active?: boolean;
63
- onClick?: (type: string) => void;
64
- }
65
- declare function NavigationItem({ title, type, active, onClick }: NavigationItemProps): react_jsx_runtime.JSX.Element;
66
-
67
- declare function ContentContainer({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
68
-
69
- declare function ContentRow({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
70
-
71
- declare function LayoutWrapper({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
72
-
73
- export { Body, Button, type ButtonProps, ContentContainer, ContentRow, Footer, Header, HeaderText, LayoutWrapper, Navigation, NavigationItem, NpmBadge };
package/dist/index.d.ts DELETED
@@ -1,73 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, MouseEvent } from 'react';
3
-
4
- interface BodyProps {
5
- title: ReactNode;
6
- description?: ReactNode;
7
- children?: ReactNode;
8
- }
9
- declare function Body({ title, description, children }: BodyProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface ButtonProps {
12
- buttonClassName?: string;
13
- type?: "button" | "submit" | "reset";
14
- disabled?: boolean;
15
- onAction?: () => Promise<unknown>;
16
- onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
17
- onDone?: (result: unknown) => void;
18
- onError?: (error: unknown) => void;
19
- onFinally?: () => void;
20
- children?: ReactNode;
21
- loadingChildren?: ReactNode;
22
- renderContent?: () => ReactNode;
23
- renderLoading?: () => ReactNode;
24
- loadingText?: string;
25
- showSpinner?: boolean;
26
- }
27
- declare function Button({ buttonClassName, type, disabled, onAction, onClick, onDone, onError, onFinally, children, loadingChildren, renderContent, renderLoading, loadingText, showSpinner, }: ButtonProps): react_jsx_runtime.JSX.Element;
28
-
29
- interface FooterProps {
30
- children?: ReactNode;
31
- }
32
- declare function Footer({ children }: FooterProps): react_jsx_runtime.JSX.Element;
33
-
34
- interface HeaderProps {
35
- children?: ReactNode;
36
- }
37
- declare function Header({ children }: HeaderProps): react_jsx_runtime.JSX.Element;
38
-
39
- interface HeaderBrandProps {
40
- children: ReactNode;
41
- }
42
- declare function HeaderText({ children }: HeaderBrandProps): react_jsx_runtime.JSX.Element;
43
-
44
- interface NpmBadgeProps {
45
- packageLabel: string;
46
- packageName: string;
47
- packageUrl: string;
48
- color?: string;
49
- height?: number;
50
- }
51
- declare function NpmBadge({ packageName, packageLabel, packageUrl, color, height }: NpmBadgeProps): react_jsx_runtime.JSX.Element;
52
-
53
- interface NavigationProps {
54
- title?: ReactNode;
55
- children: ReactNode;
56
- }
57
- declare function Navigation({ title, children }: NavigationProps): react_jsx_runtime.JSX.Element;
58
-
59
- interface NavigationItemProps {
60
- title: ReactNode;
61
- type: string;
62
- active?: boolean;
63
- onClick?: (type: string) => void;
64
- }
65
- declare function NavigationItem({ title, type, active, onClick }: NavigationItemProps): react_jsx_runtime.JSX.Element;
66
-
67
- declare function ContentContainer({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
68
-
69
- declare function ContentRow({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
70
-
71
- declare function LayoutWrapper({ children }: React.PropsWithChildren): react_jsx_runtime.JSX.Element;
72
-
73
- export { Body, Button, type ButtonProps, ContentContainer, ContentRow, Footer, Header, HeaderText, LayoutWrapper, Navigation, NavigationItem, NpmBadge };