@siratik/wp-component-library 0.0.0-stage → 0.1.1

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.
@@ -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,209 @@
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
+ * - fill: chart series, rings and bars (see statusColor)
57
+ */
58
+ const ROLES = {
59
+ content: ["foreground-content-%s", "dark"],
60
+ accent: ["foreground-content-%s-weak", "base"],
61
+ stroke: ["stroke-surface-%s-strong", "base"],
62
+ surface: ["background-surface-%s-weak", "light"],
63
+ };
64
+
65
+ /**
66
+ * A status colour by role.
67
+ *
68
+ * `fill` has no core token: core's status foregrounds are darkened for text
69
+ * contrast (caution reads olive as a fill), so filled shapes use the bright
70
+ * base palette instead.
71
+ *
72
+ * @param {'success' | 'warning' | 'error' | 'info'} type
73
+ * @param {'content' | 'accent' | 'stroke' | 'surface' | 'fill'} [role='accent']
74
+ * @returns {string}
75
+ */
76
+ export const statusColor = (type, role = "accent") => {
77
+ if (role === "fill") {
78
+ return STATUS_COLOR_FALLBACKS[type]?.base ?? STATUS_COLOR_FALLBACKS.error.base;
79
+ }
80
+
81
+ const [token, variant] = ROLES[role] ?? ROLES.accent;
82
+ const family = CORE_FAMILY[type] ?? "error";
83
+ const fallback = STATUS_COLOR_FALLBACKS[type]?.[variant] ?? "#646970";
84
+
85
+ // eslint-disable-next-line @wordpress/no-unknown-ds-tokens -- token names come from the ROLES/CORE_FAMILY maps above.
86
+ return `var(--wpds-color-${token.replace("%s", family)}, ${fallback})`;
87
+ };
88
+
89
+ /**
90
+ * A status colour by variant: base (text and icons), light (tinted
91
+ * backgrounds) or dark (text on a tinted background).
92
+ *
93
+ * @param {'success' | 'warning' | 'error' | 'info'} type
94
+ * @param {'base' | 'light' | 'dark'} [variant='base']
95
+ * @returns {string}
96
+ */
97
+ export const statusVar = (type, variant = "base") => {
98
+ const role = { base: "accent", light: "surface", dark: "content" }[variant] ?? "accent";
99
+
100
+ return statusColor(type, role);
101
+ };
102
+
103
+ /**
104
+ * Surface colors for score badges, pills, and bordered indicators.
105
+ *
106
+ * @param {'success' | 'warning' | 'error' | 'info'} status
107
+ * @returns {{ bg: string, text: string, border: string }}
108
+ */
109
+ export const getStatusSurfaceColors = (status) => ({
110
+ bg: statusColor(status, "surface"),
111
+ text: statusColor(status, "content"),
112
+ border: statusColor(status, "stroke"),
113
+ });
114
+
115
+ /**
116
+ * Map a 0–100 score onto the four status intents.
117
+ *
118
+ * @param {number} score
119
+ * @returns {'success' | 'info' | 'warning' | 'error'}
120
+ */
121
+ export const getScoreStatusTier = (score) => {
122
+ const value = Number(score);
123
+
124
+ if (!Number.isFinite(value)) {
125
+ return "error";
126
+ }
127
+
128
+ if (value >= 90) {
129
+ return "success";
130
+ }
131
+ if (value >= 70) {
132
+ return "info";
133
+ }
134
+ if (value >= 50) {
135
+ return "warning";
136
+ }
137
+
138
+ return "error";
139
+ };
140
+
141
+ /**
142
+ * @param {number} score
143
+ * @returns {{ bg: string, text: string, border: string }}
144
+ */
145
+ export const getScoreSurfaceColors = (score) =>
146
+ getStatusSurfaceColors(getScoreStatusTier(score));
147
+
148
+ /**
149
+ * @param {number} score
150
+ * @returns {{ chart: string, text: string }}
151
+ */
152
+ export const getScoreChartColors = (score) => {
153
+ const tier = getScoreStatusTier(score);
154
+
155
+ return {
156
+ chart: statusColor(tier, "fill"),
157
+ text: statusColor(tier, "content"),
158
+ };
159
+ };
160
+
161
+ /**
162
+ * Badge intent text color — error uses the accent for stronger contrast on a
163
+ * light background.
164
+ *
165
+ * @param {string} intent
166
+ * @returns {{ background: string, color: string }}
167
+ */
168
+ export const getBadgeIntentColors = (intent) => {
169
+ switch (intent) {
170
+ case "error":
171
+ case "critical":
172
+ return {
173
+ background: statusColor("error", "surface"),
174
+ color: statusColor("error", "accent"),
175
+ };
176
+ case "warning":
177
+ return {
178
+ background: statusColor("warning", "surface"),
179
+ color: statusColor("warning", "content"),
180
+ };
181
+ case "info":
182
+ case "suggestion":
183
+ return {
184
+ background: statusColor("info", "surface"),
185
+ color: statusColor("info", "content"),
186
+ };
187
+ case "success":
188
+ case "passed":
189
+ return {
190
+ background: statusColor("success", "surface"),
191
+ color: statusColor("success", "content"),
192
+ };
193
+ default:
194
+ return {
195
+ background: ADMIN_COLOR.surfaceSubtle,
196
+ color: ADMIN_COLOR.text,
197
+ };
198
+ }
199
+ };
200
+
201
+ /** Default chart series colors aligned with admin status tokens. */
202
+ export const defaultChartStatusColors = [
203
+ ADMIN_COLOR.brandFill,
204
+ "#646970",
205
+ statusColor("success", "fill"),
206
+ statusColor("warning", "fill"),
207
+ statusColor("error", "fill"),
208
+ "#8b5cf6",
209
+ ];
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@siratik/wp-component-library",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
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/issues"
29
+ },
30
+ "homepage": "https://github.com/builtnorth/wp-component-library#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
+ "@wordpress/icons": "^11.8.0",
38
+ "classnames": "^2.5.1",
39
+ "dompurify": "^3.4.7",
40
+ "prop-types": "^15.8.1",
41
+ "react-window": "^1.8.11"
42
+ },
43
+ "peerDependencies": {
44
+ "@emotion/react": "^11.14.0",
45
+ "@emotion/styled": "^11.14.1"
46
+ },
47
+ "devDependencies": {
48
+ "@wordpress/scripts": "^34.2.0",
49
+ "react": "^18.3.1",
50
+ "react-dom": "^18.3.1"
51
+ }
6
52
  }