5htp-core 0.4.6-2 → 0.4.6-4
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.4.6-
|
|
4
|
+
"version": "0.4.6-4",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,6 +50,20 @@ table {
|
|
|
50
50
|
padding-right: 2em;
|
|
51
51
|
text-align: right;
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
&.stickyColumn {
|
|
55
|
+
position: sticky;
|
|
56
|
+
left: 0;
|
|
57
|
+
background: var(--cBg);
|
|
58
|
+
white-space: break-spaces;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
thead.stickyHeader {
|
|
63
|
+
position: sticky;
|
|
64
|
+
top: 0;
|
|
65
|
+
background: var(--cBg);
|
|
66
|
+
white-space: break-spaces;
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
tbody {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
----------------------------------*/
|
|
5
5
|
// Libs
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { ComponentChild } from 'preact';
|
|
7
|
+
import { JSX, ComponentChild } from 'preact';
|
|
8
8
|
|
|
9
9
|
// Composants
|
|
10
10
|
import Button, { Props as TButtonProps } from '@client/components/button';
|
|
@@ -21,6 +21,7 @@ export type Props<TRow> = {
|
|
|
21
21
|
|
|
22
22
|
data: TRow[],
|
|
23
23
|
columns: (row: TRow, rows: TRow[], index: number) => TColumn[];
|
|
24
|
+
stickyHeader?: boolean,
|
|
24
25
|
|
|
25
26
|
setData?: (rows: TRow[]) => void,
|
|
26
27
|
empty?: ComponentChild | false,
|
|
@@ -29,11 +30,11 @@ export type Props<TRow> = {
|
|
|
29
30
|
actions?: TAction<TRow>[]
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export type TColumn = {
|
|
33
|
+
export type TColumn = JSX.HTMLAttributes<HTMLElement> & {
|
|
33
34
|
label: ComponentChild,
|
|
34
35
|
cell: ComponentChild,
|
|
35
36
|
raw?: number | string | boolean,
|
|
36
|
-
|
|
37
|
+
stick?: string
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type TAction<TRow> = Omit<TButtonProps, 'onClick'> & {
|
|
@@ -47,6 +48,7 @@ export type TAction<TRow> = Omit<TButtonProps, 'onClick'> & {
|
|
|
47
48
|
- COMPOSANTS
|
|
48
49
|
----------------------------------*/
|
|
49
50
|
export default function Liste<TRow extends TDonneeInconnue>({
|
|
51
|
+
stickyHeader,
|
|
50
52
|
data: rows, setData, empty,
|
|
51
53
|
columns, actions, ...props
|
|
52
54
|
}: Props<TRow>) {
|
|
@@ -92,23 +94,35 @@ export default function Liste<TRow extends TDonneeInconnue>({
|
|
|
92
94
|
</td>
|
|
93
95
|
)}
|
|
94
96
|
|
|
95
|
-
{columns(row, rows, iDonnee).map((
|
|
97
|
+
{columns(row, rows, iDonnee).map(({ label, cell, class: className, raw, stick, ...cellProps }) => {
|
|
98
|
+
|
|
99
|
+
let classe = className || '';
|
|
100
|
+
if (typeof raw === 'number')
|
|
101
|
+
classe += 'txtRight';
|
|
102
|
+
|
|
103
|
+
if (stick) {
|
|
104
|
+
classe += ' stickyColumn';
|
|
105
|
+
if (cellProps.style === undefined)
|
|
106
|
+
cellProps.style = {};
|
|
107
|
+
cellProps.style = {
|
|
108
|
+
...cellProps.style,
|
|
109
|
+
minWidth: stick,
|
|
110
|
+
width: stick,
|
|
111
|
+
maxWidth: stick,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
96
114
|
|
|
97
115
|
if (iDonnee === 0) renduColonnes.push(
|
|
98
|
-
<th>
|
|
99
|
-
{
|
|
116
|
+
<th class={classe} {...cellProps}>
|
|
117
|
+
{label}
|
|
100
118
|
</th>
|
|
101
119
|
);
|
|
102
120
|
|
|
103
|
-
const affichageBrut = ['number', 'string'].includes(typeof
|
|
104
|
-
|
|
105
|
-
let classe = col.class || '';
|
|
106
|
-
if (typeof col.raw === 'number')
|
|
107
|
-
classe += 'txtRight';
|
|
121
|
+
const affichageBrut = ['number', 'string'].includes(typeof cell) || React.isValidElement(cell);
|
|
108
122
|
|
|
109
123
|
return (
|
|
110
|
-
<td class={classe}>
|
|
111
|
-
{affichageBrut ?
|
|
124
|
+
<td class={classe} {...cellProps}>
|
|
125
|
+
{affichageBrut ? cell : JSON.stringify(cell)}
|
|
112
126
|
</td>
|
|
113
127
|
)
|
|
114
128
|
})}
|
|
@@ -148,7 +162,7 @@ export default function Liste<TRow extends TDonneeInconnue>({
|
|
|
148
162
|
return <>
|
|
149
163
|
<div {...props}>
|
|
150
164
|
<table>
|
|
151
|
-
<thead>
|
|
165
|
+
<thead className={stickyHeader ? 'stickyHeader' : undefined}>
|
|
152
166
|
<tr>
|
|
153
167
|
{selectionMultiple && (
|
|
154
168
|
<th>
|
|
@@ -41,6 +41,28 @@ type TSubtype = TSchemaSubtype | Validator<any>;
|
|
|
41
41
|
----------------------------------*/
|
|
42
42
|
export default class SchemaValidators {
|
|
43
43
|
|
|
44
|
+
/*----------------------------------
|
|
45
|
+
- UTILITIES
|
|
46
|
+
----------------------------------*/
|
|
47
|
+
// Make every field optional
|
|
48
|
+
public partial = ( schema: TSchemaFields ) => {
|
|
49
|
+
|
|
50
|
+
const partialSchema: TSchemaFields = {};
|
|
51
|
+
for (const key in schema) {
|
|
52
|
+
|
|
53
|
+
// Only if validator
|
|
54
|
+
if (schema[key] instanceof Validator)
|
|
55
|
+
partialSchema[key] = new Validator(schema[key].type, schema[key].validateType, {
|
|
56
|
+
...schema[key].options,
|
|
57
|
+
opt: true
|
|
58
|
+
});
|
|
59
|
+
else
|
|
60
|
+
partialSchema[key] = schema[key];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return partialSchema;
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
/*----------------------------------
|
|
45
67
|
- CONTENEURS
|
|
46
68
|
----------------------------------*/
|