styles.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import styled from '@emotion/styled';
  2. import {Panel, PanelBody} from 'sentry/components/panels';
  3. import space from 'sentry/styles/space';
  4. export const GRID_HEAD_ROW_HEIGHT = 45;
  5. export const GRID_BODY_ROW_HEIGHT = 40;
  6. export const GRID_STATUS_MESSAGE_HEIGHT = GRID_BODY_ROW_HEIGHT * 4;
  7. /**
  8. * Local z-index stacking context
  9. * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
  10. */
  11. // Parent context is Panel
  12. const Z_INDEX_PANEL = 1;
  13. const Z_INDEX_GRID_STATUS = -1;
  14. const Z_INDEX_GRID = 5;
  15. // Parent context is GridHeadCell
  16. const Z_INDEX_GRID_RESIZER = 1;
  17. export const Header = styled('div')`
  18. display: flex;
  19. justify-content: space-between;
  20. align-items: center;
  21. margin-bottom: ${space(1)};
  22. `;
  23. export const HeaderTitle = styled('h4')`
  24. margin: 0;
  25. font-size: ${p => p.theme.fontSizeMedium};
  26. color: ${p => p.theme.subText};
  27. `;
  28. export const HeaderButtonContainer = styled('div')`
  29. display: grid;
  30. gap: ${space(1)};
  31. grid-auto-flow: column;
  32. grid-auto-columns: auto;
  33. justify-items: end;
  34. /* Hovercard anchor element when features are disabled. */
  35. & > span {
  36. display: flex;
  37. flex-direction: row;
  38. }
  39. `;
  40. export const Body = styled(({children, ...props}) => (
  41. <Panel {...props}>
  42. <PanelBody>{children}</PanelBody>
  43. </Panel>
  44. ))`
  45. overflow: hidden;
  46. z-index: ${Z_INDEX_PANEL};
  47. `;
  48. /**
  49. * Grid is the parent element for the tableResizable component.
  50. *
  51. * On newer browsers, it will use CSS Grids to implement its layout.
  52. *
  53. * However, it is based on <table>, which has a distinction between header/body
  54. * HTML elements, which allows CSS selectors to its full potential. This has
  55. * the added advantage that older browsers will still have a chance of
  56. * displaying the data correctly (but this is untested).
  57. *
  58. * <thead>, <tbody>, <tr> are ignored by CSS Grid.
  59. * The entire layout is determined by the usage of <th> and <td>.
  60. */
  61. export const Grid = styled('table')`
  62. position: inherit;
  63. display: grid;
  64. /* Overwritten by GridEditable.setGridTemplateColumns */
  65. grid-template-columns: repeat(auto-fill, minmax(50px, auto));
  66. box-sizing: border-box;
  67. border-collapse: collapse;
  68. margin: 0;
  69. z-index: ${Z_INDEX_GRID};
  70. overflow-x: auto;
  71. overflow-y: hidden;
  72. `;
  73. export const GridRow = styled('tr')`
  74. display: contents;
  75. &:last-child,
  76. &:last-child > td:first-child,
  77. &:last-child > td:last-child {
  78. border-bottom-left-radius: ${p => p.theme.borderRadius};
  79. border-bottom-right-radius: ${p => p.theme.borderRadius};
  80. }
  81. `;
  82. /**
  83. * GridHead is the collection of elements that builds the header section of the
  84. * Grid. As the entirety of the add/remove/resize actions are performed on the
  85. * header, most of the elements behave different for each stage.
  86. */
  87. export const GridHead = styled('thead')`
  88. display: contents;
  89. `;
  90. export const GridHeadCell = styled('th')<{isFirst: boolean}>`
  91. /* By default, a grid item cannot be smaller than the size of its content.
  92. We override this by setting min-width to be 0. */
  93. position: relative; /* Used by GridResizer */
  94. height: ${GRID_HEAD_ROW_HEIGHT}px;
  95. display: flex;
  96. align-items: center;
  97. min-width: 24px;
  98. padding: 0 ${space(2)};
  99. border-right: 1px solid transparent;
  100. border-left: 1px solid transparent;
  101. background-color: ${p => p.theme.backgroundSecondary};
  102. color: ${p => p.theme.subText};
  103. font-size: ${p => p.theme.fontSizeSmall};
  104. font-weight: 600;
  105. text-transform: uppercase;
  106. user-select: none;
  107. a,
  108. div,
  109. span {
  110. line-height: 1.1;
  111. color: inherit;
  112. white-space: nowrap;
  113. text-overflow: ellipsis;
  114. overflow: hidden;
  115. }
  116. &:first-child {
  117. border-top-left-radius: ${p => p.theme.borderRadius};
  118. }
  119. &:last-child {
  120. border-top-right-radius: ${p => p.theme.borderRadius};
  121. border-right: none;
  122. }
  123. &:hover {
  124. border-left-color: ${p => (p.isFirst ? 'transparent' : p.theme.border)};
  125. border-right-color: ${p => p.theme.border};
  126. }
  127. `;
  128. /**
  129. * Create spacing/padding similar to GridHeadCellWrapper but
  130. * without interactive aspects.
  131. */
  132. export const GridHeadCellStatic = styled('th')`
  133. height: ${GRID_HEAD_ROW_HEIGHT}px;
  134. display: flex;
  135. align-items: center;
  136. padding: 0 ${space(2)};
  137. background-color: ${p => p.theme.backgroundSecondary};
  138. font-size: ${p => p.theme.fontSizeSmall};
  139. font-weight: 600;
  140. line-height: 1;
  141. text-transform: uppercase;
  142. text-overflow: ellipsis;
  143. white-space: nowrap;
  144. overflow: hidden;
  145. &:first-child {
  146. border-top-left-radius: ${p => p.theme.borderRadius};
  147. padding: ${space(1)} 0 ${space(1)} ${space(3)};
  148. }
  149. `;
  150. /**
  151. * GridBody are the collection of elements that contains and display the data
  152. * of the Grid. They are rather simple.
  153. */
  154. export const GridBody = styled('tbody')`
  155. display: contents;
  156. > tr:first-child td {
  157. border-top: 1px solid ${p => p.theme.border};
  158. }
  159. `;
  160. export const GridBodyCell = styled('td')`
  161. /* By default, a grid item cannot be smaller than the size of its content.
  162. We override this by setting min-width to be 0. */
  163. min-width: 0;
  164. /* Locking in the height makes calculation for resizer to be easier.
  165. min-height is used to allow a cell to expand and this is used to display
  166. feedback during empty/error state */
  167. min-height: ${GRID_BODY_ROW_HEIGHT}px;
  168. padding: ${space(1)} ${space(2)};
  169. background-color: ${p => p.theme.background};
  170. border-top: 1px solid ${p => p.theme.innerBorder};
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: center;
  174. font-size: ${p => p.theme.fontSizeMedium};
  175. &:first-child {
  176. padding: ${space(1)} 0 ${space(1)} ${space(3)};
  177. }
  178. &:last-child {
  179. border-right: none;
  180. padding: ${space(1)} ${space(2)};
  181. }
  182. `;
  183. const GridStatusWrapper = styled(GridBodyCell)`
  184. grid-column: 1 / -1;
  185. width: 100%;
  186. height: ${GRID_STATUS_MESSAGE_HEIGHT}px;
  187. background-color: transparent;
  188. `;
  189. const GridStatusFloat = styled('div')`
  190. position: absolute;
  191. top: 45px;
  192. left: 0;
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. width: 100%;
  197. height: ${GRID_STATUS_MESSAGE_HEIGHT}px;
  198. z-index: ${Z_INDEX_GRID_STATUS};
  199. background: ${p => p.theme.background};
  200. `;
  201. export const GridBodyCellStatus = props => (
  202. <GridStatusWrapper>
  203. <GridStatusFloat>{props.children}</GridStatusFloat>
  204. </GridStatusWrapper>
  205. );
  206. /**
  207. * We have a fat GridResizer and we use the ::after pseudo-element to draw
  208. * a thin 1px border.
  209. *
  210. * The right most cell does not have a resizer as resizing from that side does strange things.
  211. */
  212. export const GridResizer = styled('div')<{dataRows: number}>`
  213. position: absolute;
  214. top: 0px;
  215. right: -6px;
  216. width: 11px;
  217. height: ${p => {
  218. const numOfRows = p.dataRows;
  219. let height = GRID_HEAD_ROW_HEIGHT + numOfRows * GRID_BODY_ROW_HEIGHT;
  220. if (numOfRows >= 1) {
  221. // account for border-bottom height
  222. height += numOfRows;
  223. }
  224. return height;
  225. }}px;
  226. padding-left: 5px;
  227. padding-right: 5px;
  228. cursor: col-resize;
  229. z-index: ${Z_INDEX_GRID_RESIZER};
  230. /**
  231. * This element allows us to have a fat GridResizer that is easy to hover and
  232. * drag, but still draws an appealing thin line for the border
  233. */
  234. &::after {
  235. content: ' ';
  236. display: block;
  237. width: 100%; /* Equivalent to 1px */
  238. height: 100%;
  239. }
  240. &:hover::after {
  241. background-color: ${p => p.theme.gray200};
  242. }
  243. /**
  244. * Ensure that this rule is after :hover, otherwise it will flicker when
  245. * the GridResizer is dragged
  246. */
  247. &:active::after,
  248. &:focus::after {
  249. background-color: ${p => p.theme.purple300};
  250. }
  251. /**
  252. * This element gives the resize handle a more visible knob to grab
  253. */
  254. &:hover::before {
  255. position: absolute;
  256. top: 0;
  257. left: 2px;
  258. content: ' ';
  259. display: block;
  260. width: 7px;
  261. height: ${GRID_HEAD_ROW_HEIGHT}px;
  262. background-color: ${p => p.theme.purple300};
  263. opacity: 0.4;
  264. }
  265. `;