Skip to content

Commit c3706c4

Browse files
committed
Initial commit
0 parents  commit c3706c4

File tree

9 files changed

+5755
-0
lines changed

9 files changed

+5755
-0
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"react",
4+
"env",
5+
"stage-0"
6+
]
7+
}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Component lib directory
2+
lib
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
# Compiled binary addons (http://nodejs.org/api/addons.html)
30+
build/Release
31+
32+
# Dependency directories
33+
node_modules
34+
jspm_packages
35+
typings

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src
2+
demo
3+
.babelrc
4+
webpack.config.js

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
## Installation
3+
4+
```bash
5+
npm install text-editor-react
6+
```
7+
Include fontawesome cdn in your html for icons to work
8+
[https://fontawesome.com/](https://fontawesome.com/)
9+
10+
## Usage
11+
12+
### Simple Example
13+
```jsx
14+
import React from "react";
15+
import { TextEditor } from "text-editor-react";
16+
17+
function MyComponent() {
18+
const id = "my-unique-id";
19+
20+
return (
21+
<TextEditor
22+
id={id}
23+
/>
24+
);
25+
}
26+
```
27+
28+
### How to save content?
29+
30+
```jsx
31+
import React from "react";
32+
import { TextEditor, getInnerHtml } from "text-editor-react";
33+
34+
function MyComponent() {
35+
const id = "my-unique-id";
36+
37+
const saveContent = () => {
38+
const content = getInnerHtml(id);
39+
// This is the part where you save the content
40+
// to the database
41+
};
42+
43+
return (
44+
<div>
45+
<TextEditor
46+
id={id}
47+
/>
48+
<button onClick={saveContent}>Save</button>
49+
</div>
50+
);
51+
}
52+
```
53+
54+
### How to display content saved in database?
55+
56+
```jsx
57+
import React, { useEffect } from "react";
58+
import { addContentTo } from "text-editor-react";
59+
60+
function MyComponent() {
61+
const targetDiv = "target-div";
62+
63+
const content = `<p>Hello World!</p>`;
64+
65+
useEffect(() => {
66+
addContentTo(content, targetDiv);
67+
// Provide content and id of the div you want to
68+
// add the content to
69+
}, []);
70+
71+
return (
72+
<React.Fragment>
73+
<div id={targetDiv}></div>
74+
<button onClick={addContent}>Add Content</button>
75+
</React.Fragment>
76+
);
77+
}
78+
```

0 commit comments

Comments
 (0)