|
2 | 2 | import type { Snippet } from 'svelte'; |
3 | 3 | import { twMerge } from 'tailwind-merge'; |
4 | 4 | import { setContext } from 'svelte'; |
| 5 | + import type { HTMLTableAttributes } from 'svelte/elements'; |
5 | 6 |
|
6 | 7 | type TableSearchType = { |
7 | 8 | striped?: boolean; |
8 | 9 | hoverable?: boolean; |
9 | 10 | color?: string | undefined | null; |
10 | 11 | }; |
11 | | - interface Props { |
| 12 | + interface Props extends HTMLTableAttributes{ |
12 | 13 | children?: Snippet; |
13 | 14 | svgSearch?: any; |
14 | 15 | header?: Snippet; |
|
17 | 18 | inputValue?: string | undefined | null; |
18 | 19 | striped?: boolean; |
19 | 20 | hoverable?: boolean; |
20 | | - placeholder?: string | undefined | null; |
21 | 21 | customColor?: string | undefined; |
22 | 22 | color?: string | undefined; |
23 | 23 | innerDivClass?: string | undefined | null; |
24 | | - inputclass?: string | undefined | null; |
| 24 | + inputClass?: string | undefined | null; |
25 | 25 | searchClass?: string | undefined | null; |
26 | 26 | svgDivClass?: string | undefined | null; |
27 | 27 | svgClass?: string | undefined | null; |
| 28 | + tableClass? : string | undefined | null; |
28 | 29 | classDiv?: string | undefined | null; |
29 | 30 | class?: string | undefined | null; |
30 | 31 | } |
|
34 | 35 | svgSearch, |
35 | 36 | header, |
36 | 37 | footer, |
37 | | - divClass = '', |
| 38 | + divClass = 'relative overflow-x-auto shadow-md sm:rounded-lg', |
38 | 39 | inputValue = $bindable(), |
39 | 40 | striped, |
40 | 41 | hoverable, |
41 | | - placeholder = 'Search', |
42 | 42 | customColor = '', |
43 | 43 | color = 'default', |
44 | | - innerDivClass = '', |
45 | | - inputclass, |
46 | | - searchClass = '', |
| 44 | + innerDivClass = 'p-4', |
| 45 | + inputClass, |
| 46 | + searchClass = 'relative mt-1', |
47 | 47 | svgDivClass, |
48 | | - svgClass = '', |
| 48 | + svgClass = 'w-5 h-5 text-gray-500 dark:text-gray-400', |
| 49 | + tableClass = 'w-full text-left text-sm', |
49 | 50 | classDiv, |
50 | 51 | class: className, |
51 | 52 | ...attributes |
52 | 53 | }: Props = $props(); |
53 | 54 |
|
54 | 55 | let inputCls = twMerge( |
55 | 56 | 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-80 p-2.5 ps-10 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500', |
56 | | - inputclass |
| 57 | + inputClass |
57 | 58 | ); |
58 | 59 | let svgDivCls = twMerge( |
59 | 60 | 'absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none', |
|
80 | 81 | setContext('tableCtx', tableSearchCtx); |
81 | 82 | </script> |
82 | 83 |
|
83 | | -<div class={twMerge('relative overflow-x-auto shadow-md sm:rounded-lg',divClass)}> |
84 | | - <div class={twMerge('p-4',innerDivClass)}> |
| 84 | +<div class={divClass}> |
| 85 | + <div class={innerDivClass}> |
85 | 86 | <label for="table-search" class="sr-only">Search</label> |
86 | | - <div class={twMerge('relative mt-1',searchClass)}> |
| 87 | + <div class={searchClass}> |
87 | 88 | <div class={svgDivCls}> |
88 | 89 | <svg |
89 | | - class={twMerge('w-5 h-5 text-gray-500 dark:text-gray-400',svgClass)} |
| 90 | + class={svgClass} |
90 | 91 | fill="currentColor" |
91 | 92 | viewBox="0 0 20 20" |
92 | 93 | xmlns="http://www.w3.org/2000/svg" |
|
103 | 104 | type="text" |
104 | 105 | id="table-search" |
105 | 106 | class={inputCls} |
106 | | - {placeholder} |
107 | 107 | /> |
108 | 108 | </div> |
109 | 109 | {#if header} |
|
112 | 112 | </div> |
113 | 113 | <table |
114 | 114 | {...attributes} |
115 | | - class={twMerge('w-full text-left text-sm', colors[color], className)} |
| 115 | + class={twMerge(tableClass, colors[color], className)} |
116 | 116 | > |
117 | 117 | {#if children} |
118 | 118 | {@render children()} |
|
139 | 139 | @prop customColor = '' |
140 | 140 | @prop color = 'default' |
141 | 141 | @prop innerDivClass = '' |
142 | | -@prop inputclass |
| 142 | +@prop inputClass |
143 | 143 | @prop searchClass = '' |
144 | 144 | @prop svgDivClass |
145 | 145 | @prop svgClass = '' |
|
0 commit comments