Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 2ccdab9

Browse files
committed
init
1 parent ed7c9bd commit 2ccdab9

File tree

19 files changed

+289
-0
lines changed

19 files changed

+289
-0
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# dependencies
2+
/node_modules
3+
4+
# testing
5+
6+
# production
7+
/dist
8+
9+
# workspace
10+
.vscode
11+
12+
# misc
13+
.DS_Store
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"bracketSpacing": true,
3+
"jsxBracketSameLine": false,
4+
"printWidth": 89,
5+
"semi": true,
6+
"singleQuote": true,
7+
"tabWidth": 2,
8+
"trailingComma": "all",
9+
"useTabs": false
10+
}

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# React semantics
2+
3+
Are you tired of your react components looking like an unreadable mess?
4+
Have you often asked yourself: "there must be a better way!"?
5+
Then look no further, because this library is just what you need!
6+
7+
Multiple studies from reputable anonymous sources have shown that projects using `react-semantics` have 24% higher productivity and increased life satisfaction.
8+
Does this sound too good to be true?
9+
Does the rational part of your brain see through this shallow pitch for yet another mediocre react library?
10+
Reject those thoughts and allow me to demonstrate the might of this library with a simple example below!
11+
12+
### Before
13+
14+
```javascript
15+
const Menu = ({ showMenuItems }) => (
16+
<nav>
17+
<a href="/">Home</a>
18+
{showMenuItems ? (
19+
<ul>
20+
{['prices', 'contact', 'about'].map(m => (
21+
<li key={m}>
22+
<a href={`/${m}`}>{m}</a>
23+
</li>
24+
))}
25+
</ul>
26+
) : null}
27+
</nav>
28+
);
29+
```
30+
31+
### After
32+
33+
```javascript
34+
import { Array, Show } from 'react-semantics';
35+
36+
const Menu = ({ showMenuItems }) => (
37+
<nav>
38+
<a href="/">Home</a>
39+
<Show when={showMenuItems}>
40+
<ul>
41+
<Array.Map
42+
array={['prices', 'contact', 'about']}
43+
render={m => (
44+
<li key={m}>
45+
<a href={`/${m}`}>{m}</a>
46+
</li>
47+
)}
48+
/>
49+
</ul>
50+
</Show>
51+
</nav>
52+
);
53+
```
54+
55+
## Install
56+
57+
Coming soon...
58+
59+
## Usage
60+
61+
```javascript
62+
import React from 'react';
63+
import { Show, Array } from 'react-semantics';
64+
65+
<Show when={5 === 2 + 2}>
66+
<div>Will only render in 1984</div>
67+
</Show>
68+
69+
```
70+
71+
## API
72+
73+
Coming soon...
74+
75+
## License
76+
77+
MIT

package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "react-semantics",
3+
"version": "0.1.0",
4+
"description": "Useful semantic helper components for working with React.",
5+
"author": "Christian Svenkerud",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/csvenke/react-semantics.git"
9+
},
10+
"main": "index.ts",
11+
"types": "index.d.ts",
12+
"private": false,
13+
"license": "MIT",
14+
"keywords": [
15+
"react",
16+
"react-components",
17+
"react-utils",
18+
"react-library",
19+
"components",
20+
"semantic"
21+
],
22+
"dependencies": {
23+
"prop-types": "^15.6.2"
24+
},
25+
"peerDependencies": {
26+
"react-dom": "^16.4.1",
27+
"react": "^16.4.1"
28+
},
29+
"devDependencies": {
30+
"@types/react": "^16.4.6",
31+
"@types/react-dom": "^16.0.6",
32+
"husky": "1.0.0-rc.2",
33+
"lint-staged": "^7.2.0",
34+
"prettier": "^1.13.7",
35+
"react-dom": "^16.4.1",
36+
"react": "^16.4.1",
37+
"rimraf": "^2.6.2",
38+
"tslint-config-prettier": "^1.14.0",
39+
"tslint-plugin-prettier": "^1.3.0",
40+
"tslint": "^5.11.0",
41+
"typescript": "^2.9.2"
42+
},
43+
"scripts": {
44+
"build": "npm run clean:build && npm run lint && npm run prettify && tsc -p ./tsconfig.build.json && cp ./package.json ./dist/lib",
45+
"clean:build": "rimraf ./dist/lib",
46+
"dist": "cd ./dist/lib && npm publish",
47+
"lint": "tslint -c tslint.json './src/**/*'",
48+
"lintfix": "tslint -c tslint.json --fix './src/**/*'",
49+
"prettify": "prettier -c .prettierrc --write \"src/**/*.@(ts|tsx)\""
50+
},
51+
"husky": {
52+
"hooks": {
53+
"pre-commit": "lint-staged"
54+
}
55+
},
56+
"lint-staged": {
57+
"*.{ts,tsx}": [
58+
"prettier -c .prettierrc --write",
59+
"tslint -c tslint.json --fix",
60+
"git add"
61+
]
62+
}
63+
}

src/components/Array/Array.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react';
2+
3+
import ArrayMap from './ArrayMap';
4+
5+
class Array extends React.Component {
6+
public static Map = ArrayMap;
7+
public render() {
8+
return null;
9+
}
10+
}
11+
12+
export default Array;

src/components/Array/ArrayMap.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
3+
export interface IArrayMapProps {
4+
array: any[];
5+
render?: (value?: any, index?: number, array?: any[]) => React.ReactNode;
6+
children?: (value?: any, index?: number, array?: any[]) => React.ReactNode;
7+
}
8+
9+
const ArrayMap: React.SFC<IArrayMapProps> = ({ array, render, children }) => {
10+
const func = children ? children : render;
11+
12+
if (!func) {
13+
return null;
14+
}
15+
16+
return <React.Fragment>{array.map((a, b, c) => func(a, b, c))}</React.Fragment>;
17+
};
18+
19+
export default ArrayMap;

src/components/Array/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Array';

src/components/Show/Show.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
3+
import { isEmptyChildren } from '../../utils';
4+
5+
export interface IShowProps {
6+
when: boolean;
7+
render?: () => React.ReactNode;
8+
children?: React.ReactNode;
9+
}
10+
11+
const Show: React.SFC<IShowProps> = ({ when, render, children }) => {
12+
if (when) {
13+
if (children && !isEmptyChildren(children)) {
14+
return React.Children.only(children);
15+
}
16+
17+
if (render) {
18+
return <React.Fragment>{render()}</React.Fragment>;
19+
}
20+
}
21+
22+
return null;
23+
};
24+
25+
export default Show;

src/components/Show/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Show';

src/components/Switch/Switch.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
3+
export interface ISwitchProps {
4+
value: string | boolean | number;
5+
children: React.ReactNode;
6+
}
7+
8+
class Switch extends React.Component<ISwitchProps> {
9+
public render() {
10+
return null;
11+
}
12+
}
13+
14+
export default Switch;

0 commit comments

Comments
 (0)