@navikt/ds-react 0.14.9 → 0.14.10-next.0
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/cjs/form/search-field/SearchField.js +44 -23
- package/cjs/form/search-field/useSearchField.js +31 -0
- package/cjs/util/index.js +15 -1
- package/esm/form/search-field/SearchField.d.ts +25 -25
- package/esm/form/search-field/SearchField.js +46 -24
- package/esm/form/search-field/SearchField.js.map +1 -1
- package/esm/form/search-field/useSearchField.d.ts +10 -0
- package/esm/form/search-field/useSearchField.js +25 -0
- package/esm/form/search-field/useSearchField.js.map +1 -0
- package/esm/util/index.d.ts +5 -0
- package/esm/util/index.js +13 -0
- package/esm/util/index.js.map +1 -1
- package/package.json +2 -2
- package/src/form/search-field/SearchField.tsx +126 -71
- package/src/form/search-field/stories/search-field.stories.mdx +158 -89
- package/src/form/search-field/stories/search-field.stories.tsx +62 -154
- package/src/form/search-field/useSearchField.ts +31 -0
- package/src/util/index.ts +33 -0
- package/cjs/form/search-field/SearchFieldButton.js +0 -50
- package/cjs/form/search-field/SearchFieldClearButton.js +0 -50
- package/cjs/form/search-field/SearchFieldInput.js +0 -49
- package/esm/form/search-field/SearchFieldButton.d.ts +0 -17
- package/esm/form/search-field/SearchFieldButton.js +0 -27
- package/esm/form/search-field/SearchFieldButton.js.map +0 -1
- package/esm/form/search-field/SearchFieldClearButton.d.ts +0 -17
- package/esm/form/search-field/SearchFieldClearButton.js +0 -27
- package/esm/form/search-field/SearchFieldClearButton.js.map +0 -1
- package/esm/form/search-field/SearchFieldInput.d.ts +0 -6
- package/esm/form/search-field/SearchFieldInput.js +0 -26
- package/esm/form/search-field/SearchFieldInput.js.map +0 -1
- package/src/form/search-field/SearchFieldButton.tsx +0 -47
- package/src/form/search-field/SearchFieldClearButton.tsx +0 -49
- package/src/form/search-field/SearchFieldInput.tsx +0 -42
- package/src/form/search-field/stories/search-field-example.tsx +0 -25
|
@@ -33,37 +33,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
|
|
36
|
+
const ds_icons_1 = require("@navikt/ds-icons");
|
|
37
37
|
const classnames_1 = __importDefault(require("classnames"));
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
39
40
|
const __1 = require("../..");
|
|
40
|
-
const
|
|
41
|
-
const useFormField_1 = require("../useFormField");
|
|
42
|
-
const SearchFieldButton_1 = __importDefault(require("./SearchFieldButton"));
|
|
43
|
-
const SearchFieldClearButton_1 = __importDefault(require("./SearchFieldClearButton"));
|
|
44
|
-
const SearchFieldInput_1 = __importDefault(require("./SearchFieldInput"));
|
|
45
|
-
exports.SearchFieldContext = react_1.default.createContext(null);
|
|
41
|
+
const useSearchField_1 = require("./useSearchField");
|
|
46
42
|
const SearchField = (0, react_1.forwardRef)((props, ref) => {
|
|
47
|
-
const { inputProps,
|
|
48
|
-
const { className, hideLabel,
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const { inputProps, size, inputDescriptionId } = (0, useSearchField_1.useSearchField)(props, "searchfield");
|
|
44
|
+
const { className, hideLabel, label, description, value, clearButtonLabel, onClear, inverted = false, clearButton = true } = props, rest = __rest(props, ["className", "hideLabel", "label", "description", "value", "clearButtonLabel", "onClear", "inverted", "clearButton"]);
|
|
45
|
+
const [controlledValue, setControlledValue] = (0, react_1.useState)(value !== null && value !== void 0 ? value : "");
|
|
46
|
+
const searchRef = (0, react_1.useRef)(null);
|
|
47
|
+
const mergedRef = (0, react_merge_refs_1.default)([searchRef, ref]);
|
|
48
|
+
const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
|
|
49
|
+
const handleChange = (0, react_1.useCallback)((v) => {
|
|
50
|
+
var _a;
|
|
51
|
+
if (searchRef.current && value === undefined) {
|
|
52
|
+
searchRef.current.value = v;
|
|
53
|
+
setControlledValue(v);
|
|
54
|
+
}
|
|
55
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v);
|
|
56
|
+
}, [props, value]);
|
|
57
|
+
const handleClear = (0, react_1.useCallback)(() => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
onClear === null || onClear === void 0 ? void 0 : onClear();
|
|
60
|
+
handleChange("");
|
|
61
|
+
searchRef.current && ((_b = (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
62
|
+
}, [handleChange, onClear]);
|
|
63
|
+
(0, __1.useEventListener)("keydown", (0, react_1.useCallback)((e) => {
|
|
64
|
+
if (e.key === "Escape") {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
handleClear();
|
|
67
|
+
}
|
|
68
|
+
}, [handleClear]), wrapperRef);
|
|
69
|
+
(0, react_1.useEffect)(() => {
|
|
70
|
+
value !== undefined && setControlledValue(value);
|
|
71
|
+
}, [value]);
|
|
72
|
+
return (react_1.default.createElement("div", { ref: setWrapperRef, className: (0, classnames_1.default)(className, "navds-form-field", `navds-form-field--${size !== null && size !== void 0 ? size : "medium"}`, "navds-search-field", {
|
|
51
73
|
"navds-search-field--disabled": !!inputProps.disabled,
|
|
52
|
-
|
|
74
|
+
"navds-search-field--inverted": inverted,
|
|
75
|
+
}) },
|
|
53
76
|
react_1.default.createElement(__1.Label, { htmlFor: inputProps.id, size: size, as: "label", className: (0, classnames_1.default)("navds-text-field__label", {
|
|
54
|
-
"sr-only": hideLabel,
|
|
77
|
+
"navds-sr-only": hideLabel,
|
|
55
78
|
}) }, label),
|
|
56
79
|
!!description && (react_1.default.createElement(__1.BodyShort, { as: "div", className: (0, classnames_1.default)("navds-text-field__description", {
|
|
57
|
-
"sr-only": hideLabel,
|
|
80
|
+
"navds-sr-only": hideLabel,
|
|
58
81
|
}), id: inputDescriptionId, size: size }, description)),
|
|
59
|
-
react_1.default.createElement("div", { className: "navds-search-field__input-wrapper" },
|
|
60
|
-
react_1.default.createElement(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
react_1.default.createElement("div", { "data-value": !!controlledValue, className: "navds-search-field__input-wrapper" },
|
|
83
|
+
react_1.default.createElement("span", { className: "navds-search-field__input-icon" },
|
|
84
|
+
react_1.default.createElement(ds_icons_1.Search, { "aria-hidden": true })),
|
|
85
|
+
react_1.default.createElement("input", Object.assign({ ref: mergedRef }, (0, __1.omit)(rest, ["size"]), inputProps, (props.value !== undefined && { value: props.value }), { onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: (0, classnames_1.default)(className, "navds-search-field__input", "navds-text-field__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`) })),
|
|
86
|
+
controlledValue && clearButton && (react_1.default.createElement("button", { onClick: () => handleClear(), className: "navds-search-field__clear-button" },
|
|
87
|
+
react_1.default.createElement("span", { className: "navds-sr-only" }, clearButtonLabel ? clearButtonLabel : "Slett tekst i felt"),
|
|
88
|
+
react_1.default.createElement(ds_icons_1.Close, { "aria-hidden": true }))))));
|
|
65
89
|
});
|
|
66
|
-
SearchField.Button = SearchFieldButton_1.default;
|
|
67
|
-
SearchField.Clear = SearchFieldClearButton_1.default;
|
|
68
|
-
SearchField.Input = SearchFieldInput_1.default;
|
|
69
90
|
exports.default = SearchField;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useSearchField = void 0;
|
|
7
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const index_1 = require("../../index");
|
|
10
|
+
const index_2 = require("../index");
|
|
11
|
+
const useSearchField = (props, prefix) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { size } = props;
|
|
14
|
+
const fieldset = (0, react_1.useContext)(index_2.FieldsetContext);
|
|
15
|
+
const genId = (0, index_1.useId)();
|
|
16
|
+
const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${prefix}-${genId}`;
|
|
17
|
+
const inputDescriptionId = `${prefix}-description-${genId}`;
|
|
18
|
+
const disabled = (fieldset === null || fieldset === void 0 ? void 0 : fieldset.disabled) || props.disabled;
|
|
19
|
+
return {
|
|
20
|
+
inputDescriptionId,
|
|
21
|
+
size: (_b = size !== null && size !== void 0 ? size : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _b !== void 0 ? _b : "medium",
|
|
22
|
+
inputProps: {
|
|
23
|
+
id,
|
|
24
|
+
"aria-describedby": (0, classnames_1.default)(props["aria-describedby"], {
|
|
25
|
+
[inputDescriptionId]: !!(props === null || props === void 0 ? void 0 : props.description),
|
|
26
|
+
}) || undefined,
|
|
27
|
+
disabled,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.useSearchField = useSearchField;
|
package/cjs/util/index.js
CHANGED
|
@@ -10,10 +10,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.omit = void 0;
|
|
13
|
+
exports.useEventListener = exports.omit = void 0;
|
|
14
|
+
const react_1 = require("react");
|
|
14
15
|
__exportStar(require("./OverridableComponent"), exports);
|
|
15
16
|
__exportStar(require("./useId"), exports);
|
|
16
17
|
const omit = (obj, props) => Object.entries(obj)
|
|
17
18
|
.filter(([key]) => !props.includes(key))
|
|
18
19
|
.reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {});
|
|
19
20
|
exports.omit = omit;
|
|
21
|
+
/* https://github.com/streamich/react-use/blob/master/src/useEvent.ts */
|
|
22
|
+
const useEventListener = (name, handler, target = window) => {
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
if (!target) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(name, handler);
|
|
28
|
+
return () => {
|
|
29
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(name, handler);
|
|
30
|
+
};
|
|
31
|
+
}, [name, handler, target]);
|
|
32
|
+
};
|
|
33
|
+
exports.useEventListener = useEventListener;
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { InputHTMLAttributes } from "react";
|
|
2
2
|
import { FormFieldProps } from "../useFormField";
|
|
3
|
-
|
|
4
|
-
import { SearchFieldClearButtonType } from "./SearchFieldClearButton";
|
|
5
|
-
import { SearchFieldInputType } from "./SearchFieldInput";
|
|
6
|
-
export interface SearchFieldContextProps {
|
|
7
|
-
inputProps: {
|
|
8
|
-
id: string;
|
|
9
|
-
"aria-invalid": boolean;
|
|
10
|
-
"aria-describedby"?: string;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
};
|
|
13
|
-
size?: "medium" | "small";
|
|
14
|
-
}
|
|
15
|
-
export declare const SearchFieldContext: React.Context<SearchFieldContextProps | null>;
|
|
16
|
-
export interface SearchFieldProps extends FormFieldProps, React.HTMLAttributes<HTMLDivElement> {
|
|
17
|
-
/**
|
|
18
|
-
* SearchFieldInput & SearchFieldButton
|
|
19
|
-
*/
|
|
20
|
-
children: React.ReactNode;
|
|
3
|
+
export interface SearchFieldProps extends Omit<FormFieldProps, "error" | "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
|
|
21
4
|
/**
|
|
22
5
|
* If enabled shows the label and description for screenreaders only
|
|
23
6
|
*/
|
|
@@ -26,11 +9,28 @@ export interface SearchFieldProps extends FormFieldProps, React.HTMLAttributes<H
|
|
|
26
9
|
* SearchField label
|
|
27
10
|
*/
|
|
28
11
|
label: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Inverts color theme
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
inverted?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Customize aria-label on clear button
|
|
19
|
+
* @default "Slett tekst i felt"
|
|
20
|
+
*/
|
|
21
|
+
clearButtonLabel?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Callback for when user manually clears input with button or Escape
|
|
24
|
+
*/
|
|
25
|
+
onClear?: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Callback for value in input after change
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (value: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Toggles display of "clear"-button when there is text in field
|
|
32
|
+
*/
|
|
33
|
+
clearButton?: boolean;
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
Button: SearchFieldButtonType;
|
|
32
|
-
Clear: SearchFieldClearButtonType;
|
|
33
|
-
Input: SearchFieldInputType;
|
|
34
|
-
}
|
|
35
|
-
declare const SearchField: SearchFieldComponent;
|
|
35
|
+
declare const SearchField: React.ForwardRefExoticComponent<SearchFieldProps & React.RefAttributes<HTMLInputElement>>;
|
|
36
36
|
export default SearchField;
|
|
@@ -9,37 +9,59 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
+
import { Close, Search } from "@navikt/ds-icons";
|
|
12
13
|
import cl from "classnames";
|
|
13
|
-
import React, { forwardRef } from "react";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import SearchFieldButton from "./SearchFieldButton";
|
|
18
|
-
import SearchFieldClearButton from "./SearchFieldClearButton";
|
|
19
|
-
import SearchFieldInput from "./SearchFieldInput";
|
|
20
|
-
export const SearchFieldContext = React.createContext(null);
|
|
14
|
+
import React, { forwardRef, useCallback, useEffect, useRef, useState, } from "react";
|
|
15
|
+
import mergeRefs from "react-merge-refs";
|
|
16
|
+
import { BodyShort, Label, omit, useEventListener } from "../..";
|
|
17
|
+
import { useSearchField } from "./useSearchField";
|
|
21
18
|
const SearchField = forwardRef((props, ref) => {
|
|
22
|
-
const { inputProps,
|
|
23
|
-
const { className, hideLabel,
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const { inputProps, size, inputDescriptionId } = useSearchField(props, "searchfield");
|
|
20
|
+
const { className, hideLabel, label, description, value, clearButtonLabel, onClear, inverted = false, clearButton = true } = props, rest = __rest(props, ["className", "hideLabel", "label", "description", "value", "clearButtonLabel", "onClear", "inverted", "clearButton"]);
|
|
21
|
+
const [controlledValue, setControlledValue] = useState(value !== null && value !== void 0 ? value : "");
|
|
22
|
+
const searchRef = useRef(null);
|
|
23
|
+
const mergedRef = mergeRefs([searchRef, ref]);
|
|
24
|
+
const [wrapperRef, setWrapperRef] = useState(null);
|
|
25
|
+
const handleChange = useCallback((v) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (searchRef.current && value === undefined) {
|
|
28
|
+
searchRef.current.value = v;
|
|
29
|
+
setControlledValue(v);
|
|
30
|
+
}
|
|
31
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v);
|
|
32
|
+
}, [props, value]);
|
|
33
|
+
const handleClear = useCallback(() => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
onClear === null || onClear === void 0 ? void 0 : onClear();
|
|
36
|
+
handleChange("");
|
|
37
|
+
searchRef.current && ((_b = (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
38
|
+
}, [handleChange, onClear]);
|
|
39
|
+
useEventListener("keydown", useCallback((e) => {
|
|
40
|
+
if (e.key === "Escape") {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
handleClear();
|
|
43
|
+
}
|
|
44
|
+
}, [handleClear]), wrapperRef);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
value !== undefined && setControlledValue(value);
|
|
47
|
+
}, [value]);
|
|
48
|
+
return (React.createElement("div", { ref: setWrapperRef, className: cl(className, "navds-form-field", `navds-form-field--${size !== null && size !== void 0 ? size : "medium"}`, "navds-search-field", {
|
|
26
49
|
"navds-search-field--disabled": !!inputProps.disabled,
|
|
27
|
-
|
|
50
|
+
"navds-search-field--inverted": inverted,
|
|
51
|
+
}) },
|
|
28
52
|
React.createElement(Label, { htmlFor: inputProps.id, size: size, as: "label", className: cl("navds-text-field__label", {
|
|
29
|
-
"sr-only": hideLabel,
|
|
53
|
+
"navds-sr-only": hideLabel,
|
|
30
54
|
}) }, label),
|
|
31
55
|
!!description && (React.createElement(BodyShort, { as: "div", className: cl("navds-text-field__description", {
|
|
32
|
-
"sr-only": hideLabel,
|
|
56
|
+
"navds-sr-only": hideLabel,
|
|
33
57
|
}), id: inputDescriptionId, size: size }, description)),
|
|
34
|
-
React.createElement("div", { className: "navds-search-field__input-wrapper" },
|
|
35
|
-
React.createElement(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
React.createElement("div", { "data-value": !!controlledValue, className: "navds-search-field__input-wrapper" },
|
|
59
|
+
React.createElement("span", { className: "navds-search-field__input-icon" },
|
|
60
|
+
React.createElement(Search, { "aria-hidden": true })),
|
|
61
|
+
React.createElement("input", Object.assign({ ref: mergedRef }, omit(rest, ["size"]), inputProps, (props.value !== undefined && { value: props.value }), { onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: cl(className, "navds-search-field__input", "navds-text-field__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`) })),
|
|
62
|
+
controlledValue && clearButton && (React.createElement("button", { onClick: () => handleClear(), className: "navds-search-field__clear-button" },
|
|
63
|
+
React.createElement("span", { className: "navds-sr-only" }, clearButtonLabel ? clearButtonLabel : "Slett tekst i felt"),
|
|
64
|
+
React.createElement(Close, { "aria-hidden": true }))))));
|
|
40
65
|
});
|
|
41
|
-
SearchField.Button = SearchFieldButton;
|
|
42
|
-
SearchField.Clear = SearchFieldClearButton;
|
|
43
|
-
SearchField.Input = SearchFieldInput;
|
|
44
66
|
export default SearchField;
|
|
45
67
|
//# sourceMappingURL=SearchField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchField.js","sourceRoot":"","sources":["../../../src/form/search-field/SearchField.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SearchField.js","sourceRoot":"","sources":["../../../src/form/search-field/SearchField.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,UAAU,EAEV,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAqClD,MAAM,WAAW,GAAG,UAAU,CAC5B,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACb,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,kBAAkB,EAAE,GAAG,cAAc,CAC7D,KAAK,EACL,aAAa,CACd,CAAC;IAEF,MAAM,EACJ,SAAS,EACT,SAAS,EACT,KAAK,EACL,WAAW,EACX,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,WAAW,GAAG,IAAI,KAEhB,KAAK,EADJ,IAAI,U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,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC7C,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,WAAW,EAChB,SAAS,EAAE,EAAE,CACX,SAAS,EACT,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,QAAQ,EAAE,CACjC,IACD;YACD,eAAe,IAAI,WAAW,IAAI,CACjC,gCACE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAC5B,SAAS,EAAC,kCAAkC;gBAE5C,8BAAM,SAAS,EAAC,eAAe,IAC5B,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,oBAAoB,CACtD;gBACP,oBAAC,KAAK,0BAAe,CACd,CACV,CACG,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FormFieldProps } from "../useFormField";
|
|
2
|
+
export declare const useSearchField: (props: FormFieldProps, prefix: string) => {
|
|
3
|
+
inputDescriptionId: string;
|
|
4
|
+
size: "small" | "medium";
|
|
5
|
+
inputProps: {
|
|
6
|
+
id: string;
|
|
7
|
+
"aria-describedby": string | undefined;
|
|
8
|
+
disabled: boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import cl from "classnames";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { useId } from "../../index";
|
|
4
|
+
import { FieldsetContext } from "../index";
|
|
5
|
+
export const useSearchField = (props, prefix) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const { size } = props;
|
|
8
|
+
const fieldset = useContext(FieldsetContext);
|
|
9
|
+
const genId = useId();
|
|
10
|
+
const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${prefix}-${genId}`;
|
|
11
|
+
const inputDescriptionId = `${prefix}-description-${genId}`;
|
|
12
|
+
const disabled = (fieldset === null || fieldset === void 0 ? void 0 : fieldset.disabled) || props.disabled;
|
|
13
|
+
return {
|
|
14
|
+
inputDescriptionId,
|
|
15
|
+
size: (_b = size !== null && size !== void 0 ? size : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _b !== void 0 ? _b : "medium",
|
|
16
|
+
inputProps: {
|
|
17
|
+
id,
|
|
18
|
+
"aria-describedby": cl(props["aria-describedby"], {
|
|
19
|
+
[inputDescriptionId]: !!(props === null || props === void 0 ? void 0 : props.description),
|
|
20
|
+
}) || undefined,
|
|
21
|
+
disabled,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useSearchField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearchField.js","sourceRoot":"","sources":["../../../src/form/search-field/useSearchField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAqB,EAAE,MAAc,EAAE,EAAE;;IACtE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAEvB,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;IAEtB,MAAM,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;IAC5C,MAAM,kBAAkB,GAAG,GAAG,MAAM,gBAAgB,KAAK,EAAE,CAAC;IAE5D,MAAM,QAAQ,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,KAAI,KAAK,CAAC,QAAQ,CAAC;IAEtD,OAAO;QACL,kBAAkB;QAClB,IAAI,EAAE,MAAA,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,QAAQ;QACxC,UAAU,EAAE;YACV,EAAE;YACF,kBAAkB,EAChB,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;gBAC5B,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAA;aAC3C,CAAC,IAAI,SAAS;YACjB,QAAQ;SACT;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/esm/util/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export * from "./OverridableComponent";
|
|
2
2
|
export * from "./useId";
|
|
3
3
|
export declare const omit: (obj: object, props: string[]) => {};
|
|
4
|
+
export interface ListenerT {
|
|
5
|
+
addEventListener(name: string, handler: (event?: any) => void, ...args: any[]): any;
|
|
6
|
+
removeEventListener(name: string, handler: (event?: any) => void, ...args: any[]): any;
|
|
7
|
+
}
|
|
8
|
+
export declare const useEventListener: <T extends ListenerT>(name: Parameters<ListenerT["addEventListener"]>[0], handler: Parameters<ListenerT["addEventListener"]>[1], target?: Window | T | null) => void;
|
package/esm/util/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
1
2
|
export * from "./OverridableComponent";
|
|
2
3
|
export * from "./useId";
|
|
3
4
|
export const omit = (obj, props) => Object.entries(obj)
|
|
4
5
|
.filter(([key]) => !props.includes(key))
|
|
5
6
|
.reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {});
|
|
7
|
+
/* https://github.com/streamich/react-use/blob/master/src/useEvent.ts */
|
|
8
|
+
export const useEventListener = (name, handler, target = window) => {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!target) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(name, handler);
|
|
14
|
+
return () => {
|
|
15
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(name, handler);
|
|
16
|
+
};
|
|
17
|
+
}, [name, handler, target]);
|
|
18
|
+
};
|
|
6
19
|
//# sourceMappingURL=index.js.map
|
package/esm/util/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC;AAExB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,KAAe,EAAE,EAAE,CACnD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;KAChB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KACvC,MAAM,CACL,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,iCAClB,GAAG,KACN,CAAC,GAAG,CAAC,EAAE,KAAK,IACZ,EACF,EAAE,CACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC;AAExB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,KAAe,EAAE,EAAE,CACnD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;KAChB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KACvC,MAAM,CACL,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,iCAClB,GAAG,KACN,CAAC,GAAG,CAAC,EAAE,KAAK,IACZ,EACF,EAAE,CACH,CAAC;AAgBN,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAkD,EAClD,OAAqD,EACrD,SAA4B,MAAM,EAC5B,EAAE;IACR,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE;YACX,OAAO;SACR;QACD,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,GAAG,EAAE;YACV,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.10-next.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NAV designsystem react components",
|
|
6
6
|
"author": "NAV Designsystem team",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@types/react": "^17.0.30",
|
|
65
65
|
"react": "^17.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "d9174b43520c8691e6f539ed7c76554fb50dadd0"
|
|
68
68
|
}
|