From a48e0bb7dbac8ab2c623ec18f42a0e523a1028aa Mon Sep 17 00:00:00 2001 From: Bastian Ike Date: Thu, 19 Jan 2023 10:22:18 +0100 Subject: [PATCH] fix(badges): use relative coloring for badges fixes #286 --- src/components/Badge/Badge.tsx | 12 +++++++++++- src/components/Badge/badge.scss | 8 ++++---- src/components/ItemRevision/ItemRevision.tsx | 5 ++++- src/components/ItemRevisions/ItemRevisions.tsx | 4 ++++ src/components/PageItem/PageItem.tsx | 5 +++-- src/components/PageItemMobile/PageItemMobile.tsx | 7 +++++-- src/components/PageOverview/PageOverview.tsx | 5 ++++- .../QuadrantSection/QuadrantSection.tsx | 15 +++++++++------ 8 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/components/Badge/Badge.tsx b/src/components/Badge/Badge.tsx index 2a1ab18..7917ad4 100644 --- a/src/components/Badge/Badge.tsx +++ b/src/components/Badge/Badge.tsx @@ -1,25 +1,35 @@ import classNames from "classnames"; import React, { MouseEventHandler } from "react"; +import { ConfigData } from "../../config"; import "./badge.scss"; type BadgeProps = { onClick?: MouseEventHandler; big?: boolean; type: "big" | "all" | "empty" | string; + config: ConfigData; +}; + +const badgeClass = (type: string, config: ConfigData) => { + if (!config.rings.includes(type)) { + return type; + } + return ["first", "second", "third", "fourth"][config.rings.indexOf(type)]; }; export default function Badge({ onClick, big, type, + config, children, }: React.PropsWithChildren) { const Comp = onClick ? "a" : "span"; return (
- + {revision.ring} | {formatRelease(revision.release, dateFormat)}
diff --git a/src/components/ItemRevisions/ItemRevisions.tsx b/src/components/ItemRevisions/ItemRevisions.tsx index e4e9424..8e79234 100644 --- a/src/components/ItemRevisions/ItemRevisions.tsx +++ b/src/components/ItemRevisions/ItemRevisions.tsx @@ -1,3 +1,4 @@ +import { ConfigData } from "../../config"; import { useMessages } from "../../context/MessagesContext"; import { Revision } from "../../model"; import HeadlineGroup from "../HeadlineGroup/HeadlineGroup"; @@ -6,9 +7,11 @@ import "./item-revisions.scss"; export default function ItemRevisions({ revisions, + config, dateFormat, }: { revisions: Revision[]; + config: ConfigData; dateFormat?: string; }) { const { revisionsText } = useMessages(); @@ -25,6 +28,7 @@ export default function ItemRevisions({ key={revision.release} revision={revision} dateFormat={dateFormat} + config={config} /> ))} diff --git a/src/components/PageItem/PageItem.tsx b/src/components/PageItem/PageItem.tsx index 54bcd00..38e16ae 100644 --- a/src/components/PageItem/PageItem.tsx +++ b/src/components/PageItem/PageItem.tsx @@ -81,7 +81,7 @@ const PageItem: React.FC = ({ >
- + {item.ring}
@@ -119,7 +119,7 @@ const PageItem: React.FC = ({ {editButton}
- + {item.ring}
@@ -134,6 +134,7 @@ const PageItem: React.FC = ({ )} diff --git a/src/components/PageItemMobile/PageItemMobile.tsx b/src/components/PageItemMobile/PageItemMobile.tsx index cffcb20..4e6f10f 100644 --- a/src/components/PageItemMobile/PageItemMobile.tsx +++ b/src/components/PageItemMobile/PageItemMobile.tsx @@ -65,7 +65,7 @@ export default function PageItemMobile({ {editButton}
- + {item.ring}
@@ -77,7 +77,10 @@ export default function PageItemMobile({ /> {item.revisions.length > 1 && ( - + )} diff --git a/src/components/PageOverview/PageOverview.tsx b/src/components/PageOverview/PageOverview.tsx index bcc75a8..1aade31 100644 --- a/src/components/PageOverview/PageOverview.tsx +++ b/src/components/PageOverview/PageOverview.tsx @@ -101,6 +101,7 @@ export default function PageOverview({ big onClick={handleRingClick(ringName)} type={isRingActive(ringName) ? ringName : "empty"} + config={config} > {ringName} @@ -137,7 +138,9 @@ export default function PageOverview({ {translate(config, item.quadrant)}
- {item.ring} + + {item.ring} +
diff --git a/src/components/QuadrantSection/QuadrantSection.tsx b/src/components/QuadrantSection/QuadrantSection.tsx index f14ebe4..926d684 100644 --- a/src/components/QuadrantSection/QuadrantSection.tsx +++ b/src/components/QuadrantSection/QuadrantSection.tsx @@ -10,6 +10,7 @@ const renderList = ( ringName: string, quadrantName: string, groups: Group, + config: ConfigData, big: boolean ) => { const itemsInRing = groups[quadrantName][ringName] || []; @@ -17,7 +18,7 @@ const renderList = ( if (big) { return ( - + {ringName} @@ -27,7 +28,9 @@ const renderList = ( return (
- {ringName} + + {ringName} +
{itemsInRing.map((item) => ( @@ -45,11 +48,11 @@ const renderRing = ( ringName: string, quadrantName: string, groups: Group, - renderIfEmpty: boolean, + config: ConfigData, big: boolean ) => { if ( - !renderIfEmpty && + !config.showEmptyRings && (!groups[quadrantName] || !groups[quadrantName][ringName] || groups[quadrantName][ringName].length === 0) @@ -58,7 +61,7 @@ const renderRing = ( } return (
- {renderList(ringName, quadrantName, groups, big)} + {renderList(ringName, quadrantName, groups, config, big)}
); }; @@ -93,7 +96,7 @@ export default function QuadrantSection({
{config.rings.map((ringName: string) => - renderRing(ringName, quadrantName, groups, config.showEmptyRings, big) + renderRing(ringName, quadrantName, groups, config, big) )}