Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ _* Required_
| -----| -------| -------- |
| text (*)| string | Text to be displayed on both the label and initially in the editor |
| isEditing | bool | Flags whether the label should be in editor mode
| isTextarea | bool | Flags whether input type text or textarea
| labelClassName | string | Class name for the text styling
| labelId | string | Id for the label
| labelFontSize | string | Font size for the text
| labelFontWeight | string | Font weight for the text
| inputMaxLength | number | Max length for the input in editing mode
Expand All @@ -25,7 +27,9 @@ _* Required_
| inputFontSize | string | Font size for the input in editing mode
| inputFontWeight | string | Font weight for the input in editing mode
| inputClassName | string | Class name for the input editor's styling
| inputId | string | Id for the input
| inputBorderWidth | string | Border width for the input in editing mode
| textareaCols | number | Specifies the visible width of the textarea
| onFocus | function | Callback for text focusing. Parameter(s): `text`
| onFocusOut | function | Callback for focus leaving editor. Parameter(s): `text`

Expand All @@ -34,7 +38,7 @@ _* Required_
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import EditableLabel from 'react-inline-edit';
import EditableLabel from 'react-inline-editing';

class App extends React.Component {
constructor(props){
Expand All @@ -44,19 +48,23 @@ class App extends React.Component {
this._handleFocusOut = this._handleFocusOut.bind(this);
}

_handleFocus(text) {
_handleFocus(text, event) {
console.log('Focused with text: ' + text);
console.log('Label id: ' + event.target.id);
}

_handleFocusOut(text) {
_handleFocusOut(text, event) {
console.log('Left editor with text: ' + text);
console.log('Input id: ' + event.target.id);
}

render() {
return <div>
<EditableLabel text='Hello!'
labelClassName='myLabelClass'
labelId='myLabelId'
inputClassName='myInputClass'
inputId="myInputId"
inputWidth='200px'
inputHeight='25px'
inputMaxLength='50'
Expand All @@ -65,6 +73,16 @@ class App extends React.Component {
onFocus={this._handleFocus}
onFocusOut={this._handleFocusOut}
/>
<EditableLabel text='Hello this is a textarea!'
isTextarea={true}
labelClassName='myLabelClass'
labelId='myLabelId'
inputClassName='myInputClass'
inputId="myInputId"
textareaCols='50'
onFocus={this._handleFocus}
onFocusOut={this._handleFocusOut}
/>
</div>
}
}
Expand Down
44 changes: 40 additions & 4 deletions dist/main.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ var EditableLabel = function (_React$Component) {

_this.state = {
isEditing: _this.props.isEditing || false,
text: _this.props.text || ""
text: _this.props.text || "",
isTextarea: _this.props.isTextarea || false
};

_this._handleFocus = _this._handleFocus.bind(_this);
Expand All @@ -493,14 +494,14 @@ var EditableLabel = function (_React$Component) {

_createClass(EditableLabel, [{
key: '_handleFocus',
value: function _handleFocus() {
value: function _handleFocus(event) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes shouldn't happen to the bundle file. This is just the distribution bundle created by webpack. If you want to make changes, you need to change the src/main.jsx and rebundle.

if (this.state.isEditing) {
if (typeof this.props.onFocusOut === 'function') {
this.props.onFocusOut(this.state.text);
this.props.onFocusOut(this.state.text, event);
}
} else {
if (typeof this.props.onFocus === 'function') {
this.props.onFocus(this.state.text);
this.props.onFocus(this.state.text, event);
}
}

Expand All @@ -521,11 +522,40 @@ var EditableLabel = function (_React$Component) {
var _this2 = this;

if (this.state.isEditing) {
if (this.state.isTextarea) {
return _react2.default.createElement(
'div',
null,
_react2.default.createElement('textarea', {
className: this.props.inputClassName,
id: this.props.inputId,
ref: function ref(input) {
_this2.textInput = input;
},
value: this.state.text,
onChange: this._handleChange,
onBlur: this._handleFocus,
style: {
width: this.props.inputWidth,
height: this.props.inputHeight,
fontSize: this.props.inputFontSize,
fontWeight: this.props.inputFontWeight,
borderWidth: this.props.inputBorderWidth

},
cols: this.props.textareaCols,
placeholder: this.props.inputPlaceHolder,
tabIndex: this.props.inputTabIndex,
autoFocus: true })
);
}

return _react2.default.createElement(
'div',
null,
_react2.default.createElement('input', { type: 'text',
className: this.props.inputClassName,
id: this.props.inputId,
ref: function ref(input) {
_this2.textInput = input;
},
Expand Down Expand Up @@ -553,6 +583,7 @@ var EditableLabel = function (_React$Component) {
_react2.default.createElement(
'label',
{ className: this.props.labelClassName,
id: this.props.labelId,
onClick: this._handleFocus,
style: {
fontSize: this.props.labelFontSize,
Expand All @@ -573,8 +604,10 @@ exports.default = EditableLabel;
EditableLabel.propTypes = {
text: _propTypes2.default.string.isRequired,
isEditing: _propTypes2.default.bool,
isTextarea: _propTypes2.default.bool,

labelClassName: _propTypes2.default.string,
labelId: _propTypes2.default.string,
labelFontSize: _propTypes2.default.string,
labelFontWeight: _propTypes2.default.string,

Expand All @@ -586,8 +619,11 @@ EditableLabel.propTypes = {
inputFontSize: _propTypes2.default.string,
inputFontWeight: _propTypes2.default.string,
inputClassName: _propTypes2.default.string,
inputId: _propTypes2.default.string,
inputBorderWidth: _propTypes2.default.string,

textareaCols: _propTypes2.default.number,

onFocus: _propTypes2.default.func,
onFocusOut: _propTypes2.default.func
};
Expand Down
Loading