From 3161693346b50709a410b9da91b03cd881457838 Mon Sep 17 00:00:00 2001 From: IamAnkit19 Date: Thu, 18 Dec 2025 20:35:41 +0530 Subject: [PATCH 1/2] feat(plays): add character counter play this play provides a real-time interface for users to track character and word counts using react usestate and regex. it includes reading time estimation and a clear-all feature. fixes #1631 --- .../character-counter/CharacterCounter.css | 84 +++++++++++++++++++ .../character-counter/CharacterCounter.jsx | 46 ++++++++++ src/plays/character-counter/Readme.md | 22 +++++ src/plays/character-counter/meta.json | 13 +++ 4 files changed, 165 insertions(+) create mode 100644 src/plays/character-counter/CharacterCounter.css create mode 100644 src/plays/character-counter/CharacterCounter.jsx create mode 100644 src/plays/character-counter/Readme.md create mode 100644 src/plays/character-counter/meta.json diff --git a/src/plays/character-counter/CharacterCounter.css b/src/plays/character-counter/CharacterCounter.css new file mode 100644 index 000000000..116358f5f --- /dev/null +++ b/src/plays/character-counter/CharacterCounter.css @@ -0,0 +1,84 @@ +.character-counter-wrapper { + display: flex; + justify-content: center; + align-items: flex-start; + min-height: 500px; + padding: 2rem; + background-color: #f0f2f5; +} + +.counter-card { + background: #fff; + padding: 30px; + border-radius: 12px; + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); + width: 100%; + max-width: 700px; +} + +.counter-title { + margin-bottom: 20px; + color: #1a202c; + font-size: 1.5rem; +} + +.counter-textarea { + width: 100%; + height: 250px; + padding: 15px; + border: 2px solid #e2e8f0; + border-radius: 8px; + font-size: 16px; + line-height: 1.5; + outline: none; + transition: border-color 0.2s; +} + +.counter-textarea:focus { + border-color: #4a90e2; +} + +.stats-container { + display: flex; + justify-content: space-between; + margin: 25px 0; + gap: 10px; +} + +.stat-item { + flex: 1; + background: #f8fafc; + padding: 15px; + border-radius: 8px; + text-align: center; + border: 1px solid #edf2f7; +} + +.stat-num { + display: block; + font-size: 1.8rem; + font-weight: bold; + color: #4a90e2; +} + +.stat-label { + font-size: 0.75rem; + color: #718096; + text-transform: uppercase; + letter-spacing: 1px; +} + +.reset-btn { + background-color: #e53e3e; + color: white; + border: none; + padding: 10px 20px; + border-radius: 6px; + cursor: pointer; + font-weight: 600; + transition: opacity 0.2s; +} + +.reset-btn:hover { + opacity: 0.9; +} \ No newline at end of file diff --git a/src/plays/character-counter/CharacterCounter.jsx b/src/plays/character-counter/CharacterCounter.jsx new file mode 100644 index 000000000..0480481ae --- /dev/null +++ b/src/plays/character-counter/CharacterCounter.jsx @@ -0,0 +1,46 @@ +import React, { useState } from 'react'; +import './CharacterCounter.css'; + +const CharacterCounter = () => { + const [text, setText] = useState(''); + + const charCount = text.length; + const wordCount = text.trim() === '' ? 0 : text.trim().split(/\s+/).filter(Boolean).length; + const readingTime = Math.ceil(wordCount / 200); + + return ( +
+
+

Character & Word Counter

+ +