@sikka/hawa 0.0.202 → 0.0.203
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 +653 -648
- package/es/hooks/useTable.d.ts +5 -0
- package/es/index.es.js +1 -1
- package/lib/hooks/useTable.d.ts +5 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/elements/HawaSelect.tsx +17 -3
- package/src/elements/HawaTable.tsx +190 -8
- package/src/hooks/useTable.ts +32 -0
- package/src/styles.css +653 -648
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import clsx from "clsx"
|
|
1
2
|
import React from "react"
|
|
2
3
|
import Select from "react-select"
|
|
3
4
|
import CreatableSelect from "react-select/creatable"
|
|
@@ -7,6 +8,7 @@ type OptionTypes = {
|
|
|
7
8
|
getStyles: any
|
|
8
9
|
innerProps: any
|
|
9
10
|
innerRef: any
|
|
11
|
+
size?: "small" | "normal" | "large"
|
|
10
12
|
}
|
|
11
13
|
const Option: React.FunctionComponent<OptionTypes> = ({
|
|
12
14
|
cx,
|
|
@@ -14,11 +16,12 @@ const Option: React.FunctionComponent<OptionTypes> = ({
|
|
|
14
16
|
getStyles,
|
|
15
17
|
innerProps,
|
|
16
18
|
innerRef,
|
|
19
|
+
size = "normal",
|
|
17
20
|
...props
|
|
18
21
|
}) => (
|
|
19
22
|
<div
|
|
20
23
|
ref={innerRef}
|
|
21
|
-
className="m-2 flex flex-row items-center justify-between rounded
|
|
24
|
+
className="m-2 flex flex-row items-center justify-between rounded p-1 px-3 hover:bg-buttonPrimary-500 hover:text-white"
|
|
22
25
|
{...innerProps}
|
|
23
26
|
>
|
|
24
27
|
{children}
|
|
@@ -31,6 +34,7 @@ type ControlTypes = {
|
|
|
31
34
|
getStyles: any
|
|
32
35
|
innerProps: any
|
|
33
36
|
innerRef: any
|
|
37
|
+
size?: "small" | "normal" | "large"
|
|
34
38
|
}
|
|
35
39
|
const Control: React.FunctionComponent<ControlTypes> = ({
|
|
36
40
|
cx,
|
|
@@ -38,12 +42,21 @@ const Control: React.FunctionComponent<ControlTypes> = ({
|
|
|
38
42
|
getStyles,
|
|
39
43
|
innerProps,
|
|
40
44
|
innerRef,
|
|
45
|
+
size = "normal",
|
|
41
46
|
...props
|
|
42
47
|
}) => {
|
|
48
|
+
let sizeStyles = {
|
|
49
|
+
small: "h-7 text-xs",
|
|
50
|
+
normal: "h-10 text-sm",
|
|
51
|
+
large: "",
|
|
52
|
+
}
|
|
43
53
|
return (
|
|
44
54
|
<div
|
|
45
55
|
ref={innerRef}
|
|
46
|
-
className=
|
|
56
|
+
className={clsx(
|
|
57
|
+
sizeStyles[size],
|
|
58
|
+
"flex w-full rounded border border-gray-300 bg-gray-50 text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
|
59
|
+
)}
|
|
47
60
|
{...innerProps}
|
|
48
61
|
// {...props}
|
|
49
62
|
>
|
|
@@ -93,10 +106,11 @@ type SelectTypes = {
|
|
|
93
106
|
value?: any
|
|
94
107
|
children?: any
|
|
95
108
|
getOptionLabel?: any
|
|
109
|
+
// size?
|
|
96
110
|
}
|
|
97
111
|
export const HawaSelect: React.FunctionComponent<SelectTypes> = (props) => {
|
|
98
112
|
return (
|
|
99
|
-
<div className="
|
|
113
|
+
<div className="">
|
|
100
114
|
{props.label && (
|
|
101
115
|
<label className="mb-2 block text-sm font-medium text-gray-900 dark:text-gray-300">
|
|
102
116
|
{props.label}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { BsThreeDotsVertical } from "react-icons/bs"
|
|
1
|
+
import React, { useEffect, useState } from "react"
|
|
2
|
+
import { BsChevronRight, BsThreeDotsVertical } from "react-icons/bs"
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
import { HawaMenu } from "./HawaMenu"
|
|
5
|
+
import useTable from "../hooks/useTable"
|
|
5
6
|
|
|
6
7
|
type TableTypes = {
|
|
7
8
|
columns: any[string]
|
|
@@ -37,6 +38,20 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
|
|
|
37
38
|
bordersWidth = "1",
|
|
38
39
|
...props
|
|
39
40
|
}) => {
|
|
41
|
+
const [perPage, setPerPage] = useState(10)
|
|
42
|
+
const [enteredPage, setEnteredPage] = useState(null)
|
|
43
|
+
const [page, setPage] = useState(1)
|
|
44
|
+
|
|
45
|
+
const { slice, range } = useTable(props.rows ?? [], page, perPage)
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (slice?.length < 1 && page !== 1) {
|
|
48
|
+
setPage(page - 1)
|
|
49
|
+
}
|
|
50
|
+
if (enteredPage) {
|
|
51
|
+
setPage(enteredPage)
|
|
52
|
+
}
|
|
53
|
+
}, [slice, page])
|
|
54
|
+
|
|
40
55
|
let isRTL = direction === "rtl"
|
|
41
56
|
|
|
42
57
|
let sizeStyles = {
|
|
@@ -91,9 +106,8 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
|
|
|
91
106
|
>
|
|
92
107
|
{/* Table Rows */}
|
|
93
108
|
{props.rows ? (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
let lastRow = rowIndex == props.rows.length - 1
|
|
109
|
+
slice?.map((singleRow: any, rowIndex: any) => {
|
|
110
|
+
let lastRow = rowIndex == slice?.length - 1
|
|
97
111
|
|
|
98
112
|
return (
|
|
99
113
|
<tr
|
|
@@ -109,9 +123,9 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
|
|
|
109
123
|
: ""
|
|
110
124
|
)}
|
|
111
125
|
>
|
|
112
|
-
{singleRow
|
|
126
|
+
{singleRow?.map((r: any, i: any) => {
|
|
113
127
|
let firstCell = i === 0
|
|
114
|
-
let lastCell = i === singleRow
|
|
128
|
+
let lastCell = i === singleRow?.length - 1
|
|
115
129
|
let isRTLLastCell =
|
|
116
130
|
isRTL && lastRow && lastCell && !props.actions
|
|
117
131
|
let isRTLFirstCell = isRTL && lastRow && firstCell
|
|
@@ -192,7 +206,6 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
|
|
|
192
206
|
})
|
|
193
207
|
) : (
|
|
194
208
|
<tr className="bg-transparent">
|
|
195
|
-
{/* {console.log('props', props.columns.length)} */}
|
|
196
209
|
<td colSpan={20}>
|
|
197
210
|
<div
|
|
198
211
|
className={clsx(
|
|
@@ -206,7 +219,176 @@ export const HawaTable: React.FunctionComponent<TableTypes> = ({
|
|
|
206
219
|
</tr>
|
|
207
220
|
)}
|
|
208
221
|
</tbody>
|
|
222
|
+
<div></div>
|
|
209
223
|
</table>
|
|
224
|
+
<div className="mt-2 flex flex-row items-center justify-between ">
|
|
225
|
+
{/* Pagination Pages */}
|
|
226
|
+
{range.length > 1 ? (
|
|
227
|
+
<div className="flex w-fit flex-row items-stretch justify-center gap-2 overflow-clip rounded ">
|
|
228
|
+
{/* Previous Page Button */}
|
|
229
|
+
<div
|
|
230
|
+
className={clsx(
|
|
231
|
+
"flex h-6 w-6 rotate-180 items-center justify-center rounded bg-gray-100 p-1 text-xs hover:bg-layoutPrimary-700 "
|
|
232
|
+
)}
|
|
233
|
+
onClick={() =>
|
|
234
|
+
page <= 1 ? setPage(range.length) : setPage(page - 1)
|
|
235
|
+
}
|
|
236
|
+
>
|
|
237
|
+
<BsChevronRight />
|
|
238
|
+
</div>
|
|
239
|
+
{/* Numbered Pagination */}
|
|
240
|
+
<div className="flex flex-row items-center overflow-clip rounded transition-all">
|
|
241
|
+
{/* The first page */}
|
|
242
|
+
{range.length > 6 &&
|
|
243
|
+
range.map((el, index) => {
|
|
244
|
+
if (index <= 0) {
|
|
245
|
+
return (
|
|
246
|
+
<button
|
|
247
|
+
key={index}
|
|
248
|
+
className={clsx(
|
|
249
|
+
"w-10 p-1 text-xs hover:bg-gray-200",
|
|
250
|
+
page === el
|
|
251
|
+
? "bg-buttonPrimary-500 text-white hover:bg-buttonPrimary-500"
|
|
252
|
+
: "bg-gray-100"
|
|
253
|
+
)}
|
|
254
|
+
onClick={() => setPage(el)}
|
|
255
|
+
>
|
|
256
|
+
{el}
|
|
257
|
+
</button>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
})}
|
|
261
|
+
{/* The Current Page / Input */}
|
|
262
|
+
{range?.length > 6 && (
|
|
263
|
+
<input
|
|
264
|
+
type={"text"}
|
|
265
|
+
className=" w-10 bg-gray-100 p-1 text-center text-xs"
|
|
266
|
+
defaultValue={
|
|
267
|
+
page !== 0 || page !== range.length - 1 ? page : "..."
|
|
268
|
+
}
|
|
269
|
+
value={
|
|
270
|
+
page == 1 || page == range.length
|
|
271
|
+
? "..."
|
|
272
|
+
: enteredPage
|
|
273
|
+
? enteredPage
|
|
274
|
+
: page
|
|
275
|
+
}
|
|
276
|
+
onChange={(e) => setEnteredPage(parseInt(e.target.value))}
|
|
277
|
+
onKeyDown={(e) => {
|
|
278
|
+
if (e.key === "Enter") {
|
|
279
|
+
setPage(enteredPage)
|
|
280
|
+
setEnteredPage(null)
|
|
281
|
+
}
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
)}
|
|
285
|
+
{/* The last page */}
|
|
286
|
+
{range?.length > 6 &&
|
|
287
|
+
range.map((el, index) => {
|
|
288
|
+
if (index >= range.length - 1) {
|
|
289
|
+
return (
|
|
290
|
+
<button
|
|
291
|
+
key={index}
|
|
292
|
+
className={clsx(
|
|
293
|
+
"w-10 p-1 text-xs hover:bg-gray-200",
|
|
294
|
+
page === el
|
|
295
|
+
? "bg-buttonPrimary-500 text-white hover:bg-buttonPrimary-500"
|
|
296
|
+
: "bg-gray-100"
|
|
297
|
+
)}
|
|
298
|
+
onClick={() => setPage(el)}
|
|
299
|
+
>
|
|
300
|
+
{el}
|
|
301
|
+
</button>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
})}
|
|
305
|
+
|
|
306
|
+
{/* All Pages if less than 6 pages */}
|
|
307
|
+
{range?.length <= 6 &&
|
|
308
|
+
range.map((el, index) => {
|
|
309
|
+
return (
|
|
310
|
+
<button
|
|
311
|
+
key={index}
|
|
312
|
+
className={clsx(
|
|
313
|
+
"w-10 p-1 text-xs hover:bg-gray-200",
|
|
314
|
+
page === el
|
|
315
|
+
? "bg-buttonPrimary-500 text-white hover:bg-buttonPrimary-500"
|
|
316
|
+
: "bg-gray-100"
|
|
317
|
+
)}
|
|
318
|
+
onClick={() => setPage(el)}
|
|
319
|
+
>
|
|
320
|
+
{el}
|
|
321
|
+
</button>
|
|
322
|
+
)
|
|
323
|
+
})}
|
|
324
|
+
</div>
|
|
325
|
+
{/* Next Page Button */}
|
|
326
|
+
<div
|
|
327
|
+
onClick={() =>
|
|
328
|
+
page >= range.length ? setPage(1) : setPage(page + 1)
|
|
329
|
+
}
|
|
330
|
+
className={clsx(
|
|
331
|
+
"flex h-6 w-6 items-center justify-center rounded bg-gray-100 p-1 text-xs hover:bg-layoutPrimary-700 "
|
|
332
|
+
)}
|
|
333
|
+
>
|
|
334
|
+
<BsChevronRight />
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
) : (
|
|
338
|
+
<div></div>
|
|
339
|
+
)}
|
|
340
|
+
{/* Pagination Settings */}
|
|
341
|
+
<div className="w-fit ">
|
|
342
|
+
<select
|
|
343
|
+
value={perPage}
|
|
344
|
+
className="h-6 rounded text-xs"
|
|
345
|
+
onChange={(e) => {
|
|
346
|
+
setPerPage(parseInt(e.target.value))
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<option value={10} style={{ fontSize: 10 }}>
|
|
350
|
+
10 Items
|
|
351
|
+
</option>
|
|
352
|
+
<option value={20} style={{ fontSize: 10 }}>
|
|
353
|
+
20 Items
|
|
354
|
+
</option>
|
|
355
|
+
<option value={30} style={{ fontSize: 10 }}>
|
|
356
|
+
30 Items
|
|
357
|
+
</option>
|
|
358
|
+
<option value={50} style={{ fontSize: 10 }}>
|
|
359
|
+
50 Items
|
|
360
|
+
</option>
|
|
361
|
+
<option value={100} style={{ fontSize: 10 }}>
|
|
362
|
+
100 Items
|
|
363
|
+
</option>
|
|
364
|
+
</select>
|
|
365
|
+
{/* <HawaSelect
|
|
366
|
+
// label="Per Page"
|
|
367
|
+
isCreatable={false}
|
|
368
|
+
isMulti={false}
|
|
369
|
+
isSearchable={false}
|
|
370
|
+
isClearable={false}
|
|
371
|
+
options={[
|
|
372
|
+
{ value: 2, label: "2" },
|
|
373
|
+
{ value: 7, label: "7" },
|
|
374
|
+
{ value: 10, label: "10" },
|
|
375
|
+
{ value: 20, label: "20" },
|
|
376
|
+
]}
|
|
377
|
+
onChange={(e: any) => {
|
|
378
|
+
// field.onChange(e.value)
|
|
379
|
+
console.log("changing to ", e.value)
|
|
380
|
+
setPage(1)
|
|
381
|
+
setPerPage(e.value)
|
|
382
|
+
}}
|
|
383
|
+
onInputChange={(e: any) => {
|
|
384
|
+
// field.onChange(e.value)
|
|
385
|
+
console.log("changing to ", e.value)
|
|
386
|
+
setPage(1)
|
|
387
|
+
setPerPage(e.value)
|
|
388
|
+
}}
|
|
389
|
+
/> */}
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
210
392
|
</div>
|
|
211
393
|
)
|
|
212
394
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useEffect } from "react"
|
|
2
|
+
|
|
3
|
+
const calculateRange = (data, rowsPerPage) => {
|
|
4
|
+
const range = []
|
|
5
|
+
const num = Math.ceil(data?.length / rowsPerPage)
|
|
6
|
+
let i = 1
|
|
7
|
+
for (let i = 1; i <= num; i++) {
|
|
8
|
+
range.push(i)
|
|
9
|
+
}
|
|
10
|
+
return range
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const sliceData = (data, page, rowsPerPage) => {
|
|
14
|
+
return data?.slice((page - 1) * rowsPerPage, page * rowsPerPage)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const useTable = (data, page, rowsPerPage) => {
|
|
18
|
+
const [tableRange, setTableRange] = useState([])
|
|
19
|
+
const [slice, setSlice] = useState([])
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const range = calculateRange(data, rowsPerPage)
|
|
23
|
+
setTableRange([...range])
|
|
24
|
+
|
|
25
|
+
const slice = sliceData(data, page, rowsPerPage)
|
|
26
|
+
setSlice([...slice])
|
|
27
|
+
}, [data, setTableRange, page, setSlice, rowsPerPage])
|
|
28
|
+
|
|
29
|
+
return { slice, range: tableRange }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default useTable
|