Skip to content

Commit

Permalink
refactor :: add hstack
Browse files Browse the repository at this point in the history
  • Loading branch information
dutexion committed Nov 9, 2024
1 parent 0b6eda5 commit 37893cd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/components/Layouts/HStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { IChildren } from '@/utils/types/components/children';
import styled from '@emotion/styled';

interface IProps extends IChildren {
widthFit?: boolean;
gap?: number;
align?: 'top' | 'center' | 'bottom';
justify?: 'left' | 'right' | 'center' | 'between';
}

export const HStack = ({ children, widthFit = true, gap = 0, justify = 'center', align = 'top' }: IProps) => (
<Wrapper widthFit={widthFit} gap={gap} justify={justify} align={align}>
{children}
</Wrapper>
);

const Wrapper = styled.div<Omit<IProps, 'children'>>`
display: flex;
flex-direction: row;
align-items: ${({ align }) => {
switch (align) {
case 'top':
return 'start';
case 'bottom':
return 'end';
default:
return 'center';
}
}};
justify-content: ${({ justify }) => {
switch (justify) {
case 'left':
return 'start';
case 'right':
return 'end';
case 'center':
return 'center';
case 'between':
return 'space-between';
}
}};
gap: ${({ gap }) => `${gap}px`};
width: ${({ widthFit }) => (widthFit ? '100%' : 'auto')};
`;

0 comments on commit 37893cd

Please sign in to comment.