@dust-tt/sparkle 0.2.529 → 0.2.530-rc-2

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,6 +1,7 @@
1
1
  import React from "react";
2
2
 
3
3
  import { SparkleContext } from "@sparkle/context";
4
+ import { cn } from "@sparkle/lib";
4
5
 
5
6
  export interface LinkWrapperProps {
6
7
  children: React.ReactNode;
@@ -10,29 +11,56 @@ export interface LinkWrapperProps {
10
11
  shallow?: boolean;
11
12
  target?: string;
12
13
  prefetch?: boolean;
14
+ disabled?: boolean;
15
+ ariaLabel?: string;
16
+ ariaCurrent?: string;
17
+ className?: string;
18
+ style?: React.CSSProperties;
13
19
  }
14
20
 
15
21
  export const LinkWrapper = React.forwardRef<
16
22
  HTMLAnchorElement,
17
23
  LinkWrapperProps
18
- >(({ children, href, rel, replace, shallow, target, prefetch }, ref) => {
19
- const { components } = React.useContext(SparkleContext);
24
+ >(
25
+ (
26
+ {
27
+ children,
28
+ href,
29
+ rel,
30
+ replace,
31
+ shallow,
32
+ target,
33
+ prefetch,
34
+ disabled,
35
+ ariaLabel,
36
+ ariaCurrent,
37
+ className,
38
+ style,
39
+ },
40
+ ref
41
+ ) => {
42
+ const { components } = React.useContext(SparkleContext);
20
43
 
21
- if (href) {
22
- return (
23
- <components.link
24
- ref={ref}
25
- href={href}
26
- target={target}
27
- rel={rel}
28
- replace={replace}
29
- shallow={shallow}
30
- prefetch={prefetch}
31
- >
32
- {children}
33
- </components.link>
34
- );
35
- }
44
+ if (href) {
45
+ return (
46
+ <components.link
47
+ ref={ref}
48
+ href={href}
49
+ target={target}
50
+ rel={rel}
51
+ replace={replace}
52
+ shallow={shallow}
53
+ prefetch={prefetch}
54
+ className={cn(className, disabled && "s-pointer-events-none")}
55
+ aria-label={ariaLabel}
56
+ aria-current={ariaCurrent}
57
+ style={style}
58
+ >
59
+ {children}
60
+ </components.link>
61
+ );
62
+ }
36
63
 
37
- return children;
38
- });
64
+ return children;
65
+ }
66
+ );
package/src/context.tsx CHANGED
@@ -2,7 +2,7 @@ import React, { ComponentType, MouseEvent, ReactNode } from "react";
2
2
  import type { UrlObject } from "url";
3
3
  import url from "url";
4
4
 
5
- type SparkleLinkProps = {
5
+ export type SparkleLinkProps = {
6
6
  href: string | UrlObject;
7
7
  className?: string;
8
8
  children: ReactNode;
@@ -22,6 +22,7 @@ type SparkleLinkProps = {
22
22
  target?: string;
23
23
  rel?: string;
24
24
  prefetch?: boolean;
25
+ style?: React.CSSProperties;
25
26
  };
26
27
 
27
28
  export type SparkleContextLinkType = ComponentType<
@@ -39,7 +40,17 @@ export const aLink: SparkleContextLinkType = React.forwardRef<
39
40
  SparkleLinkProps
40
41
  >(
41
42
  (
42
- { href, className, ariaCurrent, ariaLabel, onClick, children, target, rel },
43
+ {
44
+ href,
45
+ className,
46
+ ariaCurrent,
47
+ ariaLabel,
48
+ onClick,
49
+ children,
50
+ target,
51
+ rel,
52
+ style,
53
+ },
43
54
  ref
44
55
  ) => {
45
56
  const hrefAsString = typeof href !== "string" ? url.format(href) : href;
@@ -54,6 +65,7 @@ export const aLink: SparkleContextLinkType = React.forwardRef<
54
65
  onClick={onClick}
55
66
  target={target}
56
67
  rel={rel}
68
+ style={style}
57
69
  >
58
70
  {children}
59
71
  </a>
@@ -120,6 +120,13 @@ const ButtonBySize = ({
120
120
  label="Button with href"
121
121
  href="hello"
122
122
  />
123
+ <Button
124
+ size={size}
125
+ variant="primary"
126
+ label="Disabled button with href"
127
+ href="hello"
128
+ disabled
129
+ />
123
130
  </div>
124
131
  <div className="s-flex s-items-center s-gap-4">
125
132
  <Button size={size} label="Button" isLoading />
@@ -140,10 +147,29 @@ const ButtonBySize = ({
140
147
 
141
148
  export const Gallery: Story = {
142
149
  render: () => (
143
- <div className="s-flex s-flex-col s-gap-4">
144
- <ButtonBySize size="xs" />
145
- <ButtonBySize size="sm" />
146
- <ButtonBySize size="md" />
150
+ <div className="s-flex s-flex-col s-gap-6">
151
+ <div className="s-flex s-flex-col s-gap-4">
152
+ <ButtonBySize size="xs" />
153
+ <ButtonBySize size="sm" />
154
+ <ButtonBySize size="md" />
155
+ </div>
156
+ <Separator />
157
+ <div>
158
+ <h3 className="mb-3 s-text-primary dark:s-text-primary-50">
159
+ With tooltip
160
+ </h3>
161
+ <div className="s-flex s-gap-4">
162
+ <Button label="Button" tooltip="Hello" />
163
+ <Button label="Disabled button" tooltip="Hello" disabled />
164
+ <Button label="Button with href" tooltip="Hello" href="hello" />
165
+ <Button
166
+ label="Disabled button with href (won't work)"
167
+ tooltip="Hello"
168
+ href="hello"
169
+ disabled
170
+ />
171
+ </div>
172
+ </div>
147
173
  </div>
148
174
  ),
149
175
  };