styles.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. `;
  72. export const GridRow = styled('tr')`
  73. display: contents;
  74. &:last-child,
  75. &:last-child > td:first-child,
  76. &:last-child > td:last-child {
  77. border-bottom-left-radius: ${p => p.theme.borderRadius};
  78. border-bottom-right-radius: ${p => p.theme.borderRadius};
  79. }
  80. `;
  81. /**
  82. * GridHead is the collection of elements that builds the header section of the
  83. * Grid. As the entirety of the add/remove/resize actions are performed on the
  84. * header, most of the elements behave different for each stage.
  85. */
  86. export const GridHead = styled('thead')`
  87. display: contents;
  88. `;
  89. export const GridHeadCell = styled('th')<{isFirst: boolean}>`
  90. /* By default, a grid item cannot be smaller than the size of its content.
  91. We override this by setting min-width to be 0. */
  92. position: relative; /* Used by GridResizer */
  93. height: ${GRID_HEAD_ROW_HEIGHT}px;
  94. display: flex;
  95. align-items: center;
  96. min-width: 24px;
  97. padding: 0 ${space(2)};
  98. border-right: 1px solid transparent;
  99. border-left: 1px solid transparent;
  100. background-color: ${p => p.theme.backgroundSecondary};
  101. color: ${p => p.theme.subText};
  102. font-size: ${p => p.theme.fontSizeSmall};
  103. font-weight: 600;
  104. text-transform: uppercase;
  105. user-select: none;
  106. a,
  107. div,
  108. span {
  109. line-height: 1.1;
  110. color: inherit;
  111. white-space: nowrap;
  112. text-overflow: ellipsis;
  113. overflow: hidden;
  114. }
  115. &:first-child {
  116. border-top-left-radius: ${p => p.theme.borderRadius};
  117. }
  118. &:last-child {
  119. border-top-right-radius: ${p => p.theme.borderRadius};
  120. border-right: none;
  121. }
  122. &:hover {
  123. border-left-color: ${p => (p.isFirst ? 'transparent' : p.theme.border)};
  124. border-right-color: ${p => p.theme.border};
  125. }
  126. `;
  127. /**
  128. * Create spacing/padding similar to GridHeadCellWrapper but
  129. * without interactive aspects.
  130. */
  131. export const GridHeadCellStatic = styled('th')`
  132. height: ${GRID_HEAD_ROW_HEIGHT}px;
  133. display: flex;
  134. align-items: center;
  135. padding: 0 ${space(2)};
  136. background-color: ${p => p.theme.backgroundSecondary};
  137. font-size: ${p => p.theme.fontSizeSmall};
  138. font-weight: 600;
  139. line-height: 1;
  140. text-transform: uppercase;
  141. text-overflow: ellipsis;
  142. white-space: nowrap;
  143. overflow: hidden;
  144. &:first-child {
  145. border-top-left-radius: ${p => p.theme.borderRadius};
  146. padding: ${space(1)} 0 ${space(1)} ${space(3)};
  147. }
  148. `;
  149. /**
  150. * GridBody are the collection of elements that contains and display the data
  151. * of the Grid. They are rather simple.
  152. */
  153. export const GridBody = styled('tbody')`
  154. display: contents;
  155. > tr:first-child td {
  156. border-top: 1px solid ${p => p.theme.border};
  157. }
  158. `;
  159. export const GridBodyCell = styled('td')`
  160. /* By default, a grid item cannot be smaller than the size of its content.
  161. We override this by setting min-width to be 0. */
  162. min-width: 0;
  163. /* Locking in the height makes calculation for resizer to be easier.
  164. min-height is used to allow a cell to expand and this is used to display
  165. feedback during empty/error state */
  166. min-height: ${GRID_BODY_ROW_HEIGHT}px;
  167. padding: ${space(1)} ${space(2)};
  168. background-color: ${p => p.theme.background};
  169. border-top: 1px solid ${p => p.theme.innerBorder};
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. font-size: ${p => p.theme.fontSizeMedium};
  174. &:first-child {
  175. padding: ${space(1)} 0 ${space(1)} ${space(3)};
  176. }
  177. &:last-child {
  178. border-right: none;
  179. padding: ${space(1)} ${space(2)};
  180. }
  181. `;
  182. const GridStatusWrapper = styled(GridBodyCell)`
  183. grid-column: 1 / -1;
  184. width: 100%;
  185. height: ${GRID_STATUS_MESSAGE_HEIGHT}px;
  186. background-color: transparent;
  187. `;
  188. const GridStatusFloat = styled('div')`
  189. position: absolute;
  190. top: 45px;
  191. left: 0;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. width: 100%;
  196. height: ${GRID_STATUS_MESSAGE_HEIGHT}px;
  197. z-index: ${Z_INDEX_GRID_STATUS};
  198. background: ${p => p.theme.background};
  199. `;
  200. export const GridBodyCellStatus = props => (
  201. <GridStatusWrapper>
  202. <GridStatusFloat>{props.children}</GridStatusFloat>
  203. </GridStatusWrapper>
  204. );
  205. /**
  206. * We have a fat GridResizer and we use the ::after pseudo-element to draw
  207. * a thin 1px border.
  208. *
  209. * The right most cell does not have a resizer as resizing from that side does strange things.
  210. */
  211. export const GridResizer = styled('div')<{dataRows: number}>`
  212. position: absolute;
  213. top: 0px;
  214. right: -6px;
  215. width: 11px;
  216. height: ${p => {
  217. const numOfRows = p.dataRows;
  218. let height = GRID_HEAD_ROW_HEIGHT + numOfRows * GRID_BODY_ROW_HEIGHT;
  219. if (numOfRows >= 1) {
  220. // account for border-bottom height
  221. height += numOfRows;
  222. }
  223. return height;
  224. }}px;
  225. padding-left: 5px;
  226. padding-right: 5px;
  227. cursor: col-resize;
  228. z-index: ${Z_INDEX_GRID_RESIZER};
  229. /**
  230. * This element allows us to have a fat GridResizer that is easy to hover and
  231. * drag, but still draws an appealing thin line for the border
  232. */
  233. &::after {
  234. content: ' ';
  235. display: block;
  236. width: 100%; /* Equivalent to 1px */
  237. height: 100%;
  238. }
  239. &:hover::after {
  240. background-color: ${p => p.theme.gray200};
  241. }
  242. /**
  243. * Ensure that this rule is after :hover, otherwise it will flicker when
  244. * the GridResizer is dragged
  245. */
  246. &:active::after,
  247. &:focus::after {
  248. background-color: ${p => p.theme.purple300};
  249. }
  250. /**
  251. * This element gives the resize handle a more visible knob to grab
  252. */
  253. &:hover::before {
  254. position: absolute;
  255. top: 0;
  256. left: 2px;
  257. content: ' ';
  258. display: block;
  259. width: 7px;
  260. height: ${GRID_HEAD_ROW_HEIGHT}px;
  261. background-color: ${p => p.theme.purple300};
  262. opacity: 0.4;
  263. }
  264. `;