@dust-tt/sparkle 0.2.216 → 0.2.217

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": "@dust-tt/sparkle",
3
- "version": "0.2.216",
3
+ "version": "0.2.217",
4
4
  "scripts": {
5
5
  "build": "rm -rf dist && rollup -c",
6
6
  "build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
@@ -1,7 +1,7 @@
1
1
  import type { ComponentType } from "react";
2
2
  import React from "react";
3
3
 
4
- import { noHrefLink, SparkleContextLinkType } from "@sparkle/context";
4
+ import { SparkleContextLinkType } from "@sparkle/context";
5
5
  import {
6
6
  ChevronRightIcon,
7
7
  DropdownMenu,
@@ -32,12 +32,15 @@ type BreadcrumbsAccumulator = {
32
32
  export function Breadcrumbs({ items }: BreadcrumbProps) {
33
33
  const { components } = React.useContext(SparkleContext);
34
34
 
35
+ const Link: SparkleContextLinkType = components.link;
36
+
35
37
  const { itemsShown, itemsHidden } = items.reduce(
36
38
  (acc: BreadcrumbsAccumulator, item, index) => {
37
39
  if (items.length <= 5 || index < 2 || index >= items.length - 2) {
38
40
  acc.itemsShown.push(item);
39
41
  } else if (index === 2) {
40
42
  acc.itemsShown.push({ label: ELLIPSIS_STRING });
43
+ acc.itemsHidden.push(item);
41
44
  } else {
42
45
  acc.itemsHidden.push(item);
43
46
  }
@@ -57,26 +60,40 @@ export function Breadcrumbs({ items }: BreadcrumbProps) {
57
60
  <Icon visual={item.icon} className="s-text-brand" />
58
61
  {item.label === ELLIPSIS_STRING ? (
59
62
  <DropdownMenu>
60
- <DropdownMenu.Button>${ELLIPSIS_STRING}</DropdownMenu.Button>
63
+ <DropdownMenu.Button>{ELLIPSIS_STRING}</DropdownMenu.Button>
61
64
  <DropdownMenu.Items origin="topLeft">
62
65
  {itemsHidden.map((item, index) => (
63
66
  <DropdownMenu.Item
64
- key={`breadcrumbs-hidden-${index}`}
65
67
  icon={item.icon}
66
68
  label={item.label}
69
+ href={item.href || "#"}
70
+ key={`breadcrumbs-hidden-${index}`}
67
71
  >
68
- {getLinkForItem(item, false, components.link)}
72
+ {truncateWithTooltip(
73
+ item.label,
74
+ LABEL_TRUNCATE_LENGTH_MIDDLE
75
+ )}
69
76
  </DropdownMenu.Item>
70
77
  ))}
71
78
  </DropdownMenu.Items>
72
79
  </DropdownMenu>
73
80
  ) : (
74
81
  <div>
75
- {getLinkForItem(
76
- item,
77
- index === itemsShown.length - 1,
78
- components.link
79
- )}
82
+ <Link
83
+ href={item.href || "#"}
84
+ className={
85
+ index === items.length - 1
86
+ ? "s-text-element-900"
87
+ : "s-text-element-700"
88
+ }
89
+ >
90
+ {index === items.length - 1
91
+ ? truncateWithTooltip(item.label, LABEL_TRUNCATE_LENGTH_END)
92
+ : truncateWithTooltip(
93
+ item.label,
94
+ LABEL_TRUNCATE_LENGTH_MIDDLE
95
+ )}
96
+ </Link>
80
97
  </div>
81
98
  )}
82
99
  {index === itemsShown.length - 1 ? null : (
@@ -89,25 +106,6 @@ export function Breadcrumbs({ items }: BreadcrumbProps) {
89
106
  );
90
107
  }
91
108
 
92
- function getLinkForItem(
93
- item: BreadcrumbItem,
94
- isLast: boolean,
95
- link: SparkleContextLinkType
96
- ) {
97
- const Link: SparkleContextLinkType = item.href ? link : noHrefLink;
98
-
99
- return (
100
- <Link
101
- href={item.href || "#"}
102
- className={isLast ? "s-text-element-900" : "s-text-element-700"}
103
- >
104
- {isLast
105
- ? truncateWithTooltip(item.label, LABEL_TRUNCATE_LENGTH_END)
106
- : truncateWithTooltip(item.label, LABEL_TRUNCATE_LENGTH_MIDDLE)}
107
- </Link>
108
- );
109
- }
110
-
111
109
  function truncateWithTooltip(text: string, length: number) {
112
110
  return text.length > length ? (
113
111
  <Tooltip
@@ -36,7 +36,7 @@ export const BreadcrumbsExample = () => {
36
36
  icon: CompanyIcon,
37
37
  },
38
38
  { label: "My Vault", href: "#" },
39
- { label: "Data Sources" },
39
+ { label: "Data Sources", href: ".." },
40
40
  { label: "Folder1", href: "#", icon: FolderIcon },
41
41
  { label: "With ellipsis", href: "#" },
42
42
  ];