Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat: improve component lib
Browse files Browse the repository at this point in the history
  • Loading branch information
rudigier committed Mar 24, 2023
1 parent b7814ee commit b631f7d
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/components/Atoms/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type TGrid = {
/*
* Styles
*/
export const GridBaseStyle = 'flex';
export const GridBaseStyle = 'flex w-full';

export const GridVariantStyleMap: Record<string, string> = {
row: 'flex-row',
Expand Down
1 change: 1 addition & 0 deletions src/components/Atoms/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const Link = Template.bind({});
Link.args = {
children: 'Link',
href: '/',
newTab: true,
};
106 changes: 0 additions & 106 deletions src/components/Molecules/IconLink/IconLink.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Molecules/IconLink/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';

import { IconNames } from '../../Atoms/Icon/IconLib';
import { IconLink as Component, IconLinkSizeMap, IconLinkColorMap } from './IconLink';
import { IconText as Component, IconTextSizeMap, IconTextColorMap } from './IconText';

export default {
title: 'Components/Molecules/IconLink',
title: 'Components/Molecules/IconText',
component: Component,
argTypes: {
icon: {
Expand All @@ -14,16 +14,16 @@ export default {
},
size: {
control: { type: 'radio' },
options: Object.keys(IconLinkSizeMap),
options: Object.keys(IconTextSizeMap),
},
colorScheme: {
control: { type: 'radio' },
options: Object.keys(IconLinkColorMap),
options: Object.keys(IconTextColorMap),
},
},
} as ComponentMeta<typeof Component>;

const Template: ComponentStory<typeof Component> = (args): JSX.Element => <Component {...args} />;

export const IconLink = Template.bind({});
IconLink.args = {};
export const IconText = Template.bind({});
IconText.args = {};
88 changes: 88 additions & 0 deletions src/components/Molecules/IconText/IconText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { FC, ReactNode } from 'react';

import { Icon, TIconSize, TIconName } from '../../Atoms/Icon/Icon';

/*
* Type
*/

type TIconTextSize = keyof typeof IconTextSizeMap;
type TIconTextColor = keyof typeof IconTextColorMap;

type TIconText = {
/**
* React Children: here most probably text
*/
children: ReactNode;

/**
* text size options of this button (S, M, L)
*/
size?: TIconTextSize;

/**
* color scheme options of this button (slate, violet, gradient)
*/
colorScheme: TIconTextColor;

/**
* icon name to render
*/
icon: TIconName;
};

/*
* Style
*/

const IconTextBaseStyle: string[] = ['flex items-center', 'leading-none', 'rounded-full'];

export const IconTextSizeMap: Record<string, string> = {
S: 'text-sm gap-1 px-2 py-1',
M: 'text-base gap-2 px-3 py-2',
L: 'text-xl gap-2 px-4 py-3',
};

export const IconTextColorMap: Record<string, string> = {
slate: 'text-slate-400 hover:text-slate-600 hover:bg-slate-100 ',
violet: 'text-violet-600 hover:text-violet-900 hover:bg-violet-50 ',
pink: ' text-pink-400 hover:text-pink-600 hover:bg-pink-50',
};

/**
* IconText component
*
* @param {string} children - React Children: here most probably text
* @param {string} as - HTML tag to render a button (button, a, span)
* @param {string} size - text size options of this button (S, M, L)
* @param {string} colorScheme - color scheme options of this button (slate, violet, gradient)
* @param {string} icon - icon name to render
*
* @example <IconText icon="arrowRight" colorScheme="slate" size="M">IconText</IconText>
* /
/*
* State
*/

export const IconText: FC<TIconText> = ({ children = 'IconText', colorScheme = 'slate', size = 'M', icon, ...props }) => {
const styles = [
...IconTextBaseStyle,
IconTextSizeMap[size],
IconTextColorMap[colorScheme],
'group',
'transition-all duration-300',
];

return (
<span
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{...(props as any)}
className={styles.join(' ')}
>
<Icon name={icon} size={size as TIconSize} />
{children}
</span>
);
};
1 change: 1 addition & 0 deletions src/components/Molecules/IconText/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './IconText';
19 changes: 0 additions & 19 deletions src/components/Molecules/UserName/UserName.stories.tsx

This file was deleted.

34 changes: 0 additions & 34 deletions src/components/Molecules/UserName/UserName.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Molecules/UserName/index.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/components/Organisms/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const ModalBaseStyle = [
'bg-white rounded-2xl shadow-lg sm:rounded-none sm:shadow-none ',
];
const ModalOverlayStyle = ['fixed inset-0 z-40', 'opacity-25 bg-violet-600'];
const ModalBodyStyle = ['relative flex flex-col w-full overflow-x-hidden max-w-screen max-h-screen min-w-full'];
const ModalBodyStyle = [
'relative flex flex-col w-full overflow-x-hidden max-w-screen max-h-screen min-w-full sm:rounded-none sm:shadow-none sm:h-full',
];
const ModalHeaderStyle = ['flex items-center justify-between gap-4', 'px-8 py-6', 'bg-violet-600 text-white'];

/**
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ export * from './components/Atoms/TimeStamp';
export * from './components/Molecules/Button';
export * from './components/Molecules/Card';
export * from './components/Molecules/Form';
export * from './components/Molecules/IconLink';
export * from './components/Molecules/IconText';
export * from './components/Molecules/ImageOverlay';
export * from './components/Molecules/InteractionButton';
export * from './components/Molecules/Navi';
export * from './components/Molecules/RoundButton';
export * from './components/Molecules/Switch';
export * from './components/Molecules/UserName';
export * from './components/Molecules/UserProfile';
export * from './components/Organisms/CopyToClipboardButton';
export * from './components/Organisms/Modal';
Expand Down
6 changes: 6 additions & 0 deletions src/styles/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
body {
@apply bg-slate-100 dark:bg-slate-900 text-slate-900 dark:text-slate-100;
}
}
13 changes: 8 additions & 5 deletions src/templates/Snippets/ContentCard/ContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { Image } from '../../../components/Atoms/Image';
import { Richtext } from '../../../components/Atoms/Richtext';
import { Label } from '../../../components/Atoms/Label';

import { UserName } from '../../../components/Molecules/UserName';
import { IconLink } from '../../../components/Molecules/IconLink';
import { IconText } from '../../../components/Molecules/IconText';
import { ImageOverlay } from '../../../components/Molecules/ImageOverlay';
import { InteractionButton } from '../../../components/Molecules/InteractionButton';

Expand Down Expand Up @@ -68,10 +67,14 @@ export const ContentCard: FC<TContentCard> = ({ variant, post }) => {
{post.author.fullName}
</Label>
<Grid variant="row" gap="S">
<UserName href={post.author.profileLink}>{post.author.userName}</UserName>
<IconLink as="span" icon="calendar" colorScheme="slate" size="S">
<a href={post.author.profileLink}>
<IconText icon="profile" colorScheme="violet" size="S">
{post.author.userName}
</IconText>
</a>
<IconText icon="calendar" colorScheme="slate" size="S">
<TimeStamp date={post.createdAt} />
</IconLink>
</IconText>
</Grid>
</Grid>
);
Expand Down
8 changes: 6 additions & 2 deletions src/templates/Snippets/ContentInput/ContentInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { FC } from 'react';
import { Grid } from '../../../components/Atoms/Grid/Grid';
import { Label } from '../../../components/Atoms/Label';

import { UserName } from '../../../components/Molecules/UserName';
import { IconText } from '../../../components/Molecules/IconText';
import { Button } from '../../../components/Molecules/Button';
import { FormTextarea } from '../../../components/Molecules/Form/FormTextarea';

Expand Down Expand Up @@ -54,7 +54,11 @@ export const ContentInput: FC<TContentInput> = (props) => {
{author.fullName}
</Label>
<Grid variant="row" gap="S">
<UserName href={author.profileLink}>{author.userName}</UserName>
<a href={author.profileLink}>
<IconText icon="profile" colorScheme="violet" size="S">
{author.userName}
</IconText>
</a>
</Grid>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit b631f7d

Please sign in to comment.