Skip to content

Commit 72329a1

Browse files
committed
0.0.7 update + Fragment added + code refactored
1 parent 1f08c3e commit 72329a1

20 files changed

+5021
-3056
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export default withTemplating(MyComponent);
3232
- Use Wrapper HTML tags
3333

3434
```jsx
35-
import { Div, P, Button, Br, Span } from 'react-jsx-templating'; // Note: named import. There are total 118 Elements
35+
// Note: named import. There are total 118 Elements
36+
import { Fragment, Div, P, Button, Br, Span } from 'react-jsx-templating';
3637
```
3738

3839
## Syntax
@@ -98,7 +99,7 @@ function ExampleSwitchCase() {
9899

99100
```jsx
100101
import React, { Component } from 'react';
101-
import { Div, P, Button, Br } from 'react-jsx-templating';
102+
import { Div, Fragment, Button, Br } from 'react-jsx-templating';
102103
import { EnglishNewsPaper, SpanishNewsPaper } from './Components';
103104

104105
class ExampleIfElse extends Component {
@@ -114,9 +115,9 @@ class ExampleIfElse extends Component {
114115
const { isEngLang } = this.state;
115116
return (
116117
<div>
117-
<P $if={isEngLang} $else={<p>Hola!</p>}>
118+
<Fragment $if={isEngLang} $else={<>Hola!</>}>
118119
Hello!
119-
</P>
120+
</Fragment>
120121
<EnglishNewsPaper $if={isEngLang} $else={SpanishNewsPaper} />
121122
<Button onClick={this.toogleLanguage}>Toggle Language</Button>
122123
</div>
@@ -145,6 +146,7 @@ function ExampleForLoop() {
145146

146147
- ~~Switch Case~~ (added)
147148
- ~~Loop~~ (added)
149+
- ~~Fragment~~ (added)
148150

149151
## License
150152

example/package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
"prop-types": "^15.6.2",
99
"react": "^16.4.1",
1010
"react-dom": "^16.4.1",
11-
"react-scripts": "^1.1.4",
12-
"react-jsx-templating": "link:.."
11+
"react-jsx-templating": "link:..",
12+
"react-scripts": "^2.1.8"
1313
},
1414
"scripts": {
1515
"start": "react-scripts start",
1616
"build": "react-scripts build",
1717
"test": "react-scripts test --env=jsdom",
1818
"eject": "react-scripts eject"
19-
}
19+
},
20+
"browserslist": [
21+
">0.2%",
22+
"not dead",
23+
"not ie <= 11",
24+
"not op_mini all"
25+
]
2026
}

example/src/components/IfElse.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22

3-
import { Div, P, Button, Br, Span } from 'react-jsx-templating';
3+
import { Div, P, Button, Br, Fragment } from 'react-jsx-templating';
44
import MySomeComponent from './Helper/MySomeComponent';
55

66
function IfElse() {
@@ -15,9 +15,9 @@ function IfElse() {
1515
Welcome here
1616
</MySomeComponent>
1717
<Button onClick={() => setShowToggler(v => !v)}>
18-
<Span $if={!showToggler} $else={<Span>Hide Toggler</Span>}>
18+
<Fragment $if={!showToggler} $else={<>Hide Toggler</>}>
1919
Show Toggler
20-
</Span>
20+
</Fragment>
2121
</Button>
2222
<Br $if={showToggler} />
2323
<Button $if={showToggler} onClick={() => setShow(v => !v)}>

example/yarn.lock

+4,777-2,813
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-jsx-templating",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "React Jsx Templating, inspired by Angular :)",
55
"author": "ritwickdey",
66
"license": "MIT",

src/__test__/.gitkeep

Whitespace-only changes.

src/index.js

+1-122
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,4 @@
11
import withTemplating from './lib/withTemplating';
2-
import Elements from './lib/Elements';
2+
export * from './lib/Elements';
33

44
export default withTemplating;
5-
6-
export const {
7-
A,
8-
Abbr,
9-
Address,
10-
Area,
11-
Article,
12-
Aside,
13-
Audio,
14-
B,
15-
Base,
16-
Bdi,
17-
Bdo,
18-
Blockquote,
19-
Body,
20-
Br,
21-
Button,
22-
Canvas,
23-
Caption,
24-
Cite,
25-
Code,
26-
Col,
27-
Colgroup,
28-
Data,
29-
Datalist,
30-
Dd,
31-
Del,
32-
Details,
33-
Dfn,
34-
Dialog,
35-
Div,
36-
Dl,
37-
Dt,
38-
Em,
39-
Embed,
40-
Fieldset,
41-
Figcaption,
42-
Figure,
43-
Footer,
44-
Form,
45-
H1,
46-
H2,
47-
H3,
48-
H4,
49-
H5,
50-
H6,
51-
Head,
52-
Header,
53-
Hgroup,
54-
Hr,
55-
Html,
56-
I,
57-
Iframe,
58-
Img,
59-
Input,
60-
Ins,
61-
Kbd,
62-
Keygen,
63-
Label,
64-
Legend,
65-
Li,
66-
Link,
67-
Main,
68-
Map,
69-
Mark,
70-
Math,
71-
Menu,
72-
Menuitem,
73-
Meta,
74-
Meter,
75-
Nav,
76-
Noscript,
77-
Object,
78-
Ol,
79-
Optgroup,
80-
Option,
81-
Output,
82-
P,
83-
Param,
84-
Picture,
85-
Pre,
86-
Progress,
87-
Q,
88-
Rb,
89-
Rp,
90-
Rt,
91-
Rtc,
92-
Ruby,
93-
S,
94-
Samp,
95-
Script,
96-
Section,
97-
Select,
98-
Slot,
99-
Small,
100-
Source,
101-
Span,
102-
Strong,
103-
Style,
104-
Sub,
105-
Summary,
106-
Sup,
107-
Svg,
108-
Table,
109-
Tbody,
110-
Td,
111-
Template,
112-
Textarea,
113-
Tfoot,
114-
Th,
115-
Thead,
116-
Time,
117-
Title,
118-
Tr,
119-
Track,
120-
U,
121-
Ul,
122-
Var,
123-
Video,
124-
wbr
125-
} = Elements;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
2-
import { HTML_TAGS } from './html-tags';
3-
import withTemplating from './withTemplating';
2+
import { HTML_TAGS } from '../utils/html-tags';
3+
import withTemplating from '../withTemplating';
44

5-
export const Elements = {};
5+
const DOMElements = {};
66

77
HTML_TAGS.forEach(tag => {
88
const Fn = props => {
@@ -11,11 +11,11 @@ HTML_TAGS.forEach(tag => {
1111
};
1212
const Tag = capitalCase(tag);
1313
Fn.displayName = Tag;
14-
Elements[Tag] = withTemplating(Fn);
14+
DOMElements[Tag] = withTemplating(Fn);
1515
});
1616

1717
function capitalCase(str) {
1818
return str.charAt(0).toUpperCase() + str.slice(1);
1919
}
2020

21-
export default { ...Elements };
21+
export default DOMElements;

src/lib/Elements/Fragment.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import withTemplating from "../withTemplating";
2+
3+
const Fragment = ({ children }) => {
4+
return children;
5+
};
6+
7+
export default withTemplating(Fragment);

src/lib/Elements/index.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import DOMElements from './DOMElements';
2+
export { default as Fragment } from './Fragment';
3+
4+
export const {
5+
A,
6+
Abbr,
7+
Address,
8+
Area,
9+
Article,
10+
Aside,
11+
Audio,
12+
B,
13+
Base,
14+
Bdi,
15+
Bdo,
16+
Blockquote,
17+
Body,
18+
Br,
19+
Button,
20+
Canvas,
21+
Caption,
22+
Cite,
23+
Code,
24+
Col,
25+
Colgroup,
26+
Data,
27+
Datalist,
28+
Dd,
29+
Del,
30+
Details,
31+
Dfn,
32+
Dialog,
33+
Div,
34+
Dl,
35+
Dt,
36+
Em,
37+
Embed,
38+
Fieldset,
39+
Figcaption,
40+
Figure,
41+
Footer,
42+
Form,
43+
H1,
44+
H2,
45+
H3,
46+
H4,
47+
H5,
48+
H6,
49+
Head,
50+
Header,
51+
Hgroup,
52+
Hr,
53+
Html,
54+
I,
55+
Iframe,
56+
Img,
57+
Input,
58+
Ins,
59+
Kbd,
60+
Keygen,
61+
Label,
62+
Legend,
63+
Li,
64+
Link,
65+
Main,
66+
Map,
67+
Mark,
68+
Math,
69+
Menu,
70+
Menuitem,
71+
Meta,
72+
Meter,
73+
Nav,
74+
Noscript,
75+
Object,
76+
Ol,
77+
Optgroup,
78+
Option,
79+
Output,
80+
P,
81+
Param,
82+
Picture,
83+
Pre,
84+
Progress,
85+
Q,
86+
Rb,
87+
Rp,
88+
Rt,
89+
Rtc,
90+
Ruby,
91+
S,
92+
Samp,
93+
Script,
94+
Section,
95+
Select,
96+
Slot,
97+
Small,
98+
Source,
99+
Span,
100+
Strong,
101+
Style,
102+
Sub,
103+
Summary,
104+
Sup,
105+
Svg,
106+
Table,
107+
Tbody,
108+
Td,
109+
Template,
110+
Textarea,
111+
Tfoot,
112+
Th,
113+
Thead,
114+
Time,
115+
Title,
116+
Tr,
117+
Track,
118+
U,
119+
Ul,
120+
Var,
121+
Video,
122+
wbr
123+
} = DOMElements;

src/lib/helpers/doIfElseOperation.js renamed to src/lib/helperFns/doIfElseOperation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { isTrusy } from './utils';
2+
import { isTrusy } from '../utils';
33

44
export function doIfElseOperation(props, Component) {
55
const { $if: condition, $else: elseBlock, ...restProps } = props;

src/lib/helpers/doSwitchCaseOperation.js renamed to src/lib/helperFns/doSwitchCaseOperation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { isTrusy, isUndefined } from './utils';
2+
import { isTrusy, isUndefined } from '../utils';
33

44
export function doSwitchCaseOperation(props, Component) {
55
const { $switch: switchValue, children, ...restProps } = props;

src/lib/helperFns/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { doIfElseOperation } from './doIfElseOperation';
2+
export { doSwitchCaseOperation } from './doSwitchCaseOperation';
3+
export { doForLoopOperation } from './doForLoopOperation';
File renamed without changes.

0 commit comments

Comments
 (0)