@sikka/hawa 0.1.20 → 0.1.22
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/styles.css +0 -3
- package/es/index.es.js +3 -3
- package/es/layout/AppLayout.d.ts +1 -0
- package/es/layout/Sidebar.d.ts +3 -6
- package/lib/index.js +1 -1
- package/lib/layout/AppLayout.d.ts +1 -0
- package/lib/layout/Sidebar.d.ts +3 -6
- package/package.json +1 -1
- package/src/layout/AppLayout.tsx +24 -21
- package/src/layout/Sidebar.tsx +57 -49
- package/src/styles.css +0 -3
package/lib/layout/Sidebar.d.ts
CHANGED
|
@@ -15,16 +15,13 @@ type SubItem = {
|
|
|
15
15
|
interface SidebarGroupProps {
|
|
16
16
|
title?: string;
|
|
17
17
|
items: Item[];
|
|
18
|
-
|
|
18
|
+
openedItem?: any;
|
|
19
|
+
setOpenedItem?: any;
|
|
19
20
|
selectedItem?: any;
|
|
20
21
|
isOpen?: boolean;
|
|
21
22
|
onItemClick?: (value: string[]) => void;
|
|
22
23
|
onSubItemClick?: (values: string[]) => void;
|
|
23
24
|
}
|
|
24
|
-
interface SidebarRootProps {
|
|
25
|
-
children: any;
|
|
26
|
-
}
|
|
27
|
-
declare const SidebarRoot: React.FC<SidebarRootProps>;
|
|
28
25
|
declare const SidebarGroup: React.FC<SidebarGroupProps>;
|
|
29
26
|
declare const SidebarItem: React.FC<{
|
|
30
27
|
item: Item;
|
|
@@ -33,4 +30,4 @@ declare const SidebarItem: React.FC<{
|
|
|
33
30
|
onSubItemClick?: (values: string[]) => void;
|
|
34
31
|
isOpen?: boolean;
|
|
35
32
|
}>;
|
|
36
|
-
export {
|
|
33
|
+
export { SidebarGroup, SidebarItem };
|
package/package.json
CHANGED
package/src/layout/AppLayout.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import clsx from "clsx"
|
|
|
3
3
|
import useDiscloser from "../hooks/useDiscloser"
|
|
4
4
|
import useBreakpoint from "../hooks/useBreakpoint"
|
|
5
5
|
import { Button, DropdownMenu, Tooltip } from "../elements"
|
|
6
|
-
import { SidebarGroup
|
|
6
|
+
import { SidebarGroup } from "./Sidebar"
|
|
7
7
|
|
|
8
8
|
type AppLayoutTypes = {
|
|
9
9
|
/** The pages of the side drawer */
|
|
@@ -24,6 +24,7 @@ type AppLayoutTypes = {
|
|
|
24
24
|
profileMenuItems?: ProfileItem[]
|
|
25
25
|
onSettingsClick?: () => void
|
|
26
26
|
DrawerFooterActions?: any
|
|
27
|
+
clickedItem?: any
|
|
27
28
|
texts?: {
|
|
28
29
|
expandSidebar?: string
|
|
29
30
|
collapseSidebar?: string
|
|
@@ -59,12 +60,17 @@ export const AppLayout: React.FunctionComponent<AppLayoutTypes> = ({
|
|
|
59
60
|
drawerSize = "md",
|
|
60
61
|
onSettingsClick,
|
|
61
62
|
DrawerFooterActions,
|
|
63
|
+
currentPage,
|
|
64
|
+
clickedItem,
|
|
62
65
|
...props
|
|
63
66
|
}) => {
|
|
64
67
|
const [openSideMenu, setOpenSideMenu] = useState(false)
|
|
65
68
|
const [openSubItem, setOpenSubitem] = useState("")
|
|
69
|
+
const [openedSidebarItem, setOpenedSidebarItem] = useState("")
|
|
66
70
|
const { isOpen, onClose, onOpen } = useDiscloser(false)
|
|
67
|
-
const [
|
|
71
|
+
const [selectedItem, setSelectedItem] = useState(
|
|
72
|
+
currentPage ? currentPage : []
|
|
73
|
+
)
|
|
68
74
|
|
|
69
75
|
const [keepOpen, setKeepOpen] = useState(false)
|
|
70
76
|
const ref = useRef(null)
|
|
@@ -237,11 +243,10 @@ export const AppLayout: React.FunctionComponent<AppLayoutTypes> = ({
|
|
|
237
243
|
}}
|
|
238
244
|
onMouseEnter={() => {
|
|
239
245
|
setOpenSideMenu(true)
|
|
240
|
-
setCollapsed((prev) => !prev)
|
|
241
246
|
}}
|
|
242
247
|
onMouseLeave={() => {
|
|
243
248
|
keepOpen ? setOpenSideMenu(true) : setOpenSideMenu(false)
|
|
244
|
-
|
|
249
|
+
setOpenedSidebarItem("")
|
|
245
250
|
}}
|
|
246
251
|
ref={ref}
|
|
247
252
|
>
|
|
@@ -304,9 +309,7 @@ export const AppLayout: React.FunctionComponent<AppLayoutTypes> = ({
|
|
|
304
309
|
*/}
|
|
305
310
|
<div
|
|
306
311
|
className={clsx(
|
|
307
|
-
// "no-scrollbar", TODO: make this optional to hide scrollbar or not
|
|
308
312
|
"fixed bottom-14 top-14 bg-primary-foreground p-2 py-2 transition-all",
|
|
309
|
-
// bg-yellow-400
|
|
310
313
|
openSideMenu ? "overflow-auto" : "overflow-hidden"
|
|
311
314
|
)}
|
|
312
315
|
style={{
|
|
@@ -323,21 +326,21 @@ export const AppLayout: React.FunctionComponent<AppLayoutTypes> = ({
|
|
|
323
326
|
* ----------------------------------------------------------------------------------------------------
|
|
324
327
|
*/}
|
|
325
328
|
|
|
326
|
-
<
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
329
|
+
<SidebarGroup
|
|
330
|
+
onItemClick={(values) => {
|
|
331
|
+
setSelectedItem(values)
|
|
332
|
+
clickedItem(values)
|
|
333
|
+
}}
|
|
334
|
+
onSubItemClick={(values) => {
|
|
335
|
+
setSelectedItem(values)
|
|
336
|
+
clickedItem(values)
|
|
337
|
+
}}
|
|
338
|
+
selectedItem={selectedItem}
|
|
339
|
+
openedItem={openedSidebarItem}
|
|
340
|
+
setOpenedItem={(e) => setOpenedSidebarItem(e)}
|
|
341
|
+
isOpen={openSideMenu}
|
|
342
|
+
items={props.drawerItems}
|
|
343
|
+
/>
|
|
341
344
|
</div>
|
|
342
345
|
{/*
|
|
343
346
|
* ----------------------------------------------------------------------------------------------------
|
package/src/layout/Sidebar.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from "react"
|
|
|
2
2
|
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
|
3
3
|
|
|
4
4
|
import { cn } from "../util"
|
|
5
|
+
import { Button } from "../elements"
|
|
5
6
|
|
|
6
7
|
const Accordion = AccordionPrimitive.Root
|
|
7
8
|
|
|
@@ -15,10 +16,16 @@ const AccordionItem = React.forwardRef<
|
|
|
15
16
|
))
|
|
16
17
|
AccordionItem.displayName = "AccordionItem"
|
|
17
18
|
|
|
19
|
+
type AccordionTriggerProps = React.ComponentPropsWithoutRef<
|
|
20
|
+
typeof AccordionPrimitive.Trigger
|
|
21
|
+
> & {
|
|
22
|
+
showArrow?: any
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
const AccordionTrigger = React.forwardRef<
|
|
19
26
|
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
|
20
|
-
|
|
21
|
-
>(({ className, children, ...props }, ref) => (
|
|
27
|
+
AccordionTriggerProps
|
|
28
|
+
>(({ className, showArrow, children, ...props }, ref) => (
|
|
22
29
|
<AccordionPrimitive.Header className="flex">
|
|
23
30
|
<AccordionPrimitive.Trigger
|
|
24
31
|
ref={ref}
|
|
@@ -26,21 +33,23 @@ const AccordionTrigger = React.forwardRef<
|
|
|
26
33
|
{...props}
|
|
27
34
|
>
|
|
28
35
|
{children}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
{showArrow && (
|
|
37
|
+
<svg
|
|
38
|
+
aria-label="Chevron Right Icon"
|
|
39
|
+
stroke="currentColor"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
stroke-width="1"
|
|
42
|
+
viewBox="0 0 16 16"
|
|
43
|
+
height="1em"
|
|
44
|
+
width="1em"
|
|
45
|
+
className="h-4 w-4 shrink-0 rotate-90 transition-transform duration-200"
|
|
46
|
+
>
|
|
47
|
+
<path
|
|
48
|
+
fill-rule="evenodd"
|
|
49
|
+
d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"
|
|
50
|
+
></path>
|
|
51
|
+
</svg>
|
|
52
|
+
)}
|
|
44
53
|
</AccordionPrimitive.Trigger>
|
|
45
54
|
</AccordionPrimitive.Header>
|
|
46
55
|
))
|
|
@@ -79,41 +88,34 @@ type SubItem = {
|
|
|
79
88
|
interface SidebarGroupProps {
|
|
80
89
|
title?: string
|
|
81
90
|
items: Item[]
|
|
82
|
-
|
|
91
|
+
openedItem?: any
|
|
92
|
+
setOpenedItem?: any
|
|
83
93
|
selectedItem?: any
|
|
84
94
|
isOpen?: boolean
|
|
85
95
|
onItemClick?: (value: string[]) => void
|
|
86
96
|
onSubItemClick?: (values: string[]) => void
|
|
87
97
|
}
|
|
88
|
-
interface SidebarRootProps {
|
|
89
|
-
children: any
|
|
90
|
-
}
|
|
91
98
|
|
|
92
|
-
const SidebarRoot: React.FC<SidebarRootProps> = ({ children }) => (
|
|
93
|
-
<div className="flex flex-col gap-2">{children}</div>
|
|
94
|
-
)
|
|
95
99
|
const SidebarGroup: React.FC<SidebarGroupProps> = ({
|
|
96
100
|
title,
|
|
97
101
|
items,
|
|
98
102
|
selectedItem,
|
|
99
|
-
|
|
103
|
+
openedItem,
|
|
104
|
+
setOpenedItem,
|
|
100
105
|
onItemClick,
|
|
101
106
|
onSubItemClick,
|
|
102
107
|
isOpen,
|
|
103
108
|
}) => {
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
if (collapsed) {
|
|
106
|
-
// Logic to close all groups
|
|
107
|
-
}
|
|
108
|
-
}, [collapsed])
|
|
109
|
-
|
|
110
109
|
return (
|
|
111
110
|
<div>
|
|
112
111
|
{title && <h3 className="mb-1 font-bold">{title}</h3>}
|
|
113
112
|
<ul className="flex flex-col gap-2">
|
|
114
113
|
<Accordion
|
|
114
|
+
value={openedItem}
|
|
115
115
|
type="single"
|
|
116
|
-
|
|
116
|
+
onValueChange={(e) => {
|
|
117
|
+
setOpenedItem(e)
|
|
118
|
+
}}
|
|
117
119
|
collapsible
|
|
118
120
|
className="flex flex-col gap-1"
|
|
119
121
|
>
|
|
@@ -142,26 +144,32 @@ const SidebarItem: React.FC<{
|
|
|
142
144
|
const getSelectedStyle = (value: string, index: number) => {
|
|
143
145
|
return isSelected && isSelected[index] === value
|
|
144
146
|
? "bg-primary text-primary-foreground cursor-default"
|
|
145
|
-
: ""
|
|
147
|
+
: "hover:bg-primary/30"
|
|
146
148
|
}
|
|
147
149
|
if (item.subitems) {
|
|
148
150
|
return (
|
|
149
151
|
<AccordionItem value={item.value} className="overflow-x-clip">
|
|
150
152
|
<AccordionTrigger
|
|
151
|
-
className={cn(getSelectedStyle(item.value, 0)
|
|
153
|
+
className={cn(getSelectedStyle(item.value, 0))}
|
|
154
|
+
showArrow={isOpen}
|
|
152
155
|
>
|
|
153
|
-
<div
|
|
156
|
+
<div
|
|
157
|
+
className={cn(
|
|
158
|
+
!isOpen && "py-1",
|
|
159
|
+
"flex w-fit flex-row items-center gap-2"
|
|
160
|
+
)}
|
|
161
|
+
>
|
|
154
162
|
{item.icon}
|
|
155
|
-
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
{isOpen && (
|
|
164
|
+
<span
|
|
165
|
+
className={cn(
|
|
166
|
+
"transition-all ",
|
|
167
|
+
isOpen ? "opacity-100" : "opacity-0"
|
|
168
|
+
)}
|
|
169
|
+
>
|
|
170
|
+
{item.label}
|
|
171
|
+
</span>
|
|
172
|
+
)}
|
|
165
173
|
</div>
|
|
166
174
|
</AccordionTrigger>
|
|
167
175
|
{item.subitems && (
|
|
@@ -171,6 +179,7 @@ const SidebarItem: React.FC<{
|
|
|
171
179
|
>
|
|
172
180
|
{item.subitems.map((subitem, idx) => (
|
|
173
181
|
<li
|
|
182
|
+
key={idx}
|
|
174
183
|
onClick={(e) => {
|
|
175
184
|
e.stopPropagation()
|
|
176
185
|
if (onSubItemClick) {
|
|
@@ -178,10 +187,9 @@ const SidebarItem: React.FC<{
|
|
|
178
187
|
}
|
|
179
188
|
}}
|
|
180
189
|
className={cn(
|
|
181
|
-
"flex h-full cursor-pointer flex-row items-center gap-2 rounded bg-foreground/10 p-2 transition-all
|
|
190
|
+
"flex h-full cursor-pointer flex-row items-center gap-2 rounded bg-foreground/10 p-2 transition-all",
|
|
182
191
|
getSelectedStyle(subitem.value, 1)
|
|
183
192
|
)}
|
|
184
|
-
key={idx}
|
|
185
193
|
>
|
|
186
194
|
{subitem.icon}
|
|
187
195
|
{subitem.label}
|
|
@@ -203,7 +211,7 @@ const SidebarItem: React.FC<{
|
|
|
203
211
|
className={cn(
|
|
204
212
|
triggerStyles,
|
|
205
213
|
getSelectedStyle(item.value, 0),
|
|
206
|
-
"overflow-x-clip
|
|
214
|
+
"overflow-x-clip "
|
|
207
215
|
)}
|
|
208
216
|
>
|
|
209
217
|
<div className={"flex flex-row items-center gap-2 "}>
|
|
@@ -221,4 +229,4 @@ const SidebarItem: React.FC<{
|
|
|
221
229
|
)
|
|
222
230
|
}
|
|
223
231
|
}
|
|
224
|
-
export {
|
|
232
|
+
export { SidebarGroup, SidebarItem }
|
package/src/styles.css
CHANGED
|
@@ -2941,9 +2941,6 @@ body {
|
|
|
2941
2941
|
.hover\:bg-destructive\/90:hover {
|
|
2942
2942
|
background-color: hsl(var(--destructive) / 0.9);
|
|
2943
2943
|
}
|
|
2944
|
-
.hover\:bg-foreground\/30:hover {
|
|
2945
|
-
background-color: hsl(var(--foreground) / 0.3);
|
|
2946
|
-
}
|
|
2947
2944
|
.hover\:bg-gray-100:hover {
|
|
2948
2945
|
--tw-bg-opacity: 1;
|
|
2949
2946
|
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
|