Skip to content

Commit 4658168

Browse files
committed
initial commit
0 parents  commit 4658168

File tree

18 files changed

+7392
-0
lines changed

18 files changed

+7392
-0
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"env",
4+
"react"
5+
],
6+
"plugins": [
7+
["transform-object-rest-spread"]
8+
]
9+
}

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
extends: [
3+
"eslint:recommended",
4+
"plugin:react/recommended",
5+
"prettier",
6+
],
7+
plugins: [
8+
"react",
9+
"prettier",
10+
],
11+
rules: {
12+
"prettier/prettier": ["error", {
13+
"singleQuote": true,
14+
"trailingComma": "es5",
15+
"bracketSpacing": true,
16+
"jsxBracketSameLine": true,
17+
"printWidth": 100,
18+
"parser": "babylon",
19+
}]
20+
},
21+
parser: "babel-eslint",
22+
env: {
23+
"es6": true,
24+
"node": true,
25+
"browser": true,
26+
"jest": true,
27+
},
28+
};

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
logs
2+
*.log
3+
npm-debug.log.*
4+
node_modules
5+
dist
6+
!demo/dist

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
demo
2+
node_modules
3+
.eslintrc.js
4+
.gitignore
5+
yarn.lock
6+
webpack.config.js

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
A react component for editing/formating
2+
> react-numeric is a wrapper component of [autonumeric](https://github.com/autoNumeric/autoNumeric).
3+
4+
## Installition
5+
6+
```sh
7+
yarn add react-numeric
8+
# or
9+
npm install react-numeric --save
10+
```
11+
12+
## Usage
13+
14+
```jsx
15+
import ReactNumeric from 'ract-numeric';
16+
17+
export function USDMoneyInput(props){
18+
const { value } = props; // number typed
19+
return (
20+
<ReactNumeric
21+
value={value}
22+
currencySymbol="$"
23+
minimumValue="0"
24+
decimalCharacter="."
25+
digitGroupSeparator=""
26+
onChange={(event, value)=>{
27+
console.log(event.target.value); // '1,234.5 $'
28+
console.log(value); // 1234.5
29+
}}
30+
/>
31+
);
32+
}
33+
34+
// You can use predefinedOptions
35+
import { predefinedOptions } from 'react-numeric';
36+
37+
export function USDMoneyInput(props){
38+
const { value } = props; // number typed
39+
return (
40+
<ReactNumeric
41+
value={value}
42+
preDefined={predefinedOptions.dollarPos}
43+
onChange={(e, value)=> this.setState({ value })}
44+
/>
45+
);
46+
}
47+
48+
// if you want to store value as string typed
49+
export function USDMoneyInput(props){
50+
const { value } = props; // string typed
51+
return (
52+
<ReactNumeric
53+
value={value}
54+
outputFormat="string"
55+
onChange={(e, value)=> this.setState({ value })}
56+
/>
57+
);
58+
}
59+
```

demo/dist/main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>react-numeric</title>
8+
<link href="https://fonts.googleapis.com/css?family=Open+Sans|PT+Sans:400,700" rel="stylesheet">
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
<script src="dist/main.js"></script>
13+
</body>
14+
</html>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.wrapper{
2+
background: #f8f9f9;
3+
font-size: 0.9em;
4+
margin-top: 2em;
5+
margin-bottom: 6em;
6+
position: relative;
7+
}
8+
9+
.content{
10+
position: relative;
11+
z-index: 1;
12+
background: #f8f9f9!important;
13+
}
14+
15+
.preview{
16+
display: flex;
17+
justify-content: center;
18+
align-items: center;
19+
min-height: 12em;
20+
}
21+
22+
.code{
23+
background: #f8f9f9!important;
24+
}
25+
26+
.buttons{
27+
position: absolute;
28+
top: 100%;
29+
right: 0em;
30+
}
31+
32+
.button{
33+
background-color: rgb(248, 249, 249);
34+
padding: 1em;
35+
border: 1px solid transparent;
36+
font-size: 0.8em;
37+
cursor: pointer;
38+
outline: 0;
39+
color: #3d91ff;
40+
}
41+
42+
.button:hover{
43+
border-color: #3d91ff;
44+
}
45+
46+
.button:first-child{
47+
border-bottom-left-radius: 4px;
48+
}
49+
50+
.button:last-child{
51+
border-bottom-right-radius: 4px;
52+
}
53+
54+
.passiveButton{
55+
background: #f1f2f2;
56+
color: #666666;
57+
}
58+
59+
input{
60+
font-size: 1.6em;
61+
padding: 0.5em;
62+
}
63+
64+
input:focus{
65+
outline:2px solid #3d91ff;
66+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import styles from './componentSnippet.css';
3+
import SyntaxHighlighter from 'react-syntax-highlighter/prism';
4+
import dark from 'react-syntax-highlighter/styles/prism/coy.js';
5+
import cx from 'classnames';
6+
import PropTypes from 'prop-types';
7+
8+
class ComponentSnippet extends React.Component {
9+
constructor(props){
10+
super(props);
11+
this.state = {
12+
mode: props.initialMode,
13+
}
14+
}
15+
16+
render() {
17+
const {mode} = this.state;
18+
const { preview, code} = this.props;
19+
return (
20+
<div className={styles.wrapper}>
21+
<div className={styles.content}>
22+
{mode === 'code' ? (
23+
<SyntaxHighlighter className={styles.code} language='jsx' style={dark}>
24+
{code}
25+
</SyntaxHighlighter>
26+
) : (
27+
<div className={styles.preview}>{preview}</div>
28+
)}
29+
</div>
30+
<div className={styles.buttons}>
31+
<button onClick={()=>this.setState({mode: 'code'})} className={cx(styles.button, {[styles.passiveButton]: mode !== 'code'})}>CODE</button>
32+
<button onClick={()=>this.setState({mode: 'preview'})} className={cx(styles.button, {[styles.passiveButton]: mode !== 'preview'})}>PREVIEW</button>
33+
</div>
34+
</div>
35+
);
36+
}
37+
}
38+
39+
ComponentSnippet.propTypes = {
40+
initialMode: PropTypes.oneOf(['preview', 'code']),
41+
}
42+
43+
ComponentSnippet.defaultProps = {
44+
initialMode: 'preview',
45+
}
46+
47+
export default ComponentSnippet;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import styles from './layout.css';
3+
4+
const Layout = props => {
5+
return (
6+
<div className={styles.wrapper}>
7+
{props.children}
8+
</div>
9+
);
10+
};
11+
12+
export default Layout;

0 commit comments

Comments
 (0)