// ~/src/siteplane/components/store-button/store-button.tsx "use client"; import type * as React from "react"; import { useSiteplaneMessages } from "../../system/locale/messages-context"; import { useResolvedControlSize } from "../../system/provider/siteplane-ui-provider"; import { Button } from "../button"; import { AppleLogo } from "../social-button/social-logos"; import { AppGalleryLogo, GalaxyStoreLogo, GooglePlayLogo } from "./store-logos"; import "./store-button.css"; /** The mobile app stores a StoreButton links to. */ export type StoreButtonStore = "app-store" | "app-gallery" | "galaxy-store" | "google-play"; /** * The sizes of the Button that a StoreButton is: md is 40 px high with a * 24 px mark, lg 44 px with everything 10 % larger and xl 48 px with * everything 20 % larger. There is no sm: 40 px is the smallest App Store * badge Apple allows on screen. */ export type StoreButtonSize = "md" | "lg" | "xl"; /** * `solid` is the black badge, black in light and dark themes, with the store's * mark in its colours. `outline` is the badge without its fill: text, mark and * ring in the text colour. */ export type StoreButtonAppearance = "outline" | "solid"; // The store's name, and the message of the store's own wording, the caption // over the name. Together they are the link's name. const stores = { "app-gallery": { caption: "appGallery", name: "AppGallery" }, "app-store": { caption: "appStore", name: "App Store" }, "galaxy-store": { caption: "galaxyStore", name: "Galaxy Store" }, "google-play": { caption: "googlePlay", name: "Google Play" }, } as const satisfies Record< StoreButtonStore, { caption: "appGallery" | "appStore" | "galaxyStore" | "googlePlay"; name: string; } >; export type StoreButtonProps = Omit, "children"> & { /** The store, which picks the mark, the caption and the store's name. */ store: StoreButtonStore; /** * md (40 px), lg (44 px) or xl (48 px). The control size of the * SiteplaneUIProvider by default, and md where that is sm. */ size?: StoreButtonSize | undefined; /** `solid` (the default) or `outline`. */ appearance?: StoreButtonAppearance | undefined; }; // The mark of a store. It is decoration: the link's name says the store. function logoFor( store: StoreButtonStore, colorful: boolean, ): React.ReactElement { const logo = { "aria-hidden": true, className: "sp-store-button-logo", "data-slot": "store-button-logo", } as const; switch (store) { case "app-gallery": return ; case "app-store": return ; case "galaxy-store": return ; case "google-play": return ; } } /** * A link to an app in a mobile app store: the kit Button rendered as an * anchor, with the store's mark before two lines of text, the store's caption * over its name. The solid badge is the inverse Button held black in both * themes; the outline badge is the outline Button with its ring in the text * colour (store-button.css). Size, radius, focus, hover, press and cursor are * the Button's: it takes the provider's control size, as every Button does, * but never goes below md, 40 px, the smallest App Store badge Apple allows on * screen (Lukas, 4 November 2026; it was fixed at md). The link is named with * the store's wording, such as "Get it on Google Play", unless `aria-label` * names it. Anchor props pass through, such as `href`, `target`, `rel` and * `onClick`. */ export function StoreButton({ "aria-label": ariaLabel, appearance = "solid", className, size: sizeProp, store, ...props }: StoreButtonProps): React.ReactElement { const messages = useSiteplaneMessages("storeButton"); const resolved = useResolvedControlSize(sizeProp); const size = resolved === "sm" ? "md" : resolved; const caption = messages[stores[store].caption]; const { name } = stores[store]; return ( ); } // ~/src/siteplane/components/store-button/store-logos.tsx import type * as React from "react"; /* * The marks of Google Play, Galaxy Store and AppGallery, drawn for the kit in * a few simple shapes on a 24 x 24 grid. They are no store's official badge * artwork. The App Store's mark is SocialButton's Apple logo. */ /** The props of a store mark: an svg on a 24 x 24 grid. */ export type StoreLogoProps = React.SVGProps & { /** The store's own colours; without them the mark takes the text colour. */ colorful?: boolean | undefined; }; /* * Google Play: a play triangle cut into four pieces by two lines that meet * 56 % across it, in the four colours of Google's own logo. In colour the left * piece is the whole triangle and the other three lie on it, so no seam shows * between them; in one colour each piece is drawn 0.6 units in from the lines * it shares, so a gap of 1.2 units parts the pieces. */ const googlePlayTriangle = "M2 0.75L22 12L2 23.25Z"; const googlePlayPieces = [ { color: "#4285F4", piece: "M2 0.75L13.2 12L2 23.25Z", inset: "M2 1.6L12.35 12L2 22.4Z", }, { color: "#34A853", piece: "M2 0.75L16.8 9.07L13.2 12Z", inset: "M3.92 1.83L16.24 8.76L13.24 11.19Z", }, { color: "#FBBC04", piece: "M16.8 9.07L22 12L16.8 14.93L13.2 12Z", inset: "M17.36 9.39L22 12L17.36 14.61L14.15 12Z", }, { color: "#EA4335", piece: "M2 23.25L13.2 12L16.8 14.93Z", inset: "M3.92 22.17L13.24 12.81L16.24 15.24Z", }, ] as const; export function GooglePlayLogo({ colorful = false, ...props }: StoreLogoProps): React.ReactElement { return ( {colorful ? ( <> {googlePlayPieces.slice(1).map(({ color, piece }) => ( ))} ) : ( googlePlayPieces.map(({ color, inset }) => ( )) )} ); } /* * Galaxy Store: a white shopping bag, its body and the arc of its handle, on a * rounded tile in the average colour of the store's gradient. In one colour the * tile takes the text colour and the bag is cut out of it. */ const galaxyStoreTile = "M9 0h6a9 9 0 0 1 9 9v6a9 9 0 0 1-9 9H9a9 9 0 0 1-9-9V9a9 9 0 0 1 9-9Z"; const galaxyStoreBag = "M8.25 9a3.75 3.75 0 0 1 7.5 0h-1.5a2.25 2.25 0 0 0-4.5 0ZM7 9h10a1 1 0 0 1 1 1v5.5a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V10a1 1 0 0 1 1-1Z"; export function GalaxyStoreLogo({ colorful = false, ...props }: StoreLogoProps): React.ReactElement { return ( {colorful ? ( <> ) : ( )} ); } /* * AppGallery: the white smile of the store's bag on a red rounded tile. In one * colour the tile takes the text colour and the smile is cut out of it. */ const appGalleryTile = "M6 0h12a6 6 0 0 1 6 6v12a6 6 0 0 1-6 6H6a6 6 0 0 1-6-6V6a6 6 0 0 1 6-6Z"; const appGallerySmile = "M7.75 9a4.25 4.25 0 0 0 8.5 0H15a3 3 0 0 1-6 0Z"; export function AppGalleryLogo({ colorful = false, ...props }: StoreLogoProps): React.ReactElement { return ( {colorful ? ( <> ) : ( )} ); } // ~/src/siteplane/components/store-button/store-button.css @layer theme, base, components, siteplane, utilities; @layer siteplane { /* A StoreButton is the kit Button as a link at the control size of its * provider, never below md (Lukas, 4 November 2026; it was fixed at md): md * is Button md (40 px), lg Button lg (44 px) and xl Button xl (48 px), with * their padding, radius, focus, hover, press and cursor. Its content is the * store's mark, 8 px before two lines of text: the store's caption, 10 px, * over its name, 16 px, in the kit's typeface. md draws the mark at 24 px; * lg and xl draw mark, gap and text at --sp-store-button-scale, 10 and 20 % * larger, the steps from 40 to 44 and 48 px. The extra [data-chassis] ranks * these rules above the Button's size rules, so the two sheets can load in * any order. */ :root .sp-store-button[data-size="md"] { --sp-store-button-scale: 1; } :root .sp-store-button[data-size="lg"] { --sp-store-button-scale: 1.1; } :root .sp-store-button[data-size="xl"] { --sp-store-button-scale: 1.2; } :root .sp-store-button[data-chassis][data-size] { --sp-rw-button-icon: calc( var(--sp-rw-space-6) * var(--sp-store-button-scale, 1) ); --sp-rw-button-content-gap: calc( var(--sp-rw-space-2) * var(--sp-store-button-scale, 1) ); } /* The two lines start at one edge, and the pair centres in the Button's * height. Their unitless lines scale with the text at lg and xl; the name's * line is its size, so in Inter the baselines stand 16 px apart at md, at * 15.5 and 31.5 px from the top, as on the stores' badges. */ :root .sp-store-button-text { display: flex; flex-direction: column; align-items: flex-start; } :root .sp-store-button-caption { font-size: calc(var(--sp-rw-font-10) * var(--sp-store-button-scale, 1)); line-height: 1.2; } :root .sp-store-button-name { font-size: calc(var(--sp-rw-font-16) * var(--sp-store-button-scale, 1)); font-weight: var(--sp-rw-font-weight-label); line-height: 1; } /* Google Play and AppGallery set their caption in capitals. */ :root .sp-store-button[data-store="google-play"] .sp-store-button-caption, :root .sp-store-button[data-store="app-gallery"] .sp-store-button-caption { text-transform: uppercase; } /* A mark keeps its full colour, without the Button's 80 % icon opacity. */ :root .sp-store-button-logo { opacity: 1; } /* The solid badge is the inverse Button, the kit's black Button, held black * in Light and Dark: white text and mark on black, and the veil of hover and * press in its white text, at the inverse Button's own steps. Its ring is the * stores' light grey (#a6a6a6) in Light and white in Dark. */ :root .sp-store-button[data-chassis][data-appearance="solid"] { --sp-rw-button-source: oklch(0% 0 0); --sp-rw-button-text: var(--sp-rw-fg-emphasis); --sp-rw-button-interaction: var(--sp-rw-button-text); --sp-rw-button-rim: inset 0 0 0 var(--sp-rw-border-default) light-dark(oklch(72.5% 0 0), oklch(100% 0 0)); } /* The outline badge is the outline Button with its ring in its text colour, * the primary text, as its mark and its words. */ :root .sp-store-button[data-chassis][data-appearance="outline"] { --sp-rw-button-rim: inset 0 0 0 var(--sp-rw-border-default) var(--sp-rw-button-text); } } // ~/src/siteplane/components/store-button/index.ts export * from "./store-button";