diff --git a/packages/grafana-ui/src/themes/GlobalStyles/code.ts b/packages/grafana-ui/src/themes/GlobalStyles/code.ts index 219bd089462..78c45452a59 100644 --- a/packages/grafana-ui/src/themes/GlobalStyles/code.ts +++ b/packages/grafana-ui/src/themes/GlobalStyles/code.ts @@ -21,7 +21,7 @@ export function getCodeStyles(theme: GrafanaTheme2) { pre: { display: 'block', - margin: `0 0 ${theme.typography.body.lineHeight}`, + margin: theme.spacing(0, 0, 2), lineHeight: theme.typography.body.lineHeight, wordBreak: 'break-all', wordWrap: 'break-word', diff --git a/packages/grafana-ui/src/themes/GlobalStyles/elements.ts b/packages/grafana-ui/src/themes/GlobalStyles/elements.ts index 58b63a8e1c1..921cb01b665 100644 --- a/packages/grafana-ui/src/themes/GlobalStyles/elements.ts +++ b/packages/grafana-ui/src/themes/GlobalStyles/elements.ts @@ -9,9 +9,23 @@ export function getElementStyles(theme: GrafanaTheme2) { const isBodyScrolling = window.grafanaBootData?.settings.featureToggles.bodyScrolling; return css({ + '*, *::before, *::after': { + boxSizing: 'inherit', + }, + + // Suppress the focus outline on elements that cannot be accessed via keyboard. + // This prevents an unwanted focus outline from appearing around elements that + // might still respond to pointer events. + // + // Credit: https://github.com/suitcss/base + "[tabindex='-1']:focus": { + outline: 'none !important', + }, + html: { MsOverflowStyle: 'scrollbar', WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)', + boxSizing: 'border-box', height: '100%', fontSize: `${theme.typography.htmlFontSize}px`, fontFamily: theme.typography.fontFamily, @@ -61,6 +75,8 @@ export function getElementStyles(theme: GrafanaTheme2) { textarea: { overflow: 'auto', + // Textareas should really only resize vertically so they don't break their (horizontal) containers. + resize: 'vertical', }, button: { @@ -72,6 +88,45 @@ export function getElementStyles(theme: GrafanaTheme2) { }, }, + label: { + // Allow labels to use `margin` for spacing. + display: 'inline-block', + }, + + figure: { + margin: theme.spacing(0, 0, 2), + }, + + img: { + // By default, ``s are `inline-block`. This assumes that, and vertically + // centers them. This won't apply should you reset them to `block` level. + verticalAlign: 'middle', + // Note: ``s are deliberately not made responsive by default. + // For the rationale behind this, see the comments on the `.img-fluid` class. + }, + + fieldset: { + // Chrome and Firefox set a `min-width: min-content;` on fieldsets, + // so we reset that to ensure it behaves more like a standard block element. + // See https://github.com/twbs/bootstrap/issues/12359. + minWidth: 0, + // Reset the default outline behavior of fieldsets so they don't affect page layout. + padding: 0, + margin: 0, + border: 0, + }, + + legend: { + // Reset the entire legend element to match the `fieldset` + display: 'block', + width: '100%', + padding: 0, + marginBottom: theme.spacing(1), + fontSize: theme.spacing(3), + lineHeight: 'inherit', + border: 0, + }, + // Ex: 14px base font * 85% = about 12px 'small, .small': { fontSize: theme.typography.bodySmall.fontSize, @@ -193,7 +248,9 @@ export function getElementStyles(theme: GrafanaTheme2) { background: theme.colors.warning.main, }, - 'ul, ol': { + 'ul, ol, dl': { + marginTop: 0, + marginBottom: 0, padding: 0, }, 'ul ul, ul ol, ol ol, ol ul': { @@ -202,9 +259,9 @@ export function getElementStyles(theme: GrafanaTheme2) { li: { lineHeight: theme.typography.body.lineHeight, }, - - dl: { - marginBottom: theme.spacing(2), + dd: { + marginBottom: theme.spacing(1), + marginLeft: 0, // Undo browser default }, 'dt, dd': { lineHeight: theme.typography.body.lineHeight, @@ -218,8 +275,10 @@ export function getElementStyles(theme: GrafanaTheme2) { // 2. Correct font properties not being inherited. // 3. Address margins set differently in Firefox 4+, Safari, and Chrome. 'button, input, optgroup, select, textarea': { + borderRadius: theme.shape.radius.default, color: 'inherit', font: 'inherit', + lineHeight: 'inherit', margin: 0, }, @@ -239,6 +298,14 @@ export function getElementStyles(theme: GrafanaTheme2) { cursor: 'pointer', }, + 'input[type="search"]': { + // This overrides the extra rounded corners on search inputs in iOS so that our + // `.form-control` class can properly style them. Note that this cannot simply + // be added to `.form-control` as it's not specific enough. For details, see + // https://github.com/twbs/bootstrap/issues/11586. + WebkitAppearance: 'none', + }, + // Remove inner padding and search cancel button in Safari and Chrome on OS X. // Safari (but not Chrome) clips the cancel button when the search input has // padding (and `textfield` appearance). @@ -247,12 +314,23 @@ export function getElementStyles(theme: GrafanaTheme2) { }, table: { + // Reset for nesting within parents with `background-color`. + backgroundColor: 'transparent', borderCollapse: 'collapse', borderSpacing: 0, }, + caption: { + paddingTop: theme.spacing(0.5), + paddingBottom: theme.spacing(0.5), + color: theme.colors.text.secondary, + textAlign: 'left', + captionSide: 'bottom', + }, + th: { fontWeight: theme.typography.fontWeightMedium, + textAlign: 'left', }, 'td, th': { @@ -312,6 +390,33 @@ export function getElementStyles(theme: GrafanaTheme2) { }, }, + // iOS "clickable elements" fix for role="button" + // + // Fixes "clickability" issue (and more generally, the firing of events such as focus as well) + // for traditionally non-focusable elements with role="button" + // see https://developer.mozilla.org/en-US/docs/Web/Events/click#Safari_Mobile + "[role='button']": { + cursor: 'pointer', + }, + + // Always hide an element with the `hidden` HTML attribute (from PureCSS). + '[hidden]': { + display: 'none !important', + }, + + // Avoid 300ms click delay on touch devices that support the `touch-action` CSS property. + // + // In particular, unlike most other browsers, IE11+Edge on Windows 10 on touch devices and IE Mobile 10-11 + // DON'T remove the click delay when `` is present. + // However, they DO support removing the click delay via `touch-action: manipulation`. + // See: + // * http://v4-alpha.getbootstrap.com/content/reboot/#click-delay-optimization-for-touch + // * http://caniuse.com/#feat=css-touch-action + // * http://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay + "a, area, button, [role='button'], input, label, select, summary, textarea": { + touchAction: 'manipulation', + }, + '.text-link': { textDecoration: 'underline', }, diff --git a/public/sass/_grafana.scss b/public/sass/_grafana.scss index d0f36791e03..ec3c07791dc 100644 --- a/public/sass/_grafana.scss +++ b/public/sass/_grafana.scss @@ -1,5 +1,23 @@ +// This is specified in runtime Emotion GlobalStyles but we need them for the preloader styles +html { + font-size: $font-size-base; + height: 100%; +} + +// This is specified in runtime Emotion GlobalStyles but we need them for the preloader styles +body { + font-family: $font-family-sans-serif; + font-size: $font-size-base; + line-height: $line-height-base; + color: $text-color; + background-color: $body-bg; + height: 100%; + width: 100%; + margin: 0; + position: absolute; +} + // BASE -@import 'base/reboot'; @import 'base/grid'; @import 'base/font_awesome'; diff --git a/public/sass/base/_reboot.scss b/public/sass/base/_reboot.scss deleted file mode 100644 index 91575a98381..00000000000 --- a/public/sass/base/_reboot.scss +++ /dev/null @@ -1,318 +0,0 @@ -// scss-lint:disable ImportantRule, QualifyingElement, DuplicateProperty - -// Reboot -// -// Global resets to common HTML elements and more for easier usage by Bootstrap. -// Adds additional rules on top of Normalize.css, including several overrides. - -// Reset the box-sizing -// -// Change from `box-sizing: content-box` to `border-box` so that when you add -// `padding` or `border`s to an element, the overall declared `width` does not -// change. For example, `width: 100px;` will always be `100px` despite the -// `border: 10px solid red;` and `padding: 20px;`. -// -// Heads up! This reset may cause conflicts with some third-party widgets. For -// recommendations on resolving such conflicts, see -// http://getbootstrap.com/getting-started/#third-box-sizing. -// -// Credit: https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ - -html { - box-sizing: border-box; -} - -*, -*::before, -*::after { - box-sizing: inherit; -} - -// Make viewport responsive -// -// @viewport is needed because IE 10+ doesn't honor in -// some cases. See http://timkadlec.com/2012/10/ie10-snap-mode-and-responsive-design/. -// Eventually @viewport will replace . -// -// However, `device-width` is broken on IE 10 on Windows (Phone) 8, -// (see http://timkadlec.com/2013/01/windows-phone-8-and-device-width/ and https://github.com/twbs/bootstrap/issues/10497) -// and the fix for that involves a snippet of JavaScript to sniff the user agent -// and apply some conditional CSS. -// -// See http://getbootstrap.com/getting-started/#support-ie10-width for the relevant hack. -// -// Wrap `@viewport` with `@at-root` for when folks do a nested import (e.g., -// `.class-name { @import "bootstrap"; }`). -@at-root { - @-ms-viewport { - width: device-width; - } -} - -// -// Reset HTML, body, and more -// - -// Suppress the focus outline on elements that cannot be accessed via keyboard. -// This prevents an unwanted focus outline from appearing around elements that -// might still respond to pointer events. -// -// Credit: https://github.com/suitcss/base -[tabindex='-1']:focus { - outline: none !important; -} - -// This is specified in runtime Emotion GlobalStyles but we need them for the Grafana loading styles -html { - font-size: $font-size-base; - height: 100%; -} - -// This is specified in runtime Emotion GlobalStyles but we need them for the Grafana loading styles -body { - font-family: $font-family-sans-serif; - font-size: $font-size-base; - line-height: $line-height-base; - color: $text-color; - background-color: $body-bg; - height: 100%; - width: 100%; - margin: 0; - position: absolute; -} - -// -// Typography -// - -// Remove top margins from headings -// -// By default, `

`-`

` all receive top and bottom margins. We nuke the top -// margin for easier control within type scales as it avoids margin collapsing. -h1, -h2, -h3, -h4, -h5, -h6 { - margin-top: 0; - margin-bottom: $space-sm; -} - -// Reset margins on paragraphs -// -// Similarly, the top margin on `

`s get reset. However, we also reset the -// bottom margin to use `rem` units instead of `em`. -p { - margin-top: 0; - margin-bottom: $space-md; -} - -// Abbreviations and acronyms -abbr[title] { - cursor: help; - border-bottom: 1px dotted $abbr-border-color; -} - -address { - margin-bottom: $space-md; - font-style: normal; - line-height: inherit; -} - -ol, -ul, -dl { - margin-top: 0; - margin-bottom: 0; -} - -ol ol, -ul ul, -ol ul, -ul ol { - margin-bottom: 0; -} - -dt { - font-weight: $font-weight-semi-bold; -} - -dd { - margin-bottom: $space-sm; - margin-left: 0; // Undo browser default -} - -blockquote { - margin: 0 0 $space-md; -} - -// -// Links -// - -// -// Code -// - -pre { - // Remove browser default top margin - margin-top: 0; - // Reset browser default of `1em` to use `rem`s - margin-bottom: $space-md; -} - -// -// Figures -// - -figure { - // Normalize adds `margin` to `figure`s as browsers apply it inconsistently. - // We reset that to create a better flow in-page. - margin: 0 0 $space-md; -} - -// -// Images -// - -img { - // By default, ``s are `inline-block`. This assumes that, and vertically - // centers them. This won't apply should you reset them to `block` level. - vertical-align: middle; - // Note: ``s are deliberately not made responsive by default. - // For the rationale behind this, see the comments on the `.img-fluid` class. -} - -// iOS "clickable elements" fix for role="button" -// -// Fixes "clickability" issue (and more generally, the firing of events such as focus as well) -// for traditionally non-focusable elements with role="button" -// see https://developer.mozilla.org/en-US/docs/Web/Events/click#Safari_Mobile - -[role='button'] { - cursor: pointer; -} - -// Avoid 300ms click delay on touch devices that support the `touch-action` CSS property. -// -// In particular, unlike most other browsers, IE11+Edge on Windows 10 on touch devices and IE Mobile 10-11 -// DON'T remove the click delay when `` is present. -// However, they DO support removing the click delay via `touch-action: manipulation`. -// See: -// * http://v4-alpha.getbootstrap.com/content/reboot/#click-delay-optimization-for-touch -// * http://caniuse.com/#feat=css-touch-action -// * http://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay - -a, -area, -button, -[role='button'], -input, -label, -select, -summary, -textarea { - touch-action: manipulation; -} - -// -// Tables -// - -table { - // Reset for nesting within parents with `background-color`. - background-color: transparent; -} - -caption { - padding-top: $space-inset-squish-md; - padding-bottom: $space-inset-squish-md; - color: $text-muted; - text-align: left; - caption-side: bottom; -} - -th { - // Centered by default, but left-align-ed to match the `td`s below. - text-align: left; -} - -// -// Forms -// -label { - // Allow labels to use `margin` for spacing. - display: inline-block; -} - -// Work around a Firefox/IE bug where the transparent `button` background -// results in a loss of the default `button` focus styles. -// -// Credit: https://github.com/suitcss/base/ -button:focus { - outline: 1px dotted; - outline: 5px auto -webkit-focus-ring-color; -} - -input, -button, -select, -textarea { - // Remove all `margin`s so our classes don't have to do it themselves. - margin: 0; - // Normalize includes `font: inherit;`, so `font-family`. `font-size`, etc are - // properly inherited. However, `line-height` isn't addressed there. Using this - // ensures we don't need to unnecessarily redeclare the global font stack. - line-height: inherit; - // iOS adds rounded borders by default - border-radius: 0; -} - -textarea { - // Textareas should really only resize vertically so they don't break their (horizontal) containers. - resize: vertical; -} - -fieldset { - // Chrome and Firefox set a `min-width: min-content;` on fieldsets, - // so we reset that to ensure it behaves more like a standard block element. - // See https://github.com/twbs/bootstrap/issues/12359. - min-width: 0; - // Reset the default outline behavior of fieldsets so they don't affect page layout. - padding: 0; - margin: 0; - border: 0; -} - -legend { - // Reset the entire legend element to match the `fieldset` - display: block; - width: 100%; - padding: 0; - margin-bottom: $space-sm; - font-size: $space-lg; - line-height: inherit; - border: 0; -} - -input[type='search'] { - // This overrides the extra rounded corners on search inputs in iOS so that our - // `.form-control` class can properly style them. Note that this cannot simply - // be added to `.form-control` as it's not specific enough. For details, see - // https://github.com/twbs/bootstrap/issues/11586. - -webkit-appearance: none; -} - -// todo: needed? -output { - display: inline-block; - // font-size: $font-size-base; - // line-height: $line-height; - // color: $input-color; -} - -// Always hide an element with the `hidden` HTML attribute (from PureCSS). -[hidden] { - display: none !important; -}