Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

2.0 KB
Raw Blame
"use client";

/** ImagePickerButton — the headline API: ONE button that opens the
 *  ImagePickerDialog. Pick a colour / gradient / texture, upload a file, paste
 *  a URL, or grab a stock photo (live search via /api/v1/stock/search) —
 *  `onChange` fires with the chosen ImageValue. Use it anywhere you let a user
 *  set an image: page cover, profile header, card hero, wallpaper, banner.
 *  Pass `trigger` to swap the button for any node, or `label` / `variant` /
 *  `size` to restyle the default. Upload backend is injected (`onUpload`). */

import * as React from "react";
import { ImageIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import type { ImageValue, ImageSourceProps } from "../types";
import { ImagePickerDialog } from "./image-picker-dialog";

interface Props extends ImageSourceProps {
  onChange: (img: ImageValue) => void;
  /** Default-button text (ignored when `trigger` is supplied). */
  label?: string;
  /** Dialog heading. */
  title?: string;
  /** Override the default button with any clickable node. */
  trigger?: React.ReactNode;
  className?: string;
  variant?: React.ComponentProps<typeof Button>["variant"];
  size?: React.ComponentProps<typeof Button>["size"];
  /** Pre-fill + auto-run the stock search (opens on that tab). */
  defaultQuery?: string;
}

export function ImagePickerButton({
  onChange, label = "Choose image", title, trigger, className,
  variant = "outline", size = "sm", onUpload, defaultQuery,
}: Props) {
  const [open, setOpen] = React.useState(false);
  return (
    <>
      {trigger ? (
        <span className="contents" onClick={() => setOpen(true)}>{trigger}</span>
      ) : (
        <Button type="button" variant={variant} size={size} className={className} onClick={() => setOpen(true)}>
          <ImageIcon className="mr-1.5 h-4 w-4" /> {label}
        </Button>
      )}
      <ImagePickerDialog
        open={open}
        onOpenChange={setOpen}
        onSelect={onChange}
        onUpload={onUpload}
        title={title}
        defaultQuery={defaultQuery}
      />
    </>
  );
}