Skip to content

Commit d8fb657

Browse files
authored
Merge branch 'main' into feat/bmr-tdee-calculator
2 parents f19de5d + ab2bfbe commit d8fb657

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.character-counter-wrapper {
2+
display: flex;
3+
justify-content: center;
4+
align-items: flex-start;
5+
min-height: 500px;
6+
padding: 2rem;
7+
background-color: #f0f2f5;
8+
}
9+
10+
.counter-card {
11+
background: #fff;
12+
padding: 30px;
13+
border-radius: 12px;
14+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
15+
width: 100%;
16+
max-width: 700px;
17+
}
18+
19+
.counter-title {
20+
margin-bottom: 20px;
21+
color: #1a202c;
22+
font-size: 1.5rem;
23+
}
24+
25+
.counter-textarea {
26+
width: 100%;
27+
height: 250px;
28+
padding: 15px;
29+
border: 2px solid #e2e8f0;
30+
border-radius: 8px;
31+
font-size: 16px;
32+
line-height: 1.5;
33+
outline: none;
34+
transition: border-color 0.2s;
35+
color: black;
36+
}
37+
38+
.counter-textarea:focus {
39+
border-color: #4a90e2;
40+
}
41+
42+
.stats-container {
43+
display: flex;
44+
justify-content: space-between;
45+
margin: 25px 0;
46+
gap: 10px;
47+
}
48+
49+
.stat-item {
50+
flex: 1;
51+
background: #f8fafc;
52+
padding: 15px;
53+
border-radius: 8px;
54+
text-align: center;
55+
border: 1px solid #edf2f7;
56+
}
57+
58+
.stat-num {
59+
display: block;
60+
font-size: 1.8rem;
61+
font-weight: bold;
62+
color: #4a90e2;
63+
}
64+
65+
.stat-label {
66+
font-size: 0.75rem;
67+
color: #718096;
68+
text-transform: uppercase;
69+
letter-spacing: 1px;
70+
}
71+
72+
.reset-btn {
73+
background-color: #e53e3e;
74+
color: white;
75+
border: none;
76+
padding: 10px 20px;
77+
border-radius: 6px;
78+
cursor: pointer;
79+
font-weight: 600;
80+
transition: opacity 0.2s;
81+
}
82+
83+
.reset-btn:hover {
84+
opacity: 0.9;
85+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useState } from 'react';
2+
import './CharacterCounter.css';
3+
4+
const CharacterCounter = () => {
5+
const [text, setText] = useState('');
6+
7+
const charCount = text.length;
8+
const wordCount = text.trim() === '' ? 0 : text.trim().split(/\s+/).filter(Boolean).length;
9+
const readingTime = Math.ceil(wordCount / 200);
10+
11+
return (
12+
<div className="character-counter-wrapper">
13+
<div className="counter-card">
14+
<h2 className="counter-title">Character & Word Counter</h2>
15+
16+
<textarea
17+
className="counter-textarea"
18+
placeholder="Start typing or paste your text here..."
19+
value={text}
20+
onChange={(e) => setText(e.target.value)}
21+
/>
22+
23+
<div className="stats-container">
24+
<div className="stat-item">
25+
<span className="stat-num">{charCount}</span>
26+
<span className="stat-label">Characters</span>
27+
</div>
28+
<div className="stat-item">
29+
<span className="stat-num">{wordCount}</span>
30+
<span className="stat-label">Words</span>
31+
</div>
32+
<div className="stat-item">
33+
<span className="stat-num">{readingTime} min</span>
34+
<span className="stat-label">Reading Time</span>
35+
</div>
36+
</div>
37+
38+
<button className="reset-btn" onClick={() => setText('')}>
39+
Clear All
40+
</button>
41+
</div>
42+
</div>
43+
);
44+
};
45+
46+
export default CharacterCounter;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Character Counter
2+
3+
A simple, real-time character and word counter built with React. This play helps users analyze the length of their text and estimate reading time.
4+
5+
### 🚀 Features
6+
- **Real-time Counting**: Counts characters (including spaces) and words as you type.
7+
- **Accurate Word Logic**: Uses Regex to ensure multiple spaces or new lines don't inflate the word count.
8+
- **Reading Time Estimation**: Calculates the average time a human would take to read the text (based on 200 wpm).
9+
- **Clear Action**: A one-click button to reset the text area.
10+
11+
### 💻 React Concepts Used
12+
- **useState Hook**: To manage the string state of the text input.
13+
- **Event Handling**: Capturing `onChange` events to trigger re-calculations.
14+
- **Derived State**: Calculating counts directly during the render for better performance.
15+
16+
### 🛠️ How to use
17+
1. Type or paste your text into the provided text area.
18+
2. View the statistics updated instantly in the cards below.
19+
3. Click "Clear All" to start fresh.
20+
21+
---
22+
**Author**: IamAnkit19
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "character-counter",
3+
"name": "Character Counter",
4+
"description": "A clean tool to calculate character and word count in real-time.",
5+
"language": "js",
6+
"level": "Beginner",
7+
"tags": "useState, Regex",
8+
"author": "IamAnkit19",
9+
"github_id": "IamAnkit19",
10+
"cover": "https://placehold.co/600x400?text=Character+Counter",
11+
"blog": "",
12+
"video": ""
13+
}

0 commit comments

Comments
 (0)