@navikt/ds-react 0.16.17 → 0.16.18

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.
@@ -39,7 +39,7 @@ const classnames_1 = __importDefault(require("classnames"));
39
39
  const __1 = require("../");
40
40
  const util_1 = require("../util");
41
41
  const Button = (0, react_1.forwardRef)((_a, ref) => {
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"]);
42
+ var { as: Component = "button", variant = "primary", className, children, size = "medium", loading = false, disabled, style } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size", "loading", "disabled", "style"]);
43
43
  const buttonRef = (0, react_1.useRef)(null);
44
44
  const mergedRef = (0, react_merge_refs_1.default)([buttonRef, ref]);
45
45
  const [widthOverride, setWidthOverride] = (0, react_1.useState)();
@@ -57,7 +57,7 @@ const Button = (0, react_1.forwardRef)((_a, ref) => {
57
57
  }, [loading, children]);
58
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
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)));
60
+ }), style: Object.assign(Object.assign({}, 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 === "medium" ? "medium" : "small", "aria-live": "polite" }, widthOverride ? react_1.default.createElement(__1.Loader, { size: size }) : children)));
62
62
  });
63
63
  exports.default = Button;
@@ -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 react_1 = __importStar(require("react"));
37
+ const ds_icons_1 = require("@navikt/ds-icons");
38
+ const __1 = require("..");
39
+ const HeaderCell_1 = __importDefault(require("./HeaderCell"));
40
+ const ColumnHeader = (0, react_1.forwardRef)((_a, ref) => {
41
+ var _b, _c, _d, _e;
42
+ var { className, children, sortable = false, sortKey } = _a, rest = __rest(_a, ["className", "children", "sortable", "sortKey"]);
43
+ const context = (0, react_1.useContext)(__1.TableContext);
44
+ if (sortable && !sortKey) {
45
+ console.warn("ColumnHeader with `sortable=true` must have a sortKey.");
46
+ }
47
+ return (react_1.default.createElement(HeaderCell_1.default, Object.assign({ scope: "col", ref: ref, className: className, "aria-sort": sortable
48
+ ? ((_b = context === null || context === void 0 ? void 0 : context.sort) === null || _b === void 0 ? void 0 : _b.orderBy) === sortKey
49
+ ? (_c = context === null || context === void 0 ? void 0 : context.sort) === null || _c === void 0 ? void 0 : _c.direction
50
+ : "none"
51
+ : undefined }, rest), sortable ? (react_1.default.createElement("button", { className: "navds-table__sort-button", onClick: sortable && sortKey
52
+ ? () => { var _a; return (_a = context === null || context === void 0 ? void 0 : context.onSortChange) === null || _a === void 0 ? void 0 : _a.call(context, sortKey); }
53
+ : undefined },
54
+ children,
55
+ ((_d = context === null || context === void 0 ? void 0 : context.sort) === null || _d === void 0 ? void 0 : _d.orderBy) === sortKey &&
56
+ ((_e = context === null || context === void 0 ? void 0 : context.sort) === null || _e === void 0 ? void 0 : _e.direction) === "descending" ? (react_1.default.createElement(ds_icons_1.Down, { "aria-label": "sorter synkende" })) : (react_1.default.createElement(ds_icons_1.Up, { "aria-label": "sorter stigende" })))) : (children)));
57
+ });
58
+ exports.default = ColumnHeader;
@@ -38,8 +38,10 @@ const classnames_1 = __importDefault(require("classnames"));
38
38
  const __1 = require("..");
39
39
  const _1 = require(".");
40
40
  const DataCell = (0, react_1.forwardRef)((_a, ref) => {
41
- var { className, children = "" } = _a, rest = __rest(_a, ["className", "children"]);
41
+ var { className, children = "", align } = _a, rest = __rest(_a, ["className", "children", "align"]);
42
42
  const context = (0, react_1.useContext)(_1.TableContext);
43
- return (react_1.default.createElement(__1.BodyShort, Object.assign({ as: "td", ref: ref, className: (0, classnames_1.default)("navds-table__data-cell", className), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
43
+ return (react_1.default.createElement(__1.BodyShort, Object.assign({ as: "td", ref: ref, className: (0, classnames_1.default)("navds-table__data-cell", className, {
44
+ [`navds-table__data-cell--align-${align}`]: align,
45
+ }), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
44
46
  });
45
47
  exports.default = DataCell;
@@ -37,8 +37,10 @@ const react_1 = __importStar(require("react"));
37
37
  const classnames_1 = __importDefault(require("classnames"));
38
38
  const __1 = require("..");
39
39
  const HeaderCell = (0, react_1.forwardRef)((_a, ref) => {
40
- var { className, children } = _a, rest = __rest(_a, ["className", "children"]);
40
+ var { className, children, align } = _a, rest = __rest(_a, ["className", "children", "align"]);
41
41
  const context = (0, react_1.useContext)(__1.TableContext);
42
- return (react_1.default.createElement(__1.Label, Object.assign({ as: "th", ref: ref, className: (0, classnames_1.default)("navds-table__header-cell", className), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
42
+ return (react_1.default.createElement(__1.Label, Object.assign({ as: "th", ref: ref, className: (0, classnames_1.default)("navds-table__header-cell", className, {
43
+ [`navds-table__header-cell--align-${align}`]: align,
44
+ }), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
43
45
  });
44
46
  exports.default = HeaderCell;
@@ -39,12 +39,13 @@ const classnames_1 = __importDefault(require("classnames"));
39
39
  const Header_1 = __importDefault(require("./Header"));
40
40
  const Body_1 = __importDefault(require("./Body"));
41
41
  const Row_1 = __importDefault(require("./Row"));
42
+ const ColumnHeader_1 = __importDefault(require("./ColumnHeader"));
42
43
  const HeaderCell_1 = __importDefault(require("./HeaderCell"));
43
44
  const DataCell_1 = __importDefault(require("./DataCell"));
44
45
  exports.TableContext = (0, react_1.createContext)(null);
45
46
  const Table = (0, react_1.forwardRef)((_a, ref) => {
46
- var { className, zebraStripes = false, size = "medium" } = _a, rest = __rest(_a, ["className", "zebraStripes", "size"]);
47
- return (react_1.default.createElement(exports.TableContext.Provider, { value: { size } },
47
+ var { className, zebraStripes = false, size = "medium", onSortChange, sort } = _a, rest = __rest(_a, ["className", "zebraStripes", "size", "onSortChange", "sort"]);
48
+ return (react_1.default.createElement(exports.TableContext.Provider, { value: { size, onSortChange, sort } },
48
49
  react_1.default.createElement("table", Object.assign({}, rest, { ref: ref, className: (0, classnames_1.default)("navds-table", `navds-table--${size}`, className, {
49
50
  "navds-table--zebra-stripes": zebraStripes,
50
51
  }) }))));
@@ -52,6 +53,7 @@ const Table = (0, react_1.forwardRef)((_a, ref) => {
52
53
  Table.Header = Header_1.default;
53
54
  Table.Body = Body_1.default;
54
55
  Table.Row = Row_1.default;
56
+ Table.ColumnHeader = ColumnHeader_1.default;
55
57
  Table.HeaderCell = HeaderCell_1.default;
56
58
  Table.DataCell = DataCell_1.default;
57
59
  exports.default = Table;
@@ -14,7 +14,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
14
14
  * Changes padding, height and font-size
15
15
  * @default "medium"
16
16
  */
17
- size?: "medium" | "small";
17
+ size?: "medium" | "small" | "xsmall";
18
18
  /**
19
19
  * Prevent the user from interacting with the button: it cannot be pressed or focused.
20
20
  * @note Avoid using if possible for accessibility purposes
@@ -15,7 +15,7 @@ import cl from "classnames";
15
15
  import { BodyShort, Loader } from "../";
16
16
  import { useClientLayoutEffect } from "../util";
17
17
  const Button = forwardRef((_a, ref) => {
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"]);
18
+ var { as: Component = "button", variant = "primary", className, children, size = "medium", loading = false, disabled, style } = _a, rest = __rest(_a, ["as", "variant", "className", "children", "size", "loading", "disabled", "style"]);
19
19
  const buttonRef = useRef(null);
20
20
  const mergedRef = mergeRefs([buttonRef, ref]);
21
21
  const [widthOverride, setWidthOverride] = useState();
@@ -33,8 +33,8 @@ const Button = forwardRef((_a, ref) => {
33
33
  }, [loading, children]);
34
34
  return (React.createElement(Component, Object.assign({}, rest, { ref: mergedRef, className: cl(className, "navds-button", `navds-button--${variant}`, `navds-button--${size}`, {
35
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)));
36
+ }), style: Object.assign(Object.assign({}, 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 === "medium" ? "medium" : "small", "aria-live": "polite" }, widthOverride ? React.createElement(Loader, { size: size }) : children)));
38
38
  });
39
39
  export default Button;
40
40
  //# sourceMappingURL=Button.js.map
@@ -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,MAAM,OAAO,CAAC;AAC5D,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAwB,MAAM,EAAE,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA+BhD,MAAM,MAAM,GAAyD,UAAU,CAC7E,CACE,EASC,EACD,GAAG,EACH,EAAE;QAXF,EACE,EAAE,EAAE,SAAS,GAAG,QAAQ,EACxB,OAAO,GAAG,SAAS,EACnB,SAAS,EACT,QAAQ,EACR,IAAI,GAAG,QAAQ,EACf,OAAO,GAAG,KAAK,EACf,QAAQ,OAET,EADI,IAAI,cART,yEASC,CADQ;IAIT,MAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,EAAU,CAAC;IAE7D,qBAAqB,CAAC,GAAG,EAAE;QACzB,IAAI,OAAO,EAA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a,CAAC;AAEnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAEjB,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../src/menu/Menu.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,OAAO,IAAsB,MAAM,YAAY,CAAC;AAChD,OAAO,QAA8B,MAAM,gBAAgB,CAAC;AAc5D,MAAM,IAAI,GAAG,UAAU,CACrB,CAAC,EAAgC,EAAE,GAAG,EAAE,EAAE;QAAzC,EAAE,QAAQ,EAAE,SAAS,OAAW,EAAN,IAAI,cAA9B,yBAAgC,CAAF;IAAY,OAAA,CACzC,6CACM,IAAI,IACR,IAAI,EAAC,YAAY,EACjB,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;QAEtC,oBAAC,SAAS,QAAE,QAAQ,CAAa,CAC7B,CACP,CAAA;CAAA,CACe,CAAC;AAEnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAEjB,eAAe,IAAI,CAAC"}
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { HeaderCellProps } from "./HeaderCell";
3
+ interface ColumnHeaderProps extends HeaderCellProps {
4
+ /**
5
+ * Key to sort by
6
+ */
7
+ sortKey?: string;
8
+ /**
9
+ * Column is sortable
10
+ * @default false
11
+ */
12
+ sortable?: boolean;
13
+ }
14
+ export interface ColumnHeaderType extends React.ForwardRefExoticComponent<ColumnHeaderProps & React.RefAttributes<HTMLTableCellElement>> {
15
+ }
16
+ declare const ColumnHeader: ColumnHeaderType;
17
+ export default ColumnHeader;
@@ -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 React, { forwardRef, useContext } from "react";
13
+ import { Down, Up } from "@navikt/ds-icons";
14
+ import { TableContext } from "..";
15
+ import HeaderCell from "./HeaderCell";
16
+ const ColumnHeader = forwardRef((_a, ref) => {
17
+ var _b, _c, _d, _e;
18
+ var { className, children, sortable = false, sortKey } = _a, rest = __rest(_a, ["className", "children", "sortable", "sortKey"]);
19
+ const context = useContext(TableContext);
20
+ if (sortable && !sortKey) {
21
+ console.warn("ColumnHeader with `sortable=true` must have a sortKey.");
22
+ }
23
+ return (React.createElement(HeaderCell, Object.assign({ scope: "col", ref: ref, className: className, "aria-sort": sortable
24
+ ? ((_b = context === null || context === void 0 ? void 0 : context.sort) === null || _b === void 0 ? void 0 : _b.orderBy) === sortKey
25
+ ? (_c = context === null || context === void 0 ? void 0 : context.sort) === null || _c === void 0 ? void 0 : _c.direction
26
+ : "none"
27
+ : undefined }, rest), sortable ? (React.createElement("button", { className: "navds-table__sort-button", onClick: sortable && sortKey
28
+ ? () => { var _a; return (_a = context === null || context === void 0 ? void 0 : context.onSortChange) === null || _a === void 0 ? void 0 : _a.call(context, sortKey); }
29
+ : undefined },
30
+ children,
31
+ ((_d = context === null || context === void 0 ? void 0 : context.sort) === null || _d === void 0 ? void 0 : _d.orderBy) === sortKey &&
32
+ ((_e = context === null || context === void 0 ? void 0 : context.sort) === null || _e === void 0 ? void 0 : _e.direction) === "descending" ? (React.createElement(Down, { "aria-label": "sorter synkende" })) : (React.createElement(Up, { "aria-label": "sorter stigende" })))) : (children)));
33
+ });
34
+ export default ColumnHeader;
35
+ //# sourceMappingURL=ColumnHeader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColumnHeader.js","sourceRoot":"","sources":["../../src/table/ColumnHeader.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,UAA+B,MAAM,cAAc,CAAC;AAmB3D,MAAM,YAAY,GAAqB,UAAU,CAC/C,CAAC,EAA2D,EAAE,GAAG,EAAE,EAAE;;QAApE,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,KAAK,EAAE,OAAO,OAAW,EAAN,IAAI,cAAzD,gDAA2D,CAAF;IACxD,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,IAAI,QAAQ,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;KACxE;IAED,OAAO,CACL,oBAAC,UAAU,kBACT,KAAK,EAAC,KAAK,EACX,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,eAElB,QAAQ;YACN,CAAC,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,OAAO,MAAK,OAAO;gBAClC,CAAC,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,SAAS;gBAC1B,CAAC,CAAC,MAAM;YACV,CAAC,CAAC,SAAS,IAEX,IAAI,GAEP,QAAQ,CAAC,CAAC,CAAC,CACV,gCACE,SAAS,EAAC,0BAA0B,EACpC,OAAO,EACL,QAAQ,IAAI,OAAO;YACjB,CAAC,CAAC,GAAG,EAAE,WAAC,OAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,+CAArB,OAAO,EAAiB,OAAO,CAAC,CAAA,EAAA;YACxC,CAAC,CAAC,SAAS;QAGd,QAAQ;QACR,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,OAAO,MAAK,OAAO;YACnC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,SAAS,MAAK,YAAY,CAAC,CAAC,CAAC,CAC1C,oBAAC,IAAI,kBAAY,iBAAiB,GAAG,CACtC,CAAC,CAAC,CAAC,CACF,oBAAC,EAAE,kBAAY,iBAAiB,GAAG,CACpC,CACM,CACV,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,CACU,CACd,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,5 +1,10 @@
1
1
  import React from "react";
2
2
  interface DataCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
3
+ /**
4
+ * Content alignment
5
+ * @default "left"
6
+ */
7
+ align?: "left" | "center" | "right";
3
8
  }
4
9
  export interface DataCellType extends React.ForwardRefExoticComponent<DataCellProps & React.RefAttributes<HTMLTableCellElement>> {
5
10
  }
@@ -14,9 +14,11 @@ import cl from "classnames";
14
14
  import { BodyShort } from "..";
15
15
  import { TableContext } from ".";
16
16
  const DataCell = forwardRef((_a, ref) => {
17
- var { className, children = "" } = _a, rest = __rest(_a, ["className", "children"]);
17
+ var { className, children = "", align } = _a, rest = __rest(_a, ["className", "children", "align"]);
18
18
  const context = useContext(TableContext);
19
- return (React.createElement(BodyShort, Object.assign({ as: "td", ref: ref, className: cl("navds-table__data-cell", className), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
19
+ return (React.createElement(BodyShort, Object.assign({ as: "td", ref: ref, className: cl("navds-table__data-cell", className, {
20
+ [`navds-table__data-cell--align-${align}`]: align,
21
+ }), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
20
22
  });
21
23
  export default DataCell;
22
24
  //# sourceMappingURL=DataCell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DataCell.js","sourceRoot":"","sources":["../../src/table/DataCell.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AASjC,MAAM,QAAQ,GAAiB,UAAU,CACvC,CAAC,EAAqC,EAAE,GAAG,EAAE,EAAE;QAA9C,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,OAAW,EAAN,IAAI,cAAnC,yBAAqC,CAAF;IAClC,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,OAAO,CACL,oBAAC,SAAS,kBACR,EAAE,EAAC,IAAI,EACP,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,wBAAwB,EAAE,SAAS,CAAC,EAClD,IAAI,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,IACf,IAAI,GAEP,QAAQ,CACC,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"DataCell.js","sourceRoot":"","sources":["../../src/table/DataCell.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAejC,MAAM,QAAQ,GAAiB,UAAU,CACvC,CAAC,EAA4C,EAAE,GAAG,EAAE,EAAE;QAArD,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,KAAK,OAAW,EAAN,IAAI,cAA1C,kCAA4C,CAAF;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,OAAO,CACL,oBAAC,SAAS,kBACR,EAAE,EAAC,IAAI,EACP,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,wBAAwB,EAAE,SAAS,EAAE;YACjD,CAAC,iCAAiC,KAAK,EAAE,CAAC,EAAE,KAAK;SAClD,CAAC,EACF,IAAI,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,IACf,IAAI,GAEP,QAAQ,CACC,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import React from "react";
2
- interface HeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
2
+ export interface HeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
3
3
  scope?: string;
4
+ /**
5
+ * Content alignment
6
+ * @default "left"
7
+ */
8
+ align?: "left" | "center" | "right";
4
9
  }
5
10
  export interface HeaderCellType extends React.ForwardRefExoticComponent<HeaderCellProps & React.RefAttributes<HTMLTableCellElement>> {
6
11
  }
@@ -13,9 +13,11 @@ import React, { forwardRef, useContext } from "react";
13
13
  import cl from "classnames";
14
14
  import { Label, TableContext } from "..";
15
15
  const HeaderCell = forwardRef((_a, ref) => {
16
- var { className, children } = _a, rest = __rest(_a, ["className", "children"]);
16
+ var { className, children, align } = _a, rest = __rest(_a, ["className", "children", "align"]);
17
17
  const context = useContext(TableContext);
18
- return (React.createElement(Label, Object.assign({ as: "th", ref: ref, className: cl("navds-table__header-cell", className), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
18
+ return (React.createElement(Label, Object.assign({ as: "th", ref: ref, className: cl("navds-table__header-cell", className, {
19
+ [`navds-table__header-cell--align-${align}`]: align,
20
+ }), size: context === null || context === void 0 ? void 0 : context.size }, rest), children));
19
21
  });
20
22
  export default HeaderCell;
21
23
  //# sourceMappingURL=HeaderCell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HeaderCell.js","sourceRoot":"","sources":["../../src/table/HeaderCell.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,YAAY,EAAE,MAAM,IAAI,CAAC;AAWzC,MAAM,UAAU,GAAmB,UAAU,CAC3C,CAAC,EAAgC,EAAE,GAAG,EAAE,EAAE;QAAzC,EAAE,SAAS,EAAE,QAAQ,OAAW,EAAN,IAAI,cAA9B,yBAAgC,CAAF;IAC7B,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,OAAO,CACL,oBAAC,KAAK,kBACJ,EAAE,EAAC,IAAI,EACP,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,0BAA0B,EAAE,SAAS,CAAC,EACpD,IAAI,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,IACf,IAAI,GAEP,QAAQ,CACH,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"HeaderCell.js","sourceRoot":"","sources":["../../src/table/HeaderCell.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,YAAY,EAAE,MAAM,IAAI,CAAC;AAiBzC,MAAM,UAAU,GAAmB,UAAU,CAC3C,CAAC,EAAuC,EAAE,GAAG,EAAE,EAAE;QAAhD,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,OAAW,EAAN,IAAI,cAArC,kCAAuC,CAAF;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,OAAO,CACL,oBAAC,KAAK,kBACJ,EAAE,EAAC,IAAI,EACP,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,0BAA0B,EAAE,SAAS,EAAE;YACnD,CAAC,mCAAmC,KAAK,EAAE,CAAC,EAAE,KAAK;SACpD,CAAC,EACF,IAAI,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,IACf,IAAI,GAEP,QAAQ,CACH,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -2,8 +2,13 @@ import React from "react";
2
2
  import { HeaderType } from "./Header";
3
3
  import { BodyType } from "./Body";
4
4
  import { RowType } from "./Row";
5
+ import { ColumnHeaderType } from "./ColumnHeader";
5
6
  import { HeaderCellType } from "./HeaderCell";
6
7
  import { DataCellType } from "./DataCell";
8
+ export interface SortState {
9
+ orderBy: string;
10
+ direction: "ascending" | "descending";
11
+ }
7
12
  export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement> {
8
13
  /**
9
14
  * Changes padding
@@ -15,6 +20,14 @@ export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement>
15
20
  * @default false
16
21
  */
17
22
  zebraStripes?: boolean;
23
+ /**
24
+ * Sort state
25
+ */
26
+ sort?: SortState;
27
+ /**
28
+ * Callback whens sort state changes
29
+ */
30
+ onSortChange?: (sortKey?: string) => void;
18
31
  }
19
32
  export interface TableType extends React.ForwardRefExoticComponent<TableProps & React.RefAttributes<HTMLTableElement>> {
20
33
  Header: HeaderType;
@@ -22,9 +35,12 @@ export interface TableType extends React.ForwardRefExoticComponent<TableProps &
22
35
  Row: RowType;
23
36
  DataCell: DataCellType;
24
37
  HeaderCell: HeaderCellType;
38
+ ColumnHeader: ColumnHeaderType;
25
39
  }
26
40
  export interface TableContextProps {
27
41
  size: "medium" | "small";
42
+ onSortChange?: (sortKey: string) => void;
43
+ sort?: SortState;
28
44
  }
29
45
  export declare const TableContext: React.Context<TableContextProps | null>;
30
46
  declare const Table: TableType;
@@ -14,12 +14,13 @@ import cl from "classnames";
14
14
  import Header from "./Header";
15
15
  import Body from "./Body";
16
16
  import Row from "./Row";
17
+ import ColumnHeader from "./ColumnHeader";
17
18
  import HeaderCell from "./HeaderCell";
18
19
  import DataCell from "./DataCell";
19
20
  export const TableContext = createContext(null);
20
21
  const Table = forwardRef((_a, ref) => {
21
- var { className, zebraStripes = false, size = "medium" } = _a, rest = __rest(_a, ["className", "zebraStripes", "size"]);
22
- return (React.createElement(TableContext.Provider, { value: { size } },
22
+ var { className, zebraStripes = false, size = "medium", onSortChange, sort } = _a, rest = __rest(_a, ["className", "zebraStripes", "size", "onSortChange", "sort"]);
23
+ return (React.createElement(TableContext.Provider, { value: { size, onSortChange, sort } },
23
24
  React.createElement("table", Object.assign({}, rest, { ref: ref, className: cl("navds-table", `navds-table--${size}`, className, {
24
25
  "navds-table--zebra-stripes": zebraStripes,
25
26
  }) }))));
@@ -27,6 +28,7 @@ const Table = forwardRef((_a, ref) => {
27
28
  Table.Header = Header;
28
29
  Table.Body = Body;
29
30
  Table.Row = Row;
31
+ Table.ColumnHeader = ColumnHeader;
30
32
  Table.HeaderCell = HeaderCell;
31
33
  Table.DataCell = DataCell;
32
34
  export default Table;
@@ -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;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C;AAC1D,OAAO,QAA0B,MAAM,YAAY,CAAC;AA+CpD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAE1E,MAAM,KAAK,GAAG,UAAU,CACtB,CACE,EAOC,EACD,GAAG,EACH,EAAE;QATF,EACE,SAAS,EACT,YAAY,GAAG,KAAK,EACpB,IAAI,GAAG,QAAQ,EACf,YAAY,EACZ,IAAI,OAEL,EADI,IAAI,cANT,6DAOC,CADQ;IAGN,OAAA,CACH,oBAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;QACxD,+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,YAAY,GAAG,YAAY,CAAC;AAClC,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;AAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAE1B,eAAe,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.16.17",
3
+ "version": "0.16.18",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -59,11 +59,12 @@
59
59
  "react-router-dom": "^6.1.0",
60
60
  "rimraf": "3.0.2",
61
61
  "styled-components": "^5.3.1",
62
+ "swr": "^1.1.2",
62
63
  "ts-jest": "^27.0.5"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "@types/react": "^17.0.30",
66
67
  "react": "^17.0.0"
67
68
  },
68
- "gitHead": "9c86becab0a0f5d4cd2d9086e4c2c65812eb71fc"
69
+ "gitHead": "6f5fee96288a9d7302a595d9d5a09102387c39c2"
69
70
  }
@@ -19,7 +19,7 @@ export interface ButtonProps
19
19
  * Changes padding, height and font-size
20
20
  * @default "medium"
21
21
  */
22
- size?: "medium" | "small";
22
+ size?: "medium" | "small" | "xsmall";
23
23
  /**
24
24
  * Prevent the user from interacting with the button: it cannot be pressed or focused.
25
25
  * @note Avoid using if possible for accessibility purposes
@@ -43,6 +43,7 @@ const Button: OverridableComponent<ButtonProps, HTMLButtonElement> = forwardRef(
43
43
  size = "medium",
44
44
  loading = false,
45
45
  disabled,
46
+ style,
46
47
  ...rest
47
48
  },
48
49
  ref
@@ -76,13 +77,16 @@ const Button: OverridableComponent<ButtonProps, HTMLButtonElement> = forwardRef(
76
77
  "navds-button--loading": widthOverride,
77
78
  }
78
79
  )}
79
- style={{ width: widthOverride }}
80
+ style={{
81
+ ...style,
82
+ width: widthOverride,
83
+ }}
80
84
  disabled={disabled ?? widthOverride ? true : undefined}
81
85
  >
82
86
  <BodyShort
83
87
  as="span"
84
88
  className="navds-button__inner"
85
- size={size}
89
+ size={size === "medium" ? "medium" : "small"}
86
90
  aria-live="polite"
87
91
  >
88
92
  {widthOverride ? <Loader size={size} /> : children}
@@ -81,6 +81,14 @@ export const All = () => {
81
81
  </Button>
82
82
  ))}
83
83
  </Section>
84
+ <h2>Xsmall</h2>
85
+ <Section>
86
+ {variants.map((variant) => (
87
+ <Button key={variant} variant={variant} size="xsmall">
88
+ {varSwitch[variant]}
89
+ </Button>
90
+ ))}
91
+ </Section>
84
92
  <h2>Button w/icon</h2>
85
93
  <Section>
86
94
  {variants.map((variant) => (
package/src/menu/Menu.tsx CHANGED
@@ -19,15 +19,15 @@ interface MenuComponent
19
19
 
20
20
  const Menu = forwardRef<HTMLElement, MenuProps>(
21
21
  ({ children, className, ...rest }, ref) => (
22
- <nav
23
- {...rest}
24
- role="navigation"
25
- ref={ref}
26
- className={cl("navds-menu", className)}
27
- >
28
- <MenuItems>{children}</MenuItems>
29
- </nav>
30
- )
22
+ <nav
23
+ {...rest}
24
+ role="navigation"
25
+ ref={ref}
26
+ className={cl("navds-menu", className)}
27
+ >
28
+ <MenuItems>{children}</MenuItems>
29
+ </nav>
30
+ )
31
31
  ) as MenuComponent;
32
32
 
33
33
  Menu.Collapse = Collapse;
@@ -0,0 +1,70 @@
1
+ import React, { forwardRef, useContext } from "react";
2
+ import { Down, Up } from "@navikt/ds-icons";
3
+ import { TableContext } from "..";
4
+ import HeaderCell, { HeaderCellProps } from "./HeaderCell";
5
+
6
+ interface ColumnHeaderProps extends HeaderCellProps {
7
+ /**
8
+ * Key to sort by
9
+ */
10
+ sortKey?: string;
11
+ /**
12
+ * Column is sortable
13
+ * @default false
14
+ */
15
+ sortable?: boolean;
16
+ }
17
+
18
+ export interface ColumnHeaderType
19
+ extends React.ForwardRefExoticComponent<
20
+ ColumnHeaderProps & React.RefAttributes<HTMLTableCellElement>
21
+ > {}
22
+
23
+ const ColumnHeader: ColumnHeaderType = forwardRef(
24
+ ({ className, children, sortable = false, sortKey, ...rest }, ref) => {
25
+ const context = useContext(TableContext);
26
+
27
+ if (sortable && !sortKey) {
28
+ console.warn("ColumnHeader with `sortable=true` must have a sortKey.");
29
+ }
30
+
31
+ return (
32
+ <HeaderCell
33
+ scope="col"
34
+ ref={ref}
35
+ className={className}
36
+ aria-sort={
37
+ sortable
38
+ ? context?.sort?.orderBy === sortKey
39
+ ? context?.sort?.direction
40
+ : "none"
41
+ : undefined
42
+ }
43
+ {...rest}
44
+ >
45
+ {sortable ? (
46
+ <button
47
+ className="navds-table__sort-button"
48
+ onClick={
49
+ sortable && sortKey
50
+ ? () => context?.onSortChange?.(sortKey)
51
+ : undefined
52
+ }
53
+ >
54
+ {children}
55
+ {context?.sort?.orderBy === sortKey &&
56
+ context?.sort?.direction === "descending" ? (
57
+ <Down aria-label="sorter synkende" />
58
+ ) : (
59
+ <Up aria-label="sorter stigende" />
60
+ )}
61
+ </button>
62
+ ) : (
63
+ children
64
+ )}
65
+ </HeaderCell>
66
+ );
67
+ }
68
+ );
69
+
70
+ export default ColumnHeader;
@@ -3,7 +3,13 @@ import cl from "classnames";
3
3
  import { BodyShort } from "..";
4
4
  import { TableContext } from ".";
5
5
 
6
- interface DataCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {}
6
+ interface DataCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
7
+ /**
8
+ * Content alignment
9
+ * @default "left"
10
+ */
11
+ align?: "left" | "center" | "right";
12
+ }
7
13
 
8
14
  export interface DataCellType
9
15
  extends React.ForwardRefExoticComponent<
@@ -11,14 +17,16 @@ export interface DataCellType
11
17
  > {}
12
18
 
13
19
  const DataCell: DataCellType = forwardRef(
14
- ({ className, children = "", ...rest }, ref) => {
20
+ ({ className, children = "", align, ...rest }, ref) => {
15
21
  const context = useContext(TableContext);
16
22
 
17
23
  return (
18
24
  <BodyShort
19
25
  as="td"
20
26
  ref={ref}
21
- className={cl("navds-table__data-cell", className)}
27
+ className={cl("navds-table__data-cell", className, {
28
+ [`navds-table__data-cell--align-${align}`]: align,
29
+ })}
22
30
  size={context?.size}
23
31
  {...rest}
24
32
  >
@@ -2,8 +2,14 @@ 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.ThHTMLAttributes<HTMLTableCellElement> {
5
+ export interface HeaderCellProps
6
+ extends React.ThHTMLAttributes<HTMLTableCellElement> {
6
7
  scope?: string;
8
+ /**
9
+ * Content alignment
10
+ * @default "left"
11
+ */
12
+ align?: "left" | "center" | "right";
7
13
  }
8
14
 
9
15
  export interface HeaderCellType
@@ -12,14 +18,16 @@ export interface HeaderCellType
12
18
  > {}
13
19
 
14
20
  const HeaderCell: HeaderCellType = forwardRef(
15
- ({ className, children, ...rest }, ref) => {
21
+ ({ className, children, align, ...rest }, ref) => {
16
22
  const context = useContext(TableContext);
17
23
 
18
24
  return (
19
25
  <Label
20
26
  as="th"
21
27
  ref={ref}
22
- className={cl("navds-table__header-cell", className)}
28
+ className={cl("navds-table__header-cell", className, {
29
+ [`navds-table__header-cell--align-${align}`]: align,
30
+ })}
23
31
  size={context?.size}
24
32
  {...rest}
25
33
  >