Skip to content

Commit

Permalink
Implements #1171 - Loading indicator component
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceosterhaus committed Nov 5, 2018
1 parent daf4fd1 commit 8c2b367
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/clay-loading-indicator/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Software License Agreement (BSD License)

Copyright (c) 2014, Liferay Inc.
All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.

* The name of Liferay Inc. may not be used to endorse or promote products
derived from this software without specific prior
written permission of Liferay Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 changes: 26 additions & 0 deletions packages/clay-loading-indicator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# clay-loading-indicator

Clay Loading Indicator

## Setup

1. Install NodeJS >= v0.12.0 and NPM >= v3.0.0, if you don't have it yet. You
can find it [here](https://nodejs.org).

2. Install local dependencies:

```
npm install
```

3. Build the code:

```
npm run build
```

4. Open the demo at demos/index.html on your browser.

## Contribute

We'd love to get contributions from you! Please, check our [Contributing Guidelines](CONTRIBUTING.md) to see how you can help us improve.
28 changes: 28 additions & 0 deletions packages/clay-loading-indicator/demos/a11y.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo: Metal Clay Loading Indicator</title>
<link rel="stylesheet" href="../../../node_modules/clay-css/lib/css/atlas.css">
<script src="../build/globals/clay-loading-indicator.js"></script>
</head>

<body role="main">
<h1>Metal Clay Loading Indicator</h1>
<h3>Default:</h3>
<div id="loadingIndicator"></div>
<h3>Small:</h3>
<div id="loadingIndicatorSmall"></div>
<h3>Light:</h3>
<div id="loadingIndicatorLight"></div>

<script type="text/javascript">
new metal.ClayLoadingIndicator({}, '#loadingIndicator');
new metal.ClayLoadingIndicator({ small: true }, '#loadingIndicatorSmall');
new metal.ClayLoadingIndicator({ light: true }, '#loadingIndicatorLight');
</script>
</body>

</html>
28 changes: 28 additions & 0 deletions packages/clay-loading-indicator/demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo: Metal Clay Loading Indicator</title>
<link rel="stylesheet" href="../../../node_modules/clay-css/lib/css/atlas.css">
<script src="../build/globals/clay-loading-indicator.js"></script>
</head>

<body role="main">
<h1>Metal Clay Loading Indicator</h1>
<h3>Default:</h3>
<div id="loadingIndicator"></div>
<h3>Small:</h3>
<div id="loadingIndicatorSmall"></div>
<h3>Light:</h3>
<div id="loadingIndicatorLight"></div>

<script type="text/javascript">
new metal.ClayLoadingIndicator({}, '#loadingIndicator');
new metal.ClayLoadingIndicator({ small: true }, '#loadingIndicatorSmall');
new metal.ClayLoadingIndicator({ light: true }, '#loadingIndicatorLight');
</script>
</body>

</html>
51 changes: 51 additions & 0 deletions packages/clay-loading-indicator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "clay-loading-indicator",
"version": "1.0.0",
"description": "Clay Loading Indicator Component",
"license": "BSD",
"repository": "https://github.com/liferay/clay/tree/master/packages/clay-loading-indicator",
"engines": {
"node": ">=0.12.0",
"npm": ">=3.0.0"
},
"main": "lib/ClayLoadingIndicator.js",
"esnext:main": "src/ClayLoadingIndicator.js",
"jsnext:main": "src/ClayLoadingIndicator.js",
"files": [
"lib",
"src",
"test"
],
"scripts": {
"build": "npm run soy && webpack",
"compile": "babel -d lib/ src/ -s --ignore src/__tests__",
"prepublish": "npm run soy && npm run compile",
"link": "npm link",
"soy": "metalsoy"
},
"keywords": [
"clay",
"metal"
],
"dependencies": {
"metal": "^2.16.0",
"metal-component": "^2.16.0",
"metal-dom": "^2.16.0",
"metal-state": "^2.16.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-plugin-transform-node-env-inline": "^0.1.1",
"babel-preset-env": "^1.6.0",
"browserslist-config-clay": "^2.3.4",
"clay-css": "^2.3.4",
"metal-tools-soy": "^6.0.0",
"webpack": "^3.0.0",
"webpack-config-clay": "^2.3.4"
},
"browserslist": [
"extends browserslist-config-clay"
]
}
53 changes: 53 additions & 0 deletions packages/clay-loading-indicator/src/ClayLoadingIndicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Component from 'metal-component';
import defineWebComponent from 'metal-web-component';
import Soy from 'metal-soy';
import {Config} from 'metal-state';

import templates from './ClayLoadingIndicator.soy.js';

/**
* Implementation of the Clay loading indicator
* @extends Component
*/
class ClayLoadingIndicator extends Component {}

/**
* State definition.
* @static
* @type {!Object}
*/
ClayLoadingIndicator.STATE = {
/**
* CSS classes to be applied to the element.
* @default undefined
* @instance
* @memberof ClayLoadingIndicator
* @type {?(string|undefined)}
*/
elementClasses: Config.string(),

/**
* Flag to indicate if indicator should be light colored
* @default false
* @instance
* @memberof ClayLoadingIndicator
* @type {?bool}
*/
light: Config.bool().value(false),

/**
* Flag to indicate if the indicator should be small
* @default false
* @instance
* @memberof ClayLoadingIndicator
* @type {?bool}
*/
small: Config.bool().value(false),
};

defineWebComponent('clay-loading-indicator', ClayLoadingIndicator);

Soy.register(ClayLoadingIndicator, templates);

export {ClayLoadingIndicator};
export default ClayLoadingIndicator;
29 changes: 29 additions & 0 deletions packages/clay-loading-indicator/src/ClayLoadingIndicator.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{namespace ClayLoadingIndicator}

/**
* This renders a Clay loading indicator.
*/
{template .render}
{@param? elementClasses: string}
{@param? light: bool}
{@param? small: bool}

{let $attributes kind="attributes"}
aria-hidden="true"
class="loading-animation
{if $light}
{sp}loading-animation-light
{/if}

{if $small}
{sp}loading-animation-sm
{/if}

{if $elementClasses}
{sp}{$elementClasses}
{/if}
"
{/let}

<span {$attributes}></span>
{/template}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import ClayLoadingIndicator from '../ClayLoadingIndicator';

let clayLoading;

describe('ClayLoadingIndicator', function() {
afterEach(() => {
if (clayLoading) {
clayLoading.dispose();
}
});

it('should render', () => {
clayLoading = new ClayLoadingIndicator();

expect(clayLoading).toMatchSnapshot();
});

it('should render an indicator with classes', () => {
clayLoading = new ClayLoadingIndicator({
elementClasses: 'my-custom-class',
});

expect(clayLoading).toMatchSnapshot();
});

it('should render an indicator with light color', () => {
clayLoading = new ClayLoadingIndicator({
light: true,
});

expect(clayLoading).toMatchSnapshot();
});

it('should render an indicator with small size', () => {
clayLoading = new ClayLoadingIndicator({
small: true,
});

expect(clayLoading).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ClayLoadingIndicator should render 1`] = `<span aria-hidden="true" class="loading-animation"></span>`;

exports[`ClayLoadingIndicator should render an indicator with classes 1`] = `<span aria-hidden="true" class="loading-animation my-custom-class"></span>`;

exports[`ClayLoadingIndicator should render an indicator with light color 1`] = `<span aria-hidden="true" class="loading-animation loading-animation-light"></span>`;

exports[`ClayLoadingIndicator should render an indicator with small size 1`] = `<span aria-hidden="true" class="loading-animation loading-animation-sm"></span>`;
8 changes: 8 additions & 0 deletions packages/clay-loading-indicator/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const webpackCommonConfig = require('webpack-config-clay');

module.exports = Object.assign(webpackCommonConfig, {
entry: './src/ClayLoadingIndicator.js',
output: Object.assign(webpackCommonConfig.output, {
filename: './build/globals/clay-loading-indicator.js',
}),
});

0 comments on commit 8c2b367

Please sign in to comment.