Skip to content
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

DOP-4651: Update Highlight for dark mode #1128

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions src/components/Roles/Highlight.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { cx, css } from '@leafygreen-ui/emotion';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { palette } from '@leafygreen-ui/palette';
import ComponentFactory from '../ComponentFactory';

const colorMap = {
'highlight-blue': palette.blue.light3,
'highlight-green': palette.green.light3,
'highlight-red': palette.red.light3,
'highlight-yellow': palette.yellow.light3,
const HIGHLIGHT_BLUE = 'highlight-blue';
const HIGHLIGHT_GREEN = 'highlight-green';
const HIGHLIGHT_RED = 'highlight-red';
const HIGHLIGHT_YELLOW = 'highlight-yellow';

const COLOR_MAP = {
light: {
[HIGHLIGHT_BLUE]: palette.blue.light3,
[HIGHLIGHT_GREEN]: palette.green.light3,
[HIGHLIGHT_RED]: palette.red.light3,
[HIGHLIGHT_YELLOW]: palette.yellow.light3,
},
dark: {
[HIGHLIGHT_BLUE]: palette.blue.dark2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet this is totally correct, just making sure because all the other colors use the "3" variant except this one :)

Copy link
Collaborator Author

@rayangler rayangler Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. Just double-checked in the Figma and the design shows #083C90, which corresponds to palette.blue.dark2

[HIGHLIGHT_GREEN]: palette.green.dark3,
[HIGHLIGHT_RED]: palette.red.dark3,
[HIGHLIGHT_YELLOW]: palette.yellow.dark3,
},
};

const Highlight = ({ nodeData: { children, name } }) => (
<span
css={css`
background-color: ${colorMap[name]};
`}
>
{children.map((node, i) => (
<ComponentFactory key={i} nodeData={node} />
))}
</span>
);
const Highlight = ({ nodeData: { children, name } }) => {
const { darkMode } = useDarkMode();
const colorTheme = darkMode ? 'dark' : 'light';
const backgroundColor = COLOR_MAP[colorTheme][name];

if (!backgroundColor) {
console.warn(`Highlight color ${name} not supported.`);
}

return (
<span
className={cx(css`
background-color: var(--background-color);
`)}
style={{
'--background-color': backgroundColor,
}}
>
{children.map((node, i) => (
<ComponentFactory key={i} nodeData={node} />
))}
</span>
);
};

Highlight.propTypes = {
nodeData: PropTypes.shape({
Expand Down
Loading