This repository was archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: oui skeleton #185
Merged
Merged
feat: oui skeleton #185
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55f9b60
feat: oui skeleton
varun257 1c7ed91
feat: oui skeleton
varun257 90bc904
feat: oui skeleton
varun257 caa854d
feat: oui skeleton
varun257 b5544e1
chore(oui-skeleton): update attributes and tests
aa29fa4
chore(oui-skeleton): add flush
14704d2
feat(oui-skeleton): add randomized width
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
```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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "<?" | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}%`); | ||
} | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="oui-skeleton__loader"></div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 bywidth="80%"
. That's why by default, I let the skeleton withauto
to let the user set its width.I'll check to add your idea