Skip to content

Commit 8612852

Browse files
author
Martí Malek
committed
feat(tag): use css variables in variants
1 parent 9a64870 commit 8612852

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/components/Tag/Tag.spec.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { render, fireEvent, screen } from '@testing-library/react';
22
import * as React from 'react';
33
import { Tag } from './Tag';
44
import { SemanticColors } from '../../essentials';
5+
import { getSemanticValue } from '../../utils/cssVariables';
56

67
describe('Tag', () => {
78
it('renders and can be dismissed', () => {
@@ -28,28 +29,28 @@ describe('Tag', () => {
2829
const { container } = render(<Tag variant="disabled">Lorem</Tag>);
2930

3031
expect(container.firstChild).toHaveStyle(`
31-
border-color: ${SemanticColors.border.primary};
32+
border-color: ${getSemanticValue('border-disabled')};
3233
`);
3334
expect(screen.getByText('Lorem')).toHaveStyle(`
34-
color: ${SemanticColors.text.disabled};
35+
color: ${getSemanticValue('foreground-disabled')};
3536
`);
3637
expect(screen.getByTestId('dismiss-icon')).toHaveStyle(`
37-
color: ${SemanticColors.icon.disabled};
38+
color: ${getSemanticValue('foreground-disabled')};
3839
`);
3940
});
4041

4142
it('renders error variant', () => {
4243
const { container } = render(<Tag variant="error">Lorem</Tag>);
4344

4445
expect(container.firstChild).toHaveStyle(`
45-
background-color: ${SemanticColors.background.danger};
46-
border-color: ${SemanticColors.border.dangerEmphasized};
46+
background-color: ${getSemanticValue('background-surface-danger-default')};
47+
border-color: ${getSemanticValue('border-danger-default')};
4748
`);
4849
expect(screen.getByText('Lorem')).toHaveStyle(`
49-
color: ${SemanticColors.text.dangerInverted};
50+
color: ${getSemanticValue('foreground-danger-default')};
5051
`);
5152
expect(screen.getByTestId('dismiss-icon')).toHaveStyle(`
52-
color: ${SemanticColors.icon.danger};
53+
color: ${getSemanticValue('foreground-danger-default')};
5354
`);
5455
});
5556
});

src/components/Tag/Tag.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ const tagVariant = variant({
5050
borderColor: getSemanticValue('border-info-default'),
5151

5252
[`> ${TagText}`]: {
53-
color: get('semanticColors.text.link')
53+
color: getSemanticValue('foreground-info-default')
5454
},
5555

5656
[`> ${DismissIcon}`]: {
57-
color: get('semanticColors.icon.action')
57+
color: getSemanticValue('foreground-info-default')
5858
},
5959

6060
'&:hover': {
6161
backgroundColor: getSemanticValue('background-element-info-emphasized'),
62-
borderColor: get('semanticColors.border.infoEmphasized'),
62+
borderColor: getSemanticValue('border-info-default'),
6363

6464
[`> ${TagText}`]: {
6565
color: getSemanticValue('foreground-on-background-info')
@@ -71,38 +71,38 @@ const tagVariant = variant({
7171
}
7272
},
7373
disabled: {
74-
borderColor: get('semanticColors.border.primary'),
74+
borderColor: getSemanticValue('border-disabled'),
7575

7676
[`> ${TagText}`]: {
77-
color: get('semanticColors.text.disabled')
77+
color: getSemanticValue('foreground-disabled')
7878
},
7979

8080
[`> ${DismissIcon}`]: {
81-
color: get('semanticColors.icon.disabled')
81+
color: getSemanticValue('foreground-disabled')
8282
}
8383
},
8484
error: {
85-
backgroundColor: get('semanticColors.background.danger'),
86-
borderColor: get('semanticColors.border.dangerEmphasized'),
85+
backgroundColor: getSemanticValue('background-surface-danger-default'),
86+
borderColor: getSemanticValue('border-danger-default'),
8787

8888
[`> ${TagText}`]: {
89-
color: get('semanticColors.text.dangerInverted')
89+
color: getSemanticValue('foreground-danger-default')
9090
},
9191

9292
[`> ${DismissIcon}`]: {
93-
color: get('semanticColors.icon.danger')
93+
color: getSemanticValue('foreground-danger-default')
9494
},
9595

9696
'&:hover': {
97-
backgroundColor: get('semanticColors.background.dangerEmphasized'),
98-
borderColor: get('semanticColors.border.dangerEmphasized'),
97+
backgroundColor: getSemanticValue('background-surface-danger-emphasized'),
98+
borderColor: getSemanticValue('border-danger-default'),
9999

100100
[`> ${TagText}`]: {
101-
color: get('semanticColors.text.primaryInverted')
101+
color: getSemanticValue('foreground-on-background-danger')
102102
},
103103

104104
[`> ${DismissIcon}`]: {
105-
color: get('semanticColors.icon.primaryInverted')
105+
color: getSemanticValue('foreground-on-background-danger')
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)