Skip to content

Commit

Permalink
Merge pull request #5 from BrahimS/primitive-ui
Browse files Browse the repository at this point in the history
feat(ui): optimize flexbox, box, and heading components
  • Loading branch information
BrahimS authored Oct 7, 2024
2 parents eb6e7e6 + 16e4729 commit 4b813a1
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 197 deletions.
39 changes: 22 additions & 17 deletions apps/uikit/src/app/components/StyleGuide/Typography/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
FlexBox,
Heading,
ParagraphContainer,
TagLabel,
TagText,
TagUnderlinedText,
TypographySectionWrapper,
Box,
theme,
} from '@react-monorepo/shared-ui';
import { Link } from 'react-router-dom';

Expand All @@ -15,22 +14,28 @@ export const TypographyExample: React.FC<{
children: React.ReactNode;
}> = ({ tag, children }) => (
<FlexBox
direction="row"
gap="4"
wrap="nowrap"
justify="between"
align="center"
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'start',
}}
>
<TagLabel>
<TagText>{tag}</TagText>
</TagLabel>
<TagText style={{ marginRight: '1.5rem' }}>{tag}</TagText>
<Heading as={tag}> {children}</Heading>
</FlexBox>
);

export const TypographySection: React.FC = () => (
<TypographySectionWrapper $isbig>
<TagUnderlinedText>Typography</TagUnderlinedText>
<Box
w="60%"
as={'div'}
asChild={false}
shadow={theme.shadows.medium}
borderRadius={theme.spacing.sm}
p={theme.spacing.sm}
>
<TagText>Typography</TagText>
<ul style={{ marginBottom: '1.5rem' }}>
<li>Font family: Poppins</li>
<li>
Expand All @@ -40,7 +45,7 @@ export const TypographySection: React.FC = () => (
</Link>
</li>
</ul>
<TagUnderlinedText>Headlines</TagUnderlinedText>
<TagText>Headlines</TagText>
<TypographyExample tag="h1">This is the styleguide</TypographyExample>
<TypographyExample tag="h2">This is the styleguide</TypographyExample>
<TypographyExample tag="h3">This is the styleguide</TypographyExample>
Expand All @@ -50,16 +55,16 @@ export const TypographySection: React.FC = () => (
direction="column"
gap="0"
wrap="nowrap"
justify="between"
justify="space-between"
align="start"
>
<TagUnderlinedText>Paragraph</TagUnderlinedText>
<TagText>Paragraph</TagText>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur
dolore rem modi laboriosam deleniti vitae. Aspernatur saepe itaque,
numquam autem inventore, magnam, aperiam quidem quis ea id minima nemo
corporis!
</p>
</ParagraphContainer>
</TypographySectionWrapper>
</Box>
);
105 changes: 61 additions & 44 deletions apps/uikit/src/app/pages/Styleguide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,81 @@ import {
Container,
FlexBox,
Heading,
StyleguideContainer,
TagUnderlinedText,
TagText,
theme,
TypographySectionWrapper,
} from '@react-monorepo/shared-ui';
import { TypographySection } from '../components/StyleGuide/Typography';

// Main Styleguide page
const Styleguide: React.FC = () => {
return (
<Container size="xl">
<Heading as="h1">UI Kit Library</Heading>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Atque
voluptatem distinctio eveniet voluptatum est iste, laudantium a officiis
architecto, aspernatur veniam provident harum assumenda tempora dolorum!
</p>
<Box w="100%" as="div" asChild>
<Heading as="h1">UI Kit Library</Heading>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Atque
voluptatem distinctio eveniet voluptatum est iste, laudantium a
officiis architecto, aspernatur veniam provident harum assumenda
tempora dolorum!
</p>
</Box>

<FlexBox
gap="1"
wrap="wrap"
align="start"
justify="start"
style={{ width: '40%' }}
>
<TypographySectionWrapper $isbig={false} style={{ width: '100%' }}>
<TagUnderlinedText>Colors</TagUnderlinedText>
</TypographySectionWrapper>
{Object.entries(colorScheme).map(([key, value]) => (
<Box
key={key}
w="100px"
h="100px"
style={{
backgroundColor: value,
borderRadius: theme.spacing.md,
color:
value === theme.colors.white || value === theme.colors.cream
? theme.colors.black
: theme.colors.white,
boxSizing: 'border-box',
minWidth: '100px',
maxWidth: '100px',
textAlign: 'center',
}}
>
{key}
</Box>
))}
</FlexBox>
<StyleguideContainer
style={{
width: '100%',
}}
display="flex"
direction="row"
justify="space-between"
gap="4"
align="start"
justify="between"
wrap="nowrap"
align="start"
>
<Box
display="flex"
flexDirection="row"
justifyContent="space-between"
alignItems="start"
flexWrap="wrap"
w="38%"
p={theme.spacing.sm}
shadow={theme.shadows.medium}
borderRadius={theme.spacing.sm}
as={'div'}
asChild={false}
>
<Box as="div" asChild w="100%" p="8px 0">
<TagText>Colors</TagText>
</Box>
{Object.entries(colorScheme).map(([key, value]) => (
<Box
key={key}
w="100px"
h="100px"
display="flex"
flexDirection="column"
justifyContent="center"
alignItems="center"
shadow={theme.shadows.medium}
flexWrap="wrap"
borderRadius={theme.spacing.xs}
m={theme.spacing.xs}
bg={value}
style={{
color:
value === theme.colors.white || value === theme.colors.cream
? theme.colors.black
: theme.colors.white,
}}
as="div"
asChild
>
{key}
</Box>
))}
</Box>
<TypographySection />
</StyleguideContainer>
</FlexBox>
</Container>
);
};
Expand Down
52 changes: 41 additions & 11 deletions shared-ui/src/lib/Grid/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
import React from 'react';
import { BoxWrapper } from '../styles';
import { Responsive } from '@radix-ui/themes/dist/cjs/props/prop-def';
interface BoxProps {
as: 'div' | 'span';
asChild: boolean;
shadow?: string;
borderRadius?: string;
display?: Responsive<'none' | 'inline' | 'inline-block' | 'block' | 'flex'>;
flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
justifyContent?: 'space-between' | 'center' | 'start' | 'end' | 'between';
alignItems?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
flexWrap?: 'wrap' | 'nowrap';
w?: string;
h?: string;
p?: string;
m?: string;
style?: React.CSSProperties;
bg?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
}

export const Box = ({
asChild,
as,
display,
w,
h,
p,
m,
style,
bg,
shadow,
borderRadius,
children,
flexDirection,
justifyContent,
alignItems,
flexWrap,
...props
}: BoxProps): React.ReactNode => {
return (
<BoxWrapper
width={w}
height={h}
style={{ margin: m, padding: p, backgroundColor: bg, ...style }}
{...props}
>
{children}
</BoxWrapper>
return React.createElement(
asChild ? 'div' : as,
{
...props,
style: {
display: display,
flexDirection: flexDirection,
justifyContent: justifyContent,
alignItems: alignItems,
flexWrap: flexWrap,
width: w,
height: h,
padding: p,
margin: m,
borderRadius: borderRadius,
background: bg,
boxShadow: shadow,
...style,
},
},
children,
);
};
35 changes: 22 additions & 13 deletions shared-ui/src/lib/Grid/FlexBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { FlexBoxProps, FlexWrapper } from '../styles';
import { FlexBoxProps } from '../styles';

export const FlexBox = ({
display,
children,
direction,
gap,
Expand All @@ -11,17 +12,25 @@ export const FlexBox = ({
style,
...props
}: FlexBoxProps) => {
return (
<FlexWrapper
direction={direction}
gap={gap}
align={align}
justify={justify}
wrap={wrap}
style={style}
{...props}
>
{children}
</FlexWrapper>
return React.createElement(
'div',
{
direction,
gap,
align,
justify,
wrap,
...props,
style: {
display: display,
flexDirection: direction,
justifyContent: justify,
alignItems: align,
flexWrap: wrap,

...style,
},
},
children,
);
};
42 changes: 42 additions & 0 deletions shared-ui/src/lib/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';

interface TextProps {
children: React.ReactNode;
as: 'span' | 'div' | 'label' | 'p';
color?: string;
style?: React.CSSProperties;
role: string;
truncate?: boolean;
align?: 'left' | 'center' | 'right';
weight?: string;
size?: string;
lineheight?: string;
}

export const Text = ({
children,
as,
color,
style,
role,
truncate,
align,
weight,
size,
lineheight,
}: TextProps) => {
return React.createElement(
as,
{
role: 'textbox',
style,
color,
truncate,
align,
weight,
size,
lineheight,
},
children,
);
};
4 changes: 3 additions & 1 deletion shared-ui/src/lib/styles/GlobalStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const GlobalStyle = createGlobalStyle`
/* Global Styles */
html {
box-sizing: border-box;
font-size: 16px; /* Set base font size */
font-size: 1rem; /* Set base font size */
overflow-y: scroll;
overflow-x: hidden;
scroll-behavior: smooth;
Expand All @@ -80,6 +80,8 @@ export const GlobalStyle = createGlobalStyle`
line-height: ${theme.typography.lineHeight.heading};
color: ${theme.colors.text.primary};
font-family: ${theme.typography.fontFamily};
}
h1 {
Expand Down
Loading

0 comments on commit 4b813a1

Please sign in to comment.