Skip to content

Commit

Permalink
feat: add accent color and background color selection (#3123)
Browse files Browse the repository at this point in the history
* feat: add color pickers and preview

* formatting

* added dark / light mode

* add prettier

* ran prettier

* saved last index for selecting background

* addressed Rob's comments

* ran prettier

* addressed comments
  • Loading branch information
eljefe223 authored and radium-v committed May 18, 2020
1 parent 639e148 commit 19f7819
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 22 deletions.
5 changes: 4 additions & 1 deletion sites/fast-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"html-webpack-plugin": "^4.3.0",
"mini-css-extract-plugin": "^0.9.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"prettier": "2.0.2",
"terser-webpack-plugin": "^3.0.1",
"ts-loader": "^7.0.2",
"typescript": "^3.8.3",
Expand All @@ -24,7 +25,9 @@
},
"scripts": {
"start": "webpack-dev-server --config=./webpack.dev.js --history-api-fallback --progress",
"build": "webpack --config=./webpack.prod.js"
"build": "webpack --config=./webpack.prod.js",
"prettier": "prettier --config ../../.prettierrc --write \"**/*.ts\"",
"prettier:diff": "prettier --config ../../.prettierrc \"**/*.ts\" --list-different"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { css } from "@microsoft/fast-element";
import {
display,
heightNumber,
neutralFillInputHoverBehavior,
neutralFillInputRestBehavior,
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
forcedColorsStylesheetBehavior,
SystemColors,
focusVisible,
disabledCursor,
} from "@microsoft/fast-components";
import { neutralForegroundRestBehavior } from "@microsoft/fast-components";

export const ColorSwatchStyles = css`
${display("inline-flex")} :host {
--input-size: calc((${heightNumber} / 2) + var(--design-unit));
align-items: center;
outline: none;
margin: calc(var(--design-unit) * 1px) 0;
${
/*
* Chromium likes to select label text or the default slot when
* the radio button is clicked. Maybe there is a better solution here?
*/ ""
} user-select: none;
position: relative;
flex-direction: row;
transition: all 0.2s ease-in-out;
}
.control {
position: relative;
width: calc(var(--input-size) * 1px);
height: calc(var(--input-size) * 1px);
box-sizing: border-box;
border-radius: calc(var(--corner-radius) * 1px);
border: calc(var(--outline-width) * 1px) solid var(--neutral-outline-rest);
outline: none;
cursor: pointer;
}
.label__hidden {
display: none;
}
.label {
font-family: var(--body-font);
color: var(--neutral-foreground-rest);
${
/* Need to discuss with Brian how HorizontalSpacingNumber can work. https://github.com/microsoft/fast-dna/issues/2766 */ ""
} padding-inline-start: calc(var(--design-unit) * 2px + 2px);
margin-inline-end: calc(var(--design-unit) * 2px + 2px);
cursor: pointer;
${
/* Font size is temporary - replace when adaptive typography is figured out */ ""
} font-size: calc(1rem + (var(--density) * 2px));
}
.checked-indicator {
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
display: inline-block;
flex-shrink: 0;
background: var(--neutral-foreground-rest);
fill: var(--neutral-foreground-rest);
opacity: 0;
pointer-events: none;
}
.control:hover {
border-color: var(--neutral-outline-hover);
}
:host(:${focusVisible}) .control {
box-shadow: 0 0 0 1px var(--neutral-focus) inset;
border-color: var(--neutral-focus);
}
:host(.disabled) .label,
:host(.readonly) .label,
:host(.readonly) .control,
:host(.disabled) .control {
cursor: ${disabledCursor};
}
:host(.checked) .checked-indicator {
opacity: 1;
}
:host(.disabled) {
opacity: var(--disabled-opacity);
}
`.withBehaviors(
neutralFillInputHoverBehavior,
neutralFillInputRestBehavior,
neutralForegroundRestBehavior,
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
forcedColorsStylesheetBehavior(
css`
.control, .control:hover, .control:active {
forced-color-adjust: none;
border-color: ${SystemColors.FieldText};
background: ${SystemColors.Field};
}
:host(:${focusVisible}) .control {
border-color: ${SystemColors.Highlight};
}
:host(.checked) .control:hover, .control:active {
border-color: ${SystemColors.Highlight};
background: ${SystemColors.Highlight};
}
:host(.checked) .checked-indicator {
background: ${SystemColors.Highlight};
fill: ${SystemColors.Highlight};
}
:host(.checked) .control:hover .checked-indicator {
background: ${SystemColors.HighlightText};
fill: ${SystemColors.HighlightText};
}
:host(.disabled) {
forced-color-adjust: none;
opacity: 1;
}
:host(.disabled) .label {
color: ${SystemColors.GrayText};
}
:host(.disabled) .control,
:host(.checked.disabled) .control:hover, .control:active {
background: ${SystemColors.Field};
border-color: ${SystemColors.GrayText};
}
:host(.disabled) .checked-indicator,
:host(.checked.disabled) .control:hover .checked-indicator {
fill: ${SystemColors.GrayText};
background: ${SystemColors.GrayText};
}
`
)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { html, when, slotted } from "@microsoft/fast-element";
import { ColorSwatch } from "./color-swatch";

export const ColorSwatchTemplate = html<ColorSwatch>`
<template
role="radio"
class="${x => (x.checked ? "checked" : "")} ${x =>
x.readOnly ? "readonly" : ""}"
aria-checked="${x => x.checked}"
aria-required="${x => x.required}"
aria-disabled="${x => x.disabled}"
aria-readonly="${x => x.readOnly}"
@keypress="${(x, c) => x.keypressHandler(c.event as KeyboardEvent)}"
@click="${(x, c) => x.clickHandler(c.event as MouseEvent)}"
>
<div part="control" class="control" style="background: ${x => x.backgroundColor}">
<slot name="checked-indicator">
<div part="checked-indicator" class="checked-indicator"></div>
</slot>
</div>
<label
part="label"
class="${x =>
x.defaultSlottedNodes && x.defaultSlottedNodes.length
? "label"
: "label label__hidden"}"
>
<slot ${slotted("defaultSlottedNodes")}></slot>
</label>
</template>
`;
10 changes: 10 additions & 0 deletions sites/fast-website/src/app/components/color-swatch/color-swatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { attr, observable } from "@microsoft/fast-element";
import { FASTRadio } from "@microsoft/fast-components";

export class ColorSwatch extends FASTRadio {
@attr({ attribute: "background-color" })
public backgroundColor: string = "#F33378";

@observable
public defaultSlottedNodes: Node[];
}
14 changes: 14 additions & 0 deletions sites/fast-website/src/app/components/color-swatch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { customElement } from "@microsoft/fast-element";
import { ColorSwatch } from "./color-swatch";
import { ColorSwatchTemplate as template } from "./color-swatch.template";
import { ColorSwatchStyles as styles } from "./color-swatch.styles";

@customElement({
name: "site-color-swatch",
template,
styles,
})
export class SiteColorSwatch extends ColorSwatch {}
export * from "./color-swatch.template";
export * from "./color-swatch.styles";
export * from "./color-swatch";
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { html, when } from "@microsoft/fast-element";
import { ContentPlacement } from "./content-placement";

export const ContentPlacementTemplate = html<ContentPlacement>`<fast-card>
<div
class=${x =>
x.divider
? ""
: "contentPlacement_icon"}
>
<div class=${x => (x.divider ? "" : "contentPlacement_icon")}>
<slot name="icon"></slot>
</div>
<slot></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const FastFrameStyles = css`
grid-gap: 40px;
grid-template-columns: 1fr 1fr;
padding: 40px;
background: var(--background-color);
}
.image-container {
Expand All @@ -52,19 +53,32 @@ export const FastFrameStyles = css`
flex-direction: column;
padding: 20px;
text-align: start;
color: var(--neutral-foreground-rest);
}
.badge {
align-self: flex-end;
margin: 20px;
}
.preview-controls {
display: grid;
grid-auto-rows: max-content;
grid-gap: 20px;
}
.control-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
.control-container-2 {
display: grid;
grid-template-columns: auto auto 1fr;
grid-gap: 20px;
}
.control-container p {
margin-inline-start: calc(var(--design-unit) * 2px + 2px);
}
Expand All @@ -78,6 +92,7 @@ export const FastFrameStyles = css`
display: grid;
grid-template-columns: auto 1fr;
text-align: start;
color: var(--neutral-foreground-rest);
}
.checkbox {
Expand All @@ -99,7 +114,6 @@ export const FastFrameStyles = css`
.sample-control {
display: flex;
background: var(--background-color);
align-items: center;
width: 100%;
}
Expand All @@ -123,6 +137,14 @@ export const FastFrameStyles = css`
--badge-fill-primary: var(--accent-fill-rest);
--badge-color-primary: var(--neutral-foreground-rest);
}
fast-slider {
min-width: unset;
}
fast-button {
display: contents;
}
`.withBehaviors(
accentFillRestBehavior,
accentForegroundCutRestBehavior,
Expand Down
Loading

0 comments on commit 19f7819

Please sign in to comment.