Repository navigation
[Integrations] Support dark mode whiteIcon, circular badges, and card layout sizing #8170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
c4901bc
66a1879
334737d
f495264
9bd650d
bead3ba
f7ac96a
c79d1c6
574af28
da49eaf
f959735
b072c7f
db39b88
293fd50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,135 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
| import { ComponentsWrapper } from "./Component.style"; | ||
| import { checkImageUrlValidity } from "../../../../utils/imageValidate"; | ||
| import { useStyledDarkMode } from "../../../../theme/app/useStyledDarkMode"; | ||
|
|
||
| const getFallbackIcon = (frontmatter, isDarkActive) => { | ||
| if (isDarkActive) { | ||
| return ( | ||
| frontmatter?.darkModeIntegrationIcon?.publicURL || | ||
| frontmatter?.integrationIcon?.publicURL || | ||
| frontmatter?.integrationIcon_svg?.publicURL || | ||
| "" | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| frontmatter?.integrationIcon?.publicURL || | ||
| frontmatter?.integrationIcon_svg?.publicURL || | ||
| frontmatter?.darkModeIntegrationIcon?.publicURL || | ||
| "" | ||
| ); | ||
| }; | ||
|
|
||
| const getPreferredIcon = (component, isDarkActive, fallbackIcon) => { | ||
| const primary = isDarkActive | ||
| ? component?.whiteIcon?.publicURL | ||
| : component?.colorIcon?.publicURL; | ||
| const alternate = isDarkActive | ||
| ? component?.colorIcon?.publicURL | ||
| : component?.whiteIcon?.publicURL; | ||
|
|
||
| return primary || alternate || fallbackIcon || ""; | ||
| }; | ||
|
|
||
| const ComponentsGrid = ({ frontmatter }) => { | ||
| const components = frontmatter.components.map((component) => { | ||
| const { name, colorIcon } = component; // currently we don't have description for components | ||
| return { name, colorIcon }; | ||
| }); | ||
| const [validComponents, setValidComponents] = useState([]); | ||
| const { isDark } = useStyledDarkMode(); | ||
| const darkModeActive = Boolean(isDark); | ||
| const fallbackIcon = getFallbackIcon(frontmatter, darkModeActive); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const candidateComponents = (frontmatter?.components || []).map( | ||
| (component) => ({ | ||
| ...component, | ||
| preferredIcon: getPreferredIcon(component, darkModeActive, fallbackIcon), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }), | ||
| ); | ||
|
|
||
| const [validComponents, setValidComponents] = useState(candidateComponents); | ||
|
|
||
| useEffect(() => { | ||
| const fetchData = async () => { | ||
| const promises = components.map(async (item) => { | ||
| const isSvgPathValid = await checkImageUrlValidity( | ||
| item.colorIcon.publicURL | ||
| ); | ||
| if (isSvgPathValid) { | ||
| return item; | ||
| } else { | ||
| item.colorIcon.publicURL = frontmatter.integrationIcon.publicURL; | ||
| return item; // Return fallback image | ||
| let mounted = true; | ||
|
|
||
| const loadIcons = async () => { | ||
| let isFallbackValid = null; | ||
| const checkFallback = async () => { | ||
| if (!fallbackIcon) return false; | ||
| if (isFallbackValid === null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cache doesn't work under |
||
| isFallbackValid = await checkImageUrlValidity(fallbackIcon); | ||
| } | ||
| }); | ||
| return isFallbackValid; | ||
| }; | ||
|
|
||
| const validItems = await Promise.all( | ||
| candidateComponents.map(async (item) => { | ||
| const primaryIcon = darkModeActive | ||
| ? item.whiteIcon?.publicURL | ||
| : item.colorIcon?.publicURL; | ||
| const alternateIcon = darkModeActive | ||
| ? item.colorIcon?.publicURL | ||
| : item.whiteIcon?.publicURL; | ||
|
|
||
| const validItems = await Promise.all(promises); | ||
| // Filter out null values (items that are not valid) | ||
| const filteredValidComponents = validItems.filter( | ||
| (item) => item !== null | ||
| if (primaryIcon && (await checkImageUrlValidity(primaryIcon))) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: primaryIcon, | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| alternateIcon && | ||
| alternateIcon !== primaryIcon && | ||
| (await checkImageUrlValidity(alternateIcon)) | ||
| ) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: alternateIcon, | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| fallbackIcon && | ||
| fallbackIcon !== primaryIcon && | ||
| fallbackIcon !== alternateIcon && | ||
| (await checkFallback()) | ||
| ) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: fallbackIcon, | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| }), | ||
| ); | ||
|
|
||
| setValidComponents(filteredValidComponents); | ||
| if (mounted) { | ||
| setValidComponents(validItems.filter(Boolean)); | ||
| } | ||
| }; | ||
|
|
||
| fetchData(); | ||
| }, []); | ||
| loadIcons(); | ||
| return () => { | ||
| mounted = false; | ||
| }; | ||
| }, [frontmatter, darkModeActive, fallbackIcon]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a theme switch, the cards keep showing the previous theme's icons (for example, colour icons on the new black badge) until all new probes resolve. Cards removed by |
||
|
|
||
| return ( | ||
| <ComponentsWrapper> | ||
| <section className="heading"> | ||
| <h1> | ||
| {frontmatter.title} Components ({components.length}) | ||
| {frontmatter?.title} Components ({candidateComponents.length}) | ||
| </h1> | ||
| </section> | ||
|
|
||
| <section className="componentsSection"> | ||
| {validComponents.map((item) => ( | ||
| <div key={item.id} className="maincontainer"> | ||
| {validComponents.map((item, index) => ( | ||
| <div key={`${item.name}-${index}`} className="maincontainer"> | ||
| <div className="componentimg"> | ||
| <img src={item.colorIcon.publicURL} alt={item.name} /> | ||
| {item.preferredIcon && ( | ||
| <img src={item.preferredIcon} alt={item.name || ""} /> | ||
| )} | ||
| </div> | ||
| <p className="items">{item.name.replaceAll("-", " ")}</p> | ||
| {/* <div className="textcontent"> | ||
| </div> */} | ||
| <p className="items">{item.name?.replaceAll("-", " ") || ""}</p> | ||
| </div> | ||
| ))} | ||
| </section> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dark mode
blackToWhitemakes the badge pure black, but the fallback chain can still put a colour icon or a light-modeintegrationIconhere. A dark logo on a black circle is nearly invisible, which is the contrast problem this PR is trying to fix. Consider a neutral or contrasting badge for non-white icons.