@navikt/ds-react 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/form/Switch.js +58 -0
- package/cjs/form/index.js +3 -1
- package/esm/form/Switch.d.ts +18 -0
- package/esm/form/Switch.js +35 -0
- package/esm/form/Switch.js.map +1 -0
- package/esm/form/index.d.ts +1 -0
- package/esm/form/index.js +1 -0
- package/esm/form/index.js.map +1 -1
- package/package.json +2 -2
- package/src/form/Switch.tsx +81 -0
- package/src/form/index.ts +1 -0
- package/src/form/stories/switch.stories.mdx +104 -0
- package/src/form/stories/switch.stories.tsx +70 -0
- package/src/table/stories/table.stories.tsx +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const __1 = require("..");
|
|
39
|
+
const useFormField_1 = require("./useFormField");
|
|
40
|
+
const Switch = (0, react_1.forwardRef)((props, ref) => {
|
|
41
|
+
const { inputProps, size } = (0, useFormField_1.useFormField)(props, "switch");
|
|
42
|
+
const { children, className, description, hideLabel = false, loading } = props, rest = __rest(props, ["children", "className", "description", "hideLabel", "loading"]);
|
|
43
|
+
const Description = size === "medium" ? __1.BodyShort : __1.Detail;
|
|
44
|
+
return (react_1.default.createElement("div", { className: (0, classnames_1.default)("navds-switch", props.className, `navds-switch--${size}`, {
|
|
45
|
+
"navds-switch--disabled": inputProps.disabled,
|
|
46
|
+
}) },
|
|
47
|
+
react_1.default.createElement("input", Object.assign({}, (0, __1.omit)(rest, ["size"]), (0, __1.omit)(inputProps, ["aria-invalid", "aria-describedby"]), { ref: ref, type: "checkbox", className: (0, classnames_1.default)(className, "navds-switch__input") })),
|
|
48
|
+
react_1.default.createElement("span", { className: "navds-switch__track" },
|
|
49
|
+
react_1.default.createElement("span", { className: "navds-switch__thumb" }, loading && react_1.default.createElement(__1.Loader, { size: "xsmall" }))),
|
|
50
|
+
react_1.default.createElement("label", { htmlFor: inputProps.id, className: "navds-switch__label-wrapper" },
|
|
51
|
+
react_1.default.createElement("div", { className: (0, classnames_1.default)("navds-switch__content", {
|
|
52
|
+
"sr-only": hideLabel,
|
|
53
|
+
"navds-switch--with-description": !!description && !hideLabel,
|
|
54
|
+
}) },
|
|
55
|
+
react_1.default.createElement(__1.BodyShort, { as: "div", size: size, className: "navds-switch__label" }, children),
|
|
56
|
+
description && (react_1.default.createElement(Description, { as: "div", size: "small", className: "navds-switch__description" }, description))))));
|
|
57
|
+
});
|
|
58
|
+
exports.default = Switch;
|
package/cjs/form/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ConfirmationPanel = exports.TextField = exports.Textarea = exports.Counter = exports.ErrorSummary = exports.Select = exports.SearchField = exports.RadioGroup = exports.Radio = exports.FieldsetContext = exports.Fieldset = exports.CheckboxGroup = exports.Checkbox = void 0;
|
|
6
|
+
exports.ConfirmationPanel = exports.TextField = exports.Textarea = exports.Counter = exports.ErrorSummary = exports.Switch = exports.Select = exports.SearchField = exports.RadioGroup = exports.Radio = exports.FieldsetContext = exports.Fieldset = exports.CheckboxGroup = exports.Checkbox = void 0;
|
|
7
7
|
var checkbox_1 = require("./checkbox");
|
|
8
8
|
Object.defineProperty(exports, "Checkbox", { enumerable: true, get: function () { return checkbox_1.Checkbox; } });
|
|
9
9
|
Object.defineProperty(exports, "CheckboxGroup", { enumerable: true, get: function () { return checkbox_1.CheckboxGroup; } });
|
|
@@ -17,6 +17,8 @@ var search_field_1 = require("./search-field");
|
|
|
17
17
|
Object.defineProperty(exports, "SearchField", { enumerable: true, get: function () { return search_field_1.SearchField; } });
|
|
18
18
|
var Select_1 = require("./Select");
|
|
19
19
|
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return __importDefault(Select_1).default; } });
|
|
20
|
+
var Switch_1 = require("./Switch");
|
|
21
|
+
Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return __importDefault(Switch_1).default; } });
|
|
20
22
|
var error_summary_1 = require("./error-summary");
|
|
21
23
|
Object.defineProperty(exports, "ErrorSummary", { enumerable: true, get: function () { return error_summary_1.ErrorSummary; } });
|
|
22
24
|
var Textarea_1 = require("./Textarea");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { InputHTMLAttributes } from "react";
|
|
2
|
+
import { FormFieldProps } from "./useFormField";
|
|
3
|
+
export interface SwitchProps extends Omit<FormFieldProps, "error" | "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
4
|
+
/**
|
|
5
|
+
* Switch-label
|
|
6
|
+
*/
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* If enabled shows the label and description for screenreaders only
|
|
10
|
+
*/
|
|
11
|
+
hideLabel?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Toggles loading state with loader-component on switch
|
|
14
|
+
*/
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLInputElement>>;
|
|
18
|
+
export default Switch;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import cl from "classnames";
|
|
13
|
+
import React, { forwardRef } from "react";
|
|
14
|
+
import { BodyShort, Detail, Loader, omit } from "..";
|
|
15
|
+
import { useFormField } from "./useFormField";
|
|
16
|
+
const Switch = forwardRef((props, ref) => {
|
|
17
|
+
const { inputProps, size } = useFormField(props, "switch");
|
|
18
|
+
const { children, className, description, hideLabel = false, loading } = props, rest = __rest(props, ["children", "className", "description", "hideLabel", "loading"]);
|
|
19
|
+
const Description = size === "medium" ? BodyShort : Detail;
|
|
20
|
+
return (React.createElement("div", { className: cl("navds-switch", props.className, `navds-switch--${size}`, {
|
|
21
|
+
"navds-switch--disabled": inputProps.disabled,
|
|
22
|
+
}) },
|
|
23
|
+
React.createElement("input", Object.assign({}, omit(rest, ["size"]), omit(inputProps, ["aria-invalid", "aria-describedby"]), { ref: ref, type: "checkbox", className: cl(className, "navds-switch__input") })),
|
|
24
|
+
React.createElement("span", { className: "navds-switch__track" },
|
|
25
|
+
React.createElement("span", { className: "navds-switch__thumb" }, loading && React.createElement(Loader, { size: "xsmall" }))),
|
|
26
|
+
React.createElement("label", { htmlFor: inputProps.id, className: "navds-switch__label-wrapper" },
|
|
27
|
+
React.createElement("div", { className: cl("navds-switch__content", {
|
|
28
|
+
"sr-only": hideLabel,
|
|
29
|
+
"navds-switch--with-description": !!description && !hideLabel,
|
|
30
|
+
}) },
|
|
31
|
+
React.createElement(BodyShort, { as: "div", size: size, className: "navds-switch__label" }, children),
|
|
32
|
+
description && (React.createElement(Description, { as: "div", size: "small", className: "navds-switch__description" }, description))))));
|
|
33
|
+
});
|
|
34
|
+
export default Switch;
|
|
35
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +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,EAAE,UAAU,EAAuB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AACrD,OAAO,EAAkB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAmB9D,MAAM,MAAM,GAAG,UAAU,CAAgC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACtE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE3D,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,GAAG,KAAK,EACjB,OAAO,KAEL,KAAK,EADJ,IAAI,UACL,KAAK,EAPH,gEAOL,CAAQ,CAAC;IAEV,MAAM,WAAW,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IAE3D,OAAO,CACL,6BACE,SAAS,EAAE,EAAE,CAAC,cAAc,EAAE,KAAK,CAAC,SAAS,EAAE,iBAAiB,IAAI,EAAE,EAAE;YACtE,wBAAwB,EAAE,UAAU,CAAC,QAAQ;SAC9C,CAAC;QAEF,+CACM,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EACpB,IAAI,CAAC,UAAU,EAAE,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC,IAC1D,GAAG,EAAE,GAAG,EACR,IAAI,EAAC,UAAU,EACf,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,qBAAqB,CAAC,IAC/C;QACF,8BAAM,SAAS,EAAC,qBAAqB;YACnC,8BAAM,SAAS,EAAC,qBAAqB,IAClC,OAAO,IAAI,oBAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,GAAG,CAC/B,CACF;QAEP,+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/form/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { default as Fieldset, FieldsetContext, FieldsetProps, } from "./Fieldset
|
|
|
3
3
|
export { Radio, RadioGroup, RadioGroupProps, RadioProps } from "./radio";
|
|
4
4
|
export { SearchField, SearchFieldProps } from "./search-field";
|
|
5
5
|
export { default as Select, SelectProps } from "./Select";
|
|
6
|
+
export { default as Switch, SwitchProps } from "./Switch";
|
|
6
7
|
export { ErrorSummary, ErrorSummaryProps } from "./error-summary";
|
|
7
8
|
export { Counter, default as Textarea, TextareaProps } from "./Textarea";
|
|
8
9
|
export { default as TextField, TextFieldProps } from "./TextField";
|
package/esm/form/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as Fieldset, FieldsetContext, } from "./Fieldset";
|
|
|
3
3
|
export { Radio, RadioGroup } from "./radio";
|
|
4
4
|
export { SearchField } from "./search-field";
|
|
5
5
|
export { default as Select } from "./Select";
|
|
6
|
+
export { default as Switch } from "./Switch";
|
|
6
7
|
export { ErrorSummary } from "./error-summary";
|
|
7
8
|
export { Counter, default as Textarea } from "./Textarea";
|
|
8
9
|
export { default as TextField } from "./TextField";
|
package/esm/form/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/form/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,aAAa,GAEd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,OAAO,IAAI,QAAQ,EACnB,eAAe,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,UAAU,EAA+B,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAe,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAqB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAiB,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAkB,MAAM,aAAa,CAAC;AACnE,OAAO,EACL,OAAO,IAAI,iBAAiB,GAE7B,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/form/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,aAAa,GAEd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,OAAO,IAAI,QAAQ,EACnB,eAAe,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,UAAU,EAA+B,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAe,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAe,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAqB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAiB,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAkB,MAAM,aAAa,CAAC;AACnE,OAAO,EACL,OAAO,IAAI,iBAAiB,GAE7B,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NAV designsystem react components",
|
|
6
6
|
"author": "NAV Designsystem team",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@types/react": "^17.0.30",
|
|
65
65
|
"react": "^17.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "ce1c6de93566f930f4f9fc917ce6be9a997a9aa6"
|
|
68
68
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import cl from "classnames";
|
|
2
|
+
import React, { forwardRef, InputHTMLAttributes } from "react";
|
|
3
|
+
import { BodyShort, Detail, Loader, omit } from "..";
|
|
4
|
+
import { FormFieldProps, useFormField } from "./useFormField";
|
|
5
|
+
|
|
6
|
+
export interface SwitchProps
|
|
7
|
+
extends Omit<FormFieldProps, "error" | "errorId">,
|
|
8
|
+
Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
9
|
+
/**
|
|
10
|
+
* Switch-label
|
|
11
|
+
*/
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* If enabled shows the label and description for screenreaders only
|
|
15
|
+
*/
|
|
16
|
+
hideLabel?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Toggles loading state with loader-component on switch
|
|
19
|
+
*/
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const Switch = forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {
|
|
24
|
+
const { inputProps, size } = useFormField(props, "switch");
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
description,
|
|
30
|
+
hideLabel = false,
|
|
31
|
+
loading,
|
|
32
|
+
...rest
|
|
33
|
+
} = props;
|
|
34
|
+
|
|
35
|
+
const Description = size === "medium" ? BodyShort : Detail;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
className={cl("navds-switch", props.className, `navds-switch--${size}`, {
|
|
40
|
+
"navds-switch--disabled": inputProps.disabled,
|
|
41
|
+
})}
|
|
42
|
+
>
|
|
43
|
+
<input
|
|
44
|
+
{...omit(rest, ["size"])}
|
|
45
|
+
{...omit(inputProps, ["aria-invalid", "aria-describedby"])}
|
|
46
|
+
ref={ref}
|
|
47
|
+
type="checkbox"
|
|
48
|
+
className={cl(className, "navds-switch__input")}
|
|
49
|
+
/>
|
|
50
|
+
<span className="navds-switch__track">
|
|
51
|
+
<span className="navds-switch__thumb">
|
|
52
|
+
{loading && <Loader size="xsmall" />}
|
|
53
|
+
</span>
|
|
54
|
+
</span>
|
|
55
|
+
|
|
56
|
+
<label htmlFor={inputProps.id} className="navds-switch__label-wrapper">
|
|
57
|
+
<div
|
|
58
|
+
className={cl("navds-switch__content", {
|
|
59
|
+
"sr-only": hideLabel,
|
|
60
|
+
"navds-switch--with-description": !!description && !hideLabel,
|
|
61
|
+
})}
|
|
62
|
+
>
|
|
63
|
+
<BodyShort as="div" size={size} className="navds-switch__label">
|
|
64
|
+
{children}
|
|
65
|
+
</BodyShort>
|
|
66
|
+
{description && (
|
|
67
|
+
<Description
|
|
68
|
+
as="div"
|
|
69
|
+
size="small"
|
|
70
|
+
className="navds-switch__description"
|
|
71
|
+
>
|
|
72
|
+
{description}
|
|
73
|
+
</Description>
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
</label>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export default Switch;
|
package/src/form/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
export { Radio, RadioGroup, RadioGroupProps, RadioProps } from "./radio";
|
|
13
13
|
export { SearchField, SearchFieldProps } from "./search-field";
|
|
14
14
|
export { default as Select, SelectProps } from "./Select";
|
|
15
|
+
export { default as Switch, SwitchProps } from "./Switch";
|
|
15
16
|
export { ErrorSummary, ErrorSummaryProps } from "./error-summary";
|
|
16
17
|
export { Counter, default as Textarea, TextareaProps } from "./Textarea";
|
|
17
18
|
export { default as TextField, TextFieldProps } from "./TextField";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Meta, Canvas } from "@storybook/addon-docs";
|
|
2
|
+
import { Switch } from "../index";
|
|
3
|
+
|
|
4
|
+
<Meta title="ds-react/form/switch/intro" />
|
|
5
|
+
|
|
6
|
+
# Hvordan ta i bruk Switch
|
|
7
|
+
|
|
8
|
+
```jsx
|
|
9
|
+
<Switch>Slå på feature</Switch>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
<Canvas>
|
|
13
|
+
<Switch>Slå på feature</Switch>
|
|
14
|
+
</Canvas>
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
<Switch description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
<Canvas>
|
|
23
|
+
<Switch description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
24
|
+
</Canvas>
|
|
25
|
+
|
|
26
|
+
## Sizing
|
|
27
|
+
|
|
28
|
+
Switch har default 48px høy klikkflate. Med size="small" blir klikkflaten 32px
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
<Switch size="small" >Slå på feature</Switch>
|
|
32
|
+
<Switch size="small" description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
<Canvas>
|
|
36
|
+
<div>
|
|
37
|
+
<Switch size="small">Slå på feature</Switch>
|
|
38
|
+
<Switch size="small" description="Dette vil gjøre x og y">
|
|
39
|
+
Slå på feature
|
|
40
|
+
</Switch>
|
|
41
|
+
</div>
|
|
42
|
+
</Canvas>
|
|
43
|
+
|
|
44
|
+
## defaultChecked
|
|
45
|
+
|
|
46
|
+
Switch er en stylet checkbox, så både `checked` og `defaultChecked` fungerer
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
<Switch defaultChecked>Slå på feature</Switch>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
<Canvas>
|
|
53
|
+
<Switch defaultChecked>Slå på feature</Switch>
|
|
54
|
+
</Canvas>
|
|
55
|
+
|
|
56
|
+
## hideLabel
|
|
57
|
+
|
|
58
|
+
Ved bruk av `hideLegend` på Switch kan man gjøre slik at legend/description bare vises for skjermlesere
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
<Switch hideLabel>Slå på feature</Switch>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
<Canvas>
|
|
65
|
+
<Switch hideLabel>Slå på feature</Switch>
|
|
66
|
+
</Canvas>
|
|
67
|
+
|
|
68
|
+
## Disabled
|
|
69
|
+
|
|
70
|
+
Ved bruk av `disabled` kan man både disabled enkelte checkboxer eller checkboxgruppen.
|
|
71
|
+
|
|
72
|
+
NOTE: Husk at disabled bør unngås!
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
<Switch disabled>Slå på feature</Switch>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
<Canvas>
|
|
79
|
+
<div>
|
|
80
|
+
<Switch disabled>Slå på feature</Switch>
|
|
81
|
+
<Switch disabled defaultChecked>
|
|
82
|
+
Slå på feature
|
|
83
|
+
</Switch>
|
|
84
|
+
</div>
|
|
85
|
+
</Canvas>
|
|
86
|
+
|
|
87
|
+
## Loading
|
|
88
|
+
|
|
89
|
+
Om systemet bruker tid på å utføre handlingen vises en loading-indikator på switch’en.
|
|
90
|
+
Om ventetiden er mer enn noen sekunder bør en forklarende tekst også vises.
|
|
91
|
+
Teksten må forklare kort og godt hvorfor brukeren må vente.
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
<Switch loading>Slå på feature</Switch>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
<Canvas>
|
|
98
|
+
<div>
|
|
99
|
+
<Switch loading>Slå på feature</Switch>
|
|
100
|
+
<Switch loading defaultChecked>
|
|
101
|
+
Slå på feature
|
|
102
|
+
</Switch>
|
|
103
|
+
</div>
|
|
104
|
+
</Canvas>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Switch } from "../index";
|
|
3
|
+
import { Meta } from "@storybook/react/types-6-0";
|
|
4
|
+
import { Fieldset } from "../..";
|
|
5
|
+
export default {
|
|
6
|
+
title: "ds-react/form/switch",
|
|
7
|
+
component: Switch,
|
|
8
|
+
} as Meta;
|
|
9
|
+
|
|
10
|
+
export const All = () => {
|
|
11
|
+
const [checked, setChecked] = useState(false);
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<h1>Switch</h1>
|
|
15
|
+
<Switch>Label text</Switch>
|
|
16
|
+
|
|
17
|
+
<h2>Switch w/Description</h2>
|
|
18
|
+
<Switch>Label text</Switch>
|
|
19
|
+
<Switch description="Switch description">Label text</Switch>
|
|
20
|
+
<Switch>Label text</Switch>
|
|
21
|
+
|
|
22
|
+
<h2>hidelabel</h2>
|
|
23
|
+
<Switch description="Switch description" hideLabel>
|
|
24
|
+
Label text
|
|
25
|
+
</Switch>
|
|
26
|
+
<Switch description="Switch description" hideLabel>
|
|
27
|
+
Label text
|
|
28
|
+
</Switch>
|
|
29
|
+
<Switch hideLabel size="small">
|
|
30
|
+
Label text small
|
|
31
|
+
</Switch>
|
|
32
|
+
|
|
33
|
+
<h2>Switch small</h2>
|
|
34
|
+
<Switch size="small">Label text</Switch>
|
|
35
|
+
<Switch description="Switch description" size="small">
|
|
36
|
+
Label text
|
|
37
|
+
</Switch>
|
|
38
|
+
<Switch size="small">Label text</Switch>
|
|
39
|
+
|
|
40
|
+
<h2>Controlled</h2>
|
|
41
|
+
<Switch checked={checked} onChange={() => setChecked(!checked)}>
|
|
42
|
+
Label text
|
|
43
|
+
</Switch>
|
|
44
|
+
|
|
45
|
+
<h2>Defaultchecked</h2>
|
|
46
|
+
<Switch defaultChecked>Label text</Switch>
|
|
47
|
+
|
|
48
|
+
<h2>Disabled</h2>
|
|
49
|
+
<Switch disabled>Label text</Switch>
|
|
50
|
+
<Switch disabled defaultChecked>
|
|
51
|
+
Label text
|
|
52
|
+
</Switch>
|
|
53
|
+
|
|
54
|
+
<h2>With fieldset error</h2>
|
|
55
|
+
<Fieldset legend="Fieldset legend" error="Errormsg">
|
|
56
|
+
<Switch defaultChecked>Label text</Switch>
|
|
57
|
+
<Switch>Label text</Switch>
|
|
58
|
+
</Fieldset>
|
|
59
|
+
|
|
60
|
+
<h2>loading prop</h2>
|
|
61
|
+
<Switch loading>Label text</Switch>
|
|
62
|
+
<Switch size="small" loading>
|
|
63
|
+
Label text
|
|
64
|
+
</Switch>
|
|
65
|
+
<Switch disabled loading>
|
|
66
|
+
Label text
|
|
67
|
+
</Switch>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -142,7 +142,7 @@ const SelectionTable = ({ size = "medium" }: { size?: "small" | "medium" }) => {
|
|
|
142
142
|
const [selectedRows, toggleSelectedRow] = useToggleList([]);
|
|
143
143
|
|
|
144
144
|
return (
|
|
145
|
-
<Table size={size}>
|
|
145
|
+
<Table size={size} zebraStripes>
|
|
146
146
|
<Table.Body>
|
|
147
147
|
<Table.Row>
|
|
148
148
|
<Table.DataCell>
|