diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a2cc60453c..54ed2a2927e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src-docs/src/views/code/code.js b/src-docs/src/views/code/code.js index 43c935b84e9..9d33eafab4a 100644 --- a/src-docs/src/views/code/code.js +++ b/src-docs/src/views/code/code.js @@ -5,8 +5,22 @@ import { EuiText, } from '../../../../src/components'; +const htmlCode = ` +
+ asdf +
+`; + export default () => ( -

Sometimes you need to highlight code like this.

+

+ Sometimes you need to emphasize code like this. +

+

+ You can also pass a language in like {htmlCode.trim()}. +

+

+ Make the background transparent like this {htmlCode.trim()}. +

); diff --git a/src-docs/src/views/code/code_block.js b/src-docs/src/views/code/code_block.js index eead4e66392..4b8106caaca 100644 --- a/src-docs/src/views/code/code_block.js +++ b/src-docs/src/views/code/code_block.js @@ -21,8 +21,11 @@ export default () => ( - + {jsCode} + + + ); diff --git a/src-docs/src/views/code/code_example.js b/src-docs/src/views/code/code_example.js index 3af457c7a60..0bfe63e0022 100644 --- a/src-docs/src/views/code/code_example.js +++ b/src-docs/src/views/code/code_example.js @@ -33,7 +33,8 @@ export default props => ( }]} text={

- Description needed: how to use the Code component. + Code is for making inline code snippets that can work + within or next to bodies of text.

} demo={ @@ -62,6 +63,8 @@ export default props => (
  • paddingSize accepts "s" / "m" / "l" (default).
  • fontSize accepts "s" (default) / "m" / "l".
  • overflowHeight accepts a number. By default it is not set.
  • +
  • transparentBackground set to false will remove the background.
  • +
  • inline will display the passed code in an inline format. Will also remove any margins set.
  • } diff --git a/src/components/code/__snapshots__/code.test.js.snap b/src/components/code/__snapshots__/code.test.js.snap index 4538cce1c4b..829926c389b 100644 --- a/src/components/code/__snapshots__/code.test.js.snap +++ b/src/components/code/__snapshots__/code.test.js.snap @@ -1,9 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`EuiCode is rendered 1`] = ` - + + + + + `; diff --git a/src/components/code/_code.scss b/src/components/code/_code.scss deleted file mode 100644 index 3cb49d44773..00000000000 --- a/src/components/code/_code.scss +++ /dev/null @@ -1,10 +0,0 @@ -.euiCode { - @include euiCodeFont; - display: inline-block; - white-space: pre; - background: $euiColorLightestShade; - color: $euiColorAccent; - border: $euiBorderThin; - font-size: $euiFontSizeXS; - padding: 0 $euiSizeXS; -} diff --git a/src/components/code/_code_block.scss b/src/components/code/_code_block.scss index 1d588d406b1..377161b17d2 100644 --- a/src/components/code/_code_block.scss +++ b/src/components/code/_code_block.scss @@ -1,7 +1,9 @@ .euiCodeBlock { + display: block; overflow: auto; .euiCodeBlock__pre { + display: block; white-space: pre-wrap; } @@ -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; + } } diff --git a/src/components/code/_code_block_light.scss b/src/components/code/_code_block_light.scss index 392f94b63e6..e578c8f60a9 100644 --- a/src/components/code/_code_block_light.scss +++ b/src/components/code/_code_block_light.scss @@ -1,3 +1,4 @@ + .euiCodeBlock--light { background: #F5F5F5; color: #3F3F3F; diff --git a/src/components/code/_index.scss b/src/components/code/_index.scss index a893d614186..e3793b9f58c 100644 --- a/src/components/code/_index.scss +++ b/src/components/code/_index.scss @@ -1,4 +1,3 @@ -@import 'code'; @import 'code_block'; @import 'code_block_dark'; @import 'code_block_light'; diff --git a/src/components/code/code.js b/src/components/code/code.js index eae52f22f9d..127c6c4e284 100644 --- a/src/components/code/code.js +++ b/src/components/code/code.js @@ -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 ( - {children} - +
    ); }; diff --git a/src/components/code/code_block.js b/src/components/code/code_block.js index be6417ae8bf..40d2316a1f1 100644 --- a/src/components/code/code_block.js +++ b/src/components/code/code_block.js @@ -51,11 +51,12 @@ export class EuiCodeBlock extends Component { const { children, className, - language, color, fontSize, - paddingSize, + language, overflowHeight, + paddingSize, + transparentBackground, ...otherProps } = this.props; @@ -64,6 +65,9 @@ export class EuiCodeBlock extends Component { colorToClassNameMap[color], fontSizeToClassNameMap[fontSize], paddingSizeToClassNameMap[paddingSize], + { + 'euiCodeBlock--transparentBackground': transparentBackground, + }, className ); @@ -76,11 +80,11 @@ export class EuiCodeBlock extends Component { } return ( -
    -
    +        
                { this.code = ref; }}
                 className={codeClasses}
    @@ -88,8 +92,8 @@ export class EuiCodeBlock extends Component {
               >
                 {children}
               
    -        
    -
    + + ); } @@ -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', };