about summary refs log tree commit diff
path: root/src/view/lib/hooks/usePalette.ts
blob: e9af4ae16a42c99ee428a89a45744214d16dc134 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {TextStyle, ViewStyle} from 'react-native'
import {useTheme, PaletteColorName, PaletteColor} from '../ThemeContext'

export interface UsePaletteValue {
  colors: PaletteColor
  view: ViewStyle
  border: ViewStyle
  text: TextStyle
  textLight: TextStyle
  textInverted: TextStyle
  link: TextStyle
}
export function usePalette(color: PaletteColorName): UsePaletteValue {
  const palette = useTheme().palette[color]
  return {
    colors: palette,
    view: {
      backgroundColor: palette.background,
    },
    border: {
      borderWidth: 1,
      borderColor: palette.border,
    },
    text: {
      color: palette.text,
      fontWeight: palette.isLowContrast ? '500' : undefined,
    },
    textLight: {
      color: palette.textLight,
      fontWeight: palette.isLowContrast ? '500' : undefined,
    },
    textInverted: {
      color: palette.textInverted,
      fontWeight: palette.isLowContrast ? '500' : undefined,
    },
    link: {
      color: palette.link,
      fontWeight: palette.isLowContrast ? '500' : undefined,
    },
  }
}