@dust-tt/sparkle 0.2.124 → 0.2.125-rc1

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.
@@ -1,4 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import React, { ReactNode } from "react";
3
+ import type { UrlObject } from "url";
2
4
  interface CardButtonProps {
3
5
  children: ReactNode;
4
6
  variant?: "primary" | "secondary" | "tertiary";
@@ -7,9 +9,11 @@ interface CardButtonProps {
7
9
  onClick?: () => void;
8
10
  onMouseEnter?: () => void;
9
11
  onMouseLeave?: () => void;
10
- href?: string;
12
+ href?: string | UrlObject;
11
13
  target?: string;
12
14
  rel?: string;
15
+ replace?: boolean;
16
+ shallow?: boolean;
13
17
  }
14
- export declare function CardButton({ children, variant, size, className, onClick, onMouseEnter, onMouseLeave, href, target, rel, }: CardButtonProps): React.JSX.Element;
18
+ export declare function CardButton({ children, variant, size, className, onClick, onMouseEnter, onMouseLeave, href, target, rel, replace, shallow, }: CardButtonProps): React.JSX.Element;
15
19
  export {};
@@ -1,13 +1,15 @@
1
+ /// <reference types="node" />
1
2
  import React from "react";
3
+ import type { UrlObject } from "url";
2
4
  interface TemplateItemProps {
3
5
  description: string;
6
+ href: string | UrlObject;
4
7
  id: string;
5
8
  name: string;
6
- onClick: (id: string) => void;
7
9
  visual: {
8
10
  backgroundColor: string;
9
11
  emoji: string;
10
12
  };
11
13
  }
12
- export declare function TemplateItem({ description, id, name, onClick, visual, }: TemplateItemProps): React.JSX.Element;
14
+ export declare function TemplateItem({ description, href, name, visual, }: TemplateItemProps): React.JSX.Element;
13
15
  export {};
@@ -1,11 +1,17 @@
1
+ /// <reference types="node" />
1
2
  import React, { ComponentType, MouseEvent, ReactNode } from "react";
3
+ import type { UrlObject } from "url";
2
4
  export type SparkleContextLinkType = ComponentType<{
3
- href: string;
5
+ href: string | UrlObject;
4
6
  className?: string;
5
7
  children: ReactNode;
6
8
  ariaLabel?: string;
7
9
  ariaCurrent?: boolean | "time" | "false" | "true" | "page" | "step" | "location" | "date";
8
10
  onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
11
+ replace?: boolean;
12
+ shallow?: boolean;
13
+ target?: string;
14
+ rel?: string;
9
15
  }>;
10
16
  export type SparkleContextType = {
11
17
  components: {
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { createContext, useRef, useState, useEffect, useContext, Children, cloneElement, useLayoutEffect, forwardRef, Fragment, isValidElement, createElement, useMemo, useReducer, createRef, useCallback } from 'react';
3
+ import url from 'url';
3
4
 
4
5
  function styleInject(css, ref) {
5
6
  if ( ref === void 0 ) ref = {};
@@ -32,8 +33,9 @@ var css_248z = ".s-form-checkbox,.s-form-radio {\n -webkit-appearance: none;\n
32
33
  styleInject(css_248z);
33
34
 
34
35
  var aLink = function (_a) {
35
- var href = _a.href, className = _a.className, ariaCurrent = _a.ariaCurrent, ariaLabel = _a.ariaLabel, onClick = _a.onClick, children = _a.children;
36
- return (React__default.createElement("a", { href: href, className: className, "aria-current": ariaCurrent, "aria-label": ariaLabel, onClick: onClick }, children));
36
+ var href = _a.href, className = _a.className, ariaCurrent = _a.ariaCurrent, ariaLabel = _a.ariaLabel, onClick = _a.onClick, children = _a.children, target = _a.target, rel = _a.rel;
37
+ var hrefAsString = typeof href !== "string" ? url.format(href) : href;
38
+ return (React__default.createElement("a", { href: hrefAsString, className: className, "aria-current": ariaCurrent, "aria-label": ariaLabel, onClick: onClick, target: target, rel: rel }, children));
37
39
  };
38
40
  var noHrefLink = function (_a) {
39
41
  var className = _a.className, ariaCurrent = _a.ariaCurrent, ariaLabel = _a.ariaLabel, onClick = _a.onClick, children = _a.children;
@@ -916,15 +918,12 @@ var sizeClasses$4 = {
916
918
  lg: "s-p-5 s-rounded-3xl",
917
919
  };
918
920
  function CardButton(_a) {
919
- var children = _a.children, _b = _a.variant, variant = _b === void 0 ? "primary" : _b, _c = _a.size, size = _c === void 0 ? "md" : _c, _d = _a.className, className = _d === void 0 ? "" : _d, onClick = _a.onClick, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, href = _a.href, _e = _a.target, target = _e === void 0 ? "_blank" : _e, _f = _a.rel, rel = _f === void 0 ? "" : _f;
921
+ var children = _a.children, _b = _a.variant, variant = _b === void 0 ? "primary" : _b, _c = _a.size, size = _c === void 0 ? "md" : _c, _d = _a.className, className = _d === void 0 ? "" : _d, onClick = _a.onClick, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, href = _a.href, _e = _a.target, target = _e === void 0 ? "_blank" : _e, _f = _a.rel, rel = _f === void 0 ? "" : _f, replace = _a.replace, shallow = _a.shallow;
920
922
  var components = React__default.useContext(SparkleContext).components;
921
923
  var Link = href ? components.link : noHrefLink;
922
924
  var commonClasses = classNames("s-flex s-cursor-pointer s-transition s-duration-200", variantClasses$1[variant], sizeClasses$4[size], className);
923
925
  if (href) {
924
- if (target) {
925
- return (React__default.createElement("a", { href: href, target: target, rel: rel, className: commonClasses }, children));
926
- }
927
- return (React__default.createElement(Link, { href: href, className: commonClasses }, children));
926
+ return (React__default.createElement(Link, { href: href, className: commonClasses, replace: replace, shallow: shallow, target: target, rel: rel }, children));
928
927
  }
929
928
  else {
930
929
  return (React__default.createElement("div", { className: commonClasses, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, children));
@@ -55222,9 +55221,9 @@ function Popup(_a) {
55222
55221
  }
55223
55222
 
55224
55223
  function TemplateItem(_a) {
55225
- var description = _a.description, id = _a.id, name = _a.name, onClick = _a.onClick, visual = _a.visual;
55224
+ var description = _a.description, href = _a.href, name = _a.name, visual = _a.visual;
55226
55225
  var backgroundColor = visual.backgroundColor, emoji = visual.emoji;
55227
- return (React__default.createElement(CardButton, { className: "s-flex s-max-h-32 s-max-w-lg s-flex-row s-gap-5 s-p-4", onClick: function () { return onClick(id); }, variant: "tertiary" },
55226
+ return (React__default.createElement(CardButton, { className: "s-flex s-max-h-32 s-max-w-lg s-flex-row s-gap-5 s-p-4", href: href, variant: "tertiary", replace: true, shallow: true },
55228
55227
  React__default.createElement(Avatar, { emoji: emoji, size: "lg", isRounded: true, backgroundColor: backgroundColor }),
55229
55228
  React__default.createElement("div", { className: "s-flex s-flex-col s-gap-2" },
55230
55229
  React__default.createElement("span", { className: "s-text-bold s-text-lg s-font-medium s-text-element-900" }, name),