mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
re-structure to monorepo.
This commit is contained in:
11
packages/webapp/src/components/Layout/Box/Box.tsx
Normal file
11
packages/webapp/src/components/Layout/Box/Box.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface BoxProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Box({ className, ...rest }: BoxProps) {
|
||||
const Element = 'div';
|
||||
|
||||
return <Element className={className} {...rest} />;
|
||||
}
|
||||
1
packages/webapp/src/components/Layout/Box/index.ts
Normal file
1
packages/webapp/src/components/Layout/Box/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './Box';
|
||||
56
packages/webapp/src/components/Layout/Group/Group.tsx
Normal file
56
packages/webapp/src/components/Layout/Group/Group.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Box } from '../Box';
|
||||
import { filterFalsyChildren } from './_utils';
|
||||
|
||||
export type GroupPosition = 'right' | 'center' | 'left' | 'apart';
|
||||
|
||||
export const GROUP_POSITIONS = {
|
||||
left: 'flex-start',
|
||||
center: 'center',
|
||||
right: 'flex-end',
|
||||
apart: 'space-between',
|
||||
};
|
||||
|
||||
export interface GroupProps extends React.ComponentPropsWithoutRef<'div'> {
|
||||
/** Defines justify-content property */
|
||||
position?: GroupPosition;
|
||||
|
||||
/** Defined flex-wrap property */
|
||||
noWrap?: boolean;
|
||||
|
||||
/** Defines flex-grow property for each element, true -> 1, false -> 0 */
|
||||
grow?: boolean;
|
||||
|
||||
/** Space between elements */
|
||||
spacing?: number;
|
||||
|
||||
/** Defines align-items css property */
|
||||
align?: React.CSSProperties['alignItems'];
|
||||
}
|
||||
|
||||
const defaultProps: Partial<GroupProps> = {
|
||||
position: 'left',
|
||||
spacing: 20,
|
||||
};
|
||||
|
||||
export function Group({ children, ...props }: GroupProps) {
|
||||
const groupProps = {
|
||||
...defaultProps,
|
||||
...props,
|
||||
};
|
||||
const filteredChildren = filterFalsyChildren(children);
|
||||
|
||||
return <GroupStyled {...groupProps}>{filteredChildren}</GroupStyled>;
|
||||
}
|
||||
|
||||
const GroupStyled = styled(Box)`
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex-wrap: ${(props: GroupProps) => (props.noWrap ? 'nowrap' : 'wrap')};
|
||||
justify-content: ${(props: GroupProps) =>
|
||||
GROUP_POSITIONS[props.position || 'left']};
|
||||
gap: ${(props: GroupProps) => props.spacing}px;
|
||||
`;
|
||||
5
packages/webapp/src/components/Layout/Group/_utils.ts
Normal file
5
packages/webapp/src/components/Layout/Group/_utils.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Children, ReactElement, ReactNode } from 'react';
|
||||
|
||||
export function filterFalsyChildren(children: ReactNode) {
|
||||
return (Children.toArray(children) as ReactElement[]).filter(Boolean);
|
||||
}
|
||||
1
packages/webapp/src/components/Layout/Group/index.ts
Normal file
1
packages/webapp/src/components/Layout/Group/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './Group';
|
||||
36
packages/webapp/src/components/Layout/Stack/Stack.tsx
Normal file
36
packages/webapp/src/components/Layout/Stack/Stack.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Box } from '../Box';
|
||||
|
||||
export interface StackProps extends React.ComponentPropsWithoutRef<'div'> {
|
||||
/** Key of theme.spacing or number to set gap in px */
|
||||
spacing?: number;
|
||||
|
||||
/** align-items CSS property */
|
||||
align?: React.CSSProperties['alignItems'];
|
||||
|
||||
/** justify-content CSS property */
|
||||
justify?: React.CSSProperties['justifyContent'];
|
||||
}
|
||||
|
||||
const defaultProps: Partial<StackProps> = {
|
||||
spacing: 20,
|
||||
align: 'stretch',
|
||||
justify: 'top',
|
||||
};
|
||||
|
||||
export function Stack(props: StackProps) {
|
||||
const stackProps = {
|
||||
...defaultProps,
|
||||
...props,
|
||||
};
|
||||
return <StackStyled {...stackProps} />;
|
||||
}
|
||||
|
||||
const StackStyled = styled(Box)`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: align;
|
||||
justify-content: justify;
|
||||
gap: ${(props: StackProps) => props.spacing}px;
|
||||
`;
|
||||
1
packages/webapp/src/components/Layout/Stack/index.ts
Normal file
1
packages/webapp/src/components/Layout/Stack/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './Stack';
|
||||
3
packages/webapp/src/components/Layout/index.ts
Normal file
3
packages/webapp/src/components/Layout/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './Box';
|
||||
export * from './Group';
|
||||
export * from './Stack';
|
||||
Reference in New Issue
Block a user