Skip to content

Commit

Permalink
fix(ui-kit): fix comments color when highlighted (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosCortizasCT authored Oct 19, 2023
1 parent d0a948b commit e8e57ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-pillows-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-docs/ui-kit': patch
---

Fix color issue with comments in code examples when they are highlighted.
27 changes: 25 additions & 2 deletions packages/ui-kit/src/components/code-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { css } from '@emotion/react';
import Tooltip from '@commercetools-uikit/tooltip';
import SpacingsInline from '@commercetools-uikit/spacings-inline';
import { ClipboardIcon } from '@commercetools-uikit/icons';
import { Highlight } from 'prism-react-renderer';
import { Highlight, Token } from 'prism-react-renderer';
import {
colors,
dimensions,
Expand Down Expand Up @@ -104,6 +104,19 @@ const getLineStyles = (options: {
return [promptLineStyles, highlightLineStyles];
};

const getTokenStyles = (options: {
token: Token;
shouldHighlightLine: boolean;
}) => {
if (options.token.types.includes('comment') && options.shouldHighlightLine) {
return {
color: colors.light.textInverted,
};
}

return {};
};

/**
* This components implements most of the logic from `gatsby-remark-prismjs`.
* https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-prismjs
Expand Down Expand Up @@ -285,7 +298,17 @@ const CodeBlock = (props: CodeBlockProps) => {
})}
>
{line.map((token, key) => (
<span key={key} {...getTokenProps({ token, key })} />
<span
key={key}
{...getTokenProps({
token,
key,
style: getTokenStyles({
token,
shouldHighlightLine,
}),
})}
/>
))}
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions websites/docs-smoke-test/src/content/views/code-blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ curl -sH "Authorization: Bearer ACCESS_TOKEN" https://api.sphere.io/PROJECT_KEY/

# Javascript

Passing the option `highlightLines="2,5-7,11..16`.
Passing the option `highlightLines="1-2,5-7,11..16`.

```javascript highlightLines="2,5-7,11..16"
```javascript highlightLines="1-2,5-7,11..16"
// Constructor
var anObject = new Object();

Expand Down

0 comments on commit e8e57ed

Please sign in to comment.