diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-04 04:32:50 -0500 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-04 04:32:50 -0500 |
commit | 95abdada5a275fc258fa72781f7f3c40c0b306ea (patch) | |
tree | 6d729cebe0937ae81108005de9895b5398d1f475 /packages/components/src/global/globalUtils.tsx | |
parent | 0a8f3739cf5c30852f18751a4c05d81e0dabe928 (diff) | |
parent | 215ad40efa2e343e290d18bffbc55884829f1a0d (diff) |
Merge branch 'master' of https://github.com/brown-dash/Dash-Web into Merge
Diffstat (limited to 'packages/components/src/global/globalUtils.tsx')
-rw-r--r-- | packages/components/src/global/globalUtils.tsx | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/packages/components/src/global/globalUtils.tsx b/packages/components/src/global/globalUtils.tsx new file mode 100644 index 000000000..0f1e0adbc --- /dev/null +++ b/packages/components/src/global/globalUtils.tsx @@ -0,0 +1,93 @@ +import { Size } from './globalEnums' +import Color from 'color'; + +export interface ILocation { + top: number + left: number + width: number + height: number + override?: 'left' | 'bottom' | 'top' | 'right' +} + +export const getFormLabelSize = ( + size: Size | undefined, +) => { + switch (size) { + case Size.XSMALL: + return '7px' + case Size.SMALL: + return '10px' + case Size.MEDIUM: + return '13px' + case Size.LARGE: + return '14px' + default: + return '10px' + } +} + +export const getFontSize = ( + size: Size | undefined, + icon?: boolean +) => { + switch (size) { + case Size.XSMALL: + if (icon) return '11px' + return '9px' + case Size.SMALL: + if (icon) return '15px' + return '11px' + case Size.MEDIUM: + if (icon) return '17px' + return '14px' + case Size.LARGE: + if (icon) return '22px' + return '17px' + default: + if (icon) return '15px' + return '12px' + } +} + +export const getHeight = ( + height: number | undefined, + size: Size | undefined +) => { + if (height) return height + switch (size) { + case Size.XSMALL: + return 20 + case Size.SMALL: + return 30 + case Size.MEDIUM: + return 40 + case Size.LARGE: + return 50 + default: + return 30 + } +} + +export const colorConvert = (color: any) => { + try { + return color ? Color(color.toLowerCase()) : Color('transparent') + } catch (e) { + console.log('COLOR error:', e) + return Color('red') + } +} + +export const isDark = (color: any): boolean => { + if (color === undefined) return false + if (color === 'transparent') return false + if (color.startsWith?.('linear')) return false + const nonAlphaColor = color.startsWith('#') + ? (color as string).substring(0, 7) + : color.startsWith('rgba') + ? color.replace(/,.[^,]*\)/, ')').replace('rgba', 'rgb') + : color + const col = colorConvert(nonAlphaColor).rgb() + const colsum = col.red() + col.green() + col.blue() + if (colsum / col.alpha() > 400 || col.alpha() < 0.25) return false + else return true +} |