Skip to content

Commit 720c0d4

Browse files
committed
Addressing PR review
1 parent 9572d52 commit 720c0d4

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/components/token/token.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface TokenProps {
4646
iconType: IconType;
4747
/**
4848
* For best results use one of the vis color names (or 'gray').
49-
* Or supply your own HEX color (can be used with fill 'dark' or fill 'none' only).
49+
* Or supply your own HEX color. The `fill='light'` (lightened background) will always be overridden by `fill='dark'` (solid background).
5050
* Default: `gray` for glyphs or one of the vis colors for prefab token types
5151
*/
5252
color?: TokenColor | string;
@@ -77,6 +77,9 @@ export type EuiTokenProps = CommonProps &
7777
TokenProps &
7878
Omit<HTMLAttributes<HTMLSpanElement>, 'title'>;
7979

80+
const isTokenColor = (color: string): color is TokenColor =>
81+
COLORS.includes(color as TokenColor);
82+
8083
export const EuiToken: FunctionComponent<EuiTokenProps> = ({
8184
iconType,
8285
color,
@@ -119,8 +122,6 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
119122
const euiTheme = useEuiTheme();
120123
const styles = euiTokenStyles(euiTheme);
121124

122-
const isTokenColor = COLORS.includes(finalColor as TokenColor);
123-
124125
let cssStyles = [
125126
styles.euiToken,
126127
styles[finalShape],
@@ -130,7 +131,7 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
130131

131132
let finalStyle = style;
132133

133-
if (isTokenColor) {
134+
if (isTokenColor(finalColor)) {
134135
cssStyles = [...cssStyles, styles[finalColor as TokenColor]];
135136
} else if (finalFill === 'none') {
136137
// When a custom HEX color is passed and the token doesn't have any fill (no background),
@@ -140,7 +141,7 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
140141
} else {
141142
// When a custom HEX color is passed and the token has a fill (light or dark),
142143
// the background gets the custom color and the icon gets white or black based on the passed color
143-
// The fill='light' (transparent background) will always be overridden by fill='dark' (opaque background)
144+
// The fill='light' (lightened background) will always be overridden by fill='dark' (opaque background)
144145
// to better handle custom colors
145146
const isFinalColorDark = isColorDark(...hexToRgb(finalColor));
146147
const lightOrDarkColor = isFinalColorDark ? '#FFFFFF' : '#000000';

upcoming_changelogs/6067.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
- Updated `tokenFile`, `tokenSymbol` and `tokenRepo` default shapes to `square`
2-
31
**CSS-in-JS conversions**
42

5-
- Converted `EuiToken` to Emotion
3+
- Converted `EuiToken` to Emotion
4+
5+
**Breaking changes**
6+
7+
- Updated `tokenFile`, `tokenSymbol` and `tokenRepo` default shapes to `square` instead of `rectangle`

0 commit comments

Comments
 (0)