-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Lilypad-Tech/nadiem/feat-badge-component
feat: add badge component to leaderboard page
- Loading branch information
Showing
7 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import BadgeWrapper from "./BadgeWrapper"; | ||
import BadgeIconAtom from "./BadgeIconAtom"; | ||
import { BadgeColor, BadgeIcon, BadgeSize, BadgeType } from "./BadgeTypes"; | ||
import BadgeTextAtom from "./BadgeTextAtom"; | ||
|
||
export interface BadgeProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
color: BadgeColor; | ||
badgeType: BadgeType; | ||
icon?: BadgeIcon; | ||
size: BadgeSize; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Badge = ({ | ||
color, | ||
badgeType, | ||
icon, | ||
size, | ||
children, | ||
...props | ||
}: BadgeProps) => { | ||
return ( | ||
<BadgeWrapper {...props} color={color} badgeType={badgeType} size={size}> | ||
{icon && icon.type === "icon" && icon.leading && ( | ||
<BadgeIconAtom | ||
className={icon.className} | ||
iconUrl={icon.leading} | ||
badgeType={badgeType} | ||
color={color} | ||
size={size} | ||
/> | ||
)} | ||
<BadgeTextAtom size={size}>{children}</BadgeTextAtom> | ||
</BadgeWrapper> | ||
); | ||
}; | ||
|
||
export default Badge; |
55 changes: 55 additions & 0 deletions
55
apps/info-dashboard/src/components/Badge/BadgeIconAtom.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { CustomCSSProperties } from "@/types"; | ||
import { | ||
BadgeColor, | ||
BadgeSize, | ||
BadgeStyleLayers, | ||
BadgeType, | ||
} from "./BadgeTypes"; | ||
|
||
interface BadgeIconProps extends React.HTMLAttributes<HTMLSpanElement> { | ||
iconUrl: string; | ||
color: BadgeColor; | ||
badgeType: BadgeType; | ||
size: BadgeSize; | ||
} | ||
|
||
export let src: string; | ||
|
||
const BadgeIconAtom = ({ | ||
iconUrl, | ||
color, | ||
badgeType, | ||
size, | ||
...props | ||
}: BadgeIconProps) => { | ||
const spanStyle: CustomCSSProperties = { | ||
"--icon-url": `url(${iconUrl})`, | ||
}; | ||
|
||
const layer1 = | ||
"[mask-position:center] [mask-size:contain] [mask-repeat:no-repeat] [mask-image:var(--icon-url)] h-uui-lg w-uui-lg"; | ||
|
||
const iconStyle: BadgeStyleLayers = { | ||
"Pill outline": { | ||
gray: "bg-uui-utility-gray-600", | ||
brand: "bg-uui-utility-brand-600", | ||
warning: "bg-uui-utility-warning-600", | ||
pink: "bg-uui-utility-pink-600", | ||
}, | ||
}; | ||
|
||
const sizes = { | ||
sm: "-mx-uui-xxs only:-mx-uui-xs only:py-uui-md", | ||
}; | ||
|
||
const classes = `${layer1} ${sizes[size]} ${iconStyle[badgeType][color]}`; | ||
|
||
return ( | ||
<span | ||
{...props} | ||
style={spanStyle} | ||
className={`${classes + " " + props.className} `} | ||
/> | ||
); | ||
}; | ||
export default BadgeIconAtom; |
17 changes: 17 additions & 0 deletions
17
apps/info-dashboard/src/components/Badge/BadgeTextAtom.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BadgeSize } from "./BadgeTypes"; | ||
|
||
type BadgeTextAtomProps = { | ||
children: React.ReactNode; | ||
size: BadgeSize; | ||
}; | ||
|
||
const BadgeTextAtom = ({ children, size }: BadgeTextAtomProps) => { | ||
const layer1 = "antialiased font-medium"; | ||
const sizes = { sm: "uui-text-xs" }; | ||
|
||
const classes = `${layer1} ${sizes[size]}`; | ||
|
||
return <span className={`${classes}`}>{children}</span>; | ||
}; | ||
|
||
export default BadgeTextAtom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type BadgeStyleLayers = { | ||
"Pill outline": { | ||
gray: string; | ||
brand: string; | ||
warning: string; | ||
pink: string; | ||
}; | ||
}; | ||
|
||
export type BadgeColor = "gray" | "brand" | "warning" | "pink"; | ||
|
||
export type BadgeType = "Pill outline"; | ||
|
||
export type BadgeSize = "sm"; | ||
|
||
export type BadgeIcon = { | ||
type: "icon"; | ||
leading?: string; | ||
} & React.HTMLAttributes<HTMLSpanElement>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { BadgeStyleLayers } from "./BadgeTypes"; | ||
import type { BadgeColor, BadgeSize, BadgeType } from "./BadgeTypes"; | ||
|
||
interface BadgeWrapperProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
color: BadgeColor; | ||
badgeType: BadgeType; | ||
children: React.ReactNode; | ||
size: BadgeSize; | ||
} | ||
|
||
const BadgeWrapper = ({ | ||
color, | ||
badgeType, | ||
size, | ||
children, | ||
...props | ||
}: BadgeWrapperProps) => { | ||
const layer1 = | ||
"group flex justify-center items-center focus-visible:outline-none focus:outline-none"; | ||
|
||
const backgroundLayer: BadgeStyleLayers = { | ||
"Pill outline": { | ||
gray: "text-uui-utility-gray-600 ring-uui-utility-gray-700 ring-[0.09375rem] rounded-full", | ||
brand: | ||
"text-uui-utility-brand-600 ring-uui-utility-brand-700 ring-[0.09375rem] rounded-full", | ||
warning: | ||
"text-uui-utility-warning-600 ring-uui-utility-warning-700 ring-[0.09375rem] rounded-full", | ||
pink: "text-uui-utility-pink-600 ring-uui-utility-pink-700 ring-[0.09375rem] rounded-full", | ||
}, | ||
}; | ||
|
||
const sizes = { | ||
sm: "px-uui-md py-uui-xxs gap-uui-sm ", | ||
}; | ||
|
||
const onClickClasses = "pointer-events-auto"; | ||
const noOnClickClasses = "pointer-events-auto cursor-default"; | ||
|
||
const classes = `${layer1} ${sizes[size]} ${ | ||
backgroundLayer[badgeType][color] | ||
} ${props.onClick ? onClickClasses : noOnClickClasses}`; | ||
|
||
return ( | ||
<button {...props} className={classes + " " + props.className}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default BadgeWrapper; |