@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.
Files changed (48) hide show
  1. package/dist/components/action-icon-button.d.ts +11 -0
  2. package/dist/components/action-icon-button.d.ts.map +1 -0
  3. package/dist/components/action-icon-button.js +14 -0
  4. package/dist/components/action-icon-button.js.map +1 -0
  5. package/dist/components/copy-to-clipboard-button.d.ts +7 -0
  6. package/dist/components/copy-to-clipboard-button.d.ts.map +1 -0
  7. package/dist/components/copy-to-clipboard-button.js +16 -0
  8. package/dist/components/copy-to-clipboard-button.js.map +1 -0
  9. package/dist/components/external-link-button.d.ts +7 -0
  10. package/dist/components/external-link-button.d.ts.map +1 -0
  11. package/dist/components/external-link-button.js +10 -0
  12. package/dist/components/external-link-button.js.map +1 -0
  13. package/dist/components/mailto-button.d.ts +7 -0
  14. package/dist/components/mailto-button.d.ts.map +1 -0
  15. package/dist/components/mailto-button.js +10 -0
  16. package/dist/components/mailto-button.js.map +1 -0
  17. package/dist/components/markdown-editor.d.ts.map +1 -1
  18. package/dist/components/markdown-editor.js +0 -2
  19. package/dist/components/markdown-editor.js.map +1 -1
  20. package/dist/components/table-pagination.d.ts +21 -0
  21. package/dist/components/table-pagination.d.ts.map +1 -0
  22. package/dist/components/table-pagination.js +15 -0
  23. package/dist/components/table-pagination.js.map +1 -0
  24. package/dist/components/tooltip-icon-button.d.ts +24 -0
  25. package/dist/components/tooltip-icon-button.d.ts.map +1 -0
  26. package/dist/components/tooltip-icon-button.js +28 -0
  27. package/dist/components/tooltip-icon-button.js.map +1 -0
  28. package/dist/index.d.ts +8 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +8 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/tsconfig.build.tsbuildinfo +1 -1
  33. package/package.json +11 -20
  34. package/src/components/__tests__/action-icon-button.test.tsx +62 -0
  35. package/src/components/__tests__/copy-to-clipboard-button.test.tsx +48 -0
  36. package/src/components/__tests__/external-link-button.test.tsx +28 -0
  37. package/src/components/__tests__/mailto-button.test.tsx +30 -0
  38. package/src/components/__tests__/table-pagination.test.tsx +115 -0
  39. package/src/components/__tests__/tooltip-icon-button.test.tsx +94 -0
  40. package/src/components/action-icon-button.tsx +40 -0
  41. package/src/components/copy-to-clipboard-button.tsx +28 -0
  42. package/src/components/external-link-button.tsx +22 -0
  43. package/src/components/mailto-button.tsx +22 -0
  44. package/src/components/markdown-editor.tsx +2 -4
  45. package/src/components/table-pagination.tsx +88 -0
  46. package/src/components/tooltip-icon-button.tsx +83 -0
  47. package/src/index.ts +12 -0
  48. 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 {};