@lukoweb/apitogo-module-landing 0.2.71 → 0.2.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo-module-landing",
3
- "version": "0.2.71",
3
+ "version": "0.2.75",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.tsx"
@@ -14,7 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@types/react": "19.2.14",
16
16
  "@types/react-dom": "19.2.3",
17
- "@lukoweb/apitogo": "0.2.71",
17
+ "@lukoweb/apitogo": "0.2.75",
18
18
  "react": "19.2.4",
19
19
  "react-dom": "19.2.4",
20
20
  "typescript": "5.9.3"
@@ -1,75 +1,75 @@
1
- import { cn } from "@lukoweb/apitogo";
2
- import { Head, useZudoku } from "@lukoweb/apitogo/components";
3
- import { Children, isValidElement, type ReactNode } from "react";
4
- import { FooterSection } from "./sections/FooterSection.js";
5
- import "./landing.css";
6
-
7
- /**
8
- * Detects a composed `FooterSection` in the element tree so the
9
- * "Built with API ToGo" line can be replaced by the real footer.
10
- */
11
- const containsFooterSection = (node: ReactNode): boolean =>
12
- Children.toArray(node).some((child) => {
13
- if (!isValidElement(child)) {
14
- return false;
15
- }
16
-
17
- if (child.type === FooterSection) {
18
- return true;
19
- }
20
-
21
- const { children } = child.props as { children?: ReactNode };
22
- return children ? containsFooterSection(children) : false;
23
- });
24
-
25
- export type LandingShellProps = {
26
- children: ReactNode;
27
- /** Page title for `<Head>`. Defaults to site title from config. */
28
- title?: string;
29
- /** Meta description for `<Head>`. */
30
- description?: string;
31
- /**
32
- * Show the "Built with API ToGo" line. Defaults to true.
33
- * Automatically hidden when a `FooterSection` is composed as a child or
34
- * a footer slot is configured (e.g. `modules.landing.content.footer`).
35
- */
36
- showPoweredBy?: boolean;
37
- };
38
-
39
- export const LandingShell = ({
40
- children,
41
- title,
42
- description,
43
- showPoweredBy = true,
44
- }: LandingShellProps) => {
45
- const { options } = useZudoku();
46
- const siteTitle =
47
- options.metadata?.applicationName ?? options.site?.title ?? "API ToGo";
48
- const pageTitle = title ?? siteTitle;
49
- const hasFooter =
50
- containsFooterSection(children) || Boolean(options.slots?.footer);
51
-
52
- return (
53
- <div className="relative overflow-hidden bg-background text-foreground">
54
- {/* The site's title template adds " - <site name>"; a home page titled with the site name would read
55
- "full portal - full portal", so it keeps its title as is (API-126). */}
56
- <Head titleTemplate={pageTitle === siteTitle ? "%s" : undefined}>
57
- <title>{pageTitle}</title>
58
- {description ? <meta name="description" content={description} /> : null}
59
- </Head>
60
-
61
- {children}
62
-
63
- {showPoweredBy && !hasFooter ? (
64
- <div
65
- className={cn(
66
- "border-t border-border py-6 text-center text-xs text-muted-foreground/70",
67
- !options.site?.footer && "mb-8",
68
- )}
69
- >
70
- Built with API ToGo
71
- </div>
72
- ) : null}
73
- </div>
74
- );
75
- };
1
+ import { cn } from "@lukoweb/apitogo";
2
+ import { Head, useZudoku } from "@lukoweb/apitogo/components";
3
+ import { Children, isValidElement, type ReactNode } from "react";
4
+ import { FooterSection } from "./sections/FooterSection.js";
5
+ import "./landing.css";
6
+
7
+ /**
8
+ * Detects a composed `FooterSection` in the element tree so the
9
+ * "Built with API ToGo" line can be replaced by the real footer.
10
+ */
11
+ const containsFooterSection = (node: ReactNode): boolean =>
12
+ Children.toArray(node).some((child) => {
13
+ if (!isValidElement(child)) {
14
+ return false;
15
+ }
16
+
17
+ if (child.type === FooterSection) {
18
+ return true;
19
+ }
20
+
21
+ const { children } = child.props as { children?: ReactNode };
22
+ return children ? containsFooterSection(children) : false;
23
+ });
24
+
25
+ export type LandingShellProps = {
26
+ children: ReactNode;
27
+ /** Page title for `<Head>`. Defaults to site title from config. */
28
+ title?: string;
29
+ /** Meta description for `<Head>`. */
30
+ description?: string;
31
+ /**
32
+ * Show the "Built with API ToGo" line. Defaults to true.
33
+ * Automatically hidden when a `FooterSection` is composed as a child or
34
+ * a footer slot is configured (e.g. `modules.landing.content.footer`).
35
+ */
36
+ showPoweredBy?: boolean;
37
+ };
38
+
39
+ export const LandingShell = ({
40
+ children,
41
+ title,
42
+ description,
43
+ showPoweredBy = true,
44
+ }: LandingShellProps) => {
45
+ const { options } = useZudoku();
46
+ const siteTitle =
47
+ options.metadata?.applicationName ?? options.site?.title ?? "API ToGo";
48
+ const pageTitle = title ?? siteTitle;
49
+ const hasFooter =
50
+ containsFooterSection(children) || Boolean(options.slots?.footer);
51
+
52
+ return (
53
+ <div className="relative overflow-hidden bg-background text-foreground">
54
+ {/* The site's title template adds " - <site name>"; a home page titled with the site name would read
55
+ "full portal - full portal", so it keeps its title as is (API-126). */}
56
+ <Head titleTemplate={pageTitle === siteTitle ? "%s" : undefined}>
57
+ <title>{pageTitle}</title>
58
+ {description ? <meta name="description" content={description} /> : null}
59
+ </Head>
60
+
61
+ {children}
62
+
63
+ {showPoweredBy && !hasFooter ? (
64
+ <div
65
+ className={cn(
66
+ "border-t border-border py-6 text-center text-xs text-muted-foreground/70",
67
+ !options.site?.footer && "mb-8",
68
+ )}
69
+ >
70
+ Built with API ToGo
71
+ </div>
72
+ ) : null}
73
+ </div>
74
+ );
75
+ };
@@ -1,50 +1,50 @@
1
- import { cn } from "@lukoweb/apitogo";
2
- import { Link } from "@lukoweb/apitogo/components";
3
- import { useAuth } from "@lukoweb/apitogo/hooks";
4
- import { Button } from "@lukoweb/apitogo/ui/Button.js";
5
- import type { LucideIcon } from "lucide-react";
6
- import type { ReactNode } from "react";
7
- import { landingHref } from "./landing-href.js";
8
-
9
- type LandingButtonProps = {
10
- href: string;
11
- label: string;
12
- icon?: LucideIcon;
13
- iconPosition?: "start" | "end";
14
- variant?: "primary" | "secondary";
15
- size?: "default" | "sm";
16
- className?: string;
17
- children?: ReactNode;
18
- };
19
-
20
- export const LandingButton = ({
21
- href,
22
- label,
23
- icon: Icon,
24
- iconPosition = "end",
25
- variant = "primary",
26
- size = "default",
27
- className,
28
- children,
29
- }: LandingButtonProps) => {
30
- const auth = useAuth();
31
- const to = landingHref(href, auth.isAuthenticated);
32
- const content = children ?? (
33
- <>
34
- {Icon && iconPosition === "start" ? <Icon size={17} aria-hidden /> : null}
35
- {label}
36
- {Icon && iconPosition === "end" ? <Icon size={17} aria-hidden /> : null}
37
- </>
38
- );
39
-
40
- return (
41
- <Button
42
- asChild
43
- variant={variant === "primary" ? "default" : "outline"}
44
- size={size === "sm" ? "sm" : "lg"}
45
- className={cn(className)}
46
- >
47
- <Link to={to}>{content}</Link>
48
- </Button>
49
- );
50
- };
1
+ import { cn } from "@lukoweb/apitogo";
2
+ import { Link } from "@lukoweb/apitogo/components";
3
+ import { useAuth } from "@lukoweb/apitogo/hooks";
4
+ import { Button } from "@lukoweb/apitogo/ui/Button.js";
5
+ import type { LucideIcon } from "lucide-react";
6
+ import type { ReactNode } from "react";
7
+ import { landingHref } from "./landing-href.js";
8
+
9
+ type LandingButtonProps = {
10
+ href: string;
11
+ label: string;
12
+ icon?: LucideIcon;
13
+ iconPosition?: "start" | "end";
14
+ variant?: "primary" | "secondary";
15
+ size?: "default" | "sm";
16
+ className?: string;
17
+ children?: ReactNode;
18
+ };
19
+
20
+ export const LandingButton = ({
21
+ href,
22
+ label,
23
+ icon: Icon,
24
+ iconPosition = "end",
25
+ variant = "primary",
26
+ size = "default",
27
+ className,
28
+ children,
29
+ }: LandingButtonProps) => {
30
+ const auth = useAuth();
31
+ const to = landingHref(href, auth.isAuthenticated);
32
+ const content = children ?? (
33
+ <>
34
+ {Icon && iconPosition === "start" ? <Icon size={17} aria-hidden /> : null}
35
+ {label}
36
+ {Icon && iconPosition === "end" ? <Icon size={17} aria-hidden /> : null}
37
+ </>
38
+ );
39
+
40
+ return (
41
+ <Button
42
+ asChild
43
+ variant={variant === "primary" ? "default" : "outline"}
44
+ size={size === "sm" ? "sm" : "lg"}
45
+ className={cn(className)}
46
+ >
47
+ <Link to={to}>{content}</Link>
48
+ </Button>
49
+ );
50
+ };
@@ -1,16 +1,16 @@
1
- import { describe, expect, it } from "vitest";
2
- import { landingHref, SIGNED_IN_START_PATH } from "./landing-href.js";
3
-
4
- describe("landingHref (API-126)", () => {
5
- it("sends a signed-in visitor from sign-up to their API keys", () => {
6
- expect(landingHref("/signup", true)).toBe(SIGNED_IN_START_PATH);
7
- expect(landingHref("/signup?plan=pro", true)).toBe(SIGNED_IN_START_PATH);
8
- expect(landingHref("/register/", true)).toBe(SIGNED_IN_START_PATH);
9
- });
10
-
11
- it("keeps every link for a visitor who is not signed in, and other links for everyone", () => {
12
- expect(landingHref("/signup", false)).toBe("/signup");
13
- expect(landingHref("/introduction", true)).toBe("/introduction");
14
- expect(landingHref("/pricing", true)).toBe("/pricing");
15
- });
16
- });
1
+ import { describe, expect, it } from "vitest";
2
+ import { landingHref, SIGNED_IN_START_PATH } from "./landing-href.js";
3
+
4
+ describe("landingHref (API-126)", () => {
5
+ it("sends a signed-in visitor from sign-up to their API keys", () => {
6
+ expect(landingHref("/signup", true)).toBe(SIGNED_IN_START_PATH);
7
+ expect(landingHref("/signup?plan=pro", true)).toBe(SIGNED_IN_START_PATH);
8
+ expect(landingHref("/register/", true)).toBe(SIGNED_IN_START_PATH);
9
+ });
10
+
11
+ it("keeps every link for a visitor who is not signed in, and other links for everyone", () => {
12
+ expect(landingHref("/signup", false)).toBe("/signup");
13
+ expect(landingHref("/introduction", true)).toBe("/introduction");
14
+ expect(landingHref("/pricing", true)).toBe("/pricing");
15
+ });
16
+ });
@@ -1,14 +1,14 @@
1
- /** Where a signed-in visitor goes instead of a sign-up page: their API keys, the next thing they need. */
2
- export const SIGNED_IN_START_PATH = "/account/credentials";
3
-
4
- const SIGN_UP_PATHS = new Set(["/signup", "/register", "/sign-up"]);
5
-
6
- /**
7
- * "Get started" on the home page leads to sign-up, which a signed-in visitor has done already: for them it opens the API
8
- * keys page (API-126). Any other link is kept.
9
- */
10
- export function landingHref(href: string, signedIn: boolean): string {
11
- if (!signedIn) return href;
12
- const path = href.split(/[?#]/)[0]?.replace(/\/+$/, "") ?? href;
13
- return SIGN_UP_PATHS.has(path) ? SIGNED_IN_START_PATH : href;
14
- }
1
+ /** Where a signed-in visitor goes instead of a sign-up page: their API keys, the next thing they need. */
2
+ export const SIGNED_IN_START_PATH = "/account/credentials";
3
+
4
+ const SIGN_UP_PATHS = new Set(["/signup", "/register", "/sign-up"]);
5
+
6
+ /**
7
+ * "Get started" on the home page leads to sign-up, which a signed-in visitor has done already: for them it opens the API
8
+ * keys page (API-126). Any other link is kept.
9
+ */
10
+ export function landingHref(href: string, signedIn: boolean): string {
11
+ if (!signedIn) return href;
12
+ const path = href.split(/[?#]/)[0]?.replace(/\/+$/, "") ?? href;
13
+ return SIGN_UP_PATHS.has(path) ? SIGNED_IN_START_PATH : href;
14
+ }