@navikt/ds-react 0.19.16 → 0.19.17
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/_docs.json +38 -0
- package/cjs/form/search/Search.js +6 -4
- package/esm/form/search/Search.d.ts +1 -1
- package/esm/form/search/Search.js +7 -5
- package/esm/form/search/Search.js.map +1 -1
- package/package.json +2 -2
- package/src/form/search/Search.tsx +19 -6
- package/src/form/search/search.stories.tsx +21 -0
- package/cjs/form/search/useSearch.js +0 -31
- package/esm/form/search/useSearch.d.ts +0 -10
- package/esm/form/search/useSearch.js +0 -25
- package/esm/form/search/useSearch.js.map +0 -1
- package/src/form/search/useSearch.ts +0 -31
package/_docs.json
CHANGED
|
@@ -9019,6 +9019,44 @@
|
|
|
9019
9019
|
"name": "\"primary\" | \"secondary\" | \"simple\""
|
|
9020
9020
|
}
|
|
9021
9021
|
},
|
|
9022
|
+
"error": {
|
|
9023
|
+
"defaultValue": null,
|
|
9024
|
+
"description": "Error message for element",
|
|
9025
|
+
"name": "error",
|
|
9026
|
+
"parent": {
|
|
9027
|
+
"fileName": "react/src/form/useFormField.ts",
|
|
9028
|
+
"name": "FormFieldProps"
|
|
9029
|
+
},
|
|
9030
|
+
"declarations": [
|
|
9031
|
+
{
|
|
9032
|
+
"fileName": "react/src/form/useFormField.ts",
|
|
9033
|
+
"name": "FormFieldProps"
|
|
9034
|
+
}
|
|
9035
|
+
],
|
|
9036
|
+
"required": false,
|
|
9037
|
+
"type": {
|
|
9038
|
+
"name": "ReactNode"
|
|
9039
|
+
}
|
|
9040
|
+
},
|
|
9041
|
+
"errorId": {
|
|
9042
|
+
"defaultValue": null,
|
|
9043
|
+
"description": "Override internal errorId",
|
|
9044
|
+
"name": "errorId",
|
|
9045
|
+
"parent": {
|
|
9046
|
+
"fileName": "react/src/form/useFormField.ts",
|
|
9047
|
+
"name": "FormFieldProps"
|
|
9048
|
+
},
|
|
9049
|
+
"declarations": [
|
|
9050
|
+
{
|
|
9051
|
+
"fileName": "react/src/form/useFormField.ts",
|
|
9052
|
+
"name": "FormFieldProps"
|
|
9053
|
+
}
|
|
9054
|
+
],
|
|
9055
|
+
"required": false,
|
|
9056
|
+
"type": {
|
|
9057
|
+
"name": "string"
|
|
9058
|
+
}
|
|
9059
|
+
},
|
|
9022
9060
|
"size": {
|
|
9023
9061
|
"defaultValue": null,
|
|
9024
9062
|
"description": "Changes font-size, padding and gaps",
|
|
@@ -43,11 +43,11 @@ const classnames_1 = __importDefault(require("classnames"));
|
|
|
43
43
|
const react_1 = __importStar(require("react"));
|
|
44
44
|
const react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
45
45
|
const __1 = require("../..");
|
|
46
|
+
const useFormField_1 = require("../useFormField");
|
|
46
47
|
const SearchButton_1 = __importDefault(require("./SearchButton"));
|
|
47
|
-
const useSearch_1 = require("./useSearch");
|
|
48
48
|
exports.SearchContext = react_1.default.createContext(null);
|
|
49
49
|
exports.Search = (0, react_1.forwardRef)((props, ref) => {
|
|
50
|
-
const { inputProps, size = "medium", inputDescriptionId, } = (0,
|
|
50
|
+
const { inputProps, size = "medium", inputDescriptionId, errorId, showErrorMsg, hasError, } = (0, useFormField_1.useFormField)(props, "searchfield");
|
|
51
51
|
const { className, hideLabel = true, label, description, value, clearButtonLabel, onClear, clearButton = true, children, variant = "primary", defaultValue, onChange } = props, rest = __rest(props, ["className", "hideLabel", "label", "description", "value", "clearButtonLabel", "onClear", "clearButton", "children", "variant", "defaultValue", "onChange"]);
|
|
52
52
|
const searchRef = (0, react_1.useRef)(null);
|
|
53
53
|
const mergedRef = (0, react_merge_refs_1.default)([searchRef, ref]);
|
|
@@ -70,6 +70,7 @@ exports.Search = (0, react_1.forwardRef)((props, ref) => {
|
|
|
70
70
|
}
|
|
71
71
|
}, [handleClear]), wrapperRef);
|
|
72
72
|
return (react_1.default.createElement("div", { ref: setWrapperRef, className: (0, classnames_1.default)(className, "navds-form-field", `navds-form-field--${size}`, "navds-search", {
|
|
73
|
+
"navds-search--error": hasError,
|
|
73
74
|
"navds-search--disabled": !!inputProps.disabled,
|
|
74
75
|
}) },
|
|
75
76
|
react_1.default.createElement(__1.Label, { htmlFor: inputProps.id, size: size, as: "label", className: (0, classnames_1.default)("navds-form-field__label", {
|
|
@@ -81,7 +82,7 @@ exports.Search = (0, react_1.forwardRef)((props, ref) => {
|
|
|
81
82
|
react_1.default.createElement("div", { className: "navds-search__wrapper" },
|
|
82
83
|
react_1.default.createElement("div", { className: "navds-search__wrapper-inner" },
|
|
83
84
|
variant === "simple" && (react_1.default.createElement(ds_icons_1.Search, { "aria-hidden": true, className: "navds-search__search-icon" })),
|
|
84
|
-
react_1.default.createElement("input", Object.assign({ ref: mergedRef }, (0, __1.omit)(rest, ["size"]), inputProps, { value: value !== null && value !== void 0 ? value : internalValue, onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: (0, classnames_1.default)(className, "navds-search__input", `navds-search__input--${variant}`, "navds-text-field__input", "navds-body-short", `navds-body-${size}`) })),
|
|
85
|
+
react_1.default.createElement("input", Object.assign({ ref: mergedRef }, (0, __1.omit)(rest, ["error", "errorId", "size"]), inputProps, { value: value !== null && value !== void 0 ? value : internalValue, onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: (0, classnames_1.default)(className, "navds-search__input", `navds-search__input--${variant}`, "navds-text-field__input", "navds-body-short", `navds-body-${size}`) })),
|
|
85
86
|
(value !== null && value !== void 0 ? value : internalValue) && clearButton && (react_1.default.createElement("button", { type: "button", onClick: (e) => handleClear({ trigger: "Click", event: e }), className: "navds-search__button-clear" },
|
|
86
87
|
react_1.default.createElement("span", { className: "navds-sr-only" }, clearButtonLabel ? clearButtonLabel : "Tøm"),
|
|
87
88
|
react_1.default.createElement(ds_icons_1.Close, { "aria-hidden": true })))),
|
|
@@ -89,7 +90,8 @@ exports.Search = (0, react_1.forwardRef)((props, ref) => {
|
|
|
89
90
|
size,
|
|
90
91
|
disabled: inputProps.disabled,
|
|
91
92
|
variant,
|
|
92
|
-
} }, children ? children : variant !== "simple" && react_1.default.createElement(SearchButton_1.default, null)))
|
|
93
|
+
} }, children ? children : variant !== "simple" && react_1.default.createElement(SearchButton_1.default, null))),
|
|
94
|
+
react_1.default.createElement("div", { className: "navds-form-field__error", id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (react_1.default.createElement(__1.ErrorMessage, { size: size }, props.error)))));
|
|
93
95
|
});
|
|
94
96
|
exports.Search.Button = SearchButton_1.default;
|
|
95
97
|
exports.default = exports.Search;
|
|
@@ -8,7 +8,7 @@ export declare type SearchClearEvent = {
|
|
|
8
8
|
trigger: "Escape";
|
|
9
9
|
event: React.KeyboardEvent<HTMLDivElement>;
|
|
10
10
|
};
|
|
11
|
-
export interface SearchProps extends
|
|
11
|
+
export interface SearchProps extends FormFieldProps, Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
|
|
12
12
|
children?: React.ReactNode;
|
|
13
13
|
/**
|
|
14
14
|
* Search label
|
|
@@ -13,12 +13,12 @@ import { Close, Search as SearchIcon } from "@navikt/ds-icons";
|
|
|
13
13
|
import cl from "classnames";
|
|
14
14
|
import React, { forwardRef, useCallback, useRef, useState, } from "react";
|
|
15
15
|
import mergeRefs from "react-merge-refs";
|
|
16
|
-
import { BodyShort, Label, omit, useEventListener } from "../..";
|
|
16
|
+
import { BodyShort, ErrorMessage, Label, omit, useEventListener } from "../..";
|
|
17
|
+
import { useFormField } from "../useFormField";
|
|
17
18
|
import SearchButton from "./SearchButton";
|
|
18
|
-
import { useSearch } from "./useSearch";
|
|
19
19
|
export const SearchContext = React.createContext(null);
|
|
20
20
|
export const Search = forwardRef((props, ref) => {
|
|
21
|
-
const { inputProps, size = "medium", inputDescriptionId, } =
|
|
21
|
+
const { inputProps, size = "medium", inputDescriptionId, errorId, showErrorMsg, hasError, } = useFormField(props, "searchfield");
|
|
22
22
|
const { className, hideLabel = true, label, description, value, clearButtonLabel, onClear, clearButton = true, children, variant = "primary", defaultValue, onChange } = props, rest = __rest(props, ["className", "hideLabel", "label", "description", "value", "clearButtonLabel", "onClear", "clearButton", "children", "variant", "defaultValue", "onChange"]);
|
|
23
23
|
const searchRef = useRef(null);
|
|
24
24
|
const mergedRef = mergeRefs([searchRef, ref]);
|
|
@@ -41,6 +41,7 @@ export const Search = forwardRef((props, ref) => {
|
|
|
41
41
|
}
|
|
42
42
|
}, [handleClear]), wrapperRef);
|
|
43
43
|
return (React.createElement("div", { ref: setWrapperRef, className: cl(className, "navds-form-field", `navds-form-field--${size}`, "navds-search", {
|
|
44
|
+
"navds-search--error": hasError,
|
|
44
45
|
"navds-search--disabled": !!inputProps.disabled,
|
|
45
46
|
}) },
|
|
46
47
|
React.createElement(Label, { htmlFor: inputProps.id, size: size, as: "label", className: cl("navds-form-field__label", {
|
|
@@ -52,7 +53,7 @@ export const Search = forwardRef((props, ref) => {
|
|
|
52
53
|
React.createElement("div", { className: "navds-search__wrapper" },
|
|
53
54
|
React.createElement("div", { className: "navds-search__wrapper-inner" },
|
|
54
55
|
variant === "simple" && (React.createElement(SearchIcon, { "aria-hidden": true, className: "navds-search__search-icon" })),
|
|
55
|
-
React.createElement("input", Object.assign({ ref: mergedRef }, omit(rest, ["size"]), inputProps, { value: value !== null && value !== void 0 ? value : internalValue, onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: cl(className, "navds-search__input", `navds-search__input--${variant}`, "navds-text-field__input", "navds-body-short", `navds-body-${size}`) })),
|
|
56
|
+
React.createElement("input", Object.assign({ ref: mergedRef }, omit(rest, ["error", "errorId", "size"]), inputProps, { value: value !== null && value !== void 0 ? value : internalValue, onChange: (e) => handleChange(e.target.value), type: "search", role: "searchbox", className: cl(className, "navds-search__input", `navds-search__input--${variant}`, "navds-text-field__input", "navds-body-short", `navds-body-${size}`) })),
|
|
56
57
|
(value !== null && value !== void 0 ? value : internalValue) && clearButton && (React.createElement("button", { type: "button", onClick: (e) => handleClear({ trigger: "Click", event: e }), className: "navds-search__button-clear" },
|
|
57
58
|
React.createElement("span", { className: "navds-sr-only" }, clearButtonLabel ? clearButtonLabel : "Tøm"),
|
|
58
59
|
React.createElement(Close, { "aria-hidden": true })))),
|
|
@@ -60,7 +61,8 @@ export const Search = forwardRef((props, ref) => {
|
|
|
60
61
|
size,
|
|
61
62
|
disabled: inputProps.disabled,
|
|
62
63
|
variant,
|
|
63
|
-
} }, children ? children : variant !== "simple" && React.createElement(SearchButton, null)))
|
|
64
|
+
} }, children ? children : variant !== "simple" && React.createElement(SearchButton, null))),
|
|
65
|
+
React.createElement("div", { className: "navds-form-field__error", id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size }, props.error)))));
|
|
64
66
|
});
|
|
65
67
|
Search.Button = SearchButton;
|
|
66
68
|
export default Search;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sourceRoot":"","sources":["../../../src/form/search/Search.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,UAAU,EAEV,WAAW,EACX,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;
|
|
1
|
+
{"version":3,"file":"Search.js","sourceRoot":"","sources":["../../../src/form/search/Search.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,UAAU,EAEV,WAAW,EACX,MAAM,EACN,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CACV,CACG;YACN,oBAAC,aAAa,CAAC,QAAQ,IACrB,KAAK,EAAE;oBACL,IAAI;oBACJ,QAAQ,EAAE,UAAU,CAAC,QAAQ;oBAC7B,OAAO;iBACR,IAEA,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,oBAAC,YAAY,OAAG,CACxC,CACrB;QACN,6BACE,SAAS,EAAC,yBAAyB,EACnC,EAAE,EAAE,OAAO,mBACG,oBAAoB,eACxB,QAAQ,IAEjB,YAAY,IAAI,CACf,oBAAC,YAAY,IAAC,IAAI,EAAE,IAAI,IAAG,KAAK,CAAC,KAAK,CAAgB,CACvD,CACG,CACF,CACP,CAAC;AACJ,CAAC,CACiB,CAAC;AAErB,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC;AAE7B,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.17",
|
|
4
4
|
"description": "NAV designsystem react components",
|
|
5
5
|
"author": "NAV Designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"@types/react": "^17.0.30 || ^18.0.0",
|
|
77
77
|
"react": "^17.0.0 || ^18.0.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "c47048cc2d6af3c5f04a22420790c38ac2884040"
|
|
80
80
|
}
|
|
@@ -8,10 +8,9 @@ import React, {
|
|
|
8
8
|
useState,
|
|
9
9
|
} from "react";
|
|
10
10
|
import mergeRefs from "react-merge-refs";
|
|
11
|
-
import { BodyShort, Label, omit, useEventListener } from "../..";
|
|
12
|
-
import { FormFieldProps } from "../useFormField";
|
|
11
|
+
import { BodyShort, ErrorMessage, Label, omit, useEventListener } from "../..";
|
|
12
|
+
import { FormFieldProps, useFormField } from "../useFormField";
|
|
13
13
|
import SearchButton, { SearchButtonType } from "./SearchButton";
|
|
14
|
-
import { useSearch } from "./useSearch";
|
|
15
14
|
|
|
16
15
|
export type SearchClearEvent =
|
|
17
16
|
| {
|
|
@@ -21,7 +20,7 @@ export type SearchClearEvent =
|
|
|
21
20
|
| { trigger: "Escape"; event: React.KeyboardEvent<HTMLDivElement> };
|
|
22
21
|
|
|
23
22
|
export interface SearchProps
|
|
24
|
-
extends
|
|
23
|
+
extends FormFieldProps,
|
|
25
24
|
Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
|
|
26
25
|
children?: React.ReactNode;
|
|
27
26
|
/**
|
|
@@ -82,7 +81,10 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
82
81
|
inputProps,
|
|
83
82
|
size = "medium",
|
|
84
83
|
inputDescriptionId,
|
|
85
|
-
|
|
84
|
+
errorId,
|
|
85
|
+
showErrorMsg,
|
|
86
|
+
hasError,
|
|
87
|
+
} = useFormField(props, "searchfield");
|
|
86
88
|
|
|
87
89
|
const {
|
|
88
90
|
className,
|
|
@@ -146,6 +148,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
146
148
|
`navds-form-field--${size}`,
|
|
147
149
|
"navds-search",
|
|
148
150
|
{
|
|
151
|
+
"navds-search--error": hasError,
|
|
149
152
|
"navds-search--disabled": !!inputProps.disabled,
|
|
150
153
|
}
|
|
151
154
|
)}
|
|
@@ -179,7 +182,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
179
182
|
)}
|
|
180
183
|
<input
|
|
181
184
|
ref={mergedRef}
|
|
182
|
-
{...omit(rest, ["size"])}
|
|
185
|
+
{...omit(rest, ["error", "errorId", "size"])}
|
|
183
186
|
{...inputProps}
|
|
184
187
|
value={value ?? internalValue}
|
|
185
188
|
onChange={(e) => handleChange(e.target.value)}
|
|
@@ -217,6 +220,16 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
|
|
217
220
|
{children ? children : variant !== "simple" && <SearchButton />}
|
|
218
221
|
</SearchContext.Provider>
|
|
219
222
|
</div>
|
|
223
|
+
<div
|
|
224
|
+
className="navds-form-field__error"
|
|
225
|
+
id={errorId}
|
|
226
|
+
aria-relevant="additions removals"
|
|
227
|
+
aria-live="polite"
|
|
228
|
+
>
|
|
229
|
+
{showErrorMsg && (
|
|
230
|
+
<ErrorMessage size={size}>{props.error}</ErrorMessage>
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
220
233
|
</div>
|
|
221
234
|
);
|
|
222
235
|
}
|
|
@@ -23,6 +23,11 @@ export default {
|
|
|
23
23
|
options: ["primary", "secondary", "simple"],
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
|
+
error: {
|
|
27
|
+
control: {
|
|
28
|
+
type: "text",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
26
31
|
},
|
|
27
32
|
} as Meta;
|
|
28
33
|
|
|
@@ -38,6 +43,7 @@ export const Default = (props) => {
|
|
|
38
43
|
clearButton={props.clearButton}
|
|
39
44
|
variant={props.variant}
|
|
40
45
|
hideLabel={props.hideLabel}
|
|
46
|
+
error={props.error}
|
|
41
47
|
/>
|
|
42
48
|
</div>
|
|
43
49
|
);
|
|
@@ -79,6 +85,21 @@ export const Variants = () => (
|
|
|
79
85
|
</div>
|
|
80
86
|
);
|
|
81
87
|
|
|
88
|
+
export const ErrorVariants = () => (
|
|
89
|
+
<div className="rowgap">
|
|
90
|
+
<div className="colgap">
|
|
91
|
+
<Search error="errormsg" label="Søk" />
|
|
92
|
+
<Search error="errormsg" label="Søk" variant="secondary" />
|
|
93
|
+
<Search error="errormsg" label="Søk" variant="simple" />
|
|
94
|
+
</div>
|
|
95
|
+
<div className="colgap" data-theme="dark">
|
|
96
|
+
<Search error="errormsg" label="Søk" />
|
|
97
|
+
<Search error="errormsg" label="Søk" variant="secondary" />
|
|
98
|
+
<Search error="errormsg" label="Søk" variant="simple" />
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
|
|
82
103
|
export const Placeholder = () => (
|
|
83
104
|
<div className="rowgap">
|
|
84
105
|
<div className="colgap">
|
|
@@ -1,31 +0,0 @@
|
|
|
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.useSearch = 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 useSearch = (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.useSearch = useSearch;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FormFieldProps } from "../useFormField";
|
|
2
|
-
export declare const useSearch: (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
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import cl from "classnames";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { useId } from "../../index";
|
|
4
|
-
import { FieldsetContext } from "../index";
|
|
5
|
-
export const useSearch = (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=useSearch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../../../src/form/search/useSearch.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,SAAS,GAAG,CAAC,KAAqB,EAAE,MAAc,EAAE,EAAE;;IACjE,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"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import cl from "classnames";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { useId } from "../../index";
|
|
4
|
-
import { FieldsetContext } from "../index";
|
|
5
|
-
import { FormFieldProps } from "../useFormField";
|
|
6
|
-
|
|
7
|
-
export const useSearch = (props: FormFieldProps, prefix: string) => {
|
|
8
|
-
const { size } = props;
|
|
9
|
-
|
|
10
|
-
const fieldset = useContext(FieldsetContext);
|
|
11
|
-
|
|
12
|
-
const genId = useId();
|
|
13
|
-
|
|
14
|
-
const id = props.id ?? `${prefix}-${genId}`;
|
|
15
|
-
const inputDescriptionId = `${prefix}-description-${genId}`;
|
|
16
|
-
|
|
17
|
-
const disabled = fieldset?.disabled || props.disabled;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
inputDescriptionId,
|
|
21
|
-
size: size ?? fieldset?.size ?? "medium",
|
|
22
|
-
inputProps: {
|
|
23
|
-
id,
|
|
24
|
-
"aria-describedby":
|
|
25
|
-
cl(props["aria-describedby"], {
|
|
26
|
-
[inputDescriptionId]: !!props?.description,
|
|
27
|
-
}) || undefined,
|
|
28
|
-
disabled,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
};
|