@siratik/wp-component-library 0.0.0-stage → 0.1.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.
- package/README.md +249 -2
- package/build/index.asset.php +20 -0
- package/build/index.js +1233 -0
- package/constants/adminColors.js +42 -0
- package/constants/statusColors.js +199 -0
- package/package.json +46 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin colours by role.
|
|
3
|
+
*
|
|
4
|
+
* Each value reads WordPress's design tokens (`--wpds-color-*`, WP 7.1+) or
|
|
5
|
+
* the admin theme colour, then a fixed fallback. kitaris-dashboard maps its
|
|
6
|
+
* palette and whitelabel colours onto those tokens, so screens follow the
|
|
7
|
+
* brand when it is active and WordPress's defaults when it is not.
|
|
8
|
+
*
|
|
9
|
+
* @package WPComponentLibrary
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Neutral and brand colours. */
|
|
13
|
+
export const ADMIN_COLOR = {
|
|
14
|
+
/** Body text and icons. */
|
|
15
|
+
text: "var(--wpds-color-foreground-content-neutral, #333333)",
|
|
16
|
+
/** Muted text, secondary icons. */
|
|
17
|
+
muted: "var(--wpds-color-foreground-content-neutral-weak, #757575)",
|
|
18
|
+
/** Cards and panels. */
|
|
19
|
+
surface: "var(--wpds-color-background-surface-neutral-strong, #ffffff)",
|
|
20
|
+
/** Subtle panels, hover rows, placeholders. */
|
|
21
|
+
surfaceSubtle: "var(--wpds-color-background-surface-neutral-weak, #f0f0f0)",
|
|
22
|
+
/** Page-level background. */
|
|
23
|
+
page: "var(--wpds-color-background-surface-neutral, rgb(247, 247, 247))",
|
|
24
|
+
/** Borders. */
|
|
25
|
+
border: "var(--wpds-color-stroke-surface-neutral, rgb(217, 219, 222))",
|
|
26
|
+
/** Dividers and faint borders. */
|
|
27
|
+
borderSubtle: "var(--wpds-color-stroke-surface-neutral-weak, #f0f0f0)",
|
|
28
|
+
/** Brand text, links and icons. */
|
|
29
|
+
brand: "var(--wpds-color-foreground-interactive-brand, var(--wp-admin-theme-color, #3858e9))",
|
|
30
|
+
/** Brand fills (buttons, bars, active states). */
|
|
31
|
+
brandFill:
|
|
32
|
+
"var(--wpds-color-background-interactive-brand-strong, var(--wp-admin-theme-color, #3858e9))",
|
|
33
|
+
/** Hovered brand fills. */
|
|
34
|
+
brandFillHover:
|
|
35
|
+
"var(--wpds-color-background-interactive-brand-strong-active, var(--wp-admin-theme-color-darker-10, #2145e6))",
|
|
36
|
+
/** Brand borders and outlines. */
|
|
37
|
+
brandStroke: "var(--wpds-color-stroke-interactive-brand, var(--wp-admin-theme-color, #3858e9))",
|
|
38
|
+
/** Text and icons on a brand fill. */
|
|
39
|
+
onBrand: "var(--wpds-color-foreground-interactive-brand-strong, #ffffff)",
|
|
40
|
+
/** Second chart series and secondary accents (no core token). */
|
|
41
|
+
secondary: "var(--kitaris-admin-color-secondary, #0F9C90)",
|
|
42
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status colours for Kitaris admin surfaces.
|
|
3
|
+
*
|
|
4
|
+
* Each value reads WordPress's design tokens (`--wpds-color-*`, WP 7.1+),
|
|
5
|
+
* then a fixed fallback. kitaris-dashboard maps its status colours onto those
|
|
6
|
+
* tokens. Warning uses core's `caution` family, as core's Notice does.
|
|
7
|
+
*
|
|
8
|
+
* @package WPComponentLibrary
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { ADMIN_COLOR } from "./adminColors";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fixed fallbacks (kitaris-dashboard's default status colours).
|
|
15
|
+
*
|
|
16
|
+
* @type {Record<string, Record<'base' | 'light' | 'dark', string>>}
|
|
17
|
+
*/
|
|
18
|
+
export const STATUS_COLOR_FALLBACKS = {
|
|
19
|
+
success: {
|
|
20
|
+
base: "#4ab866",
|
|
21
|
+
light: "#edfaef",
|
|
22
|
+
dark: "#007017",
|
|
23
|
+
},
|
|
24
|
+
warning: {
|
|
25
|
+
base: "#f0b849",
|
|
26
|
+
light: "#fef8e6",
|
|
27
|
+
dark: "#b26200",
|
|
28
|
+
},
|
|
29
|
+
error: {
|
|
30
|
+
base: "#cc1818",
|
|
31
|
+
light: "#fcebea",
|
|
32
|
+
dark: "#8a0000",
|
|
33
|
+
},
|
|
34
|
+
info: {
|
|
35
|
+
base: "#3858e9",
|
|
36
|
+
light: "#e6f2ff",
|
|
37
|
+
dark: "#005cb8",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Core design-token family for each status. */
|
|
42
|
+
const CORE_FAMILY = {
|
|
43
|
+
success: "success",
|
|
44
|
+
warning: "caution",
|
|
45
|
+
error: "error",
|
|
46
|
+
info: "info",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Core token for each role, and the fallback variant it uses.
|
|
51
|
+
*
|
|
52
|
+
* - content: text on a tinted surface
|
|
53
|
+
* - accent: text, icons and chart series on neutral chrome
|
|
54
|
+
* - stroke: borders, dots and markers
|
|
55
|
+
* - surface: tinted backgrounds
|
|
56
|
+
*/
|
|
57
|
+
const ROLES = {
|
|
58
|
+
content: ["foreground-content-%s", "dark"],
|
|
59
|
+
accent: ["foreground-content-%s-weak", "base"],
|
|
60
|
+
stroke: ["stroke-surface-%s-strong", "base"],
|
|
61
|
+
surface: ["background-surface-%s-weak", "light"],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A status colour by role.
|
|
66
|
+
*
|
|
67
|
+
* @param {'success' | 'warning' | 'error' | 'info'} type
|
|
68
|
+
* @param {'content' | 'accent' | 'stroke' | 'surface'} [role='accent']
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
export const statusColor = (type, role = "accent") => {
|
|
72
|
+
const [token, variant] = ROLES[role] ?? ROLES.accent;
|
|
73
|
+
const family = CORE_FAMILY[type] ?? "error";
|
|
74
|
+
const fallback = STATUS_COLOR_FALLBACKS[type]?.[variant] ?? "#646970";
|
|
75
|
+
|
|
76
|
+
return `var(--wpds-color-${token.replace("%s", family)}, ${fallback})`;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A status colour by variant: base (text and icons), light (tinted
|
|
81
|
+
* backgrounds) or dark (text on a tinted background).
|
|
82
|
+
*
|
|
83
|
+
* @param {'success' | 'warning' | 'error' | 'info'} type
|
|
84
|
+
* @param {'base' | 'light' | 'dark'} [variant='base']
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
export const statusVar = (type, variant = "base") => {
|
|
88
|
+
const role = { base: "accent", light: "surface", dark: "content" }[variant] ?? "accent";
|
|
89
|
+
|
|
90
|
+
return statusColor(type, role);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Surface colors for score badges, pills, and bordered indicators.
|
|
95
|
+
*
|
|
96
|
+
* @param {'success' | 'warning' | 'error' | 'info'} status
|
|
97
|
+
* @returns {{ bg: string, text: string, border: string }}
|
|
98
|
+
*/
|
|
99
|
+
export const getStatusSurfaceColors = (status) => ({
|
|
100
|
+
bg: statusColor(status, "surface"),
|
|
101
|
+
text: statusColor(status, "content"),
|
|
102
|
+
border: statusColor(status, "stroke"),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Map a 0–100 score onto the four status intents.
|
|
107
|
+
*
|
|
108
|
+
* @param {number} score
|
|
109
|
+
* @returns {'success' | 'info' | 'warning' | 'error'}
|
|
110
|
+
*/
|
|
111
|
+
export const getScoreStatusTier = (score) => {
|
|
112
|
+
const value = Number(score);
|
|
113
|
+
|
|
114
|
+
if (!Number.isFinite(value)) {
|
|
115
|
+
return "error";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (value >= 90) {
|
|
119
|
+
return "success";
|
|
120
|
+
}
|
|
121
|
+
if (value >= 70) {
|
|
122
|
+
return "info";
|
|
123
|
+
}
|
|
124
|
+
if (value >= 50) {
|
|
125
|
+
return "warning";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return "error";
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {number} score
|
|
133
|
+
* @returns {{ bg: string, text: string, border: string }}
|
|
134
|
+
*/
|
|
135
|
+
export const getScoreSurfaceColors = (score) =>
|
|
136
|
+
getStatusSurfaceColors(getScoreStatusTier(score));
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {number} score
|
|
140
|
+
* @returns {{ chart: string, text: string }}
|
|
141
|
+
*/
|
|
142
|
+
export const getScoreChartColors = (score) => {
|
|
143
|
+
const tier = getScoreStatusTier(score);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
chart: statusColor(tier, "accent"),
|
|
147
|
+
text: statusColor(tier, "content"),
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Badge intent text color — error uses the accent for stronger contrast on a
|
|
153
|
+
* light background.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} intent
|
|
156
|
+
* @returns {{ background: string, color: string }}
|
|
157
|
+
*/
|
|
158
|
+
export const getBadgeIntentColors = (intent) => {
|
|
159
|
+
switch (intent) {
|
|
160
|
+
case "error":
|
|
161
|
+
case "critical":
|
|
162
|
+
return {
|
|
163
|
+
background: statusColor("error", "surface"),
|
|
164
|
+
color: statusColor("error", "accent"),
|
|
165
|
+
};
|
|
166
|
+
case "warning":
|
|
167
|
+
return {
|
|
168
|
+
background: statusColor("warning", "surface"),
|
|
169
|
+
color: statusColor("warning", "content"),
|
|
170
|
+
};
|
|
171
|
+
case "info":
|
|
172
|
+
case "suggestion":
|
|
173
|
+
return {
|
|
174
|
+
background: statusColor("info", "surface"),
|
|
175
|
+
color: statusColor("info", "content"),
|
|
176
|
+
};
|
|
177
|
+
case "success":
|
|
178
|
+
case "passed":
|
|
179
|
+
return {
|
|
180
|
+
background: statusColor("success", "surface"),
|
|
181
|
+
color: statusColor("success", "content"),
|
|
182
|
+
};
|
|
183
|
+
default:
|
|
184
|
+
return {
|
|
185
|
+
background: ADMIN_COLOR.surfaceSubtle,
|
|
186
|
+
color: ADMIN_COLOR.text,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** Default chart series colors aligned with admin status tokens. */
|
|
192
|
+
export const defaultChartStatusColors = [
|
|
193
|
+
ADMIN_COLOR.brandFill,
|
|
194
|
+
"#646970",
|
|
195
|
+
statusColor("success"),
|
|
196
|
+
statusColor("warning"),
|
|
197
|
+
statusColor("error"),
|
|
198
|
+
"#8b5cf6",
|
|
199
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siratik/wp-component-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Library of components for use in the WordPress block editor.",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"module": "build/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./build/index.js",
|
|
9
|
+
"./constants/*": "./constants/*.js"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "wp-scripts start",
|
|
14
|
+
"build": "wp-scripts build",
|
|
15
|
+
"format": "wp-scripts format",
|
|
16
|
+
"lint:js": "wp-scripts lint-js",
|
|
17
|
+
"lint:md:docs": "wp-scripts lint-md-docs",
|
|
18
|
+
"lint:pkg-json": "wp-scripts lint-pkg-json",
|
|
19
|
+
"test:unit": "wp-scripts test-unit-js components utils"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+:https://github.com/builtnorth/wp-component-library.git"
|
|
24
|
+
},
|
|
25
|
+
"author": "Built North",
|
|
26
|
+
"license": "GPL-2.0-or-later",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/builtnorth/wp-component-library.git/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/builtnorth/wp-admin-dashboard?tab=readme-ov-file#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@dnd-kit/core": "^6.3.1",
|
|
33
|
+
"@dnd-kit/modifiers": "^9.0.0",
|
|
34
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
35
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
36
|
+
"@leeoniya/ufuzzy": "^1.0.14",
|
|
37
|
+
"classnames": "^2.5.1",
|
|
38
|
+
"dompurify": "^3.4.7",
|
|
39
|
+
"prop-types": "^15.8.1",
|
|
40
|
+
"react-window": "^1.8.11"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@emotion/react": "^11.14.0",
|
|
44
|
+
"@emotion/styled": "^11.14.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@wordpress/scripts": "^34.2.0"
|
|
48
|
+
}
|
|
6
49
|
}
|