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 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- Changed the hover states of `EuiButtonEmpty` to look more like links.
- Added `inline` and `transparentBackground` props to `EuiCodeBlock`. Made light theme the default.
Copy link
Contributor

@bevacqua bevacqua Nov 10, 2017

Choose a reason for hiding this comment

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

Team light theme wins! Can I get a link to the PR at the end of this line? Same ask as in the other PR:

- Added `inline` and `transparentBackground` props to `<EuiCodeBlock>`. [(#138)](https://github.com/elastic/eui/pull/138)
- The default `<EuiCodeBlock>` `theme` prop value is now `light`. [(#138)](https://github.com/elastic/eui/pull/138)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I specifically didn't add them because your example docs didn't have them 🗡

Copy link
Contributor

Choose a reason for hiding this comment

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

I shall fix that


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

Expand Down
13 changes: 12 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,19 @@ 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>
{/* You should probably vertically align your content against the code block for centering. */}
<span style={{ verticalAlign: 'middle'}}>Inline code with a transparent background: </span>
<EuiCodeBlock language="html" fontSize="m" inline transparentBackground>
{htmlCode}
</EuiCodeBlock>
</div>

</div>
);
2 changes: 2 additions & 0 deletions src-docs/src/views/code/code_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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
16 changes: 16 additions & 0 deletions src/components/code/_code_block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@
&.euiCodeBlock--paddingLarge {
padding: $euiSizeL;
}

&.euiCodeBlock--inline {
display: inline;
padding: 0;
background: transparent;
vertical-align: middle;

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

Expand All @@ -64,6 +66,12 @@ export class EuiCodeBlock extends Component {
colorToClassNameMap[color],
fontSizeToClassNameMap[fontSize],
paddingSizeToClassNameMap[paddingSize],
{
'euiCodeBlock--transparentBackground': transparentBackground,
},
{
'euiCodeBlock--inline': inline,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Loving this. I think the transparentBackground default should be smart: if it's not set, can we use inline === true instead?

That'd be:

{
  'euiCodeBlock--inline': inline,
  'euiCodeBlock--transparentBackground': typeof transparentBackground === 'boolean'
    ? transparentBackground
    : inline,
}

className
);

Expand Down Expand Up @@ -109,7 +117,8 @@ EuiCodeBlock.propTypes = {
};

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