{
  "name": "embed",
  "type": "registry:ui",
  "framework": "react",
  "title": "Embed",
  "description": "A Discord-inspired rich message embed with an accent bar, author, title, description, fields, footer and timestamp.",
  "files": [
    {
      "path": "ui/embed.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface EmbedProps extends Omit<React.ComponentProps<\"div\">, \"color\"> {\n  /** Accent colour of the left bar. Any CSS colour; defaults to the border colour, like `V2Container`. */\n  color?: string\n}\n\nconst Embed = React.forwardRef<HTMLDivElement, EmbedProps>(\n  ({ className, children, color, style, ...props }, ref) => (\n    <div\n      ref={ref}\n      /*\n       * SAFETY: `CSSProperties` has no index signature for custom properties,\n       * but React forwards unknown `--*` keys to the style attribute verbatim,\n       * so the extra key is written out exactly as spelled here.\n       */\n      style={\n        color\n          ? ({ ...style, \"--newt-embed-color\": color } as React.CSSProperties)\n          : style\n      }\n      className={cn(\n        \"relative flex max-w-[var(--newt-embed-max-width)] overflow-hidden rounded-[var(--newt-radius-md)] border border-s-0 border-newt-embed-border bg-newt-embed-bg before:absolute before:inset-y-0 before:start-0 before:w-1 before:bg-[var(--newt-embed-color,var(--newt-border))]\",\n        className\n      )}\n      {...props}\n    >\n      <div className=\"flex min-w-0 flex-1 flex-col gap-2 py-3 ps-5 pe-4\">\n        {children}\n      </div>\n    </div>\n  )\n)\nEmbed.displayName = \"Embed\"\n\nconst EmbedAuthor = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"flex min-w-0 items-center gap-2 text-[14px] font-semibold text-newt-text-primary\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedAuthor.displayName = \"EmbedAuthor\"\n\n/*\n * The props of the element or component `as` names, so a custom image\n * component's own props type-check.\n */\nexport type EmbedIconProps<E extends React.ElementType = \"img\"> = {\n  /**\n   * The image element or component to render. Defaults to `img`; pass your\n   * framework's image component for optimised sources.\n   */\n  as?: E\n} & Omit<React.ComponentPropsWithRef<E>, \"as\">\n\ntype EmbedIconComponent = {\n  <E extends React.ElementType = \"img\">(\n    props: EmbedIconProps<E>\n  ): React.ReactNode\n  displayName?: string\n}\n\n/*\n * SAFETY: `forwardRef` drops the generic signature. The render hands every\n * prop it does not set itself to `as` unchanged, so the props of `as` are\n * the props the part receives.\n */\n// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see SAFETY\nconst EmbedAuthorIcon = React.forwardRef<HTMLImageElement, EmbedIconProps>(\n  ({ as: Tag = \"img\", className, alt = \"\", ...props }, ref) => (\n    <Tag\n      ref={ref}\n      alt={alt}\n      aria-hidden={alt === \"\" ? true : undefined}\n      className={cn(\"h-6 w-6 shrink-0 rounded-full object-cover\", className)}\n      {...props}\n    />\n  )\n) as EmbedIconComponent\nEmbedAuthorIcon.displayName = \"EmbedAuthorIcon\"\n\nconst EmbedAuthorName = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, ...props }, ref) => (\n  <span ref={ref} className={cn(\"truncate\", className)} {...props} />\n))\nEmbedAuthorName.displayName = \"EmbedAuthorName\"\n\nconst EmbedEyebrow = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"text-[12px] font-semibold text-newt-text-secondary\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedEyebrow.displayName = \"EmbedEyebrow\"\n\nconst EmbedTitle = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"text-[16px] font-semibold text-newt-text-link\", className)}\n    {...props}\n  />\n))\nEmbedTitle.displayName = \"EmbedTitle\"\n\nconst EmbedDescription = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"text-[14px] leading-[20px] text-newt-text-secondary\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedDescription.displayName = \"EmbedDescription\"\n\nconst EmbedFields = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"mt-1 grid grid-cols-[repeat(auto-fit,minmax(120px,1fr))] gap-2\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedFields.displayName = \"EmbedFields\"\n\nconst EmbedField = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div ref={ref} className={cn(className)} {...props} />\n))\nEmbedField.displayName = \"EmbedField\"\n\nconst EmbedFieldName = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"mb-0.5 text-[13px] font-semibold text-newt-text-primary\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedFieldName.displayName = \"EmbedFieldName\"\n\nconst EmbedFieldValue = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"text-[13px] text-newt-text-secondary\", className)}\n    {...props}\n  />\n))\nEmbedFieldValue.displayName = \"EmbedFieldValue\"\n\nconst EmbedFooter = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\n      \"mt-1 flex min-w-0 items-center gap-2 text-[12px] text-newt-text-muted\",\n      className\n    )}\n    {...props}\n  />\n))\nEmbedFooter.displayName = \"EmbedFooter\"\n\n/*\n * SAFETY: `forwardRef` drops the generic signature. The render hands every\n * prop it does not set itself to `as` unchanged, so the props of `as` are\n * the props the part receives.\n */\n// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see SAFETY\nconst EmbedFooterIcon = React.forwardRef<HTMLImageElement, EmbedIconProps>(\n  ({ as: Tag = \"img\", className, alt = \"\", ...props }, ref) => (\n    <Tag\n      ref={ref}\n      alt={alt}\n      aria-hidden={alt === \"\" ? true : undefined}\n      className={cn(\"h-4 w-4 shrink-0 rounded-full object-cover\", className)}\n      {...props}\n    />\n  )\n) as EmbedIconComponent\nEmbedFooterIcon.displayName = \"EmbedFooterIcon\"\n\n/* Middle dot, the way Discord separates footer text from the timestamp. */\nconst EmbedFooterSeparator = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, children = \"\\u2022\", ...props }, ref) => (\n  <span\n    ref={ref}\n    aria-hidden=\"true\"\n    className={cn(\"mx-1\", className)}\n    {...props}\n  >\n    {children}\n  </span>\n))\nEmbedFooterSeparator.displayName = \"EmbedFooterSeparator\"\n\n/*\n * A fixed locale, not the visitor's: an embed rendered on the server and\n * hydrated in the browser has to produce the same string in both places.\n * One formatter per locale and zone, built on first use.\n */\nconst embedTimeFormats = new Map<string, Intl.DateTimeFormat>()\n\nfunction embedTimeFormat(locale: string, timeZone: string | undefined) {\n  const key = `${locale}|${timeZone ?? \"\"}`\n  let format = embedTimeFormats.get(key)\n  if (!format) {\n    format = new Intl.DateTimeFormat(locale, {\n      dateStyle: \"short\",\n      timeStyle: \"short\",\n      timeZone,\n    })\n    embedTimeFormats.set(key, format)\n  }\n  return format\n}\n\nexport interface EmbedTimestampProps extends Omit<\n  React.ComponentProps<\"time\">,\n  \"dateTime\"\n> {\n  /** The moment to render. Anything `new Date()` accepts. */\n  date: Date | number | string\n  /**\n   * Locale of the text. Pass a fixed value, not the browser's language, so\n   * the server and the browser write the same text.\n   */\n  locale?: string\n  /**\n   * Time zone of the text, such as `\"Europe/Paris\"`. Defaults to the zone of\n   * the runtime. Set it when the server and the browser sit in other zones.\n   */\n  timeZone?: string\n  /** Builds the text from the date. Wins over `locale` and `timeZone`. */\n  formatter?: (date: Date) => string\n}\n\nconst EmbedTimestamp = React.forwardRef<HTMLTimeElement, EmbedTimestampProps>(\n  (\n    {\n      className,\n      date,\n      locale = \"en-US\",\n      timeZone,\n      formatter,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const value = date instanceof Date ? date : new Date(date)\n    const valid = !Number.isNaN(value.getTime())\n    const text = valid\n      ? (formatter?.(value) ?? embedTimeFormat(locale, timeZone).format(value))\n      : \"\"\n    return (\n      <time\n        ref={ref}\n        dateTime={valid ? value.toISOString() : undefined}\n        className={cn(className)}\n        {...props}\n      >\n        {children ?? text}\n      </time>\n    )\n  }\n)\nEmbedTimestamp.displayName = \"EmbedTimestamp\"\n\nexport {\n  Embed,\n  EmbedAuthor,\n  EmbedAuthorIcon,\n  EmbedAuthorName,\n  EmbedEyebrow,\n  EmbedTitle,\n  EmbedDescription,\n  EmbedFields,\n  EmbedField,\n  EmbedFieldName,\n  EmbedFieldValue,\n  EmbedFooter,\n  EmbedFooterIcon,\n  EmbedFooterSeparator,\n  EmbedTimestamp,\n}\n",
      "type": "registry:ui"
    }
  ]
}