@lumx/react 3.9.2-alpha.8 → 3.9.2
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/index.d.ts +2 -0
- package/index.js +58 -32
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/date-picker/DatePickerControlled.tsx +52 -30
- package/src/components/popover/Popover.tsx +2 -2
- package/src/components/popover/constants.ts +5 -0
- package/src/components/text-field/TextField.tsx +3 -1
- package/src/components/tooltip/Tooltip.tsx +15 -4
- package/src/components/tooltip/constants.ts +7 -0
- package/src/stories/generated/TextField/Demos.stories.tsx +1 -0
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.9.2
|
|
10
|
-
"@lumx/icons": "^3.9.2
|
|
9
|
+
"@lumx/core": "^3.9.2",
|
|
10
|
+
"@lumx/icons": "^3.9.2",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"build:storybook": "storybook build"
|
|
111
111
|
},
|
|
112
112
|
"sideEffects": false,
|
|
113
|
-
"version": "3.9.2
|
|
113
|
+
"version": "3.9.2"
|
|
114
114
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { KeyboardEventHandler, forwardRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import { DatePickerProps, Emphasis, FlexBox, IconButton, Text, TextField, Toolbar } from '@lumx/react';
|
|
3
|
+
import { DatePickerProps, Emphasis, FlexBox, IconButton, Text, TextField, TextFieldProps, Toolbar } from '@lumx/react';
|
|
4
4
|
import { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';
|
|
5
5
|
import { Comp } from '@lumx/react/utils/type';
|
|
6
6
|
import { getMonthCalendar } from '@lumx/react/utils/date/getMonthCalendar';
|
|
@@ -61,36 +61,58 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
61
61
|
return getMonthCalendar(localeObj, selectedMonth, minDate, maxDate);
|
|
62
62
|
}, [locale, minDate, maxDate, selectedMonth]);
|
|
63
63
|
|
|
64
|
-
const selectedYear = selectedMonth.
|
|
65
|
-
const
|
|
66
|
-
const
|
|
64
|
+
const selectedYear = selectedMonth.getFullYear();
|
|
65
|
+
const formattedYear = selectedMonth.toLocaleDateString(locale, { year: 'numeric' }).slice(0, 4);
|
|
66
|
+
const [currentYear, setCurrentYear] = React.useState(String(selectedYear));
|
|
67
67
|
|
|
68
68
|
// Updates month offset when validating year. Adds or removes 12 months per year when updating year value.
|
|
69
|
-
const updateMonthOffset = React.useCallback(
|
|
70
|
-
|
|
71
|
-
const yearNumber =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
onMonthChange(addMonthResetDay(selectedMonth, offset));
|
|
69
|
+
const updateMonthOffset = React.useCallback(
|
|
70
|
+
(newYearValue: string) => {
|
|
71
|
+
const yearNumber = Number(newYearValue);
|
|
72
|
+
if (yearNumber < 0 && yearNumber >= 9999) {
|
|
73
|
+
return;
|
|
75
74
|
}
|
|
76
|
-
}
|
|
77
|
-
}, [isYearValid, selectedMonth, textFieldYearValue, onMonthChange]);
|
|
78
75
|
|
|
79
|
-
|
|
76
|
+
const previousYearNumber = selectedMonth.getFullYear();
|
|
77
|
+
const offset = (yearNumber - previousYearNumber) * 12;
|
|
78
|
+
onMonthChange?.(addMonthResetDay(selectedMonth, offset));
|
|
79
|
+
},
|
|
80
|
+
[selectedMonth, onMonthChange],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const onYearChange = React.useCallback<TextFieldProps['onChange']>(
|
|
84
|
+
(newYearValue, _, event) => {
|
|
85
|
+
setCurrentYear(newYearValue);
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
// Detect if change is coming from the spin up/down arrows
|
|
88
|
+
const inputType = (event?.nativeEvent as any)?.inputType;
|
|
89
|
+
if (
|
|
90
|
+
// Chrome/Safari
|
|
91
|
+
!inputType ||
|
|
92
|
+
// Firefox
|
|
93
|
+
inputType === 'insertReplacementText'
|
|
94
|
+
) {
|
|
95
|
+
updateMonthOffset(newYearValue);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
84
98
|
[updateMonthOffset],
|
|
85
99
|
);
|
|
86
100
|
|
|
87
|
-
|
|
101
|
+
const updateYear = React.useCallback(() => {
|
|
102
|
+
updateMonthOffset(currentYear);
|
|
103
|
+
}, [updateMonthOffset, currentYear]);
|
|
104
|
+
|
|
105
|
+
const updateYearOnEnterPressed: KeyboardEventHandler = React.useMemo(
|
|
106
|
+
() => onEnterPressed(updateYear),
|
|
107
|
+
[updateYear],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const monthYear = selectedMonth.toLocaleDateString(locale, { year: 'numeric', month: 'long' });
|
|
111
|
+
|
|
112
|
+
// Update current year when selected year changes
|
|
88
113
|
React.useEffect(() => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
-
}, [selectedMonth]);
|
|
114
|
+
setCurrentYear(String(selectedYear));
|
|
115
|
+
}, [selectedYear]);
|
|
94
116
|
|
|
95
117
|
const prevSelectedMonth = usePreviousValue(selectedMonth);
|
|
96
118
|
const monthHasChanged = prevSelectedMonth && !isSameDay(selectedMonth, prevSelectedMonth);
|
|
@@ -101,7 +123,7 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
101
123
|
if (monthHasChanged) setLabelAriaLive('polite');
|
|
102
124
|
}, [monthHasChanged]);
|
|
103
125
|
|
|
104
|
-
const
|
|
126
|
+
const yearLabel = getYearDisplayName(locale);
|
|
105
127
|
|
|
106
128
|
return (
|
|
107
129
|
<div ref={ref} className={`${CLASSNAME}`}>
|
|
@@ -137,21 +159,21 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
137
159
|
vAlign="center"
|
|
138
160
|
dir="auto"
|
|
139
161
|
>
|
|
140
|
-
{RegExp(`(.*)(${
|
|
162
|
+
{RegExp(`(.*)(${formattedYear})(.*)`)
|
|
141
163
|
.exec(monthYear)
|
|
142
164
|
?.slice(1)
|
|
143
165
|
.filter((part) => part !== '')
|
|
144
166
|
.map((part) =>
|
|
145
|
-
part ===
|
|
167
|
+
part === formattedYear ? (
|
|
146
168
|
<TextField
|
|
147
|
-
value={
|
|
148
|
-
aria-label={
|
|
149
|
-
onChange={
|
|
169
|
+
value={currentYear}
|
|
170
|
+
aria-label={yearLabel}
|
|
171
|
+
onChange={onYearChange}
|
|
150
172
|
type="number"
|
|
151
173
|
max={9999}
|
|
152
174
|
min={0}
|
|
153
|
-
onBlur={
|
|
154
|
-
onKeyPress={
|
|
175
|
+
onBlur={updateYear}
|
|
176
|
+
onKeyPress={updateYearOnEnterPressed}
|
|
155
177
|
key="year"
|
|
156
178
|
className={`${CLASSNAME}__year`}
|
|
157
179
|
/>
|
|
@@ -15,7 +15,7 @@ import { skipRender } from '@lumx/react/utils/skipRender';
|
|
|
15
15
|
|
|
16
16
|
import { useRestoreFocusOnClose } from './useRestoreFocusOnClose';
|
|
17
17
|
import { usePopoverStyle } from './usePopoverStyle';
|
|
18
|
-
import { Elevation, FitAnchorWidth, Offset, Placement } from './constants';
|
|
18
|
+
import { Elevation, FitAnchorWidth, Offset, Placement, POPOVER_ZINDEX } from './constants';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Defines the props of the component.
|
|
@@ -88,7 +88,7 @@ const DEFAULT_PROPS: Partial<PopoverProps> = {
|
|
|
88
88
|
placement: Placement.AUTO,
|
|
89
89
|
focusAnchorOnClose: true,
|
|
90
90
|
usePortal: true,
|
|
91
|
-
zIndex:
|
|
91
|
+
zIndex: POPOVER_ZINDEX,
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/** Method to render the popover inside a portal if usePortal is true */
|
|
@@ -68,6 +68,8 @@ export interface TextFieldProps extends GenericProps, HasTheme {
|
|
|
68
68
|
placeholder?: string;
|
|
69
69
|
/** Reference to the wrapper. */
|
|
70
70
|
textFieldRef?: Ref<HTMLDivElement>;
|
|
71
|
+
/** Native input type (only when `multiline` is disabled). */
|
|
72
|
+
type?: React.ComponentProps<'input'>['type'];
|
|
71
73
|
/** Value. */
|
|
72
74
|
value?: string;
|
|
73
75
|
/** On blur callback. */
|
|
@@ -160,7 +162,7 @@ interface InputNativeProps {
|
|
|
160
162
|
maxLength?: number;
|
|
161
163
|
placeholder?: string;
|
|
162
164
|
rows: number;
|
|
163
|
-
type:
|
|
165
|
+
type: TextFieldProps['type'];
|
|
164
166
|
name?: string;
|
|
165
167
|
value?: string;
|
|
166
168
|
setFocus(focus: boolean): void;
|
|
@@ -13,7 +13,7 @@ import { TooltipContextProvider } from '@lumx/react/components/tooltip/context';
|
|
|
13
13
|
import { useId } from '@lumx/react/hooks/useId';
|
|
14
14
|
import { usePopper } from '@lumx/react/hooks/usePopper';
|
|
15
15
|
|
|
16
|
-
import { ARIA_LINK_MODES } from '@lumx/react/components/tooltip/constants';
|
|
16
|
+
import { ARIA_LINK_MODES, TOOLTIP_ZINDEX } from '@lumx/react/components/tooltip/constants';
|
|
17
17
|
import { useInjectTooltipRef } from './useInjectTooltipRef';
|
|
18
18
|
import { useTooltipOpen } from './useTooltipOpen';
|
|
19
19
|
|
|
@@ -55,6 +55,7 @@ const DEFAULT_PROPS: Partial<TooltipProps> = {
|
|
|
55
55
|
placement: Placement.BOTTOM,
|
|
56
56
|
closeMode: 'unmount',
|
|
57
57
|
ariaLinkMode: 'aria-describedby',
|
|
58
|
+
zIndex: TOOLTIP_ZINDEX,
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
/**
|
|
@@ -70,8 +71,18 @@ const ARROW_SIZE = 8;
|
|
|
70
71
|
* @return React element.
|
|
71
72
|
*/
|
|
72
73
|
export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, ref) => {
|
|
73
|
-
const {
|
|
74
|
-
|
|
74
|
+
const {
|
|
75
|
+
label,
|
|
76
|
+
children,
|
|
77
|
+
className,
|
|
78
|
+
delay,
|
|
79
|
+
placement,
|
|
80
|
+
forceOpen,
|
|
81
|
+
closeMode,
|
|
82
|
+
ariaLinkMode,
|
|
83
|
+
zIndex,
|
|
84
|
+
...forwardedProps
|
|
85
|
+
} = props;
|
|
75
86
|
// Disable in SSR.
|
|
76
87
|
if (!DOCUMENT) {
|
|
77
88
|
return <>{children}</>;
|
|
@@ -131,7 +142,7 @@ export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, re
|
|
|
131
142
|
hidden: !isOpen && closeMode === 'hide',
|
|
132
143
|
}),
|
|
133
144
|
)}
|
|
134
|
-
style={styles.popper}
|
|
145
|
+
style={{ ...styles.popper, zIndex }}
|
|
135
146
|
{...attributes.popper}
|
|
136
147
|
>
|
|
137
148
|
<div className={`${CLASSNAME}__arrow`} />
|
|
@@ -10,6 +10,7 @@ export { App as Disabled } from './disabled';
|
|
|
10
10
|
export { App as Helper } from './helper';
|
|
11
11
|
export { App as Icon } from './icon';
|
|
12
12
|
export { App as Invalid } from './invalid';
|
|
13
|
+
export { App as Number } from './number';
|
|
13
14
|
export { App as Placeholder } from './placeholder';
|
|
14
15
|
export { App as Required } from './required';
|
|
15
16
|
export { App as TextAreaInvalid } from './text-area-invalid';
|