@navikt/ds-react 4.9.0 → 4.10.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/_docs.json +67 -4
- package/cjs/button/Button.js +1 -1
- package/cjs/form/combobox/ComboboxWrapper.js +5 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +6 -2
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +7 -5
- package/cjs/link/Link.js +13 -2
- package/cjs/util/RandomIcon.js +37 -0
- package/esm/button/Button.js +1 -1
- package/esm/button/Button.js.map +1 -1
- package/esm/form/combobox/ComboboxWrapper.js +6 -2
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +6 -2
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +7 -5
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/esm/form/combobox/types.d.ts +3 -2
- package/esm/link/Link.d.ts +25 -0
- package/esm/link/Link.js +13 -2
- package/esm/link/Link.js.map +1 -1
- package/esm/util/RandomIcon.d.ts +2 -0
- package/esm/util/RandomIcon.js +8 -0
- package/esm/util/RandomIcon.js.map +1 -0
- package/package.json +2 -2
- package/src/button/Button.tsx +1 -5
- package/src/button/button.stories.tsx +6 -4
- package/src/form/combobox/ComboboxWrapper.tsx +6 -1
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +6 -1
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +8 -8
- package/src/form/combobox/combobox.stories.tsx +2 -0
- package/src/form/combobox/types.ts +7 -2
- package/src/link/Link.tsx +47 -3
- package/src/link/link.stories.tsx +127 -13
- package/src/util/RandomIcon.tsx +9 -0
package/_docs.json
CHANGED
|
@@ -5154,6 +5154,69 @@
|
|
|
5154
5154
|
"filePath": "src/link/Link.tsx",
|
|
5155
5155
|
"displayName": "Link",
|
|
5156
5156
|
"props": {
|
|
5157
|
+
"underline": {
|
|
5158
|
+
"defaultValue": {
|
|
5159
|
+
"value": "true"
|
|
5160
|
+
},
|
|
5161
|
+
"description": "Inverts when the underline appears. If this is false,\nthe underline does not appear by default, but does appear when the link is hovered.\nThis makes it more suitable for use when inlined in text.",
|
|
5162
|
+
"name": "underline",
|
|
5163
|
+
"parent": {
|
|
5164
|
+
"fileName": "src/link/Link.tsx",
|
|
5165
|
+
"name": "LinkProps"
|
|
5166
|
+
},
|
|
5167
|
+
"declarations": [
|
|
5168
|
+
{
|
|
5169
|
+
"fileName": "src/link/Link.tsx",
|
|
5170
|
+
"name": "LinkProps"
|
|
5171
|
+
}
|
|
5172
|
+
],
|
|
5173
|
+
"required": false,
|
|
5174
|
+
"type": {
|
|
5175
|
+
"name": "boolean"
|
|
5176
|
+
}
|
|
5177
|
+
},
|
|
5178
|
+
"inlineText": {
|
|
5179
|
+
"defaultValue": {
|
|
5180
|
+
"value": "false"
|
|
5181
|
+
},
|
|
5182
|
+
"description": "Renders link with `display: inline` for better wrapping in text.",
|
|
5183
|
+
"name": "inlineText",
|
|
5184
|
+
"parent": {
|
|
5185
|
+
"fileName": "src/link/Link.tsx",
|
|
5186
|
+
"name": "LinkProps"
|
|
5187
|
+
},
|
|
5188
|
+
"declarations": [
|
|
5189
|
+
{
|
|
5190
|
+
"fileName": "src/link/Link.tsx",
|
|
5191
|
+
"name": "LinkProps"
|
|
5192
|
+
}
|
|
5193
|
+
],
|
|
5194
|
+
"required": false,
|
|
5195
|
+
"type": {
|
|
5196
|
+
"name": "boolean"
|
|
5197
|
+
}
|
|
5198
|
+
},
|
|
5199
|
+
"variant": {
|
|
5200
|
+
"defaultValue": {
|
|
5201
|
+
"value": "action"
|
|
5202
|
+
},
|
|
5203
|
+
"description": "Variant of the component to use.",
|
|
5204
|
+
"name": "variant",
|
|
5205
|
+
"parent": {
|
|
5206
|
+
"fileName": "src/link/Link.tsx",
|
|
5207
|
+
"name": "LinkProps"
|
|
5208
|
+
},
|
|
5209
|
+
"declarations": [
|
|
5210
|
+
{
|
|
5211
|
+
"fileName": "src/link/Link.tsx",
|
|
5212
|
+
"name": "LinkProps"
|
|
5213
|
+
}
|
|
5214
|
+
],
|
|
5215
|
+
"required": false,
|
|
5216
|
+
"type": {
|
|
5217
|
+
"name": "\"action\" | \"neutral\" | \"subtle\""
|
|
5218
|
+
}
|
|
5219
|
+
},
|
|
5157
5220
|
"children": {
|
|
5158
5221
|
"defaultValue": null,
|
|
5159
5222
|
"description": "Link text",
|
|
@@ -14345,7 +14408,7 @@
|
|
|
14345
14408
|
},
|
|
14346
14409
|
"onToggleSelected": {
|
|
14347
14410
|
"defaultValue": null,
|
|
14348
|
-
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected\n@returns",
|
|
14411
|
+
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected - Whether the option has been selected or unselected\n@param isAddedByUser - Whether the option comes from user input, instead of from the list\n@returns",
|
|
14349
14412
|
"name": "onToggleSelected",
|
|
14350
14413
|
"parent": {
|
|
14351
14414
|
"fileName": "react/src/form/combobox/types.ts",
|
|
@@ -14359,7 +14422,7 @@
|
|
|
14359
14422
|
],
|
|
14360
14423
|
"required": false,
|
|
14361
14424
|
"type": {
|
|
14362
|
-
"name": "((option: string, isSelected: boolean) => void)"
|
|
14425
|
+
"name": "((option: string, isSelected: boolean, isAddedByUser: boolean) => void)"
|
|
14363
14426
|
}
|
|
14364
14427
|
},
|
|
14365
14428
|
"selectedOptions": {
|
|
@@ -14798,7 +14861,7 @@
|
|
|
14798
14861
|
},
|
|
14799
14862
|
"onToggleSelected": {
|
|
14800
14863
|
"defaultValue": null,
|
|
14801
|
-
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected\n@returns",
|
|
14864
|
+
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected - Whether the option has been selected or unselected\n@param isAddedByUser - Whether the option comes from user input, instead of from the list\n@returns",
|
|
14802
14865
|
"name": "onToggleSelected",
|
|
14803
14866
|
"parent": {
|
|
14804
14867
|
"fileName": "react/src/form/combobox/types.ts",
|
|
@@ -14812,7 +14875,7 @@
|
|
|
14812
14875
|
],
|
|
14813
14876
|
"required": false,
|
|
14814
14877
|
"type": {
|
|
14815
|
-
"name": "((option: string, isSelected: boolean) => void)"
|
|
14878
|
+
"name": "((option: string, isSelected: boolean, isAddedByUser: boolean) => void)"
|
|
14816
14879
|
}
|
|
14817
14880
|
},
|
|
14818
14881
|
"selectedOptions": {
|
package/cjs/button/Button.js
CHANGED
|
@@ -76,7 +76,7 @@ exports.Button = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
76
76
|
"navds-button--disabled": disabled !== null && disabled !== void 0 ? disabled : widthOverride,
|
|
77
77
|
}), style: Object.assign(Object.assign({}, style), { width: widthOverride }), disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }), widthOverride ? (react_1.default.createElement(__1.Loader, { size: size })) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
78
78
|
icon && iconPosition === "left" && (react_1.default.createElement("span", { className: "navds-button__icon" }, icon)),
|
|
79
|
-
children && (react_1.default.createElement(__1.Label, { as: "span", size: size === "medium" ? "medium" : "small"
|
|
79
|
+
children && (react_1.default.createElement(__1.Label, { as: "span", size: size === "medium" ? "medium" : "small" }, children)),
|
|
80
80
|
icon && iconPosition === "right" && (react_1.default.createElement("span", { className: "navds-button__icon" }, icon))))));
|
|
81
81
|
});
|
|
82
82
|
exports.default = exports.Button;
|
|
@@ -30,22 +30,26 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
30
30
|
const react_1 = __importStar(require("react"));
|
|
31
31
|
const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize, toggleIsListOpen, toggleListButtonRef, }) => {
|
|
32
32
|
const wrapperRef = (0, react_1.useRef)(null);
|
|
33
|
+
const [hasFocusWithin, setHasFocusWithin] = (0, react_1.useState)(false);
|
|
33
34
|
function onFocusInsideWrapper(e) {
|
|
34
35
|
var _a;
|
|
35
36
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget)) &&
|
|
36
37
|
(toggleListButtonRef === null || toggleListButtonRef === void 0 ? void 0 : toggleListButtonRef.current) !== e.target) {
|
|
37
38
|
toggleIsListOpen(true);
|
|
39
|
+
setHasFocusWithin(true);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
function onBlurWrapper(e) {
|
|
41
43
|
var _a;
|
|
42
44
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
43
45
|
toggleIsListOpen(false);
|
|
46
|
+
setHasFocusWithin(false);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
return (react_1.default.createElement("div", { ref: wrapperRef, className: (0, clsx_1.default)(className, "navds-form-field", `navds-form-field--${inputSize}`, "navds-search", {
|
|
47
50
|
"navds-search--error": hasError,
|
|
48
51
|
"navds-search--disabled": !!inputProps.disabled,
|
|
49
|
-
|
|
52
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
53
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper, tabIndex: -1 }, children));
|
|
50
54
|
};
|
|
51
55
|
exports.default = ComboboxWrapper;
|
|
@@ -11,7 +11,7 @@ const filteredOptionsContext_1 = require("./filteredOptionsContext");
|
|
|
11
11
|
const selectedOptionsContext_1 = require("../SelectedOptions/selectedOptionsContext");
|
|
12
12
|
const inputContext_1 = require("../Input/inputContext");
|
|
13
13
|
const FilteredOptions = () => {
|
|
14
|
-
const { inputProps: { id }, size, value, } = (0, inputContext_1.useInputContext)();
|
|
14
|
+
const { clearInput, inputProps: { id }, size, value, } = (0, inputContext_1.useInputContext)();
|
|
15
15
|
const { allowNewValues, isLoading, isListOpen, filteredOptions, filteredOptionsIndex, filteredOptionsRef, isValueNew, toggleIsListOpen, } = (0, filteredOptionsContext_1.useFilteredOptionsContext)();
|
|
16
16
|
const { isMultiSelect, selectedOptions, toggleOption } = (0, selectedOptionsContext_1.useSelectedOptionsContext)();
|
|
17
17
|
return (react_1.default.createElement("ul", { ref: filteredOptionsRef, className: (0, clsx_1.default)("navds-combobox__list", {
|
|
@@ -19,7 +19,10 @@ const FilteredOptions = () => {
|
|
|
19
19
|
}), id: `${id}-filtered-options`, role: "listbox", tabIndex: -1 },
|
|
20
20
|
isLoading && (react_1.default.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: `${id}-is-loading` },
|
|
21
21
|
react_1.default.createElement(__1.Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
22
|
-
isValueNew && allowNewValues && (react_1.default.createElement("li", { tabIndex: -1, onPointerUp: (event) =>
|
|
22
|
+
isValueNew && allowNewValues && (react_1.default.createElement("li", { tabIndex: -1, onPointerUp: (event) => {
|
|
23
|
+
toggleOption(value, event);
|
|
24
|
+
clearInput(event);
|
|
25
|
+
}, id: `${id}-combobox-new-option`, className: (0, clsx_1.default)("navds-combobox__list-item__new-option", {
|
|
23
26
|
"navds-combobox__list-item__new-option--focus": filteredOptionsIndex === -1,
|
|
24
27
|
}), role: "option", "aria-selected": false },
|
|
25
28
|
react_1.default.createElement(aksel_icons_1.PlusIcon, { "aria-hidden": true }),
|
|
@@ -36,6 +39,7 @@ const FilteredOptions = () => {
|
|
|
36
39
|
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
37
40
|
}), id: `${id}-option-${option.replace(" ", "-")}`, key: option, tabIndex: -1, onPointerUp: (event) => {
|
|
38
41
|
toggleOption(option, event);
|
|
42
|
+
clearInput(event);
|
|
39
43
|
if (!isMultiSelect) {
|
|
40
44
|
toggleIsListOpen(false);
|
|
41
45
|
}
|
|
@@ -40,9 +40,10 @@ const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
40
40
|
const selectedOptions = (0, react_1.useMemo)(() => externalSelectedOptions !== null && externalSelectedOptions !== void 0 ? externalSelectedOptions : [...customOptions, ...internalSelectedOptions], [customOptions, externalSelectedOptions, internalSelectedOptions]);
|
|
41
41
|
const addSelectedOption = (0, react_1.useCallback)((option) => {
|
|
42
42
|
var _a;
|
|
43
|
-
|
|
43
|
+
const isAddedByUser = !options
|
|
44
44
|
.map((opt) => opt.toLowerCase())
|
|
45
|
-
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option))
|
|
45
|
+
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option));
|
|
46
|
+
if (isAddedByUser) {
|
|
46
47
|
allowNewValues && addCustomOption(option);
|
|
47
48
|
}
|
|
48
49
|
else if (isMultiSelect) {
|
|
@@ -54,16 +55,17 @@ const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
54
55
|
else {
|
|
55
56
|
setSelectedOptions([option]);
|
|
56
57
|
}
|
|
57
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true);
|
|
58
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true, isAddedByUser);
|
|
58
59
|
}, [addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]);
|
|
59
60
|
const removeSelectedOption = (0, react_1.useCallback)((option) => {
|
|
60
|
-
|
|
61
|
+
const isAddedByUser = customOptions.includes(option);
|
|
62
|
+
if (isAddedByUser) {
|
|
61
63
|
removeCustomOption(option);
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
66
|
setSelectedOptions((prevSelectedOptions) => prevSelectedOptions.filter((selectedOption) => selectedOption !== option));
|
|
65
67
|
}
|
|
66
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false);
|
|
68
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false, isAddedByUser);
|
|
67
69
|
}, [customOptions, onToggleSelected, removeCustomOption]);
|
|
68
70
|
const toggleOption = (0, react_1.useCallback)((option, event) => {
|
|
69
71
|
if (selectedOptions.includes(option)) {
|
package/cjs/link/Link.js
CHANGED
|
@@ -52,9 +52,20 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
52
52
|
* <Link href="#">lenke til ny side</Link>
|
|
53
53
|
* <Link as={ReactRouter.Link} to="#">lenke til ny side</Link>
|
|
54
54
|
* ```
|
|
55
|
+
* @example
|
|
56
|
+
* ```jsx
|
|
57
|
+
* <BodyLong>
|
|
58
|
+
* ...
|
|
59
|
+
* <Link href="#" inlineText>lenke til ny side</Link>
|
|
60
|
+
* ...
|
|
61
|
+
* </BodyLong>
|
|
62
|
+
* ```
|
|
55
63
|
*/
|
|
56
64
|
exports.Link = (0, react_1.forwardRef)((_a, ref) => {
|
|
57
|
-
var { as: Component = "a", className } = _a, rest = __rest(_a, ["as", "className"]);
|
|
58
|
-
return (react_1.default.createElement(Component, Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-link", className
|
|
65
|
+
var { as: Component = "a", className, underline = true, variant = "action", inlineText = false } = _a, rest = __rest(_a, ["as", "className", "underline", "variant", "inlineText"]);
|
|
66
|
+
return (react_1.default.createElement(Component, Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-link", className, `navds-link--${variant}`, {
|
|
67
|
+
"navds-link--remove-underline": !underline,
|
|
68
|
+
"navds-link--inline-text": inlineText,
|
|
69
|
+
}) })));
|
|
59
70
|
});
|
|
60
71
|
exports.default = exports.Link;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.RandomIcon = void 0;
|
|
30
|
+
const AllIcons = __importStar(require("@navikt/aksel-icons"));
|
|
31
|
+
const react_1 = __importDefault(require("react"));
|
|
32
|
+
const icons = Object.keys(AllIcons).map((key) => AllIcons[key]);
|
|
33
|
+
const RandomIcon = () => {
|
|
34
|
+
const Icon = icons[Math.floor(Math.random() * icons.length)];
|
|
35
|
+
return react_1.default.createElement(Icon, null);
|
|
36
|
+
};
|
|
37
|
+
exports.RandomIcon = RandomIcon;
|
package/esm/button/Button.js
CHANGED
|
@@ -47,7 +47,7 @@ export const Button = forwardRef((_a, ref) => {
|
|
|
47
47
|
"navds-button--disabled": disabled !== null && disabled !== void 0 ? disabled : widthOverride,
|
|
48
48
|
}), style: Object.assign(Object.assign({}, style), { width: widthOverride }), disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }), widthOverride ? (React.createElement(Loader, { size: size })) : (React.createElement(React.Fragment, null,
|
|
49
49
|
icon && iconPosition === "left" && (React.createElement("span", { className: "navds-button__icon" }, icon)),
|
|
50
|
-
children && (React.createElement(Label, { as: "span", size: size === "medium" ? "medium" : "small"
|
|
50
|
+
children && (React.createElement(Label, { as: "span", size: size === "medium" ? "medium" : "small" }, children)),
|
|
51
51
|
icon && iconPosition === "right" && (React.createElement("span", { className: "navds-button__icon" }, icon))))));
|
|
52
52
|
});
|
|
53
53
|
export default Button;
|
package/esm/button/Button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sourceRoot":"","sources":["../../src/button/Button.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAwB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA8CtD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,UAAU,CACR,CACE,EAYC,EACD,GAAG,EACH,EAAE;QAdF,EACE,EAAE,EAAE,SAAS,GAAG,QAAQ,EACxB,OAAO,GAAG,SAAS,EACnB,SAAS,EACT,QAAQ,EACR,IAAI,GAAG,QAAQ,EACf,OAAO,GAAG,KAAK,EACf,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,YAAY,GAAG,MAAM,OAEtB,EADI,IAAI,cAXT,0GAYC,CADQ;IAIT,MAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IACzD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,EAAU,CAAC;IAE7D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,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IAAE,IAAI,CAAQ,CACnD;QACA,QAAQ,IAAI,CACX,oBAAC,KAAK,IAAC,EAAE,EAAC,MAAM,EAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,IAC1D,QAAQ,CACH,CACT;QACA,IAAI,IAAI,YAAY,KAAK,OAAO,IAAI,CACnC,8BAAM,SAAS,EAAC,oBAAoB,IAAE,IAAI,CAAQ,CACnD,CACA,CACJ,CACS,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEJ,eAAe,MAAM,CAAC"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
|
-
import React, { useRef } from "react";
|
|
2
|
+
import React, { useRef, useState } from "react";
|
|
3
3
|
const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize, toggleIsListOpen, toggleListButtonRef, }) => {
|
|
4
4
|
const wrapperRef = useRef(null);
|
|
5
|
+
const [hasFocusWithin, setHasFocusWithin] = useState(false);
|
|
5
6
|
function onFocusInsideWrapper(e) {
|
|
6
7
|
var _a;
|
|
7
8
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget)) &&
|
|
8
9
|
(toggleListButtonRef === null || toggleListButtonRef === void 0 ? void 0 : toggleListButtonRef.current) !== e.target) {
|
|
9
10
|
toggleIsListOpen(true);
|
|
11
|
+
setHasFocusWithin(true);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
function onBlurWrapper(e) {
|
|
13
15
|
var _a;
|
|
14
16
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
15
17
|
toggleIsListOpen(false);
|
|
18
|
+
setHasFocusWithin(false);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
return (React.createElement("div", { ref: wrapperRef, className: cl(className, "navds-form-field", `navds-form-field--${inputSize}`, "navds-search", {
|
|
19
22
|
"navds-search--error": hasError,
|
|
20
23
|
"navds-search--disabled": !!inputProps.disabled,
|
|
21
|
-
|
|
24
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
25
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper, tabIndex: -1 }, children));
|
|
22
26
|
};
|
|
23
27
|
export default ComboboxWrapper;
|
|
24
28
|
//# sourceMappingURL=ComboboxWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxWrapper.js","sourceRoot":"","sources":["../../../src/form/combobox/ComboboxWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ComboboxWrapper.js","sourceRoot":"","sources":["../../../src/form/combobox/ComboboxWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAchD,MAAM,eAAe,GAAG,CAAC,EACvB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACE,EAAE,EAAE;IACzB,MAAM,UAAU,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,oBAAoB,CAAC,CAAC;;QAC7B,IACE,CAAC,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;YAC9C,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,OAAO,MAAK,CAAC,CAAC,MAAM,EACzC;YACA,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,iBAAiB,CAAC,IAAI,CAAC,CAAC;SACzB;IACH,CAAC;IAED,SAAS,aAAa,CAAC,CAAC;;QACtB,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA,EAAE;YAClD,gBAAgB,CAAC,KAAK,CAAC,CAAC;YACxB,iBAAiB,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;IAED,OAAO,CACL,6BACE,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,EAAE,CACX,SAAS,EACT,kBAAkB,EAClB,qBAAqB,SAAS,EAAE,EAChC,cAAc,EACd;YACE,qBAAqB,EAAE,QAAQ;YAC/B,wBAAwB,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ;YAC/C,yBAAyB,EAAE,cAAc;SAC1C,CACF,EACD,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,CAAC,CAAC,IAEX,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
|
|
6
6
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
7
7
|
import { useInputContext } from "../Input/inputContext";
|
|
8
8
|
const FilteredOptions = () => {
|
|
9
|
-
const { inputProps: { id }, size, value, } = useInputContext();
|
|
9
|
+
const { clearInput, inputProps: { id }, size, value, } = useInputContext();
|
|
10
10
|
const { allowNewValues, isLoading, isListOpen, filteredOptions, filteredOptionsIndex, filteredOptionsRef, isValueNew, toggleIsListOpen, } = useFilteredOptionsContext();
|
|
11
11
|
const { isMultiSelect, selectedOptions, toggleOption } = useSelectedOptionsContext();
|
|
12
12
|
return (React.createElement("ul", { ref: filteredOptionsRef, className: cl("navds-combobox__list", {
|
|
@@ -14,7 +14,10 @@ const FilteredOptions = () => {
|
|
|
14
14
|
}), id: `${id}-filtered-options`, role: "listbox", tabIndex: -1 },
|
|
15
15
|
isLoading && (React.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: `${id}-is-loading` },
|
|
16
16
|
React.createElement(Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
17
|
-
isValueNew && allowNewValues && (React.createElement("li", { tabIndex: -1, onPointerUp: (event) =>
|
|
17
|
+
isValueNew && allowNewValues && (React.createElement("li", { tabIndex: -1, onPointerUp: (event) => {
|
|
18
|
+
toggleOption(value, event);
|
|
19
|
+
clearInput(event);
|
|
20
|
+
}, id: `${id}-combobox-new-option`, className: cl("navds-combobox__list-item__new-option", {
|
|
18
21
|
"navds-combobox__list-item__new-option--focus": filteredOptionsIndex === -1,
|
|
19
22
|
}), role: "option", "aria-selected": false },
|
|
20
23
|
React.createElement(PlusIcon, { "aria-hidden": true }),
|
|
@@ -31,6 +34,7 @@ const FilteredOptions = () => {
|
|
|
31
34
|
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
32
35
|
}), id: `${id}-option-${option.replace(" ", "-")}`, key: option, tabIndex: -1, onPointerUp: (event) => {
|
|
33
36
|
toggleOption(option, event);
|
|
37
|
+
clearInput(event);
|
|
34
38
|
if (!isMultiSelect) {
|
|
35
39
|
toggleIsListOpen(false);
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,EACJ,UAAU,EAAE,EAAE,EAAE,EAAE,EAClB,IAAI,EACJ,KAAK,GACN,GAAG,eAAe,EAAE,CAAC;IACtB,MAAM,EACJ,cAAc,EACd,SAAS,EACT,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,GAAG,yBAAyB,EAAE,CAAC;IAChC,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,GACpD,yBAAyB,EAAE,CAAC;IAE9B,OAAO,CACL,4BACE,GAAG,EAAE,kBAAkB,EACvB,SAAS,EAAE,EAAE,CAAC,sBAAsB,EAAE;YACpC,8BAA8B,EAAE,CAAC,UAAU;SAC5C,CAAC,EACF,EAAE,EAAE,GAAG,EAAE,mBAAmB,EAC5B,IAAI,EAAC,SAAS,EACd,QAAQ,EAAE,CAAC,CAAC;QAEX,SAAS,IAAI,CACZ,4BACE,SAAS,EAAC,oCAAoC,EAC9C,IAAI,EAAC,QAAQ,mBACE,KAAK,EACpB,EAAE,EAAE,GAAG,EAAE,aAAa;YAEtB,oBAAC,MAAM,kBAAY,eAAU,GAAG,CAC7B,CACN;QACA,UAAU,IAAI,cAAc,IAAI,CAC/B,4BACE,QAAQ,EAAE,CAAC,CAAC,EACZ,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,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C,QAAQ,CAAC,MAAM,CAAC,IAAI,oBAAC,aAAa,OAAG,CACnD,CACN,CAAC,CACC,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -11,9 +11,10 @@ export const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
11
11
|
const selectedOptions = useMemo(() => externalSelectedOptions !== null && externalSelectedOptions !== void 0 ? externalSelectedOptions : [...customOptions, ...internalSelectedOptions], [customOptions, externalSelectedOptions, internalSelectedOptions]);
|
|
12
12
|
const addSelectedOption = useCallback((option) => {
|
|
13
13
|
var _a;
|
|
14
|
-
|
|
14
|
+
const isAddedByUser = !options
|
|
15
15
|
.map((opt) => opt.toLowerCase())
|
|
16
|
-
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option))
|
|
16
|
+
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option));
|
|
17
|
+
if (isAddedByUser) {
|
|
17
18
|
allowNewValues && addCustomOption(option);
|
|
18
19
|
}
|
|
19
20
|
else if (isMultiSelect) {
|
|
@@ -25,16 +26,17 @@ export const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
25
26
|
else {
|
|
26
27
|
setSelectedOptions([option]);
|
|
27
28
|
}
|
|
28
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true);
|
|
29
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true, isAddedByUser);
|
|
29
30
|
}, [addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]);
|
|
30
31
|
const removeSelectedOption = useCallback((option) => {
|
|
31
|
-
|
|
32
|
+
const isAddedByUser = customOptions.includes(option);
|
|
33
|
+
if (isAddedByUser) {
|
|
32
34
|
removeCustomOption(option);
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
37
|
setSelectedOptions((prevSelectedOptions) => prevSelectedOptions.filter((selectedOption) => selectedOption !== option));
|
|
36
38
|
}
|
|
37
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false);
|
|
39
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false, isAddedByUser);
|
|
38
40
|
}, [customOptions, onToggleSelected, removeCustomOption]);
|
|
39
41
|
const toggleOption = useCallback((option, event) => {
|
|
40
42
|
if (selectedOptions.includes(option)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectedOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/SelectedOptions/selectedOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAelE,MAAM,sBAAsB,GAAG,aAAa,CAC1C,EAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,EACR,KAAK,GAWN,EAAE,EAAE;IACH,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,eAAe,EAAE,CAAC;IACrD,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAC1D,uBAAuB,EAAE,CAAC;IAC5B,MAAM,EACJ,cAAc,EACd,aAAa,EACb,eAAe,EAAE,uBAAuB,EACxC,gBAAgB,EAChB,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,uBAAuB,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAC7E,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CACH,uBAAuB,aAAvB,uBAAuB,cAAvB,uBAAuB,GAAI,CAAC,GAAG,aAAa,EAAE,GAAG,uBAAuB,CAAC,EAC3E,CAAC,aAAa,EAAE,uBAAuB,EAAE,uBAAuB,CAAC,CAClE,CAAC;IAEF,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,MAAc,EAAE,EAAE;;QACjB,
|
|
1
|
+
{"version":3,"file":"selectedOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/SelectedOptions/selectedOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAelE,MAAM,sBAAsB,GAAG,aAAa,CAC1C,EAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,EACR,KAAK,GAWN,EAAE,EAAE;IACH,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,eAAe,EAAE,CAAC;IACrD,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAC1D,uBAAuB,EAAE,CAAC;IAC5B,MAAM,EACJ,cAAc,EACd,aAAa,EACb,eAAe,EAAE,uBAAuB,EACxC,gBAAgB,EAChB,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,uBAAuB,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAC7E,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CACH,uBAAuB,aAAvB,uBAAuB,cAAvB,uBAAuB,GAAI,CAAC,GAAG,aAAa,EAAE,GAAG,uBAAuB,CAAC,EAC3E,CAAC,aAAa,EAAE,uBAAuB,EAAE,uBAA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aAAa,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CACtD,CAAC;IAEF,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,MAAc,EAAE,KAA+C,EAAE,EAAE;QAClE,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,oBAAoB,CAAC,MAAM,CAAC,CAAC;SAC9B;aAAM;YACL,iBAAiB,CAAC,MAAM,CAAC,CAAC;SAC3B;QACD,IAAI,CAAC,aAAa,EAAE;YAClB,UAAU,CAAC,KAAK,CAAC,CAAC;SACnB;QACD,UAAU,EAAE,CAAC;IACf,CAAC,EACD;QACE,iBAAiB;QACjB,UAAU;QACV,UAAU;QACV,aAAa;QACb,oBAAoB;QACpB,eAAe;KAChB,CACF,CAAC;IAEF,MAAM,mBAAmB,GAAG,WAAW,CAAW,eAAe,CAAC,CAAC;IAEnE,MAAM,oBAAoB,GAAG;QAC3B,iBAAiB;QACjB,aAAa;QACb,oBAAoB;QACpB,mBAAmB;QACnB,eAAe;QACf,kBAAkB;QAClB,YAAY;KACb,CAAC;IAEF,OAAO,CACL,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,oBAAoB,IACzD,QAAQ,CACuB,CACnC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -75,10 +75,11 @@ export interface ComboboxProps extends FormFieldProps, Omit<InputHTMLAttributes<
|
|
|
75
75
|
* Callback function triggered whenever an option is selected or de-selected
|
|
76
76
|
*
|
|
77
77
|
* @param option
|
|
78
|
-
* @param isSelected
|
|
78
|
+
* @param isSelected - Whether the option has been selected or unselected
|
|
79
|
+
* @param isAddedByUser - Whether the option comes from user input, instead of from the list
|
|
79
80
|
* @returns
|
|
80
81
|
*/
|
|
81
|
-
onToggleSelected?: (option: string, isSelected: boolean) => void;
|
|
82
|
+
onToggleSelected?: (option: string, isSelected: boolean, isAddedByUser: boolean) => void;
|
|
82
83
|
/**
|
|
83
84
|
* List of selected options.
|
|
84
85
|
*
|
package/esm/link/Link.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { OverridableComponent } from "../util/OverridableComponent";
|
|
3
3
|
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
4
|
+
/**
|
|
5
|
+
* Inverts when the underline appears. If this is false,
|
|
6
|
+
* the underline does not appear by default, but does appear when the link is hovered.
|
|
7
|
+
* This makes it more suitable for use when inlined in text.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
underline?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Renders link with `display: inline` for better wrapping in text.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
inlineText?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Variant of the component to use.
|
|
18
|
+
* @default "action"
|
|
19
|
+
*/
|
|
20
|
+
variant?: "action" | "neutral" | "subtle";
|
|
4
21
|
/**
|
|
5
22
|
* Link text
|
|
6
23
|
*/
|
|
@@ -18,6 +35,14 @@ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
|
18
35
|
* <Link href="#">lenke til ny side</Link>
|
|
19
36
|
* <Link as={ReactRouter.Link} to="#">lenke til ny side</Link>
|
|
20
37
|
* ```
|
|
38
|
+
* @example
|
|
39
|
+
* ```jsx
|
|
40
|
+
* <BodyLong>
|
|
41
|
+
* ...
|
|
42
|
+
* <Link href="#" inlineText>lenke til ny side</Link>
|
|
43
|
+
* ...
|
|
44
|
+
* </BodyLong>
|
|
45
|
+
* ```
|
|
21
46
|
*/
|
|
22
47
|
export declare const Link: OverridableComponent<LinkProps, HTMLAnchorElement>;
|
|
23
48
|
export default Link;
|
package/esm/link/Link.js
CHANGED
|
@@ -23,10 +23,21 @@ import cl from "clsx";
|
|
|
23
23
|
* <Link href="#">lenke til ny side</Link>
|
|
24
24
|
* <Link as={ReactRouter.Link} to="#">lenke til ny side</Link>
|
|
25
25
|
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* <BodyLong>
|
|
29
|
+
* ...
|
|
30
|
+
* <Link href="#" inlineText>lenke til ny side</Link>
|
|
31
|
+
* ...
|
|
32
|
+
* </BodyLong>
|
|
33
|
+
* ```
|
|
26
34
|
*/
|
|
27
35
|
export const Link = forwardRef((_a, ref) => {
|
|
28
|
-
var { as: Component = "a", className } = _a, rest = __rest(_a, ["as", "className"]);
|
|
29
|
-
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, className: cl("navds-link", className
|
|
36
|
+
var { as: Component = "a", className, underline = true, variant = "action", inlineText = false } = _a, rest = __rest(_a, ["as", "className", "underline", "variant", "inlineText"]);
|
|
37
|
+
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, className: cl("navds-link", className, `navds-link--${variant}`, {
|
|
38
|
+
"navds-link--remove-underline": !underline,
|
|
39
|
+
"navds-link--inline-text": inlineText,
|
|
40
|
+
}) })));
|
|
30
41
|
});
|
|
31
42
|
export default Link;
|
|
32
43
|
//# sourceMappingURL=Link.js.map
|
package/esm/link/Link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,MAAM,CAAC;AA4BtB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,IAAI,GACf,UAAU,CACR,CACE,EAOC,EACD,GAAG,EACH,EAAE;QATF,EACE,EAAE,EAAE,SAAS,GAAG,GAAG,EACnB,SAAS,EACT,SAAS,GAAG,IAAI,EAChB,OAAO,GAAG,QAAQ,EAClB,UAAU,GAAG,KAAK,OAEnB,EADI,IAAI,cANT,yDAOC,CADQ;IAGN,OAAA,CACH,oBAAC,SAAS,oBACJ,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,eAAe,OAAO,EAAE,EAAE;YAC/D,8BAA8B,EAAE,CAAC,SAAS;YAC1C,yBAAyB,EAAE,UAAU;SACtC,CAAC,IACF,CACH,CAAA;CAAA,CACF,CAAC;AAEJ,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as AllIcons from "@navikt/aksel-icons";
|
|
2
|
+
import React from "react";
|
|
3
|
+
const icons = Object.keys(AllIcons).map((key) => AllIcons[key]);
|
|
4
|
+
export const RandomIcon = () => {
|
|
5
|
+
const Icon = icons[Math.floor(Math.random() * icons.length)];
|
|
6
|
+
return React.createElement(Icon, null);
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=RandomIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RandomIcon.js","sourceRoot":"","sources":["../../src/util/RandomIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,OAAO,oBAAC,IAAI,OAAG,CAAC;AAClB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@floating-ui/react": "0.24.1",
|
|
41
|
-
"@navikt/aksel-icons": "^4.
|
|
41
|
+
"@navikt/aksel-icons": "^4.10.0",
|
|
42
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
43
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
44
44
|
"clsx": "^1.2.1",
|
package/src/button/Button.tsx
CHANGED
|
@@ -126,11 +126,7 @@ export const Button: OverridableComponent<ButtonProps, HTMLButtonElement> =
|
|
|
126
126
|
<span className="navds-button__icon">{icon}</span>
|
|
127
127
|
)}
|
|
128
128
|
{children && (
|
|
129
|
-
<Label
|
|
130
|
-
as="span"
|
|
131
|
-
size={size === "medium" ? "medium" : "small"}
|
|
132
|
-
aria-live="polite"
|
|
133
|
-
>
|
|
129
|
+
<Label as="span" size={size === "medium" ? "medium" : "small"}>
|
|
134
130
|
{children}
|
|
135
131
|
</Label>
|
|
136
132
|
)}
|
|
@@ -148,8 +148,9 @@ export const Loading = {
|
|
|
148
148
|
</div>
|
|
149
149
|
),
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
parameters: {
|
|
152
|
+
chromatic: { disableSnapshot: true },
|
|
153
|
+
},
|
|
153
154
|
};
|
|
154
155
|
|
|
155
156
|
export const Icon = () => (
|
|
@@ -275,6 +276,7 @@ export const LoadingWithAs = {
|
|
|
275
276
|
</div>
|
|
276
277
|
),
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
parameters: {
|
|
280
|
+
chromatic: { disableSnapshot: true },
|
|
281
|
+
},
|
|
280
282
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
|
-
import React, { useRef } from "react";
|
|
2
|
+
import React, { useRef, useState } from "react";
|
|
3
3
|
|
|
4
4
|
type ComboboxWrapperProps = {
|
|
5
5
|
children: any;
|
|
@@ -23,6 +23,7 @@ const ComboboxWrapper = ({
|
|
|
23
23
|
toggleListButtonRef,
|
|
24
24
|
}: ComboboxWrapperProps) => {
|
|
25
25
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
26
|
+
const [hasFocusWithin, setHasFocusWithin] = useState(false);
|
|
26
27
|
|
|
27
28
|
function onFocusInsideWrapper(e) {
|
|
28
29
|
if (
|
|
@@ -30,12 +31,14 @@ const ComboboxWrapper = ({
|
|
|
30
31
|
toggleListButtonRef?.current !== e.target
|
|
31
32
|
) {
|
|
32
33
|
toggleIsListOpen(true);
|
|
34
|
+
setHasFocusWithin(true);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
function onBlurWrapper(e) {
|
|
37
39
|
if (!wrapperRef.current?.contains(e.relatedTarget)) {
|
|
38
40
|
toggleIsListOpen(false);
|
|
41
|
+
setHasFocusWithin(false);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -50,10 +53,12 @@ const ComboboxWrapper = ({
|
|
|
50
53
|
{
|
|
51
54
|
"navds-search--error": hasError,
|
|
52
55
|
"navds-search--disabled": !!inputProps.disabled,
|
|
56
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
53
57
|
}
|
|
54
58
|
)}
|
|
55
59
|
onFocus={onFocusInsideWrapper}
|
|
56
60
|
onBlur={onBlurWrapper}
|
|
61
|
+
tabIndex={-1}
|
|
57
62
|
>
|
|
58
63
|
{children}
|
|
59
64
|
</div>
|
|
@@ -8,6 +8,7 @@ import { useInputContext } from "../Input/inputContext";
|
|
|
8
8
|
|
|
9
9
|
const FilteredOptions = () => {
|
|
10
10
|
const {
|
|
11
|
+
clearInput,
|
|
11
12
|
inputProps: { id },
|
|
12
13
|
size,
|
|
13
14
|
value,
|
|
@@ -48,7 +49,10 @@ const FilteredOptions = () => {
|
|
|
48
49
|
{isValueNew && allowNewValues && (
|
|
49
50
|
<li
|
|
50
51
|
tabIndex={-1}
|
|
51
|
-
onPointerUp={(event) =>
|
|
52
|
+
onPointerUp={(event) => {
|
|
53
|
+
toggleOption(value, event);
|
|
54
|
+
clearInput(event);
|
|
55
|
+
}}
|
|
52
56
|
id={`${id}-combobox-new-option`}
|
|
53
57
|
className={cl("navds-combobox__list-item__new-option", {
|
|
54
58
|
"navds-combobox__list-item__new-option--focus":
|
|
@@ -88,6 +92,7 @@ const FilteredOptions = () => {
|
|
|
88
92
|
tabIndex={-1}
|
|
89
93
|
onPointerUp={(event) => {
|
|
90
94
|
toggleOption(option, event);
|
|
95
|
+
clearInput(event);
|
|
91
96
|
if (!isMultiSelect) {
|
|
92
97
|
toggleIsListOpen(false);
|
|
93
98
|
}
|
|
@@ -60,11 +60,10 @@ export const SelectedOptionsProvider = ({
|
|
|
60
60
|
|
|
61
61
|
const addSelectedOption = useCallback(
|
|
62
62
|
(option: string) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
) {
|
|
63
|
+
const isAddedByUser = !options
|
|
64
|
+
.map((opt) => opt.toLowerCase())
|
|
65
|
+
.includes(option?.toLowerCase?.());
|
|
66
|
+
if (isAddedByUser) {
|
|
68
67
|
allowNewValues && addCustomOption(option);
|
|
69
68
|
} else if (isMultiSelect) {
|
|
70
69
|
setSelectedOptions((prevSelectedOptions) => [
|
|
@@ -74,14 +73,15 @@ export const SelectedOptionsProvider = ({
|
|
|
74
73
|
} else {
|
|
75
74
|
setSelectedOptions([option]);
|
|
76
75
|
}
|
|
77
|
-
onToggleSelected?.(option, true);
|
|
76
|
+
onToggleSelected?.(option, true, isAddedByUser);
|
|
78
77
|
},
|
|
79
78
|
[addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]
|
|
80
79
|
);
|
|
81
80
|
|
|
82
81
|
const removeSelectedOption = useCallback(
|
|
83
82
|
(option: string) => {
|
|
84
|
-
|
|
83
|
+
const isAddedByUser = customOptions.includes(option);
|
|
84
|
+
if (isAddedByUser) {
|
|
85
85
|
removeCustomOption(option);
|
|
86
86
|
} else {
|
|
87
87
|
setSelectedOptions((prevSelectedOptions) =>
|
|
@@ -90,7 +90,7 @@ export const SelectedOptionsProvider = ({
|
|
|
90
90
|
)
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
-
onToggleSelected?.(option, false);
|
|
93
|
+
onToggleSelected?.(option, false, isAddedByUser);
|
|
94
94
|
},
|
|
95
95
|
[customOptions, onToggleSelected, removeCustomOption]
|
|
96
96
|
);
|
|
@@ -82,6 +82,7 @@ export function MultiSelect(props) {
|
|
|
82
82
|
label="Komboboks - velg flere"
|
|
83
83
|
options={props.options}
|
|
84
84
|
isMultiSelect={props.isMultiSelect}
|
|
85
|
+
size={props.size}
|
|
85
86
|
/>
|
|
86
87
|
</DemoContainer>
|
|
87
88
|
);
|
|
@@ -90,6 +91,7 @@ export function MultiSelect(props) {
|
|
|
90
91
|
MultiSelect.args = {
|
|
91
92
|
options,
|
|
92
93
|
isMultiSelect: true,
|
|
94
|
+
size: "medium",
|
|
93
95
|
};
|
|
94
96
|
|
|
95
97
|
export function MultiSelectWithAddNewOptions(props) {
|
|
@@ -78,10 +78,15 @@ export interface ComboboxProps
|
|
|
78
78
|
* Callback function triggered whenever an option is selected or de-selected
|
|
79
79
|
*
|
|
80
80
|
* @param option
|
|
81
|
-
* @param isSelected
|
|
81
|
+
* @param isSelected - Whether the option has been selected or unselected
|
|
82
|
+
* @param isAddedByUser - Whether the option comes from user input, instead of from the list
|
|
82
83
|
* @returns
|
|
83
84
|
*/
|
|
84
|
-
onToggleSelected?: (
|
|
85
|
+
onToggleSelected?: (
|
|
86
|
+
option: string,
|
|
87
|
+
isSelected: boolean,
|
|
88
|
+
isAddedByUser: boolean
|
|
89
|
+
) => void;
|
|
85
90
|
/**
|
|
86
91
|
* List of selected options.
|
|
87
92
|
*
|
package/src/link/Link.tsx
CHANGED
|
@@ -4,6 +4,23 @@ import { OverridableComponent } from "../util/OverridableComponent";
|
|
|
4
4
|
|
|
5
5
|
export interface LinkProps
|
|
6
6
|
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
7
|
+
/**
|
|
8
|
+
* Inverts when the underline appears. If this is false,
|
|
9
|
+
* the underline does not appear by default, but does appear when the link is hovered.
|
|
10
|
+
* This makes it more suitable for use when inlined in text.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
underline?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Renders link with `display: inline` for better wrapping in text.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
inlineText?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Variant of the component to use.
|
|
21
|
+
* @default "action"
|
|
22
|
+
*/
|
|
23
|
+
variant?: "action" | "neutral" | "subtle";
|
|
7
24
|
/**
|
|
8
25
|
* Link text
|
|
9
26
|
*/
|
|
@@ -22,10 +39,37 @@ export interface LinkProps
|
|
|
22
39
|
* <Link href="#">lenke til ny side</Link>
|
|
23
40
|
* <Link as={ReactRouter.Link} to="#">lenke til ny side</Link>
|
|
24
41
|
* ```
|
|
42
|
+
* @example
|
|
43
|
+
* ```jsx
|
|
44
|
+
* <BodyLong>
|
|
45
|
+
* ...
|
|
46
|
+
* <Link href="#" inlineText>lenke til ny side</Link>
|
|
47
|
+
* ...
|
|
48
|
+
* </BodyLong>
|
|
49
|
+
* ```
|
|
25
50
|
*/
|
|
26
51
|
export const Link: OverridableComponent<LinkProps, HTMLAnchorElement> =
|
|
27
|
-
forwardRef(
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
forwardRef(
|
|
53
|
+
(
|
|
54
|
+
{
|
|
55
|
+
as: Component = "a",
|
|
56
|
+
className,
|
|
57
|
+
underline = true,
|
|
58
|
+
variant = "action",
|
|
59
|
+
inlineText = false,
|
|
60
|
+
...rest
|
|
61
|
+
},
|
|
62
|
+
ref
|
|
63
|
+
) => (
|
|
64
|
+
<Component
|
|
65
|
+
{...rest}
|
|
66
|
+
ref={ref}
|
|
67
|
+
className={cl("navds-link", className, `navds-link--${variant}`, {
|
|
68
|
+
"navds-link--remove-underline": !underline,
|
|
69
|
+
"navds-link--inline-text": inlineText,
|
|
70
|
+
})}
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
);
|
|
30
74
|
|
|
31
75
|
export default Link;
|
|
@@ -6,29 +6,76 @@ import {
|
|
|
6
6
|
ConfirmationPanel as DsConfirmationPanel,
|
|
7
7
|
Link,
|
|
8
8
|
} from "..";
|
|
9
|
+
import { RandomIcon } from "../util/RandomIcon";
|
|
10
|
+
|
|
9
11
|
export default {
|
|
10
12
|
title: "ds-react/Link",
|
|
11
13
|
component: Link,
|
|
12
14
|
};
|
|
13
15
|
|
|
16
|
+
const LinkWrapper = ({
|
|
17
|
+
children = "Ex aliqua incididunt",
|
|
18
|
+
iconRight = false,
|
|
19
|
+
iconLeft = false,
|
|
20
|
+
variant = "action",
|
|
21
|
+
underline = false,
|
|
22
|
+
inlineText = true,
|
|
23
|
+
}) => (
|
|
24
|
+
<>
|
|
25
|
+
{" "}
|
|
26
|
+
<Link
|
|
27
|
+
href="#"
|
|
28
|
+
underline={underline}
|
|
29
|
+
variant={variant as "action" | "neutral" | "subtle"}
|
|
30
|
+
inlineText={inlineText}
|
|
31
|
+
>
|
|
32
|
+
{iconLeft && (
|
|
33
|
+
<>
|
|
34
|
+
<RandomIcon />{" "}
|
|
35
|
+
</>
|
|
36
|
+
)}
|
|
37
|
+
{children}
|
|
38
|
+
{iconRight && (
|
|
39
|
+
<>
|
|
40
|
+
{" "}
|
|
41
|
+
<RandomIcon />
|
|
42
|
+
</>
|
|
43
|
+
)}
|
|
44
|
+
</Link>{" "}
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
|
|
14
48
|
export const Default = {
|
|
15
|
-
render: (
|
|
49
|
+
render: ({ icon, inline }) => {
|
|
16
50
|
const LinkD = () => (
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
<>
|
|
52
|
+
{" "}
|
|
53
|
+
<Link href="#" underline={!inline} inlineText={inline}>
|
|
54
|
+
{icon && <PlusCircleFillIcon />}Ex aliqua incididunt
|
|
55
|
+
{icon && <PlusCircleFillIcon />}
|
|
56
|
+
</Link>{" "}
|
|
57
|
+
</>
|
|
21
58
|
);
|
|
22
59
|
|
|
23
|
-
if (
|
|
60
|
+
if (inline) {
|
|
24
61
|
return (
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
<div
|
|
63
|
+
className="colgap"
|
|
64
|
+
style={{
|
|
65
|
+
width: "800px",
|
|
66
|
+
border: "1px solid black",
|
|
67
|
+
borderRadius: "8px",
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<BodyLong>
|
|
71
|
+
Incididunt laborum nisi nisi Lorem
|
|
72
|
+
<LinkD />
|
|
73
|
+
in. Laborum aute fugiat officia adipisicing non veniam dolor nulla
|
|
74
|
+
non ex consectetur fugiat eiusmod aute. Culpa sit aute est duis
|
|
75
|
+
minim in in voluptate velit fugiat. Laboris est id deserunt ut ea
|
|
76
|
+
Lorem eu. Esse elit laboris aute commodo sint laborum fugiat aliqua.
|
|
77
|
+
</BodyLong>
|
|
78
|
+
</div>
|
|
32
79
|
);
|
|
33
80
|
}
|
|
34
81
|
return <LinkD />;
|
|
@@ -40,6 +87,49 @@ export const Default = {
|
|
|
40
87
|
},
|
|
41
88
|
};
|
|
42
89
|
|
|
90
|
+
export const InlineInsideBodyLong = {
|
|
91
|
+
render: ({ iconLeft, iconRight }) => {
|
|
92
|
+
return (
|
|
93
|
+
<div
|
|
94
|
+
className="colgap"
|
|
95
|
+
style={{
|
|
96
|
+
width: "800px",
|
|
97
|
+
border: "1px solid black",
|
|
98
|
+
borderRadius: "8px",
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<style>{`.storybook-custom-spacing { white-space: pre;}`}</style>
|
|
102
|
+
<BodyLong>
|
|
103
|
+
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
|
|
104
|
+
Eiusmod aute.
|
|
105
|
+
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
|
|
106
|
+
Culpa sit aute est duis minim in in voluptate velit Incididunt laborum
|
|
107
|
+
nisi nisi Lorem officia adipisicing non veniam
|
|
108
|
+
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
|
|
109
|
+
blah blah blah blah blah blah blah blah blah blah blah blah blah
|
|
110
|
+
blah blah blah blah blah blah blah blah
|
|
111
|
+
</LinkWrapper>
|
|
112
|
+
dolor eu. Esse elit laboris aute commodo sint laborum fugiat aliqua.
|
|
113
|
+
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
|
|
114
|
+
Link
|
|
115
|
+
</LinkWrapper>
|
|
116
|
+
</BodyLong>
|
|
117
|
+
<BodyLong className="storybook-custom-spacing">
|
|
118
|
+
Custom{" "}
|
|
119
|
+
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
|
|
120
|
+
link
|
|
121
|
+
</LinkWrapper>
|
|
122
|
+
{" "}spacing.
|
|
123
|
+
</BodyLong>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
args: {
|
|
128
|
+
iconLeft: false,
|
|
129
|
+
iconRight: false,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
43
133
|
const DemoLink = () => (
|
|
44
134
|
<Link href="#">
|
|
45
135
|
<PlusCircleFillIcon aria-hidden /> Ex aliqua incididunt{" "}
|
|
@@ -83,3 +173,27 @@ export const ConfirmationPanel = () => {
|
|
|
83
173
|
</div>
|
|
84
174
|
);
|
|
85
175
|
};
|
|
176
|
+
|
|
177
|
+
export const Variants = {
|
|
178
|
+
render: ({ iconLeft, iconRight }) => {
|
|
179
|
+
return (
|
|
180
|
+
<div className="colgap">
|
|
181
|
+
{["action", "neutral", "subtle"].map((variant) => (
|
|
182
|
+
<>
|
|
183
|
+
<div>
|
|
184
|
+
<LinkWrapper
|
|
185
|
+
iconLeft={iconLeft}
|
|
186
|
+
iconRight={iconRight}
|
|
187
|
+
variant={variant}
|
|
188
|
+
/>
|
|
189
|
+
</div>
|
|
190
|
+
</>
|
|
191
|
+
))}
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
},
|
|
195
|
+
args: {
|
|
196
|
+
iconLeft: false,
|
|
197
|
+
iconRight: false,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as AllIcons from "@navikt/aksel-icons";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
const icons = Object.keys(AllIcons).map((key) => AllIcons[key]);
|
|
5
|
+
|
|
6
|
+
export const RandomIcon = () => {
|
|
7
|
+
const Icon = icons[Math.floor(Math.random() * icons.length)];
|
|
8
|
+
return <Icon />;
|
|
9
|
+
};
|