allaw-ui 4.3.5 → 4.3.7

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.
@@ -4,4 +4,4 @@ declare namespace _default {
4
4
  }
5
5
  export default _default;
6
6
  export const Default: any;
7
- import FilterButtonPrimary from './FilterButtonPrimary';
7
+ import FilterButtonPrimary from "./FilterButtonPrimary";
@@ -10,17 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  // FilterButtonPrimary.stories.js
13
- import React from 'react';
14
- import FilterButtonPrimary from './FilterButtonPrimary';
13
+ // import React from 'react';
14
+ import FilterButtonPrimary from "./FilterButtonPrimary";
15
15
  import "../../../styles/global.css";
16
16
  export default {
17
- title: 'Components/Atoms/Buttons/FilterButtonPrimary',
17
+ title: "Components/Atoms/Buttons/FilterButtonPrimary",
18
18
  component: FilterButtonPrimary,
19
19
  };
20
20
  var Template = function (args) { return React.createElement(FilterButtonPrimary, __assign({}, args)); };
21
21
  export var Default = Template.bind({});
22
22
  Default.args = {
23
- onClick: function () { return alert('Button clicked!'); },
24
- zIndex: '100',
25
- children: 'Filter Button',
23
+ onClick: function () { return alert("Button clicked!"); },
24
+ zIndex: "100",
25
+ children: "Filter Button",
26
26
  };
@@ -11,6 +11,7 @@ export interface DatepickerProps {
11
11
  minDate?: Date;
12
12
  maxDate?: Date;
13
13
  disableFutur?: Boolean;
14
+ mode?: "button" | "input";
14
15
  }
15
16
  declare const Datepicker: React.FC<DatepickerProps>;
16
17
  export default Datepicker;
@@ -10,7 +10,7 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- import React, { forwardRef, useState, useRef, useEffect, useMemo } from "react";
13
+ import React, { forwardRef, useState, useRef, useEffect, useMemo, useImperativeHandle, } from "react";
14
14
  import ReactDatePicker from "react-datepicker";
15
15
  import ReactDOM from "react-dom";
16
16
  import "react-datepicker/dist/react-datepicker.css";
@@ -18,6 +18,7 @@ import "./datepicker.css";
18
18
  import "../../../styles/global.css";
19
19
  import { fr } from "date-fns/locale";
20
20
  import { format } from "date-fns";
21
+ import TinyInfo from "../typography/TinyInfo";
21
22
  var CustomInput = forwardRef(function (_a, ref) {
22
23
  var value = _a.value, onClick = _a.onClick, placeholder = _a.placeholder;
23
24
  var _b = useState(placeholder), displayedPlaceholder = _b[0], setDisplayedPlaceholder = _b[1];
@@ -47,14 +48,72 @@ var CustomInput = forwardRef(function (_a, ref) {
47
48
  React.createElement("span", { className: "datepicker-test-text", ref: testRef, "aria-hidden": "true" })));
48
49
  });
49
50
  CustomInput.displayName = "CustomInput";
51
+ var CustomInputField = forwardRef(function (_a, ref) {
52
+ var value = _a.value, onChange = _a.onChange, onCalendarClick = _a.onCalendarClick, placeholder = _a.placeholder, onBlur = _a.onBlur, error = _a.error;
53
+ var _b = useState(value || ""), inputValue = _b[0], setInputValue = _b[1];
54
+ var _c = useState(false), isTouched = _c[0], setIsTouched = _c[1];
55
+ var _d = useState(error || ""), localError = _d[0], setLocalError = _d[1];
56
+ var inputRef = useRef(null);
57
+ useEffect(function () {
58
+ setInputValue(value || "");
59
+ }, [value]);
60
+ useEffect(function () {
61
+ setLocalError(error || "");
62
+ }, [error]);
63
+ useImperativeHandle(ref, function () { return inputRef.current; });
64
+ var handleInput = function (e) {
65
+ var val = e.target.value.replace(/[^0-9/]/g, "");
66
+ if (val.length === 2 && inputValue.length === 1)
67
+ val += "/";
68
+ if (val.length === 5 && inputValue.length === 4)
69
+ val += "/";
70
+ setInputValue(val);
71
+ setLocalError("");
72
+ onChange === null || onChange === void 0 ? void 0 : onChange(val);
73
+ };
74
+ var validateDate = function (val) {
75
+ if (!/^\d{2}\/\d{2}\/\d{4}$/.test(val))
76
+ return "Format invalide";
77
+ var _a = val.split("/").map(Number), jj = _a[0], mm = _a[1], aaaa = _a[2];
78
+ var now = new Date();
79
+ var minYear = now.getFullYear() - 120;
80
+ var maxYear = now.getFullYear() - 15;
81
+ if (jj < 1 || jj > 31)
82
+ return "Jour invalide";
83
+ if (mm < 1 || mm > 12)
84
+ return "Mois invalide";
85
+ if (aaaa < minYear || aaaa > maxYear)
86
+ return "Ann\u00E9e entre ".concat(minYear, " et ").concat(maxYear);
87
+ var d = new Date(aaaa, mm - 1, jj);
88
+ if (d.getFullYear() !== aaaa ||
89
+ d.getMonth() !== mm - 1 ||
90
+ d.getDate() !== jj)
91
+ return "Date incohérente";
92
+ return "";
93
+ };
94
+ var handleBlur = function () {
95
+ setIsTouched(true);
96
+ var err = validateDate(inputValue);
97
+ setLocalError(err);
98
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur();
99
+ };
100
+ return (React.createElement("div", { style: { width: "100%" } },
101
+ React.createElement("div", { className: "datepicker-input-wrapper" },
102
+ React.createElement("input", { ref: inputRef, type: "text", inputMode: "numeric", pattern: "\\d{2}/\\d{2}/\\d{4}", maxLength: 10, className: "datepicker-input ".concat(localError && isTouched ? "datepicker-input-error" : ""), placeholder: placeholder, value: inputValue, onChange: handleInput, onBlur: handleBlur, autoComplete: "off" }),
103
+ React.createElement("button", { type: "button", className: "datepicker-input-icon", tabIndex: -1, onClick: onCalendarClick },
104
+ React.createElement("i", { className: "datepicker-icon allaw-icon-calendar" }))),
105
+ localError && isTouched && (React.createElement(TinyInfo, { variant: "medium12", color: "actions-error", text: localError }))));
106
+ });
107
+ CustomInputField.displayName = "CustomInputField";
50
108
  var Datepicker = function (_a) {
51
- var value = _a.value, onChange = _a.onChange, _b = _a.placeholder, placeholder = _b === void 0 ? "Sélectionner une date" : _b, _c = _a.yearDropdownItemNumber, yearDropdownItemNumber = _c === void 0 ? 10 : _c, maxDaysInPast = _a.maxDaysInPast, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.disableFutur, disableFutur = _d === void 0 ? true : _d;
52
- var _e = useState(value), selectedDate = _e[0], setSelectedDate = _e[1];
53
- var _f = useState(false), isOpen = _f[0], setIsOpen = _f[1];
54
- var _g = useState({ top: 0, left: 0 }), position = _g[0], setPosition = _g[1];
109
+ var value = _a.value, onChange = _a.onChange, _b = _a.placeholder, placeholder = _b === void 0 ? "Sélectionner une date" : _b, _c = _a.yearDropdownItemNumber, yearDropdownItemNumber = _c === void 0 ? 10 : _c, maxDaysInPast = _a.maxDaysInPast, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.disableFutur, disableFutur = _d === void 0 ? true : _d, _e = _a.mode, mode = _e === void 0 ? "button" : _e;
110
+ var _f = useState(value), selectedDate = _f[0], setSelectedDate = _f[1];
111
+ var _g = useState(false), isOpen = _g[0], setIsOpen = _g[1];
112
+ var _h = useState({ top: 0, left: 0 }), position = _h[0], setPosition = _h[1];
55
113
  var buttonRef = useRef(null);
56
114
  var calendarRef = useRef(null);
57
- var _h = useState("bottom"), placement = _h[0], setPlacement = _h[1];
115
+ var _j = useState("bottom"), placement = _j[0], setPlacement = _j[1];
116
+ var _k = useState(""), inputError = _k[0], setInputError = _k[1];
58
117
  useEffect(function () {
59
118
  setSelectedDate(value);
60
119
  }, [value]);
@@ -100,12 +159,10 @@ var Datepicker = function (_a) {
100
159
  };
101
160
  }, [isOpen]);
102
161
  var handleDateChange = function (date) {
103
- // console.log("Avant l'appel à onChange :", date);
104
162
  setSelectedDate(date || undefined);
105
163
  if (date) {
106
164
  onChange === null || onChange === void 0 ? void 0 : onChange(date);
107
165
  }
108
- // console.log("Après l'appel à onChange :", date);
109
166
  setIsOpen(false);
110
167
  };
111
168
  var handleClickOutside = function (event) {
@@ -139,11 +196,26 @@ var Datepicker = function (_a) {
139
196
  return new Date(new Date().setFullYear(new Date().getFullYear() - yearDropdownItemNumber));
140
197
  }, [minDate, maxDaysInPast, yearDropdownItemNumber]);
141
198
  return (React.createElement("div", { className: "datepicker-container", ref: buttonRef },
142
- React.createElement(CustomInput, { value: selectedDate
199
+ mode === "input" ? (React.createElement(CustomInputField, { value: selectedDate ? format(selectedDate, "dd/MM/yyyy") : "", onChange: function (val) {
200
+ setInputError("");
201
+ if (/^\d{2}\/\d{2}\/\d{4}$/.test(val)) {
202
+ var _a = val.split("/").map(Number), jj = _a[0], mm = _a[1], aaaa = _a[2];
203
+ var d = new Date(aaaa, mm - 1, jj);
204
+ if (d.getFullYear() === aaaa &&
205
+ d.getMonth() === mm - 1 &&
206
+ d.getDate() === jj) {
207
+ setSelectedDate(d);
208
+ onChange === null || onChange === void 0 ? void 0 : onChange(d);
209
+ }
210
+ }
211
+ }, onCalendarClick: function () { return setIsOpen(!isOpen); }, placeholder: placeholder, error: inputError, onBlur: function () {
212
+ if (!selectedDate)
213
+ setInputError("Date invalide");
214
+ } })) : (React.createElement(CustomInput, { value: selectedDate
143
215
  ? format(selectedDate, "dd MMMM yyyy", { locale: fr })
144
- : "", onClick: function () { return setIsOpen(!isOpen); }, placeholder: placeholder }),
216
+ : "", onClick: function () { return setIsOpen(!isOpen); }, placeholder: placeholder })),
145
217
  isOpen &&
146
- ReactDOM.createPortal(React.createElement("div", { ref: calendarRef, className: "datepicker-portal ".concat(placement), style: __assign({ left: "".concat(position.left, "px") }, (placement === "bottom"
218
+ ReactDOM.createPortal(React.createElement("div", { ref: calendarRef, className: "datepicker-portal ".concat(placement, " datepicker-portal-animated"), style: __assign({ left: "".concat(position.left, "px") }, (placement === "bottom"
147
219
  ? { top: "".concat(position.top, "px") }
148
220
  : { top: "".concat(position.top, "px") })) },
149
221
  React.createElement(ReactDatePicker, { selected: selectedDate, onChange: handleDateChange, locale: fr, inline: true, dateFormat: "dd MMMM yyyy", calendarClassName: "custom-calendar", showMonthDropdown: true, showYearDropdown: true, dropdownMode: "select", maxDate: maxDate || (disableFutur ? new Date() : undefined), minDate: calculatedMinDate })), document.body)));
@@ -38,6 +38,18 @@ declare namespace _default {
38
38
  let description_2: string;
39
39
  export { description_2 as description };
40
40
  }
41
+ namespace mode {
42
+ export namespace control_3 {
43
+ let type_3: string;
44
+ export { type_3 as type };
45
+ export let options: string[];
46
+ }
47
+ export { control_3 as control };
48
+ let description_3: string;
49
+ export { description_3 as description };
50
+ let defaultValue_1: string;
51
+ export { defaultValue_1 as defaultValue };
52
+ }
41
53
  }
42
54
  }
43
55
  export default _default;
@@ -87,4 +99,13 @@ export namespace WithBothConstraints {
87
99
  }
88
100
  export { args_4 as args };
89
101
  }
102
+ export namespace InputMode {
103
+ export namespace args_5 {
104
+ let mode_1: string;
105
+ export { mode_1 as mode };
106
+ let placeholder_5: string;
107
+ export { placeholder_5 as placeholder };
108
+ }
109
+ export { args_5 as args };
110
+ }
90
111
  import Datepicker from "./Datepicker";
@@ -31,6 +31,11 @@ export default {
31
31
  control: { type: "date" },
32
32
  description: "Date minimale sélectionnable",
33
33
  },
34
+ mode: {
35
+ control: { type: "select", options: ["button", "input"] },
36
+ description: "Mode d'affichage du sélecteur (bouton ou champ de saisie)",
37
+ defaultValue: "button",
38
+ },
34
39
  },
35
40
  };
36
41
  export var Default = {
@@ -65,3 +70,9 @@ export var WithBothConstraints = {
65
70
  minDate: new Date("2024-01-01"),
66
71
  },
67
72
  };
73
+ export var InputMode = {
74
+ args: {
75
+ mode: "input",
76
+ placeholder: "jj/mm/aaaa",
77
+ },
78
+ };
@@ -245,3 +245,92 @@
245
245
  background: none !important;
246
246
  cursor: not-allowed;
247
247
  }
248
+
249
+ .datepicker-input-wrapper {
250
+ display: flex;
251
+ align-items: center;
252
+ width: 100%;
253
+ position: relative;
254
+ background: var(--Primary-Blanc, #fff);
255
+ border-radius: 8px;
256
+ border: 2px solid var(--grey-venom, #e6edf5);
257
+ padding: 10px;
258
+ min-width: 120px;
259
+ height: 43px;
260
+ }
261
+ .datepicker-input-wrapper:focus-within {
262
+ border-color: var(--mid-grey, #728ea7);
263
+ }
264
+ .datepicker-input-wrapper:hover {
265
+ border-color: var(--venom-grey-dark, #d1dce8);
266
+ }
267
+ .datepicker-input {
268
+ flex: 1;
269
+ border: none;
270
+ outline: none;
271
+ background: transparent;
272
+ color: var(--noir);
273
+ font-family: "Open Sans";
274
+ font-size: 14px;
275
+ font-weight: 400;
276
+ line-height: normal;
277
+ padding-right: 36px;
278
+ }
279
+ .datepicker-input::placeholder {
280
+ color: var(--Tags-Mid-grey, rgba(114, 142, 167, 1));
281
+ opacity: 0.8;
282
+ font-weight: 400;
283
+ }
284
+ .datepicker-input-icon {
285
+ position: absolute;
286
+ right: 3px;
287
+ top: 50%;
288
+ transform: translateY(-50%);
289
+ background: none;
290
+ border: none;
291
+ cursor: pointer;
292
+ display: flex;
293
+ align-items: center;
294
+ justify-content: center;
295
+ width: 64px;
296
+ height: 30px;
297
+ padding: 0px;
298
+ border-radius: 4px;
299
+ transition: background-color 0.2s;
300
+ }
301
+ .datepicker-input-icon .datepicker-icon {
302
+ color: var(--Primary-Dark-grey, #456073);
303
+ font-size: 18px;
304
+ }
305
+ .datepicker-input-icon:hover {
306
+ background: var(--grey-venom, #e6edf5);
307
+ transition: background-color 0.2s;
308
+ }
309
+ .datepicker-input-error {
310
+ border-color: var(--actions-error, #e15151) !important;
311
+ /* background-color: rgba(225, 81, 81, 0.1) !important; */
312
+ }
313
+ .datepicker-input-error-message {
314
+ position: absolute;
315
+ left: 0;
316
+ top: 100%;
317
+ color: var(--actions-error, #e15151);
318
+ font-size: 12px;
319
+ margin-top: 2px;
320
+ padding-left: 2px;
321
+ }
322
+
323
+ .datepicker-portal-animated {
324
+ animation: fadeIn 0.2s ease-out;
325
+ }
326
+
327
+ @keyframes fadeIn {
328
+ from {
329
+ opacity: 0;
330
+ transform: scale(0.98);
331
+ }
332
+ to {
333
+ opacity: 1;
334
+ transform: scale(1);
335
+ }
336
+ }
@@ -6,4 +6,4 @@ export default _default;
6
6
  export const Default: any;
7
7
  export const SingleSelect: any;
8
8
  export const WithoutIcon: any;
9
- import BaseFilter from './Filter';
9
+ import BaseFilter from "./Filter";
@@ -1,3 +1,5 @@
1
+ // BaseFilter.stories.js
2
+ // import React from 'react';
1
3
  var __assign = (this && this.__assign) || function () {
2
4
  __assign = Object.assign || function(t) {
3
5
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,69 +11,67 @@ var __assign = (this && this.__assign) || function () {
9
11
  };
10
12
  return __assign.apply(this, arguments);
11
13
  };
12
- // BaseFilter.stories.js
13
- import React from 'react';
14
14
  import "../../../styles/global.css";
15
- import BaseFilter from './Filter';
15
+ import BaseFilter from "./Filter";
16
16
  export default {
17
- title: 'Components/Atoms/Filters/Filter',
17
+ title: "Components/Atoms/Filters/Filter",
18
18
  component: BaseFilter,
19
19
  };
20
20
  var Template = function (args) { return React.createElement(BaseFilter, __assign({}, args)); };
21
21
  export var Default = Template.bind({});
22
22
  Default.args = {
23
- tooltipContent: 'This is a tooltip',
24
- tooltipId: 'tooltip-1',
23
+ tooltipContent: "This is a tooltip",
24
+ tooltipId: "tooltip-1",
25
25
  showIcon: true,
26
- defaultSelectedValues: ['confirmed'],
26
+ defaultSelectedValues: ["confirmed"],
27
27
  filterData: [
28
- { value: 'confirmed', name: 'Confirmed' },
29
- { value: 'pending', name: 'Pending' },
30
- { value: 'available', name: 'Available' },
31
- { value: 'unavailable', name: 'Unavailable' },
32
- { value: 'cancelled', name: 'Cancelled' },
33
- { value: 'passed', name: 'Passed' },
34
- { value: 'refused', name: 'Refused' },
28
+ { value: "confirmed", name: "Confirmed" },
29
+ { value: "pending", name: "Pending" },
30
+ { value: "available", name: "Available" },
31
+ { value: "unavailable", name: "Unavailable" },
32
+ { value: "cancelled", name: "Cancelled" },
33
+ { value: "passed", name: "Passed" },
34
+ { value: "refused", name: "Refused" },
35
35
  ],
36
- setFilters: function (values) { return console.log('Selected values:', values); },
36
+ setFilters: function (values) { return console.log("Selected values:", values); },
37
37
  multiselect: true,
38
- iconName: 'fa fa-filter', // Replace with your actual icon class
39
- children: 'Filter Button',
38
+ iconName: "fa fa-filter", // Replace with your actual icon class
39
+ children: "Filter Button",
40
40
  showNumIndic: true,
41
41
  isStatusTag: true,
42
42
  };
43
43
  export var SingleSelect = Template.bind({});
44
44
  SingleSelect.args = {
45
- tooltipContent: 'This is a tooltip',
46
- tooltipId: 'tooltip-2',
45
+ tooltipContent: "This is a tooltip",
46
+ tooltipId: "tooltip-2",
47
47
  showIcon: true,
48
- defaultSelectedValues: ['confirmed'],
48
+ defaultSelectedValues: ["confirmed"],
49
49
  filterData: [
50
- { value: 'confirmed', name: 'Confirmed' },
51
- { value: 'pending', name: 'Pending' },
52
- { value: 'available', name: 'Available' },
50
+ { value: "confirmed", name: "Confirmed" },
51
+ { value: "pending", name: "Pending" },
52
+ { value: "available", name: "Available" },
53
53
  ],
54
- setFilters: function (values) { return console.log('Selected values:', values); },
54
+ setFilters: function (values) { return console.log("Selected values:", values); },
55
55
  multiselect: false,
56
- iconName: 'fa fa-filter', // Replace with your actual icon class
57
- children: 'Single Select Filter Button',
56
+ iconName: "fa fa-filter", // Replace with your actual icon class
57
+ children: "Single Select Filter Button",
58
58
  showNumIndic: true,
59
59
  isStatusTag: false,
60
60
  };
61
61
  export var WithoutIcon = Template.bind({});
62
62
  WithoutIcon.args = {
63
- tooltipContent: 'This is a tooltip',
64
- tooltipId: 'tooltip-3',
63
+ tooltipContent: "This is a tooltip",
64
+ tooltipId: "tooltip-3",
65
65
  showIcon: false,
66
- defaultSelectedValues: ['confirmed'],
66
+ defaultSelectedValues: ["confirmed"],
67
67
  filterData: [
68
- { value: 'confirmed', name: 'Confirmed' },
69
- { value: 'pending', name: 'Pending' },
70
- { value: 'available', name: 'Available' },
68
+ { value: "confirmed", name: "Confirmed" },
69
+ { value: "pending", name: "Pending" },
70
+ { value: "available", name: "Available" },
71
71
  ],
72
- setFilters: function (values) { return console.log('Selected values:', values); },
72
+ setFilters: function (values) { return console.log("Selected values:", values); },
73
73
  multiselect: true,
74
- children: 'Filter Button Without Icon',
74
+ children: "Filter Button Without Icon",
75
75
  showNumIndic: true,
76
76
  isStatusTag: true,
77
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "4.3.5",
3
+ "version": "4.3.7",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",