Skip to content

Commit 45d2b07

Browse files
authored
Merge pull request #875 from ably/web-4400-custom-header-logo
[WEB-4400] chore: add optional badge to logo component, add support to header
2 parents b3e73df + 9f05a20 commit 45d2b07

File tree

6 files changed

+96
-22
lines changed

6 files changed

+96
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ably/ui",
3-
"version": "17.6.1",
3+
"version": "17.6.2",
44
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
55
"repository": {
66
"type": "git",

src/core/Header.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ export type HeaderProps = {
136136
* Optional location object to detect location changes.
137137
*/
138138
location?: Location;
139+
140+
/**
141+
* Optional badge text to display on the logo.
142+
*/
143+
logoBadge?: string;
139144
};
140145

141146
const FLEXIBLE_DESKTOP_CLASSES = "hidden md:flex flex-1 items-center h-full";
@@ -160,6 +165,7 @@ const Header: React.FC<HeaderProps> = ({
160165
themedScrollpoints = [],
161166
searchButtonVisibility = "all",
162167
location,
168+
logoBadge,
163169
}) => {
164170
const [showMenu, setShowMenu] = useState(false);
165171
const [fadingOut, setFadingOut] = useState(false);
@@ -248,7 +254,7 @@ const Header: React.FC<HeaderProps> = ({
248254
<header
249255
role="banner"
250256
className={cn(
251-
"fixed left-0 top-0 w-full z-50 bg-neutral-000 dark:bg-neutral-1300 border-b border-neutral-300 dark:border-neutral-1000 transition-colors px-6 md:px-16",
257+
"fixed left-0 top-0 w-full z-50 bg-neutral-000 dark:bg-neutral-1300 border-b border-neutral-300 dark:border-neutral-1000 transition-colors px-6 lg:px-16",
252258
scrollpointClasses,
253259
{
254260
"md:top-auto": bannerVisible,
@@ -263,8 +269,9 @@ const Header: React.FC<HeaderProps> = ({
263269
key={theme}
264270
href={logoHref}
265271
theme={theme}
272+
badge={logoBadge}
266273
additionalLinkAttrs={{
267-
className: cn("h-full focus-base rounded mr-8 w-24", {
274+
className: cn("h-full focus-base rounded mr-4 lg:mr-8", {
268275
"flex dark:hidden": theme === "light",
269276
"hidden dark:flex": theme === "dark",
270277
}),

src/core/Header/Header.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ WithSearchBar.args = {
143143
<input type="text" placeholder="Search" className="ui-input w-64" />
144144
),
145145
};
146+
147+
export const WithLogoBadge = Template.bind({});
148+
WithLogoBadge.args = {
149+
...baseArgs,
150+
logoBadge: "docs",
151+
};

src/core/Logo.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React from "react";
1+
import React, { AnchorHTMLAttributes, ImgHTMLAttributes } from "react";
2+
import Badge from "./Badge";
3+
import cn from "./utils/cn";
24
import LogoAssetMonoStacked from "./images/logo/ably-logo-mono-stacked.svg";
35
import LogoAssetMonoWhiteStacked from "./images/logo/ably-logo-mono-white-stacked.svg";
46
import LogoAssetMonoWhite from "./images/logo/ably-logo-mono-white.svg";
@@ -13,11 +15,12 @@ type LogoProps = {
1315
logoUrl?: string;
1416
logoAlt?: string;
1517
href?: string;
16-
additionalImgAttrs?: object;
17-
additionalLinkAttrs?: object;
18+
additionalImgAttrs?: ImgHTMLAttributes<HTMLImageElement>;
19+
additionalLinkAttrs?: AnchorHTMLAttributes<HTMLAnchorElement>;
1820
theme?: "light" | "dark";
1921
variant?: "default" | "mono";
2022
orientation?: "default" | "stacked";
23+
badge?: string;
2124
};
2225

2326
const Logo = ({
@@ -30,6 +33,7 @@ const Logo = ({
3033
orientation = "default",
3134
logoUrl,
3235
logoAlt = "Ably logo",
36+
badge,
3337
}: LogoProps) => {
3438
const getLogoSrc = React.useCallback(() => {
3539
if (logoUrl) return logoUrl;
@@ -56,8 +60,21 @@ const Logo = ({
5660
const logoSrc = getLogoSrc();
5761

5862
return (
59-
<a href={href} data-id={dataId} className="block" {...additionalLinkAttrs}>
60-
<img src={logoSrc} width="108px" alt={logoAlt} {...additionalImgAttrs} />
63+
<a
64+
href={href}
65+
data-id={dataId}
66+
{...additionalLinkAttrs}
67+
className={cn(
68+
"flex items-center gap-2 justify-center",
69+
additionalLinkAttrs?.className,
70+
)}
71+
>
72+
<img src={logoSrc} width="96px" alt={logoAlt} {...additionalImgAttrs} />
73+
{badge && (
74+
<Badge className="uppercase h-8 bg-transparent dark:bg-transparent rounded border border-neutral-400 dark:border-neutral-900 text-lg p-2 font-semibold text-neutral-800 dark:text-neutral-500">
75+
{badge}
76+
</Badge>
77+
)}
6178
</a>
6279
);
6380
};

src/core/Logo/Logo.stories.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ export default {
66
component: Logo,
77
};
88

9-
const LogoSet = (variant, orientation) => (
9+
const LogoSet = (variant, orientation, badge?: string) => (
1010
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
1111
<div className="text-center ui-text-code2 order-1">light</div>
1212
<div className="text-center ui-text-code2 order-3 sm:order-2">dark</div>
1313
<Logo
1414
variant={variant}
1515
orientation={orientation}
1616
theme="light"
17+
badge={badge}
1718
additionalLinkAttrs={{
1819
className: "text-center p-2 bg-neutral-000 rounded order-2 sm:order-3",
1920
}}
@@ -22,8 +23,10 @@ const LogoSet = (variant, orientation) => (
2223
variant={variant}
2324
orientation={orientation}
2425
theme="dark"
26+
badge={badge}
2527
additionalLinkAttrs={{
26-
className: "text-center p-2 bg-neutral-1300 rounded order-4",
28+
className:
29+
"ui-theme-dark text-center p-2 bg-neutral-1300 rounded order-4",
2730
}}
2831
/>
2932
</div>
@@ -40,3 +43,7 @@ export const Mono = {
4043
export const Stacked = {
4144
render: () => LogoSet("default", "stacked"),
4245
};
46+
47+
export const WithBadge = {
48+
render: () => LogoSet("default", "default", "docs"),
49+
};

0 commit comments

Comments
 (0)