mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-13 21:33:20 +01:00
Extract theme-related utilities
This commit is contained in:
parent
79fa204897
commit
ab8d608458
1 changed files with 47 additions and 0 deletions
47
app/javascript/retrospring/utilities/theme.ts
Normal file
47
app/javascript/retrospring/utilities/theme.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
export const THEME_MAPPING = {
|
||||
'primary_color': 'primary',
|
||||
'primary_text': 'primary-text',
|
||||
'danger_color': 'danger',
|
||||
'danger_text': 'danger-text',
|
||||
'warning_color': 'warning',
|
||||
'warning_text': 'warning-text',
|
||||
'info_color': 'info',
|
||||
'info_text': 'info-text',
|
||||
'success_color': 'success',
|
||||
'success_text': 'success-text',
|
||||
'dark_color': 'dark',
|
||||
'dark_text': 'dark-text',
|
||||
'light_color': 'light',
|
||||
'light_text': 'light-text',
|
||||
'raised_background': 'raised-bg',
|
||||
'raised_accent': 'raised-accent',
|
||||
'background_color': 'background',
|
||||
'body_text': 'body-text',
|
||||
'input_color': 'input-bg',
|
||||
'input_text': 'input-text',
|
||||
'input_placeholder': 'input-placeholder',
|
||||
'muted_text': 'muted-text'
|
||||
};
|
||||
|
||||
export const getHexColorFromThemeValue = (themeValue: string): string => {
|
||||
return ('000000' + parseInt(themeValue).toString(16)).substr(-6, 6);
|
||||
}
|
||||
|
||||
export const getDecimalTripletsFromHex = (hex: string): string => {
|
||||
return hex.match(/.{1,2}/g).map((value) => parseInt(value, 16)).join(', ');
|
||||
}
|
||||
|
||||
export const getIntegerFromHexColor = (hex: string): number => {
|
||||
console.log(hex, hex.substr(1, 6), parseInt(hex.substr(1, 6), 16));
|
||||
return parseInt(hex.substr(1, 6), 16);
|
||||
}
|
||||
|
||||
export const getColorForKey = (key: string, color: string): string => {
|
||||
const hex = getHexColorFromThemeValue(color);
|
||||
|
||||
if (key.includes('text') || key.includes('placeholder') || key.includes('rgb')) {
|
||||
return getDecimalTripletsFromHex(hex);
|
||||
} else {
|
||||
return `#${hex}`;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue