@addev-be/ui 0.2.9 → 0.2.11

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/ui",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc -b --watch",
@@ -8,25 +8,23 @@ import {
8
8
  DataGridFilterGroup,
9
9
  DataGridFilterRenderer,
10
10
  DataGridFilterValue,
11
- } from './types';
12
- import { debounce, join } from 'lodash';
13
- import { defaultRendererAndFormatter, getCheckboxes } from './helpers';
11
+ } from '../types';
12
+ import { defaultRendererAndFormatter, getCheckboxes } from '../helpers';
14
13
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
15
14
 
16
- import { useElementSize } from '../../../hooks';
15
+ import { debounce } from 'lodash';
16
+ import { useElementSize } from '../../../../hooks';
17
17
 
18
18
  const CheckboxTemplate = ({
19
19
  selectedValues,
20
20
  value,
21
21
  index,
22
- className,
23
22
  style,
24
23
  onToggle,
25
24
  }: {
26
25
  selectedValues: DataGridFilterValue[];
27
26
  value: DataGridFilterCheckbox;
28
27
  index: number;
29
- className?: string;
30
28
  style?: React.CSSProperties;
31
29
  onToggle?: (values: DataGridFilterValue[]) => void;
32
30
  }) => {
@@ -37,28 +35,12 @@ const CheckboxTemplate = ({
37
35
  return (
38
36
  <styles.FilterValueContainer
39
37
  key={index}
40
- className={join(
41
- [
42
- // 'absolute left-0 right-0 flex flex-row cursor-pointer hover:bg-gray-50',
43
- className,
44
- ],
45
- ' '
46
- )}
47
38
  style={{ ...style, paddingLeft: `${value.level}rem` }}
48
39
  title={value.title}
49
40
  onClick={() => onToggle?.(value.values)}
50
41
  >
51
- <input
52
- type="checkbox"
53
- checked={checked}
54
- readOnly
55
- // className="inline-block mr-2"
56
- />
57
- <span
58
- // className="mr-2 truncate"
59
- >
60
- {value.displayValue || '(Vides)'}
61
- </span>
42
+ <input type="checkbox" checked={checked} readOnly />
43
+ <span>{value.displayValue || '(Vides)'}</span>
62
44
  </styles.FilterValueContainer>
63
45
  );
64
46
  };
@@ -121,10 +103,9 @@ export const FilterValuesScroller = ({
121
103
  onScroll={onScroll}
122
104
  $rowHeight={rowHeight}
123
105
  >
124
- <div style={{ height: `${values.length * rowHeight}px` }}>
106
+ <div style={{ height: `${checkboxes.length * rowHeight}px` }}>
125
107
  {visibleCheckboxes.map((value, index) => (
126
108
  <CheckboxTemplate
127
- className="checkbox"
128
109
  style={{ top: firstCheckboxTop + index * rowHeight + 'px' }}
129
110
  key={index}
130
111
  selectedValues={selectedValues}
@@ -42,7 +42,7 @@ import {
42
42
  } from 'react';
43
43
 
44
44
  import { ContextMenu } from '../../../ui/ContextMenu';
45
- import { FilterValuesScroller } from '../FilterValuesScroller';
45
+ import { FilterValuesScroller } from './FilterValuesScroller';
46
46
  import { Input } from '../../../forms';
47
47
  import { useFilterModal } from './hooks';
48
48
 
@@ -1,5 +1,7 @@
1
1
  import styled from 'styled-components';
2
2
 
3
+ export const DEFAULT_FILTER_ROW_HEIGHT = 24;
4
+
3
5
  export const InputContainer = styled.div.attrs({
4
6
  className: 'InputContainer',
5
7
  })`
@@ -47,3 +49,48 @@ export const Separator = styled.div.attrs({
47
49
  border-top: 1px solid var(--color-neutral-200);
48
50
  margin: var(--space-1) 0;
49
51
  `;
52
+
53
+ export const FilterValueContainer = styled.div.attrs({
54
+ className: 'FilterValueContainer',
55
+ })`
56
+ position: absolute;
57
+ left: 0;
58
+ right: 0;
59
+ display: flex;
60
+ flex-direction: row;
61
+ align-items: center;
62
+ cursor: pointer;
63
+ &:hover {
64
+ background-color: var(--color-neutral-50);
65
+ }
66
+ `;
67
+
68
+ export const FilterValuesScrollerContainer = styled.div.attrs({
69
+ className: 'FilterValuesScrollerContainer',
70
+ })<{
71
+ $rowHeight?: number;
72
+ }>`
73
+ display: block;
74
+ font-size: var(--text-base);
75
+ background-color: var(--color-neutral-0);
76
+ overflow-y: scroll;
77
+ overflow-x: hidden;
78
+ height: 100%;
79
+
80
+ & > div {
81
+ position: relative;
82
+ }
83
+
84
+ & ${FilterValueContainer} {
85
+ position: absolute;
86
+ display: flex;
87
+ flex-direction: row;
88
+ align-items: center;
89
+ height: ${({ $rowHeight = DEFAULT_FILTER_ROW_HEIGHT }) =>
90
+ `${$rowHeight}px`};
91
+
92
+ input[type='checkbox'] {
93
+ margin-right: var(--space-1);
94
+ }
95
+ }
96
+ `;
@@ -4,6 +4,7 @@ import { DataGridColumn, DataGridColumns, DataGridSettings } from '../types';
4
4
  import {
5
5
  formatMoney,
6
6
  formatNumber,
7
+ formatNumberInvariant,
7
8
  formatPercentage,
8
9
  } from '../../../../helpers/numbers';
9
10
  import { numberFilter, textFilter } from './filters';
@@ -15,7 +16,7 @@ export const isColumnVisible = <R,>(
15
16
  obj: DataGridColumn<R> | DataGridSettings
16
17
  ): boolean => obj?.order !== -1;
17
18
 
18
- const buildExcelFormat = (decimals = 2, suffix = '') =>
19
+ export const buildExcelFormat = (decimals = 2, suffix = '') =>
19
20
  `#0${decimals > 0 ? `.${repeat('0', decimals)}` : ''}${suffix}`;
20
21
 
21
22
  export const textColumn = <R extends Record<string, any>>(
@@ -125,7 +126,8 @@ export const numberColumn = <R extends Record<string, any>>(
125
126
  [key]: {
126
127
  name: title,
127
128
  render: (row) => formatNumber(row[key], decimals) ?? '',
128
- excelFormatter: () => '#',
129
+ excelFormatter: () => buildExcelFormat(decimals),
130
+ excelValue: (value) => formatNumberInvariant(value, decimals),
129
131
  getter: (row) => row[key] ?? '',
130
132
  sortGetter: (row) => row[key] ?? '',
131
133
  footer: {
@@ -170,6 +172,7 @@ export const moneyColumn = <R extends Record<string, any>>(
170
172
  name: title,
171
173
  render: (row) => formatMoney(row[key], decimals) ?? '',
172
174
  excelFormatter: () => buildExcelFormat(decimals, ' €'),
175
+ excelValue: (value) => formatNumberInvariant(value, decimals),
173
176
  getter: (row) => row[key] ?? '',
174
177
  sortGetter: (row) => row[key] ?? '',
175
178
  filter: {
@@ -213,7 +216,8 @@ export const percentageColumn = <R extends Record<string, any>>(
213
216
  [key]: {
214
217
  name: title,
215
218
  render: (row) => formatPercentage(row[key]) ?? '',
216
- excelFormatter: () => buildExcelFormat(decimals),
219
+ excelFormatter: () => buildExcelFormat(decimals, '%'),
220
+ excelValue: (value) => formatNumberInvariant(value, decimals),
217
221
  getter: (row) => row[key] ?? '',
218
222
  sortGetter: (row) => row[key] ?? '',
219
223
  filter: numberFilter(key),
@@ -156,7 +156,7 @@ export const groupDatesByYearAndMonth = (dates: any[]) =>
156
156
  if (!acc[year]) {
157
157
  acc[year] = {};
158
158
  }
159
- const yearAndMonth = moment(date).format(`YYYY-MM`);
159
+ const yearAndMonth = moment(date).format(`MM/YYYY`);
160
160
  if (!acc[year][yearAndMonth]) {
161
161
  acc[year][yearAndMonth] = [];
162
162
  }
@@ -194,7 +194,7 @@ export const useDataGrid = <R,>(
194
194
  typeof column.footer[footerKey] === 'function' &&
195
195
  column.footer[footerKey] !== null
196
196
  ) {
197
- acc[columnKey] = column.footer[footerKey];
197
+ acc[columnKey] = column.footer[footerKey] as any;
198
198
  }
199
199
  return acc;
200
200
  }, {} as Record<string, DataGridFooterFunction<R>>),
@@ -67,6 +67,11 @@ export const useDataGridCopy = <R>({
67
67
  ? "mso-number-format: '" + col.excelFormatter(col) + "';"
68
68
  : ''
69
69
  }
70
+ ${
71
+ col.excelBackgroundColor
72
+ ? "background-color: '" + col.excelBackgroundColor(value) + "';"
73
+ : ''
74
+ }
70
75
  white-space: nowrap;
71
76
  ">
72
77
  ${generateCellText(col, value)}
@@ -7,7 +7,6 @@ export const TOOLBAR_HEIGHT = 40;
7
7
  export const DEFAULT_HEADER_ROW_HEIGHT = 40;
8
8
  export const DEFAULT_FOOTER_ROW_HEIGHT = 40;
9
9
  export const DEFAULT_ROW_HEIGHT = 32;
10
- export const DEFAULT_FILTER_ROW_HEIGHT = 24;
11
10
 
12
11
  export const TopPaddingRow = styled.div``;
13
12
  export const BottomPaddingRow = styled.div``;
@@ -322,46 +321,3 @@ export const ResizeBackdrop = styled.div.attrs({
322
321
  cursor: col-resize;
323
322
  `;
324
323
  ResizeBackdrop.displayName = 'ResizeBackdrop';
325
-
326
- export const FilterValuesScrollerContainer = styled.div.attrs({
327
- className: 'FilterValuesScrollerContainer',
328
- })<{
329
- $rowHeight?: number;
330
- }>`
331
- display: block;
332
- font-size: var(--text-base);
333
- background-color: var(--color-neutral-0);
334
- overflow-y: scroll;
335
- overflow-x: hidden;
336
- height: 100%;
337
-
338
- & > div {
339
- position: relative;
340
- }
341
-
342
- & .checkbox {
343
- position: absolute;
344
- display: flex;
345
- flex-direction: row;
346
- align-items: center;
347
- height: ${({ $rowHeight = DEFAULT_FILTER_ROW_HEIGHT }) =>
348
- `${$rowHeight}px`};
349
-
350
- input[type='checkbox'] {
351
- margin-right: var(--space-1);
352
- }
353
- }
354
- `;
355
-
356
- export const FilterValueContainer = styled.div.attrs({
357
- className: 'FilterValueContainer',
358
- })`
359
- position: absolute;
360
- display: flex;
361
- flex-direction: row;
362
- align-items: center;
363
- cursor: pointer;
364
- &:hover {
365
- background-color: var(--color-neutral-50);
366
- }
367
- `;
@@ -38,6 +38,7 @@ export type DataGridColumn<R> = {
38
38
  component?: DataGridCellFC;
39
39
  editable?: boolean;
40
40
  excelFormatter?: (value: any) => string;
41
+ excelBackgroundColor?: (value: any) => string;
41
42
  excelValue?: (value: any) => string;
42
43
  filter?: DataGridFilter;
43
44
  footer?:
@@ -1,12 +1,17 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
3
  import { SqlRequestDataGridColumn, SqlRequestDataGridColumns } from '../types';
4
+ import {
5
+ buildExcelFormat,
6
+ numberFilter,
7
+ textFilter,
8
+ } from '../../DataGrid/helpers';
4
9
  import {
5
10
  formatMoney,
6
11
  formatNumber,
12
+ formatNumberInvariant,
7
13
  formatPercentage,
8
14
  } from '../../../../helpers/numbers';
9
- import { numberFilter, textFilter } from '../../DataGrid/helpers';
10
15
 
11
16
  import { formatDate } from '../../../../helpers/dates';
12
17
 
@@ -103,7 +108,14 @@ export const sqlDateColumn = <R extends Record<string, any>>(
103
108
  render: (row) => formatDate(row[key]),
104
109
  getter: (row) => row[key] ?? '',
105
110
  sortGetter: (row) => row[key] ?? '',
106
- filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
111
+ excelFormatter: () => 'dd/mm/yyyy',
112
+ excelValue: (value) => formatDate(value, 'YYYY-MM-DD'),
113
+ filter: {
114
+ ...textFilter(key),
115
+ getter: (value) => value[key] ?? '',
116
+ formatter: (value) => formatDate(value),
117
+ renderer: (value) => formatDate(value),
118
+ },
107
119
  footer: (rows) => `${rows[0][key]} éléments`,
108
120
  ...options,
109
121
  },
@@ -134,7 +146,8 @@ export const sqlNumberColumn = <R extends Record<string, any>>(
134
146
  [key]: {
135
147
  name: title,
136
148
  render: (row) => formatNumber(row[key], decimals) ?? '',
137
- excelFormatter: () => '#',
149
+ excelFormatter: () => buildExcelFormat(decimals),
150
+ excelValue: (value) => formatNumberInvariant(value, decimals),
138
151
  getter: (row) => row[key] ?? '',
139
152
  sortGetter: (row) => row[key] ?? '',
140
153
  filter: {
@@ -163,7 +176,8 @@ export const sqlMoneyColumn = <R extends Record<string, any>>(
163
176
  name: title,
164
177
  type: 'number',
165
178
  render: (row) => formatMoney(row[key], decimals) ?? '',
166
- excelFormatter: () => '#0.00',
179
+ excelFormatter: () => buildExcelFormat(decimals, ''),
180
+ excelValue: (value) => formatNumberInvariant(value, decimals),
167
181
  getter: (row) => row[key] ?? '',
168
182
  sortGetter: (row) => row[key] ?? '',
169
183
  filter: {
@@ -191,7 +205,8 @@ export const sqlPercentageColumn = <R extends Record<string, any>>(
191
205
  [key]: {
192
206
  name: title,
193
207
  render: (row) => formatPercentage(row[key]) ?? '',
194
- excelFormatter: () => '#0.00',
208
+ excelFormatter: () => buildExcelFormat(decimals, '%'),
209
+ excelValue: (value) => formatNumberInvariant(value, decimals),
195
210
  getter: (row) => row[key] ?? '',
196
211
  sortGetter: (row) => row[key] ?? '',
197
212
  filter: {
@@ -238,6 +253,8 @@ export const sqlColorColumn = <R extends Record<string, any>>(
238
253
  &nbsp;
239
254
  </div>
240
255
  ),
256
+ excelValue: () => '',
257
+ excelBackgroundColor: (value) => value,
241
258
  getter: (row) => row[key] ?? '',
242
259
  sortGetter: (row) => row[key] ?? '',
243
260
  filter: {
@@ -18,3 +18,9 @@ export const formatNumber = (number: number, decimals = 2) =>
18
18
  minimumFractionDigits: decimals,
19
19
  maximumFractionDigits: decimals,
20
20
  }).format(number);
21
+
22
+ export const formatNumberInvariant = (number: number, decimals = 2) =>
23
+ new Intl.NumberFormat('es-US', {
24
+ minimumFractionDigits: decimals,
25
+ maximumFractionDigits: decimals,
26
+ }).format(number);