@dust-tt/sparkle 0.1.6 → 0.1.8

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.
Files changed (32) hide show
  1. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Button.d.ts +1 -1
  2. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Button.js.map +1 -1
  3. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Item.d.ts +13 -0
  4. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Item.js +63 -0
  5. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Item.js.map +1 -0
  6. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Tab.js +5 -5
  7. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Tab.js.map +1 -1
  8. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.d.ts +3 -2
  9. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.js +6 -9
  10. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.js.map +1 -1
  11. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.d.ts +2 -0
  12. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.js +2 -0
  13. package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.js.map +1 -1
  14. package/dist/cjs/components/Button.d.ts +1 -1
  15. package/dist/cjs/components/Item.d.ts +13 -0
  16. package/dist/cjs/context.d.ts +3 -2
  17. package/dist/cjs/index.d.ts +2 -0
  18. package/dist/cjs/index.js +84 -24
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/esm/components/Button.d.ts +1 -1
  21. package/dist/esm/components/Item.d.ts +13 -0
  22. package/dist/esm/context.d.ts +3 -2
  23. package/dist/esm/index.d.ts +2 -0
  24. package/dist/esm/index.js +84 -25
  25. package/dist/esm/index.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/components/Button.tsx +3 -1
  28. package/src/components/Item.tsx +122 -0
  29. package/src/components/Tab.tsx +7 -6
  30. package/src/context.tsx +26 -17
  31. package/src/index.ts +3 -0
  32. package/tsconfig.json +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dust-tt/sparkle",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "scripts": {
5
5
  "build": "rollup -c"
6
6
  },
@@ -1,5 +1,7 @@
1
- import React, { MouseEvent, ComponentType } from "react";
1
+ import React, { ComponentType,MouseEvent } from "react";
2
+
2
3
  import { classNames } from "@sparkle/lib/utils";
4
+
3
5
  import { Icon } from "./Icon";
4
6
 
5
7
  type ButtonProps = {
@@ -0,0 +1,122 @@
1
+ import React, { ComponentType, MouseEvent } from "react";
2
+
3
+ import {
4
+ noHrefLink,
5
+ SparkleContext,
6
+ SparkleContextLinkType,
7
+ } from "@sparkle/context";
8
+ import { ChevronRight } from "@sparkle/icons/mini";
9
+ import { classNames } from "@sparkle/lib/utils";
10
+
11
+ import { Icon } from "./Icon";
12
+
13
+ type ItemProps = {
14
+ onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
15
+ size?: "sm" | "md";
16
+ selected?: boolean;
17
+ disabled?: boolean;
18
+ label: string;
19
+ icon?: ComponentType;
20
+ className?: string;
21
+ href?: string;
22
+ };
23
+
24
+ const baseClasses =
25
+ "group inline-flex transition-color ease-out duration-400 box-border gap-x-2 py-3 text-sm font-semibold";
26
+
27
+ const iconBaseClasses = "h-5 w-5 transition-color ease-out duration-400";
28
+
29
+ const iconClasses = {
30
+ default: {
31
+ base: "h-5 w-5 text-element-700",
32
+ hover: "group-hover:text-action-400",
33
+ dark: {
34
+ base: "dark:text-element-600-dark",
35
+ hover: "dark:group-hover:text-action-500-dark",
36
+ },
37
+ },
38
+ selected: {
39
+ base: "text-action-500",
40
+ hover: "",
41
+ dark: {
42
+ base: "dark:text-action-500-dark",
43
+ hover: "",
44
+ },
45
+ },
46
+ };
47
+
48
+ const stateClasses = {
49
+ default: {
50
+ base: "text-element-900 cursor-pointer",
51
+ hover: "hover:text-action-500",
52
+ active: "active:text-action-700",
53
+ dark: {
54
+ base: "dark:bg-action-500-dark dark:border-action-600-dark",
55
+ hover: "dark:hover:bg-action-500-dark dark:hover:border-action-500-dark",
56
+ active:
57
+ "dark:active:bg-action-600-dark dark:active:border-action-700-dark",
58
+ },
59
+ disabled: "cursor-not-allowed opacity-50 bg-gray-200",
60
+ },
61
+ selected: {
62
+ base: "bg-action-500 border-action-600 text-white cursor-default",
63
+ dark: {
64
+ base: "dark:bg-action-500-dark dark:border-action-600-dark",
65
+ },
66
+ },
67
+ };
68
+
69
+ export function Item({
70
+ onClick,
71
+ selected = false,
72
+ disabled = false,
73
+ label,
74
+ icon,
75
+ className = "",
76
+ href,
77
+ }: ItemProps) {
78
+ const { components } = React.useContext(SparkleContext);
79
+
80
+ const currentStateClasses = selected
81
+ ? stateClasses.selected
82
+ : stateClasses.default;
83
+
84
+ const itemClasses = classNames(
85
+ baseClasses,
86
+ currentStateClasses.base,
87
+ currentStateClasses.dark?.base,
88
+ disabled ? currentStateClasses.disabled : "",
89
+ !selected && !disabled ? currentStateClasses.hover : "",
90
+ !selected && !disabled ? currentStateClasses.dark?.hover : "",
91
+ !selected && !disabled ? currentStateClasses.active : "",
92
+ !selected && !disabled ? currentStateClasses.dark?.active : "",
93
+ className
94
+ );
95
+
96
+ const currentIconClasses = selected
97
+ ? iconClasses.selected
98
+ : iconClasses.default;
99
+
100
+ const finalIconClasses = classNames(
101
+ iconBaseClasses,
102
+ currentIconClasses.base,
103
+ currentIconClasses.hover,
104
+ currentIconClasses.dark.base,
105
+ currentIconClasses.dark.hover
106
+ );
107
+
108
+ const Link: SparkleContextLinkType = href ? components.link : noHrefLink;
109
+
110
+ return (
111
+ <Link
112
+ className={itemClasses}
113
+ onClick={selected || disabled ? undefined : onClick}
114
+ aria-label={label}
115
+ href={href || "#"}
116
+ >
117
+ {icon && <Icon IconComponent={icon} className={finalIconClasses} />}
118
+ <span className="grow">{label}</span>
119
+ <Icon IconComponent={ChevronRight} className={finalIconClasses} />
120
+ </Link>
121
+ );
122
+ }
@@ -2,7 +2,7 @@ import { ReactComponentLike } from "prop-types";
2
2
  import React, { MouseEvent } from "react";
3
3
 
4
4
  import {
5
- divLink,
5
+ noHrefLink,
6
6
  SparkleContext,
7
7
  SparkleContextLinkType,
8
8
  } from "@sparkle/context";
@@ -66,12 +66,9 @@ const tabSizingClasses = {
66
66
 
67
67
  export function Tab({ tabs, onTabClick, className = "" }: TabProps) {
68
68
  const { components } = React.useContext(SparkleContext);
69
+
69
70
  const renderTabs = () =>
70
71
  tabs.map((tab) => {
71
- // If we don't have an set the href to "" and use a div.
72
- const href = tab.href || "";
73
- const Link: SparkleContextLinkType = tab.href ? components.link : divLink;
74
-
75
72
  const tabStateClasses = tab.current
76
73
  ? tabClasses.selected
77
74
  : tabClasses.default;
@@ -98,13 +95,17 @@ export function Tab({ tabs, onTabClick, className = "" }: TabProps) {
98
95
  className
99
96
  );
100
97
 
98
+ const Link: SparkleContextLinkType = tab.href
99
+ ? components.link
100
+ : noHrefLink;
101
+
101
102
  return (
102
103
  <Link
103
104
  key={tab.label}
104
105
  className={finalTabClasses}
105
106
  aria-current={tab.current ? "page" : undefined}
106
107
  onClick={(event) => onTabClick?.(tab.label, event)}
107
- href={href}
108
+ href={tab.href || "#"}
108
109
  >
109
110
  <div
110
111
  className={
package/src/context.tsx CHANGED
@@ -5,7 +5,8 @@ export type SparkleContextLinkType = ComponentType<{
5
5
  href: string;
6
6
  className?: string;
7
7
  children: ReactNode;
8
- arriaCurrent?:
8
+ ariaLabel?: string;
9
+ ariaCurrent?:
9
10
  | boolean
10
11
  | "time"
11
12
  | "false"
@@ -27,36 +28,44 @@ export const aLink: SparkleContextLinkType = ({
27
28
  key,
28
29
  href,
29
30
  className,
30
- arriaCurrent,
31
+ ariaCurrent,
32
+ ariaLabel,
33
+ onClick,
31
34
  children,
32
35
  }) => (
33
- <a key={key} href={href} className={className} aria-current={arriaCurrent}>
36
+ <a
37
+ key={key}
38
+ href={href}
39
+ className={className}
40
+ aria-current={ariaCurrent}
41
+ aria-label={ariaLabel}
42
+ onClick={onClick}
43
+ >
34
44
  {children}
35
45
  </a>
36
46
  );
37
47
 
38
- export const divLink: SparkleContextLinkType = ({
48
+ export const noHrefLink: SparkleContextLinkType = ({
39
49
  key,
40
50
  className,
41
- arriaCurrent,
51
+ ariaCurrent,
52
+ ariaLabel,
53
+ onClick,
42
54
  children,
43
55
  }) => (
44
- <div key={key} className={className} aria-current={arriaCurrent}>
56
+ <a
57
+ key={key}
58
+ className={className}
59
+ aria-current={ariaCurrent}
60
+ arria-label={ariaLabel}
61
+ onClick={onClick}
62
+ >
45
63
  {children}
46
- </div>
64
+ </a>
47
65
  );
48
66
 
49
67
  export const SparkleContext = React.createContext<SparkleContextType>({
50
68
  components: {
51
- link: ({ key, href, className, arriaCurrent, children }) => (
52
- <a
53
- key={key}
54
- href={href}
55
- className={className}
56
- aria-current={arriaCurrent}
57
- >
58
- {children}
59
- </a>
60
- ),
69
+ link: aLink,
61
70
  },
62
71
  });
package/src/index.ts CHANGED
@@ -9,6 +9,9 @@ export { Button };
9
9
  import { Tab } from "./components/Tab";
10
10
  export { Tab };
11
11
 
12
+ import { Item } from "./components/Item";
13
+ export { Item };
14
+
12
15
  import { Icon } from "./components/Icon";
13
16
  export { Icon };
14
17
 
package/tsconfig.json CHANGED
@@ -23,9 +23,9 @@
23
23
  "include": [
24
24
  "src/**/*.ts",
25
25
  "src/**/*.tsx",
26
- ".eslintrc.js",
27
- "tailwind.config.js",
28
- "rollup.config.mjs"
26
+ // ".eslintrc.js",
27
+ // "tailwind.config.js",
28
+ // "rollup.config.mjs"
29
29
  ],
30
30
  "exclude": ["node_modules", "dist"]
31
31
  }