Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AliAlmasi committed Dec 1, 2024
1 parent dcf3f6c commit 3007819
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
21 changes: 12 additions & 9 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,24 @@ button:active {
}

.settings {
min-width: 50%;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}

.Today,
.Reset {
.vertical {
flex-direction: column;
}

.count {
font-size: inherit;
text-align: center;
width: 10rem;
}

.Today {
font-size: 1.8rem;
width: auto;
padding: 0 1rem;
}

.Group {
display: flex;
flex-direction: column;
gap: 0.4rem;
}
53 changes: 24 additions & 29 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@ export default function App() {
<div className="App">
<Step step={step} setStep={setStep} />
<Counter step={step} count={count} setCount={setCount} />
<div className="Group">
<Today setCount={setCount} />
<Reset setStep={setStep} />
</div>
{count !== 0 && <Today setCount={setCount} />}
</div>
);
}

function Step({ step, setStep }) {
return (
<div className="settings">
<button
onClick={() => {
if (step > 1) setStep((s) => s - 1);
}}
>
-
</button>
<div className="settings vertical">
<span>Step: {step}</span>
<button onClick={() => setStep((s) => s + 1)}>+</button>
<input
type="range"
value={step}
min={1}
max={31}
onChange={(e) => setStep(Number(e.target.value))}
/>
</div>
);
}
Expand All @@ -40,12 +36,22 @@ function Counter({ step, count, setCount }) {
<>
<div className="settings">
<button onClick={() => setCount((c) => c - step)}>-</button>
<span>Count: {count}</span>
<span>
Count:{" "}
<input
className="count"
type="text"
value={count}
onChange={(e) => setCount(Number(e.target.value))}
/>
</span>
<button onClick={() => setCount((c) => c + step)}>+</button>
</div>
<p>
<span>
{count === 0
{isNaN(count)
? "Input Error"
: count === 0
? "Today is "
: count > 0
? count === 1
Expand All @@ -55,7 +61,9 @@ function Counter({ step, count, setCount }) {
? `${Math.abs(count)} day ago was `
: `${Math.abs(count)} days ago was `}
</span>
<span>{date.toDateString()}</span>
<span>
{date.toDateString() === "Invalid Date" ? "" : date.toDateString()}
</span>
</p>
</>
);
Expand All @@ -73,16 +81,3 @@ function Today({ setCount }) {
</button>
);
}

function Reset({ setStep }) {
return (
<button
onClick={() => {
setStep(1);
}}
className="Reset"
>
Reset steps
</button>
);
}

0 comments on commit 3007819

Please sign in to comment.