@ttoss/components 2.21.2 → 2.22.1

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/README.md CHANGED
@@ -105,6 +105,8 @@ import { DatePicker } from '@ttoss/components';
105
105
  />;
106
106
  ```
107
107
 
108
+ Dates, the placeholder and the calendar's month and weekday names follow the `I18nProvider` locale (the calendar supports English, Spanish and Portuguese, falling back to English). Preset labels are yours to translate.
109
+
108
110
  ### Drawer
109
111
 
110
112
  Slide-out panels from screen edges. [Docs](https://storybook.ttoss.dev/?path=/docs/components-drawer--docs)
package/dist/index.d.mts CHANGED
@@ -163,7 +163,7 @@ declare const Accordion: ({
163
163
  ...boxProps
164
164
  }: AccordionProps) => import("react/jsx-runtime").JSX.Element;
165
165
  //#endregion
166
- //#region src/components/DatePicker/DatePicker.d.ts
166
+ //#region src/components/DatePicker/DatePicker.types.d.ts
167
167
  interface DateRange {
168
168
  from: Date | undefined;
169
169
  to: Date | undefined;
@@ -172,6 +172,8 @@ interface DateRangePreset {
172
172
  label: string;
173
173
  getValue: () => DateRange;
174
174
  }
175
+ //#endregion
176
+ //#region src/components/DatePicker/DatePicker.d.ts
175
177
  interface DatePickerProps {
176
178
  label?: string;
177
179
  value?: DateRange;
@@ -1053,4 +1055,4 @@ declare const Tabs: {
1053
1055
  declare const ToastContainer: (props: ToastContainerProps) => import("react/jsx-runtime").JSX.Element;
1054
1056
  declare const toast: typeof toast$1;
1055
1057
  //#endregion
1056
- export { Accordion, AccordionItem, AccordionProps, AccordionRenderItemProps, BaseMetric, ConsentScope, DateMetric, DatePicker, DateRange, Drawer, DrawerProps, EnhancedTitle, EnhancedTitleBadge, EnhancedTitleProps, EnhancedTitleVariant, FileUploadState, FileUploader, FileUploaderProps, InstallPwa, InstallPwaUi, InstallPwaUiProps, JsonEditor, JsonView, type LinkComponentProps, List, ListItem, ListItemProps, ListProps, LockedOverlay, Markdown, MarkdownProps, Menu, MenuProps, Metric, MetricCard, MetricCardProps, Modal, ModalProps, NavList, type NavListGroup, type NavListItem, type NavListProps, Notification, NotificationAction, NotificationButton, NotificationButtonProps, NotificationCard, NotificationCardProps, NotificationsMenu, NumberMetric, OAuthConsent, OAuthConsentLabels, OAuthConsentProps, OnFilesChange, OnRemove, OnUpload, OnUploadComplete, OnUploadError, OnUploadProgress, OnUploadStart, PercentageMetric, Search, SearchProps, SpotlightCard, SpotlightCardProps, type TabListProps, type TabPanelProps, type TabProps, Table, Tabs, type TabsProps, ToastContainer, type ToastContainerProps, type ToastOptions, UploadResult, UploadedFile, collectGrantedScopes, createCell, createColumnHelper, flexRender, getCoreRowModel, toast, useReactTable };
1058
+ export { Accordion, AccordionItem, AccordionProps, AccordionRenderItemProps, BaseMetric, ConsentScope, DateMetric, DatePicker, type DateRange, Drawer, DrawerProps, EnhancedTitle, EnhancedTitleBadge, EnhancedTitleProps, EnhancedTitleVariant, FileUploadState, FileUploader, FileUploaderProps, InstallPwa, InstallPwaUi, InstallPwaUiProps, JsonEditor, JsonView, type LinkComponentProps, List, ListItem, ListItemProps, ListProps, LockedOverlay, Markdown, MarkdownProps, Menu, MenuProps, Metric, MetricCard, MetricCardProps, Modal, ModalProps, NavList, type NavListGroup, type NavListItem, type NavListProps, Notification, NotificationAction, NotificationButton, NotificationButtonProps, NotificationCard, NotificationCardProps, NotificationsMenu, NumberMetric, OAuthConsent, OAuthConsentLabels, OAuthConsentProps, OnFilesChange, OnRemove, OnUpload, OnUploadComplete, OnUploadError, OnUploadProgress, OnUploadStart, PercentageMetric, Search, SearchProps, SpotlightCard, SpotlightCardProps, type TabListProps, type TabPanelProps, type TabProps, Table, Tabs, type TabsProps, ToastContainer, type ToastContainerProps, type ToastOptions, UploadResult, UploadedFile, collectGrantedScopes, createCell, createColumnHelper, flexRender, getCoreRowModel, toast, useReactTable };
package/dist/index.mjs CHANGED
@@ -2,11 +2,11 @@
2
2
  import { Badge, BaseStyles, Box, Button, Card, Checkbox, CloseButton, Divider, Flex, Heading, IconButton, Input, Label, Link, Stack, Tag, Text, TooltipIcon, keyframes, useResponsiveValue, useTheme } from "@ttoss/ui";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { defineMessages, useI18n } from "@ttoss/react-i18n";
5
6
  import { Icon } from "@ttoss/react-icons";
6
7
  import { DayPicker } from "react-day-picker";
7
- import { ptBR } from "react-day-picker/locale";
8
+ import { enUS, es, ptBR } from "react-day-picker/locale";
8
9
  import DrawerUi from "react-modern-drawer";
9
- import { defineMessages, useI18n } from "@ttoss/react-i18n";
10
10
  import { JsonEditor } from "json-edit-react";
11
11
  import { JsonView } from "react-json-view-lite";
12
12
  import ReactMarkdown from "react-markdown";
@@ -189,72 +189,415 @@ var Accordion = ({
189
189
  };
190
190
 
191
191
  //#endregion
192
- //#region src/components/DatePicker/DatePicker.tsx
193
- var formatDate = date => {
194
- return date.toLocaleDateString("pt-BR");
192
+ //#region src/components/DatePicker/DatePicker.styles.ts
193
+ var triggerSx = {
194
+ width: "100%",
195
+ justifyContent: "space-between",
196
+ fontSize: ["14px", "14px"],
197
+ fontWeight: 400,
198
+ backgroundColor: "white",
199
+ padding: "8px 12px",
200
+ borderRadius: "lg",
201
+ border: "md",
202
+ borderColor: "display.border.muted.default",
203
+ height: "40px",
204
+ minWidth: ["auto", "240px"],
205
+ "&:disabled": {
206
+ borderColor: "display.border.muted.default"
207
+ }
195
208
  };
196
- var DatePicker = ({
197
- label,
198
- value,
209
+ var triggerTextSx = {
210
+ fontSize: ["12px", "14px"],
211
+ overflow: "hidden",
212
+ textOverflow: "ellipsis",
213
+ whiteSpace: "nowrap"
214
+ };
215
+ var backdropSx = {
216
+ display: ["block", "none"],
217
+ position: "fixed",
218
+ top: 0,
219
+ left: 0,
220
+ right: 0,
221
+ bottom: 0,
222
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
223
+ zIndex: 49
224
+ };
225
+ var panelSx = {
226
+ position: ["fixed", "absolute"],
227
+ top: ["auto", "calc(100% + 4px)"],
228
+ bottom: ["0", "auto"],
229
+ left: ["0", "0"],
230
+ right: ["0", "auto"],
231
+ width: ["100%", "auto"],
232
+ maxWidth: ["100%", "650px"],
233
+ zIndex: 50,
234
+ backgroundColor: "white",
235
+ border: "1px solid",
236
+ borderColor: "display.border.muted.default",
237
+ borderRadius: ["16px 16px 0 0", "8px"],
238
+ boxShadow: ["0 -4px 6px -1px rgba(0, 0, 0, 0.1)", "0 4px 6px -1px rgba(0, 0, 0, 0.1)"],
239
+ overflow: "hidden",
240
+ maxHeight: ["80vh", "none"],
241
+ display: "flex",
242
+ flexDirection: "column"
243
+ };
244
+ var mobileHeaderSx = {
245
+ display: ["flex", "none"],
246
+ justifyContent: "space-between",
247
+ alignItems: "center",
248
+ padding: "12px 16px",
249
+ borderBottom: "1px solid",
250
+ borderColor: "display.border.muted.default"
251
+ };
252
+ var closeButtonSx = {
253
+ padding: "4px",
254
+ minWidth: "auto",
255
+ width: "32px",
256
+ height: "32px"
257
+ };
258
+ var panelBodySx = {
259
+ minHeight: "300px",
260
+ flexDirection: ["column", "row"],
261
+ maxHeight: ["calc(80vh - 60px)", "none"],
262
+ overflow: ["auto", "visible"]
263
+ };
264
+ var presetsSx = {
265
+ flexDirection: ["row", "column"],
266
+ gap: "4px",
267
+ padding: ["8px", "12px"],
268
+ borderRight: ["none", "1px solid"],
269
+ borderBottom: ["1px solid", "none"],
270
+ borderColor: "display.border.muted.default",
271
+ backgroundColor: "navigation.background.muted.default",
272
+ minWidth: ["auto", "140px"],
273
+ width: ["100%", "auto"],
274
+ overflowX: ["auto", "visible"],
275
+ overflowY: ["visible", "auto"],
276
+ flexWrap: ["nowrap", "wrap"],
277
+ "@media (max-width: 768px)": {
278
+ "&::-webkit-scrollbar": {
279
+ display: "none"
280
+ },
281
+ scrollbarWidth: "none"
282
+ }
283
+ };
284
+ var presetButtonSx = {
285
+ justifyContent: ["center", "flex-start"],
286
+ fontSize: ["12px", "14px"],
287
+ fontWeight: 400,
288
+ padding: ["6px 8px", "8px 12px"],
289
+ color: "display.text.secondary.default",
290
+ backgroundColor: "transparent",
291
+ whiteSpace: "nowrap",
292
+ minWidth: ["auto", "auto"],
293
+ flexShrink: 0,
294
+ "&:hover": {
295
+ backgroundColor: "input.background.muted.active"
296
+ }
297
+ };
298
+ var calendarSx = {
299
+ padding: ["12px", "16px"],
300
+ flex: 1,
301
+ overflow: "auto",
302
+ "& .rdp": {
303
+ margin: 0
304
+ },
305
+ "& .rdp-month": {
306
+ width: "100%"
307
+ },
308
+ "& .rdp-day_button": {
309
+ borderRadius: "50% !important",
310
+ border: "none",
311
+ fontSize: ["12px", "14px"],
312
+ width: ["32px", "36px"],
313
+ height: ["32px", "36px"],
314
+ cursor: "pointer"
315
+ },
316
+ "& .rdp-range_start .rdp-day_button": {
317
+ backgroundColor: "action.background.accent.default",
318
+ color: "black"
319
+ },
320
+ "& .rdp-range_end .rdp-day_button": {
321
+ backgroundColor: "action.background.accent.default",
322
+ color: "black"
323
+ },
324
+ "& .rdp-day_button:hover": {
325
+ backgroundColor: "action.background.primary.default",
326
+ color: "action.text.primary.default"
327
+ },
328
+ "& .rdp-day_selected": {
329
+ backgroundColor: "action.background.accent.default",
330
+ color: "white",
331
+ fontWeight: 600
332
+ },
333
+ "& .rdp-day_range_middle": {
334
+ backgroundColor: "action.background.accent.default",
335
+ color: "white"
336
+ },
337
+ "& .rdp-day_range_start, & .rdp-day_range_end": {
338
+ backgroundColor: "action.background.accent.default",
339
+ color: "white",
340
+ fontWeight: 600
341
+ },
342
+ "& .rdp-weekday": {
343
+ fontSize: ["10px", "12px"],
344
+ fontWeight: 500,
345
+ color: "display.text.muted.default"
346
+ },
347
+ "& .rdp-month_caption": {
348
+ fontSize: ["12px", "14px"],
349
+ fontWeight: 600,
350
+ marginBottom: ["12px", "16px"]
351
+ },
352
+ "@media (max-width: 768px)": {
353
+ "& .rdp-caption": {
354
+ marginBottom: "8px"
355
+ },
356
+ "& .rdp-table": {
357
+ width: "100%"
358
+ }
359
+ }
360
+ };
361
+
362
+ //#endregion
363
+ //#region src/components/DatePicker/DatePickerPanel.tsx
364
+ var toDayPickerSelection = selection => {
365
+ if (!selection?.from) return;
366
+ return {
367
+ from: selection.from,
368
+ to: selection.to ?? selection.from
369
+ };
370
+ };
371
+ var Presets = ({
199
372
  presets,
200
- onChange,
201
- disabled
373
+ onPresetClick
374
+ }) => {
375
+ return /* @__PURE__ */jsx(Flex, {
376
+ sx: presetsSx,
377
+ children: presets.map(preset => {
378
+ return /* @__PURE__ */jsx(Button, {
379
+ variant: "ghost",
380
+ onClick: () => {
381
+ return onPresetClick(preset);
382
+ },
383
+ sx: presetButtonSx,
384
+ children: preset.label
385
+ }, preset.label);
386
+ })
387
+ });
388
+ };
389
+ var DatePickerPanel = ({
390
+ title,
391
+ presets,
392
+ pickerSelection,
393
+ dayPickerLocale,
394
+ disabled,
395
+ onClose,
396
+ onPresetClick,
397
+ onSelect,
398
+ onDayClick
399
+ }) => {
400
+ return /* @__PURE__ */jsxs(Fragment, {
401
+ children: [/* @__PURE__ */jsx(Box, {
402
+ sx: backdropSx,
403
+ onClick: onClose
404
+ }), /* @__PURE__ */jsxs(Box, {
405
+ sx: panelSx,
406
+ children: [/* @__PURE__ */jsxs(Flex, {
407
+ sx: mobileHeaderSx,
408
+ children: [/* @__PURE__ */jsx(Text, {
409
+ sx: {
410
+ fontSize: "16px",
411
+ fontWeight: 600
412
+ },
413
+ children: title
414
+ }), /* @__PURE__ */jsx(Button, {
415
+ variant: "ghost",
416
+ onClick: onClose,
417
+ sx: closeButtonSx,
418
+ children: /* @__PURE__ */jsx(Icon, {
419
+ icon: "mdi:close",
420
+ size: 20
421
+ })
422
+ })]
423
+ }), /* @__PURE__ */jsxs(Flex, {
424
+ sx: panelBodySx,
425
+ children: [presets && presets.length > 0 && /* @__PURE__ */jsx(Presets, {
426
+ presets,
427
+ onPresetClick
428
+ }), /* @__PURE__ */jsx(Box, {
429
+ sx: calendarSx,
430
+ children: /* @__PURE__ */jsx(DayPicker, {
431
+ disabled,
432
+ mode: "range",
433
+ locale: dayPickerLocale,
434
+ selected: toDayPickerSelection(pickerSelection),
435
+ onSelect: selected => {
436
+ return onSelect(selected);
437
+ },
438
+ onDayClick,
439
+ weekStartsOn: 1,
440
+ showOutsideDays: true
441
+ })
442
+ })]
443
+ })]
444
+ })]
445
+ });
446
+ };
447
+
448
+ //#endregion
449
+ //#region src/components/DatePicker/dayPickerLocale.ts
450
+ var DAY_PICKER_LOCALES = {
451
+ en: enUS,
452
+ es,
453
+ pt: ptBR
454
+ };
455
+ /**
456
+ * The calendar locale (month and weekday names) for an intl locale, matched
457
+ * by language and falling back to English.
458
+ */
459
+ var getDayPickerLocale = locale => {
460
+ return DAY_PICKER_LOCALES[locale?.split("-")[0].toLowerCase() ?? "en"] ?? enUS;
461
+ };
462
+
463
+ //#endregion
464
+ //#region src/components/DatePicker/useDatePicker.ts
465
+ var isFullRange = range => {
466
+ return Boolean(range?.from && range?.to);
467
+ };
468
+ var isPartialRange = range => {
469
+ return Boolean(range?.from && !range?.to);
470
+ };
471
+ var resolveResetToSingleDay = ({
472
+ selected,
473
+ pickerSelection,
474
+ isResettingRange
475
+ }) => {
476
+ if (!isResettingRange || selected || !isPartialRange(pickerSelection)) return;
477
+ const day = pickerSelection.from;
478
+ return [{
479
+ kind: "commit",
480
+ range: {
481
+ from: day,
482
+ to: day
483
+ },
484
+ close: true
485
+ }];
486
+ };
487
+ var resolveRestartFromClickedDay = ({
488
+ selected,
489
+ date,
490
+ pickerSelection
491
+ }) => {
492
+ if (!isFullRange(date) || isPartialRange(pickerSelection) || !isFullRange(selected)) return;
493
+ return [{
494
+ kind: "edit",
495
+ selection: {
496
+ from: selected.from.getTime() === date.from.getTime() ? selected.to : selected.from,
497
+ to: void 0
498
+ }
499
+ }];
500
+ };
501
+ /**
502
+ * What a DayPicker `onSelect` means for the picker, given the committed range
503
+ * and the range being edited.
504
+ */
505
+ var resolveDayPickerSelect = args => {
506
+ const special = resolveResetToSingleDay(args) ?? resolveRestartFromClickedDay(args);
507
+ if (special) return special;
508
+ const {
509
+ selected
510
+ } = args;
511
+ const edit = {
512
+ kind: "edit",
513
+ selection: selected
514
+ };
515
+ if (isFullRange(selected)) return [edit, {
516
+ kind: "commit",
517
+ range: selected,
518
+ close: true
519
+ }];
520
+ if (!selected?.from && !selected?.to) return [edit, {
521
+ kind: "commit",
522
+ range: void 0,
523
+ close: false
524
+ }];
525
+ return [edit];
526
+ };
527
+ var useCloseOnClickOutside = ({
528
+ containerRef,
529
+ isOpen,
530
+ close
202
531
  }) => {
203
- const [date, setDate] = React.useState(value);
204
- const [pickerSelection, setPickerSelection] = React.useState(value);
205
- const [isOpen, setIsOpen] = React.useState(false);
206
- const containerRef = React.useRef(null);
207
- const isResettingRangeRef = React.useRef(false);
208
- React.useEffect(() => {
209
- setDate(value);
210
- }, [value]);
211
- React.useEffect(() => {
212
- if (isOpen) setPickerSelection(date);
213
- }, [isOpen, date]);
214
532
  React.useEffect(() => {
215
533
  const handleClickOutside = event => {
216
- if (containerRef.current && !containerRef.current.contains(event.target)) setIsOpen(false);
534
+ if (containerRef.current && !containerRef.current.contains(event.target)) close();
217
535
  };
218
536
  if (isOpen) document.addEventListener("mousedown", handleClickOutside);
219
537
  return () => {
220
538
  document.removeEventListener("mousedown", handleClickOutside);
221
539
  };
222
- }, [isOpen]);
540
+ }, [containerRef, isOpen, close]);
541
+ };
542
+ /**
543
+ * Selection state of the DatePicker: `date` is the committed range shown on
544
+ * the trigger, `pickerSelection` the range being edited while the calendar is
545
+ * open.
546
+ */
547
+ var useDatePicker = ({
548
+ value,
549
+ onChange,
550
+ containerRef
551
+ }) => {
552
+ const [date, setDate] = React.useState(value);
553
+ const [pickerSelection, setPickerSelection] = React.useState(value);
554
+ const [isOpen, setIsOpen] = React.useState(false);
555
+ const [prevValue, setPrevValue] = React.useState(value);
556
+ const isResettingRangeRef = React.useRef(false);
557
+ if (value !== prevValue) {
558
+ setPrevValue(value);
559
+ setDate(value);
560
+ if (isOpen) setPickerSelection(value);
561
+ }
562
+ const close = React.useCallback(() => {
563
+ setIsOpen(false);
564
+ }, []);
565
+ useCloseOnClickOutside({
566
+ containerRef,
567
+ isOpen,
568
+ close
569
+ });
570
+ const toggle = () => {
571
+ if (!isOpen) setPickerSelection(date);
572
+ setIsOpen(!isOpen);
573
+ };
223
574
  const commitSelection = range => {
224
575
  setDate(range);
225
576
  onChange?.(range);
226
577
  };
227
578
  const handlePresetClick = preset => {
228
579
  commitSelection(preset.getValue());
229
- setIsOpen(false);
580
+ close();
230
581
  };
231
582
  const handleDayPickerSelect = selected => {
232
- if (isResettingRangeRef.current && !selected && pickerSelection?.from && !pickerSelection?.to) {
233
- commitSelection({
234
- from: pickerSelection.from,
235
- to: pickerSelection.from
236
- });
237
- setIsOpen(false);
238
- return;
239
- }
583
+ const outcomes = resolveDayPickerSelect({
584
+ selected,
585
+ date,
586
+ pickerSelection,
587
+ isResettingRange: isResettingRangeRef.current
588
+ });
240
589
  isResettingRangeRef.current = false;
241
- const hadFullRange = date?.from && date?.to;
242
- const hadPartialPicker = pickerSelection?.from && !pickerSelection?.to;
243
- if (hadFullRange && !hadPartialPicker && selected?.from && selected?.to) {
244
- setPickerSelection({
245
- from: selected.from.getTime() === date?.from?.getTime() ? selected.to : selected.from,
246
- to: void 0
247
- });
248
- return;
590
+ for (const outcome of outcomes) {
591
+ if (outcome.kind === "edit") {
592
+ setPickerSelection(outcome.selection);
593
+ continue;
594
+ }
595
+ commitSelection(outcome.range);
596
+ if (outcome.close) close();
249
597
  }
250
- setPickerSelection(selected);
251
- if (selected?.from && selected?.to) {
252
- commitSelection(selected);
253
- setIsOpen(false);
254
- } else if (!selected?.from && !selected?.to) commitSelection(void 0);
255
598
  };
256
599
  const handleDayClick = day => {
257
- if (date?.from && date?.to) {
600
+ if (isFullRange(date)) {
258
601
  isResettingRangeRef.current = true;
259
602
  setPickerSelection({
260
603
  from: day,
@@ -262,6 +605,60 @@ var DatePicker = ({
262
605
  });
263
606
  }
264
607
  };
608
+ return {
609
+ date,
610
+ pickerSelection,
611
+ isOpen,
612
+ toggle,
613
+ close,
614
+ handlePresetClick,
615
+ handleDayPickerSelect,
616
+ handleDayClick
617
+ };
618
+ };
619
+
620
+ //#endregion
621
+ //#region src/components/DatePicker/DatePicker.tsx
622
+ var messages$4 = defineMessages({
623
+ selectPeriod: {
624
+ id: "Yvbvep",
625
+ defaultMessage: [{
626
+ "type": 0,
627
+ "value": "Select a period"
628
+ }]
629
+ }
630
+ });
631
+ var formatRange = ({
632
+ range,
633
+ formatDate
634
+ }) => {
635
+ if (!range.from) return;
636
+ if (!range.to) return formatDate(range.from);
637
+ return `${formatDate(range.from)} - ${formatDate(range.to)}`;
638
+ };
639
+ var DatePicker = ({
640
+ label,
641
+ value,
642
+ presets,
643
+ onChange,
644
+ disabled
645
+ }) => {
646
+ const {
647
+ intl
648
+ } = useI18n();
649
+ const containerRef = React.useRef(null);
650
+ const picker = useDatePicker({
651
+ value,
652
+ onChange,
653
+ containerRef
654
+ });
655
+ const selectPeriod = intl.formatMessage(messages$4.selectPeriod);
656
+ const rangeText = picker.date ? formatRange({
657
+ range: picker.date,
658
+ formatDate: date => {
659
+ return intl.formatDate(date);
660
+ }
661
+ }) : void 0;
265
662
  return /* @__PURE__ */jsxs(Flex, {
266
663
  ref: containerRef,
267
664
  sx: {
@@ -274,246 +671,27 @@ var DatePicker = ({
274
671
  }), /* @__PURE__ */jsx(Button, {
275
672
  disabled,
276
673
  variant: "secondary",
277
- onClick: () => {
278
- return setIsOpen(!isOpen);
279
- },
280
- sx: {
281
- width: "100%",
282
- justifyContent: "space-between",
283
- fontSize: ["14px", "14px"],
284
- fontWeight: 400,
285
- backgroundColor: "white",
286
- padding: "8px 12px",
287
- borderRadius: "lg",
288
- border: "md",
289
- borderColor: "display.border.muted.default",
290
- height: "40px",
291
- minWidth: ["auto", "240px"],
292
- "&:disabled": {
293
- borderColor: "display.border.muted.default"
294
- }
295
- },
296
- children: date?.from ? date.to ? /* @__PURE__ */jsxs(Text, {
297
- sx: {
298
- fontSize: ["12px", "14px"],
299
- overflow: "hidden",
300
- textOverflow: "ellipsis",
301
- whiteSpace: "nowrap"
302
- },
303
- children: [formatDate(date.from), " - ", formatDate(date.to)]
304
- }) : /* @__PURE__ */jsx(Text, {
305
- sx: {
306
- fontSize: ["12px", "14px"],
307
- overflow: "hidden",
308
- textOverflow: "ellipsis",
309
- whiteSpace: "nowrap"
310
- },
311
- children: formatDate(date.from)
674
+ onClick: picker.toggle,
675
+ sx: triggerSx,
676
+ children: rangeText ? /* @__PURE__ */jsx(Text, {
677
+ sx: triggerTextSx,
678
+ children: rangeText
312
679
  }) : /* @__PURE__ */jsx(Text, {
313
680
  sx: {
314
681
  fontSize: ["12px", "14px"]
315
682
  },
316
- children: "Selecione o período"
683
+ children: selectPeriod
317
684
  })
318
- }), isOpen && /* @__PURE__ */jsxs(Fragment, {
319
- children: [/* @__PURE__ */jsx(Box, {
320
- sx: {
321
- display: ["block", "none"],
322
- position: "fixed",
323
- top: 0,
324
- left: 0,
325
- right: 0,
326
- bottom: 0,
327
- backgroundColor: "rgba(0, 0, 0, 0.5)",
328
- zIndex: 49
329
- },
330
- onClick: () => {
331
- return setIsOpen(false);
332
- }
333
- }), /* @__PURE__ */jsxs(Box, {
334
- sx: {
335
- position: ["fixed", "absolute"],
336
- top: ["auto", "calc(100% + 4px)"],
337
- bottom: ["0", "auto"],
338
- left: ["0", "0"],
339
- right: ["0", "auto"],
340
- width: ["100%", "auto"],
341
- maxWidth: ["100%", "650px"],
342
- zIndex: 50,
343
- backgroundColor: "white",
344
- border: "1px solid",
345
- borderColor: "display.border.muted.default",
346
- borderRadius: ["16px 16px 0 0", "8px"],
347
- boxShadow: ["0 -4px 6px -1px rgba(0, 0, 0, 0.1)", "0 4px 6px -1px rgba(0, 0, 0, 0.1)"],
348
- overflow: "hidden",
349
- maxHeight: ["80vh", "none"],
350
- display: "flex",
351
- flexDirection: "column"
352
- },
353
- children: [/* @__PURE__ */jsxs(Flex, {
354
- sx: {
355
- display: ["flex", "none"],
356
- justifyContent: "space-between",
357
- alignItems: "center",
358
- padding: "12px 16px",
359
- borderBottom: "1px solid",
360
- borderColor: "display.border.muted.default"
361
- },
362
- children: [/* @__PURE__ */jsx(Text, {
363
- sx: {
364
- fontSize: "16px",
365
- fontWeight: 600
366
- },
367
- children: label || "Selecione o período"
368
- }), /* @__PURE__ */jsx(Button, {
369
- variant: "ghost",
370
- onClick: () => {
371
- return setIsOpen(false);
372
- },
373
- sx: {
374
- padding: "4px",
375
- minWidth: "auto",
376
- width: "32px",
377
- height: "32px"
378
- },
379
- children: /* @__PURE__ */jsx(Icon, {
380
- icon: "mdi:close",
381
- size: 20
382
- })
383
- })]
384
- }), /* @__PURE__ */jsxs(Flex, {
385
- sx: {
386
- minHeight: "300px",
387
- flexDirection: ["column", "row"],
388
- maxHeight: ["calc(80vh - 60px)", "none"],
389
- overflow: ["auto", "visible"]
390
- },
391
- children: [presets && presets.length > 0 && /* @__PURE__ */jsx(Flex, {
392
- sx: {
393
- flexDirection: ["row", "column"],
394
- gap: "4px",
395
- padding: ["8px", "12px"],
396
- borderRight: ["none", "1px solid"],
397
- borderBottom: ["1px solid", "none"],
398
- borderColor: "display.border.muted.default",
399
- backgroundColor: "navigation.background.muted.default",
400
- minWidth: ["auto", "140px"],
401
- width: ["100%", "auto"],
402
- overflowX: ["auto", "visible"],
403
- overflowY: ["visible", "auto"],
404
- flexWrap: ["nowrap", "wrap"],
405
- "@media (max-width: 768px)": {
406
- "&::-webkit-scrollbar": {
407
- display: "none"
408
- },
409
- scrollbarWidth: "none"
410
- }
411
- },
412
- children: presets?.map(preset => {
413
- return /* @__PURE__ */jsx(Button, {
414
- variant: "ghost",
415
- onClick: () => {
416
- return handlePresetClick(preset);
417
- },
418
- sx: {
419
- justifyContent: ["center", "flex-start"],
420
- fontSize: ["12px", "14px"],
421
- fontWeight: 400,
422
- padding: ["6px 8px", "8px 12px"],
423
- color: "display.text.secondary.default",
424
- backgroundColor: "transparent",
425
- whiteSpace: "nowrap",
426
- minWidth: ["auto", "auto"],
427
- flexShrink: 0,
428
- "&:hover": {
429
- backgroundColor: "input.background.muted.active"
430
- }
431
- },
432
- children: preset.label
433
- }, preset.label);
434
- })
435
- }), /* @__PURE__ */jsx(Box, {
436
- sx: {
437
- padding: ["12px", "16px"],
438
- flex: 1,
439
- overflow: "auto",
440
- "& .rdp": {
441
- margin: 0
442
- },
443
- "& .rdp-month": {
444
- width: "100%"
445
- },
446
- "& .rdp-day_button": {
447
- borderRadius: "50% !important",
448
- border: "none",
449
- fontSize: ["12px", "14px"],
450
- width: ["32px", "36px"],
451
- height: ["32px", "36px"],
452
- cursor: "pointer"
453
- },
454
- "& .rdp-range_start .rdp-day_button": {
455
- backgroundColor: "action.background.accent.default",
456
- color: "black"
457
- },
458
- "& .rdp-range_end .rdp-day_button": {
459
- backgroundColor: "action.background.accent.default",
460
- color: "black"
461
- },
462
- "& .rdp-day_button:hover": {
463
- backgroundColor: "action.background.primary.default",
464
- color: "action.text.primary.default"
465
- },
466
- "& .rdp-day_selected": {
467
- backgroundColor: "action.background.accent.default",
468
- color: "white",
469
- fontWeight: 600
470
- },
471
- "& .rdp-day_range_middle": {
472
- backgroundColor: "action.background.accent.default",
473
- color: "white"
474
- },
475
- "& .rdp-day_range_start, & .rdp-day_range_end": {
476
- backgroundColor: "action.background.accent.default",
477
- color: "white",
478
- fontWeight: 600
479
- },
480
- "& .rdp-weekday": {
481
- fontSize: ["10px", "12px"],
482
- fontWeight: 500,
483
- color: "display.text.muted.default"
484
- },
485
- "& .rdp-month_caption": {
486
- fontSize: ["12px", "14px"],
487
- fontWeight: 600,
488
- marginBottom: ["12px", "16px"]
489
- },
490
- "@media (max-width: 768px)": {
491
- "& .rdp-caption": {
492
- marginBottom: "8px"
493
- },
494
- "& .rdp-table": {
495
- width: "100%"
496
- }
497
- }
498
- },
499
- children: /* @__PURE__ */jsx(DayPicker, {
500
- disabled,
501
- mode: "range",
502
- locale: ptBR,
503
- selected: pickerSelection?.from ? {
504
- from: pickerSelection.from,
505
- to: pickerSelection.to ?? pickerSelection.from
506
- } : void 0,
507
- onSelect: selected => {
508
- return handleDayPickerSelect(selected);
509
- },
510
- onDayClick: handleDayClick,
511
- weekStartsOn: 1,
512
- showOutsideDays: true
513
- })
514
- })]
515
- })]
516
- })]
685
+ }), picker.isOpen && /* @__PURE__ */jsx(DatePickerPanel, {
686
+ title: label || selectPeriod,
687
+ presets,
688
+ pickerSelection: picker.pickerSelection,
689
+ dayPickerLocale: getDayPickerLocale(intl.locale),
690
+ disabled,
691
+ onClose: picker.close,
692
+ onPresetClick: picker.handlePresetClick,
693
+ onSelect: picker.handleDayPickerSelect,
694
+ onDayClick: picker.handleDayClick
517
695
  })]
518
696
  });
519
697
  };
@@ -59,6 +59,12 @@
59
59
  "value": "File Upload"
60
60
  }
61
61
  ],
62
+ "Yvbvep": [
63
+ {
64
+ "type": 0,
65
+ "value": "Select a period"
66
+ }
67
+ ],
62
68
  "dx4ZnR": [
63
69
  {
64
70
  "type": 1,
@@ -59,6 +59,12 @@
59
59
  "value": "Upload de Arquivo"
60
60
  }
61
61
  ],
62
+ "Yvbvep": [
63
+ {
64
+ "type": 0,
65
+ "value": "Selecione o período"
66
+ }
67
+ ],
62
68
  "dx4ZnR": [
63
69
  {
64
70
  "type": 0,
package/i18n/lang/en.json CHANGED
@@ -36,6 +36,10 @@
36
36
  "XKyo5X": {
37
37
  "defaultMessage": "File Upload"
38
38
  },
39
+ "Yvbvep": {
40
+ "defaultMessage": "Select a period",
41
+ "description": "Date range picker: placeholder when no range is selected, and the mobile panel title when there is no label."
42
+ },
39
43
  "dx4ZnR": {
40
44
  "defaultMessage": "{name} logo",
41
45
  "description": "OAuth consent: alt text for the requesting application logo."
@@ -39,6 +39,10 @@
39
39
  "defaultMessage": "Upload de Arquivo",
40
40
  "description": null
41
41
  },
42
+ "Yvbvep": {
43
+ "defaultMessage": "Selecione o período",
44
+ "description": "Date range picker: placeholder when no range is selected, and the mobile panel title when there is no label."
45
+ },
42
46
  "dx4ZnR": {
43
47
  "defaultMessage": "Logo de {name}",
44
48
  "description": "OAuth consent: alt text for the requesting application logo."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/components",
3
- "version": "2.21.2",
3
+ "version": "2.22.1",
4
4
  "description": "React components for ttoss ecosystem.",
5
5
  "keywords": [
6
6
  "React",
@@ -55,17 +55,17 @@
55
55
  "tsdown": "^0.22.2",
56
56
  "tsx": "^4.21.0",
57
57
  "@ttoss/config": "^1.39.1",
58
- "@ttoss/react-hooks": "^2.4.1",
59
58
  "@ttoss/i18n-cli": "^0.11.1",
60
- "@ttoss/react-i18n": "^2.5.2",
61
- "@ttoss/test-utils": "^4.3.1",
62
59
  "@ttoss/react-icons": "^0.10.1",
60
+ "@ttoss/react-i18n": "^2.5.3",
61
+ "@ttoss/react-hooks": "^2.4.1",
62
+ "@ttoss/test-utils": "^4.3.1",
63
63
  "@ttoss/ui": "^6.10.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "react": ">=16.8.0",
67
- "@ttoss/react-i18n": "^2.5.2",
68
67
  "@ttoss/react-hooks": "^2.4.1",
68
+ "@ttoss/react-i18n": "^2.5.3",
69
69
  "@ttoss/react-icons": "^0.10.1",
70
70
  "@ttoss/ui": "^6.10.2"
71
71
  },