@sikka/hawa 0.0.260 → 0.0.262
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 +42 -124
- package/es/index.es.js +3 -3
- package/es/layout/HawaAppLayoutSimplified.d.ts +31 -0
- package/es/layout/index.d.ts +1 -0
- package/lib/index.js +3 -3
- package/lib/layout/HawaAppLayoutSimplified.d.ts +31 -0
- package/lib/layout/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/elements/BackToTop.tsx +61 -28
- package/src/elements/HawaAlert.tsx +8 -3
- package/src/layout/HawaAppLayout.tsx +7 -4
- package/src/layout/HawaAppLayoutSimplified.tsx +516 -0
- package/src/layout/index.ts +1 -0
- package/src/styles.css +42 -124
- package/src/tailwind.css +11 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type HawaAppLayoutTypes = {
|
|
3
|
+
drawerItems: {
|
|
4
|
+
label: string;
|
|
5
|
+
icon: any;
|
|
6
|
+
slug: string;
|
|
7
|
+
action: () => void;
|
|
8
|
+
subItems?: any;
|
|
9
|
+
}[][];
|
|
10
|
+
direction?: "rtl" | "ltr";
|
|
11
|
+
currentPage: string;
|
|
12
|
+
pageTitle?: string;
|
|
13
|
+
logoSymbol?: any;
|
|
14
|
+
logoLink?: string;
|
|
15
|
+
logoText?: any;
|
|
16
|
+
children?: any;
|
|
17
|
+
topBar?: boolean;
|
|
18
|
+
username?: string;
|
|
19
|
+
email?: string;
|
|
20
|
+
drawerSize?: "sm" | "md" | "large";
|
|
21
|
+
profileMenuItems?: MenuItems[][];
|
|
22
|
+
onSettingsClick?: () => void;
|
|
23
|
+
};
|
|
24
|
+
type MenuItems = {
|
|
25
|
+
icon?: JSX.Element;
|
|
26
|
+
label: string;
|
|
27
|
+
action?: (e: any) => void;
|
|
28
|
+
isButton?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare const HawaAppLayoutSimplified: React.FunctionComponent<HawaAppLayoutTypes>;
|
|
31
|
+
export {};
|
package/lib/layout/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./Box";
|
|
|
2
2
|
export * from "./HawaBottomAppBar";
|
|
3
3
|
export * from "./HawaSiteLayout";
|
|
4
4
|
export * from "./HawaAppLayout";
|
|
5
|
+
export * from "./HawaAppLayoutSimplified";
|
|
5
6
|
export * from "./HawaContainer";
|
|
6
7
|
export * from "./AppSidebar";
|
|
7
8
|
export * from "./Footer";
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, RefObject, useState, useEffect } from "react"
|
|
1
|
+
import React, { FC, RefObject, useState, useEffect, useRef } from "react"
|
|
2
2
|
import { clsx } from "clsx"
|
|
3
3
|
|
|
4
4
|
type ComponentTypes = {
|
|
@@ -11,6 +11,14 @@ type ComponentTypes = {
|
|
|
11
11
|
|
|
12
12
|
export const BackToTop: FC<ComponentTypes> = ({ ...props }) => {
|
|
13
13
|
const [visible, setVisible] = useState<boolean>(false)
|
|
14
|
+
const [rect, _setRect] = useState<DOMRect>(null)
|
|
15
|
+
const _rect = useRef(rect)
|
|
16
|
+
const setRect = (data) => {
|
|
17
|
+
_rect.current = data
|
|
18
|
+
_setRect(data)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const self = useRef(null)
|
|
14
22
|
|
|
15
23
|
const getCoords = () => {
|
|
16
24
|
let anchor = props.anchor.current
|
|
@@ -29,42 +37,59 @@ export const BackToTop: FC<ComponentTypes> = ({ ...props }) => {
|
|
|
29
37
|
props.anchor.current.scrollTo(0, 0)
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
// FIXME: Observers and listeners run twice
|
|
32
41
|
useEffect(() => {
|
|
42
|
+
if (!props.anchor.current) return
|
|
43
|
+
|
|
33
44
|
props.anchor.current.addEventListener("scroll", onScroll)
|
|
34
45
|
|
|
46
|
+
// Listens to rect changes. Alternatives like ResizeObserver & IntersectionObserver fail to detect positional changes consistently
|
|
47
|
+
let interval = setInterval(() => {
|
|
48
|
+
if (!props.anchor.current) return
|
|
49
|
+
|
|
50
|
+
let newRect = props.anchor.current.getBoundingClientRect()
|
|
51
|
+
if (_rect.current == null) return setRect(newRect)
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
!(
|
|
55
|
+
_rect.current.top == newRect.top &&
|
|
56
|
+
_rect.current.left == newRect.left &&
|
|
57
|
+
_rect.current.width == newRect.width &&
|
|
58
|
+
_rect.current.height == newRect.height
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
setRect(newRect)
|
|
62
|
+
}
|
|
63
|
+
}, 1)
|
|
64
|
+
|
|
35
65
|
return () => {
|
|
36
66
|
props.anchor.current?.removeEventListener("scroll", onScroll)
|
|
67
|
+
clearInterval(interval)
|
|
37
68
|
}
|
|
38
69
|
}, [])
|
|
39
70
|
|
|
40
|
-
// // Reference to tailwind classes of corners
|
|
41
|
-
// const corners = {
|
|
42
|
-
// "top-left": ["top-0 left-0", "ml", "mt"],
|
|
43
|
-
// "top-right": ["top-0 right-0", "mr", "mt"],
|
|
44
|
-
// "bottom-left": ["bottom-0 left-0", "ml", "mb"],
|
|
45
|
-
// "bottom-right": ["bottom-0 right-0", "mr", "mb"],
|
|
46
|
-
// }
|
|
47
|
-
|
|
48
|
-
// const getClasses = () => {
|
|
49
|
-
// let [corner, horizontal, vertical] = corners[props.corner || "bottom-right"]
|
|
50
|
-
|
|
51
|
-
// return clsx(
|
|
52
|
-
// `${horizontal}-[${props.paddingX || 100}px]`,
|
|
53
|
-
// `${vertical}-[${props.paddingY || 0}px]`,
|
|
54
|
-
// `${corner}`,
|
|
55
|
-
// `${visible ? "block" : "hidden"}`
|
|
56
|
-
// )
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
// Had to use react styles because tailwind didn't update top & left
|
|
60
71
|
const getStyles = () => {
|
|
72
|
+
if (!props.anchor.current) return {}
|
|
73
|
+
|
|
61
74
|
let corner = props.corner || "bottom-right"
|
|
62
75
|
let [vertical, horizontal] = corner.split("-")
|
|
63
76
|
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
let anchorRect = props.anchor.current.getBoundingClientRect()
|
|
78
|
+
let selfRect = self.current.getBoundingClientRect()
|
|
79
|
+
|
|
80
|
+
let width = horizontal == "right" ? anchorRect.width - selfRect.width : 0
|
|
81
|
+
let height = vertical == "bottom" ? anchorRect.height - selfRect.height : 0
|
|
82
|
+
|
|
83
|
+
let style = {
|
|
84
|
+
top:
|
|
85
|
+
anchorRect.y +
|
|
86
|
+
height +
|
|
87
|
+
(vertical == "bottom" ? -1 : 1) * (props.paddingX || 10),
|
|
88
|
+
left:
|
|
89
|
+
anchorRect.x +
|
|
90
|
+
width +
|
|
91
|
+
(horizontal == "right" ? -1 : 1) * (props.paddingX || 25),
|
|
92
|
+
}
|
|
68
93
|
|
|
69
94
|
return style
|
|
70
95
|
}
|
|
@@ -72,11 +97,19 @@ export const BackToTop: FC<ComponentTypes> = ({ ...props }) => {
|
|
|
72
97
|
return (
|
|
73
98
|
<div
|
|
74
99
|
className={clsx(
|
|
75
|
-
"fixed w-fit rounded bg-blue-300 p-2 text-black transition-all hover:bg-blue-500
|
|
76
|
-
`${
|
|
100
|
+
"fixed w-fit rounded bg-blue-300 p-2 text-black transition-all hover:bg-blue-500",
|
|
101
|
+
`${
|
|
102
|
+
visible
|
|
103
|
+
? "pointer-events-all opacity-100"
|
|
104
|
+
: "pointer-events-none opacity-0"
|
|
105
|
+
}`
|
|
77
106
|
)}
|
|
78
|
-
style={
|
|
107
|
+
style={{
|
|
108
|
+
...getStyles(),
|
|
109
|
+
transitionProperty: "opacity, background-color",
|
|
110
|
+
}}
|
|
79
111
|
onClick={backToTop}
|
|
112
|
+
ref={self}
|
|
80
113
|
>
|
|
81
114
|
{/* Back to top arrow 👇*/}
|
|
82
115
|
<svg
|
|
@@ -117,7 +117,11 @@ export const HawaAlert: React.FunctionComponent<AlertTypes> = ({
|
|
|
117
117
|
role="alert"
|
|
118
118
|
dir={direction}
|
|
119
119
|
>
|
|
120
|
-
<span
|
|
120
|
+
<span
|
|
121
|
+
className={clsx("font-medium", direction === "rtl" ? "ml-8" : "mr-8")}
|
|
122
|
+
>
|
|
123
|
+
{props.title}
|
|
124
|
+
</span>
|
|
121
125
|
<span>{" " + props.text}</span>
|
|
122
126
|
|
|
123
127
|
{props.actions && (
|
|
@@ -137,8 +141,9 @@ export const HawaAlert: React.FunctionComponent<AlertTypes> = ({
|
|
|
137
141
|
<button
|
|
138
142
|
type="button"
|
|
139
143
|
className={clsx(
|
|
140
|
-
"absolute
|
|
141
|
-
closeButtonStyle[props.severity]
|
|
144
|
+
"absolute top-2 inline-flex h-9 w-9 items-center justify-center rounded-inner p-1.5 text-gray-400 transition-all hover:text-gray-900 focus:ring-2 focus:ring-gray-300 dark:bg-gray-800 dark:text-gray-500 dark:hover:bg-gray-700 dark:hover:text-white",
|
|
145
|
+
closeButtonStyle[props.severity],
|
|
146
|
+
direction === "rtl" ? "left-2" : "right-2"
|
|
142
147
|
)}
|
|
143
148
|
data-dismiss-target="#alert-default"
|
|
144
149
|
aria-label="Close"
|
|
@@ -7,7 +7,6 @@ import useDiscloser from "../hooks/useDiscloser"
|
|
|
7
7
|
import useBreakpoint from "../hooks/useBreakpoint"
|
|
8
8
|
import { HawaButton, HawaMenu } from "../elements"
|
|
9
9
|
|
|
10
|
-
// TODO: when no navbar, the drawer can't be opened
|
|
11
10
|
// TODO: when no pagetitle, navbar gets messy
|
|
12
11
|
|
|
13
12
|
type HawaAppLayoutTypes = {
|
|
@@ -229,6 +228,8 @@ export const HawaAppLayout: React.FunctionComponent<HawaAppLayoutTypes> = ({
|
|
|
229
228
|
{/* Drawer Content Container */}
|
|
230
229
|
<div
|
|
231
230
|
className={clsx(
|
|
231
|
+
"no-scrollbar",
|
|
232
|
+
|
|
232
233
|
props.topBar ? "" : "mt-2",
|
|
233
234
|
openSideMenu ? "overflow-auto" : "overflow-hidden"
|
|
234
235
|
)}
|
|
@@ -395,9 +396,10 @@ export const HawaAppLayout: React.FunctionComponent<HawaAppLayoutTypes> = ({
|
|
|
395
396
|
{openSideMenu && (
|
|
396
397
|
<div
|
|
397
398
|
className={clsx(
|
|
398
|
-
"fixed bottom-0
|
|
399
|
-
openSideMenu ? "bg-layoutPrimary-500" : "bg-
|
|
400
|
-
onSettingsClick ? "justify-between" : "justify-end"
|
|
399
|
+
"fixed bottom-0 flex flex-row items-center bg-layoutPrimary-500 p-4 transition-all",
|
|
400
|
+
openSideMenu ? "bg-layoutPrimary-500 " : "bg-red-500",
|
|
401
|
+
onSettingsClick ? "justify-between" : "justify-end",
|
|
402
|
+
direction === "rtl" ? "right-0" : "left-0"
|
|
401
403
|
)}
|
|
402
404
|
style={{
|
|
403
405
|
width: `${
|
|
@@ -454,6 +456,7 @@ export const HawaAppLayout: React.FunctionComponent<HawaAppLayoutTypes> = ({
|
|
|
454
456
|
<FaChevronRight
|
|
455
457
|
fontSize={14}
|
|
456
458
|
className={clsx(
|
|
459
|
+
"transition-all",
|
|
457
460
|
isRTL
|
|
458
461
|
? keepOpen
|
|
459
462
|
? "rotate-0"
|