@dbcdk/react-components 0.0.55 → 0.0.56
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/filter-field/FilterField.js +3 -2
- package/dist/components/forms/typeahead/Typeahead.d.ts +2 -1
- package/dist/components/forms/typeahead/Typeahead.js +2 -2
- package/dist/components/popover/Popover.d.ts +1 -0
- package/dist/components/popover/Popover.js +10 -9
- package/package.json +1 -1
|
@@ -71,6 +71,7 @@ function isFilterActive(value) {
|
|
|
71
71
|
}
|
|
72
72
|
export function FilterField({ field, control, operator, value, onChange, operators, options = [], single = true, size = 'md', variant = 'surface', label, placeholder = 'Type value…', disabled, 'data-cy': dataCy, minWidth, width, maxWidth, debounceTime = INPUT_DEBOUNCE_MS, ...inputProps }) {
|
|
73
73
|
var _a, _b, _c, _d, _e, _f;
|
|
74
|
+
const filterFieldRef = useRef(null);
|
|
74
75
|
const ops = useMemo(() => operators !== null && operators !== void 0 ? operators : DEFAULT_TEXT_OPERATORS, [operators]);
|
|
75
76
|
const [selectedOperator, setSelectedOperator] = useState(operator);
|
|
76
77
|
const active = isFilterActive(value);
|
|
@@ -156,7 +157,7 @@ export function FilterField({ field, control, operator, value, onChange, operato
|
|
|
156
157
|
clearDebounce();
|
|
157
158
|
};
|
|
158
159
|
}, []);
|
|
159
|
-
return (_jsxs("div", { ...(dataCy ? { 'data-cy': dataCy } : {}), className: [styles.filterField, styles[size], styles[variant], active ? styles.active : '']
|
|
160
|
+
return (_jsxs("div", { ref: filterFieldRef, ...(dataCy ? { 'data-cy': dataCy } : {}), className: [styles.filterField, styles[size], styles[variant], active ? styles.active : '']
|
|
160
161
|
.filter(Boolean)
|
|
161
162
|
.join(' '), children: [label ? _jsx("span", { className: `${styles.label} ${styles[size]}`, children: label }) : null, _jsx(OperatorDropdown, { value: selectedOperator, onChange: handleOperatorChange, operators: ops, size: size, disabled: disabled }), _jsx("div", { className: [styles.valueWrapper, control === 'input' ? 'dbc-flex dbc-flex-grow' : '']
|
|
162
163
|
.filter(Boolean)
|
|
@@ -171,7 +172,7 @@ export function FilterField({ field, control, operator, value, onChange, operato
|
|
|
171
172
|
pendingValueRef.current = '';
|
|
172
173
|
setLocalValue('');
|
|
173
174
|
emit({ value: '' });
|
|
174
|
-
} })) : (_jsx(Typeahead, { options: options, mode: single ? 'single' : 'multi', selectedValue: single ? ((_f = value) !== null && _f !== void 0 ? _f : null) : Array.isArray(value) ? value : [], onChange: v => emit({ value: v }), minWidth: minWidth, placeholder: placeholder, variant: "embedded", inputProps: {
|
|
175
|
+
} })) : (_jsx(Typeahead, { options: options, mode: single ? 'single' : 'multi', selectedValue: single ? ((_f = value) !== null && _f !== void 0 ? _f : null) : Array.isArray(value) ? value : [], onChange: v => emit({ value: v }), minWidth: minWidth, popoverAnchorRef: filterFieldRef, placeholder: placeholder, variant: "embedded", inputProps: {
|
|
175
176
|
inputSize: size,
|
|
176
177
|
fieldClassName: styles.embeddedInputField,
|
|
177
178
|
inputClassName: styles.embeddedInputElement,
|
|
@@ -30,6 +30,7 @@ interface TypeaheadProps<T> {
|
|
|
30
30
|
autoCorrect?: InputProps['autoCorrect'];
|
|
31
31
|
autoCapitalize?: InputProps['autoCapitalize'];
|
|
32
32
|
spellCheck?: InputProps['spellCheck'];
|
|
33
|
+
popoverAnchorRef?: React.RefObject<HTMLElement | null>;
|
|
33
34
|
}
|
|
34
|
-
export declare function Typeahead<T extends string | number>({ options, mode, multiValueDisplayMode, multiSelectedValuesDisplayMode, multiSelectedValueChipContent, selectedValue, onChange, placeholder, variant, disabled, fullWidth, onClear, emptyMessage, filterOptions, inputProps, inputSize, width, minWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, }: TypeaheadProps<T>): React.ReactElement;
|
|
35
|
+
export declare function Typeahead<T extends string | number>({ options, mode, multiValueDisplayMode, multiSelectedValuesDisplayMode, multiSelectedValueChipContent, selectedValue, onChange, placeholder, variant, disabled, fullWidth, onClear, emptyMessage, filterOptions, inputProps, inputSize, width, minWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, popoverAnchorRef, }: TypeaheadProps<T>): React.ReactElement;
|
|
35
36
|
export {};
|
|
@@ -7,7 +7,7 @@ import { Input } from '../../../components/forms/input/Input';
|
|
|
7
7
|
import { Menu } from '../../../components/menu/Menu';
|
|
8
8
|
import { Popover } from '../../../components/popover/Popover';
|
|
9
9
|
import styles from './Typeahead.module.css';
|
|
10
|
-
export function Typeahead({ options, mode = 'single', multiValueDisplayMode = 'chips', multiSelectedValuesDisplayMode = 'hidden', multiSelectedValueChipContent = 'label', selectedValue = null, onChange, placeholder, variant = 'outlined', disabled = false, fullWidth = false, onClear, emptyMessage = 'Ingen resultater', filterOptions, inputProps, inputSize, width, minWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, }) {
|
|
10
|
+
export function Typeahead({ options, mode = 'single', multiValueDisplayMode = 'chips', multiSelectedValuesDisplayMode = 'hidden', multiSelectedValueChipContent = 'label', selectedValue = null, onChange, placeholder, variant = 'outlined', disabled = false, fullWidth = false, onClear, emptyMessage = 'Ingen resultater', filterOptions, inputProps, inputSize, width, minWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, popoverAnchorRef, }) {
|
|
11
11
|
var _a;
|
|
12
12
|
const inputRef = useRef(null);
|
|
13
13
|
const listboxRef = useRef(null);
|
|
@@ -270,7 +270,7 @@ export function Typeahead({ options, mode = 'single', multiValueDisplayMode = 'c
|
|
|
270
270
|
? 8
|
|
271
271
|
: 0,
|
|
272
272
|
width: fullWidth ? '100%' : undefined,
|
|
273
|
-
}, children: [_jsx(Popover, { open: open, minWidth: minWidth, onOpenChange: nextOpen => {
|
|
273
|
+
}, children: [_jsx(Popover, { open: open, minWidth: minWidth, anchorRef: popoverAnchorRef, onOpenChange: nextOpen => {
|
|
274
274
|
setOpen(nextOpen);
|
|
275
275
|
if (nextOpen) {
|
|
276
276
|
if (mode === 'single' && selectedOption) {
|
|
@@ -37,7 +37,7 @@ function parseMinWidthPx(minWidth, elForEm) {
|
|
|
37
37
|
}
|
|
38
38
|
return 0;
|
|
39
39
|
}
|
|
40
|
-
export const Popover = forwardRef(function Popover({ trigger: Trigger, children, open, defaultOpen = false, onOpenChange, contentId, minWidth = '200px', matchTriggerWidth = true, viewportPadding = 8, edgeBuffer = 100, dataCy, fullWidth = false, autoFocusContent = false, returnFocus = true, }, ref) {
|
|
40
|
+
export const Popover = forwardRef(function Popover({ trigger: Trigger, children, open, defaultOpen = false, onOpenChange, contentId, minWidth = '200px', matchTriggerWidth = true, viewportPadding = 8, edgeBuffer = 100, dataCy, fullWidth = false, autoFocusContent = false, returnFocus = true, anchorRef, }, ref) {
|
|
41
41
|
const internalId = useId();
|
|
42
42
|
const resolvedContentId = contentId !== null && contentId !== void 0 ? contentId : `popover-${internalId}`;
|
|
43
43
|
const isControlled = open !== undefined;
|
|
@@ -66,8 +66,9 @@ export const Popover = forwardRef(function Popover({ trigger: Trigger, children,
|
|
|
66
66
|
setOpen(false);
|
|
67
67
|
}, [setOpen]);
|
|
68
68
|
const togglePopover = useCallback((e) => {
|
|
69
|
-
var _a;
|
|
70
|
-
triggerElRef.current =
|
|
69
|
+
var _a, _b;
|
|
70
|
+
triggerElRef.current =
|
|
71
|
+
(_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : containerRef.current) !== null && _b !== void 0 ? _b : e.currentTarget;
|
|
71
72
|
if (isOpen)
|
|
72
73
|
closePopover('trigger');
|
|
73
74
|
else
|
|
@@ -79,11 +80,11 @@ export const Popover = forwardRef(function Popover({ trigger: Trigger, children,
|
|
|
79
80
|
isOpen: () => isOpen,
|
|
80
81
|
}), [closePopover, openPopover, isOpen]);
|
|
81
82
|
const computeAndSetPosition = useCallback(() => {
|
|
82
|
-
var _a;
|
|
83
|
+
var _a, _b;
|
|
83
84
|
const content = contentRef.current;
|
|
84
85
|
if (!content)
|
|
85
86
|
return;
|
|
86
|
-
const triggerEl = (_a =
|
|
87
|
+
const triggerEl = (_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : triggerElRef.current) !== null && _b !== void 0 ? _b : containerRef.current;
|
|
87
88
|
if (!triggerEl)
|
|
88
89
|
return;
|
|
89
90
|
const triggerRect = triggerEl.getBoundingClientRect();
|
|
@@ -158,16 +159,16 @@ export const Popover = forwardRef(function Popover({ trigger: Trigger, children,
|
|
|
158
159
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
160
|
}, [isOpen]);
|
|
160
161
|
useEffect(() => {
|
|
161
|
-
var _a, _b;
|
|
162
|
+
var _a, _b, _c;
|
|
162
163
|
if (!isOpen)
|
|
163
164
|
return;
|
|
164
165
|
const content = contentRef.current;
|
|
165
166
|
if (!content)
|
|
166
167
|
return;
|
|
167
|
-
const triggerEl = (_a =
|
|
168
|
+
const triggerEl = (_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : triggerElRef.current) !== null && _b !== void 0 ? _b : containerRef.current;
|
|
168
169
|
if (autoFocusContent) {
|
|
169
170
|
const focusables = getFocusable(content);
|
|
170
|
-
(
|
|
171
|
+
(_c = focusables[0]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
171
172
|
}
|
|
172
173
|
const handlePointerDownCapture = (e) => {
|
|
173
174
|
const container = containerRef.current;
|
|
@@ -203,7 +204,7 @@ export const Popover = forwardRef(function Popover({ trigger: Trigger, children,
|
|
|
203
204
|
window.removeEventListener('scroll', handleReposition, true);
|
|
204
205
|
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
205
206
|
};
|
|
206
|
-
}, [isOpen, closePopover, computeAndSetPosition, autoFocusContent]);
|
|
207
|
+
}, [isOpen, closePopover, computeAndSetPosition, autoFocusContent, anchorRef]);
|
|
207
208
|
useEffect(() => {
|
|
208
209
|
var _a, _b;
|
|
209
210
|
if (isOpen)
|