-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d02772e
commit 9928227
Showing
10 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import tinycolor from 'tinyColor2'; | ||
import { includes, map } from 'lodash'; | ||
import { Palette } from '@/common'; | ||
|
||
export const generatePalette = (palette: Palette, brandColor: string) => { | ||
const { basicColors, ...restParams } = palette; | ||
const preBrandColor = tinycolor( | ||
basicColors[restParams?.brandColorIndex], | ||
).toRgb(); | ||
const newBrandColor = tinycolor(brandColor).toRgb(); | ||
const distance = { | ||
r: newBrandColor.r - preBrandColor.r, | ||
g: newBrandColor.g - preBrandColor.g, | ||
b: newBrandColor.b - preBrandColor.b, | ||
}; | ||
const newColors = map(basicColors, (color: string, key) => { | ||
if (includes(restParams?.fixedColorIndex, key)) { | ||
return color; | ||
} | ||
const preColor = tinycolor(color).toRgb(); | ||
const newColor = tinycolor({ | ||
r: preColor.r + distance.r, | ||
g: preColor.g + distance.g, | ||
b: preColor.b + distance.b, | ||
}); | ||
return `#${newColor.toHex().toUpperCase()}`; | ||
}); | ||
return { | ||
basicColors: newColors, | ||
...restParams, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters