From 8885cd0ba25af5cd758ade5f026580ad088d42ea Mon Sep 17 00:00:00 2001 From: QiShaoXuan Date: Fri, 9 Dec 2022 01:36:57 +0800 Subject: [PATCH] feat: add layout component --- packages/app/src/ui/Layout/content.tsx | 23 ++++++++++++ packages/app/src/ui/Layout/index.ts | 2 ++ packages/app/src/ui/Layout/styles.ts | 50 ++++++++++++++++++++++++++ packages/app/src/ui/Layout/wrapper.tsx | 42 ++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 packages/app/src/ui/Layout/content.tsx create mode 100644 packages/app/src/ui/Layout/index.ts create mode 100644 packages/app/src/ui/Layout/styles.ts create mode 100644 packages/app/src/ui/Layout/wrapper.tsx diff --git a/packages/app/src/ui/Layout/content.tsx b/packages/app/src/ui/Layout/content.tsx new file mode 100644 index 0000000000..ed0ccf1ec0 --- /dev/null +++ b/packages/app/src/ui/Layout/content.tsx @@ -0,0 +1,23 @@ +import React, { CSSProperties, HTMLAttributes, PropsWithChildren } from 'react'; +import { StyledContent } from '@/ui/Layout/styles'; + +// This component should be just used to be contained the text content +export type ContentProps = { + width?: CSSProperties['width']; + maxWidth?: CSSProperties['maxWidth']; + color?: CSSProperties['color']; + fontSize?: CSSProperties['fontSize']; + fontWeight?: CSSProperties['fontWeight']; + lineHeight?: CSSProperties['lineHeight']; + ellipsis?: boolean; + lineNum?: number; + children: string; +}; +export const Content = ({ + children, + ...props +}: ContentProps & HTMLAttributes) => { + return {children}; +}; + +export default Content; diff --git a/packages/app/src/ui/Layout/index.ts b/packages/app/src/ui/Layout/index.ts new file mode 100644 index 0000000000..fdca622500 --- /dev/null +++ b/packages/app/src/ui/Layout/index.ts @@ -0,0 +1,2 @@ +export * from './wrapper'; +export * from './content'; diff --git a/packages/app/src/ui/Layout/styles.ts b/packages/app/src/ui/Layout/styles.ts new file mode 100644 index 0000000000..e4043f6831 --- /dev/null +++ b/packages/app/src/ui/Layout/styles.ts @@ -0,0 +1,50 @@ +import { styled, textEllipsis } from '@/styles'; +import { WrapperProps } from './wrapper'; +import { ContentProps } from '@/ui/Layout/content'; + +export const StyledWrapper = styled.div( + ({ + display, + justifyContent, + alignItems, + flexWrap, + flexDirection, + flexShrink, + flexGrow, + }) => { + return { + display, + justifyContent, + alignItems, + flexWrap, + flexDirection, + flexShrink, + flexGrow, + }; + } +); + +export const StyledContent = styled.div( + ({ + theme, + color, + fontSize, + fontWeight, + lineHeight, + ellipsis, + lineNum, + width, + maxWidth, + }) => { + return { + width, + maxWidth, + display: 'inline-block', + color: color ?? theme.colors.textColor, + fontSize: fontSize ?? theme.font.base, + fontWeight: fontWeight ?? 400, + lineHeight: lineHeight ?? 1.5, + ...(ellipsis ? textEllipsis(lineNum) : {}), + }; + } +); diff --git a/packages/app/src/ui/Layout/wrapper.tsx b/packages/app/src/ui/Layout/wrapper.tsx new file mode 100644 index 0000000000..ea16ab7027 --- /dev/null +++ b/packages/app/src/ui/Layout/wrapper.tsx @@ -0,0 +1,42 @@ +import type { CSSProperties, HTMLAttributes, PropsWithChildren } from 'react'; +import { StyledWrapper } from './styles'; + +// Sometimes we just want to wrap a component with a div to set flex or other styles, but we don't want to create a new component for it. +export type WrapperProps = { + display?: CSSProperties['display']; + flexDirection?: CSSProperties['flexDirection']; + justifyContent?: CSSProperties['justifyContent']; + alignItems?: CSSProperties['alignItems']; + flexWrap?: CSSProperties['flexWrap']; + flexShrink?: CSSProperties['flexShrink']; + flexGrow?: CSSProperties['flexGrow']; +}; + +export const Wrapper = ({ + children, + display = 'flex', + justifyContent = 'flex-start', + alignItems = 'center', + flexWrap = 'nowrap', + flexDirection = 'row', + flexShrink = '0', + flexGrow = '0', + ...props +}: PropsWithChildren>) => { + return ( + + {children} + + ); +}; + +export default Wrapper;