@dbcdk/react-components 0.0.60 → 0.0.62
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.d.ts +2 -1
- package/dist/components/filter-field/FilterField.js +2 -2
- package/dist/components/forms/text-area/Textarea.js +18 -7
- package/dist/components/forms/typeahead/Typeahead.d.ts +2 -1
- package/dist/components/forms/typeahead/Typeahead.js +2 -2
- package/package.json +1 -1
|
@@ -27,10 +27,11 @@ export interface FilterFieldProps extends Omit<React.InputHTMLAttributes<HTMLInp
|
|
|
27
27
|
minWidth?: string;
|
|
28
28
|
width?: string;
|
|
29
29
|
maxWidth?: string;
|
|
30
|
+
popoverWidth?: string;
|
|
30
31
|
debounceTime?: number;
|
|
31
32
|
}
|
|
32
33
|
export declare const NUMBER_OPERATORS: Operator[];
|
|
33
|
-
export declare function FilterField({ field, control, operator, value, onChange, operators, options, single, size, variant, label, placeholder, disabled, 'data-cy': dataCy, minWidth, width, maxWidth, debounceTime, ...inputProps }: FilterFieldProps & {
|
|
34
|
+
export declare function FilterField({ field, control, operator, value, onChange, operators, options, single, size, variant, label, placeholder, disabled, 'data-cy': dataCy, minWidth, width, maxWidth, popoverWidth, debounceTime, ...inputProps }: FilterFieldProps & {
|
|
34
35
|
'data-cy'?: string;
|
|
35
36
|
}): React.ReactElement;
|
|
36
37
|
export {};
|
|
@@ -69,7 +69,7 @@ function isFilterActive(value) {
|
|
|
69
69
|
return value.trim().length > 0;
|
|
70
70
|
return value != null;
|
|
71
71
|
}
|
|
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 }) {
|
|
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, popoverWidth, debounceTime = INPUT_DEBOUNCE_MS, ...inputProps }) {
|
|
73
73
|
var _a, _b, _c, _d, _e, _f;
|
|
74
74
|
const filterFieldRef = useRef(null);
|
|
75
75
|
const ops = useMemo(() => operators !== null && operators !== void 0 ? operators : DEFAULT_TEXT_OPERATORS, [operators]);
|
|
@@ -183,7 +183,7 @@ export function FilterField({ field, control, operator, value, onChange, operato
|
|
|
183
183
|
pendingValueRef.current = '';
|
|
184
184
|
setLocalValue('');
|
|
185
185
|
emit({ value: '' });
|
|
186
|
-
} })) : (_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: {
|
|
186
|
+
} })) : (_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, popoverWidth: popoverWidth, popoverAnchorRef: filterFieldRef, placeholder: placeholder, variant: "embedded", inputProps: {
|
|
187
187
|
inputSize: size,
|
|
188
188
|
fieldClassName: styles.embeddedInputField,
|
|
189
189
|
inputClassName: styles.embeddedInputElement,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useId, useMemo } from 'react';
|
|
3
|
+
import { useCallback, useId, useLayoutEffect, useMemo, useRef } from 'react';
|
|
4
4
|
import { useTooltipTrigger } from '../../../components/overlay/tooltip/useTooltipTrigger';
|
|
5
5
|
import styles from './Textarea.module.css';
|
|
6
6
|
import { InputContainer } from '../input-container/InputContainer';
|
|
@@ -9,17 +9,28 @@ export const Textarea = function Textarea({ value, inputChanged, disabled, rows
|
|
|
9
9
|
label, error, helpText, orientation = 'horizontal', labelWidth = '160px', fullWidth = false, required,
|
|
10
10
|
// Native textarea props
|
|
11
11
|
className, ...rest }) {
|
|
12
|
+
const HEIGHT_BUFFER_PX = 2;
|
|
12
13
|
const generatedId = useId();
|
|
13
14
|
const textareaId = id !== null && id !== void 0 ? id : `textarea-${generatedId}`;
|
|
15
|
+
const textareaRef = useRef(null);
|
|
16
|
+
const syncHeight = useCallback((textarea) => {
|
|
17
|
+
if (!adjustHeight)
|
|
18
|
+
return;
|
|
19
|
+
textarea.style.height = 'auto';
|
|
20
|
+
textarea.style.height = `${textarea.scrollHeight + HEIGHT_BUFFER_PX}px`;
|
|
21
|
+
}, [adjustHeight]);
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
const textarea = textareaRef.current;
|
|
24
|
+
if (!textarea)
|
|
25
|
+
return;
|
|
26
|
+
syncHeight(textarea);
|
|
27
|
+
}, [syncHeight, value, rows]);
|
|
14
28
|
const onInput = useCallback((e) => {
|
|
15
29
|
const textarea = e.currentTarget;
|
|
16
|
-
|
|
17
|
-
textarea.style.height = 'auto';
|
|
18
|
-
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
19
|
-
}
|
|
30
|
+
syncHeight(textarea);
|
|
20
31
|
inputChanged(e);
|
|
21
|
-
}, [inputChanged,
|
|
22
|
-
const inputField = useMemo(() => (_jsx("textarea", { ...rest, id: textareaId, className: [styles.textarea, className].filter(Boolean).join(' '), placeholder: placeholder, rows: rows, value: value, onChange: onInput, disabled: disabled, "aria-invalid": Boolean(error) || undefined })), [rest, textareaId, className, placeholder, rows, value, onInput, disabled, error]);
|
|
32
|
+
}, [inputChanged, syncHeight]);
|
|
33
|
+
const inputField = useMemo(() => (_jsx("textarea", { ...rest, ref: textareaRef, id: textareaId, className: [styles.textarea, className].filter(Boolean).join(' '), placeholder: placeholder, rows: rows, value: value, onChange: onInput, disabled: disabled, "aria-invalid": Boolean(error) || undefined })), [rest, textareaId, className, placeholder, rows, value, onInput, disabled, error]);
|
|
23
34
|
// Enable tooltip if tooltip exists, and if showTooltip is either true or undefined.
|
|
24
35
|
// (So you can deprecate showTooltip later without breaking callers.)
|
|
25
36
|
const tooltipEnabled = Boolean(tooltip) && (showTooltip !== null && showTooltip !== void 0 ? showTooltip : true);
|
|
@@ -26,6 +26,7 @@ interface TypeaheadProps<T> {
|
|
|
26
26
|
inputSize?: InputProps['inputSize'];
|
|
27
27
|
width?: InputProps['width'];
|
|
28
28
|
minWidth?: string;
|
|
29
|
+
popoverWidth?: string;
|
|
29
30
|
autoComplete?: InputProps['autoComplete'];
|
|
30
31
|
autoCorrect?: InputProps['autoCorrect'];
|
|
31
32
|
autoCapitalize?: InputProps['autoCapitalize'];
|
|
@@ -33,5 +34,5 @@ interface TypeaheadProps<T> {
|
|
|
33
34
|
popoverAnchorRef?: React.RefObject<HTMLElement | null>;
|
|
34
35
|
fitContent?: boolean;
|
|
35
36
|
}
|
|
36
|
-
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, fitContent, }: TypeaheadProps<T>): React.ReactElement;
|
|
37
|
+
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, popoverWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, popoverAnchorRef, fitContent, }: TypeaheadProps<T>): React.ReactElement;
|
|
37
38
|
export {};
|
|
@@ -86,7 +86,7 @@ function measureFitContentWidth(input, text, minWidth) {
|
|
|
86
86
|
endAdornmentWidth);
|
|
87
87
|
return Math.max(parseLengthToPx(minWidth, inputFontSize) || 120, nextWidth);
|
|
88
88
|
}
|
|
89
|
-
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, fitContent = false, }) {
|
|
89
|
+
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, popoverWidth, autoComplete, autoCorrect, autoCapitalize, spellCheck, popoverAnchorRef, fitContent = false, }) {
|
|
90
90
|
var _a, _b;
|
|
91
91
|
const rootRef = useRef(null);
|
|
92
92
|
const inputRef = useRef(null);
|
|
@@ -528,7 +528,7 @@ export function Typeahead({ options, mode = 'single', multiValueDisplayMode = 'c
|
|
|
528
528
|
flex: fullWidth || shouldFitContent ? '1 1 auto' : undefined,
|
|
529
529
|
minWidth: 0,
|
|
530
530
|
maxWidth: shouldFitContent ? '100%' : undefined,
|
|
531
|
-
}, children: [_jsx(Popover, { open: open, minWidth: minWidth, matchTriggerWidth: true, fillTrigger: true, anchorRef: popoverAnchorRef, onOpenChange: nextOpen => {
|
|
531
|
+
}, children: [_jsx(Popover, { open: open, minWidth: popoverWidth !== null && popoverWidth !== void 0 ? popoverWidth : minWidth, matchTriggerWidth: true, fillTrigger: true, anchorRef: popoverAnchorRef, onOpenChange: nextOpen => {
|
|
532
532
|
setOpen(nextOpen);
|
|
533
533
|
if (nextOpen) {
|
|
534
534
|
if (mode === 'single' && selectedOption) {
|