Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styled-jsx: EuiMark #7

Draft
wants to merge 2 commits into
base: ref/styled-jsx
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ import { ListGroupExample } from './views/list_group/list_group_example';

import { LoadingExample } from './views/loading/loading_example';

import { MarkExample } from './views/mark/mark_example';

import { ModalExample } from './views/modal/modal_example';

import { MutationObserverExample } from './views/mutation_observer/mutation_observer_example';
Expand Down Expand Up @@ -358,6 +360,7 @@ const navigation = [
InnerTextExample,
I18nExample,
IsColorDarkExample,
MarkExample,
PrettyDurationExample,
MutationObserverExample,
OutsideClickDetectorExample,
Expand Down
17 changes: 17 additions & 0 deletions src-docs/src/views/mark/mark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

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

export default () => (
<React.Fragment>
<EuiText>
A <EuiMark>marked</EuiMark> thing
</EuiText>
<EuiText>
A <EuiMark type="strong">strong</EuiMark> thing
</EuiText>
<EuiText>
A, <EuiMark type="em">em</EuiMark> thing
</EuiText>
</React.Fragment>
);
44 changes: 44 additions & 0 deletions src-docs/src/views/mark/mark_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';

import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';

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

import Mark from './mark';
const markSource = require('!!raw-loader!./mark');
const markHtml = renderToHtml(Mark);
// const markSnippet = [
// `<EuiLink href="#"><!-- Link text --></EuiLink>
// `,
// `<EuiLink href="#" color="secondary">
// <!-- Colored link text -->
// </EuiLink>
// `,
// ];

export const MarkExample = {
title: 'Mark',
sections: [
{
source: [
{
type: GuideSectionTypes.JS,
code: markSource,
},
{
type: GuideSectionTypes.HTML,
code: markHtml,
},
],
text: <p />,
props: { EuiMark },
// snippet: markSnippet,
demo: <Mark />,
},
],
};
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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
3 changes: 2 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 All @@ -59,4 +60,4 @@
@import 'token/index';
@import 'toggle/index';
@import 'tool_tip/index';
@import 'text/index';
@import 'text/index';
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';
39 changes: 39 additions & 0 deletions src/components/mark/_mark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@import '../../global_styling/context';

.euiMark {
color: inherit;

&.euiMark--mark {
background-color: $euiColorVis5;
}

&.euiMark--strong {
background-color: transparent;
font-weight: $euiFontWeightBold;
}

&.euiMark--em {
background-color: transparent;
font-style: italic;
}
}

// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark#Accessibility_concerns
.euiMark:before,
.euiMark:after {
clip-path: inset(100%);
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.euiMark:before {
content: ' [highlight start] ';
}

.euiMark:after {
content: ' [highlight end] ';
}
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';
24 changes: 24 additions & 0 deletions src/components/mark/mark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classnames from 'classnames';
import { CommonProps } from '../common';

type EuiMarkProps = CommonProps &
HTMLAttributes<HTMLElement> & {
type?: 'mark' | 'strong' | 'em';
};

export const EuiMark: FunctionComponent<EuiMarkProps> = ({
children,
className,
type = 'mark',
}) => {
const classes = classnames('euiMark', [`euiMark--${type}`], className);
return (
<mark className={classes}>
{children}
<style jsx>{`
@import 'mark';
`}</style>
</mark>
);
};