How to use @microsoft/fast-colors - 10 common examples

To help you get started, we’ve selected a few @microsoft/fast-colors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / fast-dna / packages / fast-components-styles-msft / src / utilities / color / accent-foreground.spec.ts View on Github external
(swatch: Swatch): void => {
                        const designSystem: DesignSystem = Object.assign(
                            {},
                            designSystemDefaults,
                            {
                                backgroundColor: swatch,
                                accentPaletteConfig: Object.assign(
                                    {},
                                    accentPaletteConfig,
                                    { baseColor: parseColorHexRGB(swatch) }
                                ),
                            }
                        );

                        expect(
                            contrast(swatch, accentForegroundRest(designSystem))
                            // There are a few states that are impossible to meet contrast on
                        ).toBeGreaterThanOrEqual(4.47);
                        expect(
                            contrast(swatch, accentForegroundHover(designSystem))
                            // There are a few states that are impossible to meet contrast on
                        ).toBeGreaterThanOrEqual(3.7);
                        expect(
                            contrast(swatch, accentForegroundLargeRest(designSystem))
                        ).toBeGreaterThanOrEqual(3);
                        expect(
github microsoft / fast-dna / packages / fast-components-styles-msft / src / utilities / elevation.ts View on Github external
yOffsetMultiplier,
            opacity,
            blurMultiplier,
            blurBase = 0,
        }: ShadowConfig = shadowConfig;
        // TODO: (Breaking) Remove default https://github.com/microsoft/fast-dna/issues/2469

        const lum: number = rgbToRelativeLuminance(
            parseColorString(backgroundColor(config))
        );
        const opacityMultiple: number = 2 - lum; // white (1) = 1; black (0) = 2;
        return [xOffsetMultiplier, yOffsetMultiplier]
            .map((val: number) => parseFloat((val * elevationValue).toFixed(1)))
            .concat(blurBase + blurMultiplier * elevationValue)
            .map(toPx)
            .concat(new ColorRGBA64(r, g, b, opacity * opacityMultiple).toStringWebRGBA())
            .join(" ");
    };
}
github microsoft / fast-dna / packages / fast-components-styles-msft / src / utilities / elevation.ts View on Github external
return (config: DesignSystem): string => {
        const { r, g, b }: ColorRGBA64 = parseColorString(color);
        const {
            xOffsetMultiplier,
            yOffsetMultiplier,
            opacity,
            blurMultiplier,
            blurBase = 0,
        }: ShadowConfig = shadowConfig;
        // TODO: (Breaking) Remove default https://github.com/microsoft/fast-dna/issues/2469

        const lum: number = rgbToRelativeLuminance(
            parseColorString(backgroundColor(config))
        );
        const opacityMultiple: number = 2 - lum; // white (1) = 1; black (0) = 2;
        return [xOffsetMultiplier, yOffsetMultiplier]
            .map((val: number) => parseFloat((val * elevationValue).toFixed(1)))
            .concat(blurBase + blurMultiplier * elevationValue)
            .map(toPx)
            .concat(new ColorRGBA64(r, g, b, opacity * opacityMultiple).toStringWebRGBA())
            .join(" ");
    };
}
github microsoft / fast-dna / packages / fast-color-explorer / app / control-pane.tsx View on Github external
return (newColor: { hex: string }): void => {
            const color: ColorRGBA64 | null = parseColorHexRGB(newColor.hex);

            if (color instanceof ColorRGBA64 && typeof callback === "function") {
                callback(color);
            }

            this.setState({
                [palette]: newColor.hex,
            } as any);
        };
    }
github microsoft / fast-dna / packages / fast-color-explorer / app / control-pane.tsx View on Github external
const onClick: React.MouseEventHandler = (
                    e: React.MouseEvent
                ): void => {
                    const color: ColorRGBA64 | null = parseColorHexRGB(
                        colorValues[colorName]
                    );
                    if (color instanceof ColorRGBA64) {
                        callback(color);
                    }

                    this.setState({
                        [stateKey]: colorValues[colorName],
                    } as any);
                };
github microsoft / fast-dna / packages / fast-color-explorer / app / design-system.ts View on Github external
import {
    DesignSystem,
    DesignSystemDefaults,
    Palette,
} from "@microsoft/fast-components-styles-msft";
import { createColorPalette } from "@microsoft/fast-components-styles-msft";
import { ColorRGBA64, parseColorHexRGB } from "@microsoft/fast-colors";
import { defaultAccentColor, defaultNeutralColor } from "./colors";
import { StandardLuminance } from "@microsoft/fast-components-styles-msft/dist/utilities/color/neutral-layer";

const neutralPalette: Palette = createColorPalette(parseColorHexRGB(
    defaultNeutralColor
) as ColorRGBA64);

export type ColorsDesignSystem = DesignSystem;
export const colorsDesignSystem: ColorsDesignSystem = Object.assign(
    {},
    DesignSystemDefaults,
    {
        baseLayerLuminance: StandardLuminance.DarkMode,
        neutralPalette,
        accentPalette: createColorPalette(parseColorHexRGB(
            defaultAccentColor
        ) as ColorRGBA64),
        accentBaseColor: defaultAccentColor,
    }
);
github microsoft / fast-dna / packages / fast-tooling-react / src / css-editor / box-shadow / box-shadow.tsx View on Github external
public componentDidUpdate(
        prevProps: CSSBoxShadowProps,
        prevState: CSSBoxShadowState
    ): void {
        if (this.state !== prevState) {
            const rgb: ColorRGBA64 = parseColorHexRGB(this.state.boxShadowColor);
            const rgba: ColorRGBA64 = ColorRGBA64.fromObject({
                r: rgb.r,
                g: rgb.g,
                b: rgb.b,
                a: this.state.boxShadowOpacity,
            });

            const boxShadowArray: string[] = [
                this.state.boxShadowOffsetX,
                this.state.boxShadowOffsetY,
                this.state.boxShadowBlurRadius,
                rgba.toStringWebRGBA(),
            ];

            this.props.onChange({
                boxShadow: boxShadowArray.reduce(
github microsoft / fast-dna / packages / fast-components-styles-msft / src / utilities / color / common.ts View on Github external
(color: string): ColorRGBA64 => {
        let parsed: ColorRGBA64 | null = parseColorHexRGB(color);

        if (parsed !== null) {
            return parsed;
        }

        parsed = parseColorWebRGB(color);

        if (parsed !== null) {
            return parsed;
        }

        throw new Error(
            `${color} cannot be converted to a ColorRGBA64. Color strings must be one of the following formats: "#RGB", "#RRGGBB", or "rgb(r, g, b)"`
        );
    }
);
github microsoft / fast-dna / packages / fast-components-styles-msft / src / utilities / color / color-constants.ts View on Github external
clipDark: 0,
};

/**
 * @deprecated
 */
export const neutralPaletteConfig: ColorPaletteConfig = {
    ...paletteConstants,
};

/**
 * @deprecated
 */
export const accentPaletteConfig: ColorPaletteConfig = {
    ...paletteConstants,
    baseColor: parseColorHexRGB("#0078D4"),
};
github microsoft / fast-dna / packages / fast-color-explorer / app / design-system.ts View on Github external
import { ColorRGBA64, parseColorHexRGB } from "@microsoft/fast-colors";
import { defaultAccentColor, defaultNeutralColor } from "./colors";
import { StandardLuminance } from "@microsoft/fast-components-styles-msft/dist/utilities/color/neutral-layer";

const neutralPalette: Palette = createColorPalette(parseColorHexRGB(
    defaultNeutralColor
) as ColorRGBA64);

export type ColorsDesignSystem = DesignSystem;
export const colorsDesignSystem: ColorsDesignSystem = Object.assign(
    {},
    DesignSystemDefaults,
    {
        baseLayerLuminance: StandardLuminance.DarkMode,
        neutralPalette,
        accentPalette: createColorPalette(parseColorHexRGB(
            defaultAccentColor
        ) as ColorRGBA64),
        accentBaseColor: defaultAccentColor,
    }
);