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

Replace react-content-loader with css implementation. #484

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"prop-types": "^15.7.2",
"qs": "^6.9.1",
"react": "^16.13.1",
"react-content-loader": "^4.3.2",
"react-dom": "^16.13.0",
"react-intl": "^3.6.2",
"react-json-view": "^1.19.1",
Expand Down
2 changes: 0 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import '@redhat-cloud-services/frontend-components-notifications/index.css';
import '@redhat-cloud-services/frontend-components/index.css';
import { getAxiosInstance } from './helpers/shared/user-login';
import { CATALOG_API_BASE, SOURCES_API_BASE } from './utilities/constants';
import GlobalStyle from './global-styles';
import UserContext from './user-context';

smoothscroll.polyfill();
Expand Down Expand Up @@ -112,7 +111,6 @@ const App = () => {
value={{ permissions: userPermissions, userIdentity }}
>
<Fragment>
<GlobalStyle />
<NotificationsPortal />
<Main className="pf-u-p-0 pf-u-ml-0">
<Grid style={{ minHeight: MIN_SCREEN_HEIGHT }}>
Expand Down
233 changes: 92 additions & 141 deletions src/presentational-components/shared/loader-placeholders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Fragment } from 'react';
import ContentLoader, { List } from 'react-content-loader';
import PropTypes from 'prop-types';
import { Main } from '@redhat-cloud-services/frontend-components/components/Main';
import { Spinner } from '@patternfly/react-core/dist/js/components/Spinner/Spinner';
Expand All @@ -20,52 +19,75 @@ import {
FormGroup,
TextContent,
Text,
TextVariants
TextVariants,
ActionGroup,
Button
} from '@patternfly/react-core';
import styled, { keyframes } from 'styled-components';

const wave = keyframes`
0% {
transform: translateX(-100%);
}
60% {
transform: translateX(100%);
}
100% {
transform: translateX(100%);
}
`;

const Skeleton = ({ component: Component = 'span', ...props }) => {
return (
<SkeletonContainer {...props}>
<Component />
</SkeletonContainer>
);
};

Skeleton.propTypes = {
component: PropTypes.string
};

export const CardLoader = ({ items, ...props }) => (
const SkeletonContainer = styled.div`
& > * {
position: relative;
overflow: hidden;
width: ${({ width }) =>
width ? `${width}${typeof width === 'number' ? 'px' : ''}` : '100%'};
height: ${({ height }) =>
height ? `${height}${typeof height === 'number' ? 'px' : ''}` : '20px'};
display: block;
border-radius: 3px;
background-color: ${({ secondaryColor }) =>
secondaryColor ? secondaryColor : '#f3f3f3'};
&:after {
animation: 2s ${wave} linear 0.5s infinite;
background: linear-gradient(90deg, transparent, #ecebeb, transparent);
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
top: 0;
transform: translateX(-100%);
z-index: 1;
}
}
`;

export const CardLoader = ({ items }) => (
<Grid gutter="md">
<GridItem sm={12} className="pf-u-p-md">
<Gallery gutter="md">
{[...Array(items)].map((_item, index) => (
<GalleryItem key={index}>
<Card style={{ height: 350 }}>
<CardBody>
<ContentLoader
height={160}
width={300}
speed={2}
primaryColor="#f3f3f3"
secondaryColor="#ecebeb"
{...props}
>
<rect x="2" y="99" rx="3" ry="3" width="300" height="6.4" />
<rect
x="2"
y="119.72"
rx="3"
ry="3"
width="290"
height="5.76"
/>
<rect x="2" y="139" rx="3" ry="3" width="201" height="6.4" />
<rect
x="-2.16"
y="0.67"
rx="0"
ry="0"
width="271.6"
height="82.74"
/>
<rect
x="136.84"
y="37.67"
rx="0"
ry="0"
width="6"
height="3"
/>
</ContentLoader>
<Skeleton height={70} width="85%" className="pf-u-mb-lg" />
<Skeleton height={5} width="90%" className="pf-u-mb-sm" />
<Skeleton height={5} width="100%" className="pf-u-mb-sm" />
<Skeleton height={5} width="76%" className="pf-u-mb-sm" />
</CardBody>
</Card>
</GalleryItem>
Expand All @@ -83,84 +105,38 @@ CardLoader.defaultProps = {
items: 13
};

export const PortfolioLoader = ({ items, ...props }) => (
<Grid gutter="md">
<GridItem sm={12}>
<ContentLoader
height={16}
width={300}
speed={2}
primaryColor="#FFFFFF"
secondaryColor="#FFFFFF"
{...props}
>
<rect x="0" y="0" rx="0" ry="0" width="420" height="16" />
</ContentLoader>
</GridItem>
<GridItem sm={12} style={{ paddingLeft: 16, paddingRight: 16 }}>
<CardLoader items={items} />
</GridItem>
</Grid>
);

PortfolioLoader.propTypes = {
items: PropTypes.number
};

PortfolioLoader.defaultProps = {
items: 5
};

export const AppPlaceholder = (props) => (
export const AppPlaceholder = () => (
<Main className="pf-u-m-0 pf-u-p-0">
<ContentLoader
height={16}
width={300}
speed={2}
primaryColor="#FFFFFF"
secondaryColor="#FFFFFF"
{...props}
>
<rect x="0" y="0" rx="0" ry="0" width="420" height="10" />
</ContentLoader>
<div>
<Skeleton height={32} className="pf-u-p-lg global-primary-background" />
<div className="pf-u-mt-lg">
<Bullseye>
<Spinner />
</Bullseye>
</div>
</Main>
);

export const ToolbarTitlePlaceholder = (props) => (
<ContentLoader
height={21}
width={200}
speed={2}
primaryColor="#f3f3f3"
secondaryColor="#ecebeb"
{...props}
>
<rect x="0" y="0" rx="0" ry="0" width="200" height="21" />
</ContentLoader>
);
export const ToolbarTitlePlaceholder = () => <Skeleton height={30} />;

const ProducLoaderColumn = styled.div`
width: 100%;
max-width: 250px;
`;

export const ProductLoaderPlaceholder = (props) => (
export const ProductLoaderPlaceholder = () => (
<Fragment>
<ContentLoader
height={15}
width={200}
speed={2}
primaryColor="#f3f3f3"
secondaryColor="#ecebeb"
{...props}
>
<rect x="0" y="0" rx="0" ry="0" width="200" height="10" />
</ContentLoader>
<div style={{ width: 300 }}>
<List />
<List speed={3} />
<List />
</div>
<Skeleton height={70} className="pf-u-mb-xl" />
<ProducLoaderColumn>
{[...Array(3)].map((_, index) => (
<Fragment key={index}>
<Skeleton height={8} className="pf-u-mb-sm" />
<Skeleton height={8} className="pf-u-ml-md pf-u-mb-sm" width="60%" />
<Skeleton height={8} className="pf-u-ml-md pf-u-mb-sm" width="50%" />
<Skeleton height={8} className="pf-u-mb-sm" width="80%" />
<Skeleton height={8} className="pf-u-ml-md pf-u-mb-lg" width="40%" />
</Fragment>
))}
</ProducLoaderColumn>
</Fragment>
);

Expand All @@ -178,17 +154,7 @@ IconPlaceholder.defaultProps = {
height: '40'
};

const FormItemLoader = () => (
<ContentLoader
height={36}
width={400}
speed={2}
primaryColor="#ffffff"
secondaryColor="#ecebeb"
>
<rect x="0" y="0" rx="0" ry="0" width="400" height="36" />
</ContentLoader>
);
const FormItemLoader = () => <Skeleton height={38} className="pf-u-mb-lg" />;

export const ShareLoader = () => (
<Form>
Expand All @@ -212,35 +178,26 @@ export const ShareLoader = () => (

export const WorkflowLoader = () => (
<Form>
<FormGroup fieldId="1">
<TextContent>
<Text component={TextVariants.medium}>Approval workflow</Text>
</TextContent>
</FormGroup>
<FormGroup fieldId="2">
<FormGroup fieldId="2" label="Select workflow">
<FormItemLoader />
</FormGroup>
<ActionGroup>
<Button variant="primary" isDisabled>
Save
</Button>
</ActionGroup>
</Form>
);

export const ListLoader = ({ items, ...props }) => (
export const ListLoader = ({ items }) => (
<DataList aria-label="list-loader" aria-labelledby="datalist-placeholder">
{[...Array(items)].map((_item, index) => (
<DataListItem key={index} aria-labelledby="datalist-item-placeholder">
<DataListItemRow aria-label="datalist-item-placeholder-row">
<DataListItemCells
dataListCells={[
<DataListCell key="1">
<ContentLoader
height={12}
width={300}
speed={2}
primaryColor="#FFFFFF"
secondaryColor="#ecebeb"
{...props}
>
<rect x="0" y="0" rx="0" ry="0" width="300" height="12" />
</ContentLoader>
<Skeleton height={67} />
</DataListCell>
]}
/>
Expand All @@ -258,10 +215,4 @@ ListLoader.defaultProps = {
items: 5
};

export const OrderDetailToolbarPlaceholder = () => (
<div>
<ContentLoader height={20} width={300}>
<rect x="0" y="0" rx="0" ry="0" width="300" height="12" />
</ContentLoader>
</div>
);
export const OrderDetailToolbarPlaceholder = () => <Skeleton height={70} />;
2 changes: 2 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
import AppContext from './app-context';
import GlobalStyle from './global-styles';

const pathName = window.location.pathname.split('/');
pathName.shift();
Expand All @@ -13,6 +14,7 @@ if (pathName[0] === 'beta') {

const Router = () => (
<AppContext.Provider value={{ release }}>
<GlobalStyle />
<BrowserRouter basename={`${release}${pathName[0]}/${pathName[1]}`}>
<App />
</BrowserRouter>
Expand Down
Loading