Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paste feature requested on #48 #52

Merged
merged 3 commits into from
May 30, 2023
Merged
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
23 changes: 23 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class IPAddress extends Component {
};
this.handleChange = this.handleChange.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handlePaste = this.handlePaste.bind(this);
this.handleWheel = this.handleWheel.bind(this);
}

Expand Down Expand Up @@ -65,6 +66,26 @@ class IPAddress extends Component {
}
}

handlePaste(event) {
const pasteText = event.clipboardData.getData('Text');
var details = new Netmask(pasteText);
const cidrParts = details.toString().split('/');
var octets = this.state.octets;
const octetParts = cidrParts[0].split('.');
octetParts.map((octet, i) => {
octets[i] = octet;
})
this.setState({
octets: octets
});

if (+cidrParts[1] <= 32) {
this.setState({
cidr: +cidrParts[1]
});
}
}

handleWheel(event) {
var lowerOctetValue = 0;
var higherOctetValue = event.target.dataset.octet === 'cidr' ? 32 : 255;
Expand Down Expand Up @@ -96,6 +117,7 @@ class IPAddress extends Component {
data-octet={octet}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onPaste={this.handlePaste}
onWheel={this.handleWheel}
value={this.state.octets[octet]}
/>
Expand All @@ -108,6 +130,7 @@ class IPAddress extends Component {
data-octet="cidr"
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onPaste={this.handlePaste}
onWheel={this.handleWheel}
value={this.state.cidr}
/>
Expand Down