Polish/code snippets (#12302)

* Refactor CopyText component into CodeSnippet component

* Update instances of code snippet

* Force code snippet contents to wrap

* Update changelog
pull/12304/head
alexpaxton 2019-03-01 12:33:37 -08:00 committed by GitHub
parent 290d06f98f
commit 86f5753b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 166 additions and 80 deletions

View File

@ -6,8 +6,10 @@
### Bug Fixes ### Bug Fixes
1. [12302](https://github.com/influxdata/influxdb/pull/12302): Prevent clipping of code snippets in Firefox
### UI Improvements ### UI Improvements
1. [12302](https://github.com/influxdata/influxdb/pull/12302): Make code snippet copy functionality easier to use
## v2.0.0-alpha.4 [2019-02-21] ## v2.0.0-alpha.4 [2019-02-21]
### Features ### Features

View File

@ -6,7 +6,7 @@ import _ from 'lodash'
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
// Components // Components
import CopyText from 'src/shared/components/CopyText' import CodeSnippet from 'src/shared/components/CodeSnippet'
// Types // Types
import {NotificationAction} from 'src/types' import {NotificationAction} from 'src/types'
@ -45,13 +45,13 @@ class TelegrafInstructions extends PureComponent<Props> {
copy the following command to your terminal window to set an copy the following command to your terminal window to set an
environment variable with your token. environment variable with your token.
</p> </p>
<CopyText copyText={exportToken} notify={notify} /> <CodeSnippet copyText={exportToken} notify={notify} label="CLI" />
<h6>3. Start Telegraf</h6> <h6>3. Start Telegraf</h6>
<p> <p>
Finally, you can run the following command the start Telegraf agent Finally, you can run the following command the start Telegraf agent
running on your machine. running on your machine.
</p> </p>
<CopyText copyText={configScript} notify={notify} /> <CodeSnippet copyText={configScript} notify={notify} label="CLI" />
</div> </div>
) )
} }

View File

@ -25,8 +25,9 @@ exports[`TelegrafInstructions matches snapshot 1`] = `
<p> <p>
Your API token is required for pushing data into InfluxDB. You can copy the following command to your terminal window to set an environment variable with your token. Your API token is required for pushing data into InfluxDB. You can copy the following command to your terminal window to set an environment variable with your token.
</p> </p>
<CopyText <CodeSnippet
copyText="export INFLUX_TOKEN=" copyText="export INFLUX_TOKEN="
label="CLI"
notify={[MockFunction]} notify={[MockFunction]}
/> />
<h6> <h6>
@ -35,8 +36,9 @@ exports[`TelegrafInstructions matches snapshot 1`] = `
<p> <p>
Finally, you can run the following command the start Telegraf agent running on your machine. Finally, you can run the following command the start Telegraf agent running on your machine.
</p> </p>
<CopyText <CodeSnippet
copyText="telegraf -config http://localhost:9999/api/v2/telegrafs/" copyText="telegraf -config http://localhost:9999/api/v2/telegrafs/"
label="CLI"
notify={[MockFunction]} notify={[MockFunction]}
/> />
</div> </div>

View File

@ -7,7 +7,7 @@ import PermissionsWidget, {
PermissionsWidgetMode, PermissionsWidgetMode,
PermissionsWidgetSelection, PermissionsWidgetSelection,
} from 'src/shared/components/permissionsWidget/PermissionsWidget' } from 'src/shared/components/permissionsWidget/PermissionsWidget'
import CopyText from 'src/shared/components/CopyText' import CodeSnippet from 'src/shared/components/CodeSnippet'
// Types // Types
import {Authorization, Permission} from '@influxdata/influx' import {Authorization, Permission} from '@influxdata/influx'
@ -43,7 +43,7 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
<OverlayContainer> <OverlayContainer>
<OverlayHeading title={description} onDismiss={this.handleDismiss} /> <OverlayHeading title={description} onDismiss={this.handleDismiss} />
<OverlayBody> <OverlayBody>
<CopyText copyText={this.props.auth.token} notify={onNotify} /> <CodeSnippet copyText={this.props.auth.token} notify={onNotify} />
<PermissionsWidget <PermissionsWidget
mode={PermissionsWidgetMode.Read} mode={PermissionsWidgetMode.Read}
heightPixels={500} heightPixels={500}

View File

@ -66,15 +66,17 @@ exports[`Account rendering renders! 1`] = `
<div <div
className="overlay--body" className="overlay--body"
> >
<CopyText <CodeSnippet
copyText="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA==" copyText="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
label="Code Snippet"
> >
<div <div
className="script-snippet--container" className="code-snippet"
> >
<FancyScrollbar <FancyScrollbar
autoHeight={true} autoHeight={true}
autoHide={false} autoHide={false}
className="code-snippet--scroll"
hideTracksWhenNotNeeded={true} hideTracksWhenNotNeeded={true}
maxHeight={400} maxHeight={400}
setScrollTop={[Function]} setScrollTop={[Function]}
@ -87,7 +89,7 @@ exports[`Account rendering renders! 1`] = `
autoHide={false} autoHide={false}
autoHideDuration={250} autoHideDuration={250}
autoHideTimeout={1000} autoHideTimeout={1000}
className="fancy-scroll--container" className="fancy-scroll--container code-snippet--scroll"
hideTracksWhenNotNeeded={true} hideTracksWhenNotNeeded={true}
onScroll={[Function]} onScroll={[Function]}
style={Object {}} style={Object {}}
@ -98,7 +100,7 @@ exports[`Account rendering renders! 1`] = `
universal={false} universal={false}
> >
<div <div
className="fancy-scroll--container" className="fancy-scroll--container code-snippet--scroll"
style={ style={
Object { Object {
"height": "auto", "height": "auto",
@ -129,9 +131,15 @@ exports[`Account rendering renders! 1`] = `
} }
} }
> >
<p> <div
ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA== className="code-snippet--text"
</p> >
<pre>
<code>
ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA==
</code>
</pre>
</div>
</div> </div>
<div <div
className="fancy-scroll--track-h" className="fancy-scroll--track-h"
@ -192,38 +200,46 @@ exports[`Account rendering renders! 1`] = `
</div> </div>
</Scrollbars> </Scrollbars>
</FancyScrollbar> </FancyScrollbar>
<CopyToClipboard <div
onCopy={[Function]} className="code-snippet--footer"
text="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
> >
<t <CopyToClipboard
active={false} onCopy={[Function]}
color="default" text="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
customClass="copy-button"
onClick={[Function]}
shape="none"
size="sm"
status="default"
testID="button"
text="Copy"
titleText="copy to clipboard"
type="button"
> >
<button <t
className="button button-sm button-default copy-button" active={false}
data-testid="button" color="secondary"
disabled={false}
onClick={[Function]} onClick={[Function]}
tabIndex={0} shape="none"
title="copy to clipboard" size="xs"
status="default"
testID="button"
text="Copy to Clipboard"
titleText="Copy to Clipboard"
type="button" type="button"
> >
Copy <button
</button> className="button button-xs button-secondary"
</t> data-testid="button"
</CopyToClipboard> disabled={false}
onClick={[Function]}
tabIndex={0}
title="Copy to Clipboard"
type="button"
>
Copy to Clipboard
</button>
</t>
</CopyToClipboard>
<label
className="code-snippet--label"
>
Code Snippet
</label>
</div>
</div> </div>
</CopyText> </CodeSnippet>
<PermissionsWidget <PermissionsWidget
heightPixels={500} heightPixels={500}
mode="read" mode="read"

View File

@ -0,0 +1,65 @@
@import 'src/style/modules';
/*
Code Snippet Widget
------------------------------------------------------------------------------
*/
.code-snippet {
margin: $ix-marg-a 0;
border-radius: $ix-radius;
overflow: hidden;
}
.code-snippet--scroll {
min-height: 26px !important;
background-color: $g4-onyx;
}
.code-snippet--text {
font-size: 13px;
line-height: 20px;
color: $c-potassium;
font-weight: 600;
font-family: $code-font;
padding: $ix-marg-a $ix-marg-c;
pre {
display: inline-block;
white-space: pre-wrap;
}
pre,
code {
word-wrap: break-word;
word-break: break-all;
}
}
.code-snippet--footer {
background-color: rgba($g4-onyx, 0.5);
display: flex;
border-top: $ix-border solid $g5-pepper;
align-items: center;
justify-content: space-between;
padding: $ix-marg-b $ix-marg-c;
}
.code-snippet--label {
font-size: $ix-text-base;
color: $g11-sidewalk;
margin: 0;
}
.copy-button {
position: absolute;
right: $ix-marg-b;
top: calc(50% - 15px);
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
.script-snippet--container:hover {
.copy-button {
opacity: 1;
}
}

View File

@ -17,30 +17,54 @@ import {
copyToClipboardFailed, copyToClipboardFailed,
} from 'src/shared/copy/notifications' } from 'src/shared/copy/notifications'
export interface Props { // Styles
import 'src/shared/components/CodeSnippet.scss'
export interface PassedProps {
copyText: string copyText: string
notify: NotificationAction notify: NotificationAction
} }
interface DefaultProps {
label?: string
}
type Props = PassedProps & DefaultProps
@ErrorHandling @ErrorHandling
class CopyText extends PureComponent<Props> { class CodeSnippet extends PureComponent<Props> {
public static defaultProps: DefaultProps = {
label: 'Code Snippet',
}
public render() { public render() {
const {copyText} = this.props const {copyText, label} = this.props
return ( return (
<div className="script-snippet--container"> <div className="code-snippet">
<FancyScrollbar autoHide={false} autoHeight={true} maxHeight={400}> <FancyScrollbar
<p>{copyText}</p> autoHide={false}
autoHeight={true}
maxHeight={400}
className="code-snippet--scroll"
>
<div className="code-snippet--text">
<pre>
<code>{copyText}</code>
</pre>
</div>
</FancyScrollbar> </FancyScrollbar>
<CopyToClipboard text={copyText} onCopy={this.handleCopyAttempt}> <div className="code-snippet--footer">
<Button <CopyToClipboard text={copyText} onCopy={this.handleCopyAttempt}>
customClass="copy-button" <Button
size={ComponentSize.Small} size={ComponentSize.ExtraSmall}
color={ComponentColor.Default} color={ComponentColor.Secondary}
titleText="copy to clipboard" titleText="Copy to Clipboard"
text="Copy" text="Copy to Clipboard"
onClick={this.handleClickCopy} onClick={this.handleClickCopy}
/> />
</CopyToClipboard> </CopyToClipboard>
<label className="code-snippet--label">{label}</label>
</div>
</div> </div>
) )
} }
@ -67,4 +91,4 @@ class CopyText extends PureComponent<Props> {
} }
} }
export default CopyText export default CodeSnippet

View File

@ -1,22 +0,0 @@
.script-snippet--container {
position: relative;
margin: $ix-marg-a 0;
padding: $ix-marg-a $ix-marg-c;
font-family: 'RobotoMono', monospace;
background-color: $g4-onyx;
border-radius: $ix-radius;
}
.copy-button {
position: absolute;
right: $ix-marg-b;
top: calc(50% - 15px);
opacity: 0;
transition: opacity .2s ease-in-out;
}
.script-snippet--container:hover {
.copy-button {
opacity: 1;
}
}

View File

@ -31,7 +31,6 @@
@import 'src/shared/components/custom_singular_time/CustomSingularTime'; @import 'src/shared/components/custom_singular_time/CustomSingularTime';
@import 'src/onboarding/OnboardingWizard.scss'; @import 'src/onboarding/OnboardingWizard.scss';
@import 'src/shared/components/columns_options/ColumnsOptions'; @import 'src/shared/components/columns_options/ColumnsOptions';
@import 'src/shared/components/CopyText';
// External // External
@import '../../node_modules/@influxdata/react-custom-scrollbars/dist/styles.css'; @import '../../node_modules/@influxdata/react-custom-scrollbars/dist/styles.css';