@rovula/ui 0.0.15 → 0.0.17

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 (43) hide show
  1. package/dist/cjs/bundle.css +61 -0
  2. package/dist/cjs/bundle.js +3 -3
  3. package/dist/cjs/bundle.js.map +1 -1
  4. package/dist/cjs/types/components/Avatar/Avatar.stories.d.ts +3 -3
  5. package/dist/cjs/types/components/Avatar/Avatar.styles.d.ts +1 -1
  6. package/dist/cjs/types/components/Collapsible/Collapsible.d.ts +23 -0
  7. package/dist/cjs/types/components/Collapsible/Collapsible.stories.d.ts +8 -0
  8. package/dist/cjs/types/components/Collapsible/Collapsible.styles.d.ts +11 -0
  9. package/dist/cjs/types/components/Collapsible/CollapsibleContext.d.ts +16 -0
  10. package/dist/cjs/types/components/Collapsible/index.d.ts +1 -0
  11. package/dist/cjs/types/index.d.ts +2 -0
  12. package/dist/components/ActionButton/ActionButton.js +0 -1
  13. package/dist/components/Collapsible/Collapsible.js +37 -0
  14. package/dist/components/Collapsible/Collapsible.stories.js +44 -0
  15. package/dist/components/Collapsible/Collapsible.styles.js +47 -0
  16. package/dist/components/Collapsible/CollapsibleContext.js +25 -0
  17. package/dist/components/Collapsible/index.js +1 -0
  18. package/dist/esm/bundle.css +61 -0
  19. package/dist/esm/bundle.js +3 -3
  20. package/dist/esm/bundle.js.map +1 -1
  21. package/dist/esm/types/components/Avatar/Avatar.stories.d.ts +3 -3
  22. package/dist/esm/types/components/Avatar/Avatar.styles.d.ts +1 -1
  23. package/dist/esm/types/components/Collapsible/Collapsible.d.ts +23 -0
  24. package/dist/esm/types/components/Collapsible/Collapsible.stories.d.ts +8 -0
  25. package/dist/esm/types/components/Collapsible/Collapsible.styles.d.ts +11 -0
  26. package/dist/esm/types/components/Collapsible/CollapsibleContext.d.ts +16 -0
  27. package/dist/esm/types/components/Collapsible/index.d.ts +1 -0
  28. package/dist/esm/types/index.d.ts +2 -0
  29. package/dist/index.d.ts +33 -1
  30. package/dist/index.js +2 -0
  31. package/dist/src/theme/global.css +72 -0
  32. package/dist/theme/global.css +16 -0
  33. package/dist/theme/presets/colors.js +16 -0
  34. package/package.json +1 -1
  35. package/src/components/ActionButton/ActionButton.tsx +0 -2
  36. package/src/components/Collapsible/Collapsible.stories.tsx +65 -0
  37. package/src/components/Collapsible/Collapsible.styles.ts +62 -0
  38. package/src/components/Collapsible/Collapsible.tsx +113 -0
  39. package/src/components/Collapsible/CollapsibleContext.tsx +61 -0
  40. package/src/components/Collapsible/index.ts +1 -0
  41. package/src/index.ts +2 -0
  42. package/src/theme/global.css +16 -0
  43. package/src/theme/presets/colors.js +16 -0
@@ -0,0 +1,113 @@
1
+ import React, { forwardRef, Ref, useEffect, useRef, useState } from "react";
2
+ import { ChevronDownIcon } from "@heroicons/react/16/solid";
3
+ import { CollapsibleProvider, useCollapsible } from "./CollapsibleContext";
4
+ import { cn } from "@/utils/cn";
5
+ import {
6
+ collapseButtonVariants,
7
+ collapseContainerVariants,
8
+ collapseIconVariants,
9
+ collapsePanelVariants,
10
+ } from "./Collapsible.styles";
11
+
12
+ const CollapsibleButton = forwardRef<
13
+ HTMLButtonElement,
14
+ {
15
+ children: React.ReactNode;
16
+ className?: string;
17
+ hideExpandIcon?: boolean;
18
+ }
19
+ >(({ children, className, hideExpandIcon = false }, ref) => {
20
+ const { toggle, isExpand, size } = useCollapsible();
21
+
22
+ const collapseButtonClassName = collapseButtonVariants({ size });
23
+ const collapseIconClassName = collapseIconVariants({ isExpand, size });
24
+
25
+ return (
26
+ <button
27
+ onClick={toggle}
28
+ className={cn(collapseButtonClassName, className)}
29
+ ref={ref}
30
+ >
31
+ <span className="flex flex-1">{children}</span>
32
+ {!hideExpandIcon && (
33
+ <span className={cn(collapseIconClassName)}>
34
+ <ChevronDownIcon className={cn("size-full")} />
35
+ </span>
36
+ )}
37
+ </button>
38
+ );
39
+ });
40
+
41
+ CollapsibleButton.displayName = "CollapsibleButton";
42
+
43
+ const CollapsiblePanel = forwardRef<
44
+ HTMLDivElement,
45
+ { children: React.ReactNode; className?: string }
46
+ >(({ children, className }, ref) => {
47
+ const { isExpand, size } = useCollapsible();
48
+ const collapsePanelClassName = collapsePanelVariants({ size });
49
+
50
+ const [height, setHeight] = useState<string | number>("0px");
51
+ const contentRef = useRef<HTMLDivElement>(null);
52
+
53
+ useEffect(() => {
54
+ if (contentRef.current) {
55
+ setHeight(isExpand ? `${contentRef.current.scrollHeight}px` : "0px");
56
+ }
57
+ }, [isExpand, children]); // Add `children` to the dependency array to recalculate height on content change
58
+
59
+ return (
60
+ <div
61
+ ref={ref}
62
+ className={cn("overflow-hidden transition-all ease-in-out")}
63
+ style={{ height }}
64
+ >
65
+ <div ref={contentRef} className={cn(collapsePanelClassName, className)}>
66
+ {children}
67
+ </div>
68
+ </div>
69
+ );
70
+ });
71
+
72
+ CollapsiblePanel.displayName = "CollapsiblePanel";
73
+
74
+ interface CollapsibleComponent
75
+ extends React.ForwardRefExoticComponent<
76
+ CollapsibleProps & React.RefAttributes<HTMLDivElement>
77
+ > {
78
+ Button: typeof CollapsibleButton;
79
+ Panel: typeof CollapsiblePanel;
80
+ }
81
+
82
+ interface CollapsibleProps {
83
+ size?: "sm" | "md" | "lg";
84
+ children: React.ReactNode;
85
+ isExpand?: boolean;
86
+ className?: string;
87
+ onToggle?: (isExpand: boolean) => void;
88
+ }
89
+
90
+ const Collapsible = forwardRef<HTMLDivElement, CollapsibleProps>(
91
+ ({ children, isExpand, size, className, onToggle }, ref) => {
92
+ const collapseContainerClassName = collapseContainerVariants();
93
+
94
+ return (
95
+ <CollapsibleProvider
96
+ size={size}
97
+ isExpandControlled={isExpand}
98
+ onToggle={onToggle}
99
+ >
100
+ <div ref={ref} className={cn(collapseContainerClassName, className)}>
101
+ {children}
102
+ </div>
103
+ </CollapsibleProvider>
104
+ );
105
+ }
106
+ ) as CollapsibleComponent;
107
+
108
+ Collapsible.displayName = "Collapsible";
109
+
110
+ Collapsible.Button = CollapsibleButton;
111
+ Collapsible.Panel = CollapsiblePanel;
112
+
113
+ export default Collapsible;
@@ -0,0 +1,61 @@
1
+ import React, {
2
+ createContext,
3
+ useContext,
4
+ useState,
5
+ ReactNode,
6
+ useEffect,
7
+ } from "react";
8
+
9
+ interface CollapsibleContextProps {
10
+ size?: "sm" | "md" | "lg";
11
+ isExpand: boolean;
12
+ toggle: () => void;
13
+ setIsExpand: React.Dispatch<React.SetStateAction<boolean>>;
14
+ }
15
+
16
+ const CollapsibleContext = createContext<CollapsibleContextProps | undefined>(
17
+ undefined
18
+ );
19
+
20
+ export const useCollapsible = (): CollapsibleContextProps => {
21
+ const context = useContext(CollapsibleContext);
22
+ if (!context) {
23
+ throw new Error("useCollapsible must be used within a CollapsibleProvider");
24
+ }
25
+ return context;
26
+ };
27
+
28
+ interface CollapsibleProviderProps {
29
+ size?: "sm" | "md" | "lg";
30
+ children: ReactNode;
31
+ isExpandControlled?: boolean;
32
+ onToggle?: (isExpand: boolean) => void;
33
+ }
34
+
35
+ export const CollapsibleProvider: React.FC<CollapsibleProviderProps> = ({
36
+ size,
37
+ children,
38
+ isExpandControlled,
39
+ onToggle,
40
+ }) => {
41
+ const [isExpand, setIsExpand] = useState<boolean>(false);
42
+
43
+ const toggle = () => {
44
+ setIsExpand((prev) => !prev);
45
+ if (onToggle) onToggle(!isExpand);
46
+ };
47
+
48
+ useEffect(() => {
49
+ if (isExpandControlled !== undefined) {
50
+ setIsExpand(isExpandControlled);
51
+ }
52
+ }, [isExpandControlled]);
53
+
54
+ return (
55
+ <CollapsibleContext.Provider
56
+ value={{ size, isExpand, toggle, setIsExpand }}
57
+ >
58
+ {children}
59
+ </CollapsibleContext.Provider>
60
+ );
61
+ };
@@ -0,0 +1 @@
1
+ export { default as Collapsible } from "./Collapsible";
package/src/index.ts CHANGED
@@ -10,7 +10,9 @@ export { Checkbox } from "./components/Checkbox/Checkbox";
10
10
  export { Label } from "./components/Label/Label";
11
11
  export { Input } from "./components/Input/Input";
12
12
  export { Navbar } from "./components/Navbar";
13
+ export { default as ActionButton } from "./components/ActionButton/ActionButton";
13
14
  export { Avatar, AvatarGroup } from "./components/Avatar";
15
+ export { Collapsible } from "./components/Collapsible";
14
16
  export * from "./components/Table/Table";
15
17
  export * from "./components/DataTable/DataTable";
16
18
  export * from "./components/Dialog/Dialog";
@@ -108,23 +108,39 @@
108
108
  --grey-default: var(--grey-100);
109
109
  --grey-foreground: var(--white);
110
110
 
111
+ --info-lighter: 208 242 255;
112
+ --info-light: 116 202 255;
111
113
  --info-100: 41 152 255; /* #2998FF */
112
114
  --info-120: 33 122 204; /* #217ACC */
115
+ --info-dark: 12 83 183;
116
+ --info-darker: 4 41 122;
113
117
  --info-default: var(--info-100);
114
118
  --info-foreground: var(--white);
115
119
 
120
+ --success-lighter: 233 252 212;
121
+ --success-light: 170 242 127;
116
122
  --success-100: 84 214 44; /* #54D62C */
117
123
  --success-120: 67 171 35; /* #43AB23 */
124
+ --success-dark: 34 154 22;
125
+ --success-darker:8 102 13;
118
126
  --success-default: var(--success-100);
119
127
  --success-foreground: var(--white);
120
128
 
129
+ --warning-lighter: 255 247 205;
130
+ --warning-light:255 225 106;
121
131
  --warning-100: 255 193 7; /* #FFC107 */
122
132
  --warning-120: 204 154 6; /* #CC9A06 */
133
+ --warning-dark: 183 129 3;
134
+ --warning-darker: 122 79 1;
123
135
  --warning-default: var(--warning-100);
124
136
  --warning-foreground: var(--white);
125
137
 
138
+ --error-lighter: 255 231 217;
139
+ --error-light: 255 164 141;
126
140
  --error-100: 255 77 53; /* #FF4D35 */
127
141
  --error-120: 204 62 42; /* #CC3E2A */
142
+ --error-dark: 183 33 54;
143
+ --error-darker: 122 12 46;
128
144
  --error-default: var(--error-100);
129
145
  --error-foreground: var(--white);
130
146
 
@@ -118,26 +118,42 @@ module.exports = {
118
118
  foreground: "rgb(var(--grey2-foreground) / <alpha-value>)",
119
119
  },
120
120
  info: {
121
+ lighter: "rgb(var(--info-lighter)) / <alpha-value>)",
122
+ light: "rgb(var(--info-light)) / <alpha-value>)",
121
123
  100: "rgb(var(--info-100)) / <alpha-value>)",
122
124
  120: "rgb(var(--info-120)) / <alpha-value>)",
125
+ dark: "rgb(var(--info-dark)) / <alpha-value>)",
126
+ darker: "rgb(var(--info-darker)) / <alpha-value>)",
123
127
  DEFAULT: "rgb(var(--info-default) / <alpha-value>)",
124
128
  foreground: "rgb(var(--info-foreground) / <alpha-value>)",
125
129
  },
126
130
  success: {
131
+ lighter: "rgb(var(--success-lighter)) / <alpha-value>)",
132
+ light: "rgb(var(--success-light)) / <alpha-value>)",
127
133
  100: "rgb(var(--success-100)) / <alpha-value>)",
128
134
  120: "rgb(var(--success-120)) / <alpha-value>)",
135
+ dark: "rgb(var(--success-dark)) / <alpha-value>)",
136
+ darker: "rgb(var(--success-darker)) / <alpha-value>)",
129
137
  DEFAULT: "rgb(var(--success-default) / <alpha-value>)",
130
138
  foreground: "rgb(var(--success-foreground) / <alpha-value>)",
131
139
  },
132
140
  warning: {
141
+ lighter: "rgb(var(--warning-lighter)) / <alpha-value>)",
142
+ light: "rgb(var(--warning-light)) / <alpha-value>)",
133
143
  100: "rgb(var(--warning-100) / <alpha-value>)",
134
144
  120: "rgb(var(--warning-120) / <alpha-value>)",
145
+ dark: "rgb(var(--warning-dark)) / <alpha-value>)",
146
+ darker: "rgb(var(--warning-darker)) / <alpha-value>)",
135
147
  DEFAULT: "rgb(var(--warning-default) / <alpha-value>)",
136
148
  foreground: "rgb(var(--warning-foreground) / <alpha-value>)",
137
149
  },
138
150
  error: {
151
+ lighter: "rgb(var(--error-lighter)) / <alpha-value>)",
152
+ light: "rgb(var(--error-light)) / <alpha-value>)",
139
153
  100: "rgb(var(--error-100) / <alpha-value>)",
140
154
  120: "rgb(var(--error-120) / <alpha-value>)",
155
+ dark: "rgb(var(--error-dark)) / <alpha-value>)",
156
+ darker: "rgb(var(--error-darker)) / <alpha-value>)",
141
157
  DEFAULT: "rgb(var(--error-100) / <alpha-value>)",
142
158
  foreground: "rgb(var(--error-foreground) / <alpha-value>)",
143
159
  },