diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0a9bab407..fadf630d538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Added alpha channel (opacity) support to `EuiColorPicker` and `EuiColorStops` ([#2850](https://github.com/elastic/eui/pull/2850)) - Added `useResizeObserver` hook ([#2991](https://github.com/elastic/eui/pull/2991)) - Added `showColumnSelector.allowHide` and `showColumnSelector.allowReorder` props to `EuiDataGrid` UI configuration ([#2993](https://github.com/elastic/eui/pull/2993)) +- Added `EuiMark` component ([#3060](https://github.com/elastic/eui/pull/3060)) **Bug Fixes** diff --git a/src-docs/src/routes.js b/src-docs/src/routes.js index 41a0c6088b6..6f008e81fe7 100644 --- a/src-docs/src/routes.js +++ b/src-docs/src/routes.js @@ -118,7 +118,7 @@ import { HeaderExample } from './views/header/header_example'; import { HealthExample } from './views/health/health_example'; -import { HighlightExample } from './views/highlight/highlight_example'; +import { HighlightAndMarkExample } from './views/highlight_and_mark/highlight_and_mark_example'; import { HorizontalRuleExample } from './views/horizontal_rule/horizontal_rule_example'; @@ -413,7 +413,7 @@ const navigation = [ DelayRenderExample, ErrorBoundaryExample, FocusTrapExample, - HighlightExample, + HighlightAndMarkExample, InnerTextExample, I18nExample, IsColorDarkExample, diff --git a/src-docs/src/views/highlight/highlight.js b/src-docs/src/views/highlight_and_mark/highlight.js similarity index 100% rename from src-docs/src/views/highlight/highlight.js rename to src-docs/src/views/highlight_and_mark/highlight.js diff --git a/src-docs/src/views/highlight/highlight_example.js b/src-docs/src/views/highlight_and_mark/highlight_and_mark_example.js similarity index 53% rename from src-docs/src/views/highlight/highlight_example.js rename to src-docs/src/views/highlight_and_mark/highlight_and_mark_example.js index 87ebc10f4c7..d61fe836b14 100644 --- a/src-docs/src/views/highlight/highlight_example.js +++ b/src-docs/src/views/highlight_and_mark/highlight_and_mark_example.js @@ -4,14 +4,19 @@ import { renderToHtml } from '../../services'; import { GuideSectionTypes } from '../../components'; -import { EuiCode, EuiHighlight } from '../../../../src/components'; +import { EuiCode, EuiHighlight, EuiMark } from '../../../../src/components'; import { Highlight } from './highlight'; +import { Mark } from './mark'; + const highlightSource = require('!!raw-loader!./highlight'); const highlightHtml = renderToHtml(Highlight); -export const HighlightExample = { - title: 'Highlight', +const markSource = require('!!raw-loader!./mark'); +const markHtml = renderToHtml(Mark); + +export const HighlightAndMarkExample = { + title: 'Highlight and mark', sections: [ { title: 'Highlight', @@ -35,5 +40,26 @@ export const HighlightExample = { components: { EuiHighlight }, demo: , }, + { + title: 'Mark', + source: [ + { + type: GuideSectionTypes.JS, + code: markSource, + }, + { + type: GuideSectionTypes.HTML, + code: markHtml, + }, + ], + text: ( +

+ Use EuiMark to wrap a string in an + mark element. +

+ ), + components: { EuiMark }, + demo: , + }, ], }; diff --git a/src-docs/src/views/highlight_and_mark/mark.js b/src-docs/src/views/highlight_and_mark/mark.js new file mode 100644 index 00000000000..2b94e860422 --- /dev/null +++ b/src-docs/src/views/highlight_and_mark/mark.js @@ -0,0 +1,13 @@ +import React, { Fragment } from 'react'; + +import { EuiMark } from '../../../../src/components'; + +export function Mark() { + return ( + + The quick brown fox + jumped over + the lazy dog + + ); +} diff --git a/src/components/index.js b/src/components/index.js index fab472fa1f1..71e2cced408 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -186,6 +186,8 @@ export { EuiLink } from './link'; export { EuiListGroup, EuiListGroupItem } from './list_group'; +export { EuiMark } from './mark'; + export { EUI_MODAL_CANCEL_BUTTON, EUI_MODAL_CONFIRM_BUTTON, diff --git a/src/components/index.scss b/src/components/index.scss index 57f885deb08..cc4f1615102 100644 --- a/src/components/index.scss +++ b/src/components/index.scss @@ -39,6 +39,7 @@ @import 'link/index'; @import 'list_group/index'; @import 'loading/index'; +@import 'mark/index'; @import 'modal/index'; @import 'nav_drawer/index'; @import 'overlay_mask/index'; diff --git a/src/components/mark/__snapshots__/mark.test.tsx.snap b/src/components/mark/__snapshots__/mark.test.tsx.snap new file mode 100644 index 00000000000..4c160bb08be --- /dev/null +++ b/src/components/mark/__snapshots__/mark.test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`EuiMark is rendered 1`] = ` + + Marked + +`; diff --git a/src/components/mark/_index.scss b/src/components/mark/_index.scss new file mode 100644 index 00000000000..4888bf861b6 --- /dev/null +++ b/src/components/mark/_index.scss @@ -0,0 +1 @@ +@import 'mark'; \ No newline at end of file diff --git a/src/components/mark/_mark.scss b/src/components/mark/_mark.scss new file mode 100644 index 00000000000..db48c830c0d --- /dev/null +++ b/src/components/mark/_mark.scss @@ -0,0 +1,4 @@ +.euiMark { + margin: $euiSizeXS; + padding: $euiSizeXS; +} \ No newline at end of file diff --git a/src/components/mark/index.ts b/src/components/mark/index.ts new file mode 100644 index 00000000000..24ad3219c0a --- /dev/null +++ b/src/components/mark/index.ts @@ -0,0 +1 @@ +export { EuiMark } from './mark'; diff --git a/src/components/mark/mark.test.tsx b/src/components/mark/mark.test.tsx new file mode 100644 index 00000000000..1db9382e18c --- /dev/null +++ b/src/components/mark/mark.test.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { render } from 'enzyme'; + +import { EuiMark } from './mark'; + +describe('EuiMark', () => { + test('is rendered', () => { + const component = render(Marked); + + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/components/mark/mark.tsx b/src/components/mark/mark.tsx new file mode 100644 index 00000000000..6a1e2c9ce9d --- /dev/null +++ b/src/components/mark/mark.tsx @@ -0,0 +1,21 @@ +import React, { HTMLAttributes, FunctionComponent } from 'react'; +import { CommonProps } from '../common'; +import classNames from 'classnames'; +export type EuiMarkProps = HTMLAttributes & + CommonProps & { + children: string; + }; + +export const EuiMark: FunctionComponent = ({ + children, + className, + ...rest +}) => { + const classes = classNames('euiMark', className); + + return ( + + {children} + + ); +};