@navikt/ds-react 0.16.5 → 0.16.9
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/alert/Alert.js +5 -5
- package/cjs/index.js +1 -0
- package/cjs/toggle-group/ToggleGroup.js +68 -0
- package/cjs/toggle-group/ToggleItem.js +47 -0
- package/cjs/toggle-group/index.js +8 -0
- package/cjs/toggle-group/package.json +6 -0
- package/esm/alert/Alert.js +5 -5
- package/esm/alert/Alert.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/modal/Modal.d.ts +1 -1
- package/esm/table/DataCell.d.ts +1 -1
- package/esm/table/HeaderCell.d.ts +1 -1
- package/esm/table/Table.d.ts +1 -1
- package/esm/table/Table.js.map +1 -1
- package/esm/toggle-group/ToggleGroup.d.ts +38 -0
- package/esm/toggle-group/ToggleGroup.js +44 -0
- package/esm/toggle-group/ToggleGroup.js.map +1 -0
- package/esm/toggle-group/ToggleItem.d.ts +14 -0
- package/esm/toggle-group/ToggleItem.js +24 -0
- package/esm/toggle-group/ToggleItem.js.map +1 -0
- package/esm/toggle-group/index.d.ts +2 -0
- package/esm/toggle-group/index.js +2 -0
- package/esm/toggle-group/index.js.map +1 -0
- package/package.json +3 -2
- package/src/alert/Alert.tsx +5 -9
- package/src/button/button.stories.tsx +3 -0
- package/src/index.ts +1 -0
- package/src/modal/Modal.tsx +1 -1
- package/src/table/DataCell.tsx +1 -1
- package/src/table/HeaderCell.tsx +1 -1
- package/src/table/Table.tsx +2 -1
- package/src/toggle-group/ToggleGroup.stories.tsx +111 -0
- package/src/toggle-group/ToggleGroup.tsx +131 -0
- package/src/toggle-group/ToggleItem.tsx +45 -0
- package/src/toggle-group/index.ts +2 -0
package/cjs/alert/Alert.js
CHANGED
|
@@ -41,13 +41,13 @@ const Icon = (_a) => {
|
|
|
41
41
|
var { variant } = _a, props = __rest(_a, ["variant"]);
|
|
42
42
|
switch (variant) {
|
|
43
43
|
case "error":
|
|
44
|
-
return react_1.default.createElement(ds_icons_1.ErrorFilled, Object.assign({}, props));
|
|
44
|
+
return react_1.default.createElement(ds_icons_1.ErrorFilled, Object.assign({ title: "Feil" }, props));
|
|
45
45
|
case "warning":
|
|
46
|
-
return react_1.default.createElement(ds_icons_1.WarningFilled, Object.assign({}, props));
|
|
46
|
+
return react_1.default.createElement(ds_icons_1.WarningFilled, Object.assign({ title: "Advarsel" }, props));
|
|
47
47
|
case "info":
|
|
48
|
-
return react_1.default.createElement(ds_icons_1.InformationFilled, Object.assign({}, props));
|
|
48
|
+
return react_1.default.createElement(ds_icons_1.InformationFilled, Object.assign({ title: "Informasjon" }, props));
|
|
49
49
|
case "success":
|
|
50
|
-
return react_1.default.createElement(ds_icons_1.SuccessFilled, Object.assign({}, props));
|
|
50
|
+
return react_1.default.createElement(ds_icons_1.SuccessFilled, Object.assign({ title: "Suksess" }, props));
|
|
51
51
|
default:
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
@@ -55,7 +55,7 @@ const Icon = (_a) => {
|
|
|
55
55
|
const Alert = (0, react_1.forwardRef)((_a, ref) => {
|
|
56
56
|
var { children, className, variant, size = "medium", fullWidth = false, inline = false } = _a, rest = __rest(_a, ["children", "className", "variant", "size", "fullWidth", "inline"]);
|
|
57
57
|
return (react_1.default.createElement("div", Object.assign({}, rest, { ref: ref, className: (0, classnames_1.default)(className, "navds-alert", `navds-alert--${variant}`, `navds-alert--${size}`, { "navds-alert--full-width": fullWidth, "navds-alert--inline": inline }) }),
|
|
58
|
-
react_1.default.createElement(Icon, {
|
|
58
|
+
react_1.default.createElement(Icon, { variant: variant, className: "navds-alert__icon" }),
|
|
59
59
|
react_1.default.createElement(__1.BodyLong, { as: "div", size: size, className: "navds-alert__wrapper" }, children)));
|
|
60
60
|
});
|
|
61
61
|
exports.default = Alert;
|
package/cjs/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./popover"), exports);
|
|
|
27
27
|
__exportStar(require("./speech-bubble"), exports);
|
|
28
28
|
__exportStar(require("./step-indicator"), exports);
|
|
29
29
|
__exportStar(require("./tag"), exports);
|
|
30
|
+
__exportStar(require("./toggle-group"), exports);
|
|
30
31
|
__exportStar(require("./table"), exports);
|
|
31
32
|
__exportStar(require("./typography"), exports);
|
|
32
33
|
__exportStar(require("./util"), exports);
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
exports.ToggleGroupContext = void 0;
|
|
37
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const ToggleItem_1 = __importDefault(require("./ToggleItem"));
|
|
40
|
+
const RadixToggleGroup = __importStar(require("@radix-ui/react-toggle-group"));
|
|
41
|
+
const __1 = require("..");
|
|
42
|
+
exports.ToggleGroupContext = (0, react_1.createContext)(null);
|
|
43
|
+
const ToggleGroup = (0, react_1.forwardRef)((_a, ref) => {
|
|
44
|
+
var { className, children, onChange, size = "medium", label, value, defaultValue, id, "aria-describedby": desc } = _a, rest = __rest(_a, ["className", "children", "onChange", "size", "label", "value", "defaultValue", "id", "aria-describedby"]);
|
|
45
|
+
const [groupValue, setGroupValue] = (0, react_1.useState)(defaultValue);
|
|
46
|
+
const labelId = `toggle-group-label-${(0, __1.useId)()}`;
|
|
47
|
+
const handleValueChange = (v) => {
|
|
48
|
+
if (v !== "") {
|
|
49
|
+
setGroupValue(v);
|
|
50
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(v);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (!value && !defaultValue) {
|
|
54
|
+
console.error("ToggleGroup without value/defaultvalue is not allowed");
|
|
55
|
+
}
|
|
56
|
+
const describeBy = (0, classnames_1.default)({
|
|
57
|
+
[desc !== null && desc !== void 0 ? desc : ""]: !!desc,
|
|
58
|
+
[labelId]: !!label,
|
|
59
|
+
});
|
|
60
|
+
return (react_1.default.createElement(exports.ToggleGroupContext.Provider, { value: {
|
|
61
|
+
size,
|
|
62
|
+
} },
|
|
63
|
+
react_1.default.createElement("div", null,
|
|
64
|
+
label && (react_1.default.createElement(__1.Label, { size: size, className: "navds-toggle-group__label", id: labelId }, label)),
|
|
65
|
+
react_1.default.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: (0, classnames_1.default)("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { type: "single" }), children))));
|
|
66
|
+
});
|
|
67
|
+
ToggleGroup.Item = ToggleItem_1.default;
|
|
68
|
+
exports.default = ToggleGroup;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 react_1 = __importStar(require("react"));
|
|
37
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
38
|
+
const __1 = require("..");
|
|
39
|
+
const RadixToggleGroup = __importStar(require("@radix-ui/react-toggle-group"));
|
|
40
|
+
const ToggleGroup_1 = require("./ToggleGroup");
|
|
41
|
+
const ToggleItem = (0, react_1.forwardRef)((_a, ref) => {
|
|
42
|
+
var { className, children } = _a, rest = __rest(_a, ["className", "children"]);
|
|
43
|
+
const context = (0, react_1.useContext)(ToggleGroup_1.ToggleGroupContext);
|
|
44
|
+
return (react_1.default.createElement(RadixToggleGroup.Item, Object.assign({}, rest, { ref: ref, className: (0, classnames_1.default)("navds-toggle-group__button", className) }),
|
|
45
|
+
react_1.default.createElement(__1.Label, { as: "span", className: "navds-toggle-group__button-inner", size: context === null || context === void 0 ? void 0 : context.size }, children)));
|
|
46
|
+
});
|
|
47
|
+
exports.default = ToggleItem;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ToggleGroup = void 0;
|
|
7
|
+
var ToggleGroup_1 = require("./ToggleGroup");
|
|
8
|
+
Object.defineProperty(exports, "ToggleGroup", { enumerable: true, get: function () { return __importDefault(ToggleGroup_1).default; } });
|
package/esm/alert/Alert.js
CHANGED
|
@@ -17,13 +17,13 @@ const Icon = (_a) => {
|
|
|
17
17
|
var { variant } = _a, props = __rest(_a, ["variant"]);
|
|
18
18
|
switch (variant) {
|
|
19
19
|
case "error":
|
|
20
|
-
return React.createElement(ErrorFilled, Object.assign({}, props));
|
|
20
|
+
return React.createElement(ErrorFilled, Object.assign({ title: "Feil" }, props));
|
|
21
21
|
case "warning":
|
|
22
|
-
return React.createElement(WarningFilled, Object.assign({}, props));
|
|
22
|
+
return React.createElement(WarningFilled, Object.assign({ title: "Advarsel" }, props));
|
|
23
23
|
case "info":
|
|
24
|
-
return React.createElement(InformationFilled, Object.assign({}, props));
|
|
24
|
+
return React.createElement(InformationFilled, Object.assign({ title: "Informasjon" }, props));
|
|
25
25
|
case "success":
|
|
26
|
-
return React.createElement(SuccessFilled, Object.assign({}, props));
|
|
26
|
+
return React.createElement(SuccessFilled, Object.assign({ title: "Suksess" }, props));
|
|
27
27
|
default:
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ const Icon = (_a) => {
|
|
|
31
31
|
const Alert = forwardRef((_a, ref) => {
|
|
32
32
|
var { children, className, variant, size = "medium", fullWidth = false, inline = false } = _a, rest = __rest(_a, ["children", "className", "variant", "size", "fullWidth", "inline"]);
|
|
33
33
|
return (React.createElement("div", Object.assign({}, rest, { ref: ref, className: cl(className, "navds-alert", `navds-alert--${variant}`, `navds-alert--${size}`, { "navds-alert--full-width": fullWidth, "navds-alert--inline": inline }) }),
|
|
34
|
-
React.createElement(Icon, {
|
|
34
|
+
React.createElement(Icon, { variant: variant, className: "navds-alert__icon" }),
|
|
35
35
|
React.createElement(BodyLong, { as: "div", size: size, className: "navds-alert__wrapper" }, children)));
|
|
36
36
|
});
|
|
37
37
|
export default Alert;
|
package/esm/alert/Alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.js","sourceRoot":"","sources":["../../src/alert/Alert.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AA2B9B,MAAM,IAAI,GAAG,CAAC,EAAqB,EAAE,EAAE;QAAzB,EAAE,OAAO,OAAY,EAAP,KAAK,cAAnB,WAAqB,CAAF;IAC/B,QAAQ,OAAO,EAAE;QACf,KAAK,OAAO;YACV,OAAO,oBAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"Alert.js","sourceRoot":"","sources":["../../src/alert/Alert.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AA2B9B,MAAM,IAAI,GAAG,CAAC,EAAqB,EAAE,EAAE;QAAzB,EAAE,OAAO,OAAY,EAAP,KAAK,cAAnB,WAAqB,CAAF;IAC/B,QAAQ,OAAO,EAAE;QACf,KAAK,OAAO;YACV,OAAO,oBAAC,WAAW,kBAAC,KAAK,EAAC,MAAM,IAAK,KAAK,EAAI,CAAC;QACjD,KAAK,SAAS;YACZ,OAAO,oBAAC,aAAa,kBAAC,KAAK,EAAC,UAAU,IAAK,KAAK,EAAI,CAAC;QACvD,KAAK,MAAM;YACT,OAAO,oBAAC,iBAAiB,kBAAC,KAAK,EAAC,aAAa,IAAK,KAAK,EAAI,CAAC;QAC9D,KAAK,SAAS;YACZ,OAAO,oBAAC,aAAa,kBAAC,KAAK,EAAC,SAAS,IAAK,KAAK,EAAI,CAAC;QACtD;YACE,OAAO,IAAI,CAAC;KACf;AACH,CAAC,CAAC;AAMF,MAAM,KAAK,GAAG,UAAU,CACtB,CACE,EAQC,EACD,GAAG,EACH,EAAE;QAVF,EACE,QAAQ,EACR,SAAS,EACT,OAAO,EACP,IAAI,GAAG,QAAQ,EACf,SAAS,GAAG,KAAK,EACjB,MAAM,GAAG,KAAK,OAEf,EADI,IAAI,cAPT,mEAQC,CADQ;IAGN,OAAA,CACH,6CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,SAAS,EACT,aAAa,EACb,gBAAgB,OAAO,EAAE,EACzB,gBAAgB,IAAI,EAAE,EACtB,EAAE,yBAAyB,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,EAAE,CACxE;QAED,oBAAC,IAAI,IAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,mBAAmB,GAAG;QACxD,oBAAC,QAAQ,IAAC,EAAE,EAAC,KAAK,EAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAC,sBAAsB,IAC5D,QAAQ,CACA,CACP,CACP,CAAA;CAAA,CACF,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AAEvB,6BAA6B;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AAEvB,6BAA6B;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
|
package/esm/modal/Modal.d.ts
CHANGED
package/esm/table/DataCell.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface DataCellProps extends React.
|
|
2
|
+
interface DataCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
|
|
3
3
|
}
|
|
4
4
|
export interface DataCellType extends React.ForwardRefExoticComponent<DataCellProps & React.RefAttributes<HTMLTableCellElement>> {
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface HeaderCellProps extends React.
|
|
2
|
+
interface HeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
|
|
3
3
|
scope?: string;
|
|
4
4
|
}
|
|
5
5
|
export interface HeaderCellType extends React.ForwardRefExoticComponent<HeaderCellProps & React.RefAttributes<HTMLTableCellElement>> {
|
package/esm/table/Table.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { BodyType } from "./Body";
|
|
|
4
4
|
import { RowType } from "./Row";
|
|
5
5
|
import { HeaderCellType } from "./HeaderCell";
|
|
6
6
|
import { DataCellType } from "./DataCell";
|
|
7
|
-
export interface TableProps extends React.
|
|
7
|
+
export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement> {
|
|
8
8
|
/**
|
|
9
9
|
* Changes padding
|
|
10
10
|
* @default "medium"
|
package/esm/table/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../src/table/Table.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,MAAsB,MAAM,UAAU,CAAC;AAC9C,OAAO,IAAkB,MAAM,QAAQ,CAAC;AACxC,OAAO,GAAgB,MAAM,OAAO,CAAC;AACrC,OAAO,UAA8B,MAAM,cAAc,CAAC;AAC1D,OAAO,QAA0B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../src/table/Table.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,MAAsB,MAAM,UAAU,CAAC;AAC9C,OAAO,IAAkB,MAAM,QAAQ,CAAC;AACxC,OAAO,GAAgB,MAAM,OAAO,CAAC;AACrC,OAAO,UAA8B,MAAM,cAAc,CAAC;AAC1D,OAAO,QAA0B,MAAM,YAAY,CAAC;AA+BpD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAE1E,MAAM,KAAK,GAAG,UAAU,CACtB,CAAC,EAA6D,EAAE,GAAG,EAAE,EAAE;QAAtE,EAAE,SAAS,EAAE,YAAY,GAAG,KAAK,EAAE,IAAI,GAAG,QAAQ,OAAW,EAAN,IAAI,cAA3D,qCAA6D,CAAF;IAAY,OAAA,CACtE,oBAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,IAAI,EAAE;QACpC,+CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,gBAAgB,IAAI,EAAE,EAAE,SAAS,EAAE;gBAC9D,4BAA4B,EAAE,YAAY;aAC3C,CAAC,IACF,CACoB,CACzB,CAAA;CAAA,CACW,CAAC;AAEf,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;AACtB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;AAClB,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;AAChB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;AAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAE1B,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from "react";
|
|
2
|
+
import { ToggleItemType } from "./ToggleItem";
|
|
3
|
+
export interface ToggleGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "dir"> {
|
|
4
|
+
/**
|
|
5
|
+
* Toggles.Item elements
|
|
6
|
+
*/
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Changes padding and font-size
|
|
10
|
+
* @default "medium"
|
|
11
|
+
*/
|
|
12
|
+
size?: "medium" | "small";
|
|
13
|
+
/**
|
|
14
|
+
* Controlled selected value
|
|
15
|
+
*/
|
|
16
|
+
value?: string;
|
|
17
|
+
/**
|
|
18
|
+
* If not controlled, a default-value needs to be set
|
|
19
|
+
*/
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns elements that wants to be active
|
|
23
|
+
*/
|
|
24
|
+
onChange: (value: string) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Label describing ToggleGroup
|
|
27
|
+
*/
|
|
28
|
+
label?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
interface ToggleGroupComponent extends React.ForwardRefExoticComponent<ToggleGroupProps & React.RefAttributes<HTMLDivElement>> {
|
|
31
|
+
Item: ToggleItemType;
|
|
32
|
+
}
|
|
33
|
+
interface ToggleContextProps {
|
|
34
|
+
size: "medium" | "small";
|
|
35
|
+
}
|
|
36
|
+
export declare const ToggleGroupContext: React.Context<ToggleContextProps | null>;
|
|
37
|
+
declare const ToggleGroup: ToggleGroupComponent;
|
|
38
|
+
export default ToggleGroup;
|
|
@@ -0,0 +1,44 @@
|
|
|
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, { createContext, forwardRef, useState, } from "react";
|
|
14
|
+
import ToggleItem from "./ToggleItem";
|
|
15
|
+
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
|
|
16
|
+
import { Label, useId } from "..";
|
|
17
|
+
export const ToggleGroupContext = createContext(null);
|
|
18
|
+
const ToggleGroup = forwardRef((_a, ref) => {
|
|
19
|
+
var { className, children, onChange, size = "medium", label, value, defaultValue, id, "aria-describedby": desc } = _a, rest = __rest(_a, ["className", "children", "onChange", "size", "label", "value", "defaultValue", "id", "aria-describedby"]);
|
|
20
|
+
const [groupValue, setGroupValue] = useState(defaultValue);
|
|
21
|
+
const labelId = `toggle-group-label-${useId()}`;
|
|
22
|
+
const handleValueChange = (v) => {
|
|
23
|
+
if (v !== "") {
|
|
24
|
+
setGroupValue(v);
|
|
25
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(v);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
if (!value && !defaultValue) {
|
|
29
|
+
console.error("ToggleGroup without value/defaultvalue is not allowed");
|
|
30
|
+
}
|
|
31
|
+
const describeBy = cl({
|
|
32
|
+
[desc !== null && desc !== void 0 ? desc : ""]: !!desc,
|
|
33
|
+
[labelId]: !!label,
|
|
34
|
+
});
|
|
35
|
+
return (React.createElement(ToggleGroupContext.Provider, { value: {
|
|
36
|
+
size,
|
|
37
|
+
} },
|
|
38
|
+
React.createElement("div", null,
|
|
39
|
+
label && (React.createElement(Label, { size: size, className: "navds-toggle-group__label", id: labelId }, label)),
|
|
40
|
+
React.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: cl("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { type: "single" }), children))));
|
|
41
|
+
});
|
|
42
|
+
ToggleGroup.Item = ToggleItem;
|
|
43
|
+
export default ToggleGroup;
|
|
44
|
+
//# sourceMappingURL=ToggleGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/ToggleGroup.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,UAAU,EAEV,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,UAA8B,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AA0ClC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,IAAI,CACL,CAAC;AAEF,MAAM,WAAW,GAAG,UAAU,CAC5B,CACE,EAWC,EACD,GAAG,EACH,EAAE;QAbF,EACE,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,IAAI,GAAG,QAAQ,EACf,KAAK,EACL,KAAK,EACL,YAAY,EACZ,EAAE,EACF,kBAAkB,EAAE,IAAI,OAEzB,EADI,IAAI,cAVT,yGAWC,CADQ;IAIT,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,sBAAsB,KAAK,EAAE,EAAE,CAAC;IAEhD,MAAM,iBAAiB,GAAG,CAAC,CAAS,EAAE,EAAE;QACtC,IAAI,CAAC,KAAK,EAAE,EAAE;YACZ,aAAa,CAAC,CAAC,CAAC,CAAC;YACjB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,CAAC,CAAC,CAAC;SACf;IACH,CAAC,CAAC;IAEF,IAAI,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;KACxE;IAED,MAAM,UAAU,GAAG,EAAE,CAAC;QACpB,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI;QACpB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK;KACnB,CAAC,CAAC;IAEH,OAAO,CACL,oBAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,IAAI;SACL;QAED;YACG,KAAK,IAAI,CACR,oBAAC,KAAK,IACJ,IAAI,EAAE,IAAI,EACV,SAAS,EAAC,2BAA2B,EACrC,EAAE,EAAE,OAAO,IAEV,KAAK,CACA,CACT;YACD,oBAAC,gBAAgB,CAAC,IAAI,oBAChB,IAAI,IACR,aAAa,EAAE,iBAAiB,EAChC,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,UAAU,EAC1B,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,oBAAoB,EACpB,SAAS,EACT,uBAAuB,IAAI,EAAE,CAC9B,IACG,CAAC,UAAU,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,IACtD,IAAI,EAAC,QAAQ,KAEZ,QAAQ,CACa,CACpB,CACsB,CAC/B,CAAC;AACJ,CAAC,CACsB,CAAC;AAE1B,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC;AAE9B,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ToggleItemProps extends React.HTMLAttributes<HTMLButtonElement> {
|
|
3
|
+
/**
|
|
4
|
+
* Content
|
|
5
|
+
*/
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* Value for state-handling
|
|
9
|
+
*/
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
export declare type ToggleItemType = React.ForwardRefExoticComponent<ToggleItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
13
|
+
declare const ToggleItem: ToggleItemType;
|
|
14
|
+
export default ToggleItem;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 React, { forwardRef, useContext } from "react";
|
|
13
|
+
import cl from "classnames";
|
|
14
|
+
import { Label } from "..";
|
|
15
|
+
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
|
|
16
|
+
import { ToggleGroupContext } from "./ToggleGroup";
|
|
17
|
+
const ToggleItem = forwardRef((_a, ref) => {
|
|
18
|
+
var { className, children } = _a, rest = __rest(_a, ["className", "children"]);
|
|
19
|
+
const context = useContext(ToggleGroupContext);
|
|
20
|
+
return (React.createElement(RadixToggleGroup.Item, Object.assign({}, rest, { ref: ref, className: cl("navds-toggle-group__button", className) }),
|
|
21
|
+
React.createElement(Label, { as: "span", className: "navds-toggle-group__button-inner", size: context === null || context === void 0 ? void 0 : context.size }, children)));
|
|
22
|
+
});
|
|
23
|
+
export default ToggleItem;
|
|
24
|
+
//# sourceMappingURL=ToggleItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToggleItem.js","sourceRoot":"","sources":["../../src/toggle-group/ToggleItem.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAkBnD,MAAM,UAAU,GAAG,UAAU,CAC3B,CAAC,EAAgC,EAAE,GAAG,EAAE,EAAE;QAAzC,EAAE,SAAS,EAAE,QAAQ,OAAW,EAAN,IAAI,cAA9B,yBAAgC,CAAF;IAC7B,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAE/C,OAAO,CACL,oBAAC,gBAAgB,CAAC,IAAI,oBAChB,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,4BAA4B,EAAE,SAAS,CAAC;QAEtD,oBAAC,KAAK,IACJ,EAAE,EAAC,MAAM,EACT,SAAS,EAAC,kCAAkC,EAC5C,IAAI,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,IAElB,QAAQ,CACH,CACc,CACzB,CAAC;AACJ,CAAC,CACgB,CAAC;AAEpB,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/toggle-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NAV designsystem react components",
|
|
6
6
|
"author": "NAV Designsystem team",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@material-ui/core": "^4.12.3",
|
|
38
38
|
"@navikt/ds-icons": "^0.8.4",
|
|
39
39
|
"@popperjs/core": "^2.10.1",
|
|
40
|
+
"@radix-ui/react-toggle-group": "^0.1.4",
|
|
40
41
|
"classnames": "^2.2.6",
|
|
41
42
|
"react-collapse": "^5.1.0",
|
|
42
43
|
"react-merge-refs": "^1.1.0",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"@types/react": "^17.0.30",
|
|
65
66
|
"react": "^17.0.0"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8a58d75efbbfd6ae78d9a352aeacefb10617cf70"
|
|
68
69
|
}
|
package/src/alert/Alert.tsx
CHANGED
|
@@ -36,13 +36,13 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
36
36
|
const Icon = ({ variant, ...props }) => {
|
|
37
37
|
switch (variant) {
|
|
38
38
|
case "error":
|
|
39
|
-
return <ErrorFilled {...props} />;
|
|
39
|
+
return <ErrorFilled title="Feil" {...props} />;
|
|
40
40
|
case "warning":
|
|
41
|
-
return <WarningFilled {...props} />;
|
|
41
|
+
return <WarningFilled title="Advarsel" {...props} />;
|
|
42
42
|
case "info":
|
|
43
|
-
return <InformationFilled {...props} />;
|
|
43
|
+
return <InformationFilled title="Informasjon" {...props} />;
|
|
44
44
|
case "success":
|
|
45
|
-
return <SuccessFilled {...props} />;
|
|
45
|
+
return <SuccessFilled title="Suksess" {...props} />;
|
|
46
46
|
default:
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
@@ -76,11 +76,7 @@ const Alert = forwardRef<HTMLDivElement, AlertProps>(
|
|
|
76
76
|
{ "navds-alert--full-width": fullWidth, "navds-alert--inline": inline }
|
|
77
77
|
)}
|
|
78
78
|
>
|
|
79
|
-
<Icon
|
|
80
|
-
title={`${variant}-ikon`}
|
|
81
|
-
variant={variant}
|
|
82
|
-
className="navds-alert__icon"
|
|
83
|
-
/>
|
|
79
|
+
<Icon variant={variant} className="navds-alert__icon" />
|
|
84
80
|
<BodyLong as="div" size={size} className="navds-alert__wrapper">
|
|
85
81
|
{children}
|
|
86
82
|
</BodyLong>
|
package/src/index.ts
CHANGED
package/src/modal/Modal.tsx
CHANGED
package/src/table/DataCell.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import cl from "classnames";
|
|
|
3
3
|
import { BodyShort } from "..";
|
|
4
4
|
import { TableContext } from ".";
|
|
5
5
|
|
|
6
|
-
interface DataCellProps extends React.
|
|
6
|
+
interface DataCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {}
|
|
7
7
|
|
|
8
8
|
export interface DataCellType
|
|
9
9
|
extends React.ForwardRefExoticComponent<
|
package/src/table/HeaderCell.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import React, { forwardRef, useContext } from "react";
|
|
|
2
2
|
import cl from "classnames";
|
|
3
3
|
import { Label, TableContext } from "..";
|
|
4
4
|
|
|
5
|
-
interface HeaderCellProps extends React.
|
|
5
|
+
interface HeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
|
|
6
6
|
scope?: string;
|
|
7
7
|
}
|
|
8
8
|
|
package/src/table/Table.tsx
CHANGED
|
@@ -6,7 +6,8 @@ import Row, { RowType } from "./Row";
|
|
|
6
6
|
import HeaderCell, { HeaderCellType } from "./HeaderCell";
|
|
7
7
|
import DataCell, { DataCellType } from "./DataCell";
|
|
8
8
|
|
|
9
|
-
export interface TableProps
|
|
9
|
+
export interface TableProps
|
|
10
|
+
extends React.TableHTMLAttributes<HTMLTableElement> {
|
|
10
11
|
/**
|
|
11
12
|
* Changes padding
|
|
12
13
|
* @default "medium"
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Attachment, Hamburger, Star, System } from "@navikt/ds-icons";
|
|
3
|
+
import { ToggleGroup } from "../index";
|
|
4
|
+
import { Meta } from "@storybook/react/types-6-0";
|
|
5
|
+
export default {
|
|
6
|
+
title: "ds-react/toggle-group",
|
|
7
|
+
component: ToggleGroup,
|
|
8
|
+
parameters: {
|
|
9
|
+
chromatic: { disable: true },
|
|
10
|
+
},
|
|
11
|
+
} as Meta;
|
|
12
|
+
|
|
13
|
+
const Items = (icon?: boolean, both?: boolean) => (
|
|
14
|
+
<>
|
|
15
|
+
<ToggleGroup.Item value="first">
|
|
16
|
+
{both ? (
|
|
17
|
+
<>
|
|
18
|
+
<Hamburger /> First
|
|
19
|
+
</>
|
|
20
|
+
) : (
|
|
21
|
+
<>{icon ? <Hamburger /> : "First"}</>
|
|
22
|
+
)}
|
|
23
|
+
</ToggleGroup.Item>
|
|
24
|
+
<ToggleGroup.Item value="second">
|
|
25
|
+
{both ? (
|
|
26
|
+
<>
|
|
27
|
+
<Star /> Second more txt
|
|
28
|
+
</>
|
|
29
|
+
) : (
|
|
30
|
+
<>{icon ? <Star /> : "Second more txt"}</>
|
|
31
|
+
)}
|
|
32
|
+
</ToggleGroup.Item>
|
|
33
|
+
<ToggleGroup.Item value="third">
|
|
34
|
+
{both ? (
|
|
35
|
+
<>
|
|
36
|
+
<Attachment /> Thrid
|
|
37
|
+
</>
|
|
38
|
+
) : (
|
|
39
|
+
<>{icon ? <Attachment /> : "Third"}</>
|
|
40
|
+
)}
|
|
41
|
+
</ToggleGroup.Item>
|
|
42
|
+
<ToggleGroup.Item value="fourth">
|
|
43
|
+
{both ? (
|
|
44
|
+
<>
|
|
45
|
+
<System /> Fourth
|
|
46
|
+
</>
|
|
47
|
+
) : (
|
|
48
|
+
<>{icon ? <System /> : "Fourth"}</>
|
|
49
|
+
)}
|
|
50
|
+
</ToggleGroup.Item>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const All = () => {
|
|
55
|
+
const [activeValue, setActiveValue] = useState("first");
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<h2>ToggleGroup</h2>
|
|
60
|
+
<h3>{activeValue}</h3>
|
|
61
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}>
|
|
62
|
+
<ToggleGroup value={activeValue} onChange={setActiveValue}>
|
|
63
|
+
{Items()}
|
|
64
|
+
</ToggleGroup>
|
|
65
|
+
<ToggleGroup value={activeValue} onChange={setActiveValue}>
|
|
66
|
+
{Items(true)}
|
|
67
|
+
</ToggleGroup>
|
|
68
|
+
<ToggleGroup value={activeValue} onChange={setActiveValue}>
|
|
69
|
+
{Items(true, true)}
|
|
70
|
+
</ToggleGroup>
|
|
71
|
+
</div>
|
|
72
|
+
<h2>ToggleGroup Small</h2>
|
|
73
|
+
<h3>{activeValue}</h3>
|
|
74
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}>
|
|
75
|
+
<ToggleGroup size="small" value={activeValue} onChange={setActiveValue}>
|
|
76
|
+
{Items()}
|
|
77
|
+
</ToggleGroup>
|
|
78
|
+
<ToggleGroup size="small" value={activeValue} onChange={setActiveValue}>
|
|
79
|
+
{Items(true)}
|
|
80
|
+
</ToggleGroup>
|
|
81
|
+
<ToggleGroup size="small" value={activeValue} onChange={setActiveValue}>
|
|
82
|
+
{Items(true, true)}
|
|
83
|
+
</ToggleGroup>
|
|
84
|
+
</div>
|
|
85
|
+
<h2>ToggleGroup label</h2>
|
|
86
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}>
|
|
87
|
+
<ToggleGroup
|
|
88
|
+
label="Label msg"
|
|
89
|
+
value={activeValue}
|
|
90
|
+
onChange={setActiveValue}
|
|
91
|
+
>
|
|
92
|
+
{Items()}
|
|
93
|
+
</ToggleGroup>
|
|
94
|
+
<ToggleGroup
|
|
95
|
+
label="Label msg"
|
|
96
|
+
value={activeValue}
|
|
97
|
+
onChange={setActiveValue}
|
|
98
|
+
aria-describedby="demo-id"
|
|
99
|
+
>
|
|
100
|
+
{Items()}
|
|
101
|
+
</ToggleGroup>
|
|
102
|
+
</div>
|
|
103
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}>
|
|
104
|
+
<h2>Uncontrolled</h2>
|
|
105
|
+
<ToggleGroup onChange={setActiveValue} defaultValue="second">
|
|
106
|
+
{Items()}
|
|
107
|
+
</ToggleGroup>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import cl from "classnames";
|
|
2
|
+
import React, {
|
|
3
|
+
createContext,
|
|
4
|
+
forwardRef,
|
|
5
|
+
HTMLAttributes,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
import ToggleItem, { ToggleItemType } from "./ToggleItem";
|
|
9
|
+
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
|
|
10
|
+
import { Label, useId } from "..";
|
|
11
|
+
|
|
12
|
+
export interface ToggleGroupProps
|
|
13
|
+
extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "dir"> {
|
|
14
|
+
/**
|
|
15
|
+
* Toggles.Item elements
|
|
16
|
+
*/
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Changes padding and font-size
|
|
20
|
+
* @default "medium"
|
|
21
|
+
*/
|
|
22
|
+
size?: "medium" | "small";
|
|
23
|
+
/**
|
|
24
|
+
* Controlled selected value
|
|
25
|
+
*/
|
|
26
|
+
value?: string;
|
|
27
|
+
/**
|
|
28
|
+
* If not controlled, a default-value needs to be set
|
|
29
|
+
*/
|
|
30
|
+
defaultValue?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Returns elements that wants to be active
|
|
33
|
+
*/
|
|
34
|
+
onChange: (value: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Label describing ToggleGroup
|
|
37
|
+
*/
|
|
38
|
+
label?: React.ReactNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ToggleGroupComponent
|
|
42
|
+
extends React.ForwardRefExoticComponent<
|
|
43
|
+
ToggleGroupProps & React.RefAttributes<HTMLDivElement>
|
|
44
|
+
> {
|
|
45
|
+
Item: ToggleItemType;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ToggleContextProps {
|
|
49
|
+
size: "medium" | "small";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const ToggleGroupContext = createContext<ToggleContextProps | null>(
|
|
53
|
+
null
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const ToggleGroup = forwardRef<HTMLDivElement, ToggleGroupProps>(
|
|
57
|
+
(
|
|
58
|
+
{
|
|
59
|
+
className,
|
|
60
|
+
children,
|
|
61
|
+
onChange,
|
|
62
|
+
size = "medium",
|
|
63
|
+
label,
|
|
64
|
+
value,
|
|
65
|
+
defaultValue,
|
|
66
|
+
id,
|
|
67
|
+
"aria-describedby": desc,
|
|
68
|
+
...rest
|
|
69
|
+
},
|
|
70
|
+
ref
|
|
71
|
+
) => {
|
|
72
|
+
const [groupValue, setGroupValue] = useState(defaultValue);
|
|
73
|
+
const labelId = `toggle-group-label-${useId()}`;
|
|
74
|
+
|
|
75
|
+
const handleValueChange = (v: string) => {
|
|
76
|
+
if (v !== "") {
|
|
77
|
+
setGroupValue(v);
|
|
78
|
+
onChange?.(v);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (!value && !defaultValue) {
|
|
83
|
+
console.error("ToggleGroup without value/defaultvalue is not allowed");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const describeBy = cl({
|
|
87
|
+
[desc ?? ""]: !!desc,
|
|
88
|
+
[labelId]: !!label,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<ToggleGroupContext.Provider
|
|
93
|
+
value={{
|
|
94
|
+
size,
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<div>
|
|
98
|
+
{label && (
|
|
99
|
+
<Label
|
|
100
|
+
size={size}
|
|
101
|
+
className="navds-toggle-group__label"
|
|
102
|
+
id={labelId}
|
|
103
|
+
>
|
|
104
|
+
{label}
|
|
105
|
+
</Label>
|
|
106
|
+
)}
|
|
107
|
+
<RadixToggleGroup.Root
|
|
108
|
+
{...rest}
|
|
109
|
+
onValueChange={handleValueChange}
|
|
110
|
+
value={value ?? groupValue}
|
|
111
|
+
defaultValue={defaultValue}
|
|
112
|
+
ref={ref}
|
|
113
|
+
className={cl(
|
|
114
|
+
"navds-toggle-group",
|
|
115
|
+
className,
|
|
116
|
+
`navds-toggle-group--${size}`
|
|
117
|
+
)}
|
|
118
|
+
{...(describeBy && { "aria-describedby": describeBy })}
|
|
119
|
+
type="single"
|
|
120
|
+
>
|
|
121
|
+
{children}
|
|
122
|
+
</RadixToggleGroup.Root>
|
|
123
|
+
</div>
|
|
124
|
+
</ToggleGroupContext.Provider>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
) as ToggleGroupComponent;
|
|
128
|
+
|
|
129
|
+
ToggleGroup.Item = ToggleItem;
|
|
130
|
+
|
|
131
|
+
export default ToggleGroup;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { forwardRef, useContext } from "react";
|
|
2
|
+
import cl from "classnames";
|
|
3
|
+
import { Label } from "..";
|
|
4
|
+
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
|
|
5
|
+
import { ToggleGroupContext } from "./ToggleGroup";
|
|
6
|
+
|
|
7
|
+
export interface ToggleItemProps
|
|
8
|
+
extends React.HTMLAttributes<HTMLButtonElement> {
|
|
9
|
+
/**
|
|
10
|
+
* Content
|
|
11
|
+
*/
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Value for state-handling
|
|
15
|
+
*/
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ToggleItemType = React.ForwardRefExoticComponent<
|
|
20
|
+
ToggleItemProps & React.RefAttributes<HTMLButtonElement>
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
const ToggleItem = forwardRef<HTMLButtonElement, ToggleItemProps>(
|
|
24
|
+
({ className, children, ...rest }, ref) => {
|
|
25
|
+
const context = useContext(ToggleGroupContext);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<RadixToggleGroup.Item
|
|
29
|
+
{...rest}
|
|
30
|
+
ref={ref}
|
|
31
|
+
className={cl("navds-toggle-group__button", className)}
|
|
32
|
+
>
|
|
33
|
+
<Label
|
|
34
|
+
as="span"
|
|
35
|
+
className="navds-toggle-group__button-inner"
|
|
36
|
+
size={context?.size}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</Label>
|
|
40
|
+
</RadixToggleGroup.Item>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
) as ToggleItemType;
|
|
44
|
+
|
|
45
|
+
export default ToggleItem;
|