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 all 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,150 @@ | ||
| 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 || fallbackIcon || alternate || ""; | ||
| }; | ||
|
|
||
| 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 { 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([]); | ||
|
|
||
| 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; | ||
|
|
||
| if (primaryIcon && (await checkImageUrlValidity(primaryIcon))) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: primaryIcon, | ||
| }; | ||
| } | ||
|
|
||
| const validItems = await Promise.all(promises); | ||
| // Filter out null values (items that are not valid) | ||
| const filteredValidComponents = validItems.filter( | ||
| (item) => item !== null | ||
| // 1. Fallback to the theme-aware integration icon | ||
| if ( | ||
| fallbackIcon && | ||
| fallbackIcon !== primaryIcon && | ||
|
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. The integration-level icon is tried before the component's own other-theme icon. In dark mode, a component with a |
||
| (await checkFallback()) | ||
| ) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: fallbackIcon, | ||
| }; | ||
| } | ||
|
|
||
| // 2. Last resort: opposite-theme component icon | ||
| if ( | ||
| alternateIcon && | ||
| alternateIcon !== primaryIcon && | ||
| alternateIcon !== fallbackIcon && | ||
| (await checkImageUrlValidity(alternateIcon)) | ||
| ) { | ||
| return { | ||
| ...item, | ||
| preferredIcon: alternateIcon, | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| }), | ||
| ); | ||
|
|
||
| setValidComponents(filteredValidComponents); | ||
| if (mounted) { | ||
| setValidComponents(validItems.filter(Boolean)); | ||
| } | ||
| }; | ||
|
|
||
| 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 |
||
|
|
||
| fetchData(); | ||
| }, []); | ||
| const handleImageError = (nameToRemove) => { | ||
|
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. Each icon is validated twice: once by the |
||
| setValidComponents((prev) => | ||
| prev.filter((item) => item.name !== nameToRemove), | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <ComponentsWrapper> | ||
| <section className="heading"> | ||
| <h1> | ||
| {frontmatter.title} Components ({components.length}) | ||
| {frontmatter?.title} Components ({validComponents.length}) | ||
|
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.
|
||
| </h1> | ||
| </section> | ||
|
|
||
| <section className="componentsSection"> | ||
| {validComponents.map((item) => ( | ||
| <div key={item.id} className="maincontainer"> | ||
| <div key={item.name} className="maincontainer"> | ||
|
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. Using |
||
| <div className="componentimg"> | ||
| <img src={item.colorIcon.publicURL} alt={item.name} /> | ||
| {item.preferredIcon && ( | ||
| <img | ||
| src={item.preferredIcon} | ||
| alt={item.name || ""} | ||
| onError={(e) => { | ||
| e.currentTarget.onerror = null; | ||
| handleImageError(item.name); | ||
| }} | ||
| /> | ||
| )} | ||
| </div> | ||
| <p className="items">{item.name.replaceAll("-", " ")}</p> | ||
| {/* <div className="textcontent"> | ||
| </div> */} | ||
| <p className="items">{item.name?.replaceAll("-", " ") || ""}</p> | ||
| </div> | ||
| ))} | ||
| </section> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,11 @@ const NoResources = ({ errorMessage,errorSubtitle }) => { | |
| <ResourcePageWrapper> | ||
| <div className="no-resources-page"> | ||
| <Container> | ||
| <Row className="empty-state-row"> | ||
| <Col $xs={12} $lg={4}> | ||
| <Row> | ||
|
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 also reverts the earlier mobile fix: it removes the |
||
| <Col $sm={12} $lg={4}> | ||
| <img src={serviceMesh} alt="service meshes" className="mesh" /> | ||
| </Col> | ||
| <Col $xs={12} $lg={8}> | ||
| <Col $sm={12} $lg={8}> | ||
| <div className="error-text"> | ||
| <h1 className="errorMessage"> {errorMessage} </h1> | ||
| <h3 className="errorSubtitle">{errorSubtitle}</h3> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,90 +75,28 @@ export const ResourcePageWrapper = styled.div` | |
| margin: 1rem; | ||
|
|
||
| box-shadow: 0px 3px 10px 1px rgba(0, 179, 159, 0.5); | ||
|
|
||
| .empty-state-row { | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .errorMessage { | ||
| font-size: 2rem; | ||
| line-height: 2rem; | ||
| overflow-wrap: break-word; | ||
| word-break: break-word; | ||
| } | ||
| .error-text{ | ||
| margin-top: 5rem; | ||
| overflow-wrap: break-word; | ||
| word-break: break-word; | ||
| } | ||
| .errorSubtitle { | ||
| font-weight: 400; | ||
| font-size: 1.5rem; | ||
| color: gray; | ||
| font-style: italic; | ||
| margin-top: 2.5rem; | ||
| overflow-wrap: break-word; | ||
| word-break: break-word; | ||
| } | ||
| img{ | ||
| display: block; | ||
| margin:auto; | ||
| margin-top: 3.125rem; | ||
| width: 14rem; | ||
| max-width: 100%; | ||
| height: auto; | ||
| object-fit: contain; | ||
| } | ||
|
|
||
| @media only screen and (max-width: 992px) { | ||
|
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 PR deletes the responsive empty-state styles (the |
||
| padding: 2rem 1.5rem 3rem; | ||
| text-align: center; | ||
|
|
||
| .empty-state-row { | ||
| justify-content: center; | ||
| } | ||
|
|
||
| img { | ||
| margin: 1rem auto 0; | ||
| width: 12rem; | ||
| max-width: 100%; | ||
| height: auto; | ||
| } | ||
|
|
||
| .error-text { | ||
| margin-top: 1.5rem; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .errorMessage { | ||
| font-size: 1.5rem; | ||
| line-height: 1.3; | ||
| } | ||
|
|
||
| .errorSubtitle { | ||
| font-size: 1.15rem; | ||
| line-height: 1.4; | ||
| margin-top: 1rem; | ||
| } | ||
| } | ||
|
|
||
| @media only screen and (max-width: 575px) { | ||
| padding: 1.5rem 1rem 2.5rem; | ||
| margin: 0.5rem; | ||
|
|
||
| img { | ||
| width: 9rem; | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| .errorMessage { | ||
| font-size: 1.25rem; | ||
| } | ||
|
|
||
| .errorSubtitle { | ||
| font-size: 1rem; | ||
| margin-top: 0.75rem; | ||
| @media only screen and (max-width:700px){ | ||
| max-width: 100%; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `; | ||
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.