-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(projects): refactor @sa/color-palette => @sa/color & perf @s…
…a/utils
- Loading branch information
1 parent
1cb3816
commit 3499997
Showing
31 changed files
with
269 additions
and
171 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,7 @@ | ||
import { colorPalettes } from './constant'; | ||
|
||
export * from './palette'; | ||
export * from './shared'; | ||
export { colorPalettes }; | ||
|
||
export * from './types'; |
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,45 @@ | ||
import type { AnyColor } from 'colord'; | ||
import { getHex } from '../shared'; | ||
import type { ColorPaletteNumber } from '../types'; | ||
import { getRecommendedColorPalette } from './recommend'; | ||
import { getAntDColorPalette } from './antd'; | ||
|
||
/** | ||
* get color palette by provided color | ||
* | ||
* @param color | ||
* @param recommended whether to get recommended color palette (the provided color may not be the main color) | ||
*/ | ||
export function getColorPalette(color: AnyColor, recommended = false) { | ||
const colorMap = new Map<ColorPaletteNumber, string>(); | ||
|
||
if (recommended) { | ||
const colorPalette = getRecommendedColorPalette(getHex(color)); | ||
colorPalette.palettes.forEach(palette => { | ||
colorMap.set(palette.number, palette.hex); | ||
}); | ||
} else { | ||
const colors = getAntDColorPalette(color); | ||
|
||
const colorNumbers: ColorPaletteNumber[] = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]; | ||
|
||
colorNumbers.forEach((number, index) => { | ||
colorMap.set(number, colors[index]); | ||
}); | ||
} | ||
|
||
return colorMap; | ||
} | ||
|
||
/** | ||
* get color palette color by number | ||
* | ||
* @param color the provided color | ||
* @param number the color palette number | ||
* @param recommended whether to get recommended color palette (the provided color may not be the main color) | ||
*/ | ||
export function getPaletteColorByNumber(color: AnyColor, number: ColorPaletteNumber, recommended = false) { | ||
const colorMap = getColorPalette(color, recommended); | ||
|
||
return colorMap.get(number as ColorPaletteNumber)!; | ||
} |
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
Oops, something went wrong.