@mezzanine-ui/react 0.14.4 → 0.14.6
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/DateRangePicker/DateRangePicker.js +1 -0
- package/DateRangePicker/useDateRangePickerValue.d.ts +7 -2
- package/DateRangePicker/useDateRangePickerValue.js +12 -2
- package/Picker/useRangePickerValue.d.ts +4 -1
- package/Picker/useRangePickerValue.js +11 -6
- package/Select/Select.js +2 -2
- package/Typography/Typography.d.ts +5 -1
- package/Typography/Typography.js +8 -2
- package/Typography/index.d.ts +1 -1
- package/_internal/InputTriggerPopper/InputTriggerPopper.js +3 -1
- package/package.json +4 -4
|
@@ -2,16 +2,21 @@ import { DateType } from '@mezzanine-ui/core/calendar';
|
|
|
2
2
|
import { RangePickerPickingValue, RangePickerValue } from '@mezzanine-ui/core/picker';
|
|
3
3
|
import { ChangeEventHandler, KeyboardEventHandler } from 'react';
|
|
4
4
|
import { UseRangePickerValueProps } from '../Picker/useRangePickerValue';
|
|
5
|
+
import { DateRangePickerCalendarProps } from './DateRangePickerCalendar';
|
|
5
6
|
export interface UseDateRangePickerValueProps extends Omit<UseRangePickerValueProps, 'onChange'> {
|
|
7
|
+
mode?: DateRangePickerCalendarProps['mode'];
|
|
6
8
|
onChange?: (value?: RangePickerValue) => void;
|
|
7
9
|
}
|
|
8
|
-
export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
|
|
10
|
+
export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
|
|
9
11
|
calendarValue: string[] | undefined;
|
|
10
12
|
inputFromValue: string;
|
|
11
13
|
inputToValue: string;
|
|
12
14
|
onCalendarChange: (val?: DateType) => void;
|
|
13
15
|
onCalendarHover: import("react").Dispatch<import("react").SetStateAction<string | undefined>> | undefined;
|
|
14
|
-
onChange: (target?: RangePickerPickingValue | undefined
|
|
16
|
+
onChange: (target?: RangePickerPickingValue | undefined, callback?: {
|
|
17
|
+
from: (date?: string | undefined) => string | undefined;
|
|
18
|
+
to: (date?: string | undefined) => string | undefined;
|
|
19
|
+
}) => RangePickerPickingValue | undefined;
|
|
15
20
|
onClear: () => void;
|
|
16
21
|
onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
|
|
17
22
|
onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useState, useMemo } from 'react';
|
|
2
2
|
import { useRangePickerValue } from '../Picker/useRangePickerValue.js';
|
|
3
|
+
import { useCalendarContext } from '../Calendar/CalendarContext.js';
|
|
3
4
|
|
|
4
|
-
function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }) {
|
|
5
|
+
function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }) {
|
|
6
|
+
const { addDay, } = useCalendarContext();
|
|
5
7
|
const { inputFromValue, inputToValue, onChange, onFromBlur, onFromKeyDown, onInputFromChange, onInputToChange, onToBlur, onToKeyDown, value, } = useRangePickerValue({
|
|
6
8
|
format,
|
|
7
9
|
formats,
|
|
@@ -25,7 +27,15 @@ function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, on
|
|
|
25
27
|
? [val, undefined]
|
|
26
28
|
: [firstVal, val];
|
|
27
29
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
|
-
const [sortedFrom, sortedTo] = onChange(newValue
|
|
30
|
+
const [sortedFrom, sortedTo] = onChange(newValue, {
|
|
31
|
+
from: (nextFrom) => nextFrom,
|
|
32
|
+
to: (nextTo) => {
|
|
33
|
+
if (!nextTo)
|
|
34
|
+
return nextTo;
|
|
35
|
+
/** week mode should use the last day of the week (default is the first day) */
|
|
36
|
+
return mode === 'week' ? addDay(nextTo, 6) : nextTo;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
29
39
|
if (sortedFrom && sortedTo) {
|
|
30
40
|
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([sortedFrom, sortedTo]);
|
|
31
41
|
}
|
|
@@ -9,7 +9,10 @@ export interface UseRangePickerValueProps extends Pick<UsePickerValueProps, 'for
|
|
|
9
9
|
export declare function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value: valueProp, }: UseRangePickerValueProps): {
|
|
10
10
|
inputFromValue: string;
|
|
11
11
|
inputToValue: string;
|
|
12
|
-
onChange: (target?: RangePickerPickingValue
|
|
12
|
+
onChange: (target?: RangePickerPickingValue, callback?: {
|
|
13
|
+
from: (date?: string) => string | undefined;
|
|
14
|
+
to: (date?: string) => string | undefined;
|
|
15
|
+
}) => RangePickerPickingValue | undefined;
|
|
13
16
|
onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
|
|
14
17
|
onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
|
|
15
18
|
onInputFromChange: ChangeEventHandler<HTMLInputElement>;
|
|
@@ -23,16 +23,21 @@ function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value:
|
|
|
23
23
|
inputRef: inputToRef,
|
|
24
24
|
});
|
|
25
25
|
const value = [from, to];
|
|
26
|
-
const onChange = (target
|
|
26
|
+
const onChange = (target, callback = {
|
|
27
|
+
from: (date) => date,
|
|
28
|
+
to: (date) => date,
|
|
29
|
+
}) => {
|
|
27
30
|
const [newFrom, newTo] = target || [];
|
|
28
31
|
if (newFrom && newTo) {
|
|
29
32
|
const sortedVal = sortValues([newFrom, newTo]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const resolvedFrom = callback.from(sortedVal[0]);
|
|
34
|
+
const resolvedTo = callback.to(sortedVal[1]);
|
|
35
|
+
onFromChange(resolvedFrom);
|
|
36
|
+
onToChange(resolvedTo);
|
|
37
|
+
return [resolvedFrom, resolvedTo];
|
|
33
38
|
}
|
|
34
|
-
onFromChange(target === null || target === void 0 ? void 0 : target[0]);
|
|
35
|
-
onToChange(target === null || target === void 0 ? void 0 : target[1]);
|
|
39
|
+
onFromChange(callback.from(target === null || target === void 0 ? void 0 : target[0]));
|
|
40
|
+
onToChange(callback.to(target === null || target === void 0 ? void 0 : target[1]));
|
|
36
41
|
return target;
|
|
37
42
|
};
|
|
38
43
|
const onOrderGuardedInputFromChange = (event) => {
|
package/Select/Select.js
CHANGED
|
@@ -44,7 +44,6 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
44
44
|
});
|
|
45
45
|
const nodeRef = useRef(null);
|
|
46
46
|
const controlRef = useRef(null);
|
|
47
|
-
const popperRef = useRef(null);
|
|
48
47
|
const composedRef = useComposeRefs([ref, controlRef]);
|
|
49
48
|
function getPlaceholder() {
|
|
50
49
|
if (typeof renderValue === 'function') {
|
|
@@ -100,6 +99,7 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
100
99
|
};
|
|
101
100
|
/** menu onScroll listener */
|
|
102
101
|
const onMenuScrollCallback = useCallback(async (evt) => {
|
|
102
|
+
evt.stopPropagation();
|
|
103
103
|
if (onMenuScroll) {
|
|
104
104
|
const target = evt.target;
|
|
105
105
|
const maxScrollTop = target.scrollHeight - target.getBoundingClientRect().height;
|
|
@@ -121,7 +121,7 @@ const Select = forwardRef(function Select(props, ref) {
|
|
|
121
121
|
onChange,
|
|
122
122
|
value,
|
|
123
123
|
}), [onChange, value]);
|
|
124
|
-
return (jsx(SelectControlContext.Provider, { value: context, children: jsxs("div", { ref: nodeRef, className: cx(selectClasses.host, fullWidth && selectClasses.hostFullWidth), children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, inputRef: inputRef, mode: mode, onTagClose: onChange, onClear: onClear, onClick: onClickTextField, onKeyDown: onKeyDownTextField, prefix: prefix, readOnly: true, renderValue: renderValue, required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: suffixActionIcon, value: value }), jsx(InputTriggerPopper, {
|
|
124
|
+
return (jsx(SelectControlContext.Provider, { value: context, children: jsxs("div", { ref: nodeRef, className: cx(selectClasses.host, fullWidth && selectClasses.hostFullWidth), children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, inputRef: inputRef, mode: mode, onTagClose: onChange, onClear: onClear, onClick: onClickTextField, onKeyDown: onKeyDownTextField, prefix: prefix, readOnly: true, renderValue: renderValue, required: required, inputProps: resolvedInputProps, size: size, suffixActionIcon: suffixActionIcon, value: value }), jsx(InputTriggerPopper, { anchor: controlRef, className: selectClasses.popper, disablePortal: disablePortal, open: open, options: popperOptions, sameWidth: true, children: jsx(Menu, { id: MENU_ID, "aria-activedescendant": Array.isArray(value) ? (_b = (_a = value === null || value === void 0 ? void 0 : value[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '' : value === null || value === void 0 ? void 0 : value.id, itemsInView: itemsInView, maxHeight: menuMaxHeight, onScroll: onMenuScrollCallback, role: menuRole, size: menuSize, style: { border: 0 }, children: children }) })] }) }));
|
|
125
125
|
});
|
|
126
126
|
var Select$1 = Select;
|
|
127
127
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSXElementConstructor } from 'react';
|
|
2
|
-
import { TypographyAlign, TypographyColor, TypographyDisplay, TypographyVariant } from '@mezzanine-ui/core/typography';
|
|
2
|
+
import { TypographyAlign, TypographyColor, TypographyDisplay, TypographyVariant, TypographyWeight } from '@mezzanine-ui/core/typography';
|
|
3
3
|
import { ComponentOverridableForwardRefComponentPropsFactory } from '../utils/jsx-types';
|
|
4
4
|
export type TypographyComponent = `h${1 | 2 | 3 | 4 | 5 | 6}` | 'p' | 'span' | 'label' | 'div' | 'caption' | 'a' | JSXElementConstructor<any>;
|
|
5
5
|
interface TypographyPropsBase {
|
|
@@ -32,6 +32,10 @@ interface TypographyPropsBase {
|
|
|
32
32
|
* @default 'body1'
|
|
33
33
|
*/
|
|
34
34
|
variant?: TypographyVariant;
|
|
35
|
+
/**
|
|
36
|
+
* The css variable for customizing `font-weight`.
|
|
37
|
+
*/
|
|
38
|
+
weight?: TypographyWeight;
|
|
35
39
|
}
|
|
36
40
|
export type TypographyProps<C extends TypographyComponent = 'p'> = ComponentOverridableForwardRefComponentPropsFactory<TypographyComponent, C, TypographyPropsBase>;
|
|
37
41
|
/**
|
package/Typography/Typography.js
CHANGED
|
@@ -16,9 +16,14 @@ function getComponentFromVariant(variant) {
|
|
|
16
16
|
* The react component for `mezzanine` typography.
|
|
17
17
|
*/
|
|
18
18
|
const Typography = forwardRef(function Typography(props, ref) {
|
|
19
|
-
const { align, children, className, color, component, display, ellipsis = false, noWrap = false, variant = 'body1', style: styleProp, ...rest } = props;
|
|
19
|
+
const { align, children, className, color, component, display, ellipsis = false, noWrap = false, variant = 'body1', style: styleProp, weight, ...rest } = props;
|
|
20
20
|
const Component = component || getComponentFromVariant(variant);
|
|
21
|
-
const cssVars = toTypographyCssVars({
|
|
21
|
+
const cssVars = toTypographyCssVars({
|
|
22
|
+
align,
|
|
23
|
+
color,
|
|
24
|
+
display,
|
|
25
|
+
weight,
|
|
26
|
+
});
|
|
22
27
|
const style = {
|
|
23
28
|
...cssVars,
|
|
24
29
|
...styleProp,
|
|
@@ -32,6 +37,7 @@ const Typography = forwardRef(function Typography(props, ref) {
|
|
|
32
37
|
[typographyClasses.display]: display,
|
|
33
38
|
[typographyClasses.ellipsis]: ellipsis,
|
|
34
39
|
[typographyClasses.noWrap]: noWrap,
|
|
40
|
+
[typographyClasses.weight]: weight,
|
|
35
41
|
}, className), style: style, title: title, children: children }));
|
|
36
42
|
});
|
|
37
43
|
var Typography$1 = Typography;
|
package/Typography/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ElementRef, PropsWithoutRef, ReactElement, RefAttributes } from 'react';
|
|
2
2
|
import { TypographyComponent, TypographyProps } from './Typography';
|
|
3
|
-
export type { TypographyAlign, TypographyColor, TypographyDisplay, TypographyVariant, } from '@mezzanine-ui/core/typography';
|
|
3
|
+
export type { TypographyAlign, TypographyColor, TypographyDisplay, TypographyVariant, TypographyWeight, } from '@mezzanine-ui/core/typography';
|
|
4
4
|
export type { TypographyComponent, TypographyProps, };
|
|
5
5
|
/**
|
|
6
6
|
* @remark
|
|
@@ -25,7 +25,9 @@ const InputTriggerPopper = forwardRef(function InputTriggerPopper(props, ref) {
|
|
|
25
25
|
reassignState.elements.popper.style.minWidth = `${state.elements.reference.getBoundingClientRect().width}px`;
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
|
-
return (jsx(Fade, { ...fadeProps, in: open, ref: ref, children: jsx(Popper, { ...restPopperProps, open: true, anchor: anchor, className: cx(inputTriggerPopperClasses.host, className),
|
|
28
|
+
return (jsx(Fade, { ...fadeProps, in: open, ref: ref, children: jsx(Popper, { ...restPopperProps, open: true, anchor: anchor, className: cx(inputTriggerPopperClasses.host, className),
|
|
29
|
+
/** Prevent event bubble (Because popper may use portal, then click away function would be buggy) */
|
|
30
|
+
onClick: (e) => e.stopPropagation(), onTouchStart: (e) => e.stopPropagation(), onTouchMove: (e) => e.stopPropagation(), onTouchEnd: (e) => e.stopPropagation(), options: {
|
|
29
31
|
placement: 'bottom-start',
|
|
30
32
|
...restPopperOptions,
|
|
31
33
|
modifiers: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.6",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"react-dom": "^18.2.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mezzanine-ui/core": "^0.14.
|
|
32
|
-
"@mezzanine-ui/icons": "^0.14.
|
|
33
|
-
"@mezzanine-ui/system": "^0.14.
|
|
31
|
+
"@mezzanine-ui/core": "^0.14.6",
|
|
32
|
+
"@mezzanine-ui/icons": "^0.14.6",
|
|
33
|
+
"@mezzanine-ui/system": "^0.14.6",
|
|
34
34
|
"@popperjs/core": "^2.11.6",
|
|
35
35
|
"@types/react-transition-group": "^4.4.8",
|
|
36
36
|
"clsx": "^2.0.0",
|