Skip to content

Commit

Permalink
(web-components) standardized remaining design token recipe types (#1…
Browse files Browse the repository at this point in the history
…8602)

Standardized remaining design token recipe types
  • Loading branch information
bheston authored and chrisdholt committed Jul 2, 2021
1 parent beb5650 commit 8e5d11b
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Standardized remaining design token recipe types",
"packageName": "@fluentui/web-components",
"email": "47367562+bheston@users.noreply.github.com",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion packages/web-components/src/color-vNext/recipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Swatch } from './swatch';

export interface SwatchFamily {
/** @public */
export interface InteractiveSwatchSet {
/**
* The swatch to apply to the rest state
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { inRange } from 'lodash-es';
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';

/**
* @internal
*/
export function accentFill(
palette: Palette,
neutralPaletteRGB: Palette,
neutralPalette: Palette,
reference: Swatch,
textColor: Swatch,
contrastTarget: number,
Expand All @@ -17,9 +18,9 @@ export function accentFill(
neutralFillRestDelta: number,
neutralFillHoverDelta: number,
neutralFillActiveDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const accent = palette.source;
const referenceIndex = neutralPaletteRGB.closestIndexOf(reference);
const referenceIndex = neutralPalette.closestIndexOf(reference);
const swapThreshold = Math.max(neutralFillRestDelta, neutralFillHoverDelta, neutralFillActiveDelta);
const direction = referenceIndex >= swapThreshold ? -1 : 1;
const paletteLength = palette.swatches.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';
import { directionByIsDark } from '../utilities/direction-by-is-dark';

Expand All @@ -13,7 +14,7 @@ export function accentForeground(
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const accent = palette.source;
const accentIndex = palette.closestIndexOf(accent);
const direction = directionByIsDark(reference);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';
import { directionByIsDark } from '../utilities/direction-by-is-dark';

Expand All @@ -12,7 +13,7 @@ export function neutralFillContrast(
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const direction = directionByIsDark(reference);
const accessibleIndex = palette.closestIndexOf(palette.colorContrast(reference, 4.5));
const accessibleIndex2 = accessibleIndex + direction * Math.abs(restDelta - hoverDelta);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';
import { directionByIsDark } from '../utilities/direction-by-is-dark';

Expand All @@ -12,7 +13,7 @@ export function neutralFillInput(
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const direction = directionByIsDark(reference);
const referenceIndex = palette.closestIndexOf(reference);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';
import { directionByIsDark } from '../utilities/direction-by-is-dark';

Expand All @@ -12,7 +13,7 @@ export function neutralFillInverse(
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const direction = directionByIsDark(reference);
const accessibleIndex = palette.closestIndexOf(palette.colorContrast(reference, 14));
const accessibleIndex2 = accessibleIndex + direction * Math.abs(restDelta - hoverDelta);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';

/**
Expand All @@ -15,7 +16,7 @@ export function neutralFillStealth(
fillHoverDelta: number,
fillActiveDelta: number,
fillFocusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const swapThreshold = Math.max(
restDelta,
hoverDelta,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';

/**
Expand All @@ -18,7 +19,7 @@ export function neutralFill(
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const referenceIndex = palette.closestIndexOf(reference);
const threshold = Math.max(restDelta, hoverDelta, activeDelta, focusDelta);
const direction = referenceIndex >= threshold ? -1 : 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { clamp } from '@microsoft/fast-colors';
import { PaletteRGB } from '../palette';
import { SwatchRGB } from '../swatch';
import { Palette } from '../palette';
import { Swatch } from '../swatch';
import { baseLayerLuminanceSwatch } from '../utilities/base-layer-luminance';

/**
* @internal
*/
export function neutralLayerCardContainer(
palette: PaletteRGB,
palette: Palette,
relativeLuminance: number,
layerDelta: number,
): SwatchRGB {
): Swatch {
const oldCardIndex: number = clamp(
palette.closestIndexOf(baseLayerLuminanceSwatch(relativeLuminance)) - layerDelta,
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { PaletteRGB } from '../palette';
import { Palette } from '../palette';
import { InteractiveSwatchSet } from '../recipe';
import { Swatch } from '../swatch';
import { directionByIsDark } from '../utilities/direction-by-is-dark';

/**
* @internal
*/
export function neutralStroke(
palette: PaletteRGB,
palette: Palette,
reference: Swatch,
restDelta: number,
hoverDelta: number,
activeDelta: number,
focusDelta: number,
): Record<"rest" | "hover" | "active" | "focus", Swatch> {
): InteractiveSwatchSet {
const referenceIndex = palette.closestIndexOf(reference);
const direction = directionByIsDark(reference);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SwatchRGB } from '../swatch';
import { Swatch, SwatchRGB } from '../swatch';

export function baseLayerLuminanceSwatch(luminance: number) {
export function baseLayerLuminanceSwatch(luminance: number): Swatch {
return SwatchRGB.create(luminance, luminance, luminance);
}
Loading

0 comments on commit 8e5d11b

Please sign in to comment.