Skip to content

Commit

Permalink
Review some and clean up in the interfaces (#133) (#134)
Browse files Browse the repository at this point in the history
* moved avatar interface to global

* removed unused import

* moved IDefaultAvatar to global, and renamed from DefaultAvatarProps

* Typoghraphy constants: Update avatar component typography constants

* Add typography constants

* Add typography constants

---------

Co-authored-by: triple iii <[email protected]>
  • Loading branch information
ballyalley-o and in-a-iii authored Apr 14, 2024
1 parent dcf7837 commit 03142cd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
20 changes: 6 additions & 14 deletions src/component/avatar/avatar-default.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, forwardRef } from 'react'
import { useTheme } from '@mui/material/styles'
import { Badge, Avatar, Typography } from '@mui/material'
import { KEY, SizeType } from 'constant'
import { KEY, TYPOGRAPHY, FONTWEIGHT } from 'constant'

const getCharAtName = (name: string) => name && name.charAt(0).toUpperCase()
const getCharAtSecondName = (name: string) => name && name.split(' ')[1]?.charAt(0).toUpperCase()
Expand All @@ -15,18 +15,10 @@ const getColorByName = (name: string) => {
return KEY.DEFAULT
}

interface DefaultAvatarProps {
color?: COLOR
firstName?: string
lastName?: string
extension?: string
isLarge?: boolean
children?: React.ReactNode
BadgeProps?: object
sx?: object
}
const { H4, OVERLINE } = TYPOGRAPHY
const { BOLD, NORMAL } = FONTWEIGHT

const DefaultAvatar: FC<DefaultAvatarProps> = forwardRef<HTMLDivElement, DefaultAvatarProps>(
const DefaultAvatar: FC<IDefaultAvatar> = forwardRef<HTMLDivElement, IDefaultAvatar>(
({ color, firstName = '', lastName = '', BadgeProps, children, extension, isLarge, sx, ...other }, ref) => {
const theme = useTheme()
const charAtName = lastName ? getCharAtName(firstName) + getCharAtName(lastName) : getCharAtName(firstName)
Expand Down Expand Up @@ -61,10 +53,10 @@ const DefaultAvatar: FC<DefaultAvatarProps> = forwardRef<HTMLDivElement, Default
}}
{...other}>
<Typography
variant={isLarge ? 'h4' : 'overline'}
variant={isLarge ? H4 : OVERLINE}
color={theme.palette[colr].contrastText}
sx={{
fontWeight: isLarge ? 'bold' : 'normal'
fontWeight: isLarge ? BOLD : NORMAL
}}>
{firstName && charAtName}
</Typography>
Expand Down
1 change: 0 additions & 1 deletion src/component/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { FC, forwardRef } from 'react'
import { Link as RouterLink } from 'react-router-dom'
import { Box, Link } from '@mui/material'
import { GLOBAL } from 'config'
import DefaultAvatar from './avatar-default'

interface AvatarProps {
disabledLink?: boolean
Expand Down
1 change: 1 addition & 0 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export { default as MENU_POPOVER_ARROW } from './menu-popover-arrow'
export { default as TITLE } from './title'
export { default as ARIA } from './aria'
export { BUTTON } from './button'
export * from './typography'
export * from './size'
export * from './color'
27 changes: 27 additions & 0 deletions src/constant/typography.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export enum TYPOGRAPHY {
H0 = 'h0',
H1 = 'h1',
H2 = 'h2',
H3 = 'h3',
H4 = 'h4',
H5 = 'h5',
H6 = 'h6',
H7 = 'h7',
BODY1 = 'body1',
BODY2 = 'body2',
SUBTITLE1 = 'subtitle1',
SUBTITLE2 = 'subtitle2',
OVERLINE = 'overline',
CAPTION = 'caption',
BUTTON = 'button',
PARAGRAPH = 'paragraph'
}

export enum FONTWEIGHT {
NORMAL = 'normal',
LIGHT = 'light',
REGULAR = 'regular',
MEDIUM = 'medium',
BOLD = 'bold',
BLACK = 'black'
}
12 changes: 12 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ declare global {
xl?: number
}

interface IDefaultAvatar {
color?: COLOR
firstName?: string
lastName?: string
extension?: string
isLarge?: boolean
children?: React.ReactNode
BadgeProps?: object
sx?: object
}


interface EndpointBuilder {
/**
*
Expand Down

0 comments on commit 03142cd

Please sign in to comment.