Skip to content

Commit 5743c5d

Browse files
committed
refactor(ui): deduplicate shared utilities and remove dead code
- Extract mix() color helper to src/utils/colorMix.ts (was duplicated in DocCard, PathCard, PathwayRow) - Extract CUI icon map to src/components/docs/icons/cuiMap.ts (was duplicated in DocCard, ChallengeGrid) - Delete 11 unused custom SVG icon files in components/docs/icons/ - Rename RunningStrip ext prop to external, consistent with QuickStrip API - Replace RunningStrip inline SVG arrow with CIcon cilArrowRight
1 parent 02789bf commit 5743c5d

20 files changed

Lines changed: 69 additions & 327 deletions

File tree

crowdsec-docs/src/components/docs/ChallengeGrid/index.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
import {
2-
cilBarChart,
3-
cilBell,
4-
cilCompass,
5-
cilGlobeAlt,
6-
cilLayers,
7-
cilLockLocked,
8-
cilRss,
9-
cilSearch,
10-
cilShieldAlt,
11-
cilSpeedometer,
12-
} from "@coreui/icons";
131
import { CIcon } from "@coreui/icons-react";
142
import React from "react";
15-
16-
const CUI: Record<string, object> = {
17-
search: cilSearch,
18-
pulse: cilBarChart,
19-
box: cilLayers,
20-
shield: cilShieldAlt,
21-
compass: cilCompass,
22-
gauge: cilSpeedometer,
23-
globe: cilGlobeAlt,
24-
lock: cilLockLocked,
25-
bell: cilBell,
26-
feed: cilRss,
27-
};
3+
import { CUI } from "../icons/cuiMap";
284

295
export type Challenge = {
306
iconName?: string;

crowdsec-docs/src/components/docs/DocCard/index.tsx

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,8 @@
1-
import {
2-
cilArrowRight,
3-
cilBarChart,
4-
cilBell,
5-
cilBook,
6-
cilBriefcase,
7-
cilCheckCircle,
8-
cilCode,
9-
cilCompass,
10-
cilGlobeAlt,
11-
cilInfo,
12-
cilLayers,
13-
cilLockLocked,
14-
cilNotes,
15-
cilPeople,
16-
cilPuzzle,
17-
cilRss,
18-
cilSearch,
19-
cilShieldAlt,
20-
cilSpeedometer,
21-
cilStar,
22-
cilTerminal,
23-
cilWarning,
24-
} from "@coreui/icons";
1+
import { cilArrowRight } from "@coreui/icons";
252
import { CIcon } from "@coreui/icons-react";
263
import React from "react";
27-
28-
/* Shared icon set — use CoreUI icons throughout */
29-
const CUI: Record<string, object> = {
30-
search: cilSearch,
31-
key: cilLockLocked,
32-
terminal: cilTerminal,
33-
globe: cilGlobeAlt,
34-
shield: cilShieldAlt,
35-
feed: cilRss,
36-
compass: cilCompass,
37-
book: cilBook,
38-
plug: cilPuzzle,
39-
alert: cilWarning,
40-
gauge: cilSpeedometer,
41-
lock: cilLockLocked,
42-
box: cilLayers,
43-
pulse: cilBarChart,
44-
users: cilPeople,
45-
bell: cilBell,
46-
check: cilCheckCircle,
47-
code: cilCode,
48-
star: cilStar,
49-
info: cilInfo,
50-
notes: cilNotes,
51-
briefcase: cilBriefcase,
52-
};
4+
import { mix } from "../../../utils/colorMix";
5+
import { CUI } from "../icons/cuiMap";
536

547
function renderIcon(name: string) {
558
const icon = CUI[name];
@@ -78,8 +31,6 @@ export type DocCardProps = {
7831
children?: React.ReactNode;
7932
};
8033

81-
const mix = (c: string, pct: number) => `color-mix(in srgb, ${c} ${pct}%, transparent)`;
82-
8334
function ExternalArrow() {
8435
return (
8536
<CIcon

crowdsec-docs/src/components/docs/PathCard/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState } from "react";
2+
import { mix } from "../../../utils/colorMix";
23

34
type Props = {
45
eyebrow?: string;
@@ -13,7 +14,6 @@ type Props = {
1314
};
1415

1516
/* color-mix() helper so CSS vars like var(--cs-orange) can be used with opacity */
16-
const mix = (c: string, pct: number) => `color-mix(in srgb, ${c} ${pct}%, transparent)`;
1717

1818
export default function PathCard({ eyebrow, color, icon, title, desc, tag, tags = [], audience, href }: Props) {
1919
const [hover, setHover] = useState(false);

crowdsec-docs/src/components/docs/PathwayRow/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState } from "react";
2+
import { mix } from "../../../utils/colorMix";
23

34
export type Step = {
45
title: string;
@@ -36,8 +37,6 @@ function ArrowIcon() {
3637
);
3738
}
3839

39-
const mix = (c: string, pct: number) => `color-mix(in srgb, ${c} ${pct}%, transparent)`;
40-
4140
const HINT_STYLE: Record<string, React.CSSProperties> = {
4241
RECOMMENDED: {
4342
background: "color-mix(in srgb, var(--cs-teal) 15%, transparent)",

crowdsec-docs/src/components/docs/RunningStrip/index.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { cilArrowRight } from "@coreui/icons";
2+
import { CIcon } from "@coreui/icons-react";
13
import React from "react";
24

3-
type Link = { icon?: React.ReactNode; label: string; href: string; color?: string; ext?: boolean };
5+
type Link = { icon?: React.ReactNode; label: string; href: string; color?: string; external?: boolean };
46

57
type Props = {
68
label?: string;
@@ -68,21 +70,12 @@ export default function RunningStrip({ label = "Already running CrowdSec?", link
6870
>
6971
{l.icon && <span style={{ color: l.color || "var(--cs-orange)", display: "flex", flexShrink: 0 }}>{l.icon}</span>}
7072
{l.label}
71-
{l.ext && (
72-
<svg
73-
width="11"
74-
height="11"
75-
viewBox="0 0 24 24"
76-
fill="none"
77-
stroke="currentColor"
78-
strokeWidth={1.6}
79-
strokeLinecap="round"
80-
strokeLinejoin="round"
81-
style={{ opacity: 0.5, flexShrink: 0, color: "var(--cs-ink-mute)" }}
73+
{l.external && (
74+
<CIcon
75+
icon={cilArrowRight}
76+
style={{ width: 11, height: 11, opacity: 0.5, flexShrink: 0, transform: "rotate(-45deg)" }}
8277
aria-hidden="true"
83-
>
84-
<path d="M5 12h14M13 6l6 6-6 6" />
85-
</svg>
78+
/>
8679
)}
8780
</a>
8881
))}

crowdsec-docs/src/components/docs/icons/AlertIcon.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

crowdsec-docs/src/components/docs/icons/BarChartIcon.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

crowdsec-docs/src/components/docs/icons/BlocklistIcon.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

crowdsec-docs/src/components/docs/icons/CheckIcon.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

crowdsec-docs/src/components/docs/icons/ConsoleIcon.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)