@navikt/ds-react 2.7.8 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_docs.json +340 -0
- package/cjs/expansion-card/ExpansionCard.js +76 -0
- package/cjs/expansion-card/ExpansionCardContent.js +56 -0
- package/cjs/expansion-card/ExpansionCardDescription.js +47 -0
- package/cjs/expansion-card/ExpansionCardHeader.js +56 -0
- package/cjs/expansion-card/ExpansionCardTitle.js +46 -0
- package/cjs/expansion-card/index.js +8 -0
- package/cjs/expansion-card/package.json +6 -0
- package/cjs/index.js +1 -0
- package/esm/expansion-card/ExpansionCard.d.ts +43 -0
- package/esm/expansion-card/ExpansionCard.js +48 -0
- package/esm/expansion-card/ExpansionCard.js.map +1 -0
- package/esm/expansion-card/ExpansionCardContent.d.ts +7 -0
- package/esm/expansion-card/ExpansionCardContent.js +29 -0
- package/esm/expansion-card/ExpansionCardContent.js.map +1 -0
- package/esm/expansion-card/ExpansionCardDescription.d.ts +7 -0
- package/esm/expansion-card/ExpansionCardDescription.js +19 -0
- package/esm/expansion-card/ExpansionCardDescription.js.map +1 -0
- package/esm/expansion-card/ExpansionCardHeader.d.ts +7 -0
- package/esm/expansion-card/ExpansionCardHeader.js +29 -0
- package/esm/expansion-card/ExpansionCardHeader.js.map +1 -0
- package/esm/expansion-card/ExpansionCardTitle.d.ts +13 -0
- package/esm/expansion-card/ExpansionCardTitle.js +18 -0
- package/esm/expansion-card/ExpansionCardTitle.js.map +1 -0
- package/esm/expansion-card/index.d.ts +1 -0
- package/esm/expansion-card/index.js +2 -0
- package/esm/expansion-card/index.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/package.json +3 -2
- package/src/expansion-card/ExpansionCard.tsx +119 -0
- package/src/expansion-card/ExpansionCardContent.tsx +42 -0
- package/src/expansion-card/ExpansionCardDescription.tsx +22 -0
- package/src/expansion-card/ExpansionCardHeader.tsx +50 -0
- package/src/expansion-card/ExpansionCardTitle.tsx +34 -0
- package/src/expansion-card/expansion-card.stories.tsx +269 -0
- package/src/expansion-card/index.ts +4 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ExpansionCardContentType } from "./ExpansionCardContent";
|
|
3
|
+
import { ExpansionCardDescriptionType } from "./ExpansionCardDescription";
|
|
4
|
+
import { ExpansionCardHeaderType } from "./ExpansionCardHeader";
|
|
5
|
+
import { ExpansionCardTitleType } from "./ExpansionCardTitle";
|
|
6
|
+
interface ExpansionCardComponent extends React.ForwardRefExoticComponent<ExpansionCardProps & React.RefAttributes<HTMLDivElement>> {
|
|
7
|
+
Header: ExpansionCardHeaderType;
|
|
8
|
+
Title: ExpansionCardTitleType;
|
|
9
|
+
Description: ExpansionCardDescriptionType;
|
|
10
|
+
Content: ExpansionCardContentType;
|
|
11
|
+
}
|
|
12
|
+
export interface ExpansionCardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Callback for when Card is toggled open/closed
|
|
16
|
+
*/
|
|
17
|
+
onToggle?: (open: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Controlled open-state
|
|
20
|
+
* Using this removes automatic control of open-state
|
|
21
|
+
*/
|
|
22
|
+
open?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Defaults to open if not controlled
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
defaultOpen?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @default "medium"
|
|
30
|
+
*/
|
|
31
|
+
size?: "medium" | "small";
|
|
32
|
+
/**
|
|
33
|
+
* Since ExpansionCard is a section-element, accessible name is required.
|
|
34
|
+
*/
|
|
35
|
+
["aria-label"]: string;
|
|
36
|
+
}
|
|
37
|
+
export type ExpansionCardContextProps = {
|
|
38
|
+
open: boolean;
|
|
39
|
+
toggleOpen: () => void;
|
|
40
|
+
};
|
|
41
|
+
export declare const ExpansionCardContext: React.Context<ExpansionCardContextProps>;
|
|
42
|
+
export declare const ExpansionCard: ExpansionCardComponent;
|
|
43
|
+
export default ExpansionCard;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 "clsx";
|
|
13
|
+
import React, { createContext, forwardRef, useRef, useState } from "react";
|
|
14
|
+
import ExpansionCardContent from "./ExpansionCardContent";
|
|
15
|
+
import { ExpansionCardDescription, } from "./ExpansionCardDescription";
|
|
16
|
+
import ExpansionCardHeader from "./ExpansionCardHeader";
|
|
17
|
+
import { ExpansionCardTitle, } from "./ExpansionCardTitle";
|
|
18
|
+
export const ExpansionCardContext = createContext({
|
|
19
|
+
open: false,
|
|
20
|
+
toggleOpen: () => { },
|
|
21
|
+
});
|
|
22
|
+
export const ExpansionCard = forwardRef((_a, ref) => {
|
|
23
|
+
var { className, onToggle, open, defaultOpen = false, size = "medium" } = _a, rest = __rest(_a, ["className", "onToggle", "open", "defaultOpen", "size"]);
|
|
24
|
+
const [_open, _setOpen] = useState(defaultOpen);
|
|
25
|
+
const shouldFade = useRef(!(Boolean(open) || defaultOpen));
|
|
26
|
+
const handleOpen = () => {
|
|
27
|
+
if (open === undefined) {
|
|
28
|
+
const newOpen = !_open;
|
|
29
|
+
_setOpen(newOpen);
|
|
30
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(newOpen);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(!open);
|
|
34
|
+
}
|
|
35
|
+
shouldFade.current = true;
|
|
36
|
+
};
|
|
37
|
+
return (React.createElement(ExpansionCardContext.Provider, { value: { open: open !== null && open !== void 0 ? open : _open, toggleOpen: handleOpen } },
|
|
38
|
+
React.createElement("section", Object.assign({}, rest, { className: cl("navds-expansioncard", className, `navds-expansioncard--${size}`, {
|
|
39
|
+
"navds-expansioncard--open": open !== null && open !== void 0 ? open : _open,
|
|
40
|
+
"navds-expansioncard--no-fade": !shouldFade.current,
|
|
41
|
+
}), ref: ref }))));
|
|
42
|
+
});
|
|
43
|
+
ExpansionCard.Header = ExpansionCardHeader;
|
|
44
|
+
ExpansionCard.Content = ExpansionCardContent;
|
|
45
|
+
ExpansionCard.Title = ExpansionCardTitle;
|
|
46
|
+
ExpansionCard.Description = ExpansionCardDescription;
|
|
47
|
+
export default ExpansionCard;
|
|
48
|
+
//# sourceMappingURL=ExpansionCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpansionCard.js","sourceRoot":"","sources":["../../src/expansion-card/ExpansionCard.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,oBAEN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,mBAEN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AA4C9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B;IAC3E,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CACrC,CACE,EAOC,EACD,GAAG,EACH,EAAE;QATF,EACE,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,WAAW,GAAG,KAAK,EACnB,IAAI,GAAG,QAAQ,OAEhB,EADI,IAAI,cANT,wDAOC,CADQ;IAIT,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEhD,MAAM,UAAU,GAAG,MAAM,CAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC;IAEpE,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC;YACvB,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,OAAO,CAAC,CAAC;SACrB;aAAM;YACL,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,CAAC,IAAI,CAAC,CAAC;SACnB;QACD,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE;QAEtD,iDACM,IAAI,IACR,SAAS,EAAE,EAAE,CACX,qBAAqB,EACrB,SAAS,EACT,wBAAwB,IAAI,EAAE,EAC9B;gBACE,2BAA2B,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,KAAK;gBAC1C,8BAA8B,EAAE,CAAC,UAAU,CAAC,OAAO;aACpD,CACF,EACD,GAAG,EAAE,GAAG,IACR,CAC4B,CACjC,CAAC;AACJ,CAAC,CACwB,CAAC;AAE5B,aAAa,CAAC,MAAM,GAAG,mBAAmB,CAAC;AAC3C,aAAa,CAAC,OAAO,GAAG,oBAAoB,CAAC;AAC7C,aAAa,CAAC,KAAK,GAAG,kBAAkB,CAAC;AACzC,aAAa,CAAC,WAAW,GAAG,wBAAwB,CAAC;AAErD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ExpansionCardContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export type ExpansionCardContentType = React.ForwardRefExoticComponent<ExpansionCardContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
declare const ExpansionCardContent: ExpansionCardContentType;
|
|
7
|
+
export default ExpansionCardContent;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 "clsx";
|
|
13
|
+
import React, { forwardRef, useContext } from "react";
|
|
14
|
+
import { BodyLong } from "../typography/BodyLong";
|
|
15
|
+
import { ExpansionCardContext } from "./ExpansionCard";
|
|
16
|
+
const ExpansionCardContent = forwardRef((_a, ref) => {
|
|
17
|
+
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
|
|
18
|
+
const panelContext = useContext(ExpansionCardContext);
|
|
19
|
+
if (panelContext === null) {
|
|
20
|
+
console.error("<ExpansionCard.Content> has to be used within an <ExpansionCard>");
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (React.createElement(BodyLong, Object.assign({}, rest, { ref: ref, as: "div", className: cl("navds-expansioncard__content", {
|
|
24
|
+
"navds-expansioncard__content--closed": !panelContext.open,
|
|
25
|
+
}), "aria-hidden": !panelContext.open }),
|
|
26
|
+
React.createElement("div", { className: "navds-expansioncard__content-inner" }, children)));
|
|
27
|
+
});
|
|
28
|
+
export default ExpansionCardContent;
|
|
29
|
+
//# sourceMappingURL=ExpansionCardContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpansionCardContent.js","sourceRoot":"","sources":["../../src/expansion-card/ExpansionCardContent.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAWvD,MAAM,oBAAoB,GAA6B,UAAU,CAC/D,CAAC,EAAgC,EAAE,GAAG,EAAE,EAAE;QAAzC,EAAE,QAAQ,EAAE,SAAS,OAAW,EAAN,IAAI,cAA9B,yBAAgC,CAAF;IAC7B,MAAM,YAAY,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEtD,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO,CAAC,KAAK,CACX,kEAAkE,CACnE,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,oBAAC,QAAQ,oBACH,IAAI,IACR,GAAG,EAAE,GAAG,EACR,EAAE,EAAC,KAAK,EACR,SAAS,EAAE,EAAE,CAAC,8BAA8B,EAAE;YAC5C,sCAAsC,EAAE,CAAC,YAAY,CAAC,IAAI;SAC3D,CAAC,iBACW,CAAC,YAAY,CAAC,IAAI;QAE/B,6BAAK,SAAS,EAAC,oCAAoC,IAAE,QAAQ,CAAO,CAC3D,CACZ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface ExpansionCardDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export type ExpansionCardDescriptionType = React.ForwardRefExoticComponent<ExpansionCardDescriptionProps & React.RefAttributes<HTMLParagraphElement>>;
|
|
6
|
+
export declare const ExpansionCardDescription: ExpansionCardDescriptionType;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 } from "react";
|
|
13
|
+
import cl from "clsx";
|
|
14
|
+
import { BodyLong } from "../typography/BodyLong";
|
|
15
|
+
export const ExpansionCardDescription = forwardRef((_a, ref) => {
|
|
16
|
+
var { className } = _a, rest = __rest(_a, ["className"]);
|
|
17
|
+
return (React.createElement(BodyLong, Object.assign({}, rest, { as: "p", ref: ref, className: cl("navds-link-panel__description", className) })));
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=ExpansionCardDescription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpansionCardDescription.js","sourceRoot":"","sources":["../../src/expansion-card/ExpansionCardDescription.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAWlD,MAAM,CAAC,MAAM,wBAAwB,GACnC,UAAU,CAAC,CAAC,EAAsB,EAAE,GAAG,EAAE,EAAE;QAA/B,EAAE,SAAS,OAAW,EAAN,IAAI,cAApB,aAAsB,CAAF;IAAY,OAAA,CAC1C,oBAAC,QAAQ,oBACH,IAAI,IACR,EAAE,EAAC,GAAG,EACN,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,+BAA+B,EAAE,SAAS,CAAC,IACzD,CACH,CAAA;CAAA,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ExpansionCardHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export type ExpansionCardHeaderType = React.ForwardRefExoticComponent<ExpansionCardHeaderProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
declare const ExpansionCardHeader: ExpansionCardHeaderType;
|
|
7
|
+
export default ExpansionCardHeader;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 "clsx";
|
|
13
|
+
import React, { forwardRef, useContext } from "react";
|
|
14
|
+
import { ExpansionCardContext } from "./ExpansionCard";
|
|
15
|
+
import { ChevronDownIcon } from "@navikt/aksel-icons";
|
|
16
|
+
const ExpansionCardHeader = forwardRef((_a, ref) => {
|
|
17
|
+
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
|
|
18
|
+
const panelContext = useContext(ExpansionCardContext);
|
|
19
|
+
if (panelContext === null) {
|
|
20
|
+
console.error("<ExpansionCard.Header> has to be used within an <ExpansionCard>");
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (React.createElement("div", Object.assign({ ref: ref }, rest, { className: cl("navds-expansioncard__header", className) }),
|
|
24
|
+
React.createElement("div", { className: "navds-expansioncard__header-content" }, children),
|
|
25
|
+
React.createElement("button", { className: "navds-expansioncard__header-button", onClick: () => panelContext.toggleOpen(), type: "button", "aria-expanded": panelContext.open },
|
|
26
|
+
React.createElement(ChevronDownIcon, { className: "navds-expansioncard__header-chevron", title: "Vis mer" }))));
|
|
27
|
+
});
|
|
28
|
+
export default ExpansionCardHeader;
|
|
29
|
+
//# sourceMappingURL=ExpansionCardHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpansionCardHeader.js","sourceRoot":"","sources":["../../src/expansion-card/ExpansionCardHeader.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAWtD,MAAM,mBAAmB,GAA4B,UAAU,CAC7D,CAAC,EAAgC,EAAE,GAAG,EAAE,EAAE;QAAzC,EAAE,QAAQ,EAAE,SAAS,OAAW,EAAN,IAAI,cAA9B,yBAAgC,CAAF;IAC7B,MAAM,YAAY,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEtD,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO,CAAC,KAAK,CACX,iEAAiE,CAClE,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,2CACE,GAAG,EAAE,GAAG,IACJ,IAAI,IACR,SAAS,EAAE,EAAE,CAAC,6BAA6B,EAAE,SAAS,CAAC;QAEvD,6BAAK,SAAS,EAAC,qCAAqC,IAAE,QAAQ,CAAO;QAErE,gCACE,SAAS,EAAC,oCAAoC,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,EACxC,IAAI,EAAC,QAAQ,mBACE,YAAY,CAAC,IAAI;YAEhC,oBAAC,eAAe,IACd,SAAS,EAAC,qCAAqC,EAC/C,KAAK,EAAC,SAAS,GACf,CACK,CACL,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { OverridableComponent } from "../util/OverridableComponent";
|
|
3
|
+
interface ExpansionCardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* Changes text-sizing
|
|
7
|
+
* @default small
|
|
8
|
+
*/
|
|
9
|
+
size?: "large" | "medium" | "small";
|
|
10
|
+
}
|
|
11
|
+
export type ExpansionCardTitleType = OverridableComponent<ExpansionCardTitleProps, HTMLHeadingElement>;
|
|
12
|
+
export declare const ExpansionCardTitle: ExpansionCardTitleType;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from "react";
|
|
13
|
+
import cl from "clsx";
|
|
14
|
+
export const ExpansionCardTitle = forwardRef((_a, ref) => {
|
|
15
|
+
var { className, as: Component = "h3", size = "small" } = _a, rest = __rest(_a, ["className", "as", "size"]);
|
|
16
|
+
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, className: cl("navds-expansioncard__title", `navds-expansioncard__title--${size}`, "navds-heading", `navds-heading--${size}`, className) })));
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=ExpansionCardTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpansionCardTitle.js","sourceRoot":"","sources":["../../src/expansion-card/ExpansionCardTitle.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,MAAM,CAAC;AAkBtB,MAAM,CAAC,MAAM,kBAAkB,GAA2B,UAAU,CAClE,CAAC,EAA4D,EAAE,GAAG,EAAE,EAAE;QAArE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,GAAG,OAAO,OAAW,EAAN,IAAI,cAA1D,2BAA4D,CAAF;IAAY,OAAA,CACrE,oBAAC,SAAS,oBACJ,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,4BAA4B,EAC5B,+BAA+B,IAAI,EAAE,EACrC,eAAe,EACf,kBAAkB,IAAI,EAAE,EACxB,SAAS,CACV,IACD,CACH,CAAA;CAAA,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type ExpansionCardProps, default as ExpansionCard, } from "./ExpansionCard";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expansion-card/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,IAAI,aAAa,GACzB,MAAM,iBAAiB,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,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,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,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@floating-ui/react": "0.17.0",
|
|
40
|
-
"@navikt/
|
|
40
|
+
"@navikt/aksel-icons": "^2.8.0",
|
|
41
|
+
"@navikt/ds-icons": "^2.8.0",
|
|
41
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
42
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
43
44
|
"clsx": "^1.2.1",
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { createContext, forwardRef, useRef, useState } from "react";
|
|
3
|
+
import ExpansionCardContent, {
|
|
4
|
+
ExpansionCardContentType,
|
|
5
|
+
} from "./ExpansionCardContent";
|
|
6
|
+
import {
|
|
7
|
+
ExpansionCardDescription,
|
|
8
|
+
ExpansionCardDescriptionType,
|
|
9
|
+
} from "./ExpansionCardDescription";
|
|
10
|
+
import ExpansionCardHeader, {
|
|
11
|
+
ExpansionCardHeaderType,
|
|
12
|
+
} from "./ExpansionCardHeader";
|
|
13
|
+
import {
|
|
14
|
+
ExpansionCardTitle,
|
|
15
|
+
ExpansionCardTitleType,
|
|
16
|
+
} from "./ExpansionCardTitle";
|
|
17
|
+
|
|
18
|
+
interface ExpansionCardComponent
|
|
19
|
+
extends React.ForwardRefExoticComponent<
|
|
20
|
+
ExpansionCardProps & React.RefAttributes<HTMLDivElement>
|
|
21
|
+
> {
|
|
22
|
+
Header: ExpansionCardHeaderType;
|
|
23
|
+
Title: ExpansionCardTitleType;
|
|
24
|
+
Description: ExpansionCardDescriptionType;
|
|
25
|
+
Content: ExpansionCardContentType;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ExpansionCardProps
|
|
29
|
+
extends React.HTMLAttributes<HTMLDivElement> {
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Callback for when Card is toggled open/closed
|
|
33
|
+
*/
|
|
34
|
+
onToggle?: (open: boolean) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Controlled open-state
|
|
37
|
+
* Using this removes automatic control of open-state
|
|
38
|
+
*/
|
|
39
|
+
open?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Defaults to open if not controlled
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
defaultOpen?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @default "medium"
|
|
47
|
+
*/
|
|
48
|
+
size?: "medium" | "small";
|
|
49
|
+
/**
|
|
50
|
+
* Since ExpansionCard is a section-element, accessible name is required.
|
|
51
|
+
*/
|
|
52
|
+
["aria-label"]: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type ExpansionCardContextProps = {
|
|
56
|
+
open: boolean;
|
|
57
|
+
toggleOpen: () => void;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const ExpansionCardContext = createContext<ExpansionCardContextProps>({
|
|
61
|
+
open: false,
|
|
62
|
+
toggleOpen: () => {},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const ExpansionCard = forwardRef<HTMLDivElement, ExpansionCardProps>(
|
|
66
|
+
(
|
|
67
|
+
{
|
|
68
|
+
className,
|
|
69
|
+
onToggle,
|
|
70
|
+
open,
|
|
71
|
+
defaultOpen = false,
|
|
72
|
+
size = "medium",
|
|
73
|
+
...rest
|
|
74
|
+
},
|
|
75
|
+
ref
|
|
76
|
+
) => {
|
|
77
|
+
const [_open, _setOpen] = useState(defaultOpen);
|
|
78
|
+
|
|
79
|
+
const shouldFade = useRef<boolean>(!(Boolean(open) || defaultOpen));
|
|
80
|
+
|
|
81
|
+
const handleOpen = () => {
|
|
82
|
+
if (open === undefined) {
|
|
83
|
+
const newOpen = !_open;
|
|
84
|
+
_setOpen(newOpen);
|
|
85
|
+
onToggle?.(newOpen);
|
|
86
|
+
} else {
|
|
87
|
+
onToggle?.(!open);
|
|
88
|
+
}
|
|
89
|
+
shouldFade.current = true;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ExpansionCardContext.Provider
|
|
94
|
+
value={{ open: open ?? _open, toggleOpen: handleOpen }}
|
|
95
|
+
>
|
|
96
|
+
<section
|
|
97
|
+
{...rest}
|
|
98
|
+
className={cl(
|
|
99
|
+
"navds-expansioncard",
|
|
100
|
+
className,
|
|
101
|
+
`navds-expansioncard--${size}`,
|
|
102
|
+
{
|
|
103
|
+
"navds-expansioncard--open": open ?? _open,
|
|
104
|
+
"navds-expansioncard--no-fade": !shouldFade.current,
|
|
105
|
+
}
|
|
106
|
+
)}
|
|
107
|
+
ref={ref}
|
|
108
|
+
/>
|
|
109
|
+
</ExpansionCardContext.Provider>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
) as ExpansionCardComponent;
|
|
113
|
+
|
|
114
|
+
ExpansionCard.Header = ExpansionCardHeader;
|
|
115
|
+
ExpansionCard.Content = ExpansionCardContent;
|
|
116
|
+
ExpansionCard.Title = ExpansionCardTitle;
|
|
117
|
+
ExpansionCard.Description = ExpansionCardDescription;
|
|
118
|
+
|
|
119
|
+
export default ExpansionCard;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { forwardRef, useContext } from "react";
|
|
3
|
+
import { BodyLong } from "../typography/BodyLong";
|
|
4
|
+
import { ExpansionCardContext } from "./ExpansionCard";
|
|
5
|
+
|
|
6
|
+
export interface ExpansionCardContentProps
|
|
7
|
+
extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ExpansionCardContentType = React.ForwardRefExoticComponent<
|
|
12
|
+
ExpansionCardContentProps & React.RefAttributes<HTMLDivElement>
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
const ExpansionCardContent: ExpansionCardContentType = forwardRef(
|
|
16
|
+
({ children, className, ...rest }, ref) => {
|
|
17
|
+
const panelContext = useContext(ExpansionCardContext);
|
|
18
|
+
|
|
19
|
+
if (panelContext === null) {
|
|
20
|
+
console.error(
|
|
21
|
+
"<ExpansionCard.Content> has to be used within an <ExpansionCard>"
|
|
22
|
+
);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<BodyLong
|
|
28
|
+
{...rest}
|
|
29
|
+
ref={ref}
|
|
30
|
+
as="div"
|
|
31
|
+
className={cl("navds-expansioncard__content", {
|
|
32
|
+
"navds-expansioncard__content--closed": !panelContext.open,
|
|
33
|
+
})}
|
|
34
|
+
aria-hidden={!panelContext.open}
|
|
35
|
+
>
|
|
36
|
+
<div className="navds-expansioncard__content-inner">{children}</div>
|
|
37
|
+
</BodyLong>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export default ExpansionCardContent;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import cl from "clsx";
|
|
3
|
+
import { BodyLong } from "../typography/BodyLong";
|
|
4
|
+
|
|
5
|
+
interface ExpansionCardDescriptionProps
|
|
6
|
+
extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ExpansionCardDescriptionType = React.ForwardRefExoticComponent<
|
|
11
|
+
ExpansionCardDescriptionProps & React.RefAttributes<HTMLParagraphElement>
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export const ExpansionCardDescription: ExpansionCardDescriptionType =
|
|
15
|
+
forwardRef(({ className, ...rest }, ref) => (
|
|
16
|
+
<BodyLong
|
|
17
|
+
{...rest}
|
|
18
|
+
as="p"
|
|
19
|
+
ref={ref}
|
|
20
|
+
className={cl("navds-link-panel__description", className)}
|
|
21
|
+
/>
|
|
22
|
+
));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { forwardRef, useContext } from "react";
|
|
3
|
+
import { ExpansionCardContext } from "./ExpansionCard";
|
|
4
|
+
import { ChevronDownIcon } from "@navikt/aksel-icons";
|
|
5
|
+
|
|
6
|
+
export interface ExpansionCardHeaderProps
|
|
7
|
+
extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ExpansionCardHeaderType = React.ForwardRefExoticComponent<
|
|
12
|
+
ExpansionCardHeaderProps & React.RefAttributes<HTMLDivElement>
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
const ExpansionCardHeader: ExpansionCardHeaderType = forwardRef(
|
|
16
|
+
({ children, className, ...rest }, ref) => {
|
|
17
|
+
const panelContext = useContext(ExpansionCardContext);
|
|
18
|
+
|
|
19
|
+
if (panelContext === null) {
|
|
20
|
+
console.error(
|
|
21
|
+
"<ExpansionCard.Header> has to be used within an <ExpansionCard>"
|
|
22
|
+
);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
ref={ref}
|
|
29
|
+
{...rest}
|
|
30
|
+
className={cl("navds-expansioncard__header", className)}
|
|
31
|
+
>
|
|
32
|
+
<div className="navds-expansioncard__header-content">{children}</div>
|
|
33
|
+
|
|
34
|
+
<button
|
|
35
|
+
className="navds-expansioncard__header-button"
|
|
36
|
+
onClick={() => panelContext.toggleOpen()}
|
|
37
|
+
type="button"
|
|
38
|
+
aria-expanded={panelContext.open}
|
|
39
|
+
>
|
|
40
|
+
<ChevronDownIcon
|
|
41
|
+
className="navds-expansioncard__header-chevron"
|
|
42
|
+
title="Vis mer"
|
|
43
|
+
/>
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export default ExpansionCardHeader;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import cl from "clsx";
|
|
3
|
+
import { OverridableComponent } from "../util/OverridableComponent";
|
|
4
|
+
|
|
5
|
+
interface ExpansionCardTitleProps
|
|
6
|
+
extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Changes text-sizing
|
|
10
|
+
* @default small
|
|
11
|
+
*/
|
|
12
|
+
size?: "large" | "medium" | "small";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ExpansionCardTitleType = OverridableComponent<
|
|
16
|
+
ExpansionCardTitleProps,
|
|
17
|
+
HTMLHeadingElement
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export const ExpansionCardTitle: ExpansionCardTitleType = forwardRef(
|
|
21
|
+
({ className, as: Component = "h3", size = "small", ...rest }, ref) => (
|
|
22
|
+
<Component
|
|
23
|
+
{...rest}
|
|
24
|
+
ref={ref}
|
|
25
|
+
className={cl(
|
|
26
|
+
"navds-expansioncard__title",
|
|
27
|
+
`navds-expansioncard__title--${size}`,
|
|
28
|
+
"navds-heading",
|
|
29
|
+
`navds-heading--${size}`,
|
|
30
|
+
className
|
|
31
|
+
)}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
);
|