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

EuiCode now consumes EuiCodeBlock and can highlight text #138

Merged
merged 7 commits into from
Nov 10, 2017
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- Changed the hover states of `EuiButtonEmpty` to look more like links.
- Changed the hover states of `EuiButtonEmpty` to look more like links. [#135](https://github.com/elastic/eui/pull/135)
- Added `transparentBackground` prop to `EuiCodeBlock`. Made light theme the default.
`EuiCode` now just wraps `EuiCodeBlock` so you can do inline highlighting. [#138](https://github.com/elastic/eui/pull/138)

# [`0.0.1`](https://github.com/elastic/eui/tree/v0.0.1) Initial Release

Expand Down
16 changes: 15 additions & 1 deletion src-docs/src/views/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ import {
EuiText,
} from '../../../../src/components';

const htmlCode = `<!--I'm an example of HTML-->
<div>
asdf
</div>
`;

export default () => (
<EuiText>
<p>Sometimes you need to highlight <EuiCode>code</EuiCode> like this.</p>
<p>
Sometimes you need to emphasize <EuiCode>code</EuiCode> like this.
</p>
<p>
You can also pass a language in like <EuiCode language="html">{htmlCode.trim()}</EuiCode>.
</p>
<p>
Make the background transparent like this <EuiCode language="html" transparentBackground>{htmlCode.trim()}</EuiCode>.
</p>
</EuiText>
);
5 changes: 4 additions & 1 deletion src-docs/src/views/code/code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export default () => (

<EuiSpacer />

<EuiCodeBlock language="js" fontSize="l" paddingSize="s" color="light" overflowHeight={300}>
<EuiCodeBlock language="js" fontSize="l" paddingSize="s" color="dark" overflowHeight={300}>
{jsCode}
</EuiCodeBlock>

<EuiSpacer />

</div>
);
5 changes: 4 additions & 1 deletion src-docs/src/views/code/code_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default props => (
}]}
text={
<p>
Description needed: how to use the <EuiCode>Code</EuiCode> component.
<EuiCode>Code</EuiCode> is for making inline code snippets that can work
within or next to bodies of text.
</p>
}
demo={
Expand Down Expand Up @@ -62,6 +63,8 @@ export default props => (
<li><EuiCode>paddingSize</EuiCode> accepts "s" / "m" / "l" (default).</li>
<li><EuiCode>fontSize</EuiCode> accepts "s" (default) / "m" / "l".</li>
<li><EuiCode>overflowHeight</EuiCode> accepts a number. By default it is not set.</li>
<li><EuiCode>transparentBackground</EuiCode> set to <EuiCode>false</EuiCode> will remove the background.</li>
<li><EuiCode>inline</EuiCode> will display the passed code in an inline format. Will also remove any margins set.</li>
</ul>
</div>
}
Expand Down
19 changes: 14 additions & 5 deletions src/components/code/__snapshots__/code.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCode is rendered 1`] = `
<code
aria-label="aria-label"
class="euiCode testClass1 testClass2"
data-test-subj="test subject string"
/>
<span
class="euiCodeBlock euiCodeBlock--light euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline testClass1 testClass2"
style="height:auto"
>
<span
class="euiCodeBlock__pre"
>
<code
aria-label="aria-label"
class="euiCodeBlock__code"
data-test-subj="test subject string"
/>
</span>
</span>
`;
10 changes: 0 additions & 10 deletions src/components/code/_code.scss

This file was deleted.

24 changes: 24 additions & 0 deletions src/components/code/_code_block.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.euiCodeBlock {
display: block;
overflow: auto;

.euiCodeBlock__pre {
display: block;
white-space: pre-wrap;
}

Expand Down Expand Up @@ -35,4 +37,26 @@
&.euiCodeBlock--paddingLarge {
padding: $euiSizeL;
}

/**
** 1. Size the code against the text its embedded within.
**/
&.euiCodeBlock--inline {
vertical-align: middle;
display: inline-block;
white-space: pre;
color: $euiTextColor;
font-size: 75%; // 1
padding: 0 $euiSizeXS;
background: $euiColorLightestShade;

.euiCodeBlock__pre, .euiCodeBlock__code {
display: inline;
white-space: normal;
}
}

&.euiCodeBlock--transparentBackground {
background: transparent;
}
}
1 change: 1 addition & 0 deletions src/components/code/_code_block_light.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove!

.euiCodeBlock--light {
background: #F5F5F5;
color: #3F3F3F;
Expand Down
1 change: 0 additions & 1 deletion src/components/code/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import 'code';
@import 'code_block';
@import 'code_block_dark';
@import 'code_block_light';
10 changes: 7 additions & 3 deletions src/components/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import {
EuiCodeBlock,
} from '../../components';

export const EuiCode = ({
children,
className,
...rest
}) => {
const classes = classNames('euiCode', className);
const classes = classNames('euiCodeBlock--inline', className);

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

Expand Down
20 changes: 13 additions & 7 deletions src/components/code/code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ export class EuiCodeBlock extends Component {
const {
children,
className,
language,
color,
fontSize,
paddingSize,
language,
overflowHeight,
paddingSize,
transparentBackground,
...otherProps
} = this.props;

Expand All @@ -64,6 +65,9 @@ export class EuiCodeBlock extends Component {
colorToClassNameMap[color],
fontSizeToClassNameMap[fontSize],
paddingSizeToClassNameMap[paddingSize],
{
'euiCodeBlock--transparentBackground': transparentBackground,
},
className
);

Expand All @@ -76,20 +80,20 @@ export class EuiCodeBlock extends Component {
}

return (
<div
<span
className={classes}
style={{ height: optionalOverflowHeight }}
>
<pre className="euiCodeBlock__pre">
<span className="euiCodeBlock__pre">
<code
ref={ref => { this.code = ref; }}
className={codeClasses}
{...otherProps}
>
{children}
</code>
</pre>
</div>
</span>
</span>
);
}

Expand All @@ -106,10 +110,12 @@ EuiCodeBlock.propTypes = {
color: PropTypes.string,
paddingSize: PropTypes.oneOf(PADDING_SIZES),
fontSize: PropTypes.oneOf(FONT_SIZES),
transparentBackground: PropTypes.bool,
};

EuiCodeBlock.defaultProps = {
color: 'dark',
color: 'light',
transparentBackground: false,
paddingSize: 'l',
fontSize: 's',
};