Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(web-components) standardized remaining design token recipe types #18602

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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