Skip to content

Commit ae06008

Browse files
authored
Add UI for canary releases (#6173)
* [WIP] Add UI for canary releases * yellow * Switch to icon and gray * Wording, alignment, and rm flex * Heading alignment
1 parent fcc639b commit ae06008

File tree

12 files changed

+117
-28
lines changed

12 files changed

+117
-28
lines changed

src/components/Icon/IconCanary.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*/
4+
5+
import {memo} from 'react';
6+
7+
export const IconCanary = memo<JSX.IntrinsicElements['svg'] & {title?: string}>(
8+
function IconCanary({className, title}) {
9+
return (
10+
<svg
11+
className={className}
12+
width="20px"
13+
height="20px"
14+
viewBox="0 0 20 20"
15+
version="1.1"
16+
xmlns="http://www.w3.org/2000/svg">
17+
{title && <title>{title}</title>}
18+
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
19+
<g
20+
id="noun-labs-1201738-(2)"
21+
transform="translate(2, 0)"
22+
fill="currentColor"
23+
fillRule="nonzero">
24+
<path
25+
d="M10.2865804,5.55665262 L10.2865804,2.22331605 L10.8591544,2.22331605 C11.0103911,2.22244799 11.1551447,2.16342155 11.2617505,2.05914367 C11.3684534,1.95486857 11.4282767,1.81370176 11.4282767,1.66667106 L11.4282767,0.556642208 C11.4282767,0.40907262 11.3678934,0.26747526 11.2605218,0.16308627 C11.1531503,0.0587028348 11.0074938,0 10.8556998,0 L5.14338868,0 C4.9915947,0 4.84594391,0.0587028348 4.73856664,0.16308627 C4.63119507,0.267469704 4.57081178,0.40907262 4.57081178,0.556642208 L4.57081178,1.66667106 C4.57081178,1.81434899 4.63119507,1.95594912 4.73856664,2.06033811 C4.8459382,2.16472155 4.9915947,2.22331605 5.14338868,2.22331605 L5.71596273,2.22331605 L5.71596273,5.55665262 C5.71596273,8.38665538 2.97295619,9.88999017 0.651686904,15.5566623 C-0.0957823782,17.360053 -2.00560068,20 7.99951567,20 C18.004632,20 16.0948137,17.3600252 15.3507732,15.5566623 C13.0124432,9.88999017 10.2865804,8.38665538 10.2865804,5.55665262 Z M9.89570197,10.709991 C10.0921412,10.709991 10.2805515,10.7858383 10.4193876,10.9209301 C10.5583466,11.0559135 10.6363652,11.2390693 10.6363652,11.4300417 C10.6363652,11.6210141 10.5583466,11.8040698 10.4193876,11.9391533 C10.2805401,12.0741367 10.0921412,12.1499813 9.89570197,12.1499813 C9.6992627,12.1499813 9.51096673,12.074134 9.37201631,11.9391533 C9.23316875,11.8040615 9.15515307,11.6210141 9.15515307,11.4300417 C9.15515307,11.2390693 9.2331716,11.0559024 9.37201631,10.9209301 C9.57264221,10.7258996 9.61239426,10.709991 9.89570197,10.709991 Z M8.98919546,9.04212824 C9.09790709,9.14792278 9.15884755,9.29158681 9.1585213,9.44110085 C9.15829001,9.59073155 9.09678989,9.73407335 8.98763252,9.83954568 C8.87847514,9.945018 8.73069852,10.0039347 8.57678157,10.0033977 C8.42286747,10.0027392 8.27565088,9.94273467 8.16727355,9.83639845 C8.05900765,9.73006224 7.99873866,9.58628988 7.99963013,9.43664806 C8.00052304,9.28788403 8.0620221,9.14542556 8.17051087,9.04048101 C8.27911107,8.93555591 8.42599335,8.87663641 8.57913312,8.87663641 C8.73291864,8.87665585 8.88047525,8.93622535 8.98919546,9.04212824 Z M7.99965585,17.9999981 C4.91377349,17.9999981 3.29882839,17.7332867 2.51364277,17.4999976 C2.37780966,17.4476975 2.26954376,17.3439641 2.21396931,17.2125528 C2.15838628,17.0811499 2.16006066,16.9334692 2.21876871,16.8033858 C2.6144474,15.5921346 3.14916224,14.4280501 3.81316983,13.3333824 C5.980145,9.82337899 8.22941036,13.8867718 10.0980836,13.8867718 C11.9666996,13.8867718 11.4695868,12.1534924 12.1827971,13.3333824 C12.8511505,14.4269112 13.3916656,15.5896902 13.794259,16.8000524 C13.8533022,16.9322137 13.8537479,17.0822749 13.7952635,17.2147751 C13.7368889,17.3472613 13.6248314,17.4504531 13.4856467,17.5000531 C12.6833967,17.7332867 11.0855382,17.9999981 7.99965585,17.9999981 Z"
26+
id="Shape"></path>
27+
</g>
28+
</g>
29+
</svg>
30+
);
31+
}
32+
);

src/components/Layout/Page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface PageProps {
2828
children: React.ReactNode;
2929
toc: Array<TocItem>;
3030
routeTree: RouteItem;
31-
meta: {title?: string; description?: string};
31+
meta: {title?: string; canary?: boolean; description?: string};
3232
section: 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown';
3333
}
3434

@@ -40,6 +40,7 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
4040
routeTree
4141
);
4242
const title = meta.title || route?.title || '';
43+
const canary = meta.canary || false;
4344
const description = meta.description || route?.description || '';
4445
const isHomePage = cleanedPath === '/';
4546
const isBlogIndex = cleanedPath === '/blog';
@@ -56,6 +57,7 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
5657
)}>
5758
<PageHeading
5859
title={title}
60+
canary={canary}
5961
description={description}
6062
tags={route?.tags}
6163
breadcrumbs={breadcrumbs}

src/components/Layout/Sidebar/SidebarLink.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {useRef, useEffect} from 'react';
88
import * as React from 'react';
99
import cn from 'classnames';
1010
import {IconNavArrow} from 'components/Icon/IconNavArrow';
11+
import {IconCanary} from 'components/Icon/IconCanary';
1112
import Link from 'next/link';
1213

1314
interface SidebarLinkProps {
1415
href: string;
1516
selected?: boolean;
1617
title: string;
1718
level: number;
18-
wip: boolean | undefined;
19+
canary?: boolean;
1920
icon?: React.ReactNode;
2021
isExpanded?: boolean;
2122
hideArrow?: boolean;
@@ -26,7 +27,7 @@ export function SidebarLink({
2627
href,
2728
selected = false,
2829
title,
29-
wip,
30+
canary,
3031
level,
3132
isExpanded,
3233
hideArrow,
@@ -72,12 +73,16 @@ export function SidebarLink({
7273
}
7374
)}>
7475
{/* This here needs to be refactored ofc */}
75-
<span
76-
className={cn({
77-
'text-gray-400 dark:text-gray-500': wip,
78-
})}>
79-
{title}
80-
</span>
76+
<div>
77+
{title}{' '}
78+
{canary && (
79+
<IconCanary
80+
title="This feature is available in the latest Canary"
81+
className="ml-2 text-gray-30 dark:text-gray-60 inline-block w-4 h-4 align-[-3px]"
82+
/>
83+
)}
84+
</div>
85+
8186
{isExpanded != null && !hideArrow && (
8287
<span
8388
className={cn('pr-1', {

src/components/Layout/Sidebar/SidebarRouteTree.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ export function SidebarRouteTree({
8282
<ul>
8383
{currentRoutes.map(
8484
(
85-
{path, title, routes, wip, heading, hasSectionHeader, sectionHeader},
85+
{
86+
path,
87+
title,
88+
routes,
89+
canary,
90+
heading,
91+
hasSectionHeader,
92+
sectionHeader,
93+
},
8694
index
8795
) => {
8896
const selected = slug === path;
@@ -112,7 +120,7 @@ export function SidebarRouteTree({
112120
selected={selected}
113121
level={level}
114122
title={title}
115-
wip={wip}
123+
canary={canary}
116124
isExpanded={isExpanded}
117125
hideArrow={isForceExpanded}
118126
/>
@@ -136,7 +144,7 @@ export function SidebarRouteTree({
136144
selected={selected}
137145
level={level}
138146
title={title}
139-
wip={wip}
147+
canary={canary}
140148
/>
141149
</li>
142150
);

src/components/Layout/getRouteMeta.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type RouteTag =
1919
export interface RouteItem {
2020
/** Page title (for the sidebar) */
2121
title: string;
22+
/** Optional canary flag for heading */
23+
canary?: boolean;
2224
/** Optional page description for heading */
2325
description?: string;
2426
/* Additional meta info for page tagging */
@@ -27,8 +29,6 @@ export interface RouteItem {
2729
path?: string;
2830
/** Whether the entry is a heading */
2931
heading?: boolean;
30-
/** Whether the page is under construction */
31-
wip?: boolean;
3232
/** List of sub-routes */
3333
routes?: RouteItem[];
3434
/** Adds a section header above the route item */

src/components/MDX/ExpandableCallout.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import cn from 'classnames';
88
import {IconNote} from '../Icon/IconNote';
99
import {IconWarning} from '../Icon/IconWarning';
1010
import {IconPitfall} from '../Icon/IconPitfall';
11+
import {IconCanary} from '../Icon/IconCanary';
1112

12-
type CalloutVariants = 'deprecated' | 'pitfall' | 'note' | 'wip';
13+
type CalloutVariants = 'deprecated' | 'pitfall' | 'note' | 'wip' | 'canary';
1314

1415
interface ExpandableCalloutProps {
1516
children: React.ReactNode;
@@ -34,6 +35,15 @@ const variantMap = {
3435
overlayGradient:
3536
'linear-gradient(rgba(245, 249, 248, 0), rgba(245, 249, 248, 1)',
3637
},
38+
canary: {
39+
title: 'Canary',
40+
Icon: IconCanary,
41+
containerClasses:
42+
'bg-gray-5 dark:bg-gray-60 dark:bg-opacity-20 text-primary dark:text-primary-dark text-lg',
43+
textColor: 'text-gray-60 dark:text-gray-30',
44+
overlayGradient:
45+
'linear-gradient(rgba(245, 249, 248, 0), rgba(245, 249, 248, 1)',
46+
},
3747
pitfall: {
3848
title: 'Pitfall',
3949
Icon: IconPitfall,

src/components/MDX/MDXComponents.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const Note = ({children}: {children: React.ReactNode}) => (
8787
<ExpandableCallout type="note">{children}</ExpandableCallout>
8888
);
8989

90+
const Canary = ({children}: {children: React.ReactNode}) => (
91+
<ExpandableCallout type="canary">{children}</ExpandableCallout>
92+
);
93+
9094
const Blockquote = ({
9195
children,
9296
...props
@@ -416,6 +420,7 @@ export const MDXComponents = {
416420
Math,
417421
MathI,
418422
Note,
423+
Canary,
419424
PackageImport,
420425
ReadBlogPost,
421426
Recap,

src/components/PageHeading.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import Breadcrumbs from 'components/Breadcrumbs';
66
import Tag from 'components/Tag';
77
import {H1} from './MDX/Heading';
88
import type {RouteTag, RouteItem} from './Layout/getRouteMeta';
9+
import * as React from 'react';
10+
import {IconCanary} from './Icon/IconCanary';
911

1012
interface PageHeadingProps {
1113
title: string;
14+
canary?: boolean;
1215
status?: string;
1316
description?: string;
1417
tags?: RouteTag[];
@@ -18,6 +21,7 @@ interface PageHeadingProps {
1821
function PageHeading({
1922
title,
2023
status,
24+
canary,
2125
description,
2226
tags = [],
2327
breadcrumbs,
@@ -28,10 +32,16 @@ function PageHeading({
2832
{breadcrumbs ? <Breadcrumbs breadcrumbs={breadcrumbs} /> : null}
2933
<H1 className="mt-0 text-primary dark:text-primary-dark -mx-.5 break-words">
3034
{title}
35+
{canary && (
36+
<IconCanary
37+
title="This feature is available in the latest Canary"
38+
className="ml-4 mt-1 text-gray-50 dark:text-gray-40 inline-block w-6 h-6 align-[-1px]"
39+
/>
40+
)}
3141
{status ? <em>{status}</em> : ''}
3242
</H1>
3343
{description && (
34-
<p className="mt-4 mb-6 text-primary dark:text-primary-dark text-xl text-gray-90 leading-large">
44+
<p className="mt-4 mb-6 dark:text-primary-dark text-xl text-gray-90 leading-large">
3545
{description}
3646
</p>
3747
)}

src/content/reference/react/directives.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
22
title: "Directives"
3+
canary: true
34
---
45

6+
<Canary>
7+
8+
These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.
9+
10+
</Canary>
11+
512
<Intro>
613

7-
React uses two directives to provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
14+
Directives provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
815

916
</Intro>
1017

src/content/reference/react/use-client.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "'use client'"
3+
canary: true
34
---
45

5-
<Note>
6+
<Canary>
67

7-
These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.
8-
9-
</Note>
8+
`'use client'` is needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.
9+
</Canary>
1010

1111

1212
<Intro>

0 commit comments

Comments
 (0)