@servicetitan/design-system 13.4.4 → 13.4.5
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/dist/components/Popover/Popover.d.ts +1 -0
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/Popover/components.d.ts +2 -0
- package/dist/components/Popover/components.js.map +1 -1
- package/dist/components/TimePicker/TimePicker.js +8 -13
- package/dist/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/global/index.css +1 -1
- package/dist/global/version.css +1 -1
- package/dist/internal/Portal/Portal.d.ts +2 -1
- package/dist/internal/Portal/Portal.js.map +1 -1
- package/dist/system-light.css +1 -1
- package/dist/system-light.min.css +1 -1
- package/dist/system.css +1 -1
- package/dist/system.min.css +1 -1
- package/package.json +8 -8
|
@@ -9,6 +9,7 @@ export interface PopoverPropsStrict {
|
|
|
9
9
|
autoFlipVertically?: boolean;
|
|
10
10
|
/** Adds one or more classnames for Popover's overlay element */
|
|
11
11
|
className?: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
12
13
|
/** Popover direction relative to the element its apart of */
|
|
13
14
|
direction?: 't' | 'tr' | 'tl' | 'r' | 'rt' | 'rb' | 'b' | 'br' | 'bl' | 'l' | 'lt' | 'lb' | 'c';
|
|
14
15
|
/** Change the HTML element of the Popover's source element */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../../src/components/Popover/Popover.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;AAC5D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EACN,cAAc,EAEd,cAAc,EACd,aAAa,EAEb,aAAa,GAEb,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../../src/components/Popover/Popover.tsx"],"names":[],"m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nimport { Popper, PopperProps } from '../../internal/Popper';\nimport classnames from 'classnames';\nimport {\n\tPopoverContent,\n\tPopoverContentProps,\n\tPopoverDivider,\n\tPopoverFooter,\n\tPopoverFooterProps,\n\tPopoverHeader,\n\tPopoverHeaderProps,\n} from './components';\nimport { UseFocusTrapProps } from '../../hooks/useFocusTrap';\n\nexport interface PopoverPropsStrict {\n\t/** If there isn't enough space on the screen the Popover will be repositioned to the opposite side of the anchor */\n\tautoFlipHorizontally?: boolean;\n\n\t/** If there isn't enough space on the screen the Popover will be repositioned to the opposite side of the anchor */\n\tautoFlipVertically?: boolean;\n\n\t/** Adds one or more classnames for Popover's overlay element */\n\tclassName?: string;\n\n\tchildren?: React.ReactNode;\n\n\t/** Popover direction relative to the element its apart of */\n\tdirection?:\n\t\t| 't'\n\t\t| 'tr'\n\t\t| 'tl'\n\t\t| 'r'\n\t\t| 'rt'\n\t\t| 'rb'\n\t\t| 'b'\n\t\t| 'br'\n\t\t| 'bl'\n\t\t| 'l'\n\t\t| 'lt'\n\t\t| 'lb'\n\t\t| 'c';\n\n\t/** Change the HTML element of the Popover's source element */\n\tel?: 'span' | 'div';\n\n\t/** Footer for the popover */\n\tfooter?: React.ReactElement;\n\n\t/** Basic alignment for footer */\n\tfooterAlign?: PopoverFooterProps['align'];\n\n\t/** Header for the popover */\n\theader?: React.ReactElement | string;\n\n\t/** Basic alignment for header */\n\theaderAlign?: PopoverHeaderProps['align'];\n\n\t/** Basic alignment for header */\n\theaderNoPadding?: PopoverHeaderProps['noPadding'];\n\n\t/** Whether the Popover is open or not */\n\topen?: boolean;\n\n\t/**\n\t * *Warning* Only works when portal={true}\n\t * A handler that is called on every click on any element outside of the anchor element and the stick node\n\t */\n\tonClickOutside?: () => void;\n\n\t/** Define the overall padding of the popover */\n\tpadding?: 's' | 'm' | 'l' | null;\n\n\t/** Adds classnames to Popover's content wrapper */\n\tpopoverContentClassName?: string;\n\n\t/**\n\t * Renders Popover on document root through createPortal.\n\t * Effectively prevents Popover from being clipped by the boundaries of any container.\n\t */\n\tportal?: boolean;\n\n\t/** Removes the padding content around the Popover content */\n\tcontentNoPadding?: PopoverContentProps['noPadding'];\n\n\t/** Add a specific max-height value to the popover body */\n\tscrollHeight?: PopoverContentProps['contentScrollHeight'];\n\n\t/** Makes corners less rounded */\n\tsharp?: boolean;\n\n\t/** Element wrapped around Popover */\n\ttrigger?: React.ReactNode;\n\n\t/** Define the width property of the popover */\n\twidth?: 'xs' | 's' | 'm' | 'l' | '100' | 'auto';\n\n\t/** Adds one or more classnames to Popover's source element */\n\twrapperClassName?: string;\n\n\t/** Options passed into useFocusTrap */\n\tfocusTrapOptions?: UseFocusTrapProps;\n\n\t/** offset ammount between Popover and trigger */\n\toffset?: PopperProps['offset'];\n\n\t/** Props to be passed to the portaled div */\n\tportalDataAttributes?: PopperProps['portalDataAttributes'];\n}\n\nexport interface PopoverProps extends PopoverPropsStrict {\n\t/** Unstrict Props */\n\t[propName: string]: any;\n}\n\nexport interface Popover extends ForwardRefExoticComponent<PopoverProps> {\n\tHeader: typeof PopoverHeader;\n\tFooter: typeof PopoverFooter;\n\tContent: typeof PopoverContent;\n\tDivider: typeof PopoverDivider;\n}\n\nexport const Popover: Popover = React.forwardRef(\n\t(\n\t\t{\n\t\t\twidth = 's',\n\t\t\tpadding = 'm',\n\t\t\tportal = false,\n\t\t\tchildren,\n\t\t\tclassName,\n\t\t\tcontentNoPadding,\n\t\t\tfooter,\n\t\t\tfooterAlign,\n\t\t\theader,\n\t\t\theaderAlign,\n\t\t\theaderNoPadding,\n\t\t\tpopoverContentClassName,\n\t\t\tscrollHeight,\n\t\t\tsharp,\n\t\t\twrapperClassName,\n\t\t\topen,\n\t\t\tfocusTrapOptions = { disabled: true },\n\t\t\toffset = { skidding: 0, distance: 4 },\n\t\t\tportalDataAttributes,\n\t\t\t...props\n\t\t},\n\t\tref: React.RefObject<any>\n\t) => {\n\t\tconst PopoverBaseWidth = 16;\n\n\t\tconst widthSwitch = () => {\n\t\t\tswitch (width) {\n\t\t\t\tcase 'l':\n\t\t\t\t\treturn PopoverBaseWidth * 40;\n\t\t\t\tcase 'm':\n\t\t\t\t\treturn PopoverBaseWidth * 32;\n\t\t\t\tcase 's':\n\t\t\t\t\treturn PopoverBaseWidth * 20;\n\t\t\t\tcase 'xs':\n\t\t\t\t\treturn PopoverBaseWidth * 12;\n\t\t\t\tcase '100':\n\t\t\t\t\treturn `100`;\n\t\t\t\tdefault:\n\t\t\t\t\treturn `auto`;\n\t\t\t}\n\t\t};\n\n\t\tconst PopoverBodyClasses = classnames('Popover__body', className, {\n\t\t\t[`Popover--p-${padding}`]: padding,\n\t\t\t[`Popover--w-auto`]: width === 'auto',\n\t\t\t'Popover__body--sharp': sharp,\n\t\t\t'Popover__body--portal': portal,\n\t\t\t'Popover__body--open': open,\n\t\t});\n\n\t\tconst PopoverClasses = classnames('Popover', wrapperClassName, {\n\t\t\t'Popover--portal': portal,\n\t\t\t'Popover--open': open,\n\t\t});\n\n\t\treturn (\n\t\t\t<Popper\n\t\t\t\tclassName={PopoverClasses}\n\t\t\t\tbodyClassName={PopoverBodyClasses}\n\t\t\t\twidth={widthSwitch()}\n\t\t\t\tportal={portal}\n\t\t\t\tref={ref}\n\t\t\t\topen={open}\n\t\t\t\toffset={offset}\n\t\t\t\tfocusTrapOptions={focusTrapOptions}\n\t\t\t\tdata-anvil-component=\"Popover\"\n\t\t\t\tdata-portal-popover={open && portal ? 'open' : undefined}\n\t\t\t\tportalDataAttributes={portalDataAttributes}\n\t\t\t\t{...props}\n\t\t\t>\n\t\t\t\t{header && (\n\t\t\t\t\t<PopoverHeader\n\t\t\t\t\t\tnoPadding={headerNoPadding}\n\t\t\t\t\t\talign={headerAlign}\n\t\t\t\t\t>\n\t\t\t\t\t\t{header}\n\t\t\t\t\t</PopoverHeader>\n\t\t\t\t)}\n\t\t\t\t<PopoverContent\n\t\t\t\t\tcontentScrollHeight={scrollHeight}\n\t\t\t\t\tnoPadding={contentNoPadding}\n\t\t\t\t\tclassName={popoverContentClassName}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</PopoverContent>\n\t\t\t\t{footer && (\n\t\t\t\t\t<PopoverFooter align={footerAlign}>{footer}</PopoverFooter>\n\t\t\t\t)}\n\t\t\t</Popper>\n\t\t);\n\t}\n) as Popover;\n\nPopover.Header = PopoverHeader;\nPopover.Footer = PopoverFooter;\nPopover.Content = PopoverContent;\nPopover.Divider = PopoverDivider;\n"]}
|
|
@@ -3,6 +3,7 @@ import { JustifyProps } from '../../utilities/justify-props';
|
|
|
3
3
|
export interface PopoverContentPropsStrict {
|
|
4
4
|
/** Add class attribute */
|
|
5
5
|
className?: string;
|
|
6
|
+
children?: React.ReactNode;
|
|
6
7
|
/** Add a specific max-height value to the popover body */
|
|
7
8
|
contentScrollHeight?: string;
|
|
8
9
|
/** Removes content padding. For full-width backgrounds */
|
|
@@ -21,6 +22,7 @@ export interface PopoverHeaderProps {
|
|
|
21
22
|
align?: JustifyProps;
|
|
22
23
|
/** Add class attribute */
|
|
23
24
|
className?: string;
|
|
25
|
+
children?: React.ReactNode;
|
|
24
26
|
/** Removes header padding. For full-width/height backgrounds */
|
|
25
27
|
noPadding?: boolean;
|
|
26
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components/Popover/components.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAa,MAAM,OAAO,CAAC;AAClC,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components/Popover/components.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAa,MAAM,OAAO,CAAC;AAClC,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqBvC,MAAM,CAAC,M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,QAAQ;QAC5C,qBAAqB,EAAE,KAAK,KAAK,OAAO;QACxC,yBAAyB,EAAE,KAAK,KAAK,eAAe;QACpD,4BAA4B,EAAE,SAAS;KACvC,CAAC,CAAC;IACH,OAAO,CACN,oBAAC,QAAQ,kBAAC,IAAI,EAAC,OAAO,EAAC,SAAS,EAAE,uBAAuB,IAAM,KAAK,GAClE,QAAQ,CACC,CACX,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,6BAAK,SAAS,EAAC,kBAAkB,GAAG,CAAC","sourcesContent":["import React, { FC } from 'react';\nimport classnames from 'classnames';\nimport { JustifyProps } from '../../utilities/justify-props';\nimport { Headline } from '../Headline';\n\nexport interface PopoverContentPropsStrict {\n\t/** Add class attribute */\n\tclassName?: string;\n\n\tchildren?: React.ReactNode;\n\n\t/** Add a specific max-height value to the popover body */\n\tcontentScrollHeight?: string;\n\n\t/** Removes content padding. For full-width backgrounds */\n\tnoPadding?: boolean;\n\n\tonKeyDown?: (e: React.KeyboardEvent<HTMLElement>) => void;\n}\n\nexport interface PopoverContentProps extends PopoverContentPropsStrict {\n\t[propName: string]: any;\n}\n\nexport const PopoverContent: FC<PopoverContentProps> = React.forwardRef(\n\t(\n\t\t{ children, className, contentScrollHeight, noPadding, onKeyDown },\n\t\tref: React.RefObject<HTMLDivElement>\n\t) => {\n\t\tconst PopoverContentClassNames = classnames(\n\t\t\t'Popover__content',\n\t\t\tclassName,\n\t\t\t{\n\t\t\t\t'Popover__content--nopadding': noPadding,\n\t\t\t}\n\t\t);\n\t\treturn (\n\t\t\t<div\n\t\t\t\tstyle={{ maxHeight: contentScrollHeight }}\n\t\t\t\tclassName={PopoverContentClassNames}\n\t\t\t\tonKeyDown={onKeyDown}\n\t\t\t\tref={ref}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t}\n);\n\nexport interface PopoverFooterProps extends PopoverContentProps {\n\talign?: JustifyProps;\n}\n\nexport const PopoverFooter: FC<PopoverFooterProps> = ({\n\talign = 'left',\n\tchildren,\n\tclassName,\n\t...props\n}) => {\n\tconst PopoverFooterClassNames = classnames('Popover__footer', className, {\n\t\t'justify-content-start': align === 'left',\n\t\t'justify-content-center': align === 'center',\n\t\t'justify-content-end': align === 'right',\n\t\t'justify-content-between': align === 'space-between',\n\t});\n\treturn (\n\t\t<div className={PopoverFooterClassNames} {...props}>\n\t\t\t{children}\n\t\t</div>\n\t);\n};\n\nexport interface PopoverHeaderProps {\n\talign?: JustifyProps;\n\n\t/** Add class attribute */\n\tclassName?: string;\n\n\tchildren?: React.ReactNode;\n\n\t/** Removes header padding. For full-width/height backgrounds */\n\tnoPadding?: boolean;\n}\n\nexport const PopoverHeader: FC<PopoverHeaderProps> = ({\n\talign = 'left',\n\tchildren,\n\tclassName,\n\tnoPadding,\n\t...props\n}) => {\n\tconst PopoverHeaderClassNames = classnames('Popover__header', className, {\n\t\t'justify-content-start': align === 'left',\n\t\t'justify-content-center': align === 'center',\n\t\t'justify-content-end': align === 'right',\n\t\t'justify-content-between': align === 'space-between',\n\t\t'Popover__header--nopadding': noPadding,\n\t});\n\treturn (\n\t\t<Headline size=\"small\" className={PopoverHeaderClassNames} {...props}>\n\t\t\t{children}\n\t\t</Headline>\n\t);\n};\n\nexport const PopoverDivider = () => <div className=\"Popover__divider\" />;\n"]}
|
|
@@ -9,7 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React, { useCallback, useEffect, useMemo
|
|
12
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
13
13
|
import classnames from 'classnames';
|
|
14
14
|
import { FocusScope } from '@react-aria/focus';
|
|
15
15
|
import { Input } from '../Input';
|
|
@@ -34,9 +34,10 @@ export const TimePicker = React.forwardRef((props, ref) => {
|
|
|
34
34
|
const mm = () => consumeMinMax(min, max, timezone);
|
|
35
35
|
const inputRef = React.useRef(null);
|
|
36
36
|
const dropdownRef = React.useRef(null);
|
|
37
|
+
const text = typeof value === 'string' ? value : dateToTime(value) || ''; // Try to parse `value: string`, if `value: Date` use TZ
|
|
37
38
|
const [opened, setOpened] = React.useState(false); // Dropdown's visibility
|
|
38
39
|
const [dropdownFocused, setDropdownFocused] = React.useState(false); // Dropdown is in focus
|
|
39
|
-
const [input, setInput] = React.useState(
|
|
40
|
+
const [input, setInput] = React.useState(text); // User's input string
|
|
40
41
|
const [filter, setFilter] = React.useState(''); // Dropdown's options filter string (differs from user's input)
|
|
41
42
|
// Effects
|
|
42
43
|
useEffect(() => {
|
|
@@ -52,10 +53,6 @@ export const TimePicker = React.forwardRef((props, ref) => {
|
|
|
52
53
|
if (text !== input)
|
|
53
54
|
setInput(text);
|
|
54
55
|
}, [value, timezone]); // eslint-disable-line
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
// Perform autocomplete on first render to convert "value: string" into "value: Date"
|
|
57
|
-
autoComplete();
|
|
58
|
-
}, []); // eslint-disable-line
|
|
59
56
|
const handleInputFocus = () => {
|
|
60
57
|
if (disabled)
|
|
61
58
|
return;
|
|
@@ -118,17 +115,15 @@ export const TimePicker = React.forwardRef((props, ref) => {
|
|
|
118
115
|
filtered = highlightOption(filtered, closestOption); // Highlight closest option
|
|
119
116
|
return filtered;
|
|
120
117
|
}, [input, filter, options, autoRounding, closestOption]);
|
|
121
|
-
// Runs on each input blur event
|
|
122
|
-
const isEmpty = useRef(false);
|
|
123
118
|
const autoComplete = () => {
|
|
119
|
+
if (!value && input === '') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
124
122
|
if (input === '') {
|
|
125
|
-
|
|
126
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
127
|
-
isEmpty.current = true;
|
|
123
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
128
124
|
return;
|
|
129
125
|
}
|
|
130
126
|
if (closestOption) {
|
|
131
|
-
isEmpty.current = false;
|
|
132
127
|
if (closestOption.text === dateToTime(value)) {
|
|
133
128
|
setInput(closestOption.text);
|
|
134
129
|
setFilter('');
|
|
@@ -140,8 +135,8 @@ export const TimePicker = React.forwardRef((props, ref) => {
|
|
|
140
135
|
// Reject user input, if input !== ''
|
|
141
136
|
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
142
137
|
setInput(''); // Clear user's input
|
|
143
|
-
isEmpty.current = true;
|
|
144
138
|
setFilter('');
|
|
139
|
+
return;
|
|
145
140
|
}
|
|
146
141
|
if (opened)
|
|
147
142
|
setOpened(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimePicker.js","sourceRoot":"","sources":["../../../src/components/TimePicker/TimePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAM,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAc,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAgB,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EACN,UAAU,IAAI,GAAG,EACjB,UAAU,IAAI,GAAG,EACjB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,cAAc,CAAC;AA8E3E,MAAM,CAAC,MAAM,UAAU,GAAwB,KAAK,CAAC,UAAU,C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AClB,SAAS,EAAE,UAAU,CAAC,sBAAsB,EAAE,UAAU,CAAC,EACzD,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,kBAAkB,EAClC,IAAI,EACH,CAAC,QAAQ;YACT,CAAC,eAAe;YAChB,MAAM;YACN,eAAe,CAAC,MAAM,KAAK,CAAC,EAE7B,OAAO,EAAE,IAAI,EACb,MAAM,QACN,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,OAAO,EAC3C,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,iBAAiB,EACnC,WAAW,EAAE,uBAAuB,EACpC,oBAAoB,EAAE,oBAAoB,IACtC,IAAI;QAER,oBAAC,UAAU;YACV,oBAAC,oBAAoB,oBAAK,aAAa,EAAI,CAC/B,CACJ,CACV,CAAC;AACH,CAAC,CACD,CAAC;AAEF,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;AAEtC,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,EAAE;;IAC5B,IAAI,MAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,QAAQ,0CAAE,OAAO,EAAE;QACnC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,kBAAkB;KACvD;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,iBAAiB;AACtC,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC","sourcesContent":["import React, { FC, useCallback, useEffect, useMemo, useRef } from 'react';\nimport classnames from 'classnames';\nimport { FocusScope } from '@react-aria/focus';\n\nimport { Input, InputProps } from '../Input';\nimport { Popover, PopoverProps } from '../Popover';\nimport { TimezoneContext } from '../../utilities/TimezoneProvider';\nimport { keys } from '../../utilities';\nimport { FormFieldContext } from '../../components/FormField';\n\nimport {\n\tdateToTime as dtt,\n\ttimeToDate as ttd,\n\tlocalTimezone,\n\tconsumeMinMax,\n\tgetReturnDate,\n\tgenerateOptions,\n\tfilterOptionsWithRounding,\n\tfilterOptions,\n\tgetClosestOption,\n\tgetOptionByText,\n\thighlightOption,\n\tinjectOption,\n} from './utils';\n\nimport { TimePickerOptionList, TimePickerOptionProps } from './components';\nimport { PopperProps } from '../../internal';\n\nexport interface TimePickerPropsStrict\n\textends Omit<InputProps, 'value'>,\n\t\tPick<\n\t\t\tPopoverProps,\n\t\t\t| 'autoFlipVertically'\n\t\t\t| 'autoFlipHorizontally'\n\t\t\t| 'direction'\n\t\t\t| 'width'\n\t\t> {\n\t/**\n\t * If false, ignores `step` prop, so that user may fill in intermidiate values.\n\t * If true, user only allowed to choose options generated with `step` prop,\n\t * and user's input to be automatically rounded to the closest option.\n\t * Closest value to be highlighted in a dropdown.\n\t * Default is false.\n\t */\n\tautoRounding?: boolean;\n\n\t/** Preferable signifier of a value to select on autocomplete when user left the control */\n\tdefaultTimeSignifier?: 'AM' | 'PM';\n\n\t/**\n\t * Turns off TimePicker's ability to display a dropdown with options.\n\t * Default is false.\n\t */\n\tdisableDropdown?: boolean;\n\n\t/**\n\t * Specified in minutes, default is 30. Should not exceed 1440 (24 hours).\n\t * Step used to:\n\t * 1. hide intermediate values (these values are still possible to pick by typing)\n\t * from TimePicker's dropdown if `autoRounding` is false, or\n\t * 2. generate strict values for dropdown options if `autoRounding` is true.\n\t */\n\tstep?: number;\n\n\t/**\n\t * Time format.\n\t * Value of `hh:mm` stands for 24-hour format with leading zero.\n\t * Default value is `hh:mm xm`.\n\t */\n\tformat?: 'hh:mm xm' | 'hh:mm';\n\n\t/**\n\t * Minimum time allowed.\n\t * String value must have `hh:mm xm` or `hh:mm` format, from 00:00 to 23:59.\n\t * Default is `12:00 AM`.\n\t */\n\tmin?: Date | string;\n\n\t/**\n\t * Maximum time allowed.\n\t * String value must have `hh:mm xm` or `hh:mm` format, from 00:00 to 23:59.\n\t * Default is `11:59 PM`.\n\t */\n\tmax?: Date | string;\n\n\t/** Called when the user changes the value */\n\tonChange?: (value: TimePickerOptionProps['value']) => void;\n\n\t/** Show a dropdown on render, if `disableDropdown` is unset */\n\topen?: boolean;\n\n\t/** Date object, unrestricted by min and max props */\n\tvalue?: TimePickerOptionProps['value'];\n\n\t/** Props to be passed to the portaled div */\n\tportalDataAttributes?: PopperProps['portalDataAttributes'];\n}\n\nexport interface TimePickerProps extends TimePickerPropsStrict {\n\t/** Unstrict Props */\n\t[propName: string]: any;\n}\n\nexport const TimePicker: FC<TimePickerProps> = React.forwardRef(\n\t(props, ref: React.RefObject<any>) => {\n\t\tconst {\n\t\t\tautoRounding = false,\n\t\t\tclassName,\n\t\t\tdefaultTimeSignifier = 'AM',\n\t\t\tdisabled,\n\t\t\tdisableDropdown = false,\n\t\t\tdirection = 'br',\n\t\t\terror,\n\t\t\tfluid,\n\t\t\tformat = 'hh:mm xm',\n\t\t\tmin = '12:00 AM',\n\t\t\tmax = '23:59 PM',\n\t\t\tonChange,\n\t\t\topen,\n\t\t\tplaceholder,\n\t\t\tstep = 30,\n\t\t\tsize,\n\t\t\tvalue,\n\t\t\twidth = '100',\n\t\t\tportalDataAttributes,\n\t\t\t...rest\n\t\t} = props;\n\t\tconst timezone = React.useContext(TimezoneContext);\n\n\t\t// Date (00:00 in timezone), based on which selected time to be returned\n\t\tconst returnDate = () => getReturnDate(min, max, value, timezone);\n\t\tconst dateToTime = (d: Date, tz?: string) =>\n\t\t\tdtt(d, tz || timezone, format);\n\t\tconst timeToDate = (t: string) => ttd(t, timezone, returnDate());\n\n\t\t/**\n\t\t * In case min or max provided as strings, no timezone adjustment needed.\n\t\t * In case of Date objects, their time should be adjusted to timezone provided.\n\t\t */\n\t\tconst mm = () => consumeMinMax(min, max, timezone);\n\n\t\tconst inputRef = React.useRef(null);\n\t\tconst dropdownRef = React.useRef<HTMLDivElement>(null);\n\n\t\tconst [opened, setOpened] = React.useState(false); // Dropdown's visibility\n\t\tconst [dropdownFocused, setDropdownFocused] = React.useState(false); // Dropdown is in focus\n\t\tconst [input, setInput] = React.useState(''); // User's input string\n\t\tconst [filter, setFilter] = React.useState(''); // Dropdown's options filter string (differs from user's input)\n\n\t\t// Effects\n\t\tuseEffect(() => {\n\t\t\tif (disableDropdown || disabled) {\n\t\t\t\tsetOpened(false);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetOpened(open);\n\t\t}, [disableDropdown, disabled, open]);\n\n\t\tuseEffect(() => {\n\t\t\t// Set input's text on each non-null value change or timezone change\n\t\t\tconst text =\n\t\t\t\ttypeof value === 'string' ? value : dateToTime(value) || ''; // Try to parse `value: string`, if `value: Date` use TZ\n\t\t\tif (text !== input) setInput(text);\n\t\t}, [value, timezone]); // eslint-disable-line\n\n\t\tuseEffect(() => {\n\t\t\t// Perform autocomplete on first render to convert \"value: string\" into \"value: Date\"\n\t\t\tautoComplete();\n\t\t}, []); // eslint-disable-line\n\n\t\tconst handleInputFocus = () => {\n\t\t\tif (disabled) return;\n\t\t\tif (input === dateToTime(value)) setFilter(''); // Don't filter options until typing\n\t\t\tsetDropdownFocused(false); // Dropdown unfocus\n\t\t\tif (!disableDropdown && !opened) setOpened(true);\n\t\t};\n\n\t\tlet mouseDownOnDropdown = false; // To be false on each re-render\n\n\t\t// Prevents onBlur event handling on input when clicked inside dropdown\n\t\tconst handleDropdownMouseDown = () => (mouseDownOnDropdown = true);\n\t\tconst handleClickOutside = () => {\n\t\t\tif (!opened || disabled || disableDropdown) return;\n\t\t\tsetOpened(false);\n\t\t\tautoComplete();\n\t\t};\n\n\t\tconst handleInputBlur = () => {\n\t\t\t// User is choosing from dropdown'ed options\n\t\t\tif (dropdownFocused && !disableDropdown) return;\n\n\t\t\t// User clicked inside dropdown, prevent blur handling on input\n\t\t\tif (mouseDownOnDropdown) return;\n\n\t\t\t// Fake blur detection, case if active element not changed (alt+tab, etc)\n\t\t\tif (document.activeElement === getNode(inputRef)) return;\n\t\t\tautoComplete();\n\t\t};\n\n\t\t// Initial list of options to be generated based on min, max, step\n\t\tconst optionsArgs = [mm().min, mm().max, step, format] as const;\n\t\tconst options: TimePickerOptionProps[] = useCallback(\n\t\t\tgenerateOptions,\n\t\t\toptionsArgs\n\t\t)(...optionsArgs);\n\n\t\t// Getting most expected option based on user's input\n\t\tconst getClosestOptionArgs = [\n\t\t\toptions,\n\t\t\tinput,\n\t\t\tdefaultTimeSignifier,\n\t\t\tautoRounding,\n\t\t\tmm().min,\n\t\t\tmm().max,\n\t\t\tformat,\n\t\t] as const;\n\t\tconst closestOption = useCallback(\n\t\t\tgetClosestOption,\n\t\t\tgetClosestOptionArgs\n\t\t)(...getClosestOptionArgs);\n\n\t\t// Filtered list of options with an extra one to highligh (in case autoRounding is disabled)\n\t\tconst dropdownOptions = useMemo(() => {\n\t\t\tif (input === '') return options;\n\n\t\t\tif (filter === '')\n\t\t\t\t// Value is set, but user not yet modified input's text string\n\t\t\t\treturn highlightOption(\n\t\t\t\t\tinjectOption(options, closestOption), // Inject currently selected option in case it not yet exist\n\t\t\t\t\tclosestOption,\n\t\t\t\t\ttrue // Highlight selected value\n\t\t\t\t);\n\n\t\t\t// Filtering started, due to user's input manipulations\n\t\t\tlet filtered;\n\n\t\t\tfiltered = autoRounding\n\t\t\t\t? filterOptionsWithRounding(options, filter)\n\t\t\t\t: filterOptions(options, filter);\n\n\t\t\tfiltered = injectOption(filtered, closestOption); // Inject closest option in case it was filtered out\n\t\t\tfiltered = highlightOption(filtered, closestOption); // Highlight closest option\n\n\t\t\treturn filtered;\n\t\t}, [input, filter, options, autoRounding, closestOption]);\n\n\t\t// Runs on each input blur event\n\t\tconst isEmpty = useRef(false);\n\t\tconst autoComplete = () => {\n\t\t\tif (input === '') {\n\t\t\t\tif (!value && !isEmpty.current) onChange?.(null);\n\t\t\t\tisEmpty.current = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (closestOption) {\n\t\t\t\tisEmpty.current = false;\n\t\t\t\tif (closestOption.text === dateToTime(value)) {\n\t\t\t\t\tsetInput(closestOption.text);\n\t\t\t\t\tsetFilter('');\n\n\t\t\t\t\treturn; // Suppress onChange, as same time aready selected\n\t\t\t\t}\n\t\t\t\tonChange?.(timeToDate(closestOption.text)); // Accept user input\n\t\t\t} else {\n\t\t\t\t// Reject user input, if input !== ''\n\t\t\t\tonChange?.(null);\n\t\t\t\tsetInput(''); // Clear user's input\n\t\t\t\tisEmpty.current = true;\n\t\t\t\tsetFilter('');\n\t\t\t}\n\t\t\tif (opened) setOpened(false);\n\t\t};\n\n\t\t// Handling with user's typing\n\t\tconst handleInputChange = (e: any, data: any) => {\n\t\t\tsetInput(data.value.toUpperCase());\n\t\t\tsetFilter(data.value.toUpperCase());\n\t\t\tif (!opened && !disableDropdown) setOpened(true);\n\t\t};\n\n\t\tconst handleIconClick = () => {\n\t\t\tif (disabled) return;\n\t\t\tfocus(inputRef);\n\t\t\tif (opened || disableDropdown) return;\n\t\t\tsetOpened(true);\n\t\t};\n\n\t\tconst handleInputKeyDown = (e: React.KeyboardEvent) => {\n\t\t\tconst { key } = e;\n\n\t\t\t// Autocomplete on focus lost (on tab or shift+tab)\n\t\t\tif (key === keys.tab) {\n\t\t\t\tif (opened) setOpened(false);\n\t\t\t}\n\n\t\t\t// Explicit autocomplete (on enter)\n\t\t\tif (key === keys.enter) autoComplete();\n\n\t\t\t// Move focus to the dropdown\n\t\t\tif (key === keys.down || key === keys.up) {\n\t\t\t\tif (!disableDropdown) {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tif (!opened) setOpened(true);\n\t\t\t\t\tif (!dropdownFocused) setDropdownFocused(true);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst dropdownFocusValue = () => {\n\t\t\tconst focusValue = closestOption\n\t\t\t\t? getOptionByText(dropdownOptions, closestOption.text)\n\t\t\t\t: dropdownOptions[0];\n\n\t\t\treturn dropdownFocused ? focusValue : null;\n\t\t};\n\n\t\tconst handleDropdownChange = (val: Date) => {\n\t\t\tconst time = dateToTime(val, localTimezone); // Dropdown is using local\n\t\t\tconst date = timeToDate(time); // get date based on timezone and returnDate\n\t\t\tonChange?.(date);\n\t\t\tsetInput(time);\n\t\t\tsetFilter('');\n\t\t\tfocus(inputRef); // Move focus back to the field\n\t\t\tif (opened) setOpened(false);\n\t\t};\n\n\t\tconst { labelFor: inputId } = React.useContext(FormFieldContext);\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tfluid,\n\t\t\tdisabled,\n\t\t\terror,\n\t\t\tplaceholder:\n\t\t\t\ttypeof placeholder === 'string'\n\t\t\t\t\t? placeholder\n\t\t\t\t\t: format === 'hh:mm xm'\n\t\t\t\t\t? `HH:MM ${defaultTimeSignifier}`\n\t\t\t\t\t: 'HH:MM',\n\t\t\tsize,\n\t\t\tonChange: handleInputChange,\n\t\t\tonFocus: handleInputFocus,\n\t\t\tonBlur: handleInputBlur,\n\t\t\tvalue: input,\n\t\t};\n\n\t\tconst dropdownProps = {\n\t\t\tclassName: classnames('TimePicker__options', {\n\t\t\t\t'TimePicker__options-focused': dropdownFocused,\n\t\t\t}),\n\t\t\tfocusValue: dropdownFocusValue(),\n\t\t\toptions: dropdownOptions,\n\t\t\tonChange: handleDropdownChange,\n\t\t\tinputRef: inputRef.current?.inputRef || inputRef,\n\t\t\tdropdownRef,\n\t\t\thandleInputKeyDown,\n\t\t};\n\n\t\tconst Field = (\n\t\t\t<Input\n\t\t\t\t{...inputProps}\n\t\t\t\tclassName=\"TimePicker__input\"\n\t\t\t\tdata-anvil-component=\"TimePicker\"\n\t\t\t\ticon={{\n\t\t\t\t\tclassName: 'TimePicker__icon',\n\t\t\t\t\tel: 'span',\n\t\t\t\t\tname: 'access_time',\n\t\t\t\t\tonClick: handleIconClick,\n\t\t\t\t}}\n\t\t\t\ticonPosition=\"left\"\n\t\t\t\tonKeyDown={handleInputKeyDown}\n\t\t\t\tref={inputRef}\n\t\t\t/>\n\t\t);\n\n\t\tconst TimePickerClasses = classnames(className, 'TimePicker', {\n\t\t\t'TimePicker--open': opened,\n\t\t\t'TimePicker--disabled': disabled,\n\t\t\t[`TimePicker--${size}`]: size,\n\t\t});\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\tautoFlipVertically\n\t\t\t\tclassName={classnames('TimePicker__dropdown', 'a-Select')}\n\t\t\t\tdirection={direction}\n\t\t\t\tonClickOutside={handleClickOutside}\n\t\t\t\topen={\n\t\t\t\t\t!disabled &&\n\t\t\t\t\t!disableDropdown &&\n\t\t\t\t\topened &&\n\t\t\t\t\tdropdownOptions.length !== 0\n\t\t\t\t}\n\t\t\t\tpadding={null}\n\t\t\t\tportal\n\t\t\t\tref={ref}\n\t\t\t\tscrollHeight={props.scrollHeight || '192px'}\n\t\t\t\ttrigger={Field}\n\t\t\t\twidth={width}\n\t\t\t\twrapperClassName={TimePickerClasses}\n\t\t\t\tonMouseDown={handleDropdownMouseDown}\n\t\t\t\tportalDataAttributes={portalDataAttributes}\n\t\t\t\t{...rest}\n\t\t\t>\n\t\t\t\t<FocusScope>\n\t\t\t\t\t<TimePickerOptionList {...dropdownProps} />\n\t\t\t\t</FocusScope>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nTimePicker.displayName = 'TimePicker';\n\nconst getNode = (ref: any) => {\n\tif (ref.current?.inputRef?.current) {\n\t\treturn ref.current.inputRef.current; // Input component\n\t}\n\treturn ref.current; // Something else\n};\n\nconst focus = (ref: any) => getNode(ref).focus();\n"]}
|
|
1
|
+
{"version":3,"file":"TimePicker.js","sourceRoot":"","sources":["../../../src/components/TimePicker/TimePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAM,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAc,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE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EF,MAAM,KAAK,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC","sourcesContent":["import React, { FC, useCallback, useEffect, useMemo } from 'react';\nimport classnames from 'classnames';\nimport { FocusScope } from '@react-aria/focus';\n\nimport { Input, InputProps } from '../Input';\nimport { Popover, PopoverProps } from '../Popover';\nimport { TimezoneContext } from '../../utilities/TimezoneProvider';\nimport { keys } from '../../utilities';\nimport { FormFieldContext } from '../../components/FormField';\n\nimport {\n\tdateToTime as dtt,\n\ttimeToDate as ttd,\n\tlocalTimezone,\n\tconsumeMinMax,\n\tgetReturnDate,\n\tgenerateOptions,\n\tfilterOptionsWithRounding,\n\tfilterOptions,\n\tgetClosestOption,\n\tgetOptionByText,\n\thighlightOption,\n\tinjectOption,\n} from './utils';\n\nimport { TimePickerOptionList, TimePickerOptionProps } from './components';\nimport { PopperProps } from '../../internal';\n\nexport interface TimePickerPropsStrict\n\textends Omit<InputProps, 'value'>,\n\t\tPick<\n\t\t\tPopoverProps,\n\t\t\t| 'autoFlipVertically'\n\t\t\t| 'autoFlipHorizontally'\n\t\t\t| 'direction'\n\t\t\t| 'width'\n\t\t> {\n\t/**\n\t * If false, ignores `step` prop, so that user may fill in intermidiate values.\n\t * If true, user only allowed to choose options generated with `step` prop,\n\t * and user's input to be automatically rounded to the closest option.\n\t * Closest value to be highlighted in a dropdown.\n\t * Default is false.\n\t */\n\tautoRounding?: boolean;\n\n\t/** Preferable signifier of a value to select on autocomplete when user left the control */\n\tdefaultTimeSignifier?: 'AM' | 'PM';\n\n\t/**\n\t * Turns off TimePicker's ability to display a dropdown with options.\n\t * Default is false.\n\t */\n\tdisableDropdown?: boolean;\n\n\t/**\n\t * Specified in minutes, default is 30. Should not exceed 1440 (24 hours).\n\t * Step used to:\n\t * 1. hide intermediate values (these values are still possible to pick by typing)\n\t * from TimePicker's dropdown if `autoRounding` is false, or\n\t * 2. generate strict values for dropdown options if `autoRounding` is true.\n\t */\n\tstep?: number;\n\n\t/**\n\t * Time format.\n\t * Value of `hh:mm` stands for 24-hour format with leading zero.\n\t * Default value is `hh:mm xm`.\n\t */\n\tformat?: 'hh:mm xm' | 'hh:mm';\n\n\t/**\n\t * Minimum time allowed.\n\t * String value must have `hh:mm xm` or `hh:mm` format, from 00:00 to 23:59.\n\t * Default is `12:00 AM`.\n\t */\n\tmin?: Date | string;\n\n\t/**\n\t * Maximum time allowed.\n\t * String value must have `hh:mm xm` or `hh:mm` format, from 00:00 to 23:59.\n\t * Default is `11:59 PM`.\n\t */\n\tmax?: Date | string;\n\n\t/** Called when the user changes the value */\n\tonChange?: (value: TimePickerOptionProps['value']) => void;\n\n\t/** Show a dropdown on render, if `disableDropdown` is unset */\n\topen?: boolean;\n\n\t/** Date object, unrestricted by min and max props */\n\tvalue?: TimePickerOptionProps['value'];\n\n\t/** Props to be passed to the portaled div */\n\tportalDataAttributes?: PopperProps['portalDataAttributes'];\n}\n\nexport interface TimePickerProps extends TimePickerPropsStrict {\n\t/** Unstrict Props */\n\t[propName: string]: any;\n}\n\nexport const TimePicker: FC<TimePickerProps> = React.forwardRef(\n\t(props, ref: React.RefObject<any>) => {\n\t\tconst {\n\t\t\tautoRounding = false,\n\t\t\tclassName,\n\t\t\tdefaultTimeSignifier = 'AM',\n\t\t\tdisabled,\n\t\t\tdisableDropdown = false,\n\t\t\tdirection = 'br',\n\t\t\terror,\n\t\t\tfluid,\n\t\t\tformat = 'hh:mm xm',\n\t\t\tmin = '12:00 AM',\n\t\t\tmax = '23:59 PM',\n\t\t\tonChange,\n\t\t\topen,\n\t\t\tplaceholder,\n\t\t\tstep = 30,\n\t\t\tsize,\n\t\t\tvalue,\n\t\t\twidth = '100',\n\t\t\tportalDataAttributes,\n\t\t\t...rest\n\t\t} = props;\n\t\tconst timezone = React.useContext(TimezoneContext);\n\n\t\t// Date (00:00 in timezone), based on which selected time to be returned\n\t\tconst returnDate = () => getReturnDate(min, max, value, timezone);\n\t\tconst dateToTime = (d: Date, tz?: string) =>\n\t\t\tdtt(d, tz || timezone, format);\n\t\tconst timeToDate = (t: string) => ttd(t, timezone, returnDate());\n\n\t\t/**\n\t\t * In case min or max provided as strings, no timezone adjustment needed.\n\t\t * In case of Date objects, their time should be adjusted to timezone provided.\n\t\t */\n\t\tconst mm = () => consumeMinMax(min, max, timezone);\n\n\t\tconst inputRef = React.useRef(null);\n\t\tconst dropdownRef = React.useRef<HTMLDivElement>(null);\n\t\tconst text =\n\t\t\ttypeof value === 'string' ? value : dateToTime(value) || ''; // Try to parse `value: string`, if `value: Date` use TZ\n\t\tconst [opened, setOpened] = React.useState(false); // Dropdown's visibility\n\t\tconst [dropdownFocused, setDropdownFocused] = React.useState(false); // Dropdown is in focus\n\t\tconst [input, setInput] = React.useState(text); // User's input string\n\t\tconst [filter, setFilter] = React.useState(''); // Dropdown's options filter string (differs from user's input)\n\n\t\t// Effects\n\t\tuseEffect(() => {\n\t\t\tif (disableDropdown || disabled) {\n\t\t\t\tsetOpened(false);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetOpened(open);\n\t\t}, [disableDropdown, disabled, open]);\n\n\t\tuseEffect(() => {\n\t\t\t// Set input's text on each non-null value change or timezone change\n\t\t\tconst text =\n\t\t\t\ttypeof value === 'string' ? value : dateToTime(value) || ''; // Try to parse `value: string`, if `value: Date` use TZ\n\t\t\tif (text !== input) setInput(text);\n\t\t}, [value, timezone]); // eslint-disable-line\n\n\t\tconst handleInputFocus = () => {\n\t\t\tif (disabled) return;\n\t\t\tif (input === dateToTime(value)) setFilter(''); // Don't filter options until typing\n\t\t\tsetDropdownFocused(false); // Dropdown unfocus\n\t\t\tif (!disableDropdown && !opened) setOpened(true);\n\t\t};\n\n\t\tlet mouseDownOnDropdown = false; // To be false on each re-render\n\n\t\t// Prevents onBlur event handling on input when clicked inside dropdown\n\t\tconst handleDropdownMouseDown = () => (mouseDownOnDropdown = true);\n\t\tconst handleClickOutside = () => {\n\t\t\tif (!opened || disabled || disableDropdown) return;\n\t\t\tsetOpened(false);\n\t\t\tautoComplete();\n\t\t};\n\n\t\tconst handleInputBlur = () => {\n\t\t\t// User is choosing from dropdown'ed options\n\t\t\tif (dropdownFocused && !disableDropdown) return;\n\n\t\t\t// User clicked inside dropdown, prevent blur handling on input\n\t\t\tif (mouseDownOnDropdown) return;\n\n\t\t\t// Fake blur detection, case if active element not changed (alt+tab, etc)\n\t\t\tif (document.activeElement === getNode(inputRef)) return;\n\t\t\tautoComplete();\n\t\t};\n\n\t\t// Initial list of options to be generated based on min, max, step\n\t\tconst optionsArgs = [mm().min, mm().max, step, format] as const;\n\t\tconst options: TimePickerOptionProps[] = useCallback(\n\t\t\tgenerateOptions,\n\t\t\toptionsArgs\n\t\t)(...optionsArgs);\n\n\t\t// Getting most expected option based on user's input\n\t\tconst getClosestOptionArgs = [\n\t\t\toptions,\n\t\t\tinput,\n\t\t\tdefaultTimeSignifier,\n\t\t\tautoRounding,\n\t\t\tmm().min,\n\t\t\tmm().max,\n\t\t\tformat,\n\t\t] as const;\n\t\tconst closestOption = useCallback(\n\t\t\tgetClosestOption,\n\t\t\tgetClosestOptionArgs\n\t\t)(...getClosestOptionArgs);\n\n\t\t// Filtered list of options with an extra one to highligh (in case autoRounding is disabled)\n\t\tconst dropdownOptions = useMemo(() => {\n\t\t\tif (input === '') return options;\n\n\t\t\tif (filter === '')\n\t\t\t\t// Value is set, but user not yet modified input's text string\n\t\t\t\treturn highlightOption(\n\t\t\t\t\tinjectOption(options, closestOption), // Inject currently selected option in case it not yet exist\n\t\t\t\t\tclosestOption,\n\t\t\t\t\ttrue // Highlight selected value\n\t\t\t\t);\n\n\t\t\t// Filtering started, due to user's input manipulations\n\t\t\tlet filtered;\n\n\t\t\tfiltered = autoRounding\n\t\t\t\t? filterOptionsWithRounding(options, filter)\n\t\t\t\t: filterOptions(options, filter);\n\n\t\t\tfiltered = injectOption(filtered, closestOption); // Inject closest option in case it was filtered out\n\t\t\tfiltered = highlightOption(filtered, closestOption); // Highlight closest option\n\n\t\t\treturn filtered;\n\t\t}, [input, filter, options, autoRounding, closestOption]);\n\n\t\tconst autoComplete = () => {\n\t\t\tif (!value && input === '') {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (input === '') {\n\t\t\t\tonChange?.(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (closestOption) {\n\t\t\t\tif (closestOption.text === dateToTime(value)) {\n\t\t\t\t\tsetInput(closestOption.text);\n\t\t\t\t\tsetFilter('');\n\n\t\t\t\t\treturn; // Suppress onChange, as same time aready selected\n\t\t\t\t}\n\t\t\t\tonChange?.(timeToDate(closestOption.text)); // Accept user input\n\t\t\t} else {\n\t\t\t\t// Reject user input, if input !== ''\n\t\t\t\tonChange?.(null);\n\t\t\t\tsetInput(''); // Clear user's input\n\t\t\t\tsetFilter('');\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (opened) setOpened(false);\n\t\t};\n\n\t\t// Handling with user's typing\n\t\tconst handleInputChange = (e: any, data: any) => {\n\t\t\tsetInput(data.value.toUpperCase());\n\t\t\tsetFilter(data.value.toUpperCase());\n\t\t\tif (!opened && !disableDropdown) setOpened(true);\n\t\t};\n\n\t\tconst handleIconClick = () => {\n\t\t\tif (disabled) return;\n\t\t\tfocus(inputRef);\n\t\t\tif (opened || disableDropdown) return;\n\t\t\tsetOpened(true);\n\t\t};\n\n\t\tconst handleInputKeyDown = (e: React.KeyboardEvent) => {\n\t\t\tconst { key } = e;\n\n\t\t\t// Autocomplete on focus lost (on tab or shift+tab)\n\t\t\tif (key === keys.tab) {\n\t\t\t\tif (opened) setOpened(false);\n\t\t\t}\n\n\t\t\t// Explicit autocomplete (on enter)\n\t\t\tif (key === keys.enter) autoComplete();\n\n\t\t\t// Move focus to the dropdown\n\t\t\tif (key === keys.down || key === keys.up) {\n\t\t\t\tif (!disableDropdown) {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tif (!opened) setOpened(true);\n\t\t\t\t\tif (!dropdownFocused) setDropdownFocused(true);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst dropdownFocusValue = () => {\n\t\t\tconst focusValue = closestOption\n\t\t\t\t? getOptionByText(dropdownOptions, closestOption.text)\n\t\t\t\t: dropdownOptions[0];\n\n\t\t\treturn dropdownFocused ? focusValue : null;\n\t\t};\n\n\t\tconst handleDropdownChange = (val: Date) => {\n\t\t\tconst time = dateToTime(val, localTimezone); // Dropdown is using local\n\t\t\tconst date = timeToDate(time); // get date based on timezone and returnDate\n\t\t\tonChange?.(date);\n\t\t\tsetInput(time);\n\t\t\tsetFilter('');\n\t\t\tfocus(inputRef); // Move focus back to the field\n\t\t\tif (opened) setOpened(false);\n\t\t};\n\n\t\tconst { labelFor: inputId } = React.useContext(FormFieldContext);\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tfluid,\n\t\t\tdisabled,\n\t\t\terror,\n\t\t\tplaceholder:\n\t\t\t\ttypeof placeholder === 'string'\n\t\t\t\t\t? placeholder\n\t\t\t\t\t: format === 'hh:mm xm'\n\t\t\t\t\t? `HH:MM ${defaultTimeSignifier}`\n\t\t\t\t\t: 'HH:MM',\n\t\t\tsize,\n\t\t\tonChange: handleInputChange,\n\t\t\tonFocus: handleInputFocus,\n\t\t\tonBlur: handleInputBlur,\n\t\t\tvalue: input,\n\t\t};\n\n\t\tconst dropdownProps = {\n\t\t\tclassName: classnames('TimePicker__options', {\n\t\t\t\t'TimePicker__options-focused': dropdownFocused,\n\t\t\t}),\n\t\t\tfocusValue: dropdownFocusValue(),\n\t\t\toptions: dropdownOptions,\n\t\t\tonChange: handleDropdownChange,\n\t\t\tinputRef: inputRef.current?.inputRef || inputRef,\n\t\t\tdropdownRef,\n\t\t\thandleInputKeyDown,\n\t\t};\n\n\t\tconst Field = (\n\t\t\t<Input\n\t\t\t\t{...inputProps}\n\t\t\t\tclassName=\"TimePicker__input\"\n\t\t\t\tdata-anvil-component=\"TimePicker\"\n\t\t\t\ticon={{\n\t\t\t\t\tclassName: 'TimePicker__icon',\n\t\t\t\t\tel: 'span',\n\t\t\t\t\tname: 'access_time',\n\t\t\t\t\tonClick: handleIconClick,\n\t\t\t\t}}\n\t\t\t\ticonPosition=\"left\"\n\t\t\t\tonKeyDown={handleInputKeyDown}\n\t\t\t\tref={inputRef}\n\t\t\t/>\n\t\t);\n\n\t\tconst TimePickerClasses = classnames(className, 'TimePicker', {\n\t\t\t'TimePicker--open': opened,\n\t\t\t'TimePicker--disabled': disabled,\n\t\t\t[`TimePicker--${size}`]: size,\n\t\t});\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\tautoFlipVertically\n\t\t\t\tclassName={classnames('TimePicker__dropdown', 'a-Select')}\n\t\t\t\tdirection={direction}\n\t\t\t\tonClickOutside={handleClickOutside}\n\t\t\t\topen={\n\t\t\t\t\t!disabled &&\n\t\t\t\t\t!disableDropdown &&\n\t\t\t\t\topened &&\n\t\t\t\t\tdropdownOptions.length !== 0\n\t\t\t\t}\n\t\t\t\tpadding={null}\n\t\t\t\tportal\n\t\t\t\tref={ref}\n\t\t\t\tscrollHeight={props.scrollHeight || '192px'}\n\t\t\t\ttrigger={Field}\n\t\t\t\twidth={width}\n\t\t\t\twrapperClassName={TimePickerClasses}\n\t\t\t\tonMouseDown={handleDropdownMouseDown}\n\t\t\t\tportalDataAttributes={portalDataAttributes}\n\t\t\t\t{...rest}\n\t\t\t>\n\t\t\t\t<FocusScope>\n\t\t\t\t\t<TimePickerOptionList {...dropdownProps} />\n\t\t\t\t</FocusScope>\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nTimePicker.displayName = 'TimePicker';\n\nconst getNode = (ref: any) => {\n\tif (ref.current?.inputRef?.current) {\n\t\treturn ref.current.inputRef.current; // Input component\n\t}\n\treturn ref.current; // Something else\n};\n\nconst focus = (ref: any) => getNode(ref).focus();\n"]}
|
package/dist/global/index.css
CHANGED
package/dist/global/version.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Portal.js","sourceRoot":"","sources":["../../../src/internal/Portal/Portal.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAM,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"Portal.js","sourceRoot":"","sources":["../../../src/internal/Portal/Portal.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAM,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAY5E,MAAM,CAAC,MAAM,MAAM,GAAoB,CAAC,EACvC,QAAQ,EACR,WAAW,GAAG,IAAI,EAClB,MAAM,GACN,EAAE,EAAE;;IACJ,MAAM,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC9D,mDAAmD;IACnD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,WAAW;YAAE,OAAO,QAA8B,CAAC;QAExD,MAAM,IAAI,GAAG,MAAA,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,oBAAoB,mCAAI,QAAQ,CAAC,IAAI,CAAC;QAE7D,OAAO,YAAY,CAAC,QAAQ,EAAE,IAAe,CAAC,CAAC;KAC/C;IACD,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["import React, { FC, useContext } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { DefaultPortalContext } from '../../utilities/DefaultPortalContext';\n\ninterface PortalProps {\n\tchildren?: React.ReactNode;\n\n\t/* If true, children are portalled. If false, children are not portalled */\n\tconditional?: boolean;\n\n\t/* Target element to create portal at */\n\ttarget?: HTMLElement;\n}\n\nexport const Portal: FC<PortalProps> = ({\n\tchildren,\n\tconditional = true,\n\ttarget,\n}) => {\n\tconst defaultPortalContext = useContext(DefaultPortalContext);\n\t// Check for document for server-side rendered apps\n\tif (typeof document !== 'undefined') {\n\t\t// End early if portal isn't needed\n\t\tif (!conditional) return children as React.ReactElement;\n\n\t\tconst node = target ?? defaultPortalContext ?? document.body;\n\n\t\treturn createPortal(children, node as Element);\n\t}\n\treturn null;\n};\n"]}
|