@-reddacted-/react-ui 0.2.2 → 0.2.4
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.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/popup/PopupProvider.d.ts +4 -2
- package/dist/popup/PopupProvider.d.ts.map +1 -1
- package/dist/popup/PopupProvider.js +6 -1
- package/dist/popup/errorRules.d.ts +11 -0
- package/dist/popup/errorRules.d.ts.map +1 -1
- package/dist/popup/fetchInterceptor.d.ts +6 -1
- package/dist/popup/fetchInterceptor.d.ts.map +1 -1
- package/dist/popup/fetchInterceptor.js +15 -3
- package/dist/theme/clipboard.d.ts +1 -0
- package/dist/theme/clipboard.d.ts.map +1 -1
- package/dist/theme/clipboard.js +5 -8
- package/dist/theme/palette.d.ts +0 -9
- package/dist/theme/palette.d.ts.map +1 -1
- package/dist/theme/palette.js +4 -61
- package/package.json +34 -34
package/dist/index.d.ts
CHANGED
|
@@ -7,14 +7,14 @@ export { NavBar, type NavLink } from "./components/NavBar.js";
|
|
|
7
7
|
export { PageMessage, LoadingMessage, ErrorMessage } from "./components/PageStatus.js";
|
|
8
8
|
export { ThemeProvider, useTheme } from "./theme/ThemeProvider.js";
|
|
9
9
|
export { ThemeSelect } from "./theme/ThemeSelect.js";
|
|
10
|
-
export { defaultPalette
|
|
10
|
+
export { defaultPalette } from "./theme/palette.js";
|
|
11
11
|
export { createLocalThemeStore, createHttpThemeStore, type ThemeStore } from "./theme/store.js";
|
|
12
12
|
export { serializeColors, parseColors, isHexColor, randomHex } from "./theme/clipboard.js";
|
|
13
13
|
export type { ThemeColors, ThemeDefinition, ThemeCatalog, ThemeDraft } from "./theme/types.js";
|
|
14
14
|
export { PopupProvider } from "./popup/PopupProvider.js";
|
|
15
15
|
export { PopupHost } from "./popup/PopupHost.js";
|
|
16
16
|
export { createInterceptedFetch, type InterceptorHandlers } from "./popup/fetchInterceptor.js";
|
|
17
|
-
export { createErrorRules, defaultMessages, type ErrorRules, type ErrorRulesOptions, type PopupMessages, } from "./popup/errorRules.js";
|
|
17
|
+
export { createErrorRules, defaultMessages, type ErrorRules, type ErrorRulesOptions, type PopupMessages, type FetchErrorReport, } from "./popup/errorRules.js";
|
|
18
18
|
export { fetchJson } from "./net/fetchJson.js";
|
|
19
19
|
export { useDocumentTitle, useAsync, useElementSize, useClickOutside, useEscapeKey } from "@-reddacted-/react-hooks";
|
|
20
20
|
export type { AsyncStatus, AsyncStatus as LoadStatus, AsyncResult, ElementSize } from "@-reddacted-/react-hooks";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAC/E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEtF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,SA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9C,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACpH,YAAY,EAAE,WAAW,EAAE,WAAW,IAAI,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { NavBar } from "./components/NavBar.js";
|
|
|
7
7
|
export { PageMessage, LoadingMessage, ErrorMessage } from "./components/PageStatus.js";
|
|
8
8
|
export { ThemeProvider, useTheme } from "./theme/ThemeProvider.js";
|
|
9
9
|
export { ThemeSelect } from "./theme/ThemeSelect.js";
|
|
10
|
-
export { defaultPalette
|
|
10
|
+
export { defaultPalette } from "./theme/palette.js";
|
|
11
11
|
export { createLocalThemeStore, createHttpThemeStore } from "./theme/store.js";
|
|
12
12
|
export { serializeColors, parseColors, isHexColor, randomHex } from "./theme/clipboard.js";
|
|
13
13
|
export { PopupProvider } from "./popup/PopupProvider.js";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { ErrorRulesOptions } from "./errorRules.js";
|
|
2
|
+
import type { ErrorRulesOptions, FetchErrorReport } from "./errorRules.js";
|
|
3
3
|
type PopupProviderProps = ErrorRulesOptions & {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
closeLabel?: string;
|
|
6
|
+
/** Called for every failure the popup shows, with the method, URL and status behind it. */
|
|
7
|
+
onReport?: (report: FetchErrorReport) => void;
|
|
6
8
|
};
|
|
7
|
-
export declare function PopupProvider({ children, closeLabel, ...ruleOptions }: PopupProviderProps): import("react").JSX.Element;
|
|
9
|
+
export declare function PopupProvider({ children, closeLabel, onReport, ...ruleOptions }: PopupProviderProps): import("react").JSX.Element;
|
|
8
10
|
export {};
|
|
9
11
|
//# sourceMappingURL=PopupProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopupProvider.d.ts","sourceRoot":"","sources":["../../src/popup/PopupProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"PopupProvider.d.ts","sourceRoot":"","sources":["../../src/popup/PopupProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAc,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAMtF,KAAK,kBAAkB,GAAG,iBAAiB,GAAG;IAC5C,QAAQ,EAAE,SAAS,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC9C,CAAA;AAED,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,EAAE,kBAAkB,+BAwCnG"}
|
|
@@ -3,8 +3,12 @@ import { useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import { createErrorRules } from "./errorRules.js";
|
|
4
4
|
import { createInterceptedFetch } from "./fetchInterceptor.js";
|
|
5
5
|
import { PopupHost } from "./PopupHost.js";
|
|
6
|
-
export function PopupProvider({ children, closeLabel, ...ruleOptions }) {
|
|
6
|
+
export function PopupProvider({ children, closeLabel, onReport, ...ruleOptions }) {
|
|
7
7
|
const [messages, setMessages] = useState([]);
|
|
8
|
+
// L'interception ne s'installe qu'une fois : le callback, lui, peut changer d'un rendu à
|
|
9
|
+
// l'autre sans avoir à la réinstaller.
|
|
10
|
+
const reportRef = useRef(onReport);
|
|
11
|
+
reportRef.current = onReport;
|
|
8
12
|
// Les options arrivent en littéraux : les garder dans un ref évite de réinstaller
|
|
9
13
|
// l'interception à chaque rendu du parent.
|
|
10
14
|
const rulesRef = useRef(null);
|
|
@@ -17,6 +21,7 @@ export function PopupProvider({ children, closeLabel, ...ruleOptions }) {
|
|
|
17
21
|
const intercepted = createInterceptedFetch(original, {
|
|
18
22
|
onRequestStart: () => setMessages(current => (current.length === 0 ? current : [])),
|
|
19
23
|
onError: message => setMessages(current => (current.includes(message) ? current : [...current, message])),
|
|
24
|
+
onReport: report => reportRef.current?.(report),
|
|
20
25
|
}, rulesRef.current);
|
|
21
26
|
intercepted.__popupIntercepted = true;
|
|
22
27
|
window.fetch = intercepted;
|
|
@@ -6,6 +6,17 @@ export type PopupMessages = {
|
|
|
6
6
|
requestFailed: (status: number) => string;
|
|
7
7
|
};
|
|
8
8
|
export declare const defaultMessages: PopupMessages;
|
|
9
|
+
/** What a failed request carried, for callers that record failures instead of only showing them. */
|
|
10
|
+
export type FetchErrorReport = {
|
|
11
|
+
/** The message shown to the user, already humanised by the rules. */
|
|
12
|
+
message: string;
|
|
13
|
+
method: string;
|
|
14
|
+
url: string;
|
|
15
|
+
/** Absent when the request never reached a response. */
|
|
16
|
+
status?: number;
|
|
17
|
+
/** The thrown cause, when the failure was a network one. */
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
};
|
|
9
20
|
export type ErrorRulesOptions = {
|
|
10
21
|
/** Statuses that never raise a popup. Form input errors by default. */
|
|
11
22
|
ignoredStatuses?: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorRules.d.ts","sourceRoot":"","sources":["../../src/popup/errorRules.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;CAC1C,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,aAM7B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AuE;IACvE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,oBAAoB,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAA;IAChD,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;IAChD,gBAAgB,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACrD,CAAA;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAkC5E"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { ErrorRules } from "./errorRules.js";
|
|
1
|
+
import type { ErrorRules, FetchErrorReport } from "./errorRules.js";
|
|
2
2
|
export type InterceptorHandlers = {
|
|
3
3
|
onRequestStart: () => void;
|
|
4
4
|
onError: (message: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Called for the same failures as `onError`, with what the request itself carried. A popup only
|
|
7
|
+
* needs a sentence; a caller that records failures needs the method, the URL and the status.
|
|
8
|
+
*/
|
|
9
|
+
onReport?: (report: FetchErrorReport) => void;
|
|
5
10
|
};
|
|
6
11
|
export declare function createInterceptedFetch(original: typeof fetch, handlers: InterceptorHandlers, rules: ErrorRules): typeof fetch;
|
|
7
12
|
//# sourceMappingURL=fetchInterceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchInterceptor.d.ts","sourceRoot":"","sources":["../../src/popup/fetchInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"fetchInterceptor.d.ts","sourceRoot":"","sources":["../../src/popup/fetchInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEnE,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC9C,CAAA;AAQD,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,OAAO,KAAK,EACtB,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,UAAU,GAChB,OAAO,KAAK,CAmBd"}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
function describeRequest(input, init) {
|
|
2
|
+
if (typeof input === "string")
|
|
3
|
+
return { url: input, method: init?.method ?? "GET" };
|
|
4
|
+
if (input instanceof URL)
|
|
5
|
+
return { url: input.href, method: init?.method ?? "GET" };
|
|
6
|
+
return { url: input.url, method: init?.method ?? input.method ?? "GET" };
|
|
7
|
+
}
|
|
1
8
|
export function createInterceptedFetch(original, handlers, rules) {
|
|
2
9
|
return async (input, init) => {
|
|
3
10
|
handlers.onRequestStart();
|
|
4
11
|
try {
|
|
5
12
|
const res = await original(input, init);
|
|
6
|
-
if (rules.shouldReportResponse(res))
|
|
7
|
-
|
|
13
|
+
if (rules.shouldReportResponse(res)) {
|
|
14
|
+
const message = await rules.describeResponse(res);
|
|
15
|
+
handlers.onError(message);
|
|
16
|
+
handlers.onReport?.({ ...describeRequest(input, init), message, status: res.status });
|
|
17
|
+
}
|
|
8
18
|
return res;
|
|
9
19
|
}
|
|
10
20
|
catch (cause) {
|
|
11
|
-
if (rules.shouldReportFailure(cause))
|
|
21
|
+
if (rules.shouldReportFailure(cause)) {
|
|
12
22
|
handlers.onError(rules.networkFailureMessage);
|
|
23
|
+
handlers.onReport?.({ ...describeRequest(input, init), message: rules.networkFailureMessage, cause });
|
|
24
|
+
}
|
|
13
25
|
throw cause;
|
|
14
26
|
}
|
|
15
27
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ThemeColors } from "./types.js";
|
|
2
2
|
export declare function serializeColors(colors: ThemeColors): string;
|
|
3
|
+
/** Reads every `--name: #rrggbb` declaration. Filtering is left to the caller. */
|
|
3
4
|
export declare function parseColors(text: string): ThemeColors;
|
|
4
5
|
export declare function isHexColor(value: string): boolean;
|
|
5
6
|
export declare function randomHex(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/theme/clipboard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/theme/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK7C,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAG3D;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAMrD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,SAAS,IAAI,MAAM,CAOlC"}
|
package/dist/theme/clipboard.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { themeVariableKeys } from "./palette.js";
|
|
2
1
|
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
2
|
+
const DECLARATION = /(--[a-zA-Z0-9-]+)\s*:\s*(#[0-9a-fA-F]{6})/g;
|
|
3
3
|
export function serializeColors(colors) {
|
|
4
|
-
const lines =
|
|
5
|
-
.filter(key => colors[key])
|
|
6
|
-
.map(key => ` ${key}: ${colors[key]};`);
|
|
4
|
+
const lines = Object.entries(colors).map(([key, value]) => ` ${key}: ${value};`);
|
|
7
5
|
return `:root {\n${lines.join("\n")}\n}`;
|
|
8
6
|
}
|
|
7
|
+
/** Reads every `--name: #rrggbb` declaration. Filtering is left to the caller. */
|
|
9
8
|
export function parseColors(text) {
|
|
10
9
|
const parsed = {};
|
|
11
|
-
for (const key of
|
|
12
|
-
|
|
13
|
-
if (match)
|
|
14
|
-
parsed[key] = match[1];
|
|
10
|
+
for (const [, key, value] of text.matchAll(DECLARATION)) {
|
|
11
|
+
parsed[key] = value;
|
|
15
12
|
}
|
|
16
13
|
return parsed;
|
|
17
14
|
}
|
package/dist/theme/palette.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import type { ThemeColors } from "./types.js";
|
|
2
2
|
export declare const defaultPalette: ThemeColors;
|
|
3
|
-
export type ThemeVariableGroup = {
|
|
4
|
-
label: string;
|
|
5
|
-
variables: Array<{
|
|
6
|
-
key: string;
|
|
7
|
-
label: string;
|
|
8
|
-
}>;
|
|
9
|
-
};
|
|
10
|
-
export declare const themeVariableGroups: ThemeVariableGroup[];
|
|
11
|
-
export declare const themeVariableKeys: string[];
|
|
12
3
|
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/theme/palette.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/theme/palette.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK7C,eAAO,MAAM,cAAc,EAAE,WAW5B,CAAA"}
|
package/dist/theme/palette.js
CHANGED
|
@@ -1,72 +1,15 @@
|
|
|
1
|
+
// Base vocabulary: every variable the components in this package read, plus the
|
|
2
|
+
// hover shade a consumer is expected to theme. A project with its own vocabulary
|
|
3
|
+
// extends this and passes the result to ThemeProvider as basePalette.
|
|
1
4
|
export const defaultPalette = {
|
|
2
5
|
"--color-bg": "#ffffff",
|
|
3
6
|
"--color-surface": "#f8fafc",
|
|
7
|
+
"--color-border": "#e2e8f0",
|
|
4
8
|
"--color-text": "#1a1a1a",
|
|
5
9
|
"--color-text-muted": "#64748b",
|
|
6
10
|
"--color-primary": "#6366f1",
|
|
7
11
|
"--color-primary-hover": "#4f46e5",
|
|
8
12
|
"--color-on-primary": "#ffffff",
|
|
9
|
-
"--color-primary-soft": "#e0e7ff",
|
|
10
|
-
"--color-border": "#e2e8f0",
|
|
11
13
|
"--color-danger": "#dc2626",
|
|
12
14
|
"--color-danger-soft": "#fee2e2",
|
|
13
|
-
"--color-mindmap-red": "#dc2626",
|
|
14
|
-
"--color-mindmap-red-soft": "#fee2e2",
|
|
15
|
-
"--color-mindmap-orange": "#ea580c",
|
|
16
|
-
"--color-mindmap-orange-soft": "#ffedd5",
|
|
17
|
-
"--color-mindmap-green": "#16a34a",
|
|
18
|
-
"--color-mindmap-green-soft": "#dcfce7",
|
|
19
|
-
"--color-mindmap-blue": "#2563eb",
|
|
20
|
-
"--color-mindmap-blue-soft": "#dbeafe",
|
|
21
|
-
"--color-mindmap-purple": "#9333ea",
|
|
22
|
-
"--color-mindmap-purple-soft": "#f3e8ff",
|
|
23
15
|
};
|
|
24
|
-
export const themeVariableGroups = [
|
|
25
|
-
{
|
|
26
|
-
label: "Surfaces",
|
|
27
|
-
variables: [
|
|
28
|
-
{ key: "--color-bg", label: "Background" },
|
|
29
|
-
{ key: "--color-surface", label: "Surface" },
|
|
30
|
-
{ key: "--color-border", label: "Border" },
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
label: "Text",
|
|
35
|
-
variables: [
|
|
36
|
-
{ key: "--color-text", label: "Text" },
|
|
37
|
-
{ key: "--color-text-muted", label: "Muted text" },
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
label: "Primary",
|
|
42
|
-
variables: [
|
|
43
|
-
{ key: "--color-primary", label: "Primary" },
|
|
44
|
-
{ key: "--color-primary-hover", label: "Primary (hover)" },
|
|
45
|
-
{ key: "--color-on-primary", label: "On primary" },
|
|
46
|
-
{ key: "--color-primary-soft", label: "Primary (soft)" },
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
label: "Danger",
|
|
51
|
-
variables: [
|
|
52
|
-
{ key: "--color-danger", label: "Danger" },
|
|
53
|
-
{ key: "--color-danger-soft", label: "Danger (soft)" },
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
label: "Mindmap",
|
|
58
|
-
variables: [
|
|
59
|
-
{ key: "--color-mindmap-red", label: "Red" },
|
|
60
|
-
{ key: "--color-mindmap-red-soft", label: "Red (soft)" },
|
|
61
|
-
{ key: "--color-mindmap-orange", label: "Orange" },
|
|
62
|
-
{ key: "--color-mindmap-orange-soft", label: "Orange (soft)" },
|
|
63
|
-
{ key: "--color-mindmap-green", label: "Green" },
|
|
64
|
-
{ key: "--color-mindmap-green-soft", label: "Green (soft)" },
|
|
65
|
-
{ key: "--color-mindmap-blue", label: "Blue" },
|
|
66
|
-
{ key: "--color-mindmap-blue-soft", label: "Blue (soft)" },
|
|
67
|
-
{ key: "--color-mindmap-purple", label: "Purple" },
|
|
68
|
-
{ key: "--color-mindmap-purple-soft", label: "Purple (soft)" },
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
export const themeVariableKeys = themeVariableGroups.flatMap(group => group.variables.map(variable => variable.key));
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@-reddacted-/react-ui",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Theming system, Modal, Button, ColorPicker, NavBar and fetch error popups for React",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/index.js",
|
|
11
|
-
"types": "./dist/index.d.ts"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsc",
|
|
19
|
-
"typecheck": "tsc --noEmit"
|
|
20
|
-
},
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"react": ">=18",
|
|
23
|
-
"react-dom": ">=18"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"react-colorful": "^5.6.1",
|
|
27
|
-
"@-reddacted-/react-hooks": "^0.2.0"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@types/react": "^18.3.1",
|
|
31
|
-
"@types/react-dom": "^18.3.1",
|
|
32
|
-
"typescript": "~5.8.3"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@-reddacted-/react-ui",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "Theming system, Modal, Button, ColorPicker, NavBar and fetch error popups for React",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"typecheck": "tsc --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"react-dom": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"react-colorful": "^5.6.1",
|
|
27
|
+
"@-reddacted-/react-hooks": "^0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^18.3.1",
|
|
31
|
+
"@types/react-dom": "^18.3.1",
|
|
32
|
+
"typescript": "~5.8.3"
|
|
33
|
+
}
|
|
34
|
+
}
|