@open-elements/ui 0.4.0 → 0.6.0
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/dist/components/action-icon-button.d.ts +11 -0
- package/dist/components/action-icon-button.d.ts.map +1 -0
- package/dist/components/action-icon-button.js +14 -0
- package/dist/components/action-icon-button.js.map +1 -0
- package/dist/components/copy-to-clipboard-button.d.ts +7 -0
- package/dist/components/copy-to-clipboard-button.d.ts.map +1 -0
- package/dist/components/copy-to-clipboard-button.js +16 -0
- package/dist/components/copy-to-clipboard-button.js.map +1 -0
- package/dist/components/external-link-button.d.ts +7 -0
- package/dist/components/external-link-button.d.ts.map +1 -0
- package/dist/components/external-link-button.js +10 -0
- package/dist/components/external-link-button.js.map +1 -0
- package/dist/components/mailto-button.d.ts +7 -0
- package/dist/components/mailto-button.d.ts.map +1 -0
- package/dist/components/mailto-button.js +10 -0
- package/dist/components/mailto-button.js.map +1 -0
- package/dist/components/markdown-editor.d.ts.map +1 -1
- package/dist/components/markdown-editor.js +0 -2
- package/dist/components/markdown-editor.js.map +1 -1
- package/dist/components/table-pagination.d.ts +21 -0
- package/dist/components/table-pagination.d.ts.map +1 -0
- package/dist/components/table-pagination.js +15 -0
- package/dist/components/table-pagination.js.map +1 -0
- package/dist/components/tooltip-icon-button.d.ts +24 -0
- package/dist/components/tooltip-icon-button.d.ts.map +1 -0
- package/dist/components/tooltip-icon-button.js +28 -0
- package/dist/components/tooltip-icon-button.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -20
- package/src/components/__tests__/action-icon-button.test.tsx +62 -0
- package/src/components/__tests__/copy-to-clipboard-button.test.tsx +48 -0
- package/src/components/__tests__/external-link-button.test.tsx +28 -0
- package/src/components/__tests__/mailto-button.test.tsx +30 -0
- package/src/components/__tests__/table-pagination.test.tsx +115 -0
- package/src/components/__tests__/tooltip-icon-button.test.tsx +94 -0
- package/src/components/action-icon-button.tsx +40 -0
- package/src/components/copy-to-clipboard-button.tsx +28 -0
- package/src/components/external-link-button.tsx +22 -0
- package/src/components/mailto-button.tsx +22 -0
- package/src/components/markdown-editor.tsx +2 -4
- package/src/components/table-pagination.tsx +88 -0
- package/src/components/tooltip-icon-button.tsx +83 -0
- package/src/index.ts +12 -0
- package/src/types/tiptap-markdown.d.ts +11 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { MouseEvent, ReactNode } from "react";
|
|
4
|
+
import { cn } from "../lib/utils.ts";
|
|
5
|
+
import { Button } from "./button.tsx";
|
|
6
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx";
|
|
7
|
+
|
|
8
|
+
type Tone = "default" | "destructive";
|
|
9
|
+
|
|
10
|
+
type CommonProps = {
|
|
11
|
+
readonly tooltip: string;
|
|
12
|
+
readonly tone?: Tone;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type AsButtonProps = CommonProps & {
|
|
16
|
+
readonly icon: ReactNode;
|
|
17
|
+
readonly onClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
18
|
+
readonly disabled?: boolean;
|
|
19
|
+
readonly asChild?: never;
|
|
20
|
+
readonly children?: never;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type AsChildProps = CommonProps & {
|
|
24
|
+
readonly asChild: true;
|
|
25
|
+
readonly children: ReactNode;
|
|
26
|
+
readonly icon?: never;
|
|
27
|
+
readonly onClick?: never;
|
|
28
|
+
readonly disabled?: never;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type TooltipIconButtonProps = AsButtonProps | AsChildProps;
|
|
32
|
+
|
|
33
|
+
const TONE_CLASS: Record<Tone, string> = {
|
|
34
|
+
default: "[&_svg]:text-primary",
|
|
35
|
+
destructive: "[&_svg]:text-destructive",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function TooltipIconButton(props: TooltipIconButtonProps) {
|
|
39
|
+
const { tooltip, tone = "default" } = props;
|
|
40
|
+
const className = cn("[&_svg]:h-4 [&_svg]:w-4", TONE_CLASS[tone]);
|
|
41
|
+
|
|
42
|
+
let trigger: ReactNode;
|
|
43
|
+
if ("asChild" in props && props.asChild) {
|
|
44
|
+
trigger = (
|
|
45
|
+
<Button
|
|
46
|
+
asChild
|
|
47
|
+
variant="ghost"
|
|
48
|
+
size="icon"
|
|
49
|
+
className={className}
|
|
50
|
+
aria-label={tooltip}
|
|
51
|
+
onClick={(event) => event.stopPropagation()}
|
|
52
|
+
>
|
|
53
|
+
{props.children}
|
|
54
|
+
</Button>
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
const button = (
|
|
58
|
+
<Button
|
|
59
|
+
variant="ghost"
|
|
60
|
+
size="icon"
|
|
61
|
+
className={className}
|
|
62
|
+
aria-label={tooltip}
|
|
63
|
+
disabled={props.disabled}
|
|
64
|
+
onClick={(event) => {
|
|
65
|
+
event.stopPropagation();
|
|
66
|
+
props.onClick(event);
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
{props.icon}
|
|
70
|
+
</Button>
|
|
71
|
+
);
|
|
72
|
+
// Disabled buttons swallow pointer events, so the Tooltip stops working
|
|
73
|
+
// unless the trigger is wrapped in a span.
|
|
74
|
+
trigger = props.disabled ? <span>{button}</span> : button;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Tooltip>
|
|
79
|
+
<TooltipTrigger asChild>{trigger}</TooltipTrigger>
|
|
80
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
81
|
+
</Tooltip>
|
|
82
|
+
);
|
|
83
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -155,6 +155,18 @@ export { MarkdownView } from "./components/markdown-view.tsx";
|
|
|
155
155
|
export { UserAvatar } from "./components/user-avatar.tsx";
|
|
156
156
|
export { UserMultiSelect } from "./components/user-multi-select.tsx";
|
|
157
157
|
|
|
158
|
+
// Action buttons
|
|
159
|
+
export { ActionIconButton } from "./components/action-icon-button.tsx";
|
|
160
|
+
export { CopyToClipboardButton } from "./components/copy-to-clipboard-button.tsx";
|
|
161
|
+
export { ExternalLinkButton } from "./components/external-link-button.tsx";
|
|
162
|
+
export { MailtoButton } from "./components/mailto-button.tsx";
|
|
163
|
+
export { TooltipIconButton } from "./components/tooltip-icon-button.tsx";
|
|
164
|
+
export type { TooltipIconButtonProps } from "./components/tooltip-icon-button.tsx";
|
|
165
|
+
|
|
166
|
+
// Table pagination
|
|
167
|
+
export { TablePagination } from "./components/table-pagination.tsx";
|
|
168
|
+
export type { PaginationTranslations } from "./components/table-pagination.tsx";
|
|
169
|
+
|
|
158
170
|
// Types
|
|
159
171
|
export type { TagDto } from "./types/index.ts";
|
|
160
172
|
export type {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MarkdownStorage } from "tiptap-markdown";
|
|
2
|
+
|
|
3
|
+
// Augment tiptap's Storage interface so editor.storage.markdown is typed.
|
|
4
|
+
// See https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#storage
|
|
5
|
+
declare module "@tiptap/core" {
|
|
6
|
+
interface Storage {
|
|
7
|
+
markdown: MarkdownStorage;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {};
|