Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.
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
4 changes: 3 additions & 1 deletion packages/oui-angular/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "@oui-angular/oui-criteria-adder/src";
import "@oui-angular/oui-chips/src";
import "@oui-angular/oui-popover/src";
import "@oui-angular/oui-stepper/src";
import "@oui-angular/oui-skeleton/src";

angular.module("oui", [
"oui.button",
Expand Down Expand Up @@ -55,5 +56,6 @@ angular.module("oui", [
"oui.criteria-adder",
"oui.chips",
"oui.popover",
"oui.stepper"
"oui.stepper",
"oui.skeleton"
]);
1 change: 1 addition & 0 deletions packages/oui-angular/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ loadTests(require.context("../../oui-criteria-adder/src/", true, /.*((\.spec)|(i
loadTests(require.context("../../oui-chips/src/", true, /.*((\.spec)|(index))$/));
loadTests(require.context("../../oui-popover/src/", true, /.*((\.spec)|(index))$/));
loadTests(require.context("../../oui-stepper/src/", true, /.*((\.spec)|(index))$/));
loadTests(require.context("../../oui-skeleton/src/", true, /.*((\.spec)|(index))$/));

function loadTests (context) {
context.keys().forEach(context);
Expand Down
36 changes: 36 additions & 0 deletions packages/oui-skeleton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Skeleton

<component-status cx-design="complete" ux="rc"></component-status>

## Usage

### Default
```html:preview
<oui-skeleton></oui-skeleton>
```

### Size
Copy link
Contributor

@neolitec neolitec May 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe size is not the thing we want.
Typically the skeleton graphically represents a text we don't know in advance. So the size should be... randomized :)
Maybe the right parameters here should be "min-width" with a default value and eventually "width" / "auto" if we want to force the width... ?
In my opinion, "min-width" to 30% by default for example so that the skeleton always take between 30% and 100% of the width.
@AxelPeter what do you think about?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea. But I don't think it's the case for all uses.
We can even have both with an attribute "randomized" for example :)

In fact, I'm not a fan of replacing style="width: 80%" just by width="80%". That's why by default, I let the skeleton with auto to let the user set its width.

I'll check to add your idea

```html:preview
<oui-skeleton size="xs"></oui-skeleton>
<oui-skeleton size="s"></oui-skeleton>
<oui-skeleton size="m"></oui-skeleton>
<oui-skeleton size="l"></oui-skeleton>
<oui-skeleton size="xl"></oui-skeleton>
<oui-skeleton size="auto"></oui-skeleton>
```

### Randomized width
```html:preview
<oui-skeleton randomized></oui-skeleton>
<oui-skeleton randomized></oui-skeleton>
<oui-skeleton randomized></oui-skeleton>
<oui-skeleton randomized></oui-skeleton>
<oui-skeleton randomized></oui-skeleton>
```

## API

| Attribute | Type | Binding | One-time Binding | Values | Default | Description
| ---- | ---- | ---- | ---- | ---- | ---- | ----
| size | String | @? | yes | `xs`, `s`, `m`, `l`, `xl` | `auto` | Skeleton size
| randomized | Boolean | <? | yes | | `false` | Randomized width flag
4 changes: 4 additions & 0 deletions packages/oui-skeleton/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Skeleton from "./skeleton.component.js";

angular.module("oui.skeleton", [])
.component("ouiSkeleton", Skeleton);
33 changes: 33 additions & 0 deletions packages/oui-skeleton/src/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe("ouiSkeleton", () => {
let TestUtils;
let $timeout;

beforeEach(angular.mock.module("oui.skeleton"));
beforeEach(angular.mock.module("oui.test-utils"));

beforeEach(inject((_TestUtils_, _$timeout_) => {
TestUtils = _TestUtils_;
$timeout = _$timeout_;
}));

describe("Component", () => {
it("should display a oui-skeleton", () => {
const element = TestUtils.compileTemplate("<oui-skeleton></oui-skeleton");
expect(element).toBeTruthy();
});

it("should display a oui skeleton div", () => {
const element = TestUtils.compileTemplate("<oui-skeleton size=\"m\"></oui-skeleton");

$timeout.flush();
expect(element.hasClass("oui-skeleton_m")).toBeTruthy();
});

it("should display a oui skeleton div with a randomized width", () => {
const element = TestUtils.compileTemplate("<oui-skeleton randomized></oui-skeleton");

$timeout.flush();
expect(!!element.css("width")).toBeTruthy();
});
});
});
11 changes: 11 additions & 0 deletions packages/oui-skeleton/src/skeleton.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import controller from "./skeleton.controller";
import template from "./skeleton.html";

export default {
controller,
template,
bindings: {
size: "@?",
randomized: "<?"
}
};
31 changes: 31 additions & 0 deletions packages/oui-skeleton/src/skeleton.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { addBooleanParameter, addDefaultParameter } from "@oui-angular/common/component-utils";

export default class {
constructor ($attrs, $element, $timeout) {
"ngInject";

this.$attrs = $attrs;
this.$element = $element;
this.$timeout = $timeout;
}

$onInit () {
addDefaultParameter(this, "size", "auto");
addBooleanParameter(this, "randomized");
}

$postLink () {
this.$timeout(() => {
this.$element.addClass(`oui-skeleton oui-skeleton_${this.size}`);

if (this.randomized) {
// Needed for eslint
const minWidth = 30;
const maxWidth = 100;
const randomWidth = Math.round((Math.random() * (maxWidth - minWidth)) + minWidth);

this.$element.css("width", `${randomWidth}%`);
}
});
}
}
1 change: 1 addition & 0 deletions packages/oui-skeleton/src/skeleton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="oui-skeleton__loader"></div>