Skip to content

Commit fdb6301

Browse files
mwczkylebuch8
authored andcommitted
pfe-avatar (#222)
* add rh-avatar, first pass * add `rhelement.var` to retrieve CSS custom properties * refactor some rh-avatar attributes * fix rh-avatar test * add user-provided image test * format rh-avatar scss with prettier * add rh-avatar support for --rh-avatar--colors CSS var * update avatar README * rh-avatar: handle 3+ initials in a name * remove initials from avatar * add markup preview to avatar in storybook * removing WIP from README * removing commented out sass * adding new color defaults * making the story a bit better * commenting out the root css variable override * built files * rebuild test index file * remove copyright and useless switch statement * remove unrelated elements' bundles * remove all 'initials' mentions from pfe-avatar README * prefix pfe-avatar attributes with 'pfe-' * fix avatar demo and storybook * fix avatar's storybook markup preview
1 parent cb38c14 commit fdb6301

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+10054
-7667
lines changed

.storybook/utils.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const listProperties = (obj, prefix = "") =>
2525
let p = set[0];
2626
let v = set[1];
2727
let print = set[2] || true;
28-
return print && v && v !== "null" ? ` ${p !== "slot" ? `${prefix ? `${prefix}-` : ""}` : ""}${p}="${v}"` : "";
28+
return print && v && v !== "null"
29+
? ` ${p !== "slot" ? `${prefix ? `${prefix}-` : ""}` : ""}${p}="${v}"`
30+
: "";
2931
})
3032
.join("");
3133

@@ -82,8 +84,14 @@ const parseMarkup = string => {
8284
// Break the attributes apart using the equal sign
8385
let items = set.trim().split("=");
8486
// If items are returned and they are both strings, add them to the attributes object
85-
if (items.length > 1 && typeof items[0] === "string" && typeof items[1] === "string") {
86-
obj.attributes[items[0].trim()] = items[1].replace(quotes, "").trim();
87+
if (
88+
items.length > 1 &&
89+
typeof items[0] === "string" &&
90+
typeof items[1] === "string"
91+
) {
92+
obj.attributes[items[0].trim()] = items[1]
93+
.replace(quotes, "")
94+
.trim();
8795
}
8896
});
8997
}
@@ -107,7 +115,9 @@ const renderSlots = (slots = []) =>
107115
// Grep the content to see if we can use the first tag passed in
108116
let has_tag = typeof slot.tag !== "undefined";
109117
let has_slot = typeof slot.slot !== "undefined" && slot.slot.length > 0;
110-
let has_attr = typeof slot.attributes !== "undefined" && Object.keys(slot.attributes).length > 0;
118+
let has_attr =
119+
typeof slot.attributes !== "undefined" &&
120+
Object.keys(slot.attributes).length > 0;
111121
if (!has_tag && (has_slot || has_attr)) {
112122
Object.assign(slot, parseMarkup(slot.content));
113123
}
@@ -124,7 +134,9 @@ const renderSlots = (slots = []) =>
124134

125135
// Creates a component dynamically based on inputs
126136
export function component(tag, attributes = {}, slots = [], prefix = "") {
127-
return `<${tag}${listProperties(attributes, prefix)}>${slots.length > 0 ? renderSlots(slots) : autoContent()}</${tag}>`;
137+
return `<${tag}${listProperties(attributes, prefix)}>${
138+
slots.length > 0 ? renderSlots(slots) : autoContent()
139+
}</${tag}>`;
128140
}
129141

130142
// Create an automatic heading
@@ -245,7 +257,9 @@ export function code(markup) {
245257
);
246258

247259
// Return the rendered markup and the code snippet output
248-
return `<pre style="white-space: pre-wrap; padding: 20px 50px; background-color: #f0f0f0; font-weight: bold; border: 1px solid #bccc;">${escapeHTML(markup)}</pre>`;
260+
return `<pre style="white-space: pre-wrap; padding: 20px 50px; background-color: #f0f0f0; font-weight: bold; border: 1px solid #bccc;">${escapeHTML(
261+
markup
262+
)}</pre>`;
249263
}
250264
// prettier-ignore-end
251265

doc/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h1>Demos</h1>
1212
<ul id="demos">
1313
<li><a href="../elements/pfe-accordion/demo">pfe-accordion</a></li>
1414
<li><a href="../elements/pfe-autocomplete/demo">pfe-autocomplete</a></li>
15+
<li><a href="../elements/pfe-avatar/demo">pfe-avatar</a></li>
1516
<li><a href="../elements/pfe-band/demo">pfe-band</a></li>
1617
<li><a href="../elements/pfe-card/demo">pfe-card</a></li>
1718
<li><a href="../elements/pfe-content-set/demo">pfe-content-set</a></li>

elements/pfe-accordion/pfe-accordion.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

elements/pfe-autocomplete/pfe-autocomplete.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

elements/pfe-avatar/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": [["env", { "modules": false }]],
3+
"plugins": ["external-helpers"]
4+
}

elements/pfe-avatar/.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig: http://EditorConfig.org
2+
3+
# Top-most EditorConfig file
4+
root = true
5+
6+
# Rules for JavaScript files:
7+
8+
[*.{js,py,json,sh,html}]
9+
# 4 space indentation
10+
indent_style = space
11+
indent_size = 2
12+
# No trailing spaces
13+
trim_trailing_whitespace = true
14+
# Unix-style newlines
15+
end_of_line = lf
16+
# Newline ending every file
17+
insert_final_newline = true

elements/pfe-avatar/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

elements/pfe-avatar/.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
addons:
5+
firefox: "latest"
6+
apt:
7+
sources:
8+
- google-chrome
9+
packages:
10+
- google-chrome-stable
11+
node_js: stable
12+
before_install:
13+
- npm install -g web-component-tester
14+
install:
15+
- npm install
16+
before_script:
17+
script:
18+
- xvfb-run npm run test

elements/pfe-avatar/LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2018 Red Hat, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

elements/pfe-avatar/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
PFElements Avatar Element
2+
3+
`pfe-avatar` is an element for displaying a user's avatar image. If the user in question has provided a custom avatar, provide it and it will be displayed. If they don't, a nice colored pattern will be generated based on their name. A specific name will always generate the same pattern, so users' avatars will stay static without the need for storing their generated image.
4+
5+
## Usage
6+
7+
```html
8+
<pfe-avatar name="Eleanore Stillwagon"></pfe-avatar>
9+
10+
<pfe-avatar name="Libbie Koscinski" shape="rounded" pattern="squares"></pfe-avatar>
11+
12+
<pfe-avatar name="Blanca Rohloff" pattern="triangles"></pfe-avatar>
13+
14+
<pfe-avatar name="Edwardo Lindsey" src="https://clayto.com/2014/03/rgb-webgl-color-cube/colorcube.jpg"></pfe-avatar>
15+
```
16+
17+
## Attributes
18+
19+
### pfe-name (observed) (required)
20+
21+
The user's name, either given name and family name, or username. When displaying a pattern, the name will be used to seed the pattern generator.
22+
23+
### pfe-src (observed)
24+
25+
The URL to the user's custom avatar image. It will be displayed instead of a random pattern.
26+
27+
### pfe-pattern (observed)
28+
29+
The type of pattern to display. Currently supported values are `"squares"` and `"triangles"`.
30+
31+
| squares | triangles |
32+
| ------------------------------- | ----------------------------------- |
33+
| ![squares image](./squares.png) | ![triangles image](./triangles.png) |
34+
35+
### pfe-shape (observed)
36+
37+
The shape of the avatar itself. Supported values are `"square"` (default), `"rounded"`, and `"circle"`.
38+
39+
## Styling
40+
41+
| Theme Var Hook | Description | Default |
42+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
43+
| `--pfe-avatar--colors` | A space-delimited list of colors to use for generated patterns. Only hex values are supported, ex: `#fc0` or `#0fcb41`. Any number of colors may be provided. | `#3B0083 #f0ab00 #007a87 #00b9e4 #92d400` |
44+
45+
## Test
46+
47+
npm run test
48+
49+
## Build
50+
51+
npm run build
52+
53+
## Demo
54+
55+
From the PFElements root directory, run:
56+
57+
npm start
58+
59+
## Code style
60+
61+
Avatar (and all PFElements) use [Prettier][prettier] to auto-format JS and JSON. The style rules get applied when you commit a change. If you choose to, you can [integrate your editor][prettier-ed] with Prettier to have the style rules applied on every save.
62+
63+
[prettier]: https://github.com/prettier/prettier/
64+
[prettier-ed]: https://prettier.io/docs/en/editors.html
65+
[web-component-tester]: https://github.com/Polymer/web-component-tester

0 commit comments

Comments
 (0)