Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: avatar component

Brad Barbinfd5878dc6772
diff --git a/apps/carbon/app/components/Avatar.tsx b/apps/carbon/app/components/Avatar.tsx
index 2164c6fb7e..ed5164f594 100644
--- a/apps/carbon/app/components/Avatar.tsx
+++ b/apps/carbon/app/components/Avatar.tsx
@@ -1,18 +1,21 @@
-import type { AvatarProps as AvatarBaseProps } from "@chakra-ui/react";
-import { Avatar as AvatarBase, forwardRef } from "@chakra-ui/react";
+import type { AvatarProps as AvatarBaseProps } from "@carbon/react";
+import { Avatar as AvatarBase } from "@carbon/react";
+import { forwardRef } from "react";
import { getStoragePath } from "~/utils/path";
type AvatarProps = AvatarBaseProps & {
- path: string | null;
+ path?: string | null;
bucket?: string;
};
-const Avatar = forwardRef(
- ({ path, bucket = "avatars", ...props }: AvatarProps, ref) => {
+const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(
+ ({ name, path, bucket = "avatars", ...props }, ref) => {
const imagePath = path ? getStoragePath(bucket, path) : undefined;
- return <AvatarBase ref={ref} src={imagePath} {...props} />;
+ // @ts-ignore
+ return <AvatarBase src={imagePath} name={name} ref={ref} {...props} />;
}
);
+Avatar.displayName = "Avatar";
export default Avatar;
diff --git a/apps/carbon/app/components/Contact.tsx b/apps/carbon/app/components/Contact.tsx
index 8d523423f9..6a30618a36 100644
--- a/apps/carbon/app/components/Contact.tsx
+++ b/apps/carbon/app/components/Contact.tsx
@@ -1,5 +1,5 @@
-import { ActionMenu, Dot, HStack, VStack } from "@carbon/react";
-import { Avatar, MenuItem } from "@chakra-ui/react";
+import { ActionMenu, Avatar, Dot, HStack, VStack } from "@carbon/react";
+import { MenuItem } from "@chakra-ui/react";
import { Link } from "@remix-run/react";
import type { Action } from "~/types";
diff --git a/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx b/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
index 3c04266715..5dcb74b18e 100644
--- a/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
@@ -30,39 +30,47 @@ const IconSidebar = () => {
return (
<div className="h-full border-r border-border bg-background z-10">
- <Button isIcon asChild variant="ghost" size="lg" className="rounded-none">
- <Link to="/">
- <BsFillHexagonFill />
- </Link>
- </Button>
- <TooltipProvider>
- <VStack spacing={0} className="top-[50px] sticky">
- {links.map((link) => {
- const module = link.to.split("/")[2]; // link.to is "/x/parts" -- this returns "parts"
+ <div>
+ <TooltipProvider>
+ <VStack spacing={0} className="sticky">
+ <Button
+ isIcon
+ asChild
+ variant="ghost"
+ size="lg"
+ className="rounded-none"
+ >
+ <Link to="/">
+ <BsFillHexagonFill />
+ </Link>
+ </Button>
+ {links.map((link) => {
+ const module = link.to.split("/")[2]; // link.to is "/x/parts" -- this returns "parts"
- const isActive = matchedModules.has(module);
- return (
- <Tooltip key={link.to}>
- <TooltipTrigger asChild>
- <Button
- asChild
- isIcon
- aria-label={link.name}
- variant={isActive ? "primary" : "ghost"}
- size="lg"
- className="rounded-none"
- >
- <Link to={link.to} prefetch="intent">
- <link.icon />
- </Link>
- </Button>
- </TooltipTrigger>
- <TooltipContent side="right">{link.name}</TooltipContent>
- </Tooltip>
- );
- })}
- </VStack>
- </TooltipProvider>
+ const isActive = matchedModules.has(module);
+ return (
+ <Tooltip key={link.to}>
+ <TooltipTrigger asChild>
+ <Button
+ asChild
+ isIcon
+ aria-label={link.name}
+ variant={isActive ? "primary" : "ghost"}
+ size="lg"
+ className="rounded-none"
+ >
+ <Link to={link.to} prefetch="intent">
+ <link.icon />
+ </Link>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent side="right">{link.name}</TooltipContent>
+ </Tooltip>
+ );
+ })}
+ </VStack>
+ </TooltipProvider>
+ </div>
</div>
);
};
diff --git a/apps/carbon/app/components/Layout/Topbar/AvatarMenu.tsx b/apps/carbon/app/components/Layout/Topbar/AvatarMenu.tsx
index bf25d38b78..14538743c3 100644
--- a/apps/carbon/app/components/Layout/Topbar/AvatarMenu.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/AvatarMenu.tsx
@@ -22,10 +22,9 @@ const AvatarMenu = () => {
arial-label="User Menu"
as={Avatar}
path={user.avatarUrl}
+ name={name}
title={name}
role="button"
- size="sm"
- cursor="pointer"
/>
<MenuList fontSize="sm" boxShadow="xl" minW={48}>
<MenuItem>Signed in as {name}</MenuItem>
diff --git a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
index 23c9dd8024..6237d94532 100644
--- a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
+++ b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
@@ -1,4 +1,6 @@
import {
+ Avatar,
+ AvatarGroup,
HStack,
IconButton,
Input as InputBase,
@@ -6,7 +8,7 @@ import {
InputLeftElement,
InputRightElement,
} from "@carbon/react";
-import { Avatar, AvatarGroup, Spinner } from "@chakra-ui/react";
+import { Spinner } from "@chakra-ui/react";
import { MdOutlineClear } from "react-icons/md";
import useUserSelectContext from "../provider";
@@ -27,9 +29,9 @@ const Input = () => {
<InputGroup>
{isMulti ? (
<InputLeftElement>
- <AvatarGroup size="xs" max={2}>
- <Avatar />
- <Avatar />
+ <AvatarGroup size="xs" limit={2}>
+ <Avatar size="xs" />
+ <Avatar size="xs" />
</AvatarGroup>
</InputLeftElement>
) : (
diff --git a/apps/carbon/app/modules/account/ui/Profile/ProfilePhotoForm/ProfilePhotoForm.tsx b/apps/carbon/app/modules/account/ui/Profile/ProfilePhotoForm/ProfilePhotoForm.tsx
index 9b0910a8c6..424fc29229 100644
--- a/apps/carbon/app/modules/account/ui/Profile/ProfilePhotoForm/ProfilePhotoForm.tsx
+++ b/apps/carbon/app/modules/account/ui/Profile/ProfilePhotoForm/ProfilePhotoForm.tsx
@@ -66,7 +66,11 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
return (
<VStack className="px-8 items-center">
- <Avatar size="2xl" path={user?.avatarUrl} title={user?.fullName ?? ""} />
+ <Avatar
+ size="2xl"
+ path={user?.avatarUrl}
+ name={user?.fullName ?? undefined}
+ />
<File accept="image/*" onChange={uploadImage}>
{user.avatarUrl ? "Change" : "Upload"}
</File>
diff --git a/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable/AbilitiesTable.tsx b/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable/AbilitiesTable.tsx
index 412799ea4d..683e2ecd17 100644
--- a/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable/AbilitiesTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable/AbilitiesTable.tsx
@@ -1,4 +1,9 @@
-import { AvatarGroup, Link, MenuItem } from "@chakra-ui/react";
+import {
+ AvatarGroup,
+ AvatarGroupList,
+ AvatarOverflowIndicator,
+} from "@carbon/react";
+import { Link, MenuItem } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
@@ -70,15 +75,18 @@ const AbilitiesTable = memo(({ data, count }: AbilitiesTableProps) => {
header: "Employees",
// accessorKey: undefined, // makes the column unsortable
cell: ({ row }) => (
- <AvatarGroup max={5} size="sm" spacing={-2}>
- {row.original.employees.map((employee, index: number) => (
- <Avatar
- key={index}
- name={employee.name ?? undefined}
- title={employee.name ?? undefined}
- path={employee.avatarUrl}
- />
- ))}
+ <AvatarGroup limit={5}>
+ <AvatarGroupList>
+ {row.original.employees.map((employee, index: number) => (
+ <Avatar
+ key={index}
+ name={employee.name ?? undefined}
+ title={employee.name ?? undefined}
+ path={employee.avatarUrl}
+ />
+ ))}
+ </AvatarGroupList>
+ <AvatarOverflowIndicator />
</AvatarGroup>
),
},
diff --git a/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable/ContractorsTable.tsx b/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable/ContractorsTable.tsx
index 50e624e8db..03c0d93a9c 100644
--- a/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable/ContractorsTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable/ContractorsTable.tsx
@@ -1,5 +1,5 @@
-import { HStack } from "@carbon/react";
-import { Avatar, Link, MenuItem } from "@chakra-ui/react";
+import { Avatar, HStack } from "@carbon/react";
+import { Link, MenuItem } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
@@ -28,7 +28,6 @@ const ContractorsTable = memo(({ data, count }: ContractorsTableProps) => {
cell: ({ row }) => (
<HStack>
<Avatar size="sm" name={row.original.supplierName ?? ""} />
-
<Link
onClick={() => {
navigate(path.to.supplier(row.original.supplierId!));
diff --git a/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx b/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx
index 4b2bf17fc8..a7a8895fa5 100644
--- a/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx
@@ -1,5 +1,5 @@
-import { HStack } from "@carbon/react";
-import { Avatar, Link, MenuItem } from "@chakra-ui/react";
+import { Avatar, HStack } from "@carbon/react";
+import { Link, MenuItem } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonHeader/PersonHeader.tsx b/apps/carbon/app/modules/resources/ui/Person/PersonHeader/PersonHeader.tsx
deleted file mode 100644
index b2061aaf3c..0000000000
--- a/apps/carbon/app/modules/resources/ui/Person/PersonHeader/PersonHeader.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { Button, CardTitle, HStack, VStack } from "@carbon/react";
-import { BsEnvelopeFill } from "react-icons/bs";
-import { Avatar } from "~/components";
-import { usePermissions } from "~/hooks";
-import type { Account } from "~/modules/account";
-
-const PersonHeader = ({ user }: { user: Account }) => {
- const permissions = usePermissions();
- return (
- <HStack className="py-4 justify-between w-full" spacing={4}>
- <HStack spacing={4}>
- <Avatar size="lg" path={user.avatarUrl} />
- <VStack spacing={1}>
- <CardTitle>{user.fullName}</CardTitle>
- <p className="text-muted-foreground text-sm">{user.about}</p>
- </VStack>
- </HStack>
- <HStack>
- {permissions.can("create", "messaging") && (
- <Button
- variant="secondary"
- leftIcon={<BsEnvelopeFill />}
- onClick={() => alert("TODO")}
- >
- Message
- </Button>
- )}
- </HStack>
- </HStack>
- );
-};
-
-export default PersonHeader;
diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonHeader/index.ts b/apps/carbon/app/modules/resources/ui/Person/PersonHeader/index.ts
deleted file mode 100644
index 2f90eefbd1..0000000000
--- a/apps/carbon/app/modules/resources/ui/Person/PersonHeader/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import PersonHeader from "./PersonHeader";
-
-export default PersonHeader;
diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonPreview/PersonPreview.tsx b/apps/carbon/app/modules/resources/ui/Person/PersonPreview/PersonPreview.tsx
index 14856ce61b..bc2d5fde47 100644
--- a/apps/carbon/app/modules/resources/ui/Person/PersonPreview/PersonPreview.tsx
+++ b/apps/carbon/app/modules/resources/ui/Person/PersonPreview/PersonPreview.tsx
@@ -8,6 +8,7 @@ import {
} from "@carbon/react";
import { Stack } from "@chakra-ui/react";
import { useParams } from "@remix-run/react";
+import { Avatar } from "~/components";
import { useRouteData } from "~/hooks";
import type { EmployeeSummary } from "~/modules/resources";
import { path } from "~/utils/path";
@@ -22,11 +23,16 @@ const PartPreview = () => {
return (
<Card>
- <HStack className="justify-between items-start">
+ <HStack className="justify-between items-center p-6 pl-0">
<CardHeader>
<CardTitle>{routeData?.employeeSummary?.name}</CardTitle>
<CardDescription>{routeData?.employeeSummary?.title}</CardDescription>
</CardHeader>
+ <Avatar
+ size="lg"
+ name={routeData?.employeeSummary?.name ?? undefined}
+ path={routeData?.employeeSummary?.avatarUrl}
+ />
</HStack>
<CardContent>
<Stack direction={["column", "column", "row"]} spacing={8}>
diff --git a/apps/carbon/app/modules/resources/ui/Person/index.ts b/apps/carbon/app/modules/resources/ui/Person/index.ts
index 89601d3861..00e6a66098 100644
--- a/apps/carbon/app/modules/resources/ui/Person/index.ts
+++ b/apps/carbon/app/modules/resources/ui/Person/index.ts
@@ -1,6 +1,5 @@
import PersonAbilities from "./PersonAbilities";
import PersonDaysOff from "./PersonDaysOff";
-import PersonHeader from "./PersonHeader";
import PersonJob from "./PersonJob";
import PersonOvertime from "./PersonOvertime";
import PersonPreview from "./PersonPreview";
@@ -9,7 +8,6 @@ import PersonSidebar from "./PersonSidebar";
export {
PersonAbilities,
PersonDaysOff,
- PersonHeader,
PersonJob,
PersonOvertime,
PersonPreview,
diff --git a/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm/CompanyLogoForm.tsx b/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm/CompanyLogoForm.tsx
index 7fd4a12a94..ebec309461 100644
--- a/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm/CompanyLogoForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm/CompanyLogoForm.tsx
@@ -70,7 +70,7 @@ const CompanyLogoForm = ({ company }: CompanyLogoFormProps) => {
<Avatar
size="2xl"
src={company?.logo ?? undefined}
- title={company?.name ?? ""}
+ name={company?.name}
/>
<File accept="image/*" onChange={uploadImage}>
{company.logo ? "Change" : "Upload"}
diff --git a/apps/carbon/app/modules/shared/ui/Notes/Notes.tsx b/apps/carbon/app/modules/shared/ui/Notes/Notes.tsx
index 96e6470c3c..f403893ebf 100644
--- a/apps/carbon/app/modules/shared/ui/Notes/Notes.tsx
+++ b/apps/carbon/app/modules/shared/ui/Notes/Notes.tsx
@@ -32,7 +32,7 @@ const Notes = ({ documentId, notes }: NotesProps) => {
return (
<Fragment key={note.id}>
{/* @ts-ignore */}
- <Avatar path={note.user.avatarUrl} />
+ <Avatar path={note.user.avatarUrl} name={note.user?.fullName} />
<VStack spacing={1}>
{/* @ts-ignore */}
<p className="font-bold">{note.user?.fullName!}</p>
diff --git a/apps/carbon/app/modules/users/ui/Groups/GroupsForm/GroupsForm.tsx b/apps/carbon/app/modules/users/ui/Groups/GroupsForm/GroupsForm.tsx
index 53c944abeb..a56470dfb5 100644
--- a/apps/carbon/app/modules/users/ui/Groups/GroupsForm/GroupsForm.tsx
+++ b/apps/carbon/app/modules/users/ui/Groups/GroupsForm/GroupsForm.tsx
@@ -59,7 +59,6 @@ const GroupForm = ({ initialValues }: GroupFormProps) => {
<Users
name="selections"
selectionsMaxHeight={"calc(100vh - 330px)"}
- checkedSelections
label="Group Members"
verbose
/>
diff --git a/apps/carbon/app/modules/users/ui/Groups/GroupsTable/GroupsTable.tsx b/apps/carbon/app/modules/users/ui/Groups/GroupsTable/GroupsTable.tsx
index 0e156a0ac8..d55ec2d6c6 100644
--- a/apps/carbon/app/modules/users/ui/Groups/GroupsTable/GroupsTable.tsx
+++ b/apps/carbon/app/modules/users/ui/Groups/GroupsTable/GroupsTable.tsx
@@ -1,4 +1,9 @@
-import { AvatarGroup, MenuItem } from "@chakra-ui/react";
+import {
+ AvatarGroup,
+ AvatarGroupList,
+ AvatarOverflowIndicator,
+} from "@carbon/react";
+import { MenuItem } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
@@ -45,20 +50,23 @@ const GroupsTable = memo(({ data, count }: GroupsTableProps) => {
header: "Members",
// accessorKey: undefined, // makes the column unsortable
cell: ({ row }) => (
- <AvatarGroup max={5} size="sm" spacing={-2}>
- {row.original.members.map(
- (
- member: { name: string | null; avatar: string | null },
- index: number
- ) => (
- <Avatar
- key={index}
- name={member.name ?? undefined}
- title={member.name ?? undefined}
- path={member.avatar}
- />
- )
- )}
+ <AvatarGroup limit={3}>
+ <AvatarGroupList>
+ {row.original.members.map(
+ (
+ member: { name: string | null; avatar: string | null },
+ index: number
+ ) => (
+ <Avatar
+ key={index}
+ name={member.name ?? undefined}
+ title={member.name ?? undefined}
+ path={member.avatar}
+ />
+ )
+ )}
+ </AvatarGroupList>
+ <AvatarOverflowIndicator />
</AvatarGroup>
),
},
diff --git a/apps/carbon/app/routes/_public+/reset-password.tsx b/apps/carbon/app/routes/_public+/reset-password.tsx
index 99c4f995ed..7fd98e1c66 100644
--- a/apps/carbon/app/routes/_public+/reset-password.tsx
+++ b/apps/carbon/app/routes/_public+/reset-password.tsx
@@ -76,7 +76,6 @@ export default function ResetPasswordRoute() {
<HStack spacing={4}>
<Submit>Reset Password</Submit>
<Button
- size="md"
variant="solid"
onClick={() => navigate(path.to.authenticatedRoot)}
>
diff --git a/apps/carbon/app/routes/onboarding+/_layout.tsx b/apps/carbon/app/routes/onboarding+/_layout.tsx
index ecd5a3cc0f..96d570cd2e 100644
--- a/apps/carbon/app/routes/onboarding+/_layout.tsx
+++ b/apps/carbon/app/routes/onboarding+/_layout.tsx
@@ -1,5 +1,4 @@
-import { ClientOnly, HStack, IconButton } from "@carbon/react";
-import { Avatar } from "@chakra-ui/react";
+import { Avatar, ClientOnly, HStack, IconButton } from "@carbon/react";
import { redirect, type LoaderFunctionArgs } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
import { BsFillHexagonFill } from "react-icons/bs";
diff --git a/apps/carbon/app/routes/x+/account+/profile.tsx b/apps/carbon/app/routes/x+/account+/profile.tsx
index d75bbd4825..3ede6c629c 100644
--- a/apps/carbon/app/routes/x+/account+/profile.tsx
+++ b/apps/carbon/app/routes/x+/account+/profile.tsx
@@ -10,7 +10,6 @@ import { json, redirect } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { validationError } from "remix-validated-form";
import { PageTitle } from "~/components/Layout";
-import type { PublicAttributes } from "~/modules/account";
import {
ProfileForm,
ProfilePhotoForm,
@@ -111,11 +110,7 @@ export async function action({ request }: ActionFunctionArgs) {
path.to.profile,
await flash(
request,
- success(
- photoPath === null
- ? "Removed avatar. Please refresh the page."
- : "Updated avatar. Please refresh the page."
- )
+ success(photoPath === null ? "Removed avatar" : "Updated avatar")
)
);
} else {
@@ -143,16 +138,18 @@ export default function AccountProfile() {
<VStack spacing={8}>
<ProfileForm user={user} />
{attributes.length ? (
- attributes.map((category: PublicAttributes) => (
- <Card key={category.id}>
- <CardHeader>
- <CardTitle>{category.name}</CardTitle>
- </CardHeader>
- <CardContent>
- <UserAttributesForm attributeCategory={category} />
- </CardContent>
- </Card>
- ))
+ <>
+ {attributes.map((category) => (
+ <Card key={category.id}>
+ <CardHeader>
+ <CardTitle>{category.name}</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <UserAttributesForm attributeCategory={category} />
+ </CardContent>
+ </Card>
+ ))}
+ </>
) : (
<Card>
<CardContent className="text-muted-foreground w-full text-center py-8">
diff --git a/apps/carbon/app/routes/x+/settings+/company.tsx b/apps/carbon/app/routes/x+/settings+/company.tsx
index cd4f2d10ce..f334b437f8 100644
--- a/apps/carbon/app/routes/x+/settings+/company.tsx
+++ b/apps/carbon/app/routes/x+/settings+/company.tsx
@@ -81,8 +81,8 @@ export async function action({ request }: ActionFunctionArgs) {
request,
success(
logoPath === null
- ? "Removed logo. Please refresh the page."
- : "Updated logo. Please refresh the page."
+ ? "Removed logo. Please refresh the page"
+ : "Updated logo"
)
)
);
diff --git a/packages/database/SCHEMA.md b/packages/database/SCHEMA.md
index b9e5ace0c7..2ddc82f2c7 100644
--- a/packages/database/SCHEMA.md
+++ b/packages/database/SCHEMA.md
@@ -1,6 +1,4 @@
-# Carbon Database Schema
-
-This file is generated by `scripts/generate-schema-md.ts` using the migrations in `packages/database/supabase/migrations`.
+# Carbon Database Schema by `scripts/generate-schema-md.ts` using the migrations in `packages/database/supabase/migrations`.
@@ -7379,6 +7377,7 @@ CREATE OR REPLACE VIEW "employeeSummary" WITH(SECURITY_INVOKER=true) AS
SELECT
u.id,
u."fullName" AS "name",
+ u."avatarUrl",
ej.title,
ej."startDate",
d.name AS "departmentName",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7817cff33f..d0597510f7 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -9311,6 +9311,7 @@ export interface Database {
};
employeeSummary: {
Row: {
+ avatarUrl: string | null;
departmentName: string | null;
id: string | null;
locationName: string | null;
diff --git a/packages/database/supabase/migrations/20240103010721_employee-summary.sql b/packages/database/supabase/migrations/20240103010721_employee-summary.sql
index 8446843716..dd031d9a09 100644
--- a/packages/database/supabase/migrations/20240103010721_employee-summary.sql
+++ b/packages/database/supabase/migrations/20240103010721_employee-summary.sql
@@ -2,6 +2,7 @@ CREATE OR REPLACE VIEW "employeeSummary" WITH(SECURITY_INVOKER=true) AS
SELECT
u.id,
u."fullName" AS "name",
+ u."avatarUrl",
ej.title,
ej."startDate",
d.name AS "departmentName",
diff --git a/packages/react/src/Avatar.tsx b/packages/react/src/Avatar.tsx
new file mode 100644
index 0000000000..c4ef0c6b9c
--- /dev/null
+++ b/packages/react/src/Avatar.tsx
@@ -0,0 +1,237 @@
+"use client";
+
+import type { VariantProps } from "class-variance-authority";
+import { cva } from "class-variance-authority";
+import type {
+ ComponentProps,
+ Dispatch,
+ HTMLAttributes,
+ ReactNode,
+ SetStateAction,
+} from "react";
+import {
+ Children,
+ createContext,
+ forwardRef,
+ useContext,
+ useEffect,
+ useState,
+} from "react";
+
+import { cn } from "~/utils/cn";
+
+export const avatarVariants = cva(
+ "inline-flex overflow-hidden rounded-full items-center justify-center text-white font-semibold",
+ {
+ variants: {
+ size: {
+ "2xl": "h-32 w-32 text-6xl",
+ xl: "h-24 w-24 text-4xl",
+ lg: "h-16 w-16 text-2xl",
+ md: "h-12 w-12 text-base",
+ sm: "h-8 w-8 text-xs",
+ xs: "h-6 w-6 text-sm",
+ },
+ isGroup: {
+ true: "ring-2 ring-background",
+ },
+ },
+ defaultVariants: {
+ size: "sm",
+ isGroup: false,
+ },
+ }
+);
+
+export interface AvatarProps
+ extends ComponentProps<"span">,
+ VariantProps<typeof avatarVariants> {
+ name?: string;
+ src?: string;
+}
+
+const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(
+ ({ className, name, src, size, children, ...props }, ref) => {
+ const isGroup = !!useAvatarGroupContext()?.limit;
+ const avatarInitials = getInitials(name ?? "");
+ const [_src, setSrc] = useState(src);
+
+ useEffect(() => {
+ setSrc(src);
+ }, [src]);
+
+ return _src ? (
+ <img
+ className={cn(
+ avatarVariants({ size, isGroup }),
+ "object-cover bg-muted-foreground border border-muted",
+ className
+ )}
+ alt={name ?? "avatar"}
+ src={_src}
+ onError={() => setSrc(undefined)}
+ />
+ ) : (
+ <span
+ className={cn(
+ avatarVariants({
+ size,
+ isGroup,
+ }),
+ "bg-muted-foreground",
+ className
+ )}
+ style={{
+ backgroundColor: name ? getColorFromString(name) : undefined,
+ }}
+ {...props}
+ ref={ref}
+ >
+ <>
+ {avatarInitials ? (
+ <span className="text-white">{avatarInitials}</span>
+ ) : (
+ <svg
+ viewBox="0 0 128 128"
+ className="h-full w-full text-muted"
+ role="img"
+ aria-label=" avatar"
+ >
+ <path
+ fill="currentColor"
+ d="M103,102.1388 C93.094,111.92 79.3504,118 64.1638,118 C48.8056,118 34.9294,111.768 25,101.7892 L25,95.2 C25,86.8096 31.981,80 40.6,80 L87.4,80 C96.019,80 103,86.8096 103,95.2 L103,102.1388 Z"
+ ></path>
+ <path
+ fill="currentColor"
+ d="M63.9961647,24 C51.2938136,24 41,34.2938136 41,46.9961647 C41,59.7061864 51.2938136,70 63.9961647,70 C76.6985159,70 87,59.7061864 87,46.9961647 C87,34.2938136 76.6985159,24 63.9961647,24"
+ ></path>
+ </svg>
+ )}
+ </>
+ </span>
+ );
+ }
+);
+Avatar.displayName = "Avatar";
+
+type AvatarGroupContextValue = {
+ count?: number;
+ limit?: number;
+ setCount?: Dispatch<SetStateAction<number>>;
+ size: ComponentProps<typeof Avatar>["size"];
+};
+
+const AvatarGroupContext = createContext<AvatarGroupContextValue>({
+ size: undefined,
+});
+
+const AvatarGroupProvider = ({
+ children,
+ limit,
+ size,
+}: {
+ children?: ReactNode;
+ limit?: number;
+ size?: ComponentProps<typeof Avatar>["size"];
+}) => {
+ const [count, setCount] = useState<number>(0);
+
+ return (
+ <AvatarGroupContext.Provider
+ value={{
+ count,
+ setCount,
+ limit,
+ size,
+ }}
+ >
+ {children}
+ </AvatarGroupContext.Provider>
+ );
+};
+
+const useAvatarGroupContext = () => useContext(AvatarGroupContext);
+
+export interface AvatarGroupProps extends HTMLAttributes<HTMLDivElement> {
+ limit?: number;
+ size?: ComponentProps<typeof Avatar>["size"];
+}
+
+const AvatarGroup = forwardRef<HTMLDivElement, AvatarGroupProps>(
+ ({ children, className, limit, size = "sm", ...props }, ref) => {
+ return (
+ <AvatarGroupProvider limit={limit} size={size}>
+ <div
+ ref={ref}
+ className={cn(
+ "flex items-center justify-start -space-x-2",
+ className
+ )}
+ {...props}
+ >
+ {children}
+ </div>
+ </AvatarGroupProvider>
+ );
+ }
+);
+AvatarGroup.displayName = "AvatarGroup";
+
+const AvatarGroupList = ({ children }: { children?: ReactNode }) => {
+ const { limit, setCount } = useAvatarGroupContext();
+
+ setCount?.(Children.count(children));
+
+ return <>{limit ? Children.toArray(children).slice(0, limit) : children}</>;
+};
+
+export interface AvatarOverflowIndicatorProps
+ extends HTMLAttributes<HTMLSpanElement> {}
+
+const AvatarOverflowIndicator = forwardRef<
+ HTMLSpanElement,
+ HTMLAttributes<HTMLSpanElement> & AvatarOverflowIndicatorProps
+>(({ className, ...props }, ref) => {
+ const { limit, count, size } = useAvatarGroupContext();
+ if (!limit || !count || count <= limit) return null;
+ return (
+ <span
+ ref={ref}
+ className={cn(
+ avatarVariants({ size, isGroup: true }),
+ "relative flex bg-muted-foreground ring-2 ring-background",
+ className
+ )}
+ {...props}
+ >
+ +{count! - limit!}
+ </span>
+ );
+});
+AvatarOverflowIndicator.displayName = "AvatarOverflowIndicator";
+
+function getInitials(name: string) {
+ const names = name.trim().split(" ");
+ const firstName = names[0] ?? "";
+ const lastName = names.length > 1 ? names[names.length - 1] : "";
+ return firstName && lastName
+ ? `${firstName.charAt(0)}${lastName.charAt(0)}`
+ : firstName.charAt(0);
+}
+
+function getColorFromString(str: string) {
+ let hash = 0;
+ if (str.length === 0) return hash.toString();
+ for (let i = 0; i < str.length; i += 1) {
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
+ hash = hash & hash;
+ }
+ let color = "#";
+ for (let j = 0; j < 3; j += 1) {
+ const value = (hash >> (j * 8)) & 255;
+ color += `00${value.toString(16)}`.substr(-2);
+ }
+ return color;
+}
+
+export { Avatar, AvatarGroup, AvatarGroupList, AvatarOverflowIndicator };
diff --git a/packages/react/src/Date/components/DateSegment.tsx b/packages/react/src/Date/components/DateSegment.tsx
index e0a598aad1..671fa8ff8d 100644
--- a/packages/react/src/Date/components/DateSegment.tsx
+++ b/packages/react/src/Date/components/DateSegment.tsx
@@ -28,7 +28,7 @@ export const DateSegment = ({
<div
{...segmentProps}
ref={ref}
- className="box-content tabular-nums text-right outline-none rounded-sm group focus:ring-2 focus:ring-offset-2"
+ className="box-content tabular-nums text-right outline-none rounded-sm group focus:ring-2 ring-ring focus:ring-offset-2"
>
<span
aria-hidden="true"
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index e303fd1ce6..f81949c491 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -1,4 +1,11 @@
import { ActionMenu } from "./ActionMenu";
+import type { AvatarProps } from "./Avatar";
+import {
+ Avatar,
+ AvatarGroup,
+ AvatarGroupList,
+ AvatarOverflowIndicator,
+} from "./Avatar";
import { Badge } from "./Badge";
import type { ButtonProps } from "./Button";
import { Button } from "./Button";
@@ -132,6 +139,10 @@ import { cn } from "./utils/cn";
export {
ActionMenu,
+ Avatar,
+ AvatarGroup,
+ AvatarGroupList,
+ AvatarOverflowIndicator,
Badge,
Button,
Card,
@@ -256,4 +267,4 @@ export {
useNotification,
useOutsideClick,
};
-export type { ButtonProps, InputProps };
+export type { AvatarProps, ButtonProps, InputProps };