Skip to content

Commit 5a108c5

Browse files
author
Kirill Bolotsky
authored
feat: bash input signs are no more part of copy btn content (#161)
Side: - adjusted CodeGroup component similarly how it was done on blog to prevent buggy behavior - added $ signs to bash block on Installation page
1 parent cccd71e commit 5a108c5

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

src/components/shared/code/code-group.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import PropTypes from 'prop-types';
22
import React, { useState } from 'react';
3-
import { getRandomKey } from 'utils';
43

54
import Code from './code';
65
import styles from './code-group.module.scss';
76

87
const CodeGroup = ({ children, labels, lineNumbers, heightTogglers }) => {
98
const [currentIndex, setCurrentIndex] = useState(0);
10-
const randomKey = getRandomKey();
119
return (
1210
<div className={styles.wrapper}>
1311
<div className={styles.header}>
@@ -26,21 +24,18 @@ const CodeGroup = ({ children, labels, lineNumbers, heightTogglers }) => {
2624
</div>
2725
))}
2826
</div>
29-
<style>
30-
{`.${styles.itemsContainer}.${randomKey} > div:nth-child(${
31-
currentIndex + 1
32-
}) { display: block; }`}
33-
</style>
34-
<div className={`${styles.itemsContainer} ${randomKey}`}>
35-
{React.Children.map(children, (child, i) => (
36-
<Code
37-
showLineNumbers={lineNumbers[i]}
38-
key={i}
39-
showHeightToggler={heightTogglers[i]}
40-
>
41-
{child.props.children}
42-
</Code>
43-
))}
27+
<div className={`${styles.itemsContainer}`}>
28+
{React.Children.map(children, (child, i) =>
29+
i === currentIndex ? (
30+
<Code
31+
showLineNumbers={lineNumbers[i]}
32+
key={i}
33+
showHeightToggler={heightTogglers[i]}
34+
>
35+
{child.props.children}
36+
</Code>
37+
) : null,
38+
)}
4439
</div>
4540
</div>
4641
);

src/components/shared/code/code-group.module.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,3 @@
4444
.code-tab_active {
4545
color: #fff;
4646
}
47-
48-
.items-container {
49-
> div {
50-
display: none;
51-
}
52-
}

src/components/shared/code/code.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,20 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
6161
};
6262
}
6363

64+
const declaredLang = getLanguageDeclaration(children.props?.className);
65+
let copyBtnContent =
66+
children.props?.children ?? 'Sorry, nothing to copy here';
67+
68+
if (declaredLang === 'bash') {
69+
copyBtnContent = copyBtnContent.replace(/^\$\s/gm, '');
70+
}
71+
6472
return (
65-
<WithCopyButton dataToCopy={children.props?.children}>
73+
<WithCopyButton dataToCopy={copyBtnContent}>
6674
<Highlight
6775
{...defaultProps}
6876
code={children.props?.children}
69-
language={getLanguageDeclaration(children.props?.className)}
77+
language={declaredLang}
7078
>
7179
{({ className, tokens, getLineProps, getTokenProps }) => (
7280
<pre
@@ -84,12 +92,17 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
8492
<span className={styles.lineNumber}>{i + 1}</span>
8593
)}
8694
<span className={styles.lineContent}>
87-
{line.map((token, key) => (
88-
<span
89-
{...getTokenProps({ token, key })}
90-
style={undefined}
91-
/>
92-
))}
95+
{line.map((token, key) => {
96+
return (
97+
<span
98+
{...getTokenProps({
99+
token,
100+
key,
101+
})}
102+
style={undefined}
103+
/>
104+
);
105+
})}
93106
</span>
94107
</div>
95108
);

src/data/markdown/docs/01 guides/01 Getting started/02 Installation.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ title: 'Installation'
77
### Debian/Ubuntu
88

99
```bash
10-
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61
11-
echo "deb https://dl.bintray.com/loadimpact/deb stable main" | sudo tee -a /etc/apt/sources.list
12-
sudo apt-get update
13-
sudo apt-get install k6
10+
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61
11+
$ echo "deb https://dl.bintray.com/loadimpact/deb stable main" | sudo tee -a /etc/apt/sources.list
12+
$ sudo apt-get update
13+
$ sudo apt-get install k6
1414
```
1515

1616
> #### ⚠️ If you are behind a firewall or proxy
@@ -20,23 +20,23 @@ sudo apt-get install k6
2020
> alternative approach instead:
2121
>
2222
> ```bash
23-
> wget -q -O - https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
23+
> $ wget -q -O - https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
2424
> ```
2525
2626
### Red Hat/CentOS
2727
2828
```bash
29-
wget https://bintray.com/loadimpact/rpm/rpm -O bintray-loadimpact-rpm.repo
30-
sudo mv bintray-loadimpact-rpm.repo /etc/yum.repos.d/
31-
sudo yum install k6
29+
$ wget https://bintray.com/loadimpact/rpm/rpm -O bintray-loadimpact-rpm.repo
30+
$ sudo mv bintray-loadimpact-rpm.repo /etc/yum.repos.d/
31+
$ sudo yum install k6
3232
```
3333
3434
## Mac (brew)
3535

3636
<CodeGroup labels={['Brew']}>
3737

3838
```bash
39-
brew install k6
39+
$ brew install k6
4040
```
4141

4242
</CodeGroup>
@@ -55,7 +55,7 @@ Install the binary in your `PATH` to run **k6** from any location.
5555
<CodeGroup labels={['Docker']}>
5656

5757
```bash
58-
docker pull loadimpact/k6
58+
$ docker pull loadimpact/k6
5959
```
6060

6161
</CodeGroup>

0 commit comments

Comments
 (0)