Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fca0217
feat Add theming support to storybook
Apr 14, 2020
273904e
feat Update theming to support custom color
Apr 14, 2020
9e10e18
feat Remove commented out code
Apr 14, 2020
5077f39
feat Remove reset functionality
Apr 14, 2020
3b16e9d
feat Add Color prototype to utilities
Apr 14, 2020
7759908
feat Clean up color prototype, add todo notes
Apr 14, 2020
4b7e845
Merge branch 'master' into feat-add-theming-storybook
castastrophe May 20, 2020
81c5f07
Update Color object with latest code
castastrophe May 20, 2020
1755e0d
Update CHANGELOG-prerelease.md
castastrophe May 20, 2020
3507dfe
Merge branch 'master' into feat-add-theming-storybook
castastrophe Jul 20, 2020
4861e0d
feat: Update version dependencies
Jul 20, 2020
255e33e
feat: Update dep for pfe-jump-links
Jul 20, 2020
311ce36
feat: Add a dynamic context if custom is selected
Jul 20, 2020
15630ad
Revert package updates
Jul 20, 2020
7fc5578
Merge branch 'master' of https://github.com/patternfly/patternfly-ele…
Jul 29, 2020
9225d0d
Merge branch 'master' into feat-add-theming-storybook
castastrophe Jul 31, 2020
0cf6343
Merge branch 'master' into feat-add-theming-storybook
castastrophe Aug 4, 2020
1598f4d
Merge branch 'master' into feat-add-theming-storybook
castastrophe Aug 13, 2020
8c24bf4
Merge branch 'master' of https://github.com/patternfly/patternfly-ele…
Aug 24, 2020
9c8ba58
Merge branch 'master' into feat-add-theming-storybook
castastrophe Aug 25, 2020
4d125b4
Update CHANGELOG-prerelease.md
castastrophe Aug 25, 2020
f12c84a
Merge branch 'master' into feat-add-theming-storybook
castastrophe Sep 3, 2020
24a106b
feat: Update with latest from master
Nov 30, 2020
d317dd1
feat: Updating styles to latest
Nov 30, 2020
391b0c6
feat: Working through some jump links issues via storybook
Nov 30, 2020
8212863
feat: Fix bug in panel on jump links
Nov 30, 2020
6ac7938
feat: Update other references to autoPropKnobs
Nov 30, 2020
2e7113e
feat: Fixing storybook
Nov 30, 2020
7b2b485
feat: Remove requirement for storybook bridge to be passed to method;…
Dec 1, 2020
0bef449
feat: Remove list overrides from base styles
Dec 1, 2020
eccd380
feat: Fix 2 more minor storybook bugs
Dec 1, 2020
c09526f
removing console.log
kylebuch8 Dec 1, 2020
9f7fd47
removing priority override
kylebuch8 Dec 1, 2020
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
242 changes: 242 additions & 0 deletions .storybook/color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
export function Color(initial) {
const getsRGB = (c) => {
let item = c / 255;
item =
item <= 0.03928
? item / 12.92
: Math.pow((item + 0.055) / 1.055, 2.4);
return item;
};

this.getRGBA = (string) => {
const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/;
let match, check, getColor;

// Create an element upon which to attach this color
check = document.createElement("span");
check.style.setProperty("background-color", string);
check.style.setProperty("display", "none");
document.querySelector("body").appendChild(check);

// Get the color from this new element
getColor = window
.getComputedStyle(check, null)
.getPropertyValue("background-color");

if ((match = getColor.match(rgbRegex))) {
this.red = match[1];
this.green = match[2];
this.blue = match[3];
this.opacity = match[4] || 1;
}

return this;
};

this.setHSL = () => {
let r = this.red / 255;
let g = this.green / 255;
let b = this.blue / 255;

let min = Math.min(r, g, b);
let max = Math.max(r, g, b);
let diff = max - min;

this.lightness = (max + min) / 2;

if (max === min) {
// Achromatic
this.hue = 0;
this.saturation = 0;
} else {
this.saturation =
this.lightness < 0.5
? diff / (max + min)
: diff / (2 - max - min);

switch (max) {
case r:
this.hue = (g - b) / diff + (g < b ? 6 : 0);
break;
case g:
this.hue = (b - r) / diff + 2;
break;
case b:
this.hue = (r - g) / diff + 4;
break;
}

this.hue = this.hue / 6;
}
};

this.random = (limit = {}) => {
let lower;
let upper;
function checkRange(lower, upper) {
if (lower > upper) {
console.warn(
`Color.random() | ${color}: The lower limit (${lower}) must be a smaller number than the upper limit (${upper}).`
);
// Switch the values
return [upper, lower];
}

return [lower, upper];
}

limit = Object.assign(
{
red: {},
green: {},
blue: {},
opacity: {}
},
limit
);

["red", "green", "blue"].forEach((color) => {
lower = limit[color].lower || 1;
upper = limit[color].upper || 255;
[lower, upper] = checkRange(lower, upper);
this[color] = Math.floor(Math.random() * (upper - lower)) + lower;
});

lower = limit.opacity.lower || 0;
upper = limit.opacity.upper || 1;
[lower, upper] = checkRange(lower, upper);
this.opacity =
Math.round((Math.random() * (upper - lower) + lower) * 100) / 100;

this.setHSL();
return this;
};

// Initialize color
if (typeof initial === "string") {
this.getRGBA(initial);
} else if (typeof initial === "object") {
this.red = initial.red || 0;
this.green = initial.green || 0;
this.blue = initial.blue || 0;
this.opacity = initial.opacity || 1;
}

this.setHSL();

Object.defineProperty(this, "brightness", {
get() {
return (
1 -
(0.299 * this.red + 0.587 * this.green + 0.114 * this.blue) /
255
);
}
});

Object.defineProperty(this, "luminance", {
get() {
return (
0.2126 * getsRGB(this.red) +
0.7152 * getsRGB(this.green) +
0.0722 * getsRGB(this.blue)
);
}
});

Object.defineProperty(this, "rgba", {
get() {
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.opacity})`;
}
});

Object.defineProperty(this, "rgb", {
get() {
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
}
});

Object.defineProperty(this, "hex", {
get() {
function convert(num) {
let hex;
num = num < 1 ? Math.round(num * 255) : num;
hex = Number(num).toString(16);
return hex.length < 2 ? "0" + hex : hex;
}

return `#${convert(this.red)}${convert(this.green)}${convert(
this.blue
)}${convert(this.opacity)}`;
}
});

Object.defineProperty(this, "hsla", {
get() {
return `hsla(${Math.floor(this.hue * 360)}, ${Math.floor(
this.saturation * 100
)}%, ${Math.floor(this.lightness * 100)}%, ${this.opacity})`;
}
});

this.difference = (compare) => {
if (typeof compare === "object") {
return (
Math.max(this.red, compare.red) -
Math.min(this.red, compare.red) +
(Math.max(this.green, compare.green) -
Math.min(this.green, compare.green)) +
(Math.max(this.blue, compare.blue) -
Math.min(this.blue, compare.blue))
);
}
};

// WIP
this.a11yRating = (type) => {
const results = ["FAIL", "AA", "AAA"];
let l1, l2, contrast;
let ret = results[0];

// Collect typography values
const styles = window.getComputedStyle(type, null);
const size = parseInt(styles.getPropertyValue("font-size"));
const weight = parseInt(styles.getPropertyValue("font-weight"));
const color = new Color(styles.getPropertyValue("color"));

l1 = color.luminance;
l2 = this.luminance;

contrast =
Math.floor(
((Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05)) * 100
) / 100;

// AAA Large means that your large text has a contrast ratio of 4.5 or higher, which is the same score as AA
// The WCAG describes 14pt bold and 18pt as "large" sizes
if (size < 24 && (size < 18.5 || weight < 400)) {
// Requires 4.5:1 contrast ratio
if (contrast > 4.5) {
ret = results[1];
} else if (contrast > 7) {
ret = results[2];
}
} else {
// Requires 3:1 contrast ratio
if (contrast > 3) {
ret = results[1];
} else if (contrast > 4.5) {
ret = results[2];
}
}

// @TODO how to include opacity in this?

return {
background: this.hex,
foreground: color.hex,
ratio: contrast,
rating: ret
};
};
}
19 changes: 2 additions & 17 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { configure, addParameters } from "@storybook/polymer";

import "./test-theme.css";
import "./custom-theme.css";

const req = require.context("../elements", true, /\.story\.js$/);

Expand All @@ -13,22 +13,7 @@ addParameters({
brandTitle: "PatternFly Elements",
brandUrl: "/"
}
},
backgrounds: [
{
name: "light",
value: "#fff",
default: true
},
{
name: "dark",
value: "#252525"
},
{
name: "saturated",
value: "#007a87"
}
]
}
});

function loadStories() {
Expand Down
41 changes: 41 additions & 0 deletions .storybook/custom-theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#root {
margin: 5px 10px;
}

.sb-show-main pre {
font-family: "Overpass Mono", Consolas, Monaco, 'Andale Mono', monospace;
white-space: pre-wrap;
padding: 10px 20px;
background-color: #ddd;
border: 1px solid #bbb;
margin: 20px 10px;
}

hr {
border: 1px solid #f0f0f0;
margin: 20px 0;
}

[on="dark"] {
--pfe-broadcasted--text: var(--pfe-theme--color--text--on-dark, #fff);
--pfe-broadcasted--link: var(--pfe-theme--color--link--on-dark, #73bcf7);
--pfe-broadcasted--link--hover: var(--pfe-theme--color--link--hover--on-dark, #bee1f4);
--pfe-broadcasted--link--focus: var(--pfe-theme--color--link--focus--on-dark, #bee1f4);
--pfe-broadcasted--link--visited: var(--pfe-theme--color--link--visited--on-dark, #bee1f4);
--pfe-broadcasted--link-decoration: var(--pfe-theme--link-decoration--on-dark, none);
--pfe-broadcasted--link-decoration--hover: var(--pfe-theme--link-decoration--hover--on-dark, underline);
--pfe-broadcasted--link-decoration--focus: var(--pfe-theme--link-decoration--focus--on-dark, underline);
--pfe-broadcasted--link-decoration--visited: var(--pfe-theme--link-decoration--visited--on-dark, none);
}

[on="saturated"] {
--pfe-broadcasted--text: var(--pfe-theme--color--text--on-saturated, #fff);
--pfe-broadcasted--link: var(--pfe-theme--color--link--on-saturated, #fff);
--pfe-broadcasted--link--hover: var(--pfe-theme--color--link--hover--on-saturated, #fafafa);
--pfe-broadcasted--link--focus: var(--pfe-theme--color--link--focus--on-saturated, #fafafa);
--pfe-broadcasted--link--visited: var(--pfe-theme--color--link--visited--on-saturated, #8476d1);
--pfe-broadcasted--link-decoration: var(--pfe-theme--link-decoration--on-saturated, underline);
--pfe-broadcasted--link-decoration--hover: var(--pfe-theme--link-decoration--hover--on-saturated, underline);
--pfe-broadcasted--link-decoration--focus: var(--pfe-theme--link-decoration--focus--on-saturated, underline);
--pfe-broadcasted--link-decoration--visited: var(--pfe-theme--link-decoration--visited--on-saturated, underline);
}
14 changes: 7 additions & 7 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<style>
html,
body {
font-family: 'Open Sans', sans-serif;
}
</style>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link
href="https://fonts.googleapis.com/css2?family=Overpass+Mono:wght@300;400;600;700&family=Overpass:ital,wght@0,100;0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,600;1,700;1,800;1,900&family=Red+Hat+Display:ital,wght@0,400;0,500;0,700;0,900;1,400;1,500;1,700;1,900&family=Red+Hat+Text:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@starryeyez024 There is an issue importing the fonts from Google isn't there? We're not referencing the Red Hat fonts in the project yet but if we do the weight mappings are off right?

Copy link
Member

@starryeyez024 starryeyez024 Dec 1, 2020

Choose a reason for hiding this comment

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

PFE can/should use the google font import method since its public, and the variables in the theme should match google fonts. https://github.com/patternfly/patternfly-elements/pull/1180/files#diff-72f58e02c1bef4a30c0860a93753d6c664bcc75326b9dc79911d410bf1c0d91bR9

Redhat-theme makes use of the font on static, and set different font weights:
https://gitlab.corp.redhat.com/uxdd/redhat-theme/-/merge_requests/103/diffs#8032f081053a55c41b3898c25e235f27f1daf4f6_43_43

Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is totally fine as-is. The typography branch does the work of having the components load the RH fonts, so this just means storybook will be ready. And Overpass is working too currently 👍

rel="stylesheet">

<link href="/pfe-styles/dist/pfe-base.css" rel="stylesheet">
<link href="/pfe-styles/dist/pfe-layouts.css" rel="stylesheet">
35 changes: 0 additions & 35 deletions .storybook/test-theme.css

This file was deleted.

Loading