Skip to content

Commit d16cfc4

Browse files
authored
Pages banner (cloudflare#22134)
* Add sparkles to migration guide and support dismissible banner * Add banner to Pages
1 parent dbf4380 commit d16cfc4

File tree

137 files changed

+1550
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1550
-483
lines changed

astro.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default defineConfig({
108108
"https://github.com/cloudflare/cloudflare-docs/edit/production/",
109109
},
110110
components: {
111+
Banner: "./src/components/overrides/Banner.astro",
111112
Footer: "./src/components/overrides/Footer.astro",
112113
Head: "./src/components/overrides/Head.astro",
113114
Header: "./src/components/overrides/Header.astro",

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"@expressive-code/plugin-collapsible-sections": "0.41.2",
4242
"@floating-ui/react": "0.27.7",
4343
"@iarna/toml": "2.2.5",
44+
"@lottiefiles/dotlottie-react": "0.13.5",
4445
"@marsidev/react-turnstile": "1.1.0",
46+
"@nanostores/react": "1.0.0",
4547
"@octokit/webhooks-types": "7.6.1",
4648
"@stoplight/json-schema-tree": "4.0.0",
4749
"@tailwindcss/postcss": "4.1.4",
@@ -82,6 +84,7 @@
8284
"mdast-util-mdx-expression": "2.0.1",
8385
"mermaid": "11.6.0",
8486
"micromark-extension-mdxjs": "3.0.0",
87+
"nanostores": "1.0.1",
8588
"node-html-parser": "7.0.1",
8689
"openapi-types": "12.1.3",
8790
"parse-duration": "2.1.4",

patches/@astrojs+starlight+0.34.1.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
diff --git a/node_modules/@astrojs/starlight/components/SidebarSublist.astro b/node_modules/@astrojs/starlight/components/SidebarSublist.astro
2+
index a027f56..7e372d7 100644
3+
--- a/node_modules/@astrojs/starlight/components/SidebarSublist.astro
4+
+++ b/node_modules/@astrojs/starlight/components/SidebarSublist.astro
5+
@@ -4,6 +4,7 @@ import type { SidebarEntry } from '../utils/routing/types';
6+
import Icon from '../user-components/Icon.astro';
7+
import Badge from '../user-components/Badge.astro';
8+
import SidebarRestorePoint from './SidebarRestorePoint.astro';
9+
+import SidebarIcon from "~/components/SidebarIcon.astro"
10+
11+
interface Props {
12+
sublist: SidebarEntry[];
13+
@@ -24,7 +25,7 @@ const { sublist, nested } = Astro.props;
14+
class:list={[{ large: !nested }, entry.attrs.class]}
15+
{...entry.attrs}
16+
>
17+
- <span>{entry.label}</span>
18+
+ <span>{entry.icon && <SidebarIcon {...entry.icon} />}{entry.label}</span>
19+
{entry.badge && (
20+
<Badge
21+
variant={entry.badge.variant}
122
diff --git a/node_modules/@astrojs/starlight/user-components/Tabs.astro b/node_modules/@astrojs/starlight/user-components/Tabs.astro
223
index 6d173df..61eed80 100644
324
--- a/node_modules/@astrojs/starlight/user-components/Tabs.astro

src/components/Dismissible.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { useEffect, useState, type CSSProperties } from "react";
2+
3+
import { map } from "nanostores";
4+
import { useStore } from "@nanostores/react";
5+
6+
const dismissedMap = map<Record<string, boolean>>({});
7+
export const isDismissed = (id: string) => dismissedMap.get()[id];
8+
export const setIsDismissed = (id: string, value: boolean) =>
9+
dismissedMap.setKey(id, value);
10+
11+
const loadInitialValue = (id: string) => {
12+
if (typeof localStorage === "undefined") return false;
13+
14+
const dismissValue = localStorage.getItem(`dismisser-${id}`);
15+
16+
if (dismissValue) {
17+
if (new Date(dismissValue) > new Date()) {
18+
return true;
19+
} else {
20+
localStorage.removeItem(`dismisser-${id}`);
21+
}
22+
}
23+
24+
return false;
25+
};
26+
27+
export const useDismissible = (id: string) => {
28+
const store = useStore(dismissedMap);
29+
30+
return {
31+
isDismissed: store[id],
32+
dismiss: (days: number) => {
33+
setIsDismissed(id, true);
34+
localStorage.setItem(
35+
`dismisser-${id}`,
36+
new Date(Date.now() + days * 24 * 60 * 60 * 1000).toISOString(),
37+
);
38+
},
39+
};
40+
};
41+
42+
export const Dismisser = ({
43+
id,
44+
days,
45+
children,
46+
}: {
47+
id: string;
48+
days: number;
49+
children: React.ReactNode;
50+
}) => {
51+
const { dismiss } = useDismissible(id);
52+
53+
return (
54+
<span
55+
onClick={() => {
56+
dismiss(days);
57+
}}
58+
>
59+
{children}
60+
</span>
61+
);
62+
};
63+
64+
export const Dismissible = ({
65+
id,
66+
defaultDisplay,
67+
children,
68+
}: {
69+
id: string;
70+
defaultDisplay?: CSSProperties["display"];
71+
children: React.ReactNode;
72+
}) => {
73+
const [loaded, setLoaded] = useState(false);
74+
const store = useStore(dismissedMap);
75+
76+
useEffect(() => {
77+
setIsDismissed(id, loadInitialValue(id));
78+
setLoaded(true);
79+
}, []);
80+
81+
return (
82+
<span
83+
style={{
84+
display: !loaded ? defaultDisplay : store[id] ? "none" : undefined,
85+
}}
86+
>
87+
{children}
88+
</span>
89+
);
90+
};

src/components/SidebarIcon.astro

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { SidebarIconSchema } from "~/schemas/types/sidebar";
4+
import { DotLottieWorkerReact } from "@lottiefiles/dotlottie-react";
5+
6+
type Props = z.infer<typeof props>;
7+
8+
const props = SidebarIconSchema();
9+
10+
let iconProps = props.parse(Astro.props);
11+
12+
// https://angel-rs.github.io/css-color-filter-generator/
13+
const filter =
14+
iconProps?.color === "primary"
15+
? "brightness(0) saturate(100%) invert(60%) sepia(90%) saturate(2312%) hue-rotate(347deg) brightness(99%) contrast(95%)" // --orange-accent-200
16+
: undefined;
17+
---
18+
19+
{
20+
iconProps?.lottieLink && (
21+
<DotLottieWorkerReact
22+
style={{
23+
filter,
24+
height: "17px", // if someone smarter than me can make this properly text height, please go for it
25+
width: "17px",
26+
marginRight: "0.5em",
27+
float: "left",
28+
}}
29+
src={iconProps.lottieLink}
30+
loop
31+
autoplay
32+
client:load
33+
/>
34+
)
35+
}

0 commit comments

Comments
 (0)