From 87de46235243bc479a0d1bd92e689f72ff71df83 Mon Sep 17 00:00:00 2001 From: Wahyu Kurniawan Date: Wed, 21 Feb 2024 13:09:25 +0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20avoid=20big=20?= =?UTF-8?q?conflict=20on=20the=20example=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/pages/components/index.tsx | 165 ++++-------------- .../src/pages/components/renders/avatar.tsx | 19 ++ .../src/pages/components/renders/badge.tsx | 20 +++ .../src/pages/components/renders/button.tsx | 49 ++++++ .../src/pages/components/renders/checkbox.tsx | 27 +++ .../src/pages/components/renders/tabs.tsx | 37 ++++ 6 files changed, 189 insertions(+), 128 deletions(-) create mode 100644 packages/frontend/src/pages/components/renders/avatar.tsx create mode 100644 packages/frontend/src/pages/components/renders/badge.tsx create mode 100644 packages/frontend/src/pages/components/renders/button.tsx create mode 100644 packages/frontend/src/pages/components/renders/checkbox.tsx create mode 100644 packages/frontend/src/pages/components/renders/tabs.tsx diff --git a/packages/frontend/src/pages/components/index.tsx b/packages/frontend/src/pages/components/index.tsx index 456f433e..19e3aa73 100644 --- a/packages/frontend/src/pages/components/index.tsx +++ b/packages/frontend/src/pages/components/index.tsx @@ -1,43 +1,19 @@ -import { Avatar, AvatarVariants } from 'components/shared/Avatar'; -import { Badge, BadgeProps } from 'components/shared/Badge'; -import { Button, ButtonOrLinkProps } from 'components/shared/Button'; -import { Calendar } from 'components/shared/Calendar'; -import { Checkbox } from 'components/shared/Checkbox'; -import { PlusIcon } from 'components/shared/CustomIcon'; import React, { useState } from 'react'; +import { Calendar } from 'components/shared/Calendar'; import { Value } from 'react-calendar/dist/cjs/shared/types'; - -const avatarSizes: AvatarVariants['size'][] = [18, 20, 24, 28, 32, 36, 40, 44]; -const avatarVariants: AvatarVariants['type'][] = ['gray', 'orange', 'blue']; +import { + renderCheckbox, + renderCheckboxWithDescription, +} from './renders/checkbox'; +import { avatars, avatarsFallback } from './renders/avatar'; +import { renderBadges } from './renders/badge'; +import { renderButtonIcons, renderButtons } from './renders/button'; +import { renderTabWithBadges, renderTabs } from './renders/tabs'; const Page = () => { const [singleDate, setSingleDate] = useState(); const [dateRange, setDateRange] = useState(); - const avatars = avatarSizes.map((size) => { - return ( - - ); - }); - - const avatarsFallback = avatarVariants.map((color) => { - return avatarSizes.map((size) => { - return ( - - ); - }); - }); - return (
@@ -51,114 +27,36 @@ const Page = () => {
- {/* Insert Components here */} + {/* Button */}

Button

- {['primary', 'secondary', 'tertiary', 'danger'].map( - (variant, index) => ( -
- {['lg', 'md', 'sm', 'xs', 'disabled'].map((size) => ( - - ))} -
- ), - )} - {[ - 'primary', - 'secondary', - 'tertiary', - 'ghost', - 'danger', - 'danger-ghost', - ].map((variant, index) => ( -
- {['lg', 'md', 'sm', 'xs', 'disabled'].map((size) => ( - - ))} -
- ))} + {renderButtons()} + {renderButtonIcons()}
+ {/* Badge */}

Badge

-
- {['primary', 'secondary', 'tertiary', 'inset'].map( - (variant, index) => ( -
- {['sm', 'xs'].map((size) => ( - - 1 - - ))} -
- ), - )} -
+
{renderBadges()}
+ {/* Checkbox */}

Checkbox

+
{renderCheckbox()}
- {Array.from({ length: 5 }).map((_, index) => ( - - ))} -
-
- {Array.from({ length: 2 }).map((_, index) => ( - - ))} + {renderCheckboxWithDescription()}
+ {/* Calendar */}

Calendar

@@ -185,16 +83,27 @@ const Page = () => { />
+
-
+
- {/* Avatar */} -
-

Avatar

-
- {avatars} - {avatarsFallback} -
+ {/* Avatar */} +
+

Avatar

+
+ {avatars} + {avatarsFallback} +
+
+ +
+ + {/* Tabs */} +
+

Tabs

+
+ {renderTabs()} + {renderTabWithBadges()}
diff --git a/packages/frontend/src/pages/components/renders/avatar.tsx b/packages/frontend/src/pages/components/renders/avatar.tsx new file mode 100644 index 00000000..9ebaa03f --- /dev/null +++ b/packages/frontend/src/pages/components/renders/avatar.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Avatar, AvatarVariants } from 'components/shared/Avatar'; + +const avatarSizes: AvatarVariants['size'][] = [18, 20, 24, 28, 32, 36, 40, 44]; +const avatarVariants: AvatarVariants['type'][] = ['gray', 'orange', 'blue']; + +export const avatars = avatarSizes.map((size) => { + return ( + + ); +}); + +export const avatarsFallback = avatarVariants.map((color) => { + return avatarSizes.map((size) => { + return ( + + ); + }); +}); diff --git a/packages/frontend/src/pages/components/renders/badge.tsx b/packages/frontend/src/pages/components/renders/badge.tsx new file mode 100644 index 00000000..e4eb3114 --- /dev/null +++ b/packages/frontend/src/pages/components/renders/badge.tsx @@ -0,0 +1,20 @@ +import React from 'react'; + +import { Badge } from 'components/shared/Badge'; +import { BadgeTheme } from 'components/shared/Badge/Badge.theme'; + +export const renderBadges = () => { + return ['primary', 'secondary', 'tertiary', 'inset'].map((variant, index) => ( +
+ {['sm', 'xs'].map((size) => ( + + 1 + + ))} +
+ )); +}; diff --git a/packages/frontend/src/pages/components/renders/button.tsx b/packages/frontend/src/pages/components/renders/button.tsx new file mode 100644 index 00000000..c1c69c48 --- /dev/null +++ b/packages/frontend/src/pages/components/renders/button.tsx @@ -0,0 +1,49 @@ +import { Button, ButtonTheme } from 'components/shared/Button'; +import { PlusIcon } from 'components/shared/CustomIcon'; +import React from 'react'; + +export const renderButtons = () => { + return ['primary', 'secondary', 'tertiary', 'danger'].map( + (variant, index) => ( +
+ {['lg', 'md', 'sm', 'xs', 'disabled'].map((size) => ( + + ))} +
+ ), + ); +}; + +export const renderButtonIcons = () => { + return [ + 'primary', + 'secondary', + 'tertiary', + 'ghost', + 'danger', + 'danger-ghost', + ].map((variant, index) => ( +
+ {['lg', 'md', 'sm', 'xs', 'disabled'].map((size) => ( + + ))} +
+ )); +}; diff --git a/packages/frontend/src/pages/components/renders/checkbox.tsx b/packages/frontend/src/pages/components/renders/checkbox.tsx new file mode 100644 index 00000000..66c9eef5 --- /dev/null +++ b/packages/frontend/src/pages/components/renders/checkbox.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { Checkbox } from 'components/shared/Checkbox'; + +export const renderCheckbox = () => { + return Array.from({ length: 5 }).map((_, index) => ( + + )); +}; + +export const renderCheckboxWithDescription = () => { + return Array.from({ length: 2 }).map((_, index) => ( + + )); +}; diff --git a/packages/frontend/src/pages/components/renders/tabs.tsx b/packages/frontend/src/pages/components/renders/tabs.tsx new file mode 100644 index 00000000..ab5dbc78 --- /dev/null +++ b/packages/frontend/src/pages/components/renders/tabs.tsx @@ -0,0 +1,37 @@ +import React from 'react'; +import { Tabs } from 'components/shared/Tabs'; +import { Badge } from 'components/shared/Badge'; + +const tabs = Array.from({ length: 8 }); + +export const renderTabs = () => { + return ( + + + {tabs.map((_, index) => ( + + Tab item {index} + + ))} + + + ); +}; + +export const renderTabWithBadges = () => { + return ( + + + {tabs.map((_, index) => ( + {index}} + > + Tab item + + ))} + + + ); +};