Skip to content

Commit

Permalink
0.0.7 update + Fragment added + code refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwickdey committed Apr 2, 2019
1 parent 1f08c3e commit 72329a1
Show file tree
Hide file tree
Showing 20 changed files with 5,021 additions and 3,056 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default withTemplating(MyComponent);
- Use Wrapper HTML tags

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

## Syntax
Expand Down Expand Up @@ -98,7 +99,7 @@ function ExampleSwitchCase() {

```jsx
import React, { Component } from 'react';
import { Div, P, Button, Br } from 'react-jsx-templating';
import { Div, Fragment, Button, Br } from 'react-jsx-templating';
import { EnglishNewsPaper, SpanishNewsPaper } from './Components';

class ExampleIfElse extends Component {
Expand All @@ -114,9 +115,9 @@ class ExampleIfElse extends Component {
const { isEngLang } = this.state;
return (
<div>
<P $if={isEngLang} $else={<p>Hola!</p>}>
<Fragment $if={isEngLang} $else={<>Hola!</>}>
Hello!
</P>
</Fragment>
<EnglishNewsPaper $if={isEngLang} $else={SpanishNewsPaper} />
<Button onClick={this.toogleLanguage}>Toggle Language</Button>
</div>
Expand Down Expand Up @@ -145,6 +146,7 @@ function ExampleForLoop() {

- ~~Switch Case~~ (added)
- ~~Loop~~ (added)
- ~~Fragment~~ (added)

## License

Expand Down
12 changes: 9 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "^1.1.4",
"react-jsx-templating": "link:.."
"react-jsx-templating": "link:..",
"react-scripts": "^2.1.8"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
6 changes: 3 additions & 3 deletions example/src/components/IfElse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

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

function IfElse() {
Expand All @@ -15,9 +15,9 @@ function IfElse() {
Welcome here
</MySomeComponent>
<Button onClick={() => setShowToggler(v => !v)}>
<Span $if={!showToggler} $else={<Span>Hide Toggler</Span>}>
<Fragment $if={!showToggler} $else={<>Hide Toggler</>}>
Show Toggler
</Span>
</Fragment>
</Button>
<Br $if={showToggler} />
<Button $if={showToggler} onClick={() => setShow(v => !v)}>
Expand Down
7,590 changes: 4,777 additions & 2,813 deletions example/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-jsx-templating",
"version": "0.0.6",
"version": "0.0.7",
"description": "React Jsx Templating, inspired by Angular :)",
"author": "ritwickdey",
"license": "MIT",
Expand Down
Empty file added src/__test__/.gitkeep
Empty file.
123 changes: 1 addition & 122 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,4 @@
import withTemplating from './lib/withTemplating';
import Elements from './lib/Elements';
export * from './lib/Elements';

export default withTemplating;

export const {
A,
Abbr,
Address,
Area,
Article,
Aside,
Audio,
B,
Base,
Bdi,
Bdo,
Blockquote,
Body,
Br,
Button,
Canvas,
Caption,
Cite,
Code,
Col,
Colgroup,
Data,
Datalist,
Dd,
Del,
Details,
Dfn,
Dialog,
Div,
Dl,
Dt,
Em,
Embed,
Fieldset,
Figcaption,
Figure,
Footer,
Form,
H1,
H2,
H3,
H4,
H5,
H6,
Head,
Header,
Hgroup,
Hr,
Html,
I,
Iframe,
Img,
Input,
Ins,
Kbd,
Keygen,
Label,
Legend,
Li,
Link,
Main,
Map,
Mark,
Math,
Menu,
Menuitem,
Meta,
Meter,
Nav,
Noscript,
Object,
Ol,
Optgroup,
Option,
Output,
P,
Param,
Picture,
Pre,
Progress,
Q,
Rb,
Rp,
Rt,
Rtc,
Ruby,
S,
Samp,
Script,
Section,
Select,
Slot,
Small,
Source,
Span,
Strong,
Style,
Sub,
Summary,
Sup,
Svg,
Table,
Tbody,
Td,
Template,
Textarea,
Tfoot,
Th,
Thead,
Time,
Title,
Tr,
Track,
U,
Ul,
Var,
Video,
wbr
} = Elements;
10 changes: 5 additions & 5 deletions src/lib/Elements.js → src/lib/Elements/DOMElements.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { HTML_TAGS } from './html-tags';
import withTemplating from './withTemplating';
import { HTML_TAGS } from '../utils/html-tags';
import withTemplating from '../withTemplating';

export const Elements = {};
const DOMElements = {};

HTML_TAGS.forEach(tag => {
const Fn = props => {
Expand All @@ -11,11 +11,11 @@ HTML_TAGS.forEach(tag => {
};
const Tag = capitalCase(tag);
Fn.displayName = Tag;
Elements[Tag] = withTemplating(Fn);
DOMElements[Tag] = withTemplating(Fn);
});

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

export default { ...Elements };
export default DOMElements;
7 changes: 7 additions & 0 deletions src/lib/Elements/Fragment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import withTemplating from "../withTemplating";

const Fragment = ({ children }) => {
return children;
};

export default withTemplating(Fragment);
123 changes: 123 additions & 0 deletions src/lib/Elements/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import DOMElements from './DOMElements';
export { default as Fragment } from './Fragment';

export const {
A,
Abbr,
Address,
Area,
Article,
Aside,
Audio,
B,
Base,
Bdi,
Bdo,
Blockquote,
Body,
Br,
Button,
Canvas,
Caption,
Cite,
Code,
Col,
Colgroup,
Data,
Datalist,
Dd,
Del,
Details,
Dfn,
Dialog,
Div,
Dl,
Dt,
Em,
Embed,
Fieldset,
Figcaption,
Figure,
Footer,
Form,
H1,
H2,
H3,
H4,
H5,
H6,
Head,
Header,
Hgroup,
Hr,
Html,
I,
Iframe,
Img,
Input,
Ins,
Kbd,
Keygen,
Label,
Legend,
Li,
Link,
Main,
Map,
Mark,
Math,
Menu,
Menuitem,
Meta,
Meter,
Nav,
Noscript,
Object,
Ol,
Optgroup,
Option,
Output,
P,
Param,
Picture,
Pre,
Progress,
Q,
Rb,
Rp,
Rt,
Rtc,
Ruby,
S,
Samp,
Script,
Section,
Select,
Slot,
Small,
Source,
Span,
Strong,
Style,
Sub,
Summary,
Sup,
Svg,
Table,
Tbody,
Td,
Template,
Textarea,
Tfoot,
Th,
Thead,
Time,
Title,
Tr,
Track,
U,
Ul,
Var,
Video,
wbr
} = DOMElements;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { isTrusy } from './utils';
import { isTrusy } from '../utils';

export function doIfElseOperation(props, Component) {
const { $if: condition, $else: elseBlock, ...restProps } = props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { isTrusy, isUndefined } from './utils';
import { isTrusy, isUndefined } from '../utils';

export function doSwitchCaseOperation(props, Component) {
const { $switch: switchValue, children, ...restProps } = props;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/helperFns/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { doIfElseOperation } from './doIfElseOperation';
export { doSwitchCaseOperation } from './doSwitchCaseOperation';
export { doForLoopOperation } from './doForLoopOperation';
File renamed without changes.
Loading

0 comments on commit 72329a1

Please sign in to comment.