Skip to content

Commit

Permalink
Introduce animation helpers for loading icons
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkudrna committed Dec 31, 2019
1 parent 4a943d4 commit 99be881
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 32 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ To use React UI in your app:
import '@react-ui-org/react-ui/src/lib/theme.scss';
import '@react-ui-org/react-ui/src/lib/foundation.scss';
```
4. Optionally add the **utility classes** bundle:
4. Optionally add the **helper and utility classes** bundles:
```js
// app.jsx
import '@react-ui-org/react-ui/src/lib/theme.scss';
import '@react-ui-org/react-ui/src/lib/foundation.scss';
import '@react-ui-org/react-ui/src/lib/helpers.scss';
import '@react-ui-org/react-ui/src/lib/utilities.scss';
```
5. Finally, use React UI **components** just like you are used to:
Expand Down
10 changes: 5 additions & 5 deletions demo/generated/demo.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
}

.loader--rotate {
-webkit-animation: spin 1s infinite linear;
animation: spin 1s infinite linear;
-webkit-animation: spin 2.2s infinite cubic-bezier(0.31, 0.3, 0.34, -0.17);
animation: spin 2.2s infinite cubic-bezier(0.31, 0.3, 0.34, -0.17);
}

@-webkit-keyframes spin {
Expand All @@ -62,8 +62,8 @@
}

to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
-webkit-transform: rotate(1440deg);
transform: rotate(1440deg);
}
}

Expand All @@ -74,8 +74,8 @@
}

to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
-webkit-transform: rotate(1440deg);
transform: rotate(1440deg);
}
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion dist/lib.js

Large diffs are not rendered by default.

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": "@react-ui-org/react-ui",
"version": "0.23.2",
"version": "0.24.0",
"license": "MIT",
"main": "dist/lib.js",
"repository": {
Expand Down
37 changes: 34 additions & 3 deletions src/demo/pages/DemoContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
// React UI CSS theme and foundation
import '../../lib/theme.scss';
import '../../lib/foundation.scss';
import '../../lib/helpers.scss';

// React UI components
import {
Expand Down Expand Up @@ -635,13 +636,13 @@ class DemoContainer extends React.Component {
<Button
clickHandler={loggerClick}
label="Loading button"
loadingIcon={<Icon icon="sync" />}
loadingIcon={<span className="d-inline-flex animation-spin-counterclockwise"><Icon icon="sync" /></span>}
/>
<Button
clickHandler={loggerClick}
label="Loading button with icon and badge"
afterLabel={<Icon icon="stars" />}
loadingIcon={<Icon icon="sync" />}
loadingIcon={<span className="d-inline-flex animation-spin-counterclockwise"><Icon icon="sync" /></span>}
startCorner={<Badge label={3} />}
/>
</>
Expand Down Expand Up @@ -2464,12 +2465,42 @@ class DemoContainer extends React.Component {
/>
</section>
<hr />
<section id="helpers" className="mb-7">
<h2 className="typography-size-5 mb-6">Helpers</h2>
<p>
Helpers are CSS class names for common situations.
</p>
<h3 id="helpers-animation" className="typography-size-4 mb-6">Animation</h3>
<p>
Remember that non-block inline elements cannot be animated.
</p>
<Documentation
name="Animation"
component={(
<>
<p>
<code className="mr-3">.animation-spin-clockwise</code>
<span className="d-inline-flex animation-spin-clockwise">
<Icon icon="sync" />
</span>
</p>
<p>
<code className="mr-3">.animation-spin-counterclockwise</code>
<span className="d-inline-flex animation-spin-counterclockwise">
<Icon icon="sync" />
</span>
</p>
</>
)}
/>
</section>
<hr />
<section id="utilities" className="mb-7">
<h2 className="typography-size-5 mb-6">Utilities</h2>
<p>
Utilities are CSS class names that do just one thing.
</p>
<h3 id="utilities-block-alignment" className="typography-size-4 mb-6">Box Alignment</h3>
<h3 id="utilities-box-alignment" className="typography-size-4 mb-6">Box Alignment</h3>
<p>
Class name notation is
{' '}
Expand Down
10 changes: 10 additions & 0 deletions src/demo/pages/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ export default [
link: '#screens',
title: 'Screens',
},
{
items: [
{
link: '#helpers-animation',
title: 'Animation',
},
],
link: '#helpers',
title: 'Helpers',
},
{
items: [
{
Expand Down
14 changes: 0 additions & 14 deletions src/lib/components/ui/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
@import 'mixins';
@import 'variables';

@keyframes rotateIcon {
from {
transform: rotate(0);
}

to {
transform: rotate(-360deg);
}
}

.root {
@include button();
@include form-field-horizontal-neighbor();
Expand All @@ -34,10 +24,6 @@
justify-content: center;
}

.loadingIcon {
animation: rotateIcon 2s linear infinite;
}

.beforeLabel {
margin-right: $button-icon-offset;
}
Expand Down
24 changes: 24 additions & 0 deletions src/lib/helpers.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// General purpose helpers for common situations. Unlike utilities, helpers usually cover more CSS
// properties than one. And unlike with utilities, using `!important` is not allowed here.

$_spin-count: 4;
$_spin-duration: 2.2s;
$_spin-easing: cubic-bezier(0.31, 0.3, 0.34, -0.17);

@keyframes spin {
0% {
transform: rotate(0 * 360deg);
}

100% {
transform: rotate($_spin-count * 360deg);
}
}

:global(.animation-spin-clockwise) {
animation: spin $_spin-duration $_spin-easing infinite;
}

:global(.animation-spin-counterclockwise) {
animation: spin $_spin-duration $_spin-easing infinite reverse;
}

0 comments on commit 99be881

Please sign in to comment.