Skip to content

Commit 617f7ba

Browse files
committed
Extract icons to reusable components
1 parent 8da1a28 commit 617f7ba

7 files changed

Lines changed: 87 additions & 22 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import classNames from 'classnames';
4+
5+
type Props = {
6+
name: string;
7+
label: string;
8+
className?: string;
9+
};
10+
11+
export const CodiconIcon = styled.span`
12+
vertical-align: text-bottom;
13+
`;
14+
15+
export const Codicon = ({
16+
name,
17+
label,
18+
className
19+
}: Props) => <CodiconIcon role="img" aria-label={label} className={classNames('codicon', `codicon-${name}`, className)} />;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import { Codicon } from './Codicon';
4+
5+
const Icon = styled(Codicon)`
6+
color: var(--vscode-problemsErrorIcon-foreground);
7+
`;
8+
9+
type Props = {
10+
label?: string;
11+
className?: string;
12+
}
13+
14+
export const ErrorIcon = ({
15+
label = 'Error',
16+
className,
17+
}: Props) => <Icon name="error" label={label} className={className} />;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import { Codicon } from './Codicon';
4+
5+
const Icon = styled(Codicon)`
6+
color: var(--vscode-testing-iconPassed);
7+
`;
8+
9+
type Props = {
10+
label?: string;
11+
className?: string;
12+
}
13+
14+
export const SuccessIcon = ({
15+
label = 'Success',
16+
className,
17+
}: Props) => <Icon name="pass" label={label} className={className} />;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
import { Codicon } from './Codicon';
4+
5+
const Icon = styled(Codicon)`
6+
color: var(--vscode-problemsWarningIcon-foreground);
7+
`;
8+
9+
type Props = {
10+
label?: string;
11+
className?: string;
12+
}
13+
14+
export const WarningIcon = ({
15+
label = 'Warning',
16+
className,
17+
}: Props) => <Icon name="warning" label={label} className={className} />;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './Codicon';
2+
export * from './ErrorIcon';
3+
export * from './SuccessIcon';
4+
export * from './WarningIcon';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './icon';

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysisRepositoriesStats.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import * as React from 'react';
22
import styled from 'styled-components';
33
import { VariantAnalysisStatus } from '../../remote-queries/shared/variant-analysis';
44
import { formatDecimal } from '../../pure/number';
5+
import { CodiconIcon, ErrorIcon, SuccessIcon, WarningIcon } from '../common';
6+
7+
const Container = styled.div`
8+
${CodiconIcon} {
9+
margin-left: 0.3em;
10+
}
11+
`;
512

613
type Props = {
714
variantAnalysisStatus: VariantAnalysisStatus;
@@ -12,23 +19,6 @@ type Props = {
1219
queryResult?: 'warning' | 'stopped';
1320
};
1421

15-
const Icon = styled.span`
16-
vertical-align: text-bottom;
17-
margin-left: 0.3em;
18-
`;
19-
20-
const WarningIcon = styled(Icon)`
21-
color: var(--vscode-problemsWarningIcon-foreground);
22-
`;
23-
24-
const ErrorIcon = styled(Icon)`
25-
color: var(--vscode-problemsErrorIcon-foreground);
26-
`;
27-
28-
const SuccessIcon = styled(Icon)`
29-
color: var(--vscode-testing-iconPassed);
30-
`;
31-
3222
export const VariantAnalysisRepositoriesStats = ({
3323
variantAnalysisStatus,
3424
totalRepositoryCount,
@@ -38,17 +28,17 @@ export const VariantAnalysisRepositoriesStats = ({
3828
if (variantAnalysisStatus === VariantAnalysisStatus.Failed) {
3929
return (
4030
<>
41-
0<ErrorIcon role="img" aria-label="Error" className="codicon codicon-error" />
31+
0<ErrorIcon />
4232
</>
4333
);
4434
}
4535

4636
return (
47-
<>
37+
<Container>
4838
{formatDecimal(completedRepositoryCount)}/{formatDecimal(totalRepositoryCount)}
49-
{queryResult && <WarningIcon role="img" aria-label="Warning" className="codicon codicon-warning" />}
39+
{queryResult && <WarningIcon />}
5040
{!queryResult && variantAnalysisStatus === VariantAnalysisStatus.Succeeded &&
51-
<SuccessIcon role="img" aria-label="Completed" className="codicon codicon-pass" />}
52-
</>
41+
<SuccessIcon label="Completed" />}
42+
</Container>
5343
);
5444
};

0 commit comments

Comments
 (0)