1.0.8 • Published 3 years ago
@harryho/swatch-color v1.0.8
The package of Swatch Color
This package manages the generation of all Swatch Colors.
- This package has all definition of SWatch Colors
- This package manage validation of SWatch Color Data during the generation
- This package will be consumed by any app which requires the Swatch Color
How to add new Color type
Example: A new type -- YourNewColorType
1 Add a new color type
export interface YourNewColorType extends Color{
type: SwatchColorType.YourNewColorType,
}
2 Update SwatchColor
export type SwatchColor = RGB | HSL | BRGB | YourNewColorType;
3 Update SwatchColorType
export type SwatchColorType ={
...
YourNewColorType = "YourNewColorType"
}
- Add your new type validation
function isValidColorData(colorData: SwatchColor ) : boolean {
let isValid = true;
switch (colorData.type) {
...
case "YourNewColorType":
// TODO -- Add your validation here
break;
}
return isValid;
}
Q & A
What will happen if color data is invalid
Color Factory will return the null object instead of empty object