Skip to content

Commit 20bcfba

Browse files
provide stories
1 parent 4ae8d4d commit 20bcfba

File tree

11 files changed

+7337
-261
lines changed

11 files changed

+7337
-261
lines changed

example/index.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<title>myPage</title>
5+
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
6+
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
7+
<script crossorigin src="https://unpkg.com/[email protected]/babel.min.js"></script>
8+
<script src="../dist/stringToReactComponent.umd.min.js"></script>
9+
10+
<body>
11+
12+
<div id="root"></div>
13+
14+
<script type="text/babel">
15+
const StringToReactComponent = window.StringToReactComponent;
16+
const Welcome = function Welcome(props) {
17+
18+
return (<StringToReactComponent>
19+
{`(props)=>{
20+
const {useState}=React;
21+
const [counter,setCounter]=useState(0);
22+
const increase=()=>{
23+
setCounter(counter+1);
24+
};
25+
return (<div>
26+
<button onClick={increase}>+</button>
27+
<span>{'counter : '+ counter}</span>
28+
</div>);
29+
}`}
30+
</StringToReactComponent>);
31+
};
32+
33+
ReactDOM.render(<Welcome />, document.getElementById('root'));
34+
</script>
35+
36+
</body>
37+
38+
</html>

example/stories/data-prop/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
### Passing useState
2+
3+
```jsx
4+
import {useState} from 'react';
5+
import StringToReactComponent from 'string-to-react-component';
6+
7+
function App() {
8+
return (
9+
<StringToReactComponent data={{useState}}>
10+
{`(props)=>{
11+
const [counter,setCounter]=props.useState(0);
12+
const increase=()=>{
13+
setCounter(counter+1);
14+
};
15+
return (<>
16+
<button onClick={increase}>+</button>
17+
<span style={{padding:'0px 10px'}}>{'count : '+ counter}</span>
18+
</>);
19+
}`}
20+
</StringToReactComponent>
21+
);
22+
}
23+
<App />;
24+
```
25+
26+
### Passing Unknown Elements
27+
28+
```jsx
29+
import StringToReactComponent from 'string-to-react-component';
30+
31+
function MyFirstComponent() {
32+
return <p>This is my first component.</p>;
33+
}
34+
function MySecondComponent() {
35+
return <p>This is my second component.</p>;
36+
}
37+
38+
function App() {
39+
return (
40+
<StringToReactComponent data={{MyFirstComponent, MySecondComponent}}>
41+
{`(props)=>{
42+
const {MyFirstComponent, MySecondComponent}=props;
43+
return (<>
44+
<MyFirstComponent/>
45+
<MySecondComponent/>
46+
</>);
47+
}`}
48+
</StringToReactComponent>
49+
);
50+
}
51+
<App />;
52+
```

example/stories/source-map/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```jsx
2+
import StringToReactComponent from 'string-to-react-component';
3+
4+
function App() {
5+
return (
6+
<StringToReactComponent babelOptions={{filename: 'counter.js', sourceMaps: 'inline'}}>
7+
{`(props)=>{
8+
const {useState}=React;
9+
const [counter,setCounter]=useState(0);
10+
const increase=()=>{
11+
setCounter(counter+1);
12+
};
13+
return (<>
14+
<button onClick={increase}>+</button>
15+
<span style={{padding:'0px 10px'}}>{'count : '+ counter}</span>
16+
</>);
17+
}`}
18+
</StringToReactComponent>
19+
);
20+
}
21+
<App />;
22+
```

example/stories/styles.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pre > span.token.tag:nth-last-child(3),
2+
pre > span.token.punctuation:nth-last-child(2) {
3+
display: none;
4+
}
5+
main > footer {
6+
display: none !important;
7+
}

example/stories/typescript/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```jsx
2+
import StringToReactComponent from 'string-to-react-component';
3+
4+
function App() {
5+
return (
6+
<StringToReactComponent
7+
babelOptions={{filename: 'counter.ts', presets: [['typescript', {allExtensions: true, isTSX: true}]]}}>
8+
{`()=>{
9+
const [counter,setCounter]=React.useState<number>(0);
10+
const increase=()=>{
11+
setCounter(counter+1);
12+
};
13+
return (<>
14+
<button onClick={increase}>+</button>
15+
<span style={{padding:'0px 10px'}}>{'count : '+ counter}</span>
16+
</>);
17+
}`}
18+
</StringToReactComponent>
19+
);
20+
}
21+
<App />;
22+
```

example/stories/usage/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```jsx
2+
import StringToReactComponent from 'string-to-react-component';
3+
function App() {
4+
return (
5+
<StringToReactComponent>
6+
{`(props)=>{
7+
const {useState}=React; // React can be used as a global variable
8+
const [counter,setCounter]=useState(0);
9+
const increase=()=>{
10+
setCounter(counter+1);
11+
};
12+
return (<>
13+
<button onClick={increase}>+</button>
14+
<span style={{padding:'0px 10px'}}>{'count : '+ counter}</span>
15+
</>);
16+
}`}
17+
</StringToReactComponent>
18+
);
19+
}
20+
<App />;
21+
```

0 commit comments

Comments
 (0)