-
- );
-
- rehype2reactConfig.components.ol = ({ children }) => (
-
- {children}
-
- );
-
return (
-
+
{children}
);
diff --git a/src-docs/src/routes.js b/src-docs/src/routes.js
index 3de50564bb0b..2ac4de376be6 100644
--- a/src-docs/src/routes.js
+++ b/src-docs/src/routes.js
@@ -3,14 +3,14 @@ import { slugify } from '../../src/services';
import { createHashHistory } from 'history';
-import { GuidePage, GuideSection } from './components';
+import { GuidePage, GuideSection, GuideMarkdownFormat } from './components';
import { EuiErrorBoundary } from '../../src/components';
import { playgroundCreator } from './services/playground';
// Guidelines
-// const GettingStarted = require('!!raw-loader!./views/guidelines/getting_started.md');
+const GettingStarted = require('!!raw-loader!./views/guidelines/getting_started.md');
import AccessibilityGuidelines from './views/guidelines/accessibility';
@@ -293,34 +293,33 @@ const createExample = (example, customTitle) => {
};
};
-// const createMarkdownExample = (example, title) => {
-// const headings = example.default.match(/^(##) (.*)/gm);
+const createMarkdownExample = (example, title) => {
+ const headings = example.default.match(/^(##) (.*)/gm);
-// const sections = headings.map((heading) => {
-// const title = heading.replace('## ', '');
+ const sections = headings.map((heading) => {
+ const title = heading.replace('## ', '');
-// return { id: slugify(title), title: title };
-// });
+ return { id: slugify(title), title: title };
+ });
-// return {
-// name: title,
-// component: () => (
-//
-//
-// {example.default}
-//
-//
-// ),
-// sections: sections,
-// };
-// };
+ return {
+ name: title,
+ component: () => (
+
+
+ {example.default}
+
+
+ ),
+ sections: sections,
+ };
+};
const navigation = [
{
name: 'Guidelines',
items: [
- // TODO uncomment when EuiMarkdownFormat has a better text formatting
- // createMarkdownExample(GettingStarted, 'Getting started'),
+ createMarkdownExample(GettingStarted, 'Getting started'),
createExample(AccessibilityGuidelines, 'Accessibility'),
{
name: 'Colors',
diff --git a/src-docs/src/views/guidelines/getting_started.md b/src-docs/src/views/guidelines/getting_started.md
index 9835b5235cc1..85ea02c4d0ee 100644
--- a/src-docs/src/views/guidelines/getting_started.md
+++ b/src-docs/src/views/guidelines/getting_started.md
@@ -2,11 +2,11 @@
To install the Elastic UI Framework into an existing project, use the `yarn` CLI (`npm` is not supported).
-```js
+```
yarn add @elastic/eui
```
-Note that EUI has [several `peerDependencies` requirements](package.json) that will also need to be installed if starting with a blank project. You can read more about other ways to [consume EUI][consuming].
+Note that EUI has [several `peerDependencies` requirements](https://github.com/elastic/eui/package.json) that will also need to be installed if starting with a blank project. You can read more about other ways to [consume EUI](https://github.com/elastic/eui/blob/master/wiki/consuming.md).
```js
yarn add @elastic/eui @elastic/datemath moment prop-types
@@ -17,7 +17,7 @@ yarn add @elastic/eui @elastic/datemath moment prop-types
### Node
-We depend upon the version of node defined in [.nvmrc](.nvmrc).
+We depend upon the version of node defined in [.nvmrc](https://github.com/elastic/eui/.nvmrc).
You will probably want to install a node version manager. [nvm](https://github.com/creationix/nvm) is recommended.
@@ -29,7 +29,7 @@ nvm install
### Documentation
-You can run the documentation locally at [http://localhost:8030/](http://localhost:8030/) by running the following.
+You can run the documentation locally at `http://localhost:8030/` by running the following.
```js
yarn
diff --git a/src-docs/src/views/home/home_view.js b/src-docs/src/views/home/home_view.js
index d54b12c33cf5..3eeaf9105445 100644
--- a/src-docs/src/views/home/home_view.js
+++ b/src-docs/src/views/home/home_view.js
@@ -58,9 +58,9 @@ export const HomeView = () => (
-
+
Getting started
-
+
diff --git a/src-docs/src/views/markdown_editor/mardown_format_example.js b/src-docs/src/views/markdown_editor/mardown_format_example.js
index 01fb77106ac3..dce19cfe9223 100644
--- a/src-docs/src/views/markdown_editor/mardown_format_example.js
+++ b/src-docs/src/views/markdown_editor/mardown_format_example.js
@@ -1,24 +1,23 @@
import React, { Fragment } from 'react';
-
-import { renderToHtml } from '../../services';
-
import { GuideSectionTypes } from '../../components';
import {
EuiLink,
EuiMarkdownFormat,
EuiText,
+ EuiCode,
} from '../../../../src/components';
import { Link } from 'react-router-dom';
import MarkdownFormat from './markdown_format';
const markdownFormatSource = require('!!raw-loader!./markdown_format');
-const markdownFormatHtml = renderToHtml(MarkdownFormat);
+
+import MarkdownFormatStyles from './markdown_format_styles';
+const markdownFormatStylesSource = require('!!raw-loader!./markdown_format_styles');
import MarkdownFormatSink from './markdown_format_sink';
const markdownFormatSinkSource = require('!!raw-loader!./markdown_format_sink');
-const markdownFormatSinkHtml = renderToHtml(MarkdownFormatSink);
export const MarkdownFormatExample = {
title: 'Markdown format',
@@ -45,10 +44,6 @@ export const MarkdownFormatExample = {
type: GuideSectionTypes.JS,
code: markdownFormatSource,
},
- {
- type: GuideSectionTypes.HTML,
- code: markdownFormatHtml,
- },
],
title: 'Built in plugins',
text: (
@@ -59,8 +54,9 @@ export const MarkdownFormatExample = {
Remark
{' '}
by default. The translation layer automatically substitutes raw HTML
- output with their EUI equivalent. This means anchor and code blocks
- will become EuiLink and EuiCodeBlock{' '}
+ output with their EUI equivalent. This means anchor, code blocks and
+ horizontal rules will become EuiLink,{' '}
+ EuiCodeBlock and EuiHorizontalRule{' '}
components respectively.
),
@@ -73,11 +69,29 @@ export const MarkdownFormatExample = {
source: [
{
type: GuideSectionTypes.JS,
- code: markdownFormatSinkSource,
+ code: markdownFormatStylesSource,
},
+ ],
+ title: 'Text sizing and coloring',
+ text: (
+
+ EuiMarkdownFormat uses{' '}
+ EuiText as a wrapper to handle all
+ the CSS styling when rendering the HTML. It also gives the ability to
+ control the text size and color with the textSize{' '}
+ and color props, respectively.
+
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+ });
});
diff --git a/src/components/text/text_color.tsx b/src/components/text/text_color.tsx
index 27faa683b566..96f9391afc5b 100644
--- a/src/components/text/text_color.tsx
+++ b/src/components/text/text_color.tsx
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import React, { FunctionComponent, HTMLAttributes } from 'react';
+import React, { FunctionComponent, HTMLAttributes, CSSProperties } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';
@@ -19,6 +19,7 @@ const colorsToClassNameMap = {
danger: 'euiTextColor--danger',
warning: 'euiTextColor--warning',
ghost: 'euiTextColor--ghost',
+ inherit: 'euiTextColor--inherit',
};
export type TextColor = keyof typeof colorsToClassNameMap;
@@ -32,8 +33,9 @@ export type EuiTextColorProps = CommonProps &
> & {
/**
* **`secondary` color is DEPRECATED, use `success` instead**
+ * Any of our named colors or a `hex`, `rgb` or `rgba` value.
*/
- color?: TextColor;
+ color?: TextColor | CSSProperties['color'];
/**
* Determines the root element
*/
@@ -45,17 +47,31 @@ export const EuiTextColor: FunctionComponent = ({
color = 'default',
className,
component = 'span',
+ style,
...rest
}) => {
+ const isNamedColor = COLORS.includes(color as TextColor);
+
const classes = classNames(
'euiTextColor',
- colorsToClassNameMap[color],
+ { 'euiTextColor--custom': !isNamedColor },
+ isNamedColor && colorsToClassNameMap[color as TextColor],
className
);
const Component = component;
+ // We're checking if is a custom color.
+ // If it is a custom color we set the `color` of the `.euiTextColor` div to that custom color.
+ // This way the children text elements can `inherit` that color and border and backgrounds can get that `currentColor`.
+ const euiTextStyle = !isNamedColor
+ ? {
+ color: color,
+ ...style,
+ }
+ : { ...style };
+
return (
-
+
{children}
);
diff --git a/src/global_styling/mixins/_typography.scss b/src/global_styling/mixins/_typography.scss
index 0905e5476cbf..5d76e9fc4275 100644
--- a/src/global_styling/mixins/_typography.scss
+++ b/src/global_styling/mixins/_typography.scss
@@ -1,6 +1,41 @@
// sass-lint:disable no-vendor-prefixes
// sass-lint:disable no-important
+@function fontSizeToRemOrEm($size, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ @return #{$size / $euiFontSize}rem;
+ } @else if ($sizingMethod == 'em') {
+ @return #{$size / $euiFontSize}em;
+ }
+}
+
+// It can also be applied to calculate paddings
+@function marginToRemOrEm($elementSize, $elementFontSize, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ @return #{$elementSize / $euiFontSize}rem;
+ } @else if ($sizingMethod == 'em') {
+ @return #{$elementSize / $elementFontSize}em;
+ }
+}
+
+// Spit out rem and px
+@mixin fontSize($size: $euiFontSize, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ font-size: $size;
+ font-size: fontSizeToRemOrEm($size, 'rem');
+ } @else if ($sizingMethod == 'em') {
+ font-size: fontSizeToRemOrEm($size, 'em');
+ }
+}
+
+@mixin lineHeightFromBaseline($multiplier: 3) {
+ line-height: lineHeightFromBaseline($multiplier);
+}
+
+// Some mixins that help us deal with browser scaling of text more consistently.
+// Essentially, fonts across eui should scale against the root html element, not
+// against parent inheritance.
+
// Our base fonts
@mixin euiFont {
diff --git a/src/global_styling/variables/_typography.scss b/src/global_styling/variables/_typography.scss
index a135b93101b4..6bb7ec9c1996 100644
--- a/src/global_styling/variables/_typography.scss
+++ b/src/global_styling/variables/_typography.scss
@@ -1,30 +1,3 @@
-// Some mixins that help us deal with browser scaling of text more consistently.
-// Essentially, fonts across eui should scale against the root html element, not
-// against parent inheritance.
-
-// Typography mixins
-
-@function convertToRem($size) {
- @return #{$size / $euiFontSize}rem;
-}
-
-// Spit out rem and px
-@mixin fontSize($size: $euiFontSize) {
- font-size: $size;
- font-size: convertToRem($size);
-}
-
-// Our base gridline is at 1/2 the font-size, ensure line-heights stay on that gridline.
-// EX: A proper line-height for text is 1.5 times the font-size.
-// If our base font size (euiFontSize) is 16, our baseline is 8 (16*1.5 / 3). To ensure the
-// text stays on the baseline, we pass a multiplier to calculate a line-height in rems.
-@function lineHeightFromBaseline($multiplier: 3) {
- @return convertToRem(($euiFontSize/2)*$multiplier);
-}
-@mixin lineHeightFromBaseline($multiplier: 3) {
- line-height: lineHeightFromBaseline($multiplier);
-}
-
// Families
$euiFontFamily: 'Inter UI', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol' !default;
$euiCodeFontFamily: 'Roboto Mono', Consolas, Menlo, Courier, monospace !default;
@@ -56,6 +29,22 @@ $euiFontWeightBold: 700 !default;
$euiCodeFontWeightRegular: 400 !default;
$euiCodeFontWeightBold: 700 !default;
+
+// Normally functions are imported before variables in `_index.scss` files
+// But because they need to consume some typography variables they need to live here
+@function convertToRem($size) {
+ @return #{$size / $euiFontSize}rem;
+}
+
+// Our base gridline is at 1/2 the font-size, ensure line-heights stay on that gridline.
+// EX: A proper line-height for text is 1.5 times the font-size.
+// If our base font size (euiFontSize) is 16, our baseline is 8 (16*1.5 / 3). To ensure the
+// text stays on the baseline, we pass a multiplier to calculate a line-height in rems.
+@function lineHeightFromBaseline($multiplier: 3) {
+ @return convertToRem(($euiFontSize/2)*$multiplier);
+}
+
+
// Titles map
// Lists all the properties per EuiTitle size that then gets looped through to create the selectors.
// The map allows for tokenization and easier customization per theme, otherwise you'd have to override the selectors themselves
diff --git a/src/themes/eui-amsterdam/global_styling/mixins/_typography.scss b/src/themes/eui-amsterdam/global_styling/mixins/_typography.scss
index f33cc6d97743..f78e7763479f 100644
--- a/src/themes/eui-amsterdam/global_styling/mixins/_typography.scss
+++ b/src/themes/eui-amsterdam/global_styling/mixins/_typography.scss
@@ -2,6 +2,41 @@
// All line-heights are aligned to baseline grid
// sass-lint:disable no-vendor-prefixes
+
+@function fontSizeToRemOrEm($size, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ @return #{$size / $euiFontSize}rem;
+ } @else if ($sizingMethod == 'em') {
+ @return #{$size / $euiFontSize}em;
+ }
+}
+
+@function marginToRemOrEm($elementSize, $elementFontSize, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ @return #{$elementSize / $euiFontSize}rem;
+ } @else if ($sizingMethod == 'em') {
+ @return #{$elementSize / $elementFontSize}em;
+ }
+}
+
+// Spit out rem and px
+@mixin fontSize($size: $euiFontSize, $sizingMethod: 'rem') {
+ @if ($sizingMethod == 'rem') {
+ font-size: $size;
+ font-size: fontSizeToRemOrEm($size, 'rem');
+ } @else if ($sizingMethod == 'em') {
+ font-size: fontSizeToRemOrEm($size, 'em');
+ }
+}
+
+@mixin lineHeightFromBaseline($multiplier: 3) {
+ line-height: lineHeightFromBaseline($multiplier);
+}
+
+// Some mixins that help us deal with browser scaling of text more consistently.
+// Essentially, fonts across eui should scale against the root html element, not
+// against parent inheritance.
+
// Redoing this mixin mainly to remove the letter-spacing
@mixin euiFont {
font-family: $euiFontFamily;
diff --git a/src/themes/eui-amsterdam/global_styling/variables/_typography.scss b/src/themes/eui-amsterdam/global_styling/variables/_typography.scss
index 765e81bc80d8..84f7d3651a93 100644
--- a/src/themes/eui-amsterdam/global_styling/variables/_typography.scss
+++ b/src/themes/eui-amsterdam/global_styling/variables/_typography.scss
@@ -19,13 +19,17 @@ $euiBodyLineHeight: 1.142857143; // 16px from a 14px base font size to ensure it
$euiCodeFontWeightRegular: 400;
$euiCodeFontWeightBold: 700;
+
+// Normally functions are imported before variables in `_index.scss` files
+// But because they need to consume some typography variables they need to live here
+@function convertToRem($size) {
+ @return #{$size / $euiFontSize}rem;
+}
+
// Use 8px increments for base gridline
@function lineHeightFromBaseline($multiplier: 3) {
@return convertToRem(($euiSize/2)*$multiplier);
}
-@mixin lineHeightFromBaseline($multiplier: 3) {
- line-height: lineHeightFromBaseline($multiplier);
-}
$euiTitles: (
'xxxs': (
diff --git a/src/themes/eui-amsterdam/overrides/_text.scss b/src/themes/eui-amsterdam/overrides/_text.scss
index ffda9eff4baf..9fb169f3bd6c 100644
--- a/src/themes/eui-amsterdam/overrides/_text.scss
+++ b/src/themes/eui-amsterdam/overrides/_text.scss
@@ -1,5 +1,3 @@
-// Increase the medium (currently default) size of EuiText to original 16px
.euiText--medium {
- @include fontSize($euiFontSizeM);
- @include euiScaleText($euiFontSizeM);
+ @include euiScaleText($euiFontSizeM, 'rem');
}