本文整理汇总了TypeScript中csx.ColorHelper类的典型用法代码示例。如果您正苦于以下问题:TypeScript ColorHelper类的具体用法?TypeScript ColorHelper怎么用?TypeScript ColorHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ColorHelper类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
export const emphasizeLightness = (color: ColorHelper, weight: number, flipIfMax: boolean = true) => {
const colorLightness = color.lightness();
let weightOffset = 1;
if (colorLightness < 0.4) {
weightOffset = Math.abs(colorLightness - 0.5) * 20;
}
const weightCurved = weight * weightOffset;
const colorDarker = color.darken(weightCurved) as ColorHelper;
const colorLighter = color.lighten(weightCurved) as ColorHelper;
if (isLightColor(color)) {
if (colorLightness + weightCurved > 1 && flipIfMax) {
return colorDarker;
} else {
return colorLighter;
}
} else {
if (colorLightness - weightCurved > 0 && flipIfMax) {
return colorDarker;
} else {
return colorLighter;
}
}
};
示例2: Error
export const modifyColorBasedOnLightness = (color: ColorHelper, weight: number, flip: boolean = false) => {
let output;
if (weight > 1 || weight < 0) {
throw new Error("mixAmount must be a value between 0 and 1 inclusively.");
}
const isLight = isLightColor(color);
if ((isLight && !flip) || (!isLight && flip)) {
output = color.darken(weight) as ColorHelper;
} else {
output = color.lighten(weight) as ColorHelper;
}
return output;
};
示例3:
const contrast = (
baseColor: ColorHelper = globalVars.mainColors.fg,
hasBorder: boolean = false,
borderRadius: BorderRadiusProperty<TLength> = 0,
) => {
const shadowColor = baseColor.fade(0.2);
let border = {};
if (hasBorder) {
border = {
outline: `solid 1px ${shadowColor.toString()}`,
radius: borderRadius,
};
}
return {
boxShadow: `0 0 3px 0 ${baseColor.fade(0.3)}`,
...border,
};
};
示例4:
const gradient = (direction: "right" | "left") => {
return `linear-gradient(to ${direction}, ${colorOut(color.fade(0))} 0%, ${colorOut(
color.fade(0.3),
)} 20%, ${colorOut(color)} 90%)`;
};