@dust-tt/sparkle 0.1.4 → 0.1.6
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/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Tab.js +5 -3
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/components/Tab.js.map +1 -1
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.d.ts +11 -6
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.js +10 -2
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/context.js.map +1 -1
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.d.ts +2 -0
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.js +2 -0
- package/.rollup.cache/home/spolu/code/dust/sparkle/dist/index.js.map +1 -1
- package/dist/cjs/context.d.ts +11 -6
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +18 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/context.d.ts +11 -6
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +18 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Tab.tsx +10 -4
- package/src/context.tsx +48 -8
- package/src/index.ts +3 -0
package/package.json
CHANGED
package/src/components/Tab.tsx
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { ReactComponentLike } from "prop-types";
|
|
2
2
|
import React, { MouseEvent } from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
divLink,
|
|
6
|
+
SparkleContext,
|
|
7
|
+
SparkleContextLinkType,
|
|
8
|
+
} from "@sparkle/context";
|
|
5
9
|
import { classNames } from "@sparkle/lib/utils";
|
|
6
10
|
|
|
7
11
|
type TabProps = {
|
|
@@ -62,10 +66,12 @@ const tabSizingClasses = {
|
|
|
62
66
|
|
|
63
67
|
export function Tab({ tabs, onTabClick, className = "" }: TabProps) {
|
|
64
68
|
const { components } = React.useContext(SparkleContext);
|
|
65
|
-
const Link = components.link;
|
|
66
|
-
|
|
67
69
|
const renderTabs = () =>
|
|
68
70
|
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
|
+
|
|
69
75
|
const tabStateClasses = tab.current
|
|
70
76
|
? tabClasses.selected
|
|
71
77
|
: tabClasses.default;
|
|
@@ -98,7 +104,7 @@ export function Tab({ tabs, onTabClick, className = "" }: TabProps) {
|
|
|
98
104
|
className={finalTabClasses}
|
|
99
105
|
aria-current={tab.current ? "page" : undefined}
|
|
100
106
|
onClick={(event) => onTabClick?.(tab.label, event)}
|
|
101
|
-
href={
|
|
107
|
+
href={href}
|
|
102
108
|
>
|
|
103
109
|
<div
|
|
104
110
|
className={
|
package/src/context.tsx
CHANGED
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import React, { ComponentType, MouseEvent, ReactNode } from "react";
|
|
2
2
|
|
|
3
|
+
export type SparkleContextLinkType = ComponentType<{
|
|
4
|
+
key?: React.Key | null;
|
|
5
|
+
href: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
arriaCurrent?:
|
|
9
|
+
| boolean
|
|
10
|
+
| "time"
|
|
11
|
+
| "false"
|
|
12
|
+
| "true"
|
|
13
|
+
| "page"
|
|
14
|
+
| "step"
|
|
15
|
+
| "location"
|
|
16
|
+
| "date";
|
|
17
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
18
|
+
}>;
|
|
19
|
+
|
|
3
20
|
export type SparkleContextType = {
|
|
4
21
|
components: {
|
|
5
|
-
link:
|
|
6
|
-
href?: string;
|
|
7
|
-
className?: string;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
10
|
-
}>;
|
|
22
|
+
link: SparkleContextLinkType;
|
|
11
23
|
};
|
|
12
24
|
};
|
|
13
25
|
|
|
26
|
+
export const aLink: SparkleContextLinkType = ({
|
|
27
|
+
key,
|
|
28
|
+
href,
|
|
29
|
+
className,
|
|
30
|
+
arriaCurrent,
|
|
31
|
+
children,
|
|
32
|
+
}) => (
|
|
33
|
+
<a key={key} href={href} className={className} aria-current={arriaCurrent}>
|
|
34
|
+
{children}
|
|
35
|
+
</a>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const divLink: SparkleContextLinkType = ({
|
|
39
|
+
key,
|
|
40
|
+
className,
|
|
41
|
+
arriaCurrent,
|
|
42
|
+
children,
|
|
43
|
+
}) => (
|
|
44
|
+
<div key={key} className={className} aria-current={arriaCurrent}>
|
|
45
|
+
{children}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
|
|
14
49
|
export const SparkleContext = React.createContext<SparkleContextType>({
|
|
15
50
|
components: {
|
|
16
|
-
link: ({ href, className, children }) => (
|
|
17
|
-
<a
|
|
51
|
+
link: ({ key, href, className, arriaCurrent, children }) => (
|
|
52
|
+
<a
|
|
53
|
+
key={key}
|
|
54
|
+
href={href}
|
|
55
|
+
className={className}
|
|
56
|
+
aria-current={arriaCurrent}
|
|
57
|
+
>
|
|
18
58
|
{children}
|
|
19
59
|
</a>
|
|
20
60
|
),
|