@navikt/ds-react 0.14.8 → 0.14.11
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/button/Button.js +22 -3
- package/cjs/form/Switch.js +1 -1
- package/cjs/modal/Modal.js +4 -4
- package/esm/button/Button.d.ts +5 -0
- package/esm/button/Button.js +24 -5
- package/esm/button/Button.js.map +1 -1
- package/esm/form/Switch.js +1 -1
- package/esm/form/Switch.js.map +1 -1
- package/esm/modal/Modal.d.ts +5 -0
- package/esm/modal/Modal.js +4 -4
- package/esm/modal/Modal.js.map +1 -1
- package/package.json +2 -2
- package/src/button/Button.tsx +55 -18
- package/src/button/stories/button.stories.mdx +17 -11
- package/src/button/stories/button.stories.tsx +39 -1
- package/src/form/Switch.tsx +2 -2
- package/src/loader/stories/loader.stories.mdx +0 -22
- package/src/modal/Modal.tsx +19 -12
- package/src/modal/stories/modal.stories.tsx +16 -0
package/cjs/button/Button.js
CHANGED
|
@@ -34,11 +34,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const react_1 = __importStar(require("react"));
|
|
37
|
+
const react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
37
38
|
const classnames_1 = __importDefault(require("classnames"));
|
|
38
39
|
const __1 = require("../");
|
|
40
|
+
const util_1 = require("../util");
|
|
39
41
|
const Button = (0, react_1.forwardRef)((_a, ref) => {
|
|
40
|
-
var { as: Component = "button", variant = "primary", className, children, size = "medium" } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size"]);
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
var { as: Component = "button", variant = "primary", className, children, size = "medium", loading = false, disabled } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size", "loading", "disabled"]);
|
|
43
|
+
const buttonRef = (0, react_1.useRef)(null);
|
|
44
|
+
const mergedRef = (0, react_merge_refs_1.default)([buttonRef, ref]);
|
|
45
|
+
const [widthOverride, setWidthOverride] = (0, react_1.useState)();
|
|
46
|
+
(0, util_1.useClientLayoutEffect)(() => {
|
|
47
|
+
if (loading) {
|
|
48
|
+
const requestID = window.requestAnimationFrame(() => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
setWidthOverride((_b = (_a = buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width);
|
|
51
|
+
});
|
|
52
|
+
return () => {
|
|
53
|
+
setWidthOverride(undefined);
|
|
54
|
+
cancelAnimationFrame(requestID);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}, [loading, children]);
|
|
58
|
+
return (react_1.default.createElement(Component, Object.assign({}, rest, { ref: mergedRef, className: (0, classnames_1.default)(className, "navds-button", `navds-button--${variant}`, `navds-button--${size}`, {
|
|
59
|
+
"navds-button--loading": widthOverride,
|
|
60
|
+
}), style: { width: widthOverride }, disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }),
|
|
61
|
+
react_1.default.createElement(__1.BodyShort, { as: "span", className: "navds-button__inner", size: size, "aria-live": "polite" }, widthOverride ? react_1.default.createElement(__1.Loader, { size: size }) : children)));
|
|
43
62
|
});
|
|
44
63
|
exports.default = Button;
|
package/cjs/form/Switch.js
CHANGED
|
@@ -38,7 +38,7 @@ const react_1 = __importStar(require("react"));
|
|
|
38
38
|
const __1 = require("..");
|
|
39
39
|
const useFormField_1 = require("./useFormField");
|
|
40
40
|
const SelectedIcon = () => (react_1.default.createElement("svg", { width: "12px", height: "12px", viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", focusable: false, role: "img", "aria-hidden": true, "aria-label": "Deaktiver valg" },
|
|
41
|
-
react_1.default.createElement("path", {
|
|
41
|
+
react_1.default.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M4.01386 8L10.25 2L11 2.75L4.01386 9.5L1 6.5L1.75 5.75L4.01386 8Z", fill: "currentColor", stroke: "currentColor" })));
|
|
42
42
|
const Switch = (0, react_1.forwardRef)((props, ref) => {
|
|
43
43
|
var _a;
|
|
44
44
|
const { inputProps, size } = (0, useFormField_1.useFormField)(props, "switch");
|
package/cjs/modal/Modal.js
CHANGED
|
@@ -41,7 +41,7 @@ const ds_icons_1 = require("@navikt/ds-icons");
|
|
|
41
41
|
const __1 = require("..");
|
|
42
42
|
const ModalContent_1 = __importDefault(require("./ModalContent"));
|
|
43
43
|
const Modal = (0, react_1.forwardRef)((_a, ref) => {
|
|
44
|
-
var { children, open, onClose, className, shouldCloseOnOverlayClick = true } = _a, rest = __rest(_a, ["children", "open", "onClose", "className", "shouldCloseOnOverlayClick"]);
|
|
44
|
+
var { children, open, onClose, className, shouldCloseOnOverlayClick = true, closeButton = true } = _a, rest = __rest(_a, ["children", "open", "onClose", "className", "shouldCloseOnOverlayClick", "closeButton"]);
|
|
45
45
|
const modalRef = (0, react_1.useRef)(null);
|
|
46
46
|
const mergedRef = (0, react_merge_refs_1.default)([modalRef, ref]);
|
|
47
47
|
const buttonRef = (0, react_1.useRef)(null);
|
|
@@ -55,10 +55,10 @@ const Modal = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
55
55
|
};
|
|
56
56
|
return (react_1.default.createElement(react_modal_1.default, Object.assign({}, rest, { isOpen: open, ref: mergedRef, className: (0, classnames_1.default)("navds-modal", className), overlayClassName: "navds-modal__overlay", shouldCloseOnOverlayClick: shouldCloseOnOverlayClick, onRequestClose: (e) => onModalCloseRequest(e) }),
|
|
57
57
|
children,
|
|
58
|
-
react_1.default.createElement(__1.Button, { className: (0, classnames_1.default)("navds-modal__button", {
|
|
58
|
+
closeButton && (react_1.default.createElement(__1.Button, { className: (0, classnames_1.default)("navds-modal__button", {
|
|
59
59
|
"navds-modal__button--shake": shouldCloseOnOverlayClick,
|
|
60
|
-
}), size: "small", variant: "
|
|
61
|
-
react_1.default.createElement(ds_icons_1.Close, { title: "
|
|
60
|
+
}), size: "small", variant: "tertiary", ref: buttonRef, onClick: onClose },
|
|
61
|
+
react_1.default.createElement(ds_icons_1.Close, { title: "Lukk modalvindu" })))));
|
|
62
62
|
});
|
|
63
63
|
Modal.setAppElement = (element) => react_modal_1.default.setAppElement(element);
|
|
64
64
|
Modal.Content = ModalContent_1.default;
|
package/esm/button/Button.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
|
|
|
21
21
|
* @default false
|
|
22
22
|
*/
|
|
23
23
|
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Replaces button content with a Loader component, keeps width
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
loading?: boolean;
|
|
24
29
|
}
|
|
25
30
|
declare const Button: OverridableComponent<ButtonProps, HTMLButtonElement>;
|
|
26
31
|
export default Button;
|
package/esm/button/Button.js
CHANGED
|
@@ -9,13 +9,32 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React, { forwardRef } from "react";
|
|
12
|
+
import React, { useRef, useState, forwardRef } from "react";
|
|
13
|
+
import mergeRefs from "react-merge-refs";
|
|
13
14
|
import cl from "classnames";
|
|
14
|
-
import { BodyShort } from "../";
|
|
15
|
+
import { BodyShort, Loader } from "../";
|
|
16
|
+
import { useClientLayoutEffect } from "../util";
|
|
15
17
|
const Button = forwardRef((_a, ref) => {
|
|
16
|
-
var { as: Component = "button", variant = "primary", className, children, size = "medium" } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size"]);
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
var { as: Component = "button", variant = "primary", className, children, size = "medium", loading = false, disabled } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size", "loading", "disabled"]);
|
|
19
|
+
const buttonRef = useRef(null);
|
|
20
|
+
const mergedRef = mergeRefs([buttonRef, ref]);
|
|
21
|
+
const [widthOverride, setWidthOverride] = useState();
|
|
22
|
+
useClientLayoutEffect(() => {
|
|
23
|
+
if (loading) {
|
|
24
|
+
const requestID = window.requestAnimationFrame(() => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
setWidthOverride((_b = (_a = buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width);
|
|
27
|
+
});
|
|
28
|
+
return () => {
|
|
29
|
+
setWidthOverride(undefined);
|
|
30
|
+
cancelAnimationFrame(requestID);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}, [loading, children]);
|
|
34
|
+
return (React.createElement(Component, Object.assign({}, rest, { ref: mergedRef, className: cl(className, "navds-button", `navds-button--${variant}`, `navds-button--${size}`, {
|
|
35
|
+
"navds-button--loading": widthOverride,
|
|
36
|
+
}), style: { width: widthOverride }, disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }),
|
|
37
|
+
React.createElement(BodyShort, { as: "span", className: "navds-button__inner", size: size, "aria-live": "polite" }, widthOverride ? React.createElement(Loader, { size: size }) : children)));
|
|
19
38
|
});
|
|
20
39
|
export default Button;
|
|
21
40
|
//# sourceMappingURL=Button.js.map
|
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,UAAU,EAAE,MAAM,OAAO,CAAC;
|
|
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,MAAM,OAAO,CAAC;AAC5D,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE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,aAAa;SACvC,CACF,EACD,KAAK,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,CAAA,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,aAAa,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAEtD,oBAAC,SAAS,IACR,EAAE,EAAC,MAAM,EACT,SAAS,EAAC,qBAAqB,EAC/B,IAAI,EAAE,IAAI,eACA,QAAQ,IAEjB,aAAa,CAAC,CAAC,CAAC,oBAAC,MAAM,IAAC,IAAI,EAAE,IAAI,GAAI,CAAC,CAAC,CAAC,QAAQ,CACxC,CACF,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/esm/form/Switch.js
CHANGED
|
@@ -14,7 +14,7 @@ import React, { forwardRef, useEffect, useState, } from "react";
|
|
|
14
14
|
import { BodyShort, Detail, Loader, omit } from "..";
|
|
15
15
|
import { useFormField } from "./useFormField";
|
|
16
16
|
const SelectedIcon = () => (React.createElement("svg", { width: "12px", height: "12px", viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", focusable: false, role: "img", "aria-hidden": true, "aria-label": "Deaktiver valg" },
|
|
17
|
-
React.createElement("path", {
|
|
17
|
+
React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M4.01386 8L10.25 2L11 2.75L4.01386 9.5L1 6.5L1.75 5.75L4.01386 8Z", fill: "currentColor", stroke: "currentColor" })));
|
|
18
18
|
const Switch = forwardRef((props, ref) => {
|
|
19
19
|
var _a;
|
|
20
20
|
const { inputProps, size } = useFormField(props, "switch");
|
package/esm/form/Switch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../src/form/Switch.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,UAAU,EA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C9B,GAAG,EAAE,GAAG,EACR,IAAI,EAAC,UAAU,EACf,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAChC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,qBAAqB,CAAC,IAC/C;QACF,8BAAM,SAAS,EAAC,qBAAqB;YACnC,8BAAM,SAAS,EAAC,qBAAqB,IAClC,OAAO,CAAC,CAAC,CAAC,CACT,oBAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,GAAG,CACzB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACZ,oBAAC,YAAY,OAAG,CACjB,CAAC,CAAC,CAAC,IAAI,CACH,CACF;QACP,+BAAO,OAAO,EAAE,UAAU,CAAC,EAAE,EAAE,SAAS,EAAC,6BAA6B;YACpE,6BACE,SAAS,EAAE,EAAE,CAAC,uBAAuB,EAAE;oBACrC,SAAS,EAAE,SAAS;oBACpB,gCAAgC,EAAE,CAAC,CAAC,WAAW,IAAI,CAAC,SAAS;iBAC9D,CAAC;gBAEF,oBAAC,SAAS,IAAC,EAAE,EAAC,KAAK,EAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAC,qBAAqB,IAC5D,QAAQ,CACC;gBACX,WAAW,IAAI,CACd,oBAAC,WAAW,IACV,EAAE,EAAC,KAAK,EACR,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,2BAA2B,IAEpC,WAAW,CACA,CACf,CACG,CACA,CACJ,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/esm/modal/Modal.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export interface ModalProps {
|
|
|
23
23
|
* User defined classname for modal
|
|
24
24
|
*/
|
|
25
25
|
className?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Toggles addition of a X-button on modal
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
closeButton?: boolean;
|
|
26
31
|
}
|
|
27
32
|
interface ModalComponent extends ModalLifecycle, React.ForwardRefExoticComponent<ModalProps & React.RefAttributes<ReactModal>> {
|
|
28
33
|
Content: ModalContentType;
|
package/esm/modal/Modal.js
CHANGED
|
@@ -17,7 +17,7 @@ import { Close } from "@navikt/ds-icons";
|
|
|
17
17
|
import { Button } from "..";
|
|
18
18
|
import ModalContent from "./ModalContent";
|
|
19
19
|
const Modal = forwardRef((_a, ref) => {
|
|
20
|
-
var { children, open, onClose, className, shouldCloseOnOverlayClick = true } = _a, rest = __rest(_a, ["children", "open", "onClose", "className", "shouldCloseOnOverlayClick"]);
|
|
20
|
+
var { children, open, onClose, className, shouldCloseOnOverlayClick = true, closeButton = true } = _a, rest = __rest(_a, ["children", "open", "onClose", "className", "shouldCloseOnOverlayClick", "closeButton"]);
|
|
21
21
|
const modalRef = useRef(null);
|
|
22
22
|
const mergedRef = mergeRefs([modalRef, ref]);
|
|
23
23
|
const buttonRef = useRef(null);
|
|
@@ -31,10 +31,10 @@ const Modal = forwardRef((_a, ref) => {
|
|
|
31
31
|
};
|
|
32
32
|
return (React.createElement(ReactModal, Object.assign({}, rest, { isOpen: open, ref: mergedRef, className: cl("navds-modal", className), overlayClassName: "navds-modal__overlay", shouldCloseOnOverlayClick: shouldCloseOnOverlayClick, onRequestClose: (e) => onModalCloseRequest(e) }),
|
|
33
33
|
children,
|
|
34
|
-
React.createElement(Button, { className: cl("navds-modal__button", {
|
|
34
|
+
closeButton && (React.createElement(Button, { className: cl("navds-modal__button", {
|
|
35
35
|
"navds-modal__button--shake": shouldCloseOnOverlayClick,
|
|
36
|
-
}), size: "small", variant: "
|
|
37
|
-
React.createElement(Close, { title: "
|
|
36
|
+
}), size: "small", variant: "tertiary", ref: buttonRef, onClick: onClose },
|
|
37
|
+
React.createElement(Close, { title: "Lukk modalvindu" })))));
|
|
38
38
|
});
|
|
39
39
|
Modal.setAppElement = (element) => ReactModal.setAppElement(element);
|
|
40
40
|
Modal.Content = ModalContent;
|
package/esm/modal/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,YAAkC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,YAAkC,MAAM,gBAAgB,CAAC;AA2ChE,MAAM,KAAK,GAAG,UAAU,CACtB,CACE,EAQC,EACD,GAAG,EACH,EAAE;QAVF,EACE,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,SAAS,EACT,yBAAyB,GAAG,IAAI,EAChC,WAAW,GAAG,IAAI,OAEnB,EADI,IAAI,cAPT,wFAQC,CADQ;IAIT,MAAM,QAAQ,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG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": "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": "236feb37e8107c8ed6752496e387ea76dc798c6d"
|
|
68
68
|
}
|
package/src/button/Button.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
1
|
+
import React, { useRef, useState, forwardRef } from "react";
|
|
2
|
+
import mergeRefs from "react-merge-refs";
|
|
2
3
|
import cl from "classnames";
|
|
3
|
-
import { BodyShort, OverridableComponent } from "../";
|
|
4
|
+
import { BodyShort, OverridableComponent, Loader } from "../";
|
|
5
|
+
import { useClientLayoutEffect } from "../util";
|
|
4
6
|
|
|
5
7
|
export interface ButtonProps
|
|
6
8
|
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
@@ -24,6 +26,11 @@ export interface ButtonProps
|
|
|
24
26
|
* @default false
|
|
25
27
|
*/
|
|
26
28
|
disabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Replaces button content with a Loader component, keeps width
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
loading?: boolean;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
const Button: OverridableComponent<ButtonProps, HTMLButtonElement> = forwardRef(
|
|
@@ -34,25 +41,55 @@ const Button: OverridableComponent<ButtonProps, HTMLButtonElement> = forwardRef(
|
|
|
34
41
|
className,
|
|
35
42
|
children,
|
|
36
43
|
size = "medium",
|
|
44
|
+
loading = false,
|
|
45
|
+
disabled,
|
|
37
46
|
...rest
|
|
38
47
|
},
|
|
39
48
|
ref
|
|
40
|
-
) =>
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
) => {
|
|
50
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
51
|
+
const mergedRef = mergeRefs([buttonRef, ref]);
|
|
52
|
+
const [widthOverride, setWidthOverride] = useState<number>();
|
|
53
|
+
|
|
54
|
+
useClientLayoutEffect(() => {
|
|
55
|
+
if (loading) {
|
|
56
|
+
const requestID = window.requestAnimationFrame(() => {
|
|
57
|
+
setWidthOverride(buttonRef?.current?.getBoundingClientRect()?.width);
|
|
58
|
+
});
|
|
59
|
+
return () => {
|
|
60
|
+
setWidthOverride(undefined);
|
|
61
|
+
cancelAnimationFrame(requestID);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, [loading, children]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Component
|
|
68
|
+
{...rest}
|
|
69
|
+
ref={mergedRef}
|
|
70
|
+
className={cl(
|
|
71
|
+
className,
|
|
72
|
+
"navds-button",
|
|
73
|
+
`navds-button--${variant}`,
|
|
74
|
+
`navds-button--${size}`,
|
|
75
|
+
{
|
|
76
|
+
"navds-button--loading": widthOverride,
|
|
77
|
+
}
|
|
78
|
+
)}
|
|
79
|
+
style={{ width: widthOverride }}
|
|
80
|
+
disabled={disabled ?? widthOverride ? true : undefined}
|
|
81
|
+
>
|
|
82
|
+
<BodyShort
|
|
83
|
+
as="span"
|
|
84
|
+
className="navds-button__inner"
|
|
85
|
+
size={size}
|
|
86
|
+
aria-live="polite"
|
|
87
|
+
>
|
|
88
|
+
{widthOverride ? <Loader size={size} /> : children}
|
|
89
|
+
</BodyShort>
|
|
90
|
+
</Component>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
56
93
|
);
|
|
57
94
|
|
|
58
95
|
export default Button;
|
|
@@ -45,26 +45,32 @@ Button har to størrelser: Default 48px min-height og small 32px min-height
|
|
|
45
45
|
</Button>
|
|
46
46
|
</Canvas>
|
|
47
47
|
|
|
48
|
-
##
|
|
48
|
+
## Loading
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
bli justert
|
|
50
|
+
Button har en egen `loading`-prop setter knappen til disabled og viser `Loader`.
|
|
51
|
+
Button width bli automatisk justert basert på innholdet sin bredde.
|
|
52
52
|
|
|
53
53
|
<Canvas>
|
|
54
|
-
<Button>
|
|
55
|
-
|
|
54
|
+
<Button loading variant="primary">
|
|
55
|
+
Primary
|
|
56
56
|
</Button>
|
|
57
|
-
<Button
|
|
58
|
-
|
|
59
|
-
Laster...
|
|
60
|
-
<Loader />
|
|
57
|
+
<Button loading variant="secondary">
|
|
58
|
+
Secondary
|
|
61
59
|
</Button>
|
|
60
|
+
</Canvas>
|
|
61
|
+
|
|
62
|
+
## Med ikon
|
|
63
|
+
|
|
64
|
+
Hvis man setter ikoner (svg) rett på button vil størrelsen
|
|
65
|
+
bli justert automatisk og sentrert.
|
|
66
|
+
|
|
67
|
+
<Canvas>
|
|
62
68
|
<Button>
|
|
63
|
-
<Success />
|
|
69
|
+
<Success /> Knapp <Success />
|
|
64
70
|
</Button>
|
|
65
71
|
<Button size="small">
|
|
66
72
|
<Success />
|
|
67
|
-
|
|
73
|
+
Knapp
|
|
68
74
|
<Success />
|
|
69
75
|
</Button>
|
|
70
76
|
</Canvas>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { Button } from "../index";
|
|
3
3
|
import { Success } from "@navikt/ds-icons";
|
|
4
4
|
|
|
@@ -37,6 +37,13 @@ const varSwitch = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export const All = () => {
|
|
40
|
+
const [loadingState, setLoadingState] = useState(true);
|
|
41
|
+
const [content, setContent] = useState<string>("");
|
|
42
|
+
|
|
43
|
+
const toggleLoading = () => {
|
|
44
|
+
setLoadingState(!loadingState);
|
|
45
|
+
};
|
|
46
|
+
|
|
40
47
|
return (
|
|
41
48
|
<div style={{ paddingLeft: "1rem" }}>
|
|
42
49
|
<h1>Button</h1>
|
|
@@ -103,6 +110,37 @@ export const All = () => {
|
|
|
103
110
|
</Button>
|
|
104
111
|
))}
|
|
105
112
|
</Section>
|
|
113
|
+
<h2>Button w/loader</h2>
|
|
114
|
+
<Button onClick={toggleLoading}>Toggle loaders</Button>
|
|
115
|
+
<Button onClick={() => setContent((content) => `${content} wat`)}>
|
|
116
|
+
Change content
|
|
117
|
+
</Button>
|
|
118
|
+
<Section>
|
|
119
|
+
{variants.map((variant) => (
|
|
120
|
+
<Button
|
|
121
|
+
key={variant}
|
|
122
|
+
variant={variant}
|
|
123
|
+
loading={loadingState}
|
|
124
|
+
onClick={toggleLoading}
|
|
125
|
+
>
|
|
126
|
+
{content || varSwitch[variant]}
|
|
127
|
+
</Button>
|
|
128
|
+
))}
|
|
129
|
+
</Section>
|
|
130
|
+
<h2>Small w/loader</h2>
|
|
131
|
+
<Section>
|
|
132
|
+
{variants.map((variant) => (
|
|
133
|
+
<Button
|
|
134
|
+
key={variant}
|
|
135
|
+
variant={variant}
|
|
136
|
+
size="small"
|
|
137
|
+
loading={loadingState}
|
|
138
|
+
onClick={toggleLoading}
|
|
139
|
+
>
|
|
140
|
+
{varSwitch[variant]}
|
|
141
|
+
</Button>
|
|
142
|
+
))}
|
|
143
|
+
</Section>
|
|
106
144
|
</div>
|
|
107
145
|
);
|
|
108
146
|
};
|
package/src/form/Switch.tsx
CHANGED
|
@@ -21,8 +21,8 @@ const SelectedIcon = () => (
|
|
|
21
21
|
aria-label="Deaktiver valg"
|
|
22
22
|
>
|
|
23
23
|
<path
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
fillRule="evenodd"
|
|
25
|
+
clipRule="evenodd"
|
|
26
26
|
d="M4.01386 8L10.25 2L11 2.75L4.01386 9.5L1 6.5L1.75 5.75L4.01386 8Z"
|
|
27
27
|
fill="currentColor"
|
|
28
28
|
stroke="currentColor"
|
|
@@ -63,25 +63,3 @@ Bakgrunnen kan settes til transparent med `transparent={true}`
|
|
|
63
63
|
<Canvas>
|
|
64
64
|
<Loader size="2xlarge" transparent />
|
|
65
65
|
</Canvas>
|
|
66
|
-
|
|
67
|
-
## Bruk av loader i knapper
|
|
68
|
-
|
|
69
|
-
Husk her å gi brukeren nok informasjon om hvorfor knappen har en Loader. Dette kan gjøres ved å ha god tekst på siden,
|
|
70
|
-
i knappen og i `title`-proppen for `Loader`. Unngå også bruk av `Loader` uten noen tekst som hinter til hva som foregår.
|
|
71
|
-
|
|
72
|
-
Stylingen er overstyrt for knapper, slik at `transparent` ikke fungerer by-default ved bruk i knapper.
|
|
73
|
-
Størrelsen justeres også automatisk, slik at alt man trenger er å sette Loaderen rett inn i knappen.
|
|
74
|
-
|
|
75
|
-
```jsx
|
|
76
|
-
<Button>
|
|
77
|
-
Laster inn nytt innhold...
|
|
78
|
-
<Loader />
|
|
79
|
-
</Button>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
<Canvas>
|
|
83
|
-
<Button>
|
|
84
|
-
Laster inn nytt innhold...
|
|
85
|
-
<Loader />
|
|
86
|
-
</Button>
|
|
87
|
-
</Canvas>
|
package/src/modal/Modal.tsx
CHANGED
|
@@ -28,6 +28,11 @@ export interface ModalProps {
|
|
|
28
28
|
* User defined classname for modal
|
|
29
29
|
*/
|
|
30
30
|
className?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Toggles addition of a X-button on modal
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
closeButton?: boolean;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
interface ModalComponent
|
|
@@ -50,6 +55,7 @@ const Modal = forwardRef<ReactModal, ModalProps>(
|
|
|
50
55
|
onClose,
|
|
51
56
|
className,
|
|
52
57
|
shouldCloseOnOverlayClick = true,
|
|
58
|
+
closeButton = true,
|
|
53
59
|
...rest
|
|
54
60
|
},
|
|
55
61
|
ref
|
|
@@ -77,18 +83,19 @@ const Modal = forwardRef<ReactModal, ModalProps>(
|
|
|
77
83
|
onRequestClose={(e) => onModalCloseRequest(e)}
|
|
78
84
|
>
|
|
79
85
|
{children}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"navds-modal__button
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
{closeButton && (
|
|
87
|
+
<Button
|
|
88
|
+
className={cl("navds-modal__button", {
|
|
89
|
+
"navds-modal__button--shake": shouldCloseOnOverlayClick,
|
|
90
|
+
})}
|
|
91
|
+
size="small"
|
|
92
|
+
variant="tertiary"
|
|
93
|
+
ref={buttonRef}
|
|
94
|
+
onClick={onClose}
|
|
95
|
+
>
|
|
96
|
+
<Close title="Lukk modalvindu" />
|
|
97
|
+
</Button>
|
|
98
|
+
)}
|
|
92
99
|
</ReactModal>
|
|
93
100
|
);
|
|
94
101
|
}
|
|
@@ -11,6 +11,7 @@ Modal.setAppElement("#root");
|
|
|
11
11
|
export const All = () => {
|
|
12
12
|
const [open, setOpen] = useState(true);
|
|
13
13
|
const [openTwo, setOpenTwo] = useState(false);
|
|
14
|
+
const [openThree, setOpenThree] = useState(false);
|
|
14
15
|
|
|
15
16
|
return (
|
|
16
17
|
<>
|
|
@@ -46,6 +47,21 @@ export const All = () => {
|
|
|
46
47
|
</p>
|
|
47
48
|
</Modal.Content>
|
|
48
49
|
</Modal>
|
|
50
|
+
<button onClick={() => setOpenThree(true)}>
|
|
51
|
+
Open modal without x-button
|
|
52
|
+
</button>
|
|
53
|
+
<Modal
|
|
54
|
+
open={openThree}
|
|
55
|
+
closeButton={false}
|
|
56
|
+
onClose={() => setOpenThree(false)}
|
|
57
|
+
>
|
|
58
|
+
<Modal.Content>
|
|
59
|
+
<h1>Header</h1>
|
|
60
|
+
<h2>subheader</h2>
|
|
61
|
+
<p>Cupidatat irure ipsum veniam ad in esse.</p>
|
|
62
|
+
<p>Cillum tempor pariatur amet ut laborum Lorem enim enim.</p>
|
|
63
|
+
</Modal.Content>
|
|
64
|
+
</Modal>
|
|
49
65
|
</>
|
|
50
66
|
);
|
|
51
67
|
};
|