@granto-umbrella/umbrella-components 3.0.24 → 3.0.27

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": "@granto-umbrella/umbrella-components",
3
- "version": "3.0.24",
3
+ "version": "3.0.27",
4
4
  "description": "Umbrella Components for React",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,19 +1,19 @@
1
1
  // DatePicker.styles.ts
2
- import { createGlobalStyle, styled } from "styled-components";
2
+ import { createGlobalStyle, styled } from 'styled-components';
3
3
  import ReactDatePicker, {
4
4
  DatePickerProps,
5
5
  registerLocale,
6
- } from "react-datepicker";
7
- import { ptBR } from "date-fns/locale";
6
+ } from 'react-datepicker';
7
+ import { ptBR } from 'date-fns/locale';
8
8
  import {
9
9
  semanticColors,
10
10
  semanticRadius,
11
11
  typographyTokens,
12
12
  semanticSizes,
13
- } from "../../../styles/tokens";
13
+ } from '../../../styles/tokens';
14
14
 
15
15
  // register Portuguese‐Brazil locale
16
- registerLocale("pt-BR", ptBR);
16
+ registerLocale('pt-BR', ptBR);
17
17
 
18
18
  // 1) Global overrides for the popup calendar:
19
19
  export const DatePickerGlobalStyles = createGlobalStyle`
@@ -61,10 +61,10 @@ export const StyledDatePicker = styled(
61
61
  ReactDatePicker as unknown as React.ComponentType<DatePickerProps>
62
62
  )`
63
63
  width: 100%;
64
- padding: ${semanticSizes.global.padding.sm} ${semanticSizes.global.padding.md};
64
+ padding: 0.65rem ${semanticSizes.global.padding.md};
65
65
  border: 1px solid ${semanticColors.neutral[300]};
66
66
  border-radius: ${semanticRadius.global.radius.md};
67
- font-size: ${typographyTokens.fontSizes.bodyM};
67
+ font-size: ${typographyTokens.fontSizes.bodyS};
68
68
  color: ${semanticColors.base.text};
69
69
 
70
70
  &:focus {
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React from "react";
3
- import { DatePickerGlobalStyles, StyledDatePicker } from "./DatePicker.styles";
4
-
5
- import "react-datepicker/dist/react-datepicker.css";
2
+ import React from 'react';
3
+ import { DatePickerGlobalStyles, StyledDatePicker } from './DatePicker.styles';
4
+ import 'react-datepicker/dist/react-datepicker.css';
5
+ import { parse, isValid, format } from 'date-fns';
6
6
 
7
7
  export interface DatePickerInputProps {
8
- mode?: "single" | "range";
8
+ mode?: 'single' | 'range';
9
9
  selected: Date | [Date, Date];
10
10
  onChange: (date: Date | [Date, Date]) => void;
11
11
  minDate?: Date;
@@ -14,44 +14,141 @@ export interface DatePickerInputProps {
14
14
  [key: string]: any;
15
15
  }
16
16
 
17
+ const DF = 'dd/MM/yyyy';
18
+
19
+ // ---------- helpers de parse/format ----------
20
+ function parseBRDate(s: string): Date | null {
21
+ const d = parse(s, DF, new Date());
22
+ return isValid(d) ? d : null;
23
+ }
24
+
25
+ function maskDateDigits(digits: string) {
26
+ let v = digits.replace(/\D/g, '').slice(0, 8);
27
+ if (v.length >= 5) v = v.replace(/^(\d{2})(\d{2})(\d{0,4}).*/, '$1/$2/$3');
28
+ else if (v.length >= 3) v = v.replace(/^(\d{2})(\d{0,2}).*/, '$1/$2');
29
+ return v;
30
+ }
31
+
32
+ function autoMaskSingle(input: string) {
33
+ const digits = input.replace(/\D/g, '');
34
+ return maskDateDigits(digits);
35
+ }
36
+
37
+ function autoMaskRange(input: string) {
38
+ const parts = input.split(/\s*[-–]\s*/);
39
+ const left = autoMaskSingle(parts[0] || '');
40
+ const right = autoMaskSingle(parts[1] || '');
41
+ return right ? `${left} - ${right}` : left;
42
+ }
43
+
44
+ function tryCommitSingle(value: string): Date | null {
45
+ return parseBRDate(value);
46
+ }
47
+
48
+ function tryCommitRange(value: string): [Date | null, Date | null] {
49
+ const [a, b] = value.split(/\s*[-–]\s*/);
50
+ return [a ? parseBRDate(a) : null, b ? parseBRDate(b) : null];
51
+ }
52
+
53
+ // Tipo que o StyledDatePicker espera em onChangeRaw
54
+ type RawEvt =
55
+ | React.MouseEvent<HTMLElement>
56
+ | React.KeyboardEvent<HTMLElement>
57
+ | undefined;
58
+
59
+ // Extrai com segurança o input do evento (alvo pode não ser input diretamente)
60
+ function getInputFromRawEvent(e: RawEvt): HTMLInputElement | null {
61
+ const target = e?.target as HTMLElement | undefined;
62
+ if (!target) return null;
63
+ if (target instanceof HTMLInputElement) return target;
64
+ const input = target.closest('input');
65
+ return (input as HTMLInputElement) || null;
66
+ }
67
+
17
68
  export const DatePickerInput: React.FC<DatePickerInputProps> = ({
18
- mode = "single",
69
+ mode = 'single',
19
70
  selected,
20
71
  onChange,
21
72
  minDate,
22
73
  maxDate,
23
74
  placeholder,
24
75
  ...rest
25
- }) => (
26
- <>
27
- {/* inject our calendar overrides */}
28
- <DatePickerGlobalStyles />
29
-
30
- {mode === "range" ? (
31
- <StyledDatePicker
32
- locale="pt-BR"
33
- selectsRange
34
- startDate={(selected as [Date, Date])[0] || undefined}
35
- endDate={(selected as [Date, Date])[1] || undefined}
36
- selected={(selected as [Date, Date])[0] || undefined}
37
- onChange={(d) => onChange(d as [Date, Date])}
38
- minDate={minDate}
39
- maxDate={maxDate}
40
- placeholderText={placeholder}
41
- dateFormat="dd/MM/yyyy"
42
- {...rest}
43
- />
44
- ) : (
45
- <StyledDatePicker
46
- locale="pt-BR"
47
- selected={selected as Date}
48
- onChange={(d) => onChange(d as Date)}
49
- minDate={minDate}
50
- maxDate={maxDate}
51
- placeholderText={placeholder}
52
- dateFormat="dd/MM/yyyy"
53
- {...rest}
54
- />
55
- )}
56
- </>
57
- );
76
+ }) => {
77
+ // SINGLE
78
+ const handleChangeRawSingle = (e: RawEvt) => {
79
+ const el = getInputFromRawEvent(e);
80
+ if (!el) return;
81
+ el.value = autoMaskSingle(el.value);
82
+ };
83
+
84
+ const handleBlurSingle = (e: React.FocusEvent<HTMLInputElement>) => {
85
+ const el = e.target;
86
+ const d = tryCommitSingle(el.value);
87
+ if (d) {
88
+ el.value = format(d, DF);
89
+ onChange(d);
90
+ }
91
+ };
92
+
93
+ // RANGE
94
+ const handleChangeRawRange = (e: RawEvt) => {
95
+ const el = getInputFromRawEvent(e);
96
+ if (!el) return;
97
+ el.value = autoMaskRange(el.value);
98
+ };
99
+
100
+ const handleBlurRange = (e: React.FocusEvent<HTMLInputElement>) => {
101
+ const el = e.target;
102
+ const [d1, d2] = tryCommitRange(el.value);
103
+
104
+ if (d1) {
105
+ const oldRight = Array.isArray(selected) ? selected[1] : undefined;
106
+ const payload: [Date, Date] = [d1, (d2 || (oldRight as Date)) as Date];
107
+ const left = format(d1, DF);
108
+ const right = d2 ? format(d2, DF) : '';
109
+ el.value = right ? `${left} - ${right}` : left;
110
+ onChange(payload);
111
+ }
112
+ };
113
+
114
+ return (
115
+ <>
116
+ <DatePickerGlobalStyles />
117
+
118
+ {mode === 'range' ? (
119
+ <StyledDatePicker
120
+ locale="pt-BR"
121
+ selectsRange
122
+ startDate={(selected as [Date, Date])[0] || undefined}
123
+ endDate={(selected as [Date, Date])[1] || undefined}
124
+ selected={(selected as [Date, Date])[0] || undefined}
125
+ onChange={(d) => onChange(d as [Date, Date])}
126
+ minDate={minDate}
127
+ maxDate={maxDate}
128
+ placeholderText={placeholder}
129
+ dateFormat={DF}
130
+ onChangeRaw={handleChangeRawRange} // << tipo compatível
131
+ onBlur={handleBlurRange}
132
+ {...rest}
133
+ />
134
+ ) : (
135
+ <StyledDatePicker
136
+ locale="pt-BR"
137
+ selected={
138
+ Array.isArray(selected)
139
+ ? selected[0]
140
+ : (selected as Date) || undefined
141
+ }
142
+ onChange={(d) => onChange(d as Date)}
143
+ minDate={minDate}
144
+ maxDate={maxDate}
145
+ placeholderText={placeholder}
146
+ dateFormat={DF}
147
+ onChangeRaw={handleChangeRawSingle} // << tipo compatível
148
+ onBlur={handleBlurSingle}
149
+ {...rest}
150
+ />
151
+ )}
152
+ </>
153
+ );
154
+ };
@@ -7,6 +7,7 @@ import {
7
7
  typographyTokens,
8
8
  semanticBorders
9
9
  } from "../../../styles/tokens";
10
+ import { semanticColors } from "@granto-umbrella/umbrella-components";
10
11
 
11
12
  export const Wrapper = styled.div`
12
13
  position: fixed;
@@ -16,9 +17,9 @@ export const Wrapper = styled.div`
16
17
  `;
17
18
 
18
19
  export const Container = styled.div`
19
- background-color: ${primitiveColors.purple[100]};
20
+ background-color: ${semanticColors.info.surface.feedback};
20
21
  border-radius: ${semanticRadius.global.radius.md2};
21
- border: ${semanticBorders.global.md} solid ${primitiveColors.purple[1200]};
22
+ border: ${semanticBorders.global.md} solid ${semanticColors.info.border.feedback};
22
23
  padding: ${semanticSizes.global.padding.md} ${semanticSizes.global.padding.lg};
23
24
  display: flex;
24
25
  align-items: start;
@@ -32,7 +33,7 @@ export const Content = styled.div`
32
33
  `;
33
34
 
34
35
  export const Title = styled.p`
35
- color: ${primitiveColors.gray[1100]};
36
+ color: ${semanticColors.info.text.feedback.strong};
36
37
  font-weight: ${typographyTokens.fontWeights.semibold};
37
38
  font-size: ${typographyTokens.fontSizes.bodyM};
38
39
  margin: 0 0 ${semanticSizes.global.gap.xs} 0;