Skip to content

Commit b835fa4

Browse files
authored
Merge pull request #17 from bymi15/feat/add-format-display-text
feat: add format display text prop
2 parents 11172d6 + 7229ed5 commit b835fa4

20 files changed

Lines changed: 5125 additions & 2029 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"jsxBracketSameLine": false,
88
"arrowParens": "always",
99
"trailingComma": "none",
10-
"endOfLine":"auto"
10+
"endOfLine": "lf"
1111
}

.releaserc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
{
2-
"branches": ["main", "next"],
2+
"branches": [
3+
"main",
4+
"next"
5+
],
36
"plugins": [
47
"@semantic-release/commit-analyzer",
58
"@semantic-release/release-notes-generator",
69
"@semantic-release/changelog",
710
"@semantic-release/npm",
8-
["@semantic-release/git", {
9-
"assets": ["package.json", "CHANGELOG.md"],
10-
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
11-
}],
11+
[
12+
"@semantic-release/git",
13+
{
14+
"assets": [
15+
"package.json",
16+
"CHANGELOG.md"
17+
],
18+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
19+
}
20+
],
1221
"@semantic-release/github"
1322
]
14-
}
23+
}

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ script:
1212
- npm run semantic-release
1313
notifications:
1414
email: false
15+
git:
16+
autocrlf: input

CHANGELOG.md

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,113 @@
11
# [4.2.0](https://github.com/bymi15/react-edit-text/compare/v4.1.0...v4.2.0) (2021-08-22)
22

3-
43
### Features
54

6-
* add onBlur callback ([850adce](https://github.com/bymi15/react-edit-text/commit/850adce60b529c0ccab9c4ecebe20d3ef1d7f189))
5+
- add onBlur callback ([850adce](https://github.com/bymi15/react-edit-text/commit/850adce60b529c0ccab9c4ecebe20d3ef1d7f189))
76

87
# [4.1.0](https://github.com/bymi15/react-edit-text/compare/v4.0.3...v4.1.0) (2021-07-26)
98

10-
119
### Features
1210

13-
* add onEditMode callback prop ([836e58d](https://github.com/bymi15/react-edit-text/commit/836e58d23da12923ae8849952e23a3f78281d58b))
11+
- add onEditMode callback prop ([836e58d](https://github.com/bymi15/react-edit-text/commit/836e58d23da12923ae8849952e23a3f78281d58b))
1412

1513
## [4.0.3](https://github.com/bymi15/react-edit-text/compare/v4.0.2...v4.0.3) (2021-04-03)
1614

17-
1815
### Bug Fixes
1916

20-
* force minor version update to update readme in npmjs ([d079ab9](https://github.com/bymi15/react-edit-text/commit/d079ab94acaf2cfdbe96a178f786e01edb6a092a))
17+
- force minor version update to update readme in npmjs ([d079ab9](https://github.com/bymi15/react-edit-text/commit/d079ab94acaf2cfdbe96a178f786e01edb6a092a))
2118

2219
## [4.0.2](https://github.com/bymi15/react-edit-text/compare/v4.0.1...v4.0.2) (2021-04-03)
2320

24-
2521
### Bug Fixes
2622

27-
* setSelectionRange causing bugs for input types that are not text ([777fba9](https://github.com/bymi15/react-edit-text/commit/777fba9f5d401d4374b653e6ae4f7f39b2c2adca))
23+
- setSelectionRange causing bugs for input types that are not text ([777fba9](https://github.com/bymi15/react-edit-text/commit/777fba9f5d401d4374b653e6ae4f7f39b2c2adca))
2824

2925
## [4.0.1](https://github.com/bymi15/react-edit-text/compare/v4.0.0...v4.0.1) (2021-03-09)
3026

31-
3227
### Bug Fixes
3328

34-
* upgrade package to fix security issue ([96b5914](https://github.com/bymi15/react-edit-text/commit/96b59148c78203db085983fe04db65491d3f780b))
29+
- upgrade package to fix security issue ([96b5914](https://github.com/bymi15/react-edit-text/commit/96b59148c78203db085983fe04db65491d3f780b))
3530

3631
# [4.0.0](https://github.com/bymi15/react-edit-text/compare/v3.0.1...v4.0.0) (2021-02-19)
3732

38-
3933
### Features
4034

41-
* add previousValue field to onSave callback response ([3057b92](https://github.com/bymi15/react-edit-text/commit/3057b92078bc95e4cb3a6ddb654c0611df2e3f67))
42-
* move cursor to end of text on focus ([3fde4bd](https://github.com/bymi15/react-edit-text/commit/3fde4bde2ab8dc1f6065bc7900d5bddfbf090a24))
43-
35+
- add previousValue field to onSave callback response ([3057b92](https://github.com/bymi15/react-edit-text/commit/3057b92078bc95e4cb3a6ddb654c0611df2e3f67))
36+
- move cursor to end of text on focus ([3fde4bd](https://github.com/bymi15/react-edit-text/commit/3fde4bde2ab8dc1f6065bc7900d5bddfbf090a24))
4437

4538
### BREAKING CHANGES
4639

47-
* fix handleBlur to correctly revert changes when escape key is pressed
40+
- fix handleBlur to correctly revert changes when escape key is pressed
4841

4942
## [3.0.1](https://github.com/bymi15/react-edit-text/compare/v3.0.0...v3.0.1) (2021-01-13)
5043

51-
5244
### Bug Fixes
5345

54-
* allow onSave callback to be triggered when used with onChange ([6508ea4](https://github.com/bymi15/react-edit-text/commit/6508ea47411a422ce1ab63d2224534a6b665124a))
46+
- allow onSave callback to be triggered when used with onChange ([6508ea4](https://github.com/bymi15/react-edit-text/commit/6508ea47411a422ce1ab63d2224534a6b665124a))
5547

5648
# [3.0.0](https://github.com/bymi15/react-edit-text/compare/v2.1.3...v3.0.0) (2021-01-13)
5749

58-
5950
### Features
6051

61-
* add controllable component for both EditText and EditTextarea ([5d34a65](https://github.com/bymi15/react-edit-text/commit/5d34a65d9892451c7846a49e8f96a3629f43b821))
62-
* add controlled values (defaultValue, value, onChange) ([516dd3c](https://github.com/bymi15/react-edit-text/commit/516dd3cb5a3120495db06f732a802d67a2969ca4))
63-
52+
- add controllable component for both EditText and EditTextarea ([5d34a65](https://github.com/bymi15/react-edit-text/commit/5d34a65d9892451c7846a49e8f96a3629f43b821))
53+
- add controlled values (defaultValue, value, onChange) ([516dd3c](https://github.com/bymi15/react-edit-text/commit/516dd3cb5a3120495db06f732a802d67a2969ca4))
6454

6555
### BREAKING CHANGES
6656

67-
* add defaultValue and onChange props to allow controllable components
57+
- add defaultValue and onChange props to allow controllable components
6858

6959
## [2.1.3](https://github.com/bymi15/react-edit-text/compare/v2.1.2...v2.1.3) (2020-11-17)
7060

71-
7261
### Bug Fixes
7362

74-
* **EditTextarea:** fix newline not showing in view mode bug ([6a21fa4](https://github.com/bymi15/react-edit-text/commit/6a21fa4dd4b78c5ccb02e87ebc3d049d16170733))
63+
- **EditTextarea:** fix newline not showing in view mode bug ([6a21fa4](https://github.com/bymi15/react-edit-text/commit/6a21fa4dd4b78c5ccb02e87ebc3d049d16170733))
7564

7665
## [2.1.2](https://github.com/bymi15/react-edit-text/compare/v2.1.1...v2.1.2) (2020-11-16)
7766

78-
7967
### Bug Fixes
8068

81-
* fix css bug ([ddab856](https://github.com/bymi15/react-edit-text/commit/ddab8564ab2b3ae3c42c9d7a381126ccca32e4f6))
69+
- fix css bug ([ddab856](https://github.com/bymi15/react-edit-text/commit/ddab8564ab2b3ae3c42c9d7a381126ccca32e4f6))
8270

8371
## [2.1.1](https://github.com/bymi15/react-edit-text/compare/v2.1.0...v2.1.1) (2020-11-16)
8472

85-
8673
### Bug Fixes
8774

88-
* fix browser compatibility issue with thin scrollbar ([822ec70](https://github.com/bymi15/react-edit-text/commit/822ec709872da0ff671549caf8b9d8d3a15f908a))
75+
- fix browser compatibility issue with thin scrollbar ([822ec70](https://github.com/bymi15/react-edit-text/commit/822ec709872da0ff671549caf8b9d8d3a15f908a))
8976

9077
# [2.1.0](https://github.com/bymi15/react-edit-text/compare/v2.0.0...v2.1.0) (2020-11-16)
9178

92-
9379
### Features
9480

95-
* add scrollbar thin UI for EditTextarea ([82ccfd8](https://github.com/bymi15/react-edit-text/commit/82ccfd8bba5018900a77a7210e985a56e1a47319))
81+
- add scrollbar thin UI for EditTextarea ([82ccfd8](https://github.com/bymi15/react-edit-text/commit/82ccfd8bba5018900a77a7210e985a56e1a47319))
9682

9783
# [2.0.0](https://github.com/bymi15/react-edit-text/compare/v1.1.0...v2.0.0) (2020-11-05)
9884

99-
10085
### Features
10186

102-
* **EditTextarea:** add textarea component ([9b88363](https://github.com/bymi15/react-edit-text/commit/9b88363ae17320511c720a5b8ecfdfc80e1cf394))
103-
* **example:** update documentation page ([16da811](https://github.com/bymi15/react-edit-text/commit/16da811a1ed3f8214d7af4c26e1bac8d6762ab46))
104-
* add EditTextarea component ([bc4eb9a](https://github.com/bymi15/react-edit-text/commit/bc4eb9af793ca6d99d08cd19d15e2ac7ec0ebbe6))
105-
87+
- **EditTextarea:** add textarea component ([9b88363](https://github.com/bymi15/react-edit-text/commit/9b88363ae17320511c720a5b8ecfdfc80e1cf394))
88+
- **example:** update documentation page ([16da811](https://github.com/bymi15/react-edit-text/commit/16da811a1ed3f8214d7af4c26e1bac8d6762ab46))
89+
- add EditTextarea component ([bc4eb9a](https://github.com/bymi15/react-edit-text/commit/bc4eb9af793ca6d99d08cd19d15e2ac7ec0ebbe6))
10690

10791
### BREAKING CHANGES
10892

109-
* split up default export into EditText and EditTextarea exports
93+
- split up default export into EditText and EditTextarea exports
11094

11195
# [1.1.0](https://github.com/bymi15/react-edit-text/compare/v1.0.1...v1.1.0) (2020-10-28)
11296

113-
11497
### Features
11598

116-
* add readonly prop ([47d5a38](https://github.com/bymi15/react-edit-text/commit/47d5a38e3b3bf5efe40bca35a94b4da738c47018))
117-
* **example:** add example for readonly prop ([34d7646](https://github.com/bymi15/react-edit-text/commit/34d7646bea482793e4ce77793ca7d38a8604487b))
99+
- add readonly prop ([47d5a38](https://github.com/bymi15/react-edit-text/commit/47d5a38e3b3bf5efe40bca35a94b4da738c47018))
100+
- **example:** add example for readonly prop ([34d7646](https://github.com/bymi15/react-edit-text/commit/34d7646bea482793e4ce77793ca7d38a8604487b))
118101

119102
## [1.0.1](https://github.com/bymi15/react-edit-text/compare/v1.0.0...v1.0.1) (2020-10-28)
120103

121-
122104
### Bug Fixes
123105

124-
* **styles:** fix invalid css color for placeholder ([1bf8159](https://github.com/bymi15/react-edit-text/commit/1bf81599181a6bdf4b7bb5275eb7e3284acb5719))
106+
- **styles:** fix invalid css color for placeholder ([1bf8159](https://github.com/bymi15/react-edit-text/commit/1bf81599181a6bdf4b7bb5275eb7e3284acb5719))
125107

126108
# 1.0.0 (2020-10-14)
127109

128-
129110
### Features
130111

131-
* **EditText:** add EditText component ([a953e78](https://github.com/bymi15/react-edit-text/commit/a953e7894cd1c424f7c6e518e8d3c63b8c228b8f))
132-
* **example:** add demo web page ([854e68c](https://github.com/bymi15/react-edit-text/commit/854e68c4013a9be8ccd2b255c6bd57bdeca22cf2))
112+
- **EditText:** add EditText component ([a953e78](https://github.com/bymi15/react-edit-text/commit/a953e7894cd1c424f7c6e518e8d3c63b8c228b8f))
113+
- **example:** add demo web page ([854e68c](https://github.com/bymi15/react-edit-text/commit/854e68c4013a9be8ccd2b255c6bd57bdeca22cf2))

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
* Using welcoming and inclusive language
18-
* Being respectful of differing viewpoints and experiences
19-
* Gracefully accepting constructive criticism
20-
* Focusing on what is best for the community
21-
* Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
27-
* Trolling, insulting/derogatory comments, and personal or political attacks
28-
* Public or private harassment
29-
* Publishing others' private information, such as a physical or electronic
30-
address, without explicit permission
31-
* Other conduct which could reasonably be considered inappropriate in a
32-
professional setting
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
3333

3434
## Our Responsibilities
3535

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
## Demo
2727

28-
Feel free to check out the [live demo](https://bymi15.github.io/react-edit-text)
28+
Please visit https://brianmin.com/react-edit-text/ for a live demo and various examples.
2929

3030
## Install
3131

@@ -65,20 +65,21 @@ class Example extends Component {
6565

6666
### Shared props
6767

68-
| Prop | Type | Required | Default | Description |
69-
| ------------ | -------- | -------- | ------- | ------------------------------------------------------- |
70-
| id | string | No | | HTML DOM id attribute |
71-
| name | string | No | | HTML input name attribute |
72-
| className | string | No | | HTML class attribute |
73-
| value | string | No | | Value of the component |
74-
| defaultValue | string | No | | Default value of the component |
75-
| placeholder | string | No | '' | Placeholder value |
76-
| onSave | function | No | | Callback function triggered when input is saved |
77-
| onChange | function | No | | Callback function triggered when input is changed |
78-
| onEditMode | function | No | | Callback function triggered when component is clicked |
79-
| onBlur | function | No | | Callback function triggered when input is blurred |
80-
| style | object | No | | Sets CSS style of input and view component |
81-
| readonly | bool | No | false | Disables the input and only displays the view component |
68+
| Prop | Type | Required | Default | Description |
69+
| ----------------- | -------- | -------- | -------- | --------------------------------------------------------------------- |
70+
| id | string | No | | HTML DOM id attribute |
71+
| name | string | No | | HTML input name attribute |
72+
| className | string | No | | HTML class attribute |
73+
| value | string | No | | Value of the component |
74+
| defaultValue | string | No | | Default value of the component |
75+
| placeholder | string | No | '' | Placeholder value |
76+
| formatDisplayText | function | No | (x) => x | Callback function applied on the value to display the formatted value |
77+
| onSave | function | No | | Callback function triggered when input is saved |
78+
| onChange | function | No | | Callback function triggered when input is changed |
79+
| onEditMode | function | No | | Callback function triggered when component is clicked |
80+
| onBlur | function | No | | Callback function triggered when input is blurred |
81+
| style | object | No | | Sets CSS style of input and view component |
82+
| readonly | bool | No | false | Disables the input and only displays the view component |
8283

8384
### EditText props
8485

example/public/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
</head>
2929

3030
<body>
31-
<noscript>
32-
You need to enable JavaScript to run this app.
33-
</noscript>
31+
<noscript> You need to enable JavaScript to run this app. </noscript>
3432

3533
<div id="root"></div>
3634

example/src/App.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import React from 'react';
2-
32
import { EditText, EditTextarea } from 'react-edit-text';
43
import 'react-edit-text/dist/index.css';
5-
6-
import Navbar from './components/Navbar';
7-
import Jumbotron from './components/Jumbotron';
8-
94
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
105
import { okaidia } from 'react-syntax-highlighter/dist/esm/styles/prism';
6+
import Jumbotron from './components/Jumbotron';
7+
import Navbar from './components/Navbar';
118
import { examples } from './examples';
129

1310
const App = () => {
1411
const [text, setText] = React.useState('This is a controlled component');
12+
const [price, setPrice] = React.useState('125000.49');
1513
const [textarea, setTextarea] = React.useState(
1614
'This is a controlled text area component'
1715
);
16+
const formatPrice = (val) => '$' + Math.round(parseFloat(val));
1817
const handleSave = ({ name, value, previousValue }) => {
1918
alert(name + ' saved as: ' + value + ' (prev: ' + previousValue + ')');
2019
};
@@ -101,6 +100,10 @@ const App = () => {
101100
<li>
102101
<b>value</b> sets the value of the component
103102
</li>
103+
<li>
104+
<b>formatDisplayValue</b> callback function gets called on the input
105+
value and displays the output
106+
</li>
104107
<li>
105108
<b>onSave</b> callback function returns a {'{'}name, value,
106109
previousValue{'}'} object when the input is loses focus (
@@ -245,7 +248,7 @@ const App = () => {
245248
padding: '15px',
246249
fontSize: '24px',
247250
color: '#FFF',
248-
backgroundColor: '#000'
251+
backgroundColor: '#2196f3'
249252
}}
250253
defaultValue='Click me to edit my text'
251254
/>
@@ -263,6 +266,10 @@ const App = () => {
263266
<span id='callbacks' />
264267
<hr />
265268
<h3>Callback Usage</h3>
269+
<div>
270+
<b>formatDisplayValue</b> callback function takes in a value and
271+
outputs a value. This can be used to format the displayed value.
272+
</div>
266273
<div>
267274
<b>onSave</b> callback function is triggered when the input field is
268275
blurred or loses focus (<em>except when the escape key is pressed</em>
@@ -296,6 +303,18 @@ const App = () => {
296303
<h4>Output</h4>
297304
<div className='card'>
298305
<div className='card-body'>
306+
<EditText
307+
name='priceInput'
308+
type='number'
309+
style={{
310+
fontSize: '16px',
311+
border: '1px solid #ccc',
312+
marginBottom: '10px'
313+
}}
314+
value={price}
315+
onChange={setPrice}
316+
formatDisplayText={formatPrice}
317+
/>
299318
<EditText
300319
name='textbox'
301320
style={{ fontSize: '16px', border: '1px solid #ccc' }}

example/src/App.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom'
3-
import App from './App'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
44

55
it('renders without crashing', () => {
6-
const div = document.createElement('div')
7-
ReactDOM.render(<App />, div)
8-
ReactDOM.unmountComponentAtNode(div)
9-
})
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});

0 commit comments

Comments
 (0)