Skip to content

Commit 90767af

Browse files
committed
feat: add copyCodeButton option
1 parent 4565254 commit 90767af

File tree

8 files changed

+103
-42
lines changed

8 files changed

+103
-42
lines changed

docs/Configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ module.exports = {
9090

9191
Your components will be able to invoke the URL `http://localhost:6060/custom-endpoint` from their examples.
9292

93+
## `copyCodeButton`
94+
95+
Type: `Boolean`, default: `false`
96+
97+
Adds a little button on the top right hand corner of the editor to copy the contents of the editor into the clipboard.
98+
9399
## `dangerouslyUpdateWebpackConfig`
94100

95101
Type: `Function`, optional

examples/customised/styleguide.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ module.exports = {
9999
usageMode: 'expand',
100100
exampleMode: 'expand',
101101
styleguideDir: 'dist',
102-
codeSplit: true
102+
codeSplit: true,
103+
editorConfig: {
104+
theme: 'night'
105+
}
103106
}

packages/vue-styleguidist/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@
8181
"react-dev-utils": "^7.0.3",
8282
"react-dom": "^16.4.1",
8383
"react-group": "^1.0.6",
84+
"react-icons": "^3.7.0",
8485
"react-lifecycles-compat": "^3.0.4",
8586
"react-simple-code-editor": "^0.9.4",
86-
"react-styleguidist": "^9.0.4",
87+
"react-styleguidist": "^9.1.13",
8788
"rewrite-imports": "^2.0.3",
8889
"style-loader": "^0.21.0",
8990
"terser": "^4.1.2",

packages/vue-styleguidist/scripts/make-webpack-config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ module.exports = function(config, env) {
206206
key = 'EditorString'
207207
}
208208

209+
// add codebutton if asked for
210+
if (config.copyCodeButton) {
211+
cc[key] = 'EditorWithToolbar'
212+
key = 'EditorNoTools'
213+
}
214+
209215
// if the user chose prism, load the prism editor instead of codemirror
210216
cc[key] = path.join('VsgEditor', config.simpleEditor ? 'EditorPrism' : 'Editor')
211217
}

packages/vue-styleguidist/scripts/schemas/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ module.exports = {
6363
configureServer: {
6464
type: 'function'
6565
},
66+
copyCodeButton: {
67+
type: 'boolean',
68+
message: 'Easily copy the code of the example',
69+
description:
70+
'Add a button on the top right of the code sections to copy to clipboard the current contents of the editor',
71+
default: false
72+
},
6673
dangerouslyUpdateWebpackConfig: {
6774
type: 'function'
6875
},
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* eslint-disable react/prop-types */
2+
import React from 'react'
3+
import copy from 'clipboard-copy'
4+
import { MdContentCopy } from 'react-icons/md'
5+
import Editor from 'rsg-components/EditorNoTools'
6+
import ToolbarButton from 'rsg-components/ToolbarButton'
7+
import Styled from 'rsg-components/Styled'
8+
9+
const styles = ({ space }) => ({
10+
container: {
11+
position: 'relative'
12+
},
13+
copyButton: {
14+
position: 'absolute',
15+
right: space[1],
16+
top: space[1],
17+
zIndex: 3,
18+
cursor: 'pointer'
19+
}
20+
})
21+
22+
function EditorWithToolbar(props) {
23+
const { classes } = props
24+
return (
25+
<div className={classes.container}>
26+
<ToolbarButton
27+
small
28+
className={classes.copyButton}
29+
onClick={() => copy(props.code)}
30+
title="Copy to clipboard"
31+
>
32+
<MdContentCopy />
33+
</ToolbarButton>
34+
<Editor {...props} />
35+
</div>
36+
)
37+
}
38+
39+
export default Styled(styles)(EditorWithToolbar)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './EditorWIthToolbar'

yarn.lock

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@
382382
esutils "^2.0.2"
383383
js-tokens "^4.0.0"
384384

385-
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.1.3", "@babel/parser@^7.2.3", "@babel/parser@^7.4.0", "@babel/parser@^7.4.3":
385+
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.2.3", "@babel/parser@^7.4.0", "@babel/parser@^7.4.3":
386386
version "7.4.3"
387387
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.3.tgz#eb3ac80f64aa101c907d4ce5406360fe75b7895b"
388388
integrity sha512-gxpEUhTS1sGA63EGQGuA+WESPR/6tz6ng7tSHFCmaTJK/cGK8y37cBTspX+U2xCAue2IQVvF6Z0oigmjwD8YGQ==
@@ -4165,11 +4165,6 @@ ast-types@0.11.5:
41654165
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.5.tgz#9890825d660c03c28339f315e9fa0a360e31ec28"
41664166
integrity sha512-oJjo+5e7/vEc2FBK8gUalV0pba4L3VdBIs2EKhOLHLcOd2FgQIVQN9xb0eZ9IjEWyAL7vq6fGJxOvVvdCHNyMw==
41674167

4168-
ast-types@0.11.7:
4169-
version "0.11.7"
4170-
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.7.tgz#f318bf44e339db6a320be0009ded64ec1471f46c"
4171-
integrity sha512-2mP3TwtkY/aTv5X3ZsMpNAbOnyoC/aMJwJSoaELPkHId0nSQgFcnU4dRW3isxiz7+zBexk0ym3WNVjMiQBnJSw==
4172-
41734168
ast-types@0.12.3, ast-types@^0.12.2:
41744169
version "0.12.3"
41754170
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.12.3.tgz#2299c6201d34b2a749a2dd9f2de7ef5f0e84f423"
@@ -7565,7 +7560,7 @@ doctrine@1.5.0:
75657560
esutils "^2.0.2"
75667561
isarray "^1.0.0"
75677562

7568-
doctrine@^2.0.0, doctrine@^2.1.0:
7563+
doctrine@^2.1.0:
75697564
version "2.1.0"
75707565
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
75717566
integrity sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==
@@ -8304,6 +8299,11 @@ estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0:
83048299
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"
83058300
integrity sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=
83068301

8302+
estree-walker@^0.6.0:
8303+
version "0.6.1"
8304+
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
8305+
integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==
8306+
83078307
esutils@^2.0.0, esutils@^2.0.2:
83088308
version "2.0.2"
83098309
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
@@ -15613,18 +15613,18 @@ react-docgen-displayname-handler@^2.1.1:
1561315613
dependencies:
1561415614
ast-types "0.11.5"
1561515615

15616-
react-docgen@3.0.0-rc.2:
15617-
version "3.0.0-rc.2"
15618-
resolved "https://registry.yarnpkg.com/react-docgen/-/react-docgen-3.0.0-rc.2.tgz#5939c64699fd9959da6d97d890f7b648e542dbcc"
15619-
integrity sha512-tXbIvq7Hxdc92jW570rztqsz0adtWEM5FX8bShJYozT2Y6L/LeHvBMQcED6mSqJ72niiNMPV8fi3S37OHrGMEw==
15616+
react-docgen@^4.1.0:
15617+
version "4.1.1"
15618+
resolved "https://registry.yarnpkg.com/react-docgen/-/react-docgen-4.1.1.tgz#8fef0212dbf14733e09edecef1de6b224d87219e"
15619+
integrity sha512-o1wdswIxbgJRI4pckskE7qumiFyqkbvCO++TylEDOo2RbMiueIOg8YzKU4X9++r0DjrbXePw/LHnh81GRBTWRw==
1562015620
dependencies:
15621-
"@babel/parser" "^7.1.3"
15621+
"@babel/core" "^7.0.0"
1562215622
"@babel/runtime" "^7.0.0"
1562315623
async "^2.1.4"
1562415624
commander "^2.19.0"
15625-
doctrine "^2.0.0"
15625+
doctrine "^3.0.0"
1562615626
node-dir "^0.1.10"
15627-
recast "^0.16.0"
15627+
recast "^0.17.3"
1562815628

1562915629
react-dom@^16.4.1, react-dom@^16.8.3:
1563015630
version "16.8.6"
@@ -15655,17 +15655,19 @@ react-group@^3.0.0:
1565515655
dependencies:
1565615656
prop-types "^15.6.2"
1565715657

15658-
react-icon-base@2.1.0:
15659-
version "2.1.0"
15660-
resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
15661-
integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
15658+
react-icons@^3.7.0:
15659+
version "3.7.0"
15660+
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-3.7.0.tgz#64fe46231fabfeea27895edeae6c3b78114b8c8f"
15661+
integrity sha512-7MyPwjIhuyW0D2N3s4DEd0hGPGFf0sK+IIRKhc1FvSpZNVmnUoGvHbmAwzGJU+3my+fvihVWgwU5SDtlAri56Q==
15662+
dependencies:
15663+
camelcase "^5.0.0"
1566215664

15663-
react-icons@^2.2.7:
15664-
version "2.2.7"
15665-
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"
15666-
integrity sha512-0n4lcGqzJFcIQLoQytLdJCE0DKSA9dkwEZRYoGrIDJZFvIT6Hbajx5mv9geqhqFiNjUgtxg8kPyDfjlhymbGFg==
15665+
react-icons@^3.7.0:
15666+
version "3.7.0"
15667+
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-3.7.0.tgz#64fe46231fabfeea27895edeae6c3b78114b8c8f"
15668+
integrity sha512-7MyPwjIhuyW0D2N3s4DEd0hGPGFf0sK+IIRKhc1FvSpZNVmnUoGvHbmAwzGJU+3my+fvihVWgwU5SDtlAri56Q==
1566715669
dependencies:
15668-
react-icon-base "2.1.0"
15670+
camelcase "^5.0.0"
1566915671

1567015672
react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
1567115673
version "16.8.6"
@@ -15682,10 +15684,10 @@ react-simple-code-editor@^0.9.4, react-simple-code-editor@^0.9.7:
1568215684
resolved "https://registry.yarnpkg.com/react-simple-code-editor/-/react-simple-code-editor-0.9.10.tgz#1ab5ea7215687ed918c6d0dae90736cf01890905"
1568315685
integrity sha512-80LJwRQS7Wi9Ugh/e6FRHWdcg4oQOpMBDFxyDpORILffrHdV3EIQ1IeX5x7488r05iFgLbVDV4nQ1LRKjgCm0g==
1568415686

15685-
react-styleguidist@^9.0.4:
15686-
version "9.0.8"
15687-
resolved "https://registry.yarnpkg.com/react-styleguidist/-/react-styleguidist-9.0.8.tgz#615057eac7a2cc88d13087f2d8c37037fdbce9cb"
15688-
integrity sha512-N3JEspClgUCNkj05X14G2aGLyDE9Izv1X8BFPjQR+oVo2AoUGLE92vsA3XYD26kmAChwfBUEja7b5IZV+91DTQ==
15687+
react-styleguidist@^9.1.13:
15688+
version "9.1.13"
15689+
resolved "https://registry.yarnpkg.com/react-styleguidist/-/react-styleguidist-9.1.13.tgz#a3aaaa04eac0bc0f4b15a421d1356f5a46cac877"
15690+
integrity sha512-HD5hpwmVrA9LcQHGBiRpbR6Mh6b4aUvaKe+k51wTIhmX7j6bcQzWQU//qoTnC5IFzXHr00r3rB5y/7qENw3xrQ==
1568915691
dependencies:
1569015692
"@vxna/mini-html-webpack-template" "^0.1.7"
1569115693
acorn "^6.1.1"
@@ -15702,6 +15704,7 @@ react-styleguidist@^9.0.4:
1570215704
es6-object-assign "~1.1.0"
1570315705
es6-promise "^4.2.6"
1570415706
escodegen "^1.11.1"
15707+
estree-walker "^0.6.0"
1570515708
findup "^0.1.5"
1570615709
function.name-polyfill "^1.0.6"
1570715710
github-slugger "^1.2.1"
@@ -15731,21 +15734,21 @@ react-styleguidist@^9.0.4:
1573115734
q-i "^2.0.1"
1573215735
qss "^2.0.3"
1573315736
react-dev-utils "^6.1.1"
15734-
react-docgen "3.0.0-rc.2"
15737+
react-docgen "^4.1.0"
1573515738
react-docgen-annotation-resolver "^1.0.0"
1573615739
react-docgen-displayname-handler "^2.1.1"
1573715740
react-group "^3.0.0"
15738-
react-icons "^2.2.7"
15741+
react-icons "^3.7.0"
1573915742
react-lifecycles-compat "^3.0.4"
1574015743
react-simple-code-editor "^0.9.7"
1574115744
recast "^0.17.4"
1574215745
remark "^10.0.1"
1574315746
rewrite-imports "1.2.0"
15747+
strip-html-comments "^1.0.0"
1574415748
terser-webpack-plugin "^1.2.3"
1574515749
to-ast "^1.0.0"
1574615750
type-detect "^4.0.8"
1574715751
unist-util-visit "^1.4.0"
15748-
walkes "^0.2.1"
1574915752
webpack-dev-server "^3.2.1"
1575015753
webpack-merge "^4.2.1"
1575115754

@@ -15957,16 +15960,6 @@ recast@^0.15.0:
1595715960
private "~0.1.5"
1595815961
source-map "~0.6.1"
1595915962

15960-
recast@^0.16.0:
15961-
version "0.16.2"
15962-
resolved "https://registry.yarnpkg.com/recast/-/recast-0.16.2.tgz#3796ebad5fe49ed85473b479cd6df554ad725dc2"
15963-
integrity sha512-O/7qXi51DPjRVdbrpNzoBQH5dnAPQNbfoOFyRiUwreTMJfIHYOEBzwuH+c0+/BTSJ3CQyKs6ILSWXhESH6Op3A==
15964-
dependencies:
15965-
ast-types "0.11.7"
15966-
esprima "~4.0.0"
15967-
private "~0.1.5"
15968-
source-map "~0.6.1"
15969-
1597015963
recast@^0.17.3, recast@^0.17.4, recast@^0.17.5:
1597115964
version "0.17.5"
1597215965
resolved "https://registry.yarnpkg.com/recast/-/recast-0.17.5.tgz#cbba5757867b34826dbea3fffcee6225ba2cee3d"
@@ -17545,6 +17538,11 @@ strip-eof@^1.0.0:
1754517538
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
1754617539
integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=
1754717540

17541+
strip-html-comments@^1.0.0:
17542+
version "1.0.0"
17543+
resolved "https://registry.yarnpkg.com/strip-html-comments/-/strip-html-comments-1.0.0.tgz#0ae7dff0300a6075a4c293fb6111b4cb1d0cb7b7"
17544+
integrity sha1-Cuff8DAKYHWkwpP7YRG0yx0Mt7c=
17545+
1754817546
strip-indent@^1.0.1:
1754917547
version "1.0.1"
1755017548
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"

0 commit comments

Comments
 (0)