@zentauri-ui/zentauri-components 1.8.0 → 1.8.1
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/README.md +8 -4
- package/cli/registry.json +2 -0
- package/dist/chunk-7TGUGTTQ.mjs +147 -0
- package/dist/chunk-7TGUGTTQ.mjs.map +1 -0
- package/dist/chunk-CQMV7BB6.js +50 -0
- package/dist/chunk-CQMV7BB6.js.map +1 -0
- package/dist/chunk-DN7TYUJ6.js +119 -0
- package/dist/chunk-DN7TYUJ6.js.map +1 -0
- package/dist/chunk-ODBG4Y6R.mjs +48 -0
- package/dist/chunk-ODBG4Y6R.mjs.map +1 -0
- package/dist/chunk-RKX5MERK.js +150 -0
- package/dist/chunk-RKX5MERK.js.map +1 -0
- package/dist/chunk-VYI3GS2C.mjs +115 -0
- package/dist/chunk-VYI3GS2C.mjs.map +1 -0
- package/dist/design-system/copy-button.d.ts +43 -0
- package/dist/design-system/copy-button.d.ts.map +1 -0
- package/dist/design-system/index.d.ts +2 -0
- package/dist/design-system/index.d.ts.map +1 -1
- package/dist/design-system/kbd.d.ts +44 -0
- package/dist/design-system/kbd.d.ts.map +1 -0
- package/dist/hooks/useClipboard.js +6 -44
- package/dist/hooks/useClipboard.js.map +1 -1
- package/dist/hooks/useClipboard.mjs +1 -46
- package/dist/hooks/useClipboard.mjs.map +1 -1
- package/dist/ui/copy-button/animated/animations.d.ts +3 -0
- package/dist/ui/copy-button/animated/animations.d.ts.map +1 -0
- package/dist/ui/copy-button/animated/copy-button-animated.d.ts +6 -0
- package/dist/ui/copy-button/animated/copy-button-animated.d.ts.map +1 -0
- package/dist/ui/copy-button/animated/index.d.ts +4 -0
- package/dist/ui/copy-button/animated/index.d.ts.map +1 -0
- package/dist/ui/copy-button/animated/types.d.ts +26 -0
- package/dist/ui/copy-button/animated/types.d.ts.map +1 -0
- package/dist/ui/copy-button/animated.js +59 -0
- package/dist/ui/copy-button/animated.js.map +1 -0
- package/dist/ui/copy-button/animated.mjs +56 -0
- package/dist/ui/copy-button/animated.mjs.map +1 -0
- package/dist/ui/copy-button/copy-button-base.d.ts +6 -0
- package/dist/ui/copy-button/copy-button-base.d.ts.map +1 -0
- package/dist/ui/copy-button/copy-button.d.ts +6 -0
- package/dist/ui/copy-button/copy-button.d.ts.map +1 -0
- package/dist/ui/copy-button/index.d.ts +4 -0
- package/dist/ui/copy-button/index.d.ts.map +1 -0
- package/dist/ui/copy-button/types.d.ts +32 -0
- package/dist/ui/copy-button/types.d.ts.map +1 -0
- package/dist/ui/copy-button/variants.d.ts +6 -0
- package/dist/ui/copy-button/variants.d.ts.map +1 -0
- package/dist/ui/copy-button.js +20 -0
- package/dist/ui/copy-button.js.map +1 -0
- package/dist/ui/copy-button.mjs +15 -0
- package/dist/ui/copy-button.mjs.map +1 -0
- package/dist/ui/kbd/animated/animations.d.ts +3 -0
- package/dist/ui/kbd/animated/animations.d.ts.map +1 -0
- package/dist/ui/kbd/animated/index.d.ts +4 -0
- package/dist/ui/kbd/animated/index.d.ts.map +1 -0
- package/dist/ui/kbd/animated/kbd-animated.d.ts +6 -0
- package/dist/ui/kbd/animated/kbd-animated.d.ts.map +1 -0
- package/dist/ui/kbd/animated/types.d.ts +10 -0
- package/dist/ui/kbd/animated/types.d.ts.map +1 -0
- package/dist/ui/kbd/animated.js +42 -0
- package/dist/ui/kbd/animated.js.map +1 -0
- package/dist/ui/kbd/animated.mjs +39 -0
- package/dist/ui/kbd/animated.mjs.map +1 -0
- package/dist/ui/kbd/index.d.ts +4 -0
- package/dist/ui/kbd/index.d.ts.map +1 -0
- package/dist/ui/kbd/kbd-base.d.ts +6 -0
- package/dist/ui/kbd/kbd-base.d.ts.map +1 -0
- package/dist/ui/kbd/kbd.d.ts +6 -0
- package/dist/ui/kbd/kbd.d.ts.map +1 -0
- package/dist/ui/kbd/types.d.ts +17 -0
- package/dist/ui/kbd/types.d.ts.map +1 -0
- package/dist/ui/kbd/variants.d.ts +8 -0
- package/dist/ui/kbd/variants.d.ts.map +1 -0
- package/dist/ui/kbd.js +23 -0
- package/dist/ui/kbd.js.map +1 -0
- package/dist/ui/kbd.mjs +14 -0
- package/dist/ui/kbd.mjs.map +1 -0
- package/package.json +1 -1
- package/src/design-system/copy-button.ts +81 -0
- package/src/design-system/index.ts +2 -0
- package/src/design-system/kbd.ts +83 -0
- package/src/ui/copy-button/animated/animations.ts +22 -0
- package/src/ui/copy-button/animated/copy-button-animated.tsx +39 -0
- package/src/ui/copy-button/animated/index.ts +10 -0
- package/src/ui/copy-button/animated/types.ts +21 -0
- package/src/ui/copy-button/copy-button-base.tsx +88 -0
- package/src/ui/copy-button/copy-button.test.tsx +82 -0
- package/src/ui/copy-button/copy-button.tsx +9 -0
- package/src/ui/copy-button/index.ts +10 -0
- package/src/ui/copy-button/types.ts +37 -0
- package/src/ui/copy-button/variants.ts +29 -0
- package/src/ui/kbd/animated/animations.ts +15 -0
- package/src/ui/kbd/animated/index.ts +9 -0
- package/src/ui/kbd/animated/kbd-animated.tsx +26 -0
- package/src/ui/kbd/animated/types.ts +16 -0
- package/src/ui/kbd/index.ts +5 -0
- package/src/ui/kbd/kbd-base.tsx +50 -0
- package/src/ui/kbd/kbd.test.tsx +48 -0
- package/src/ui/kbd/kbd.tsx +9 -0
- package/src/ui/kbd/types.ts +21 -0
- package/src/ui/kbd/variants.ts +31 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { motion } from "framer-motion";
|
|
4
|
+
|
|
5
|
+
import { KbdBase } from "../kbd-base";
|
|
6
|
+
import type { KbdBaseProps } from "../types";
|
|
7
|
+
|
|
8
|
+
import { kbdAnimationPresets } from "./animations";
|
|
9
|
+
import type { KbdAnimatedProps } from "./types";
|
|
10
|
+
|
|
11
|
+
export function KbdAnimated({ animation = "none", ...props }: KbdAnimatedProps) {
|
|
12
|
+
const motionProps = kbdAnimationPresets[animation];
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<KbdBase
|
|
16
|
+
{...({
|
|
17
|
+
as: motion.span,
|
|
18
|
+
initial: animation === "none" ? false : undefined,
|
|
19
|
+
...motionProps,
|
|
20
|
+
...props,
|
|
21
|
+
} as KbdBaseProps)}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
KbdAnimated.displayName = "KbdAnimated";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLMotionProps } from "framer-motion";
|
|
2
|
+
|
|
3
|
+
import type { KbdBaseProps } from "../types";
|
|
4
|
+
|
|
5
|
+
export type KbdAnimation = "none" | "press" | "pop";
|
|
6
|
+
|
|
7
|
+
export type KbdAnimatedProps = Omit<KbdBaseProps, "as"> & {
|
|
8
|
+
animation?: KbdAnimation;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type KbdPresetMotionProps = Pick<
|
|
12
|
+
HTMLMotionProps<"span">,
|
|
13
|
+
"transition" | "whileHover" | "whileTap" | "animate" | "initial"
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
export type KbdAnimationPresets = Record<KbdAnimation, KbdPresetMotionProps>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
|
|
5
|
+
import { zuiKbdBase } from "../../design-system/kbd";
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
|
|
8
|
+
import type { KbdBaseProps } from "./types";
|
|
9
|
+
import { kbdKeyVariants, kbdSeparatorVariants } from "./variants";
|
|
10
|
+
|
|
11
|
+
export function KbdBase({
|
|
12
|
+
keys,
|
|
13
|
+
separator,
|
|
14
|
+
appearance,
|
|
15
|
+
size,
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
as: Wrapper = "span",
|
|
19
|
+
ref,
|
|
20
|
+
...rest
|
|
21
|
+
}: KbdBaseProps) {
|
|
22
|
+
const items = keys ?? (children != null ? [children] : []);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Wrapper
|
|
26
|
+
ref={ref}
|
|
27
|
+
data-slot="kbd"
|
|
28
|
+
className={cn(zuiKbdBase, className)}
|
|
29
|
+
{...rest}
|
|
30
|
+
>
|
|
31
|
+
{items.map((key, index) => (
|
|
32
|
+
<Fragment key={index}>
|
|
33
|
+
{index > 0 && separator != null ? (
|
|
34
|
+
<span data-slot="kbd-separator" className={kbdSeparatorVariants({ size })}>
|
|
35
|
+
{separator}
|
|
36
|
+
</span>
|
|
37
|
+
) : null}
|
|
38
|
+
<kbd
|
|
39
|
+
data-slot="kbd-key"
|
|
40
|
+
className={kbdKeyVariants({ appearance, size })}
|
|
41
|
+
>
|
|
42
|
+
{key}
|
|
43
|
+
</kbd>
|
|
44
|
+
</Fragment>
|
|
45
|
+
))}
|
|
46
|
+
</Wrapper>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
KbdBase.displayName = "Kbd";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createRef } from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { Kbd } from "./kbd";
|
|
6
|
+
|
|
7
|
+
describe("Kbd", () => {
|
|
8
|
+
it("should expose displayName", () => {
|
|
9
|
+
expect(Kbd.displayName).toBe("Kbd");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should stamp data-slot on the wrapper", () => {
|
|
13
|
+
render(<Kbd keys={["⌘", "K"]} />);
|
|
14
|
+
expect(document.querySelector('[data-slot="kbd"]')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should render one keycap per key", () => {
|
|
18
|
+
render(<Kbd keys={["Ctrl", "Shift", "P"]} />);
|
|
19
|
+
expect(document.querySelectorAll('[data-slot="kbd-key"]')).toHaveLength(3);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should render children as a single keycap", () => {
|
|
23
|
+
render(<Kbd>Esc</Kbd>);
|
|
24
|
+
expect(document.querySelectorAll('[data-slot="kbd-key"]')).toHaveLength(1);
|
|
25
|
+
expect(screen.getByText("Esc")).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should render separators between keys", () => {
|
|
29
|
+
render(<Kbd keys={["⌘", "K"]} separator="+" />);
|
|
30
|
+
expect(
|
|
31
|
+
document.querySelectorAll('[data-slot="kbd-separator"]'),
|
|
32
|
+
).toHaveLength(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should apply the appearance token", () => {
|
|
36
|
+
render(<Kbd keys={["A"]} appearance="emerald" />);
|
|
37
|
+
const key = document.querySelector(
|
|
38
|
+
'[data-slot="kbd-key"]',
|
|
39
|
+
) as HTMLElement;
|
|
40
|
+
expect(key.className).toMatch(/--zui-kbd-emerald-bg/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should forward ref", () => {
|
|
44
|
+
const ref = createRef<HTMLSpanElement>();
|
|
45
|
+
render(<Kbd ref={ref} keys={["A"]} />);
|
|
46
|
+
expect(ref.current?.getAttribute("data-slot")).toBe("kbd");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VariantProps } from "class-variance-authority";
|
|
2
|
+
import type { ComponentPropsWithRef, ElementType, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import type { kbdKeyVariants } from "./variants";
|
|
5
|
+
|
|
6
|
+
export type KbdVariantProps = VariantProps<typeof kbdKeyVariants>;
|
|
7
|
+
|
|
8
|
+
export interface KbdBaseProps
|
|
9
|
+
extends Omit<ComponentPropsWithRef<"span">, "children"> {
|
|
10
|
+
/** Keys to render as individual keycaps, e.g. `["⌘", "K"]`. Takes precedence over `children`. */
|
|
11
|
+
keys?: ReactNode[];
|
|
12
|
+
/** Optional node rendered between keycaps (e.g. "+" or "then"). */
|
|
13
|
+
separator?: ReactNode;
|
|
14
|
+
appearance?: KbdVariantProps["appearance"];
|
|
15
|
+
size?: KbdVariantProps["size"];
|
|
16
|
+
/** Single keycap content when `keys` is not provided. */
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
as?: ElementType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type KbdProps = Omit<KbdBaseProps, "as">;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cva } from "class-variance-authority";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
zuiKbdKeyAppearances,
|
|
5
|
+
zuiKbdKeyBase,
|
|
6
|
+
zuiKbdKeySizes,
|
|
7
|
+
zuiKbdSeparatorSizes,
|
|
8
|
+
} from "../../design-system/kbd";
|
|
9
|
+
|
|
10
|
+
export const kbdKeyVariants = cva(zuiKbdKeyBase, {
|
|
11
|
+
variants: {
|
|
12
|
+
appearance: zuiKbdKeyAppearances,
|
|
13
|
+
size: zuiKbdKeySizes,
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
appearance: "outline",
|
|
17
|
+
size: "md",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const kbdSeparatorVariants = cva(
|
|
22
|
+
"text-[color:var(--zui-kbd-separator-fg,#94a3b8)] dark:text-[color:var(--zui-kbd-separator-fg-dark,#64748b)]",
|
|
23
|
+
{
|
|
24
|
+
variants: {
|
|
25
|
+
size: zuiKbdSeparatorSizes,
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
size: "md",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|