index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* eslint-disable no-param-reassign */
  2. // @flow
  3. import _ from 'lodash';
  4. import bodyTheme from './Body';
  5. import leftTheme from './Left';
  6. import rightTheme from './Right';
  7. import headerTheme from './Header';
  8. import switchTheme from './Switch';
  9. import thumbnailTheme from './Thumbnail';
  10. import containerTheme from './Container';
  11. import contentTheme from './Content';
  12. import buttonTheme from './Button';
  13. import titleTheme from './Title';
  14. import subtitleTheme from './Subtitle';
  15. import inputGroupTheme from './InputGroup';
  16. import badgeTheme from './Badge';
  17. import checkBoxTheme from './CheckBox';
  18. import cardTheme from './Card';
  19. import radioTheme from './Radio';
  20. import h3Theme from './H3';
  21. import h2Theme from './H2';
  22. import h1Theme from './H1';
  23. import footerTheme from './Footer';
  24. import footerTabTheme from './FooterTab';
  25. import fabTheme from './Fab';
  26. import itemTheme from './Item';
  27. import labelTheme from './Label';
  28. import textAreaTheme from './Textarea';
  29. import textTheme from './Text';
  30. import toastTheme from './Toast';
  31. import tabTheme from './Tab';
  32. import tabBarTheme from './TabBar';
  33. import tabContainerTheme from './TabContainer';
  34. import viewTheme from './View';
  35. import tabHeadingTheme from './TabHeading';
  36. import iconTheme from './Icon';
  37. import inputTheme from './Input';
  38. import swipeRowTheme from './SwipeRow';
  39. import segmentTheme from './Segment';
  40. import spinnerTheme from './Spinner';
  41. import cardItemTheme from './CardItem';
  42. import listItemTheme from './ListItem';
  43. import formTheme from './Form';
  44. import separatorTheme from './Separator';
  45. import pickerTheme from './Picker';
  46. import variable from './../variables/platform';
  47. export default (variables /* : * */ = variable) => {
  48. const theme = {
  49. variables,
  50. 'NativeBase.Left': {
  51. ...leftTheme(variables)
  52. },
  53. 'NativeBase.Right': {
  54. ...rightTheme(variables)
  55. },
  56. 'NativeBase.Body': {
  57. ...bodyTheme(variables)
  58. },
  59. 'NativeBase.Header': {
  60. ...headerTheme(variables)
  61. },
  62. 'NativeBase.Button': {
  63. ...buttonTheme(variables)
  64. },
  65. 'NativeBase.Title': {
  66. ...titleTheme(variables)
  67. },
  68. 'NativeBase.Subtitle': {
  69. ...subtitleTheme(variables)
  70. },
  71. 'NativeBase.InputGroup': {
  72. ...inputGroupTheme(variables)
  73. },
  74. 'NativeBase.Input': {
  75. ...inputTheme(variables)
  76. },
  77. 'NativeBase.Badge': {
  78. ...badgeTheme(variables)
  79. },
  80. 'NativeBase.CheckBox': {
  81. ...checkBoxTheme(variables)
  82. },
  83. 'NativeBase.Radio': {
  84. ...radioTheme(variables)
  85. },
  86. 'NativeBase.Card': {
  87. ...cardTheme(variables)
  88. },
  89. 'NativeBase.CardItem': {
  90. ...cardItemTheme(variables)
  91. },
  92. 'NativeBase.Toast': {
  93. ...toastTheme(variables)
  94. },
  95. 'NativeBase.H1': {
  96. ...h1Theme(variables)
  97. },
  98. 'NativeBase.H2': {
  99. ...h2Theme(variables)
  100. },
  101. 'NativeBase.H3': {
  102. ...h3Theme(variables)
  103. },
  104. 'NativeBase.Form': {
  105. ...formTheme(variables)
  106. },
  107. 'NativeBase.Container': {
  108. ...containerTheme(variables)
  109. },
  110. 'NativeBase.Content': {
  111. ...contentTheme(variables)
  112. },
  113. 'NativeBase.Footer': {
  114. ...footerTheme(variables)
  115. },
  116. 'NativeBase.Tabs': {
  117. flex: 1
  118. },
  119. 'NativeBase.FooterTab': {
  120. ...footerTabTheme(variables)
  121. },
  122. 'NativeBase.ListItem': {
  123. ...listItemTheme(variables)
  124. },
  125. 'NativeBase.ListItem1': {
  126. ...listItemTheme(variables)
  127. },
  128. 'NativeBase.Icon': {
  129. ...iconTheme(variables)
  130. },
  131. 'NativeBase.IconNB': {
  132. ...iconTheme(variables)
  133. },
  134. 'NativeBase.Text': {
  135. ...textTheme(variables)
  136. },
  137. 'NativeBase.Spinner': {
  138. ...spinnerTheme(variables)
  139. },
  140. 'NativeBase.Fab': {
  141. ...fabTheme(variables)
  142. },
  143. 'NativeBase.Item': {
  144. ...itemTheme(variables)
  145. },
  146. 'NativeBase.Label': {
  147. ...labelTheme(variables)
  148. },
  149. 'NativeBase.Textarea': {
  150. ...textAreaTheme(variables)
  151. },
  152. 'NativeBase.PickerNB': {
  153. ...pickerTheme(variables),
  154. 'NativeBase.Button': {
  155. 'NativeBase.Text': {}
  156. }
  157. },
  158. 'NativeBase.Tab': {
  159. ...tabTheme(variables)
  160. },
  161. 'NativeBase.Segment': {
  162. ...segmentTheme(variables)
  163. },
  164. 'NativeBase.TabBar': {
  165. ...tabBarTheme(variables)
  166. },
  167. 'NativeBase.ViewNB': {
  168. ...viewTheme(variables)
  169. },
  170. 'NativeBase.TabHeading': {
  171. ...tabHeadingTheme(variables)
  172. },
  173. 'NativeBase.TabContainer': {
  174. ...tabContainerTheme(variables)
  175. },
  176. 'NativeBase.Switch': {
  177. ...switchTheme(variables)
  178. },
  179. 'NativeBase.Separator': {
  180. ...separatorTheme(variables)
  181. },
  182. 'NativeBase.SwipeRow': {
  183. ...swipeRowTheme(variables)
  184. },
  185. 'NativeBase.Thumbnail': {
  186. ...thumbnailTheme(variables)
  187. }
  188. };
  189. const cssifyTheme = (grandparent, parent, parentKey) => {
  190. _.forEach(parent, (style, styleName) => {
  191. if (
  192. styleName.indexOf('.') === 0 &&
  193. parentKey &&
  194. parentKey.indexOf('.') === 0
  195. ) {
  196. if (grandparent) {
  197. if (!grandparent[styleName]) {
  198. grandparent[styleName] = {};
  199. } else {
  200. grandparent[styleName][parentKey] = style;
  201. }
  202. }
  203. }
  204. if (
  205. style &&
  206. typeof style === 'object' &&
  207. styleName !== 'fontVariant' &&
  208. styleName !== 'transform'
  209. ) {
  210. cssifyTheme(parent, style, styleName);
  211. }
  212. });
  213. };
  214. cssifyTheme(null, theme, null);
  215. return theme;
  216. };