Skip to content

Commit 7918344

Browse files
committed
added react snippets
1 parent ff103d0 commit 7918344

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

packages/react-snippets/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `@wpmudev/react-snippets`
2+
3+
> TODO: description
4+
5+
## Usage
6+
7+
```
8+
const reactSnippets = require('@wpmudev/react-snippets');
9+
10+
// TODO: DEMONSTRATE API
11+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const reactSnippets = require('..');
4+
5+
describe('@wpmudev/react-snippets', () => {
6+
it('needs tests');
7+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react";
2+
import { Snippets } from "../lib/react-snippets";
3+
4+
export default {
5+
title: "Components/Snippets"
6+
};
7+
8+
const Template = ({ ...props }) => {
9+
return <Snippets {...props} />;
10+
};
11+
12+
export const primary = Template.bind({});
13+
primary.storyName = "Default";
14+
primary.args = {
15+
content: `<IfModule mod_rewrite.c>
16+
RewriteEngine On
17+
RewriteBase /
18+
RewriteRule ^index\\.php$ - [L]
19+
RewriteCond %{REQUEST_FILENAME} !-f
20+
RewriteCond %{REQUEST_FILENAME} !-d
21+
RewriteRule . /index.php [L]
22+
</IfModule>`,
23+
copy: true
24+
};
25+
26+
export const secondary = Template.bind({});
27+
secondary.storyName = "No-Copy Button";
28+
secondary.args = {
29+
...primary.args,
30+
copy: false
31+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useState } from "react";
2+
import { useCopyToClipboard } from "@wordpress/compose";
3+
4+
const CopyToClipboard = htmlCode => {
5+
const [hasCopied, setHasCopied] = useState(false);
6+
const CopyToClipboardRef = useCopyToClipboard(htmlCode, () => {
7+
setHasCopied(true);
8+
});
9+
10+
return (
11+
<button
12+
className={hasCopied ? "sui-button sui-tooltip" : "sui-button"}
13+
aria-label={hasCopied ? "Copied!" : ""}
14+
data-tooltip={hasCopied ? "Copied!" : ""}
15+
onMouseLeave={() => setHasCopied(false)}
16+
ref={CopyToClipboardRef}
17+
data-clipboard-target="">
18+
Copy
19+
</button>
20+
);
21+
};
22+
23+
const Snippets = ({ copy, content }) => {
24+
const htmlCode = content;
25+
26+
return (
27+
<div className="sui-code-snippet-wrapper">
28+
<pre className="sui-code-snippet">{htmlCode}</pre>
29+
{copy && CopyToClipboard(htmlCode)}
30+
</div>
31+
);
32+
};
33+
34+
export { Snippets };

packages/react-snippets/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@wpmudev/react-snippets",
3+
"version": "1.0.0",
4+
"description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
5+
"keywords": [],
6+
"author": "Pawan Kumar <[email protected]>",
7+
"license": "ISC",
8+
"main": "lib/react-snippets.js",
9+
"directories": {
10+
"lib": "lib",
11+
"test": "__tests__"
12+
},
13+
"files": [
14+
"lib"
15+
],
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/creador-dev/shared-ui-react.git"
22+
},
23+
"scripts": {
24+
"test": "echo \"Error: run tests from root\" && exit 1"
25+
},
26+
"bugs": {
27+
"url": "https://github.com/creador-dev/shared-ui-react/issues"
28+
},
29+
"homepage": "https://github.com/creador-dev/shared-ui-react#readme",
30+
"dependencies": {
31+
"@wordpress/compose": "^5.0.7"
32+
}
33+
}

0 commit comments

Comments
 (0)