Skip to content

Commit

Permalink
Add inline loader (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Jul 11, 2024
1 parent d0096ac commit 1c9d130
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
28 changes: 23 additions & 5 deletions app-typescript/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import * as React from 'react';

interface IProps {
overlay?: boolean;
interface IPropsOverlay {
overlay: true;
backgroundColor?: React.CSSProperties['backgroundColor'];
}

interface IPropsInline {
overlay?: false;
width?: React.CSSProperties['width'];
height?: React.CSSProperties['height'];
backgroundColor?: React.CSSProperties['backgroundColor'];
}

type IProps = IPropsOverlay | IPropsInline;

export class Loader extends React.Component<IProps> {
render() {

if (this.props.overlay) {
return (
<div className='sd-loader'></div>
<div className="sd-loader" style={{backgroundColor: this.props.backgroundColor}} />
);
} else {
return null;
return (
<div
className="sd-loader--inline"
style={{
width: this.props.width,
height: this.props.height,
backgroundColor: this.props.backgroundColor,
}}
/>
);
}
}
}
23 changes: 18 additions & 5 deletions app/styles/components/_sd-loader.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
// Animated loader

.sd-loader--inline {
display: inline-flex;
width: 100%;
min-width: 90px;
height: 100%;
min-height: 30px;

// inlining img/three-dots.svg as base64 encoded URL to have loader ready on application start
// otherwise, loader image would only start downloading when it already needs to be shown
background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjMwIiB2aWV3Qm94PSIwIDAgMTIwIDMwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiM3YjdiN2IiPjxjaXJjbGUgY3g9IjE1IiBjeT0iMTUiIHI9IjE1Ij48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJyIiBmcm9tPSIxNSIgdG89IjE1IiBiZWdpbj0iMHMiIGR1cj0iMC44cyIgdmFsdWVzPSIxNTs5OzE1IiBjYWxjT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GVhdENvdW50PSJpbmRlZmluaXRlIiAvPjwvY2lyY2xlPjwvc3ZnPg==");

background-repeat: no-repeat;
background-position: center center;
background-size: 60px;
background-color: var(--sd-colour-overlay-actioning);
}

.sd-loader {
@extend .sd-loader--inline;
content: '';
display: block;
position: absolute;
Expand All @@ -9,9 +27,4 @@
inset-block-end: 0;
inset-inline-start: 0;
z-index: 99999;
background-image: url(../img/three-dots.svg);
background-repeat: no-repeat;
background-position: center center;
background-size: 60px;
background-color: var(--sd-colour-overlay-actioning);
}
7 changes: 6 additions & 1 deletion examples/pages/components/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import { BorderUtilitiesDoc } from './utilities/BorderUtilities';
import { OpacityUtilitiesDoc } from './utilities/OpacityUtilities';
import { ObjectFitUtilitiesDoc } from './utilities/ObjectFitUtilities';
import { ObjectPositionUtilitiesDoc } from './utilities/ObjectPositionUtilities';
import LoaderDoc from './Loader';


interface IPages {
Expand Down Expand Up @@ -181,7 +182,11 @@ const pages: IPages = {
"illustration-button": {
name: 'Illustration Button',
component: IllustrationButtonDoc,
}
},
"loader": {
name: 'Loader',
component: LoaderDoc,
},
}
},
navigationComponents: {
Expand Down
24 changes: 24 additions & 0 deletions examples/pages/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import * as Markup from '../../js/react';
import {Loader} from '../../../app-typescript';

export default class LoaderDoc extends React.Component {
render() {
return (
<section className='docs-page__container'>
<h2 className='docs-page__h2'>Loader</h2>

<Markup.ReactMarkup>
<Markup.ReactMarkupPreview>
<Loader />
</Markup.ReactMarkupPreview>

<Markup.ReactMarkupCode>{`
<Loader />
`}
</Markup.ReactMarkupCode>
</Markup.ReactMarkup>
</section>
)
}
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superdesk-ui-framework",
"version": "3.1.15",
"version": "3.1.16",
"license": "AGPL-3.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1c9d130

Please sign in to comment.