|
| 1 | +import { DetailedHTMLProps, HtmlHTMLAttributes, ReactElement, ReactNode } from 'react'; |
| 2 | +import { Layout } from 'nextra-theme-docs'; |
| 3 | +import { Head } from 'nextra/components'; |
| 4 | +import { getPageMap } from 'nextra/page-map'; |
| 5 | +import { cn } from '../cn'; |
| 6 | +import { Body } from './body.client'; |
| 7 | + |
| 8 | +export interface HiveLayoutProps |
| 9 | + extends DetailedHTMLProps<HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement> { |
| 10 | + children: ReactNode; |
| 11 | + head: ReactNode; |
| 12 | + navbar: ReactElement; |
| 13 | + footer: ReactElement; |
| 14 | + fontFamily: string; |
| 15 | + lightOnlyPages: string[]; |
| 16 | + bodyProps?: DetailedHTMLProps<HtmlHTMLAttributes<HTMLBodyElement>, HTMLBodyElement>; |
| 17 | + docsRepositoryBase: string; |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * Alternative to `GuildLayout` for Hive-branded websites. |
| 22 | + * |
| 23 | + * Accepts navbar and footer as slots/children props, because they're highly customizable, |
| 24 | + * and their defaults belong to HiveNavigation and HiveFooter component default props. |
| 25 | + * |
| 26 | + * ## Configuration |
| 27 | + * |
| 28 | + * Pages can differ by widths and supported color schemes: |
| 29 | + * |
| 30 | + * - The footer in docs has 90rem width, in landing pages it has 75rem. |
| 31 | + * - The navbar in docs has 90rem width, in landing pages it has 1392px. |
| 32 | + * - Landing pages only support light mode for _business and prioritization reasons_. |
| 33 | + * |
| 34 | + * TODO: Consider unifying this in design phase. |
| 35 | + * |
| 36 | + * For now, a page or a layout can configue these as follows: |
| 37 | + * |
| 38 | + * ### Light-only pages |
| 39 | + * |
| 40 | + * @example |
| 41 | + * ```tsx |
| 42 | + * <HiveLayout bodyProps={{ lightOnlyPages: ['/', '/friends'] }} /> |
| 43 | + * ``` |
| 44 | + * |
| 45 | + * This will force light theme to the pages with paths `/` and `/friends`, |
| 46 | + * by adding `.light` class to the <body /> element. |
| 47 | + * |
| 48 | + * ### Landing page widths |
| 49 | + * |
| 50 | + * @example |
| 51 | + * ```tsx |
| 52 | + * import { HiveLayoutConfig } from '@theguild/components' |
| 53 | + * |
| 54 | + * <HiveLayoutConfig widths="landing-narrow" /> |
| 55 | + * ``` |
| 56 | + */ |
| 57 | +export const HiveLayout = async ({ |
| 58 | + children, |
| 59 | + head, |
| 60 | + navbar, |
| 61 | + footer, |
| 62 | + className, |
| 63 | + fontFamily, |
| 64 | + lightOnlyPages, |
| 65 | + bodyProps, |
| 66 | + docsRepositoryBase, |
| 67 | + ...rest |
| 68 | +}: HiveLayoutProps) => { |
| 69 | + const pageMap = await getPageMap(); |
| 70 | + return ( |
| 71 | + <html |
| 72 | + lang="en" |
| 73 | + // Required to be set for `nextra-theme-docs` styles |
| 74 | + dir="ltr" |
| 75 | + // Suggested by `next-themes` package https://github.com/pacocoursey/next-themes#with-app |
| 76 | + suppressHydrationWarning |
| 77 | + className={cn('font-sans', className)} |
| 78 | + {...rest} |
| 79 | + > |
| 80 | + <Head> |
| 81 | + <style>{ |
| 82 | + /* css */ ` |
| 83 | + :root { |
| 84 | + --font-sans: ${fontFamily}; |
| 85 | + } |
| 86 | + :root.dark { |
| 87 | + --nextra-primary-hue: 67.1deg; |
| 88 | + --nextra-primary-saturation: 100%; |
| 89 | + --nextra-primary-lightness: 55%; |
| 90 | + --nextra-bg: 17, 17, 17; |
| 91 | + } |
| 92 | + :root.dark *::selection { |
| 93 | + background-color: hsl(191deg 95% 72% / 0.25) |
| 94 | + } |
| 95 | + :root.light, :root.dark:has(body.light) { |
| 96 | + --nextra-primary-hue: 191deg; |
| 97 | + --nextra-primary-saturation: 40%; |
| 98 | + --nextra-bg: 255, 255, 255; |
| 99 | + } |
| 100 | + |
| 101 | + .x\\:tracking-tight, |
| 102 | + .nextra-steps :is(h2, h3, h4) { |
| 103 | + letter-spacing: normal; |
| 104 | + } |
| 105 | +
|
| 106 | + html:has(body.light) { |
| 107 | + scroll-behavior: smooth; |
| 108 | + background: #fff; |
| 109 | + color-scheme: light !important; |
| 110 | + } |
| 111 | + |
| 112 | + html:has(body.light) .nextra-search-results mark { |
| 113 | + background: oklch(0.611752 0.07807 214.47 / 0.8); |
| 114 | + } |
| 115 | + |
| 116 | + html:has(body.light) .nextra-sidebar-footer { |
| 117 | + display: none; |
| 118 | + } |
| 119 | + |
| 120 | + #crisp-chatbox { z-index: 40 !important; } |
| 121 | + ` |
| 122 | + }</style> |
| 123 | + {head} |
| 124 | + </Head> |
| 125 | + <Body lightOnlyPages={lightOnlyPages} {...bodyProps}> |
| 126 | + <Layout |
| 127 | + editLink="Edit this page on GitHub" |
| 128 | + docsRepositoryBase={docsRepositoryBase} |
| 129 | + pageMap={pageMap} |
| 130 | + feedback={{ |
| 131 | + labels: 'kind/docs', |
| 132 | + }} |
| 133 | + sidebar={{ |
| 134 | + defaultMenuCollapseLevel: 1, |
| 135 | + }} |
| 136 | + navbar={navbar} |
| 137 | + footer={footer} |
| 138 | + > |
| 139 | + {children} |
| 140 | + </Layout> |
| 141 | + </Body> |
| 142 | + </html> |
| 143 | + ); |
| 144 | +}; |
0 commit comments