@sikka/hawa 0.0.167 → 0.0.169

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 (37) hide show
  1. package/README.md +0 -1
  2. package/dist/styles.css +58 -40
  3. package/es/blocks/Misc/Newsletter.d.ts +10 -0
  4. package/es/blocks/Misc/index.d.ts +1 -0
  5. package/es/elements/DragDropImages.d.ts +6 -1
  6. package/es/elements/HawaAlert.d.ts +2 -7
  7. package/es/elements/HawaButton.d.ts +6 -3
  8. package/es/elements/HawaTable.d.ts +5 -1
  9. package/es/elements/HawaTooltip.d.ts +7 -2
  10. package/es/hooks/index.d.ts +1 -0
  11. package/es/hooks/useHover.d.ts +3 -0
  12. package/es/hooks/useScrollPosition.d.ts +2 -0
  13. package/es/index.es.js +1 -1
  14. package/lib/blocks/Misc/Newsletter.d.ts +10 -0
  15. package/lib/blocks/Misc/index.d.ts +1 -0
  16. package/lib/elements/DragDropImages.d.ts +6 -1
  17. package/lib/elements/HawaAlert.d.ts +2 -7
  18. package/lib/elements/HawaButton.d.ts +6 -3
  19. package/lib/elements/HawaTable.d.ts +5 -1
  20. package/lib/elements/HawaTooltip.d.ts +7 -2
  21. package/lib/hooks/index.d.ts +1 -0
  22. package/lib/hooks/useHover.d.ts +3 -0
  23. package/lib/hooks/useScrollPosition.d.ts +2 -0
  24. package/lib/index.js +1 -1
  25. package/package.json +1 -1
  26. package/src/blocks/Misc/Newsletter.tsx +38 -0
  27. package/src/blocks/Misc/index.ts +1 -0
  28. package/src/elements/DragDropImages.tsx +8 -3
  29. package/src/elements/HawaAlert.tsx +4 -9
  30. package/src/elements/HawaButton.tsx +23 -34
  31. package/src/elements/HawaCardInput.tsx +1 -0
  32. package/src/elements/HawaTable.tsx +91 -195
  33. package/src/elements/HawaTooltip.tsx +96 -26
  34. package/src/hooks/index.ts +1 -0
  35. package/src/hooks/useHover.ts +25 -0
  36. package/src/hooks/{useScrollPosition.js → useScrollPosition.ts} +0 -0
  37. package/src/styles.css +58 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sikka/hawa",
3
- "version": "0.0.167",
3
+ "version": "0.0.169",
4
4
  "description": "UI Kit",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.es.js",
@@ -0,0 +1,38 @@
1
+ import React from "react"
2
+ import { HawaButton, HawaTextField } from "../../elements"
3
+ import { HawaContainer } from "../../layout"
4
+ import { FaCheck } from "react-icons/fa"
5
+ type TNewsletter = {
6
+ variant?: "outlined" | "contained" | "neobrutalism"
7
+ texts: {
8
+ wantToStayUpdated: string
9
+ subscribeToNewsletter: string
10
+ }
11
+ }
12
+
13
+ // TODO: make it a form and handle email submission
14
+
15
+ export const Newsletter: React.FunctionComponent<TNewsletter> = ({
16
+ variant = "contained",
17
+ texts,
18
+ }) => {
19
+ return (
20
+ <HawaContainer variant={variant} centered={true}>
21
+ <div className="p-4 pt-0">
22
+ <h1 className="font-bold">{texts.wantToStayUpdated}</h1>
23
+ <span>{texts.subscribeToNewsletter}</span>
24
+ </div>
25
+ <div className="flex flex-row gap-2">
26
+ <HawaTextField
27
+ width="full"
28
+ type="email"
29
+ placeholder={"example@sikka.io"}
30
+ margin="none"
31
+ />
32
+ <HawaButton size="full" margins="none">
33
+ Submit
34
+ </HawaButton>
35
+ </div>
36
+ </HawaContainer>
37
+ )
38
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./NotFound"
2
2
  export * from "./EmptyState"
3
+ export * from "./Newsletter"
@@ -11,7 +11,6 @@ const thumbsContainer = {
11
11
  }
12
12
  type DragDropImagesTypes = {
13
13
  label?: string
14
- texts: any
15
14
  files: [File]
16
15
  setFiles: any
17
16
  setDeletedFiles: any
@@ -20,6 +19,12 @@ type DragDropImagesTypes = {
20
19
  onAcceptedFiles: any
21
20
  showPreview: any
22
21
  onDeleteFile: any
22
+ texts: {
23
+ clickHereToUpload: string
24
+ maxFileSize: string
25
+ tooManyFiles: string
26
+ fileTooLarge: string
27
+ }
23
28
  onClearFiles: any
24
29
  maxSize: number
25
30
  errorMessages: string
@@ -171,10 +176,10 @@ export const DragDropImages: React.FunctionComponent<DragDropImagesTypes> = ({
171
176
  className="mb-2 flex flex-col justify-center rounded-xl border border-dashed border-black"
172
177
  >
173
178
  <input {...getInputProps()} />
179
+ <div className="p-1 text-center">{texts.clickHereToUpload}</div>
174
180
  <div className="p-1 text-center">
175
- Click here or drop files here to upload
181
+ {texts.maxFileSize} {max}
176
182
  </div>
177
- <div className="p-1 text-center">Max file size is {max}</div>
178
183
  <div className="flex justify-center ">
179
184
  {acceptedFiles.length > 0 && (
180
185
  <HawaButton
@@ -2,15 +2,8 @@ import React from "react"
2
2
  import clsx from "clsx"
3
3
  import { HawaButton } from "./HawaButton"
4
4
 
5
- let severities = {
6
- info: "text-blue-700 bg-blue-100 dark:bg-blue-200 dark:text-blue-800",
7
- warning:
8
- "text-yellow-700 bg-yellow-100 dark:bg-yellow-200 dark:text-yellow-800",
9
- error: "text-red-700 bg-red-100 dark:bg-red-200 dark:text-red-800",
10
- success: "text-green-700 bg-green-100 dark:bg-green-200 dark:text-green-800",
11
- }
12
5
  type AlertTypes = {
13
- severity: keyof typeof severities
6
+ severity: "info" | "warning" | "error" | "success"
14
7
  title?: any
15
8
  variant?:
16
9
  | "normal"
@@ -20,6 +13,7 @@ type AlertTypes = {
20
13
  | "right-accent"
21
14
  | "bottom-accent"
22
15
  text: any
16
+ direction?: "rtl" | "ltr"
23
17
  hideIcon?: any
24
18
  actions?: [
25
19
  {
@@ -31,6 +25,7 @@ type AlertTypes = {
31
25
  }
32
26
  export const HawaAlert: React.FunctionComponent<AlertTypes> = ({
33
27
  variant = "normal",
28
+ direction = "ltr",
34
29
  ...props
35
30
  }) => {
36
31
  let styleVariant = {
@@ -83,10 +78,10 @@ export const HawaAlert: React.FunctionComponent<AlertTypes> = ({
83
78
  <div
84
79
  className={clsx(
85
80
  "mb-4 flex flex-col rounded-lg p-4 text-sm",
86
- // severities[props.severity],
87
81
  styleVariant[variant][props.severity]
88
82
  )}
89
83
  role="alert"
84
+ dir={direction}
90
85
  >
91
86
  <span className="font-medium">{props.title}</span>
92
87
  <span>{" " + props.text}</span>
@@ -1,24 +1,31 @@
1
- import * as React from "react"
1
+ import React, { useEffect } from "react"
2
2
  import clsx from "clsx"
3
3
  import { HawaSpinner } from "./HawaSpinner"
4
+ import { HawaTooltip } from "./HawaTooltip"
5
+ import useHover from "../hooks/useHover"
4
6
 
5
7
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
6
8
  variant?: "contained" | "outlined"
9
+ buttonID?: any
7
10
  color?: "default" | "primary" | "secondary"
8
11
  width?: "full" | "normal" | "half"
9
- size?: "small" | "medium" | "large" | "noPadding"
12
+ size?: "xs" | "small" | "medium" | "large" | "noPadding" | "full"
10
13
  margins?: "none" | "1" | "2" | "3" | "4"
11
14
  tooltip?: string
15
+ tooltipSize?: "normal" | "small" | "large"
16
+ tooltipPosition?: "right" | "left" | "bottom" | "top"
12
17
  isLoading?: boolean
13
18
  }
14
19
 
15
- const baseStyles = "font-medium rounded-lg transition-all"
20
+ const baseStyles = "cursor-pointer font-medium rounded-lg transition-all"
16
21
 
17
22
  const sizeStyles = {
23
+ xs: "px-1 py-1",
18
24
  small: "text-xs px-2.5 py-1.5",
19
25
  medium: "text-sm leading-4 px-3 py-2",
20
26
  large: "text-sm px-4 py-2",
21
27
  noPadding: "p-0",
28
+ full: "h-full max-h-full p-2",
22
29
  }
23
30
 
24
31
  const widthStyles = {
@@ -28,7 +35,7 @@ const widthStyles = {
28
35
  half: "w-1/2",
29
36
  }
30
37
  const variantStyles = {
31
- contained: "border border-transparent",
38
+ contained: "border-transparent",
32
39
  outlined: "bg-transparent border",
33
40
  }
34
41
 
@@ -63,31 +70,23 @@ export function HawaButton({
63
70
  width = "normal",
64
71
  disabled = false,
65
72
  isLoading = false,
73
+ tooltipSize = "normal",
74
+ tooltipPosition = "top",
66
75
  margins = "2",
67
76
  tooltip,
68
77
  children,
78
+ buttonID,
69
79
  ...props
70
80
  }: ButtonProps) {
71
- const [isHovered, setIsHovered] = React.useState(false)
72
81
  return (
73
82
  <div
74
- className={clsx(
75
- "relative",
76
- margins !== "none" ? `my-${margins}` : "my-0"
77
- )}
83
+ className={clsx("relative", margins !== "none" ? `my-${margins}` : "m-0")}
78
84
  >
79
- {/* <div className="bg-buttonPrimary-default h-32">test</div> */}
80
85
  <button
81
- onMouseEnter={() => {
82
- setIsHovered(true)
83
- }}
84
- onMouseLeave={() => {
85
- setIsHovered(false)
86
- }}
86
+ id={buttonID}
87
87
  className={
88
88
  disabled
89
89
  ? clsx(
90
- // "brightne",
91
90
  className,
92
91
  baseStyles,
93
92
  variantStyles[variant],
@@ -109,25 +108,15 @@ export function HawaButton({
109
108
  type={props.type}
110
109
  {...props}
111
110
  >
112
- {!isLoading ? (
113
- children
114
- ) : (
115
- // <div className="flex flex-row gap-x-3">
116
- // <div className="h-5 w-5 animate-spin rounded-full border-2 border-gray-400 border-t-white text-white"></div>
117
- // </div>
118
- <HawaSpinner />
119
- )}
111
+ {!isLoading ? children : <HawaSpinner />}
120
112
  </button>
121
113
  {tooltip && (
122
- <div
123
- className={
124
- isHovered
125
- ? "absolute top-10 left-0 z-10 inline-block w-fit min-w-max max-w-xs rounded-lg bg-gray-900 py-2 px-3 text-center text-sm font-medium text-white opacity-100 shadow-sm transition-opacity duration-300 dark:bg-gray-700"
126
- : "absolute top-10 left-0 z-10 inline-block w-fit min-w-max max-w-xs rounded-lg bg-gray-900 py-2 px-3 text-center text-sm font-medium text-white opacity-0 shadow-sm transition-opacity duration-300 dark:bg-gray-700"
127
- }
128
- >
129
- {tooltip}
130
- </div>
114
+ <HawaTooltip
115
+ position={tooltipPosition}
116
+ size={tooltipSize}
117
+ buttonID={buttonID}
118
+ content={tooltip}
119
+ />
131
120
  )}
132
121
  </div>
133
122
  )
@@ -84,6 +84,7 @@ export const HawaCardInput = ({
84
84
  }
85
85
 
86
86
  // TODO: We can improve the regex check with a better approach like in the card component.
87
+
87
88
  const onCardNumberChange = (event) => {
88
89
  let { value, name } = event.target
89
90
  let cardNumber = value
@@ -6,16 +6,18 @@ import clsx from "clsx"
6
6
  type TableTypes = {
7
7
  lang?: any
8
8
  columns: any[string]
9
- actions?: any
9
+ actions?: [{ type: "view" | "update" | "delete"; onClick: (e) => void }]
10
10
  rows?: any[any]
11
11
  noDataText?: any
12
12
  handleActionClick?: any
13
13
  end?: any
14
14
  size?: "normal" | "small"
15
+ customColor?: string
15
16
  }
16
17
 
17
18
  export const HawaTable: React.FunctionComponent<TableTypes> = ({
18
19
  size = "normal",
20
+ customColor = "white",
19
21
  ...props
20
22
  }) => {
21
23
  let isArabic = props.lang === "ar"
@@ -25,193 +27,87 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
25
27
  small: "px-3 py-1",
26
28
  }
27
29
  return (
28
- <>
29
- <div>
30
- <div className="relative overflow-x-auto rounded-xl">
31
- <table className="w-full text-left text-sm text-gray-500 dark:text-gray-400">
32
- <thead className="bg-gray-50 text-xs uppercase text-gray-700 dark:bg-gray-700 dark:text-gray-400">
33
- <tr>
34
- {props.columns.map((col: any, i: any) => (
35
- <th key={i} scope="col" className={clsx(sizeStyles[size])}>
36
- {col}
37
- </th>
38
- ))}
30
+ <div className="relative overflow-x-visible rounded-xl">
31
+ <table className="w-full text-left text-sm text-gray-500 dark:text-gray-400">
32
+ <thead className="bg-layoutPrimary-default text-xs uppercase text-gray-700 dark:bg-gray-700 dark:text-gray-400">
33
+ <tr>
34
+ {props.columns.map((col: any, i: any) => (
35
+ <th key={i} scope="col" className={clsx(sizeStyles[size])}>
36
+ {col}
37
+ </th>
38
+ ))}
39
+ {props.actions && size !== "small" ? (
40
+ <th scope="col" className={clsx(sizeStyles[size])}>
41
+ actions
42
+ </th>
43
+ ) : null}
44
+ </tr>
45
+ </thead>
46
+ <tbody>
47
+ {props.rows ? (
48
+ props.rows.map((singleRow: any, j: any) => (
49
+ <tr
50
+ key={j}
51
+ className={clsx(
52
+ "border-b dark:border-gray-700 dark:bg-gray-800",
53
+ "bg-" + customColor
54
+ )}
55
+ >
56
+ {singleRow.map((r: any, i: any) => {
57
+ if (i === 0) {
58
+ return (
59
+ <th
60
+ key={i}
61
+ scope="row"
62
+ className={clsx(
63
+ sizeStyles[size],
64
+ "whitespace-nowrap font-medium text-gray-900 dark:text-white"
65
+ )}
66
+ >
67
+ {r}{" "}
68
+ </th>
69
+ )
70
+ } else {
71
+ return (
72
+ <td key={i} className={clsx(sizeStyles[size])}>
73
+ {r}
74
+ </td>
75
+ )
76
+ }
77
+ })}
39
78
  {props.actions && size !== "small" ? (
40
- <th scope="col" className={clsx(sizeStyles[size])}>
41
- actions
42
- </th>
43
- ) : null}
44
- </tr>
45
- </thead>
46
- <tbody>
47
- {props.rows ? (
48
- props.rows.map((singleRow: any, j: any) => (
49
- <tr
50
- key={j}
51
- className="border-b bg-white dark:border-gray-700 dark:bg-gray-800"
79
+ <td
80
+ align={isArabic ? "right" : "left"}
81
+ style={{ fontWeight: 700 }}
82
+ className="flex flex-row gap-1"
83
+ // variant={isArabic ? "borderedRight" : "borderedLeft"}
52
84
  >
53
- {singleRow.map((r: any, i: any) => {
54
- if (i === 0) {
55
- return (
56
- <th
57
- key={i}
58
- scope="row"
59
- className={clsx(
60
- sizeStyles[size],
61
- "whitespace-nowrap font-medium text-gray-900 dark:text-white"
62
- )}
63
- >
64
- {r}{" "}
65
- </th>
66
- )
67
- } else {
68
- return (
69
- <td key={i} className={clsx(sizeStyles[size])}>
70
- {r}
71
- </td>
72
- )
73
- }
85
+ {props.actions.map((act: any, s: any) => {
86
+ return (
87
+ <TableActionButton
88
+ key={s}
89
+ row={j}
90
+ action={act.type}
91
+ handleActionClick={act.onClick}
92
+ />
93
+ )
74
94
  })}
75
- {props.actions && size !== "small" ? (
76
- <td
77
- align={isArabic ? "right" : "left"}
78
- style={{ fontWeight: 700 }}
79
- className="flex flex-row gap-1"
80
- // variant={isArabic ? "borderedRight" : "borderedLeft"}
81
- >
82
- {props.actions.map((act: any, s: any) => {
83
- return (
84
- <TableActionButton
85
- key={s}
86
- action={act.type}
87
- handleActionClick={act.onClick}
88
- />
89
- )
90
- })}
91
- </td>
92
- ) : null}
93
- </tr>
94
- ))
95
- ) : (
96
- <tr>
97
- <td colSpan={props.columns.length}>
98
- <div className="w-full bg-white p-5 text-center">
99
- {props.noDataText}
100
- </div>
101
95
  </td>
102
- </tr>
103
- )}
104
- </tbody>
105
- </table>
106
- </div>
107
- </div>
108
-
109
- {/* <TableContainer style={{ direction: isArabic ? "rtl" : "ltr" }}>
110
- <Table aria-label="a dense table">
111
- <TableHead>
112
- <TableRow>
113
- {props.columns.map((col, i) => (
114
- <TableCell
115
- align={isArabic ? "right" : "left"}
116
- key={i}
117
- style={{ fontWeight: 700 }}
118
- variant={
119
- i > 0
120
- ? isArabic
121
- ? "borderedRight"
122
- : "borderedLeft"
123
- : "body"
124
- }
125
- >
126
- {col}
127
- </TableCell>
128
- ))}
129
- {props.actions && (
130
- <TableCell
131
- align={isArabic ? "right" : "left"}
132
- style={{ fontWeight: 700 }}
133
- variant={isArabic ? "borderedRight" : "borderedLeft"}
134
- >
135
- Actions
136
- </TableCell>
137
- )}
138
- </TableRow>
139
- </TableHead>
140
-
141
- <TableBody>
142
- {props.rows ? (
143
- props.rows.map((singleRow, j) => (
144
- <TableRow key={j}>
145
- {singleRow.map((r, i) => (
146
- <TableCell
147
- align={isArabic ? "right" : "left"}
148
- key={i}
149
- component="th"
150
- scope="row"
151
- variant={
152
- i > 0
153
- ? isArabic
154
- ? "borderedRight"
155
- : "borderedLeft"
156
- : "body"
157
- }
158
- >
159
- {r}
160
- </TableCell>
161
- ))}
162
- {props.actions && (
163
- <TableCell
164
- align={isArabic ? "right" : "left"}
165
- style={{ fontWeight: 700 }}
166
- variant={isArabic ? "borderedRight" : "borderedLeft"}
167
- >
168
- {props.actions.map((act) => (
169
- <Button
170
- style={{ margin: 2 }}
171
- variant="outlined"
172
- size="small"
173
- onClick={() => props.handleActionClick(singleRow)}
174
- >
175
- {act}
176
- </Button>
177
- ))}
178
- </TableCell>
179
- )}
180
- </TableRow>
181
- ))
182
- ) : (
183
- <TableRow align="center">
184
- <TableCell align={"center"} component="th" colSpan={6}>
96
+ ) : null}
97
+ </tr>
98
+ ))
99
+ ) : (
100
+ <tr>
101
+ <td colSpan={props.columns.length}>
102
+ <div className="w-full bg-white p-5 text-center">
185
103
  {props.noDataText}
186
- </TableCell>
187
- </TableRow>
188
- )}
189
- </TableBody>
190
- {props.end && (
191
- <TableRow>
192
- {props.end.map((e, k) => (
193
- <TableCell
194
- align={isArabic ? "right" : "left"}
195
- style={{ fontWeight: 700 }}
196
- key={k}
197
- component="th"
198
- scope="row"
199
- variant={
200
- k > 0
201
- ? isArabic
202
- ? "borderedRight"
203
- : "borderedLeft"
204
- : "body"
205
- }
206
- >
207
- {e}
208
- </TableCell>
209
- ))}
210
- </TableRow>
104
+ </div>
105
+ </td>
106
+ </tr>
211
107
  )}
212
- </Table>
213
- </TableContainer> */}
214
- </>
108
+ </tbody>
109
+ </table>
110
+ </div>
215
111
  )
216
112
  }
217
113
 
@@ -219,22 +115,22 @@ const TableActionButton = (props) => {
219
115
  let smallAct = props.action.toLowerCase()
220
116
  return (
221
117
  <HawaButton
222
- size="noPadding"
223
- variant="outlined"
118
+ tooltipSize="small"
119
+ buttonID={props.action + props.row}
120
+ size="xs"
121
+ variant="contained"
224
122
  tooltip={props.action}
225
123
  onClick={() => props.handleActionClick(smallAct)}
226
124
  >
227
- <div className="w-full rounded-lg p-1.5">
228
- {smallAct === "delete" ? (
229
- <FaTrash />
230
- ) : smallAct === "view" ? (
231
- <FaExclamationCircle />
232
- ) : smallAct === "edit" ? (
233
- <FaPen />
234
- ) : (
235
- props.action
236
- )}
237
- </div>
125
+ {smallAct === "delete" ? (
126
+ <FaTrash />
127
+ ) : smallAct === "view" ? (
128
+ <FaExclamationCircle />
129
+ ) : smallAct === "edit" ? (
130
+ <FaPen />
131
+ ) : (
132
+ props.action
133
+ )}
238
134
  </HawaButton>
239
135
  )
240
136
  }