Skip to content

Commit 66ec71e

Browse files
Docs: Added new banner (#4087)
1 parent e7add1e commit 66ec71e

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

docs/docs-components/AppLayout.tsx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { Fragment, ReactNode, useEffect, useState } from 'react';
22
import { useRouter } from 'next/router';
3-
import { Box, DeviceTypeProvider, Divider, FixedZIndex, Flex, Sticky } from 'gestalt';
3+
import {
4+
Box,
5+
ButtonLink,
6+
DeviceTypeProvider,
7+
Divider,
8+
FixedZIndex,
9+
Flex,
10+
Icon,
11+
Sticky,
12+
Text,
13+
} from 'gestalt';
414
import {
515
TOKEN_COLOR_GRAY_ROBOFLOW_700,
616
TOKEN_COLOR_ORANGE_FIRETINI_0,
@@ -12,9 +22,11 @@ import Footer from './Footer';
1222
import Header from './Header';
1323
import { useNavigationContext } from './navigationContext';
1424
import SkipToContent from './SkipToContent';
25+
import useBannerResize, { SM_BREAKPOINT } from './useBannerResize';
1526

1627
export const CONTENT_MAX_WIDTH_PX = 1200;
1728
const HEADER_HEIGHT_WITH_MARGIN = 90;
29+
1830
const fullWidthPages = ['home'];
1931
const fullBleedNoNavigationPages = ['integration-test'];
2032

@@ -23,6 +35,60 @@ type Props = {
2335
colorScheme?: 'light' | 'dark';
2436
};
2537

38+
function Banner() {
39+
const { maxWidth: bannerTextMaxWidth, breakpoint } = useBannerResize();
40+
41+
const isSMBreakpoint = breakpoint === SM_BREAKPOINT;
42+
43+
return (
44+
<Box
45+
alignItems="end"
46+
dangerouslySetInlineStyle={{
47+
__style: { backgroundColor: '#EBEEFF' },
48+
}}
49+
direction="column"
50+
display="flex"
51+
justifyContent="between"
52+
paddingX={4}
53+
paddingY={4}
54+
role="banner"
55+
smAlignItems="center"
56+
smDirection="row"
57+
smPaddingX={8}
58+
smPaddingY={6}
59+
>
60+
<Flex alignItems="start" direction="row" gap={isSMBreakpoint ? 1 : 4}>
61+
<Icon
62+
accessibilityLabel="Information"
63+
color="info"
64+
icon="circle-information-fill"
65+
size={isSMBreakpoint ? 16 : 24}
66+
/>
67+
68+
<Flex direction="column" gap={1} maxWidth={bannerTextMaxWidth}>
69+
<Text size={isSMBreakpoint ? '300' : '400'} weight="bold">
70+
This is Gestalt’s legacy documentation
71+
</Text>
72+
73+
<Text size={isSMBreakpoint ? '200' : '300'}>
74+
Information might be outdated. For the latest documentation and support, visit Gestalt’s
75+
new documentation website.
76+
</Text>
77+
</Flex>
78+
</Flex>
79+
80+
<Box marginTop={4} smMarginTop={0}>
81+
<ButtonLink
82+
color="red"
83+
href="https://gestalt.pinterest.systems"
84+
size={isSMBreakpoint ? 'sm' : 'lg'}
85+
text="Explore Gestalt 2.0"
86+
/>
87+
</Box>
88+
</Box>
89+
);
90+
}
91+
2692
export default function AppLayout({ children, colorScheme }: Props) {
2793
const { isMobile } = useDocsConfig();
2894
const { isSidebarOpen, setIsSidebarOpen } = useNavigationContext();
@@ -62,6 +128,7 @@ export default function AppLayout({ children, colorScheme }: Props) {
62128
}}
63129
minHeight="100vh"
64130
>
131+
<Banner />
65132
<Sticky top={0}>
66133
<SkipToContent />
67134
<Header />
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useEffect, useState } from 'react';
2+
3+
const BANNER_TEXT_MAX_WIDTH = 545;
4+
const BANNER_TEXT_MD_MAX_WIDTH = 450;
5+
6+
const SM_BREAKPOINT_PX = 576;
7+
const MD_BREAKPOINT_PX = 768;
8+
const LG_BREAKPOINT_PX = 992;
9+
10+
export const SM_BREAKPOINT = 'sm';
11+
export const MD_BREAKPOINT = 'md';
12+
export const LG_BREAKPOINT = 'lg';
13+
14+
const useBannerResize = (): { maxWidth: number | string; breakpoint: string } => {
15+
const [maxWidth, setMaxWidth] = useState<number | string>(BANNER_TEXT_MAX_WIDTH);
16+
const [breakpoint, setBreakpoint] = useState<string>(LG_BREAKPOINT);
17+
18+
useEffect(() => {
19+
const compute = () => {
20+
if (typeof window === 'undefined') return;
21+
22+
const containerWidth = window.innerWidth;
23+
24+
if (containerWidth >= LG_BREAKPOINT_PX) {
25+
setMaxWidth(BANNER_TEXT_MAX_WIDTH);
26+
} else if (containerWidth >= MD_BREAKPOINT_PX) {
27+
setMaxWidth(BANNER_TEXT_MD_MAX_WIDTH);
28+
} else if (containerWidth > SM_BREAKPOINT_PX) {
29+
setMaxWidth(BANNER_TEXT_MD_MAX_WIDTH);
30+
} else {
31+
setMaxWidth('100%');
32+
}
33+
34+
if (containerWidth <= SM_BREAKPOINT_PX) {
35+
setBreakpoint(SM_BREAKPOINT);
36+
} else if (containerWidth <= MD_BREAKPOINT_PX) {
37+
setBreakpoint(MD_BREAKPOINT);
38+
} else {
39+
setBreakpoint(LG_BREAKPOINT);
40+
}
41+
};
42+
43+
// Initial evaluation
44+
compute();
45+
46+
// Respond to viewport resizes
47+
if (typeof window !== 'undefined') {
48+
window.addEventListener('resize', compute);
49+
}
50+
51+
return () => {
52+
if (typeof window !== 'undefined') {
53+
window.removeEventListener('resize', compute);
54+
}
55+
};
56+
}, []);
57+
58+
return { maxWidth, breakpoint };
59+
};
60+
61+
export default useBannerResize;

0 commit comments

Comments
 (0)