Skip to content

Commit

Permalink
feat(Input): add multiple sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
pure-js committed Oct 14, 2023
1 parent 4f15d7c commit 6860fd3
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 75 deletions.
15 changes: 8 additions & 7 deletions src/components/input/Input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ export const Large: Story = {
},
};

export const Small: Story = {
export const Medium: Story = {
args: {
size: 'small',
label: 'Button',
placeholder: 'placeholder',
size: 'medium',
label: 'Delete now',
id: 'button-label',
placeholder: 'placeholder',
},
};

export const Warning: Story = {
export const Small: Story = {
args: {
label: 'Delete now',
id: 'button-label',
size: 'small',
label: 'Button',
placeholder: 'placeholder',
id: 'button-label',
},
};
4 changes: 2 additions & 2 deletions src/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export const Input = ({
size = 'medium',
}: InputProps) => (
<>
<label htmlFor={id} className={(classes.label, classes[size])}>
<label htmlFor={id} className={`${classes.label} ${classes[size]}`}>
{label}
</label>
<input
id={id}
autoFocus={autoFocus}
minLength={minLength}
placeholder={placeholder}
className={(classes.input, classes[size])}
className={`${classes.input} ${classes[size]}`}
type={type}
/>
</>
Expand Down
23 changes: 23 additions & 0 deletions src/components/input/input.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
border: 1px solid rgb(155, 161, 165);
outline: none;
}

&.small {
padding: 12px 18px;
}
&.medium {
padding: 17px 24px;
}
&.large {
padding: 23px 32px;
}
}

.label {
Expand All @@ -21,4 +31,17 @@
bottom: -0.4rem;
padding: 0 10px 0 (24+1px);
background: #fff;

&.small {
bottom: -0.4rem;
padding: 0 10px 0 (18+1px);
}
&.medium {
bottom: -0.4rem;
padding: 0 10px 0 (24+1px);
}
&.large {
bottom: -0.4rem;
padding: 0 10px 0 (32+1px);
}
}
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Auth() {
}

export const HomePage = () => {
const { data, isLoading, error } = useDataFetch('/');
const { data, isLoading, error } = useDataFetch();
console.log('data ', data);

return (
Expand All @@ -31,7 +31,7 @@ export const HomePage = () => {
};

export const HomeRoute = new FileRoute('/').createRoute({
id: 'authenticated',
// id: 'authenticated',
beforeLoad: async () => {
const { isAuthenticated } = Auth();
if (!isAuthenticated) {
Expand Down
6 changes: 6 additions & 0 deletions src/services/AuthBlob.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// import { useState } from 'react';

export const Auth = () => {
// const [isAuthenticated, setIsAuthenticated] = useState(false);
return { isAuthenticated: false };
};
50 changes: 25 additions & 25 deletions src/services/auth.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
export function getUserData(token) {
return fetch(`${baseUrl}/users/me`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
}).then((res) => getResponseData(res));
}
// export function getUserData(token) {
// return fetch(`${baseUrl}/users/me`, {
// method: 'GET',
// headers: {
// 'Content-Type': 'application/json',
// Authorization: `Bearer ${token}`,
// },
// }).then((res) => getResponseData(res));
// }

function authorize() {
if (localStorage.jwt) {
getUserData(localStorage.jwt)
.then((res) => {
console.log('response: ', res);
setUserEmail(res.email);
setIsLoggedIn(true);
setIsCheckToken(false);
navigate('/');
})
.catch((err) => console.error(`Ошибка авторизации при входе ${err}`));
} else {
setIsLoggedIn(false);
setIsCheckToken(false);
}
}
// function authorize() {
// if (localStorage.jwt) {
// getUserData(localStorage.jwt)
// .then((res) => {
// console.log('response: ', res);
// setUserEmail(res.email);
// setIsLoggedIn(true);
// setIsCheckToken(false);
// navigate('/');
// })
// .catch((err) => console.error(`Ошибка авторизации при входе ${err}`));
// } else {
// setIsLoggedIn(false);
// setIsCheckToken(false);
// }
// }
87 changes: 48 additions & 39 deletions src/services/hooks/useDataFetch.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useState, useEffect, useReducer, useCallback } from 'react';
import wretch from 'wretch';
import { useState } from 'react';
// import { useState, useEffect, useReducer, useCallback } from 'react';
// import wretch from 'wretch';

const baseUrl = 'https://www.fruityvice.com';
const endPoint = 'api/fruit/all';
// const baseUrl = 'https://www.fruityvice.com';
// const endPoint = 'api/fruit/all';
// const apiKey = `api_key=${import.meta.env.VITE_NASDAQ_API_KEY}`;
// const finalurl = `${baseUrl}${endPoint}.json?${apiKey}`;
// Instantiate and configure wretch
const api = wretch(baseUrl, { mode: 'no-cors' });
// const api = wretch(baseUrl, { mode: 'no-cors' });
// .errorType('json')
// .resolve((r) => r.json());

Expand Down Expand Up @@ -37,42 +38,50 @@ const api = wretch(baseUrl, { mode: 'no-cors' });
// console.error(`${error.status}: ${message}`);
// }

export const useDataFetch = (url: string) => {
const [data, setData] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
// export const useDataFetch = (url: string) => {
// const [data, setData] = useState(null);
// const [isLoading, setIsLoading] = useState(false);
// const [error, setError] = useState(null);

useEffect(() => {
setIsLoading(true);
setData(null);
setError(null);
// useEffect(() => {
// setIsLoading(true);
// setData(null);
// setError(null);

async function logMovies() {
const response = await fetch(`${baseUrl}/${endPoint}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
// mode: 'no-cors',
});
const fruits = await response.data;
console.log('fru ', fruits);
setData(fruits);
}
logMovies();
async function getData() {
try {
const fruits = await api.get(endPoint).json();
console.log('f', fruits);
setData(fruits);
setIsLoading(false);
} catch (err) {
console.error(err);
setError(err);
}
}
// getData();
}, []);
// async function logMovies() {
// const response = await fetch(`${baseUrl}/${endPoint}`, {
// method: 'GET',
// headers: {
// 'Content-Type': 'application/json',
// },
// // mode: 'no-cors',
// });
// const fruits = await response.data;
// console.log('fru ', fruits);
// setData(fruits);
// }
// logMovies();
// async function getData() {
// try {
// const fruits = await api.get(endPoint).json();
// console.log('f', fruits);
// setData(fruits);
// setIsLoading(false);
// } catch (err) {
// console.error(err);
// setError(err);
// }
// }
// // getData();
// }, []);

// return { data, isLoading, error };
// };

export const useDataFetch = () => {
const [data] = useState(null);
const [isLoading] = useState(false);
const [error] = useState(null);

return { data, isLoading, error };
};

0 comments on commit 6860fd3

Please sign in to comment.