Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of concatenation when producing CSS classnames #2312

Merged
merged 1 commit into from Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
Copyright 2020-2021 The Tekton Authors
Copyright 2020-2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,6 +15,14 @@ limitations under the License.
import PropTypes from 'prop-types';
import React from 'react';

const tableSizeClassNames = {
xs: 'bx--data-table--xs',
sm: 'bx--data-table--sm',
md: 'bx--data-table--md',
lg: 'bx--data-table--lg',
xl: 'bx--data-table--xl'
};

const DataTableSkeleton = ({
className,
columnCount,
Expand All @@ -35,7 +43,7 @@ const DataTableSkeleton = ({
</tr>
));

const sizeClassName = size ? `bx--data-table--${size}` : '';
const sizeClassName = tableSizeClassNames[size] || '';

return (
<table
Expand Down
42 changes: 26 additions & 16 deletions packages/components/src/components/StatusIcon/StatusIcon.js
@@ -1,5 +1,5 @@
/*
Copyright 2020-2021 The Tekton Authors
Copyright 2020-2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down Expand Up @@ -27,24 +27,38 @@ import { isRunning } from '@tektoncd/dashboard-utils';
import { Spinner } from '..';

const icons = {
normal: {
cancelled: CloseFilled,
error: CloseFilled,
pending: Pending,
running: Spinner,
success: CheckmarkFilled,
warning: CheckmarkFilledWarning
},
inverse: {
cancelled: CloseOutline,
error: CloseOutline,
pending: Pending,
running: Spinner,
success: CheckmarkOutline,
warning: WarningFilled
},
normal: {
cancelled: CloseFilled,
error: CloseFilled,
pending: Pending,
running: Spinner,
success: CheckmarkFilled,
warning: CheckmarkFilledWarning
}
};

const statusClassNames = {
cancelled: 'tkn--status-icon--cancelled',
error: 'tkn--status-icon--error',
pending: 'tkn--status-icon--pending',
running: 'tkn--status-icon--running',
success: 'tkn--status-icon--success',
warning: 'tkn--status-icon--warning'
};

const typeClassNames = {
inverse: 'tkn--status-icon--type-inverse',
normal: 'tkn--status-icon--type-normal'
};

export default function StatusIcon({
DefaultIcon,
hasWarning,
Expand Down Expand Up @@ -84,13 +98,9 @@ export default function StatusIcon({

return Icon ? (
<Icon
className={classNames(
'tkn--status-icon',
{
[`tkn--status-icon--${statusClass}`]: statusClass
},
`tkn--status-icon--type-${type}`
)}
className={classNames('tkn--status-icon', typeClassNames[type], {
[statusClassNames[statusClass]]: statusClass
})}
>
{title && <title>{title}</title>}
</Icon>
Expand Down
12 changes: 6 additions & 6 deletions packages/components/src/components/StatusIcon/StatusIcon.scss
@@ -1,5 +1,5 @@
/*
Copyright 2020-2021 The Tekton Authors
Copyright 2020-2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -16,23 +16,23 @@ limitations under the License.
width: 20px;
height: 20px;

&--cancelled {
&.tkn--status-icon--cancelled {
fill: $ui-04;
}

&--error {
&.tkn--status-icon--error {
fill: $support-01;
}

&--running {
&.tkn--status-icon--running {
fill: $support-04;
}

&--success {
&.tkn--status-icon--success {
fill: $support-02;
}

&--warning {
&.tkn--status-icon--warning {
&.tkn--status-icon--type-normal {
fill: $support-02;

Expand Down