@indico-data/design-system 1.0.53 → 1.0.54
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/lib/components/Icon/Icon.d.ts +1 -0
- package/lib/components/Icon/Icon.stories.d.ts +2 -0
- package/lib/components/inputs/NoInputDatePicker/NoInputDatePicker.d.ts +2 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +38 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +38 -10
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Icon/Icon.tsx +2 -0
- package/src/components/inputs/NoInputDatePicker/NoInputDatePicker.stories.tsx +1 -0
- package/src/components/inputs/NoInputDatePicker/NoInputDatePicker.tsx +51 -9
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { StoryObj } from '@storybook/react';
|
|
2
3
|
import { Icon } from './Icon';
|
|
3
4
|
declare const meta: {
|
|
@@ -30,6 +31,7 @@ declare const meta: {
|
|
|
30
31
|
size?: [string | number] | [string | number, string | number] | undefined;
|
|
31
32
|
style?: any;
|
|
32
33
|
onClick?: (() => void) | undefined;
|
|
34
|
+
ref?: React.Ref<SVGSVGElement> | undefined;
|
|
33
35
|
}>) => import("react/jsx-runtime").JSX.Element)[];
|
|
34
36
|
};
|
|
35
37
|
export default meta;
|
|
@@ -9,11 +9,13 @@ type Props = PermafrostComponent & {
|
|
|
9
9
|
label?: string;
|
|
10
10
|
onChange: (value: Date | DateRange | undefined) => void;
|
|
11
11
|
selected?: Date | undefined;
|
|
12
|
+
selectedRange?: DateRange | undefined;
|
|
12
13
|
value: Date | undefined;
|
|
13
14
|
triggerIcon: IconName;
|
|
14
15
|
triggerIconSize: [string | number];
|
|
15
16
|
isRangePicker?: boolean;
|
|
16
17
|
isOpen?: boolean;
|
|
18
|
+
clearOnClose?: boolean;
|
|
17
19
|
};
|
|
18
20
|
export declare const NoInputDatePicker: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
19
21
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -660,6 +660,7 @@ type Props$j = PermafrostComponent & {
|
|
|
660
660
|
size?: [string | number] | [string | number, string | number];
|
|
661
661
|
style?: any;
|
|
662
662
|
onClick?(): void;
|
|
663
|
+
ref?: React__default.Ref<SVGSVGElement>;
|
|
663
664
|
};
|
|
664
665
|
/**
|
|
665
666
|
* Generic icon component, hidden from Assistive Technology by default.
|
|
@@ -811,11 +812,13 @@ type Props$c = PermafrostComponent & {
|
|
|
811
812
|
label?: string;
|
|
812
813
|
onChange: (value: Date | DateRange | undefined) => void;
|
|
813
814
|
selected?: Date | undefined;
|
|
815
|
+
selectedRange?: DateRange | undefined;
|
|
814
816
|
value: Date | undefined;
|
|
815
817
|
triggerIcon: IconName;
|
|
816
818
|
triggerIconSize: [string | number];
|
|
817
819
|
isRangePicker?: boolean;
|
|
818
820
|
isOpen?: boolean;
|
|
821
|
+
clearOnClose?: boolean;
|
|
819
822
|
};
|
|
820
823
|
declare const NoInputDatePicker: (props: Props$c) => react_jsx_runtime.JSX.Element;
|
|
821
824
|
|
package/lib/index.esm.js
CHANGED
|
@@ -1594,7 +1594,7 @@ function Icon(_a) {
|
|
|
1594
1594
|
console.error(`${props.name} is not a valid icon name.`);
|
|
1595
1595
|
return null;
|
|
1596
1596
|
}
|
|
1597
|
-
return (jsx("svg", Object.assign({}, iconComponentProps, ariaLabel, dimensions, { role: "img", className: props.className, "data-cy": props['data-cy'], "data-testid": props['data-testid'], fill: props.fill || 'currentColor', id: props.id, style: style, onClick: props.onClick })));
|
|
1597
|
+
return (jsx("svg", Object.assign({}, iconComponentProps, ariaLabel, dimensions, { ref: props.ref, role: "img", className: props.className, "data-cy": props['data-cy'], "data-testid": props['data-testid'], fill: props.fill || 'currentColor', id: props.id, style: style, onClick: props.onClick })));
|
|
1598
1598
|
}
|
|
1599
1599
|
function returnDimensions(sizeProp) {
|
|
1600
1600
|
if (sizeProp.length > 1) {
|
|
@@ -23090,12 +23090,22 @@ const StyledNoInputDatePicker = styled.div `
|
|
|
23090
23090
|
|
|
23091
23091
|
function CustomCaption(props) {
|
|
23092
23092
|
const { goToMonth, nextMonth, previousMonth } = useNavigation();
|
|
23093
|
-
return (jsxs("div", { className: "custom__caption", children: [jsx("button", { className: "custom__caption__action__button", disabled: !previousMonth, onClick: () =>
|
|
23093
|
+
return (jsxs("div", { className: "custom__caption", children: [jsx("button", { className: "custom__caption__action__button", disabled: !previousMonth, onClick: (event) => {
|
|
23094
|
+
event.preventDefault();
|
|
23095
|
+
if (previousMonth) {
|
|
23096
|
+
goToMonth(previousMonth);
|
|
23097
|
+
}
|
|
23098
|
+
}, children: jsx(Icon, { size: [10], ariaLabel: "Previous Month", name: "chevron-left" }) }), jsx("h2", { className: "custom__caption__text", children: format(props.displayMonth, 'MMM yyyy') }), jsx("button", { className: "custom__caption__action__button", disabled: !nextMonth, onClick: (event) => {
|
|
23099
|
+
event.preventDefault();
|
|
23100
|
+
if (nextMonth) {
|
|
23101
|
+
goToMonth(nextMonth);
|
|
23102
|
+
}
|
|
23103
|
+
}, children: jsx(Icon, { size: [10], ariaLabel: "Next Month", name: "chevron-right" }) })] }));
|
|
23094
23104
|
}
|
|
23095
23105
|
const NoInputDatePicker = (props) => {
|
|
23096
|
-
const { ariaLabel, className, disabled, disableBeforeDate, disableAfterDate, id, label, onChange, selected, triggerIcon, triggerIconSize, isRangePicker, isOpen, } = props;
|
|
23106
|
+
const { ariaLabel, className, disabled, disableBeforeDate, disableAfterDate, id, label, onChange, selected, triggerIcon, triggerIconSize, isRangePicker, selectedRange, isOpen, clearOnClose, } = props;
|
|
23097
23107
|
const [localSelected, setLocalSelected] = useState(selected || undefined);
|
|
23098
|
-
const [
|
|
23108
|
+
const [localSelectedRange, setLocalSelectedRange] = useState(selectedRange || undefined);
|
|
23099
23109
|
const [isPopperOpen, setIsPopperOpen] = useState(isOpen || false);
|
|
23100
23110
|
const [popperElement, setPopperElement] = useState(null);
|
|
23101
23111
|
const popperRef = useRef(null);
|
|
@@ -23111,17 +23121,34 @@ const NoInputDatePicker = (props) => {
|
|
|
23111
23121
|
],
|
|
23112
23122
|
});
|
|
23113
23123
|
const [isTrapActive, setIsTrapActive] = useState(false);
|
|
23124
|
+
const datePickerRef = useRef(null);
|
|
23125
|
+
// Addresses clickout side bug when implementing in an application
|
|
23114
23126
|
useEffect(() => {
|
|
23127
|
+
const handleClickOutside = (event) => {
|
|
23128
|
+
// Close the date picker only when clicked outside
|
|
23129
|
+
if (datePickerRef.current &&
|
|
23130
|
+
event.target instanceof Node &&
|
|
23131
|
+
!datePickerRef.current.contains(event.target)) {
|
|
23132
|
+
closePopper();
|
|
23133
|
+
}
|
|
23134
|
+
};
|
|
23135
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
23136
|
+
return () => {
|
|
23137
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
23138
|
+
};
|
|
23139
|
+
}, []);
|
|
23140
|
+
// Allow datepicker to load before setting active trap
|
|
23141
|
+
useLayoutEffect(() => {
|
|
23115
23142
|
if (isOpen) {
|
|
23116
|
-
|
|
23117
|
-
const timeoutId = setTimeout(() => setIsTrapActive(true), 0);
|
|
23118
|
-
return () => clearTimeout(timeoutId);
|
|
23143
|
+
setIsTrapActive(true);
|
|
23119
23144
|
}
|
|
23120
23145
|
else {
|
|
23121
23146
|
setIsTrapActive(false);
|
|
23122
23147
|
}
|
|
23123
23148
|
}, [isOpen]);
|
|
23124
23149
|
const closePopper = () => {
|
|
23150
|
+
clearOnClose && setLocalSelected(undefined);
|
|
23151
|
+
clearOnClose && setLocalSelectedRange(undefined);
|
|
23125
23152
|
setIsPopperOpen(false);
|
|
23126
23153
|
};
|
|
23127
23154
|
const handleDaySelect = (date) => {
|
|
@@ -23135,7 +23162,7 @@ const NoInputDatePicker = (props) => {
|
|
|
23135
23162
|
}
|
|
23136
23163
|
};
|
|
23137
23164
|
const handleRangeSelect = (range) => {
|
|
23138
|
-
|
|
23165
|
+
setLocalSelectedRange(range);
|
|
23139
23166
|
if ((range === null || range === void 0 ? void 0 : range.from) && (range === null || range === void 0 ? void 0 : range.to)) {
|
|
23140
23167
|
onChange(range);
|
|
23141
23168
|
closePopper();
|
|
@@ -23144,14 +23171,15 @@ const NoInputDatePicker = (props) => {
|
|
|
23144
23171
|
onChange(range);
|
|
23145
23172
|
}
|
|
23146
23173
|
};
|
|
23147
|
-
return (jsxs(StyledNoInputDatePicker, { className: className, "aria-label": ariaLabel || 'date select', "aria-describedby": `picker-label--${id}`, "data-cy": props['data-cy'], "data-testid": props['data-testid'], id: id, children: [label ? (jsx("div", { id: `picker-label--${id}`, className: "visually-hidden", children: label })) : null, jsx("div", { ref: popperRef, className: "no__input__date__picker-inputParent", children: jsx(Icon, { "aria-label": "Open date picker", name: triggerIcon, size: triggerIconSize, className: "date__picker__trigger", "data-testid": `datepicker-trigger-for-${id}`, onClick: () => setIsPopperOpen(!isPopperOpen) }) }), isPopperOpen && (jsx(FocusTrap$1, { active: isTrapActive, focusTrapOptions: {
|
|
23174
|
+
return (jsxs(StyledNoInputDatePicker, { className: className, "aria-label": ariaLabel || 'date select', "aria-describedby": `picker-label--${id}`, "data-cy": props['data-cy'], "data-testid": props['data-testid'], id: id, ref: datePickerRef, children: [label ? (jsx("div", { id: `picker-label--${id}`, className: "visually-hidden", children: label })) : null, jsx("div", { ref: popperRef, className: "no__input__date__picker-inputParent", children: jsx(Icon, { "aria-label": "Open date picker", name: triggerIcon, size: triggerIconSize, className: "date__picker__trigger", "data-testid": `datepicker-trigger-for-${id}`, onClick: () => setIsPopperOpen(!isPopperOpen) }) }), isPopperOpen && (jsx(FocusTrap$1, { active: isTrapActive, focusTrapOptions: {
|
|
23148
23175
|
initialFocus: false,
|
|
23149
23176
|
allowOutsideClick: true,
|
|
23150
23177
|
clickOutsideDeactivates: true,
|
|
23151
23178
|
onDeactivate: closePopper,
|
|
23179
|
+
fallbackFocus: popperRef.current || undefined,
|
|
23152
23180
|
}, children: jsx("div", Object.assign({ tabIndex: -1, style: popper.styles.popper, className: "DayPickerInput-Overlay" }, popper.attributes.popper, { ref: setPopperElement, role: "dialog", "aria-label": "DayPicker calendar", "data-testid": "datepicker-dialog", children: isRangePicker ? (jsx(DayPicker, { components: {
|
|
23153
23181
|
Caption: CustomCaption,
|
|
23154
|
-
}, disabled: disabled, mode: 'range', defaultMonth: localSelected, selected:
|
|
23182
|
+
}, disabled: disabled, mode: 'range', defaultMonth: localSelected, selected: localSelectedRange, onSelect: handleRangeSelect, fromDate: disableBeforeDate, toDate: disableAfterDate, "data-testid": "range-datepicker" })) : (jsx(DayPicker, { components: {
|
|
23155
23183
|
Caption: CustomCaption,
|
|
23156
23184
|
}, disabled: disabled, mode: 'single', defaultMonth: localSelected, selected: localSelected, onSelect: handleDaySelect, fromDate: disableBeforeDate, toDate: disableAfterDate, "data-testid": "single-datepicker" })) })) }))] }));
|
|
23157
23185
|
};
|