about summary refs log tree commit diff
path: root/src/view/com/util/text/ThemedText.tsx
blob: 2844d273c2170493a9c9d364bcd5ca31b2af2d60 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import {CustomTextProps, Text} from './Text'
import {usePalette} from 'lib/hooks/usePalette'
import {addStyle} from 'lib/styles'

export type ThemedTextProps = CustomTextProps & {
  fg?: 'default' | 'light' | 'error' | 'inverted' | 'inverted-light'
  bg?: 'default' | 'light' | 'error' | 'inverted' | 'inverted-light'
  border?: 'default' | 'dark' | 'error' | 'inverted' | 'inverted-dark'
  lineHeight?: number
}

export function ThemedText({
  fg,
  bg,
  border,
  style,
  children,
  ...props
}: React.PropsWithChildren<ThemedTextProps>) {
  const pal = usePalette('default')
  const palInverted = usePalette('inverted')
  const palError = usePalette('error')
  switch (fg) {
    case 'default':
      style = addStyle(style, pal.text)
      break
    case 'light':
      style = addStyle(style, pal.textLight)
      break
    case 'error':
      style = addStyle(style, {color: palError.colors.background})
      break
    case 'inverted':
      style = addStyle(style, palInverted.text)
      break
    case 'inverted-light':
      style = addStyle(style, palInverted.textLight)
      break
  }
  switch (bg) {
    case 'default':
      style = addStyle(style, pal.view)
      break
    case 'light':
      style = addStyle(style, pal.viewLight)
      break
    case 'error':
      style = addStyle(style, palError.view)
      break
    case 'inverted':
      style = addStyle(style, palInverted.view)
      break
    case 'inverted-light':
      style = addStyle(style, palInverted.viewLight)
      break
  }
  switch (border) {
    case 'default':
      style = addStyle(style, pal.border)
      break
    case 'dark':
      style = addStyle(style, pal.borderDark)
      break
    case 'error':
      style = addStyle(style, palError.border)
      break
    case 'inverted':
      style = addStyle(style, palInverted.border)
      break
    case 'inverted-dark':
      style = addStyle(style, palInverted.borderDark)
      break
  }
  return (
    <Text style={style} {...props}>
      {children}
    </Text>
  )
}