global.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. import type {Theme} from '@emotion/react';
  2. import {css, Global} from '@emotion/react';
  3. import {space} from 'sentry/styles/space';
  4. const prismStyles = (theme: Theme) => css`
  5. :root {
  6. ${theme.prismVariables};
  7. }
  8. /* Use dark Prism theme for code snippets imported from Sentry Docs */
  9. .gatsby-highlight,
  10. .prism-dark {
  11. ${theme.prismDarkVariables};
  12. }
  13. pre[class*='language-'] {
  14. overflow-x: auto;
  15. padding: ${space(1)} ${space(2)};
  16. border-radius: ${theme.borderRadius};
  17. box-shadow: none;
  18. code {
  19. background: unset;
  20. vertical-align: middle;
  21. }
  22. }
  23. pre[class*='language-'],
  24. code[class*='language-'] {
  25. color: var(--prism-base);
  26. background: var(--prism-block-background);
  27. font-size: ${theme.codeFontSize};
  28. text-shadow: none;
  29. font-family: ${theme.text.familyMono};
  30. direction: ltr;
  31. text-align: left;
  32. white-space: pre;
  33. word-spacing: normal;
  34. word-break: normal;
  35. -moz-tab-size: 4;
  36. -o-tab-size: 4;
  37. tab-size: 4;
  38. -webkit-hyphens: none;
  39. -moz-hyphens: none;
  40. -ms-hyphens: none;
  41. hyphens: none;
  42. .namespace {
  43. opacity: 0.7;
  44. }
  45. .token.comment,
  46. .token.prolog,
  47. .token.doctype,
  48. .token.cdata {
  49. color: var(--prism-comment);
  50. }
  51. .token.punctuation {
  52. color: var(--prism-punctuation);
  53. }
  54. .token.property,
  55. .token.tag,
  56. .token.boolean,
  57. .token.number,
  58. .token.constant,
  59. .token.symbol,
  60. .token.deleted {
  61. color: var(--prism-property);
  62. }
  63. .token.selector,
  64. .token.attr-name,
  65. .token.string,
  66. .token.char,
  67. .token.builtin,
  68. .token.inserted {
  69. color: var(--prism-selector);
  70. }
  71. .token.operator,
  72. .token.entity,
  73. .token.url,
  74. .language-css .token.string,
  75. .style .token.string {
  76. color: var(--prism-operator);
  77. background: none;
  78. }
  79. .token.atrule,
  80. .token.attr-value,
  81. .token.keyword {
  82. color: var(--prism-keyword);
  83. }
  84. .token.function {
  85. color: var(--prism-function);
  86. }
  87. .token.regex,
  88. .token.important,
  89. .token.variable {
  90. color: var(--prism-variable);
  91. }
  92. .token.important,
  93. .token.bold {
  94. font-weight: ${theme.fontWeightBold};
  95. }
  96. .token.italic {
  97. font-style: italic;
  98. }
  99. .token.entity {
  100. cursor: help;
  101. }
  102. .line-highlight {
  103. position: absolute;
  104. left: -${space(2)};
  105. right: 0;
  106. background: var(--prism-highlight-background);
  107. box-shadow: inset 5px 0 0 var(--prism-highlight-accent);
  108. z-index: 0;
  109. pointer-events: none;
  110. line-height: inherit;
  111. white-space: pre;
  112. }
  113. }
  114. pre[data-line] {
  115. position: relative;
  116. }
  117. pre[class*='language-'] > code[class*='language-'] {
  118. position: relative;
  119. z-index: 1;
  120. }
  121. `;
  122. const styles = (theme: Theme, isDark: boolean) => css`
  123. body {
  124. .sentry-error-embed-wrapper {
  125. z-index: ${theme.zIndex.sentryErrorEmbed};
  126. }
  127. color: ${theme.textColor};
  128. background: ${theme.backgroundSecondary};
  129. }
  130. abbr {
  131. ${theme.tooltipUnderline()};
  132. }
  133. a {
  134. color: ${theme.linkColor};
  135. &:focus-visible,
  136. &:hover {
  137. color: ${theme.linkHoverColor};
  138. }
  139. }
  140. .group-detail:before {
  141. background: ${theme.border};
  142. }
  143. .form-actions {
  144. border-top-color: ${theme.border};
  145. }
  146. pre,
  147. code {
  148. color: ${theme.textColor};
  149. }
  150. pre {
  151. background-color: ${theme.backgroundSecondary};
  152. white-space: pre-wrap;
  153. overflow-x: auto;
  154. }
  155. code {
  156. background-color: transparent;
  157. }
  158. ${prismStyles(theme)}
  159. /**
  160. * See https://web.dev/prefers-reduced-motion/
  161. */
  162. @media (prefers-reduced-motion) {
  163. *,
  164. ::before,
  165. ::after {
  166. animation-delay: -1ms !important;
  167. animation-duration: 0ms !important;
  168. animation-iteration-count: 1 !important;
  169. background-attachment: initial !important;
  170. scroll-behavior: auto !important;
  171. transition-duration: 0s !important;
  172. transition-delay: 0s !important;
  173. }
  174. }
  175. .ReactVirtualized__Grid:focus-visible,
  176. .ReactVirtualized__List:focus-visible {
  177. outline: ${theme.focusBorder} auto 1px;
  178. }
  179. /* Override css in LESS files here as we want to manually control dark mode for now */
  180. ${isDark
  181. ? css`
  182. .box,
  183. .box.box-modal {
  184. background: ${theme.background};
  185. border-color: ${theme.border};
  186. .box-content,
  187. .box-header {
  188. background: ${theme.background};
  189. h1,
  190. h2,
  191. h3,
  192. h4,
  193. h5,
  194. h6 {
  195. color: ${theme.headingColor};
  196. }
  197. a {
  198. color: ${theme.textColor};
  199. }
  200. }
  201. .box-header {
  202. border-bottom-color: ${theme.border};
  203. }
  204. }
  205. .loading .loading-indicator {
  206. border-color: ${theme.backgroundSecondary};
  207. border-left-color: ${theme.purple300};
  208. }
  209. .pattern-bg {
  210. opacity: 1;
  211. filter: invert(1) brightness(0.6);
  212. }
  213. .nav-tabs {
  214. & > li {
  215. &.active {
  216. a {
  217. color: ${theme.textColor} !important;
  218. border-bottom-color: ${theme.active} !important;
  219. }
  220. }
  221. a:hover {
  222. color: ${theme.textColor} !important;
  223. }
  224. }
  225. &.border-bottom {
  226. border-color: ${theme.border};
  227. }
  228. }
  229. ul.crumbs li .table.key-value pre {
  230. color: ${theme.subText};
  231. }
  232. .exception {
  233. border-color: ${theme.innerBorder};
  234. }
  235. .traceback {
  236. border-color: ${theme.border};
  237. &.in-app-traceback {
  238. .frame {
  239. &.leads-to-app {
  240. &.collapsed {
  241. .title {
  242. border-color: ${theme.border};
  243. background: ${theme.background};
  244. }
  245. }
  246. }
  247. }
  248. }
  249. .frame,
  250. .frame.system-frame {
  251. border-top-color: ${theme.border};
  252. &.is-expandable .title:hover {
  253. background-color: ${theme.background};
  254. }
  255. .btn-toggle {
  256. color: ${theme.textColor};
  257. background: transparent;
  258. }
  259. .title {
  260. background-color: ${theme.backgroundSecondary};
  261. }
  262. &.is-expandable .title {
  263. background-color: ${theme.backgroundSecondary};
  264. }
  265. .context {
  266. background: ${theme.background};
  267. table.key-value {
  268. border-color: ${theme.border};
  269. td {
  270. border-color: ${theme.border} !important;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. .exc-message {
  277. color: ${theme.subText};
  278. }
  279. .group-detail h3 em {
  280. color: ${theme.subText};
  281. }
  282. .event-details-container {
  283. background-color: ${theme.background};
  284. .secondary {
  285. border-left-color: ${theme.border};
  286. }
  287. }
  288. /* Group Details - User context */
  289. .user-widget .avatar {
  290. box-shadow: 0 0 0 5px ${theme.background};
  291. background: ${theme.background};
  292. }
  293. .nav-header a.help-link,
  294. .nav-header span.help-link a {
  295. color: ${theme.subText};
  296. }
  297. /* Global Selection header date picker */
  298. .rdrCalendarWrapper {
  299. background: ${theme.background};
  300. color: ${theme.textColor};
  301. }
  302. .rdrDayDisabled {
  303. background-color: ${theme.backgroundSecondary};
  304. color: ${theme.disabled};
  305. }
  306. .rdrMonthAndYearPickers select {
  307. color: ${theme.textColor};
  308. }
  309. .dropdown-menu {
  310. color: ${theme.textColor};
  311. background-color: ${theme.background} !important;
  312. border: 1px solid ${theme.border};
  313. &:before {
  314. border-bottom-color: ${theme.border};
  315. }
  316. &:after {
  317. border-bottom-color: ${theme.background};
  318. }
  319. &.inverted:before {
  320. border-top-color: ${theme.border};
  321. }
  322. &.inverted:after {
  323. border-top-color: ${theme.background};
  324. }
  325. }
  326. `
  327. : ''}
  328. `;
  329. /**
  330. * Renders an emotion global styles injection component
  331. */
  332. function GlobalStyles({theme, isDark}: {isDark: boolean; theme: Theme}) {
  333. return <Global styles={styles(theme, isDark)} />;
  334. }
  335. export default GlobalStyles;