Skip to content

Commit ad4d07d

Browse files
authored
Support inline icon colors (#3717)
1 parent 7508674 commit ad4d07d

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
import type { DocumentInlineIcon } from '@gitbook/api';
1+
import type { DocumentInlineIcon, DocumentMarkColor } from '@gitbook/api';
22

3+
import { tcls } from '@/lib/tailwind';
34
import { Icon, type IconName } from '@gitbook/icons';
45
import type { InlineProps } from './Inline';
6+
import { textColorToStyle } from './utils/colors';
57

68
export async function InlineIcon(props: InlineProps<DocumentInlineIcon>) {
79
const { inline } = props;
10+
const icon = inline.data.icon as IconName;
11+
// @ts-expect-error remove this comment once API is updated
12+
const color = inline.data.color
13+
? // @ts-expect-error remove "as DocumentMarkColor['data']['text']" once API is updated
14+
(inline.data.color as DocumentMarkColor['data']['text'])
15+
: undefined;
816

9-
return <Icon icon={inline.data.icon as IconName} className="inline size-[1em]" />;
17+
return (
18+
<Icon
19+
icon={icon}
20+
className={tcls('inline size-[1em]', color ? textColorToStyle[color] : null)}
21+
/>
22+
);
1023
}

packages/gitbook/src/components/DocumentView/Text.tsx

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import type {
1212
} from '@gitbook/api';
1313
import React from 'react';
1414

15-
import { type ClassValue, tcls } from '@/lib/tailwind';
15+
import { tcls } from '@/lib/tailwind';
16+
import { backgroundColorToStyle, textColorToStyle } from './utils/colors';
1617

1718
export function Text(props: { text: DocumentText }) {
1819
const { text } = props;
@@ -121,51 +122,3 @@ function Color(props: MarkedLeafProps<DocumentMarkColor>) {
121122
</span>
122123
);
123124
}
124-
125-
/**
126-
* @TODO replace by DocumentMarkColor['data']['text'] and DocumentMarkColor['data']['background']
127-
* once the API is updated.
128-
*/
129-
type DocumentMarkColorValue =
130-
| 'default'
131-
| 'green'
132-
| 'blue'
133-
| 'red'
134-
| 'orange'
135-
| 'yellow'
136-
| 'purple'
137-
| '$primary'
138-
| '$info'
139-
| '$success'
140-
| '$warning'
141-
| '$danger';
142-
143-
const textColorToStyle: { [color in DocumentMarkColorValue]: ClassValue } = {
144-
default: [],
145-
blue: ['text-blue-500'],
146-
red: ['text-red-500'],
147-
green: ['text-green-500'],
148-
yellow: ['text-yellow-600'],
149-
purple: ['text-purple-500'],
150-
orange: ['text-orange-500'],
151-
$primary: ['text-primary'],
152-
$info: ['text-info'],
153-
$success: ['text-success'],
154-
$warning: ['text-warning'],
155-
$danger: ['text-danger'],
156-
};
157-
158-
const backgroundColorToStyle: { [color in DocumentMarkColorValue]: ClassValue } = {
159-
default: [],
160-
blue: ['bg-mark-blue'],
161-
red: ['bg-mark-red'],
162-
green: ['bg-mark-green'],
163-
yellow: ['bg-mark-yellow'],
164-
purple: ['bg-mark-purple'],
165-
orange: ['bg-mark-orange'],
166-
$primary: ['bg-primary'],
167-
$info: ['bg-info'],
168-
$success: ['bg-success'],
169-
$warning: ['bg-warning'],
170-
$danger: ['bg-danger'],
171-
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { ClassValue } from '@/lib/tailwind';
2+
import type { DocumentMarkColor } from '@gitbook/api';
3+
4+
export const textColorToStyle: { [color in DocumentMarkColor['data']['text']]: ClassValue } = {
5+
default: [],
6+
blue: ['text-blue-500'],
7+
red: ['text-red-500'],
8+
green: ['text-green-500'],
9+
yellow: ['text-yellow-600'],
10+
purple: ['text-purple-500'],
11+
orange: ['text-orange-500'],
12+
$primary: ['text-primary'],
13+
$info: ['text-info'],
14+
$success: ['text-success'],
15+
$warning: ['text-warning'],
16+
$danger: ['text-danger'],
17+
};
18+
19+
export const backgroundColorToStyle: {
20+
[color in DocumentMarkColor['data']['background']]: ClassValue;
21+
} = {
22+
default: [],
23+
blue: ['bg-mark-blue'],
24+
red: ['bg-mark-red'],
25+
green: ['bg-mark-green'],
26+
yellow: ['bg-mark-yellow'],
27+
purple: ['bg-mark-purple'],
28+
orange: ['bg-mark-orange'],
29+
$primary: ['bg-primary'],
30+
$info: ['bg-info'],
31+
$success: ['bg-success'],
32+
$warning: ['bg-warning'],
33+
$danger: ['bg-danger'],
34+
};

0 commit comments

Comments
 (0)