diff --git a/.changeset/chilly-radios-relax.md b/.changeset/chilly-radios-relax.md new file mode 100644 index 00000000..bbc43571 --- /dev/null +++ b/.changeset/chilly-radios-relax.md @@ -0,0 +1,5 @@ +--- +"@worldcoin/mini-apps-ui-kit-react": minor +--- + +Add title animation to TopBar diff --git a/packages/mini-apps-ui-kit-react/src/components/TopBar/TopBar.tsx b/packages/mini-apps-ui-kit-react/src/components/TopBar/TopBar.tsx index 67ef05b5..dffb1ecd 100644 --- a/packages/mini-apps-ui-kit-react/src/components/TopBar/TopBar.tsx +++ b/packages/mini-apps-ui-kit-react/src/components/TopBar/TopBar.tsx @@ -1,4 +1,5 @@ import { cn } from "@/lib/utils"; +import { useWindowScroll } from "@uidotdev/usehooks"; import React from "react"; import { Typography } from "../Typography"; @@ -15,37 +16,48 @@ interface TopBarProps { } function TopBar({ title, startAdornment, endAdornment, className }: TopBarProps) { + const [{ y }] = useWindowScroll(); + const isScrolled = (y ?? 0) > 0; const hasStartAdornment = Boolean(startAdornment); - const hasEndAdornment = Boolean(endAdornment); - - const textAlignment = hasStartAdornment ? "text-center" : "text-left"; - const justifyContent = - hasStartAdornment || hasEndAdornment ? "justify-between" : "justify-start"; - return (
- {startAdornment &&
{startAdornment}
} + {startAdornment && ( +
{startAdornment}
+ )} + + {!hasStartAdornment && ( + + {title} + + )} {title} - {endAdornment &&
{endAdornment}
} - - {!endAdornment && hasStartAdornment && ( - + {endAdornment && ( +
{endAdornment}
)}
); diff --git a/packages/mini-apps-ui-kit-react/stories/TopBar.stories.tsx b/packages/mini-apps-ui-kit-react/stories/TopBar.stories.tsx index 2ed14e71..887a4694 100644 --- a/packages/mini-apps-ui-kit-react/stories/TopBar.stories.tsx +++ b/packages/mini-apps-ui-kit-react/stories/TopBar.stories.tsx @@ -85,6 +85,12 @@ export const Default: Story = { }, }; +export const WithLongTitle: Story = { + args: { + title: "This is a long title that should be truncated", + }, +}; + export const WithStartAdornment: Story = { args: { title: "World",