global.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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: bold;
  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. /* Override css in LESS files here as we want to manually control dark mode for now */
  176. ${isDark
  177. ? css`
  178. .box,
  179. .box.box-modal {
  180. background: ${theme.background};
  181. border-color: ${theme.border};
  182. .box-content,
  183. .box-header {
  184. background: ${theme.background};
  185. h1,
  186. h2,
  187. h3,
  188. h4,
  189. h5,
  190. h6 {
  191. color: ${theme.headingColor};
  192. }
  193. a {
  194. color: ${theme.textColor};
  195. }
  196. }
  197. .box-header {
  198. border-bottom-color: ${theme.border};
  199. }
  200. }
  201. .loading .loading-indicator {
  202. border-color: ${theme.backgroundSecondary};
  203. border-left-color: ${theme.purple300};
  204. }
  205. .pattern-bg {
  206. opacity: 1;
  207. filter: invert(1) brightness(0.6);
  208. }
  209. .nav-tabs {
  210. & > li {
  211. &.active {
  212. a {
  213. color: ${theme.textColor} !important;
  214. border-bottom-color: ${theme.active} !important;
  215. }
  216. }
  217. a:hover {
  218. color: ${theme.textColor} !important;
  219. }
  220. }
  221. &.border-bottom {
  222. border-color: ${theme.border};
  223. }
  224. }
  225. ul.crumbs li .table.key-value pre {
  226. color: ${theme.subText};
  227. }
  228. .exception {
  229. border-color: ${theme.innerBorder};
  230. }
  231. .traceback {
  232. border-color: ${theme.border};
  233. &.in-app-traceback {
  234. .frame {
  235. &.leads-to-app {
  236. &.collapsed {
  237. .title {
  238. border-color: ${theme.border};
  239. background: ${theme.background};
  240. }
  241. }
  242. }
  243. }
  244. }
  245. .frame,
  246. .frame.system-frame {
  247. border-top-color: ${theme.border};
  248. &.is-expandable .title:hover {
  249. background-color: ${theme.background};
  250. }
  251. .btn-toggle {
  252. color: ${theme.textColor};
  253. background: transparent;
  254. }
  255. .title {
  256. background-color: ${theme.backgroundSecondary};
  257. }
  258. &.is-expandable .title {
  259. background-color: ${theme.backgroundSecondary};
  260. }
  261. .context {
  262. background: ${theme.background};
  263. table.key-value {
  264. border-color: ${theme.border};
  265. td {
  266. border-color: ${theme.border} !important;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. .exc-message {
  273. color: ${theme.subText};
  274. }
  275. .group-detail h3 em {
  276. color: ${theme.subText};
  277. }
  278. .event-details-container {
  279. background-color: ${theme.background};
  280. .secondary {
  281. border-left-color: ${theme.border};
  282. }
  283. }
  284. /* Group Details - User context */
  285. .user-widget .avatar {
  286. box-shadow: 0 0 0 5px ${theme.background};
  287. background: ${theme.background};
  288. }
  289. .nav-header a.help-link,
  290. .nav-header span.help-link a {
  291. color: ${theme.subText};
  292. }
  293. /* Global Selection header date picker */
  294. .rdrCalendarWrapper {
  295. background: ${theme.background};
  296. color: ${theme.textColor};
  297. }
  298. .rdrDayDisabled {
  299. background-color: ${theme.backgroundSecondary};
  300. color: ${theme.disabled};
  301. }
  302. .rdrMonthAndYearPickers select {
  303. color: ${theme.textColor};
  304. }
  305. .dropdown-menu {
  306. color: ${theme.textColor};
  307. background-color: ${theme.background} !important;
  308. border: 1px solid ${theme.border};
  309. &:before {
  310. border-bottom-color: ${theme.border};
  311. }
  312. &:after {
  313. border-bottom-color: ${theme.background};
  314. }
  315. &.inverted:before {
  316. border-top-color: ${theme.border};
  317. }
  318. &.inverted:after {
  319. border-top-color: ${theme.background};
  320. }
  321. }
  322. `
  323. : ''}
  324. `;
  325. /**
  326. * Renders an emotion global styles injection component
  327. */
  328. function GlobalStyles({theme, isDark}: {isDark: boolean; theme: Theme}) {
  329. return <Global styles={styles(theme, isDark)} />;
  330. }
  331. export default GlobalStyles;