@sikka/hawa 0.0.205 → 0.0.206

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 (35) hide show
  1. package/dist/styles.css +124 -10
  2. package/es/elements/HawaButton.d.ts +4 -1
  3. package/es/elements/HawaChip.d.ts +3 -0
  4. package/es/elements/{HawaTimeline.d.ts → HawaStepper.d.ts} +1 -1
  5. package/es/elements/HawaTable.d.ts +7 -2
  6. package/es/elements/index.d.ts +1 -1
  7. package/es/index.es.js +1 -1
  8. package/lib/elements/HawaButton.d.ts +4 -1
  9. package/lib/elements/HawaChip.d.ts +3 -0
  10. package/lib/elements/{HawaTimeline.d.ts → HawaStepper.d.ts} +1 -1
  11. package/lib/elements/HawaTable.d.ts +7 -2
  12. package/lib/elements/index.d.ts +1 -1
  13. package/lib/index.js +1 -1
  14. package/package.json +1 -1
  15. package/src/blocks/AuthForms/NewPasswordForm.tsx +0 -1
  16. package/src/blocks/AuthForms/SignInPhone.tsx +2 -14
  17. package/src/blocks/AuthForms/SignUpForm.tsx +1 -5
  18. package/src/elements/Breadcrumb.tsx +5 -1
  19. package/src/elements/HawaButton.tsx +69 -44
  20. package/src/elements/HawaChip.tsx +31 -4
  21. package/src/elements/HawaDrawer.tsx +1 -4
  22. package/src/elements/HawaItemCard.tsx +0 -1
  23. package/src/elements/HawaMenu.tsx +1 -2
  24. package/src/elements/HawaModal.tsx +0 -2
  25. package/src/elements/HawaPhoneInput.tsx +1 -4
  26. package/src/elements/HawaSelect.tsx +3 -7
  27. package/src/elements/HawaStepper.tsx +97 -0
  28. package/src/elements/HawaTable.tsx +224 -209
  29. package/src/elements/HawaTabs.tsx +0 -2
  30. package/src/elements/HawaTextField.tsx +7 -6
  31. package/src/elements/index.ts +1 -1
  32. package/src/hooks/useBreakpoint.ts +2 -3
  33. package/src/hooks/useTable.ts +6 -4
  34. package/src/styles.css +124 -10
  35. package/src/elements/HawaTimeline.tsx +0 -84
@@ -1,24 +1,33 @@
1
1
  import React, { useEffect, useState } from "react"
2
- import { BsChevronRight, BsThreeDotsVertical } from "react-icons/bs"
2
+ import { BsChevronRight, BsFilter, BsPlus, BsThreeDots } from "react-icons/bs"
3
3
  import clsx from "clsx"
4
4
  import { HawaMenu } from "./HawaMenu"
5
5
  import useTable from "../hooks/useTable"
6
-
6
+ import { HawaTextField } from "./HawaTextField"
7
+ import { HawaButton } from "./HawaButton"
8
+ import { FaSearch } from "react-icons/fa"
9
+ // TODO: translate header tools and make it more customizable
10
+ // TODO: pass the onSearch handler to the parent
7
11
  type TableTypes = {
8
12
  columns: any[string]
9
13
  actions?: ActionItems[][]
10
14
  direction?: "rtl" | "ltr"
11
15
  rows?: any[any]
12
- noDataText?: any
13
16
  handleActionClick?: any
14
17
  end?: any
15
18
  size?: "normal" | "small"
16
19
  highlightFirst?: boolean
17
20
  customColor?: string
18
21
  clickable?: boolean
19
- actionsText?: string
22
+ texts?: {
23
+ actions?: string
24
+ noData?: any
25
+ items?: string
26
+ page?: string
27
+ }
20
28
  bordersWidth?: string
21
29
  onActionClicked?: any
30
+ headerTools?: boolean
22
31
  borders?: "all" | "cols" | "rows" | "outer" | "inner"
23
32
  }
24
33
  type ActionItems = {
@@ -42,14 +51,17 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
42
51
  const [enteredPage, setEnteredPage] = useState(null)
43
52
  const [page, setPage] = useState(1)
44
53
 
45
- const { slice, range } = useTable(props.rows ?? [], page, perPage)
46
- useEffect(() => {
54
+ const { slice, range } = useTable(props.rows, page, perPage)
55
+ const changePage = () => {
47
56
  if (slice?.length < 1 && page !== 1) {
48
57
  setPage(page - 1)
49
58
  }
50
59
  if (enteredPage) {
51
60
  setPage(enteredPage)
52
61
  }
62
+ }
63
+ useEffect(() => {
64
+ changePage()
53
65
  }, [slice, page])
54
66
 
55
67
  let isRTL = direction === "rtl"
@@ -60,168 +72,189 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
60
72
  }
61
73
 
62
74
  return (
63
- <div className="relative">
64
- <table
65
- className={clsx(
66
- "w-full rounded bg-layoutPrimary-500 text-left text-sm text-gray-500 dark:text-gray-400"
75
+ <div className="relative flex flex-col gap-2 ">
76
+ <div className="rounded bg-gray-200">
77
+ {props.headerTools && (
78
+ <div className="flex flex-row items-center justify-between px-4 py-2">
79
+ <div className="w-1/2">
80
+ <HawaTextField
81
+ icon={<FaSearch color="gray" />}
82
+ placeholder={"Search"}
83
+ width="full"
84
+ margin="none"
85
+ />
86
+ </div>
87
+ <div className="flex flex-row items-center justify-between gap-2">
88
+ <HawaButton startIcon={<BsPlus />}>Add Item</HawaButton>
89
+ <HawaButton startIcon={<BsChevronRight />}>Actions</HawaButton>
90
+ <HawaButton startIcon={<BsFilter />} endIcon={<BsChevronRight />}>
91
+ Filter
92
+ </HawaButton>
93
+ </div>
94
+ </div>
67
95
  )}
68
- >
69
- <thead className=" text-xs uppercase text-gray-700 dark:bg-gray-700 dark:text-gray-400">
70
- <tr>
71
- {props.columns.map((col: any, i: any) => {
72
- if (col.hidden) {
73
- return
74
- } else {
96
+ <table
97
+ className={clsx(
98
+ "w-full rounded bg-gray-300 text-left text-sm text-gray-500 dark:text-gray-400"
99
+ )}
100
+ >
101
+ <thead className=" text-xs uppercase text-gray-700 dark:bg-gray-700 dark:text-gray-400">
102
+ <tr>
103
+ {props.columns.map((col: any, i: any) => {
104
+ if (col.hidden) {
105
+ return
106
+ } else {
107
+ return (
108
+ <th
109
+ key={i}
110
+ scope="col"
111
+ colSpan={2}
112
+ className={clsx(
113
+ sizeStyles[size],
114
+ i !== 0 && (borders === "cols" || borders === "all")
115
+ ? `border-l border-l-[${bordersWidth}px]`
116
+ : ""
117
+ )}
118
+ >
119
+ {col.value}
120
+ </th>
121
+ )
122
+ }
123
+ })}
124
+ {props.actions && size !== "small" ? (
125
+ <th
126
+ scope="col"
127
+ className={clsx(sizeStyles[size], "w-[calc(1%)] text-center")}
128
+ >
129
+ {props.texts?.actions ?? "Actions"}
130
+ </th>
131
+ ) : null}
132
+ </tr>
133
+ </thead>
134
+ <tbody
135
+ className={
136
+ customColor && props.rows ? `bg-${customColor}` : "bg-transparent"
137
+ }
138
+ >
139
+ {/* Table Rows */}
140
+ {props.rows ? (
141
+ slice?.map((singleRow: any, rowIndex: any) => {
142
+ let lastRow = rowIndex == slice?.length - 1
75
143
  return (
76
- <th
77
- key={i}
78
- scope="col"
79
- colSpan={2}
144
+ <tr
145
+ key={rowIndex}
80
146
  className={clsx(
81
- sizeStyles[size],
82
- i !== 0 && (borders === "cols" || borders === "all")
83
- ? `border-l border-l-[${bordersWidth}px]`
147
+ " dark:border-gray-700 dark:bg-gray-800",
148
+ props.clickable ? "hover:bg-gray-100" : "",
149
+ !lastRow &&
150
+ (borders === "all" ||
151
+ borders === "rows" ||
152
+ borders === "inner")
153
+ ? `border-b border-b-[${bordersWidth}px]`
84
154
  : ""
85
155
  )}
86
156
  >
87
- {col.value}
88
- </th>
89
- )
90
- }
91
- })}
92
- {props.actions && size !== "small" ? (
93
- <th
94
- scope="col"
95
- className={clsx(sizeStyles[size], "w-[calc(1%)] text-center")}
96
- >
97
- {props.actionsText}
98
- </th>
99
- ) : null}
100
- </tr>
101
- </thead>
102
- <tbody
103
- className={
104
- customColor && props.rows ? `bg-${customColor}` : "bg-transparent"
105
- }
106
- >
107
- {/* Table Rows */}
108
- {props.rows ? (
109
- slice?.map((singleRow: any, rowIndex: any) => {
110
- let lastRow = rowIndex == slice?.length - 1
157
+ {singleRow?.map((r: any, i: any) => {
158
+ let firstCell = i === 0
159
+ let lastCell = i === singleRow?.length - 1
160
+ let isRTLLastCell =
161
+ isRTL && lastRow && lastCell && !props.actions
162
+ let isRTLFirstCell = isRTL && lastRow && firstCell
163
+ let isLTRFirstCell = !isRTL && lastRow && firstCell
164
+ let isLTRLastCell =
165
+ !isRTL && lastRow && lastCell && !props.actions
111
166
 
112
- return (
113
- <tr
114
- key={rowIndex}
115
- className={clsx(
116
- " dark:border-gray-700 dark:bg-gray-800",
117
- props.clickable ? "hover:bg-gray-100" : "",
118
- !lastRow &&
119
- (borders === "all" ||
120
- borders === "rows" ||
121
- borders === "inner")
122
- ? `border-b border-b-[${bordersWidth}px]`
123
- : ""
124
- )}
125
- >
126
- {singleRow?.map((r: any, i: any) => {
127
- let firstCell = i === 0
128
- let lastCell = i === singleRow?.length - 1
129
- let isRTLLastCell =
130
- isRTL && lastRow && lastCell && !props.actions
131
- let isRTLFirstCell = isRTL && lastRow && firstCell
132
- let isLTRFirstCell = !isRTL && lastRow && firstCell
133
- let isLTRLastCell =
134
- !isRTL && lastRow && lastCell && !props.actions
135
-
136
- if (r.hidden) {
137
- return
138
- } else {
139
- return (
140
- <td
141
- colSpan={2}
142
- key={i}
143
- className={clsx(
144
- sizeStyles[size],
145
- highlightFirst && firstCell
146
- ? "font-bold"
147
- : "font-normal",
148
- isRTLFirstCell
149
- ? "rounded-bl-none rounded-br"
150
- : isRTLLastCell
151
- ? "rounded-br-none rounded-bl"
152
- : isLTRFirstCell
153
- ? "rounded-br-none rounded-bl"
154
- : isLTRLastCell
155
- ? "rounded-bl-none rounded-br"
156
- : "",
167
+ if (r.hidden) {
168
+ return
169
+ } else {
170
+ return (
171
+ <td
172
+ colSpan={2}
173
+ key={i}
174
+ className={clsx(
175
+ sizeStyles[size],
176
+ highlightFirst && firstCell
177
+ ? "font-bold"
178
+ : "font-normal",
179
+ isRTLFirstCell
180
+ ? "rounded-bl-none rounded-br"
181
+ : isRTLLastCell
182
+ ? "rounded-br-none rounded-bl"
183
+ : isLTRFirstCell
184
+ ? "rounded-br-none rounded-bl"
185
+ : isLTRLastCell
186
+ ? "rounded-bl-none rounded-br"
187
+ : "",
157
188
 
158
- !firstCell &&
159
- !lastCell &&
160
- (borders === "cols" || borders === "inner")
161
- ? `border-l border-l-[${bordersWidth}px] border-r border-r-[${bordersWidth}px]`
162
- : !firstCell &&
163
- props.actions &&
189
+ !firstCell &&
190
+ !lastCell &&
164
191
  (borders === "cols" || borders === "inner")
165
- ? `border-l border-l-[${bordersWidth}px] border-r border-r-[${bordersWidth}px]`
166
- : ""
192
+ ? `border-l border-l-[${bordersWidth}px] border-r border-r-[${bordersWidth}px]`
193
+ : !firstCell &&
194
+ props.actions &&
195
+ (borders === "cols" || borders === "inner")
196
+ ? `border-l border-l-[${bordersWidth}px] border-r border-r-[${bordersWidth}px]`
197
+ : ""
167
198
 
168
- // customColor ? `bg-${customColor}` : "bg-white"
169
- )}
170
- >
171
- {r.value}
172
- </td>
173
- )
174
- }
175
- // }
176
- })}
177
- {props.actions && size !== "small" ? (
178
- <td
179
- align={isRTL ? "right" : "left"}
180
- className={clsx(
181
- isRTL && lastRow ? "rounded-br-none rounded-bl" : "",
182
- !isRTL && lastRow ? "rounded-bl-none rounded-br" : ""
183
- // "w-fit bg-red-400"
184
- )}
185
- colSpan={1}
186
- >
187
- <div className="flex items-center justify-center">
188
- <HawaMenu
189
- size="small"
190
- actionedItem={[rowIndex, singleRow]}
191
- menuItems={props.actions}
192
- position={
193
- direction === "rtl" ? "right-bottom" : "left-bottom"
194
- }
195
- direction={direction}
196
- >
197
- <div className="flex w-fit items-center justify-center rounded p-2 hover:bg-gray-200">
198
- <BsThreeDotsVertical />
199
- </div>
200
- </HawaMenu>
201
- </div>
202
- </td>
203
- ) : null}
204
- </tr>
205
- )
206
- })
207
- ) : (
208
- <tr className="bg-transparent">
209
- <td colSpan={20}>
210
- <div
211
- className={clsx(
212
- "w-full rounded-b bg-white p-5 text-center",
213
- customColor ? `bg-${customColor}` : "bg-white"
214
- )}
215
- >
216
- {props.noDataText}
217
- </div>
218
- </td>
219
- </tr>
220
- )}
221
- </tbody>
222
- <div></div>
223
- </table>
224
- <div className="mt-2 flex flex-row items-center justify-between ">
199
+ // customColor ? `bg-${customColor}` : "bg-white"
200
+ )}
201
+ >
202
+ {r.value}
203
+ </td>
204
+ )
205
+ }
206
+ })}
207
+ {props.actions && size !== "small" ? (
208
+ <td
209
+ align={isRTL ? "right" : "left"}
210
+ className={clsx(
211
+ isRTL && lastRow ? "rounded-br-none rounded-bl" : "",
212
+ !isRTL && lastRow ? "rounded-bl-none rounded-br" : ""
213
+ // "w-fit bg-red-400"
214
+ )}
215
+ colSpan={1}
216
+ >
217
+ <div className="flex items-center justify-center">
218
+ <HawaMenu
219
+ size="small"
220
+ actionedItem={[rowIndex, singleRow]}
221
+ menuItems={props.actions}
222
+ position={
223
+ direction === "rtl"
224
+ ? "right-bottom"
225
+ : "left-bottom"
226
+ }
227
+ direction={direction}
228
+ >
229
+ <div className="flex w-fit items-center justify-center rounded p-2 hover:bg-gray-200">
230
+ <BsThreeDots />
231
+ </div>
232
+ </HawaMenu>
233
+ </div>
234
+ </td>
235
+ ) : null}
236
+ </tr>
237
+ )
238
+ })
239
+ ) : (
240
+ <tr className="bg-transparent">
241
+ <td colSpan={20}>
242
+ <div
243
+ className={clsx(
244
+ "w-full rounded-b bg-white p-5 text-center",
245
+ customColor ? `bg-${customColor}` : "bg-white"
246
+ )}
247
+ >
248
+ {props.texts?.noData ?? "No Data"}
249
+ </div>
250
+ </td>
251
+ </tr>
252
+ )}
253
+ </tbody>
254
+ <div></div>
255
+ </table>
256
+ </div>
257
+ <div className="flex flex-row items-center justify-between ">
225
258
  {/* Pagination Pages */}
226
259
  {range.length > 1 ? (
227
260
  <div className="flex w-fit flex-row items-stretch justify-center gap-2 overflow-clip rounded ">
@@ -338,57 +371,39 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
338
371
  <div></div>
339
372
  )}
340
373
  {/* Pagination Settings */}
341
- <div className="w-fit ">
342
- {/* TODO: Hide it when props.pagination is true */}
343
- <select
344
- value={perPage}
345
- className="h-6 rounded text-xs"
346
- onChange={(e) => {
347
- setPerPage(parseInt(e.target.value))
348
- }}
349
- >
350
- <option value={10} style={{ fontSize: 10 }}>
351
- 10 Items
352
- </option>
353
- <option value={20} style={{ fontSize: 10 }}>
354
- 20 Items
355
- </option>
356
- <option value={30} style={{ fontSize: 10 }}>
357
- 30 Items
358
- </option>
359
- <option value={50} style={{ fontSize: 10 }}>
360
- 50 Items
361
- </option>
362
- <option value={100} style={{ fontSize: 10 }}>
363
- 100 Items
364
- </option>
365
- </select>
366
- {/* <HawaSelect
367
- // label="Per Page"
368
- isCreatable={false}
369
- isMulti={false}
370
- isSearchable={false}
371
- isClearable={false}
372
- options={[
373
- { value: 2, label: "2" },
374
- { value: 7, label: "7" },
375
- { value: 10, label: "10" },
376
- { value: 20, label: "20" },
377
- ]}
378
- onChange={(e: any) => {
379
- // field.onChange(e.value)
380
- console.log("changing to ", e.value)
381
- setPage(1)
382
- setPerPage(e.value)
383
- }}
384
- onInputChange={(e: any) => {
385
- // field.onChange(e.value)
386
- console.log("changing to ", e.value)
387
- setPage(1)
388
- setPerPage(e.value)
389
- }}
390
- /> */}
391
- </div>
374
+ {props.rows ? (
375
+ <div className="flex w-fit flex-row items-center gap-2 ">
376
+ <div className="text-xs ">
377
+ {props.rows.length} {props.texts?.items ?? "Items"}
378
+ </div>
379
+
380
+ <select
381
+ value={perPage}
382
+ className="h-6 rounded text-xs"
383
+ onChange={(e) => {
384
+ setPerPage(parseInt(e.target.value))
385
+ }}
386
+ >
387
+ <option value={10} style={{ fontSize: 10 }}>
388
+ 10 / {props.texts?.page ?? "Page"}
389
+ </option>
390
+ <option value={20} style={{ fontSize: 10 }}>
391
+ 20 / {props.texts?.page ?? "Page"}
392
+ </option>
393
+ <option value={30} style={{ fontSize: 10 }}>
394
+ 30 / {props.texts?.page ?? "Page"}
395
+ </option>
396
+ <option value={50} style={{ fontSize: 10 }}>
397
+ 50 / {props.texts?.page ?? "Page"}
398
+ </option>
399
+ <option value={100} style={{ fontSize: 10 }}>
400
+ 100 / {props.texts?.page ?? "Page"}
401
+ </option>
402
+ </select>
403
+ </div>
404
+ ) : (
405
+ <div></div>
406
+ )}
392
407
  </div>
393
408
  </div>
394
409
  )
@@ -35,8 +35,6 @@ export const HawaTabs: React.FunctionComponent<TabsTypes> = ({
35
35
  full: "w-full min-w-full",
36
36
  normal: "w-fit",
37
37
  }
38
- console.log("selected i : ", selectedOption)
39
- console.log("selected object : ", props.options[selectedOption])
40
38
  let orientationStyle = {
41
39
  vertical: {
42
40
  container: "flex flex-row",
@@ -1,7 +1,8 @@
1
1
  import React from "react"
2
2
  import clsx from "clsx"
3
+ // TODO: make icon based on direction
4
+ // TODO: Preferebly usse context to pass direction rtl | ltr
3
5
 
4
- import { FaSearch } from "react-icons/fa"
5
6
  type TextFieldTypes = {
6
7
  margin?: "none" | "normal" | "large"
7
8
  width?: "small" | "normal" | "full"
@@ -69,15 +70,15 @@ export const HawaTextField: React.FunctionComponent<TextFieldTypes> = ({
69
70
  />
70
71
  ) : (
71
72
  <div className="relative">
72
- <input
73
- {...props}
74
- className={clsx(defaultInputStyle, props.icon ? "pr-10" : "")}
75
- />
76
73
  {props.icon && (
77
- <div className="absolute top-1/2 right-3 -translate-y-1/2">
74
+ <div className="absolute top-1/2 left-3 -translate-y-1/2">
78
75
  {props.icon}
79
76
  </div>
80
77
  )}
78
+ <input
79
+ {...props}
80
+ className={clsx(defaultInputStyle, props.icon ? "pl-10" : "")}
81
+ />
81
82
  </div>
82
83
  )}
83
84
 
@@ -20,7 +20,7 @@ export * from "./HawaTabs"
20
20
  export * from "./HawaModal"
21
21
  export * from "./HawaMenu"
22
22
  export * from "./HawaCopyrights"
23
- export * from "./HawaTimeline"
23
+ export * from "./HawaStepper"
24
24
  export * from "./Breadcrumb"
25
25
  export * from "./HawaStats"
26
26
  export * from "./HawaSpinner"
@@ -1,7 +1,6 @@
1
1
  import { useState, useEffect } from "react"
2
2
 
3
3
  const useBreakpoint = () => {
4
- // console.log("window is ")
5
4
  const [breakpoint, setBreakpoint] = useState(window?.innerWidth)
6
5
  const resize = () => {
7
6
  setBreakpoint(window?.innerWidth)
@@ -10,9 +9,9 @@ const useBreakpoint = () => {
10
9
  useEffect(() => {
11
10
  if (typeof window !== "undefined") {
12
11
  // Client-side-only code
13
-
12
+
14
13
  window?.addEventListener("resize", resize)
15
-
14
+
16
15
  return () => {
17
16
  window?.removeEventListener("resize", resize)
18
17
  }
@@ -19,11 +19,13 @@ const useTable = (data, page, rowsPerPage) => {
19
19
  const [slice, setSlice] = useState([])
20
20
 
21
21
  useEffect(() => {
22
- const range = calculateRange(data, rowsPerPage)
23
- setTableRange([...range])
22
+ if (data) {
23
+ const range = calculateRange(data, rowsPerPage)
24
+ setTableRange([...range])
24
25
 
25
- const slice = sliceData(data, page, rowsPerPage)
26
- setSlice([...slice])
26
+ const slice = sliceData(data, page, rowsPerPage)
27
+ setSlice([...slice])
28
+ }
27
29
  }, [data, setTableRange, page, setSlice, rowsPerPage])
28
30
 
29
31
  return { slice, range: tableRange }