Format and optimized code

This commit is contained in:
2023-10-24 14:47:42 +07:00
parent 9918c7c3a4
commit 4560d29331
4 changed files with 17 additions and 11 deletions
@@ -3,7 +3,7 @@ import { useContext, useState } from 'react';
// Components // Components
import { HiEllipsisVertical } from 'react-icons/hi2'; import { HiEllipsisVertical } from 'react-icons/hi2';
import { useOutsideClick } from '../../hooks/useOutsideClick'; import { useOutsideClick } from '../../hooks/useOutsideClick';
import { StyledButton, StyledList, StyledMenu, StyledToggle } from './styled'; import { StyledMenu, StyledButton, StyledList, StyledToggle } from './styled';
// Interfaces // Interfaces
import { IButton } from '../../globals/interfaces'; import { IButton } from '../../globals/interfaces';
@@ -30,11 +30,14 @@ const Toggle = ({ id }: { id: string }): React.JSX.Element => {
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.stopPropagation(); e.stopPropagation();
openId === '' || openId !== id ? open!(id) : close!(); // prettier-ignore
openId === '' || openId !== id
? open!(id)
: close!();
}; };
return ( return (
<StyledToggle onClick={(e) => handleClick(e)}> <StyledToggle onClick={handleClick}>
<HiEllipsisVertical /> <HiEllipsisVertical />
</StyledToggle> </StyledToggle>
); );
@@ -1,13 +1,13 @@
import styled from 'styled-components'; import styled from 'styled-components';
export const StyledMenu = styled.div` const StyledMenu = styled.div`
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-end; justify-content: flex-end;
`; `;
export const StyledButton = styled.button` const StyledButton = styled.button`
width: 100%; width: 100%;
text-align: left; text-align: left;
background: none; background: none;
@@ -32,7 +32,7 @@ export const StyledButton = styled.button`
} }
`; `;
export const StyledToggle = styled.button` const StyledToggle = styled.button`
background: none; background: none;
border: none; border: none;
padding: 8px; padding: 8px;
@@ -50,7 +50,7 @@ export const StyledToggle = styled.button`
} }
`; `;
export const StyledList = styled.ul` const StyledList = styled.ul`
position: absolute; position: absolute;
z-index: 1000; z-index: 1000;
@@ -61,3 +61,5 @@ export const StyledList = styled.ul`
right: -10px; right: -10px;
top: 40px; top: 40px;
`; `;
export { StyledMenu, StyledButton, StyledList, StyledToggle };
@@ -6,8 +6,8 @@ const StyledMessage = styled.p`
padding: 20px; padding: 20px;
`; `;
const Empty = ({ children }: { children: string }) => { const Message = ({ children }: { children: string }) => {
return <StyledMessage>{children}</StyledMessage>; return <StyledMessage>{children}</StyledMessage>;
}; };
export default Empty; export default Message;
@@ -25,8 +25,9 @@ const Header = ({ children }: ITable) => {
}; };
const Body = <T,>({ data, render }: ITableBody<T>) => { const Body = <T,>({ data, render }: ITableBody<T>) => {
if (data && data.length > 0) data!.length > 0 && (
return <StyledBody>{data?.map(render as CallbackMapFunc<T>)}</StyledBody>; <StyledBody>{data?.map(render as CallbackMapFunc<T>)}</StyledBody>
);
}; };
const Row = ({ children }: ITable) => { const Row = ({ children }: ITable) => {