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

Added Sentence Case and Capitalized Case btn #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/components/TextForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ export default function TextForm(props) {
setText(newText)
props.showAlert("Converted to lowercase!", "success");
}

// Credits: Sachin Mittal
const handleSeClick = ()=>{
var newText = text.toLowerCase();
newText = newText[0].toUpperCase() + newText.slice(1);
setText(newText)
props.showAlert("Converted to Sentense case!", "success");
}

// Credits: Sachin Mittal
const handleCaClick = ()=>{
var newText = text.toLowerCase();
const arr = newText.split(" ");

for( let i=0 ; i<arr.length; i++){
arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
}

newText = arr.join(" ");

setText(newText)
props.showAlert("Converted to Capitalized Case!", "success");
}

const handleClearClick = ()=>{
let newText = '';
Expand Down Expand Up @@ -49,6 +72,8 @@ export default function TextForm(props) {
</div>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleUpClick}>Convert to Uppercase</button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleLoClick}>Convert to Lowercase</button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleSeClick}>Convert to Sentence Case </button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleCaClick}>Convert to Capitalized Case </button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleClearClick}>Clear Text</button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleCopy}>Copy Text</button>
<button disabled={text.length===0} className="btn btn-primary mx-1 my-1" onClick={handleExtraSpaces}>Remove Extra Spaces</button>
Expand Down