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

fix: isLoading on the Table component when the variant is listView #1896

Merged
merged 9 commits into from
Oct 14, 2020
17 changes: 9 additions & 8 deletions src/components/Table/body/loading.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import LoadingCells from './loadingCells';
import StyledRow from './styled/row';

export default function Loading({ columns }) {
const columnsLength = columns.length;
return (
<>
<tr>
<StyledRow>
<LoadingCells columns={columns} value={columnsLength} />
</tr>
<tr>
</StyledRow>
<StyledRow>
<LoadingCells columns={columns} value={columnsLength} />
</tr>
<tr>
</StyledRow>
<StyledRow>
<LoadingCells columns={columns} value={columnsLength - 1} />
</tr>
<tr>
</StyledRow>
<StyledRow>
<LoadingCells columns={columns} value={columnsLength - 3} />
</tr>
</StyledRow>
</>
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/Table/body/loadingCells.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import RenderIf from '../../RenderIf';
import { SELECTABLE_CHECKBOX } from '../helpers/columns';
import StyledTdLoadingContainer from './styled/tdLoadingContainer';
import StyledLoadingCell from './styled/loadingCell';
Expand All @@ -13,7 +14,7 @@ function getRandomWidth() {

export default function LoadingCells({ value, columns }) {
if (value > 0) {
return Array(value)
return Array(columns.length)
.fill()
.map((item, index) => {
const key = `loading-cell-${index}`;
Expand All @@ -26,7 +27,9 @@ export default function LoadingCells({ value, columns }) {
return (
<StyledTdLoadingContainer key={key}>
<StyledLoadingCell data-id="table_body--loading">
<StyledElementLoading style={styles} />
<RenderIf isTrue={index < value}>
<StyledElementLoading style={styles} />
</RenderIf>
</StyledLoadingCell>
</StyledTdLoadingContainer>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Table/body/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export default function Row(props) {

if (rowData.type === 'LOADING') {
return (
<tr>
<StyledRow>
<LoadingCells columns={columns} value={columns.length} />
</tr>
</StyledRow>
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/components/Table/body/styled/elementLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ const StyledElementLoading = attachThemeAttrs(styled.div)`
object-fit: contain;
border-radius: 24px;
z-index: 1;
background: ${props => props.palette.background.secondary}
background: ${props => replaceAlpha(props.palette.background.secondary, 0.5)}
linear-gradient(
90deg,
${props => replaceAlpha(props.palette.background.highlight, 0.01)} 0%,
${props => replaceAlpha(props.palette.background.highlight, 0.65)} 50%,
${props => replaceAlpha(props.palette.background.highlight, 0.7)} 50%,
${props => replaceAlpha(props.palette.background.highlight, 0.01)} 100%
);
background-size: 400% 400%;
animation: gradient 2.5s ease-in-out infinite;

filter: invert(3%);

@keyframes gradient {
0% {
background-position: 14% 0;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Table/body/styled/loadingCell.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components';
import attachThemeAttrs from '../../../../styles/helpers/attachThemeAttrs';

const StyledLoadingCell = styled.div`
const StyledLoadingCell = attachThemeAttrs(styled.div)`
height: 44px;
width: 100%;
display: flex;
Expand Down
39 changes: 38 additions & 1 deletion src/components/Table/body/styled/tdLoadingContainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components';
import attachThemeAttrs from '../../../../styles/helpers/attachThemeAttrs';

const StyledTdLoadingContainer = styled.td`
const StyledTdLoadingContainer = attachThemeAttrs(styled.td)`
padding: 0;
text-align: left;
box-sizing: border-box;
Expand All @@ -12,6 +13,42 @@ const StyledTdLoadingContainer = styled.td`
:last-of-type > div {
padding: 0 12px;
}

${props =>
wildergd marked this conversation as resolved.
Show resolved Hide resolved
props.theme.variant === 'listview' &&
`
background-color: ${props.palette.background.main};
border: none;
text-align: center;
border-top: 1px solid ${props.palette.border.divider};
border-right: 1px solid ${props.palette.border.divider};

:first-child {
border-left: 1px solid ${props.palette.border.divider};
border-left-style: solid;
border-top-left-radius: 13px;
border-bottom-left-radius: 13px;
}

:last-child {
border-right-style: solid;
border-bottom-right-radius: 13px;
border-top-right-radius: 13px;
}

:last-child > div {
border-bottom-right-radius: 12px;
border-top-right-radius: 12px;
overflow: hidden;
}

:first-child > div {
border-top-left-radius: 12px;
border-bottom-left-radius: 12px;
overflow: hidden;
padding-left: 0.75rem;
}
`}
`;

export default StyledTdLoadingContainer;