Skip to content

Commit

Permalink
Генерирование пароля без нажатия на кнопку (#2)
Browse files Browse the repository at this point in the history
* Добавление шрифтов в конфиг #1

* Удаление кнопки генерации пароля #1
  • Loading branch information
Iskait authored Feb 20, 2023
1 parent 80e8406 commit 66f581a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 47 deletions.
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import "./index.css";
import Password from "./components/Password";
import LengthSet from "./components/LengthSet";
import Settings from "./components/Settings";
import GeneratePassword from "./components/GeneratePassword";

const App: React.FC = () => {
return (
<div className="flex items-center justify-center h-screen w-screen bg-gradient-to-r from-violet-500 to-fuchsia-500 font-serif">
<div className="bg-sky-800 w-[25rem] mx-5 rounded-lg p-4 flex flex-col gap-y-5">
<div className="grid place-items-center min-h-full w-full bg-gradient-to-r from-violet-500 to-fuchsia-500 p-5">
<div className="bg-[#0a0e31] w-full max-w-[400px] rounded-lg p-5 flex flex-col gap-y-5">
<header className="text-2xl font-extrabold text-center">
<h1>Password Generator</h1>
</header>
Expand All @@ -16,7 +15,6 @@ const App: React.FC = () => {
<LengthSet />
<Settings />
</main>
<GeneratePassword />
</div>
</div>
);
Expand Down
20 changes: 0 additions & 20 deletions src/components/GeneratePassword.tsx

This file was deleted.

17 changes: 14 additions & 3 deletions src/components/LengthSet.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { useEffect } from "react";
import useAppSelector from "../hooks/useAppSelector";
import useActions from "../hooks/useActions";

function LengthSet() {
const { setLength } = useActions();
const { toggleCopied, generatePass, setLength } = useActions();
const length = useAppSelector((state) => state.generate.length);

useEffect(() => {
generatePass();
}, [generatePass]);

const handleGeneratePassword = (e: React.ChangeEvent<HTMLInputElement>) => {
toggleCopied(false);
generatePass();
setLength(+e.target.value);
};

return (
<div className="flex flex-col rounded-md bg-sky-700 gap-y-2 p-2">
<div className="flex flex-col rounded-md bg-white/5 gap-y-2 p-2">
<h3 className="justify-center gap-x-2 flex items-center">
Length: <strong>{length}</strong>
</h3>
Expand All @@ -18,7 +29,7 @@ function LengthSet() {
min={4}
max={30}
value={length}
onChange={(e) => setLength(+e.target.value)}
onChange={(e) => handleGeneratePassword(e)}
/>
<span>30</span>
</div>
Expand Down
20 changes: 13 additions & 7 deletions src/components/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const Option: React.FC<OptionProps> = ({ name }) => {

return (
<div
className={classNames(
"bg-sky-700 rounded-md py-2 px-2 flex items-center",
{ "opacity-50": disabled }
)}
className={classNames("bg-white/5 rounded-md", {
"opacity-50": disabled,
})}
>
<input
className="opacity-0 absolute"
type="checkbox"
hidden
id={name}
defaultChecked={checked}
disabled={disabled}
Expand All @@ -32,20 +32,26 @@ const Option: React.FC<OptionProps> = ({ name }) => {
}}
/>
<label
className="flex items-center justify-between w-full flex-row"
className={classNames(
"flex items-center justify-between p-2 flex-row",
{
"cursor-pointer": !disabled,
"cursor-not-allowed": disabled,
}
)}
htmlFor={name}
>
<span className="font-bold">Include {name}</span>
<div className="relative content-[''] h-8 w-12">
<span
className={classNames(
"absolute h-full w-full rounded-3xl",
checked ? "bg-sky-200" : "bg-slate-400"
checked ? "bg-[#5d68e2]" : "bg-white/75"
)}
/>
<span
className={classNames(
"absolute h-6 w-6 rounded-3xl bg-sky-600 top-1 transition-all translate-x-1",
"absolute h-6 w-6 rounded-3xl bg-white top-1 transition-all translate-x-1",
{
"translate-x-5": checked,
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ const Password: React.FC = () => {
};

return (
<div className="relative text-center bg-sky-500 rounded-md py-4 px-1">
<div className="text-black text-xs sm:text-base">
{pass || "CLICK GENERATE"}
</div>
<div className="relative text-center bg-white/5 rounded-md py-5 px-1">
<div className="text-xs sm:text-base">{pass || "CLICK GENERATE"}</div>
<button
className={classNames(
"absolute text-white -bottom-1 text-xs text-opacity-80 cursor-pointer transition-all left-2",
Expand Down
10 changes: 10 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700;800&display=swap');

:root {
@apply text-white font-main
}

#root {
@apply h-screen
}
8 changes: 4 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<Provider store={store}>
<React.StrictMode>
<React.StrictMode>
<Provider store={store}>
<App />
</React.StrictMode>
</Provider>
</Provider>
</React.StrictMode>
);
5 changes: 1 addition & 4 deletions src/store/slices/copySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { CopyState } from "../../types/copyState";
const copySlice = createSlice({
name: "copy",
initialState: {
showButtons: false,
showButtons: true,
copied: false,
} as CopyState,
reducers: {
toggleButtons: (state) => {
state.showButtons = true;
},
toggleCopied: (state, action: PayloadAction<boolean>) => {
state.copied = action.payload;
},
Expand Down
6 changes: 5 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
extend: {
fontFamily: {
main: ["Montserrat", "sans-serif"],
},
},
},
plugins: [],
};

0 comments on commit 66f581a

Please sign in to comment.