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

Генерирование пароля без нажатия на кнопку #2

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
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
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: [],
};