@festo-ui/react 4.0.3-pre-20221213.1 → 5.0.0-dev.72
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.css +3 -3202
- package/index.d.ts +50 -48
- package/index.js +50 -4797
- package/lib/components/accordion/Accordion.d.ts +9 -9
- package/lib/components/accordion/Accordion.js +38 -0
- package/lib/components/accordion/AccordionContext.d.ts +11 -11
- package/lib/components/accordion/AccordionContext.js +3 -0
- package/lib/components/accordion/accordion-header/AccordionHeader.d.ts +4 -4
- package/lib/components/accordion/accordion-header/AccordionHeader.js +17 -0
- package/lib/components/accordion/accordion-item/AccordionItem.d.ts +9 -9
- package/lib/components/accordion/accordion-item/AccordionItem.js +64 -0
- package/lib/components/accordion/accordion-item/AccordionItemContext.d.ts +8 -8
- package/lib/components/accordion/accordion-item/AccordionItemContext.js +3 -0
- package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.d.ts +4 -4
- package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +71 -0
- package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.d.ts +4 -4
- package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +41 -0
- package/lib/components/breadcrumb/Breadcrumb.d.ts +14 -14
- package/lib/components/breadcrumb/Breadcrumb.js +45 -0
- package/lib/components/buttons/button/Button.d.ts +12 -12
- package/lib/components/buttons/button/Button.js +37 -0
- package/lib/components/card/Card.d.ts +4 -4
- package/lib/components/card/Card.js +13 -0
- package/lib/components/card/CardBody.d.ts +7 -7
- package/lib/components/card/CardBody.js +18 -0
- package/lib/components/card/CardHeader.d.ts +9 -9
- package/lib/components/card/CardHeader.js +23 -0
- package/lib/components/card/CardNotification.d.ts +9 -9
- package/lib/components/card/CardNotification.js +26 -0
- package/lib/components/chips/chip/Chip.d.ts +19 -19
- package/lib/components/chips/chip/Chip.js +46 -0
- package/lib/components/chips/chip/DeleteIcon.d.ts +2 -0
- package/lib/components/chips/chip/DeleteIcon.js +7 -0
- package/lib/components/chips/chip-container/ChipContainer.d.ts +8 -8
- package/lib/components/chips/chip-container/ChipContainer.js +17 -0
- package/lib/components/link-button/LinkButton.d.ts +10 -10
- package/lib/components/link-button/LinkButton.js +26 -0
- package/lib/components/loading-indicator/LoadingIndicator.d.ts +7 -7
- package/lib/components/loading-indicator/LoadingIndicator.js +40 -0
- package/lib/components/modals/AlertModal.d.ts +14 -14
- package/lib/components/modals/AlertModal.js +76 -0
- package/lib/components/modals/ConfirmModal.d.ts +13 -13
- package/lib/components/modals/ConfirmModal.js +56 -0
- package/lib/components/modals/Modal.d.ts +11 -11
- package/lib/components/modals/Modal.js +76 -0
- package/lib/components/modals/ModalFooter.d.ts +4 -4
- package/lib/components/modals/ModalFooter.js +18 -0
- package/lib/components/modals/Prompt.d.ts +16 -16
- package/lib/components/modals/Prompt.js +65 -0
- package/lib/components/pagination/Pagination.d.ts +17 -17
- package/lib/components/pagination/Pagination.js +107 -0
- package/lib/components/popovers/legend/Legend.d.ts +12 -12
- package/lib/components/popovers/legend/Legend.js +25 -0
- package/lib/components/popovers/popover/Popover.d.ts +18 -18
- package/lib/components/popovers/popover/Popover.js +109 -0
- package/lib/components/popovers/popover-menu/PopoverMenu.d.ts +15 -15
- package/lib/components/popovers/popover-menu/PopoverMenu.js +54 -0
- package/lib/components/popovers/tooltip/Tooltip.d.ts +10 -10
- package/lib/components/popovers/tooltip/Tooltip.js +64 -0
- package/lib/components/progress/Progress.d.ts +9 -9
- package/lib/components/progress/Progress.js +32 -0
- package/lib/components/search-input/ClearButton.d.ts +2 -0
- package/lib/components/search-input/ClearButton.js +10 -0
- package/lib/components/search-input/SearchInput.d.ts +15 -0
- package/lib/components/search-input/SearchInput.js +75 -0
- package/lib/components/search-input/SearchSuggestion.d.ts +17 -0
- package/lib/components/search-input/SearchSuggestion.js +32 -0
- package/lib/components/search-input/useSearchInput.d.ts +13 -0
- package/lib/components/search-input/useSearchInput.js +94 -0
- package/lib/components/snackbar/Snackbar.d.ts +23 -23
- package/lib/components/snackbar/Snackbar.js +87 -0
- package/lib/components/snackbar/SnackbarContext.d.ts +8 -8
- package/lib/components/snackbar/SnackbarContext.js +2 -0
- package/lib/components/snackbar/SnackbarProvider.d.ts +8 -8
- package/lib/components/snackbar/SnackbarProvider.js +58 -0
- package/lib/components/snackbar/useSnackbar.d.ts +3 -3
- package/lib/components/snackbar/useSnackbar.js +3 -0
- package/lib/components/stepper-horizontal/StepperHorizontal.d.ts +7 -7
- package/lib/components/stepper-horizontal/StepperHorizontal.js +62 -0
- package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.d.ts +7 -7
- package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +23 -0
- package/lib/components/stepper-vertical/StepperVertical.d.ts +7 -7
- package/lib/components/stepper-vertical/StepperVertical.js +37 -0
- package/lib/components/stepper-vertical/step-vertical/StepVertical.d.ts +12 -12
- package/lib/components/stepper-vertical/step-vertical/StepVertical.js +77 -0
- package/lib/components/tab/Tabs.d.ts +23 -23
- package/lib/components/tab/Tabs.js +229 -0
- package/lib/components/tab/interfaces.d.ts +5 -0
- package/lib/components/tab/interfaces.js +1 -0
- package/lib/components/tab/tab-pane/TabPane.d.ts +11 -13
- package/lib/components/tab/tab-pane/TabPane.js +23 -0
- package/lib/components/tab/useTabScroll.d.ts +24 -24
- package/lib/components/tab/useTabScroll.js +233 -0
- package/lib/components/table-header-cell/TableHeaderCell.d.ts +7 -7
- package/lib/components/table-header-cell/TableHeaderCell.js +21 -0
- package/lib/forms/checkbox/Checkbox.d.ts +16 -16
- package/lib/forms/checkbox/Checkbox.js +88 -0
- package/lib/forms/color-indicator/ColorIndicator.d.ts +12 -12
- package/lib/forms/color-indicator/ColorIndicator.js +122 -0
- package/lib/forms/color-picker/ColorHelper.d.ts +9 -9
- package/lib/forms/color-picker/ColorHelper.js +142 -0
- package/lib/forms/color-picker/ColorPicker.d.ts +15 -15
- package/lib/forms/color-picker/ColorPicker.js +539 -0
- package/lib/forms/date-picker/DatePicker.d.ts +22 -21
- package/lib/forms/date-picker/DatePicker.js +124 -0
- package/lib/forms/date-range-picker/DateRangePicker.d.ts +20 -20
- package/lib/forms/date-range-picker/DateRangePicker.js +135 -0
- package/lib/forms/radio/RadioButton.d.ts +15 -15
- package/lib/forms/radio/RadioButton.js +56 -0
- package/lib/forms/radio/RadioGroup.d.ts +13 -13
- package/lib/forms/radio/RadioGroup.js +35 -0
- package/lib/forms/radio/RadioGroupContext.d.ts +12 -12
- package/lib/forms/radio/RadioGroupContext.js +3 -0
- package/lib/forms/segment/Segment.d.ts +14 -14
- package/lib/forms/segment/Segment.js +77 -0
- package/lib/forms/segment/segment-control/SegmentControl.d.ts +15 -15
- package/lib/forms/segment/segment-control/SegmentControl.js +64 -0
- package/lib/forms/select/Select.d.ts +26 -26
- package/lib/forms/select/Select.js +281 -0
- package/lib/forms/select/select-option/SelectOption.d.ts +10 -10
- package/lib/forms/select/select-option/SelectOption.js +16 -0
- package/lib/forms/slider/Slider.d.ts +18 -17
- package/lib/forms/slider/Slider.js +92 -0
- package/lib/forms/switch/Switch.d.ts +13 -12
- package/lib/forms/switch/Switch.js +51 -0
- package/lib/forms/text-area/TextArea.d.ts +22 -21
- package/lib/forms/text-area/TextArea.js +108 -0
- package/lib/forms/text-editor/TextEditor.d.ts +29 -29
- package/lib/forms/text-editor/TextEditor.js +255 -0
- package/lib/forms/text-editor/TextEditorButton.d.ts +14 -14
- package/lib/forms/text-editor/TextEditorButton.js +82 -0
- package/lib/forms/text-input/TextInput.d.ts +21 -21
- package/lib/forms/text-input/TextInput.js +75 -0
- package/lib/forms/time-picker/TimePicker.d.ts +18 -18
- package/lib/forms/time-picker/TimePicker.js +161 -0
- package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.d.ts +12 -12
- package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +213 -0
- package/lib/helper/index.d.ts +2 -2
- package/lib/helper/index.js +7 -0
- package/lib/helper/setRef.d.ts +2 -2
- package/lib/helper/setRef.js +7 -0
- package/lib/helper/types.d.ts +7 -7
- package/lib/helper/types.js +1 -0
- package/lib/helper/useControlled.d.ts +6 -6
- package/lib/helper/useControlled.js +18 -0
- package/lib/helper/useForkRef.d.ts +2 -2
- package/lib/helper/useForkRef.js +20 -0
- package/lib/helper/useId.d.ts +1 -0
- package/lib/helper/useId.js +21 -0
- package/lib/helper/useOnClickOutside.d.ts +2 -2
- package/lib/helper/useOnClickOutside.js +18 -0
- package/node/index.js +370 -0
- package/node/lib/components/accordion/Accordion.js +46 -0
- package/node/lib/components/accordion/AccordionContext.js +10 -0
- package/node/lib/components/accordion/accordion-header/AccordionHeader.js +25 -0
- package/node/lib/components/accordion/accordion-item/AccordionItem.js +71 -0
- package/node/lib/components/accordion/accordion-item/AccordionItemContext.js +10 -0
- package/node/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +78 -0
- package/node/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +49 -0
- package/node/lib/components/breadcrumb/Breadcrumb.js +52 -0
- package/node/lib/components/buttons/button/Button.js +44 -0
- package/node/lib/components/card/Card.js +21 -0
- package/node/lib/components/card/CardBody.js +25 -0
- package/node/lib/components/card/CardHeader.js +30 -0
- package/node/lib/components/card/CardNotification.js +33 -0
- package/node/lib/components/chips/chip/Chip.js +54 -0
- package/node/lib/components/chips/chip/DeleteIcon.js +13 -0
- package/node/lib/components/chips/chip-container/ChipContainer.js +25 -0
- package/node/lib/components/link-button/LinkButton.js +33 -0
- package/node/lib/components/loading-indicator/LoadingIndicator.js +48 -0
- package/node/lib/components/modals/AlertModal.js +82 -0
- package/node/lib/components/modals/ConfirmModal.js +62 -0
- package/node/lib/components/modals/Modal.js +84 -0
- package/node/lib/components/modals/ModalFooter.js +26 -0
- package/node/lib/components/modals/Prompt.js +72 -0
- package/node/lib/components/pagination/Pagination.js +116 -0
- package/node/lib/components/popovers/legend/Legend.js +32 -0
- package/node/lib/components/popovers/popover/Popover.js +117 -0
- package/node/lib/components/popovers/popover-menu/PopoverMenu.js +61 -0
- package/node/lib/components/popovers/tooltip/Tooltip.js +70 -0
- package/node/lib/components/progress/Progress.js +40 -0
- package/node/lib/components/search-input/ClearButton.js +16 -0
- package/node/lib/components/search-input/SearchInput.js +82 -0
- package/node/lib/components/search-input/SearchSuggestion.js +39 -0
- package/node/lib/components/search-input/useSearchInput.js +101 -0
- package/node/lib/components/snackbar/Snackbar.js +94 -0
- package/node/lib/components/snackbar/SnackbarContext.js +10 -0
- package/node/lib/components/snackbar/SnackbarProvider.js +65 -0
- package/node/lib/components/snackbar/useSnackbar.js +11 -0
- package/node/lib/components/stepper-horizontal/StepperHorizontal.js +70 -0
- package/node/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +31 -0
- package/node/lib/components/stepper-vertical/StepperVertical.js +47 -0
- package/node/lib/components/stepper-vertical/step-vertical/StepVertical.js +84 -0
- package/node/lib/components/tab/Tabs.js +237 -0
- package/node/lib/components/tab/interfaces.js +5 -0
- package/node/lib/components/tab/tab-pane/TabPane.js +31 -0
- package/node/lib/components/tab/useTabScroll.js +236 -0
- package/node/lib/components/table-header-cell/TableHeaderCell.js +29 -0
- package/node/lib/forms/checkbox/Checkbox.js +97 -0
- package/node/lib/forms/color-indicator/ColorIndicator.js +130 -0
- package/node/lib/forms/color-picker/ColorHelper.js +149 -0
- package/node/lib/forms/color-picker/ColorPicker.js +549 -0
- package/node/lib/forms/date-picker/DatePicker.js +131 -0
- package/node/lib/forms/date-range-picker/DateRangePicker.js +142 -0
- package/node/lib/forms/radio/RadioButton.js +63 -0
- package/node/lib/forms/radio/RadioGroup.js +43 -0
- package/node/lib/forms/radio/RadioGroupContext.js +10 -0
- package/node/lib/forms/segment/Segment.js +84 -0
- package/node/lib/forms/segment/segment-control/SegmentControl.js +72 -0
- package/node/lib/forms/select/Select.js +289 -0
- package/node/lib/forms/select/select-option/SelectOption.js +26 -0
- package/node/lib/forms/slider/Slider.js +101 -0
- package/node/lib/forms/switch/Switch.js +58 -0
- package/node/lib/forms/text-area/TextArea.js +117 -0
- package/node/lib/forms/text-editor/TextEditor.js +261 -0
- package/node/lib/forms/text-editor/TextEditorButton.js +88 -0
- package/node/lib/forms/text-input/TextInput.js +84 -0
- package/node/lib/forms/time-picker/TimePicker.js +169 -0
- package/node/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +222 -0
- package/node/lib/helper/index.js +15 -0
- package/node/lib/helper/setRef.js +13 -0
- package/node/lib/helper/types.js +5 -0
- package/node/lib/helper/useControlled.js +24 -0
- package/node/lib/helper/useForkRef.js +26 -0
- package/node/lib/helper/useId.js +27 -0
- package/node/lib/helper/useOnClickOutside.js +24 -0
- package/package.json +20 -10
- package/README.md +0 -17
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { ComponentPropsWithoutRef } from 'react';
|
|
2
|
-
export interface TimePickerOptions {
|
|
3
|
-
timeFormat?: '12' | '24';
|
|
4
|
-
showSeconds?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface TimePickerProps extends Omit<ComponentPropsWithoutRef<'
|
|
7
|
-
error?: string;
|
|
8
|
-
hint?: string;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
value?: Date;
|
|
12
|
-
defaultValue?: Date;
|
|
13
|
-
options?: TimePickerOptions;
|
|
14
|
-
formatDate?: (date: Date) => string;
|
|
15
|
-
onChange?: (date: Date) => void;
|
|
16
|
-
}
|
|
17
|
-
declare const TimePicker: React.ForwardRefExoticComponent<TimePickerProps & React.RefAttributes<
|
|
18
|
-
export default TimePicker;
|
|
1
|
+
import React, { ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
export interface TimePickerOptions {
|
|
3
|
+
timeFormat?: '12' | '24';
|
|
4
|
+
showSeconds?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface TimePickerProps extends Omit<ComponentPropsWithoutRef<'div'>, 'value' | 'defaultValue' | 'onChange'> {
|
|
7
|
+
error?: string;
|
|
8
|
+
hint?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
value?: Date;
|
|
12
|
+
defaultValue?: Date;
|
|
13
|
+
options?: TimePickerOptions;
|
|
14
|
+
formatDate?: (date: Date) => string;
|
|
15
|
+
onChange?: (date: Date) => void;
|
|
16
|
+
}
|
|
17
|
+
declare const TimePicker: React.ForwardRefExoticComponent<TimePickerProps & React.RefAttributes<HTMLDivElement>>;
|
|
18
|
+
export default TimePicker;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import React, { forwardRef, useCallback, useMemo, useRef, useState, useEffect } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import { usePopper } from 'react-popper';
|
|
5
|
+
import useForkRef from '../../helper/useForkRef';
|
|
6
|
+
import useId from '../../helper/useId';
|
|
7
|
+
import useOnClickOutside from '../../helper/useOnClickOutside';
|
|
8
|
+
import TimePickerDropdown from './time-picker-dropdown/TimePickerDropdown';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
|
+
const TimePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
13
|
+
let {
|
|
14
|
+
error,
|
|
15
|
+
hint,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
children,
|
|
19
|
+
value,
|
|
20
|
+
options,
|
|
21
|
+
defaultValue,
|
|
22
|
+
formatDate,
|
|
23
|
+
onChange,
|
|
24
|
+
id: idProps,
|
|
25
|
+
...props
|
|
26
|
+
} = _ref;
|
|
27
|
+
const id = useId(idProps);
|
|
28
|
+
const innerFormatDate = formatDate ?? Intl.DateTimeFormat('default', {
|
|
29
|
+
hour: 'numeric',
|
|
30
|
+
minute: 'numeric',
|
|
31
|
+
...(options?.showSeconds && {
|
|
32
|
+
second: 'numeric'
|
|
33
|
+
})
|
|
34
|
+
}).format;
|
|
35
|
+
const timeFormat = options?.timeFormat ?? '24';
|
|
36
|
+
const [referenceElement, setReferenceElement] = useState(null);
|
|
37
|
+
const [popperElement, setPopperElement] = useState(null);
|
|
38
|
+
const customModifier = useMemo(() => ({
|
|
39
|
+
name: 'offset',
|
|
40
|
+
options: {
|
|
41
|
+
offset: _ref2 => {
|
|
42
|
+
let {
|
|
43
|
+
placement
|
|
44
|
+
} = _ref2;
|
|
45
|
+
if (placement === 'bottom') {
|
|
46
|
+
return [0, -12];
|
|
47
|
+
}
|
|
48
|
+
return [0, 0];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}), []);
|
|
52
|
+
const {
|
|
53
|
+
styles,
|
|
54
|
+
attributes
|
|
55
|
+
} = usePopper(referenceElement, popperElement, {
|
|
56
|
+
modifiers: [customModifier]
|
|
57
|
+
});
|
|
58
|
+
const combinedRef = useForkRef(ref, r => setReferenceElement(r));
|
|
59
|
+
const labelRef = useRef(null);
|
|
60
|
+
const allRefs = useForkRef(combinedRef, labelRef);
|
|
61
|
+
const timePickerRef = useRef(null);
|
|
62
|
+
const combinedTimePickerRef = useForkRef(timePickerRef, r => setPopperElement(r));
|
|
63
|
+
const [open, setOpen] = useState(false);
|
|
64
|
+
const closeDropdown = useCallback(() => {
|
|
65
|
+
setOpen(false);
|
|
66
|
+
}, []);
|
|
67
|
+
useOnClickOutside(labelRef, closeDropdown, timePickerRef);
|
|
68
|
+
const controlled = value !== undefined;
|
|
69
|
+
const initialValue = controlled ? value : defaultValue;
|
|
70
|
+
const [innerValue, setInnerValue] = useState(initialValue ?? new Date());
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (value !== undefined) {
|
|
73
|
+
setInnerValue(value);
|
|
74
|
+
}
|
|
75
|
+
}, [value]);
|
|
76
|
+
function toggle(e) {
|
|
77
|
+
e?.preventDefault();
|
|
78
|
+
if (!disabled) {
|
|
79
|
+
setOpen(prevOpen => !prevOpen);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function handleDateChange(newDate) {
|
|
83
|
+
if (!controlled) {
|
|
84
|
+
setInnerValue(newDate);
|
|
85
|
+
}
|
|
86
|
+
if (onChange) {
|
|
87
|
+
onChange(newDate);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function handleClose(newDate) {
|
|
91
|
+
if (newDate) {
|
|
92
|
+
handleDateChange(newDate);
|
|
93
|
+
}
|
|
94
|
+
setOpen(false);
|
|
95
|
+
}
|
|
96
|
+
const handleKeyDown = event => {
|
|
97
|
+
if (event.key === 'Enter') {
|
|
98
|
+
toggle();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const handleKeyUp = event => {
|
|
102
|
+
if (event.key === ' ') {
|
|
103
|
+
toggle();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const container = labelRef?.current?.ownerDocument || document;
|
|
107
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
108
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
109
|
+
tabIndex: 0,
|
|
110
|
+
role: "button",
|
|
111
|
+
ref: allRefs,
|
|
112
|
+
onKeyDown: handleKeyDown,
|
|
113
|
+
onKeyUp: handleKeyUp,
|
|
114
|
+
onClick: toggle,
|
|
115
|
+
...props,
|
|
116
|
+
children: /*#__PURE__*/_jsxs("label", {
|
|
117
|
+
htmlFor: id,
|
|
118
|
+
className: "fr-time-picker fwe-input-text fwe-input-text-icon",
|
|
119
|
+
children: [/*#__PURE__*/_jsx("i", {
|
|
120
|
+
className: cn('fwe-icon fwe-icon-time-time', {
|
|
121
|
+
'fwe-color-hero': open,
|
|
122
|
+
'fwe-color-control-disabled': disabled
|
|
123
|
+
})
|
|
124
|
+
}), /*#__PURE__*/_jsx("input", {
|
|
125
|
+
id: id,
|
|
126
|
+
"aria-label": "picked time",
|
|
127
|
+
type: "text",
|
|
128
|
+
readOnly: true,
|
|
129
|
+
required: required,
|
|
130
|
+
className: cn({
|
|
131
|
+
'fwe-border-hero': open
|
|
132
|
+
}),
|
|
133
|
+
value: innerFormatDate(innerValue),
|
|
134
|
+
disabled: disabled
|
|
135
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
136
|
+
className: "fwe-input-text-label",
|
|
137
|
+
children: children
|
|
138
|
+
}), hint && /*#__PURE__*/_jsx("span", {
|
|
139
|
+
className: "fwe-input-text-info",
|
|
140
|
+
children: hint
|
|
141
|
+
}), error && /*#__PURE__*/_jsx("span", {
|
|
142
|
+
className: "fwe-input-text-invalid",
|
|
143
|
+
children: error
|
|
144
|
+
})]
|
|
145
|
+
})
|
|
146
|
+
}), open && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/_jsx(TimePickerDropdown, {
|
|
147
|
+
ref: combinedTimePickerRef,
|
|
148
|
+
onClose: handleClose,
|
|
149
|
+
onDateChange: handleDateChange,
|
|
150
|
+
timeFormat: timeFormat,
|
|
151
|
+
showSeconds: options?.showSeconds,
|
|
152
|
+
date: innerValue,
|
|
153
|
+
style: {
|
|
154
|
+
...styles.popper,
|
|
155
|
+
minWidth: labelRef?.current?.scrollWidth
|
|
156
|
+
},
|
|
157
|
+
...attributes.popper
|
|
158
|
+
}), container.body)]
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
export default TimePicker;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import './TimePickerDropdown.scss';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
interface TimePickerDropdownProps {
|
|
4
|
-
timeFormat: '12' | '24';
|
|
5
|
-
date: Date;
|
|
6
|
-
onDateChange: (date: Date) => void;
|
|
7
|
-
showSeconds?: boolean;
|
|
8
|
-
onClose: (date?: Date) => void;
|
|
9
|
-
style?: React.CSSProperties;
|
|
10
|
-
}
|
|
11
|
-
declare const TimePickerDropdown: React.ForwardRefExoticComponent<TimePickerDropdownProps & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
-
export default TimePickerDropdown;
|
|
1
|
+
import './TimePickerDropdown.scss';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface TimePickerDropdownProps {
|
|
4
|
+
timeFormat: '12' | '24';
|
|
5
|
+
date: Date;
|
|
6
|
+
onDateChange: (date: Date) => void;
|
|
7
|
+
showSeconds?: boolean;
|
|
8
|
+
onClose: (date?: Date) => void;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
}
|
|
11
|
+
declare const TimePickerDropdown: React.ForwardRefExoticComponent<TimePickerDropdownProps & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export default TimePickerDropdown;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import useForkRef from '../../../helper/useForkRef';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
const TimePickerDropdown = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
7
|
+
let {
|
|
8
|
+
timeFormat,
|
|
9
|
+
date,
|
|
10
|
+
onDateChange,
|
|
11
|
+
showSeconds,
|
|
12
|
+
onClose,
|
|
13
|
+
style
|
|
14
|
+
} = _ref;
|
|
15
|
+
const innerRef = useRef(null);
|
|
16
|
+
const combinedRef = useForkRef(ref, innerRef);
|
|
17
|
+
const hoursRef = useRef(null);
|
|
18
|
+
const [tmpHours, setTmpHours] = useState(null);
|
|
19
|
+
const [tmpMinutes, setTmpMinutes] = useState(null);
|
|
20
|
+
const [tmpSeconds, setTmpSeconds] = useState(null);
|
|
21
|
+
const [innerDate, setInnerDate] = useState(date);
|
|
22
|
+
const min = 0;
|
|
23
|
+
const hourMax = timeFormat === '12' ? 12 : 23;
|
|
24
|
+
const minutesSecondsMax = 59;
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
requestAnimationFrame(() => {
|
|
27
|
+
hoursRef.current?.focus();
|
|
28
|
+
});
|
|
29
|
+
}, []);
|
|
30
|
+
function handleKeyPress(e) {
|
|
31
|
+
if (e.key === 'Escape' || e.key === 'Enter') {
|
|
32
|
+
onClose(e.key === 'Enter' ? innerDate : undefined);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function handleHourUp() {
|
|
36
|
+
const newDate = new Date(innerDate);
|
|
37
|
+
newDate.setHours(innerDate.getHours() + 1);
|
|
38
|
+
setInnerDate(newDate);
|
|
39
|
+
onDateChange(newDate);
|
|
40
|
+
setTmpHours(null);
|
|
41
|
+
}
|
|
42
|
+
function handleHourDown() {
|
|
43
|
+
const newDate = new Date(innerDate);
|
|
44
|
+
newDate.setHours(innerDate.getHours() - 1);
|
|
45
|
+
setInnerDate(newDate);
|
|
46
|
+
onDateChange(newDate);
|
|
47
|
+
setTmpHours(null);
|
|
48
|
+
}
|
|
49
|
+
function handleHourChange(e) {
|
|
50
|
+
const newDate = new Date(innerDate);
|
|
51
|
+
const hour = +e.target.value;
|
|
52
|
+
newDate.setHours(Math.min(Math.max(hour, min), hourMax));
|
|
53
|
+
setInnerDate(newDate);
|
|
54
|
+
setTmpHours(e.target.value);
|
|
55
|
+
}
|
|
56
|
+
function handleMinuteUp() {
|
|
57
|
+
const newDate = new Date(innerDate);
|
|
58
|
+
newDate.setMinutes(innerDate.getMinutes() + 1);
|
|
59
|
+
setInnerDate(newDate);
|
|
60
|
+
onDateChange(newDate);
|
|
61
|
+
setTmpMinutes(null);
|
|
62
|
+
}
|
|
63
|
+
function handleMinuteDown() {
|
|
64
|
+
const newDate = new Date(innerDate);
|
|
65
|
+
newDate.setMinutes(innerDate.getMinutes() - 1);
|
|
66
|
+
setInnerDate(newDate);
|
|
67
|
+
onDateChange(newDate);
|
|
68
|
+
setTmpMinutes(null);
|
|
69
|
+
}
|
|
70
|
+
function handleMinuteChange(e) {
|
|
71
|
+
const newDate = new Date(innerDate);
|
|
72
|
+
const minute = +e.target.value;
|
|
73
|
+
newDate.setMinutes(Math.min(Math.max(minute, min), minutesSecondsMax));
|
|
74
|
+
setInnerDate(newDate);
|
|
75
|
+
setTmpMinutes(e.target.value);
|
|
76
|
+
}
|
|
77
|
+
function handleSecondUp() {
|
|
78
|
+
const newDate = new Date(innerDate);
|
|
79
|
+
newDate.setSeconds(innerDate.getSeconds() + 1);
|
|
80
|
+
setInnerDate(newDate);
|
|
81
|
+
onDateChange(newDate);
|
|
82
|
+
setTmpSeconds(null);
|
|
83
|
+
}
|
|
84
|
+
function handleSecondDown() {
|
|
85
|
+
const newDate = new Date(innerDate);
|
|
86
|
+
newDate.setSeconds(innerDate.getSeconds() - 1);
|
|
87
|
+
setInnerDate(newDate);
|
|
88
|
+
onDateChange(newDate);
|
|
89
|
+
setTmpSeconds(null);
|
|
90
|
+
}
|
|
91
|
+
function handleSecondChange(e) {
|
|
92
|
+
const newDate = new Date(innerDate);
|
|
93
|
+
const seconds = +e.target.value;
|
|
94
|
+
newDate.setSeconds(Math.min(Math.max(seconds, min), minutesSecondsMax));
|
|
95
|
+
setInnerDate(newDate);
|
|
96
|
+
setTmpSeconds(e.target.value);
|
|
97
|
+
}
|
|
98
|
+
const hours = timeFormat === '12' ? (innerDate.getHours() + 11) % 12 + 1 : innerDate.getHours();
|
|
99
|
+
return (
|
|
100
|
+
/*#__PURE__*/
|
|
101
|
+
// should not be an issue with dialog
|
|
102
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
103
|
+
_jsxs("div", {
|
|
104
|
+
role: "dialog",
|
|
105
|
+
style: style,
|
|
106
|
+
ref: combinedRef,
|
|
107
|
+
className: cn('fr-timepicker fwe-timepicker', {
|
|
108
|
+
'fwe-timepicker-am-pm': timeFormat === '12'
|
|
109
|
+
}),
|
|
110
|
+
onKeyDown: e => handleKeyPress(e),
|
|
111
|
+
tabIndex: -1,
|
|
112
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
113
|
+
className: "fwe-timepicker-spinners",
|
|
114
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
115
|
+
className: "fwe-timepicker-spinners-hours",
|
|
116
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
117
|
+
type: "button",
|
|
118
|
+
"aria-label": "hour up",
|
|
119
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
120
|
+
onClick: () => handleHourUp(),
|
|
121
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
122
|
+
"aria-hidden": true,
|
|
123
|
+
className: "fwe-icon fwe-icon-arrows-expand"
|
|
124
|
+
})
|
|
125
|
+
}), /*#__PURE__*/_jsx("input", {
|
|
126
|
+
"aria-label": "hours value",
|
|
127
|
+
className: "fwe-timepicker-hide-spinners",
|
|
128
|
+
type: "number",
|
|
129
|
+
min: min,
|
|
130
|
+
step: 1,
|
|
131
|
+
value: tmpHours ?? (hours < 10 ? '0' : '') + hours,
|
|
132
|
+
max: hourMax,
|
|
133
|
+
onInput: handleHourChange,
|
|
134
|
+
ref: hoursRef
|
|
135
|
+
}), /*#__PURE__*/_jsx("button", {
|
|
136
|
+
type: "button",
|
|
137
|
+
"aria-label": "hour down",
|
|
138
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
139
|
+
onClick: () => handleHourDown(),
|
|
140
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
141
|
+
"aria-hidden": true,
|
|
142
|
+
className: "fwe-icon fwe-icon-arrows-collapse"
|
|
143
|
+
})
|
|
144
|
+
})]
|
|
145
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
146
|
+
className: "fwe-timepicker-spinners-minutes",
|
|
147
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
148
|
+
type: "button",
|
|
149
|
+
"aria-label": "minute up",
|
|
150
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
151
|
+
onClick: () => handleMinuteUp(),
|
|
152
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
153
|
+
"aria-hidden": true,
|
|
154
|
+
className: "fwe-icon fwe-icon-arrows-expand"
|
|
155
|
+
})
|
|
156
|
+
}), /*#__PURE__*/_jsx("input", {
|
|
157
|
+
"aria-label": "minutes value",
|
|
158
|
+
className: "fwe-timepicker-hide-spinners",
|
|
159
|
+
type: "number",
|
|
160
|
+
min: min,
|
|
161
|
+
step: 1,
|
|
162
|
+
value: tmpMinutes ?? (innerDate.getMinutes() < 10 ? '0' : '') + innerDate.getMinutes(),
|
|
163
|
+
max: minutesSecondsMax,
|
|
164
|
+
onInput: handleMinuteChange
|
|
165
|
+
}), /*#__PURE__*/_jsx("button", {
|
|
166
|
+
type: "button",
|
|
167
|
+
"aria-label": "minute down",
|
|
168
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
169
|
+
onClick: () => handleMinuteDown(),
|
|
170
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
171
|
+
"aria-hidden": true,
|
|
172
|
+
className: "fwe-icon fwe-icon-arrows-collapse"
|
|
173
|
+
})
|
|
174
|
+
})]
|
|
175
|
+
}), showSeconds && /*#__PURE__*/_jsxs("div", {
|
|
176
|
+
className: "fwe-timepicker-spinners-seconds",
|
|
177
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
178
|
+
type: "button",
|
|
179
|
+
"aria-label": "seconds up",
|
|
180
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
181
|
+
onClick: () => handleSecondUp(),
|
|
182
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
183
|
+
"aria-hidden": true,
|
|
184
|
+
className: "fwe-icon fwe-icon-arrows-expand"
|
|
185
|
+
})
|
|
186
|
+
}), /*#__PURE__*/_jsx("input", {
|
|
187
|
+
"aria-label": "seconds value",
|
|
188
|
+
className: "fwe-timepicker-hide-spinners",
|
|
189
|
+
type: "number",
|
|
190
|
+
min: min,
|
|
191
|
+
step: 1,
|
|
192
|
+
value: tmpSeconds ?? (innerDate.getSeconds() < 10 ? '0' : '') + innerDate.getSeconds(),
|
|
193
|
+
max: minutesSecondsMax,
|
|
194
|
+
onInput: handleSecondChange
|
|
195
|
+
}), /*#__PURE__*/_jsx("button", {
|
|
196
|
+
type: "button",
|
|
197
|
+
"aria-label": "minute down",
|
|
198
|
+
className: "fwe-btn fwe-btn-link fwe-dark",
|
|
199
|
+
onClick: () => handleSecondDown(),
|
|
200
|
+
children: /*#__PURE__*/_jsx("i", {
|
|
201
|
+
"aria-hidden": true,
|
|
202
|
+
className: "fwe-icon fwe-icon-arrows-collapse"
|
|
203
|
+
})
|
|
204
|
+
})]
|
|
205
|
+
})]
|
|
206
|
+
}), timeFormat === '12' && /*#__PURE__*/_jsx("span", {
|
|
207
|
+
className: "fwe-badge fwe-badge-control",
|
|
208
|
+
children: innerDate.getHours() >= 12 ? 'PM' : 'AM'
|
|
209
|
+
})]
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
export default TimePickerDropdown;
|
package/lib/helper/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const provideDiv: () => HTMLDivElement;
|
|
2
|
-
export default provideDiv;
|
|
1
|
+
export declare const provideDiv: () => HTMLDivElement;
|
|
2
|
+
export default provideDiv;
|
package/lib/helper/setRef.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export default function setRef<T>(ref: React.ForwardedRef<T
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function setRef<T>(ref: React.ForwardedRef<T> | undefined, value: any): void;
|
package/lib/helper/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export interface ClassNameProps {
|
|
3
|
-
className?: string;
|
|
4
|
-
}
|
|
5
|
-
export interface ClassNamePropsWithChildren extends ClassNameProps {
|
|
6
|
-
children?: React.ReactNode;
|
|
7
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ClassNameProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ClassNamePropsWithChildren extends ClassNameProps {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
export interface UseControlledProps<T> {
|
|
3
|
-
controlled: T | undefined;
|
|
4
|
-
default: T | undefined;
|
|
5
|
-
}
|
|
6
|
-
export default function useControlled<T>({ controlled, default: defaultValue }: UseControlledProps<T>): [T, Dispatch<SetStateAction<T>>];
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export interface UseControlledProps<T> {
|
|
3
|
+
controlled: T | undefined;
|
|
4
|
+
default: T | undefined;
|
|
5
|
+
}
|
|
6
|
+
export default function useControlled<T>({ controlled, default: defaultValue, }: UseControlledProps<T>): [T | undefined, Dispatch<SetStateAction<T | undefined>>];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRef, useState, useCallback } from 'react';
|
|
2
|
+
export default function useControlled(_ref) {
|
|
3
|
+
let {
|
|
4
|
+
controlled,
|
|
5
|
+
default: defaultValue
|
|
6
|
+
} = _ref;
|
|
7
|
+
const {
|
|
8
|
+
current: isControlled
|
|
9
|
+
} = useRef(controlled !== undefined);
|
|
10
|
+
const [valueState, setValue] = useState(defaultValue);
|
|
11
|
+
const value = isControlled ? controlled : valueState;
|
|
12
|
+
const setValueIfUncontrolled = useCallback(newValue => {
|
|
13
|
+
if (!isControlled) {
|
|
14
|
+
setValue(newValue);
|
|
15
|
+
}
|
|
16
|
+
}, [isControlled]);
|
|
17
|
+
return [value, setValueIfUncontrolled];
|
|
18
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export default function useForkRef<T>(refA: React.Ref<T> | null | undefined, refB: React.Ref<T> | null | undefined): React.
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default function useForkRef<T>(refA: React.Ref<T> | null | undefined, refB: React.Ref<T> | null | undefined): React.RefCallback<T> | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import setRef from './setRef';
|
|
3
|
+
|
|
4
|
+
// https://github.com/facebook/react/issues/13029#issuecomment-497629971
|
|
5
|
+
export default function useForkRef(refA, refB) {
|
|
6
|
+
/**
|
|
7
|
+
* This will create a new function if the ref props change and are defined.
|
|
8
|
+
* This means react will call the old forkRef with `null` and the new forkRef
|
|
9
|
+
* with the ref. Cleanup naturally emerges from this behavior
|
|
10
|
+
*/
|
|
11
|
+
return React.useMemo(() => {
|
|
12
|
+
if ((refA === null || refA === undefined) && (refB == null || refB === undefined)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return instance => {
|
|
16
|
+
setRef(refA, instance);
|
|
17
|
+
setRef(refB, instance);
|
|
18
|
+
};
|
|
19
|
+
}, [refA, refB]);
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useId(idInput?: string): string | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line no-useless-concat
|
|
4
|
+
const maybeReactUseId = React['useId' + ''];
|
|
5
|
+
let nextId = 0;
|
|
6
|
+
function useLegacyId() {
|
|
7
|
+
const [id, setId] = React.useState(undefined);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (id == null) {
|
|
10
|
+
nextId += 1;
|
|
11
|
+
setId(`fr-${nextId}`);
|
|
12
|
+
}
|
|
13
|
+
}, [setId]);
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
export default function useId(idInput) {
|
|
17
|
+
if (idInput !== undefined && idInput !== null) {
|
|
18
|
+
return idInput;
|
|
19
|
+
}
|
|
20
|
+
return maybeReactUseId ? maybeReactUseId() : useLegacyId();
|
|
21
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
export default function useOnClickOutside<T extends HTMLElement = HTMLElement>(ref: RefObject<T>, callback: () => void, ref2?: RefObject<T>): void;
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export default function useOnClickOutside<T extends HTMLElement = HTMLElement>(ref: RefObject<T>, callback: (event: MouseEvent | TouchEvent) => void, ref2?: RefObject<T>): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export default function useOnClickOutside(ref, callback, ref2) {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
const listener = event => {
|
|
5
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
6
|
+
if (!ref.current || ref.current.contains(event.target) || ref2 && (!ref2.current || ref2.current.contains(event.target))) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
callback(event);
|
|
10
|
+
};
|
|
11
|
+
document.addEventListener('mousedown', listener);
|
|
12
|
+
document.addEventListener('touchstart', listener);
|
|
13
|
+
return () => {
|
|
14
|
+
document.removeEventListener('mousedown', listener);
|
|
15
|
+
document.removeEventListener('touchstart', listener);
|
|
16
|
+
};
|
|
17
|
+
}, [ref, ref2, callback]);
|
|
18
|
+
}
|