Skip to content

Commit

Permalink
Added EuiMark (elastic#3060)
Browse files Browse the repository at this point in the history
  • Loading branch information
mridulgogia authored Mar 13, 2020
1 parent 012e8c7 commit a8a4063
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -413,7 +413,7 @@ const navigation = [
DelayRenderExample,
ErrorBoundaryExample,
FocusTrapExample,
HighlightExample,
HighlightAndMarkExample,
InnerTextExample,
I18nExample,
IsColorDarkExample,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -35,5 +40,26 @@ export const HighlightExample = {
components: { EuiHighlight },
demo: <Highlight />,
},
{
title: 'Mark',
source: [
{
type: GuideSectionTypes.JS,
code: markSource,
},
{
type: GuideSectionTypes.HTML,
code: markHtml,
},
],
text: (
<p>
Use <EuiCode>EuiMark</EuiCode> to wrap a string in an
<EuiCode>mark</EuiCode> element.
</p>
),
components: { EuiMark },
demo: <Mark />,
},
],
};
13 changes: 13 additions & 0 deletions src-docs/src/views/highlight_and_mark/mark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { Fragment } from 'react';

import { EuiMark } from '../../../../src/components';

export function Mark() {
return (
<Fragment>
The quick brown fox
<EuiMark>jumped over</EuiMark>
the lazy dog
</Fragment>
);
}
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 9 additions & 0 deletions src/components/mark/__snapshots__/mark.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiMark is rendered 1`] = `
<mark
class="euiMark"
>
Marked
</mark>
`;
1 change: 1 addition & 0 deletions src/components/mark/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'mark';
4 changes: 4 additions & 0 deletions src/components/mark/_mark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.euiMark {
margin: $euiSizeXS;
padding: $euiSizeXS;
}
1 change: 1 addition & 0 deletions src/components/mark/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EuiMark } from './mark';
12 changes: 12 additions & 0 deletions src/components/mark/mark.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { render } from 'enzyme';

import { EuiMark } from './mark';

describe('EuiMark', () => {
test('is rendered', () => {
const component = render(<EuiMark>Marked</EuiMark>);

expect(component).toMatchSnapshot();
});
});
21 changes: 21 additions & 0 deletions src/components/mark/mark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { HTMLAttributes, FunctionComponent } from 'react';
import { CommonProps } from '../common';
import classNames from 'classnames';
export type EuiMarkProps = HTMLAttributes<HTMLElement> &
CommonProps & {
children: string;
};

export const EuiMark: FunctionComponent<EuiMarkProps> = ({
children,
className,
...rest
}) => {
const classes = classNames('euiMark', className);

return (
<mark className={classes} {...rest}>
{children}
</mark>
);
};

0 comments on commit a8a4063

Please sign in to comment.