From b1e059b9e5d655d41b4c95dd1fcc13f54efa8d69 Mon Sep 17 00:00:00 2001 From: Cristiano Tofani Date: Thu, 19 Oct 2023 15:50:09 +0200 Subject: [PATCH 1/2] Add the Outlined variant on Badge component --- example/src/pages/Badges.tsx | 21 ++++++++++++ src/components/badge/Badge.tsx | 61 +++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/example/src/pages/Badges.tsx b/example/src/pages/Badges.tsx index 6aa03a7f..1d4a9d44 100644 --- a/example/src/pages/Badges.tsx +++ b/example/src/pages/Badges.tsx @@ -62,6 +62,27 @@ const renderBadge = () => ( + + + + + + + + + + + + + + + + + + + + + , VariantProps> = { @@ -73,6 +74,42 @@ const mapVariants: Record, VariantProps> = { } }; +const mapOutlineVariants: Record< + NonNullable, + VariantProps +> = { + default: { + foreground: "grey-700" + }, + info: { + foreground: "info-850" + }, + warning: { + foreground: "warning-850" + }, + success: { + foreground: "success-850" + }, + error: { + foreground: "error-850" + }, + purple: { + foreground: "hanPurple-850" + }, + lightBlue: { + foreground: "blueIO-850" + }, + blue: { + foreground: "blueIO-500" + }, + turquoise: { + foreground: "turquoise-850" + }, + contrast: { + foreground: "grey-850" + } +}; + const styles = StyleSheet.create({ badge: { flexDirection: "row", @@ -106,14 +143,26 @@ const styles = StyleSheet.create({ /** * Official badge component */ -export const Badge = ({ text, variant, testID }: Badge) => { +export const Badge = ({ text, outline = false, variant, testID }: Badge) => { const { isExperimental } = useIOExperimentalDesign(); + const { background, foreground } = useMemo( + () => (outline ? mapOutlineVariants : mapVariants)[variant], + [outline, variant] + ); + return ( { style={[ styles.label, isExperimental ? styles.labelFont : styles.legacyLabelFont, - { color: IOColors[mapVariants[variant].foreground] } + { + color: IOColors[foreground] + } ]} > {text} From 5274d7a80e3b3cf19eddd9c9262d0e321e092609 Mon Sep 17 00:00:00 2001 From: Cristiano Tofani Date: Mon, 23 Oct 2023 10:15:06 +0200 Subject: [PATCH 2/2] type fix --- src/components/badge/Badge.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/badge/Badge.tsx b/src/components/badge/Badge.tsx index eda99be8..7398a212 100644 --- a/src/components/badge/Badge.tsx +++ b/src/components/badge/Badge.tsx @@ -26,12 +26,12 @@ export type Badge = WithTestID<{ | "contrast"; }>; -type VariantProps = { +type SolidVariantProps = { + background: IOColors; foreground: IOColors; - background?: IOColors; }; -const mapVariants: Record, VariantProps> = { +const mapVariants: Record, SolidVariantProps> = { default: { foreground: "grey-700", background: "grey-50" @@ -74,9 +74,14 @@ const mapVariants: Record, VariantProps> = { } }; +type OutlinedVariantProps = { + foreground: IOColors; + background?: never; +}; + const mapOutlineVariants: Record< NonNullable, - VariantProps + OutlinedVariantProps > = { default: { foreground: "grey-700"