@navikt/ds-react 4.10.2 → 4.11.1
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 +145 -63
- package/cjs/form/combobox/Input/Input.js +5 -2
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js +3 -0
- package/cjs/grid/Cell.js +4 -0
- package/cjs/grid/Grid.js +4 -0
- package/cjs/grid/index.js +1 -3
- package/cjs/index.js +2 -0
- package/cjs/layout/content-container/index.js +8 -0
- package/cjs/layout/content-container/package.json +6 -0
- package/cjs/layout/grid/HGrid.js +92 -0
- package/cjs/layout/grid/index.js +8 -0
- package/cjs/layout/grid/package.json +6 -0
- package/cjs/layout/stack/Stack.js +1 -1
- package/cjs/layout/utilities/css.js +20 -4
- package/esm/form/combobox/Input/Input.js +5 -2
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js +3 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -1
- package/esm/grid/Cell.d.ts +4 -0
- package/esm/grid/Cell.js +4 -0
- package/esm/grid/Cell.js.map +1 -1
- package/esm/grid/Grid.d.ts +4 -0
- package/esm/grid/Grid.js +4 -0
- package/esm/grid/Grid.js.map +1 -1
- package/esm/grid/index.d.ts +0 -1
- package/esm/grid/index.js +0 -1
- package/esm/grid/index.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/layout/content-container/ContentContainer.js.map +1 -0
- package/esm/layout/content-container/index.d.ts +1 -0
- package/esm/layout/content-container/index.js +2 -0
- package/esm/layout/content-container/index.js.map +1 -0
- package/esm/layout/grid/HGrid.d.ts +49 -0
- package/esm/layout/grid/HGrid.js +64 -0
- package/esm/layout/grid/HGrid.js.map +1 -0
- package/esm/layout/grid/index.d.ts +1 -0
- package/esm/layout/grid/index.js +2 -0
- package/esm/layout/grid/index.js.map +1 -0
- package/esm/layout/stack/Stack.js +1 -1
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/utilities/css.d.ts +8 -4
- package/esm/layout/utilities/css.js +18 -3
- package/esm/layout/utilities/css.js.map +1 -1
- package/package.json +2 -2
- package/src/form/combobox/Input/Input.tsx +6 -0
- package/src/form/combobox/SelectedOptions/SelectedOptions.tsx +3 -0
- package/src/form/combobox/combobox.stories.tsx +10 -2
- package/src/grid/Cell.tsx +4 -0
- package/src/grid/Grid.tsx +4 -0
- package/src/grid/index.ts +0 -4
- package/src/index.ts +2 -0
- package/src/layout/content-container/index.ts +4 -0
- package/src/layout/grid/HGrid.tsx +101 -0
- package/src/layout/grid/h-grid.stories.tsx +102 -0
- package/src/layout/grid/index.ts +1 -0
- package/src/layout/stack/Stack.tsx +5 -5
- package/src/layout/utilities/css.ts +38 -16
- package/esm/grid/ContentContainer.js.map +0 -1
- /package/cjs/{grid → layout/content-container}/ContentContainer.js +0 -0
- /package/esm/{grid → layout/content-container}/ContentContainer.d.ts +0 -0
- /package/esm/{grid → layout/content-container}/ContentContainer.js +0 -0
- /package/src/{grid → layout/content-container}/ContentContainer.tsx +0 -0
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,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,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,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,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,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,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,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentContainer.js","sourceRoot":"","sources":["../../../src/layout/content-container/ContentContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,MAAM,MAAM,CAAC;AAStB,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAGxC,CAAC,EAAsB,EAAE,GAAG,EAAE,EAAE;QAA/B,EAAE,SAAS,OAAW,EAAN,IAAI,cAApB,aAAsB,CAAF;IAAY,OAAA,CACjC,2CACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,yBAAyB,EAAE,SAAS,CAAC,IAC/C,IAAI,EACR,CACH,CAAA;CAAA,CAAC,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ContentContainer, type ContentContainerProps, } from "./ContentContainer";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layout/content-container/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,gBAAgB,GAE5B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from "react";
|
|
2
|
+
import { ResponsiveProp, SpacingScale } from "../utilities/css";
|
|
3
|
+
export interface HGridProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* Number of columns to display. Can be a number, a string with a unit or tokens for spesific breakpoints.
|
|
7
|
+
* Sets `grid-template-columns`, so `fr`, `minmax` etc. works.
|
|
8
|
+
* @example
|
|
9
|
+
* columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}
|
|
10
|
+
* @example
|
|
11
|
+
* columns={3}
|
|
12
|
+
* @example
|
|
13
|
+
* columns="repeat(3, minmax(0, 1fr))"
|
|
14
|
+
*/
|
|
15
|
+
columns?: ResponsiveProp<number | string>;
|
|
16
|
+
/** Spacing between columns. Based on spacing-tokens.
|
|
17
|
+
* @example
|
|
18
|
+
* gap="6"
|
|
19
|
+
* gap={{ sm: "2", md: "2", lg: "6", xl: "6"}}
|
|
20
|
+
*/
|
|
21
|
+
gap?: ResponsiveProp<SpacingScale>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Horizontal Grid Primitive with dynamic columns and gap based on breakpoints.
|
|
25
|
+
*
|
|
26
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/hgrid)
|
|
27
|
+
* @see 🏷️ {@link HGridProps}
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* <HGrid gap="6" columns={3}>
|
|
31
|
+
* <div />
|
|
32
|
+
* <div />
|
|
33
|
+
* <div />
|
|
34
|
+
* </HGrid>
|
|
35
|
+
* @example
|
|
36
|
+
* <HGrid gap={{xs: "2", md: "6"}} columns={3}>
|
|
37
|
+
* <div />
|
|
38
|
+
* <div />
|
|
39
|
+
* <div />
|
|
40
|
+
* </HGrid>
|
|
41
|
+
* @example
|
|
42
|
+
* <HGrid gap="6" columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}>
|
|
43
|
+
* <div />
|
|
44
|
+
* <div />
|
|
45
|
+
* <div />
|
|
46
|
+
* </HGrid>
|
|
47
|
+
*/
|
|
48
|
+
export declare const HGrid: React.ForwardRefExoticComponent<HGridProps & React.RefAttributes<HTMLDivElement>>;
|
|
49
|
+
export default HGrid;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { getResponsiveProps, getResponsiveValue, } from "../utilities/css";
|
|
15
|
+
/**
|
|
16
|
+
* Horizontal Grid Primitive with dynamic columns and gap based on breakpoints.
|
|
17
|
+
*
|
|
18
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/hgrid)
|
|
19
|
+
* @see 🏷️ {@link HGridProps}
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <HGrid gap="6" columns={3}>
|
|
23
|
+
* <div />
|
|
24
|
+
* <div />
|
|
25
|
+
* <div />
|
|
26
|
+
* </HGrid>
|
|
27
|
+
* @example
|
|
28
|
+
* <HGrid gap={{xs: "2", md: "6"}} columns={3}>
|
|
29
|
+
* <div />
|
|
30
|
+
* <div />
|
|
31
|
+
* <div />
|
|
32
|
+
* </HGrid>
|
|
33
|
+
* @example
|
|
34
|
+
* <HGrid gap="6" columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}>
|
|
35
|
+
* <div />
|
|
36
|
+
* <div />
|
|
37
|
+
* <div />
|
|
38
|
+
* </HGrid>
|
|
39
|
+
*/
|
|
40
|
+
export const HGrid = forwardRef((_a, ref) => {
|
|
41
|
+
var { className, columns, gap, style } = _a, rest = __rest(_a, ["className", "columns", "gap", "style"]);
|
|
42
|
+
const styles = Object.assign(Object.assign(Object.assign({}, style), getResponsiveProps(`hgrid`, "gap", "spacing", gap)), getResponsiveValue(`hgrid`, "columns", formatGrid(columns)));
|
|
43
|
+
return (React.createElement("div", Object.assign({}, rest, { ref: ref, className: cl("navds-hgrid", className), style: styles })));
|
|
44
|
+
});
|
|
45
|
+
function formatGrid(props) {
|
|
46
|
+
if (!props) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
if (typeof props === "string" || typeof props === "number") {
|
|
50
|
+
return getColumnValue(props);
|
|
51
|
+
}
|
|
52
|
+
return Object.fromEntries(Object.entries(props).map(([breakpointToken, columnValue]) => [
|
|
53
|
+
breakpointToken,
|
|
54
|
+
getColumnValue(columnValue),
|
|
55
|
+
]));
|
|
56
|
+
}
|
|
57
|
+
const getColumnValue = (prop) => {
|
|
58
|
+
if (typeof prop === "number") {
|
|
59
|
+
return `repeat(${prop}, minmax(0, 1fr))`;
|
|
60
|
+
}
|
|
61
|
+
return prop;
|
|
62
|
+
};
|
|
63
|
+
export default HGrid;
|
|
64
|
+
//# sourceMappingURL=HGrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HGrid.js","sourceRoot":"","sources":["../../../src/layout/grid/HGrid.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,kBAAkB,CAAC;AAsB1B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAC7B,CAAC,EAA2C,EAAE,GAAG,EAAE,EAAE;QAApD,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,OAAW,EAAN,IAAI,cAAzC,wCAA2C,CAAF;IACxC,MAAM,MAAM,iDACP,KAAK,GACL,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,GAClD,kBAAkB,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAC/D,CAAC;IAEF,OAAO,CACL,6CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,EACvC,KAAK,EAAE,MAAM,IACb,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,SAAS,UAAU,CACjB,KAAuC;IAEvC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC1D,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;KAC9B;IAED,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC;QAC5D,eAAe;QACf,cAAc,CAAC,WAAW,CAAC;KAC5B,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,CAAC,IAAqB,EAAE,EAAE;IAC/C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,UAAU,IAAI,mBAAmB,CAAC;KAC1C;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HGrid, type HGridProps } from "./HGrid";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layout/grid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAmB,MAAM,SAAS,CAAC"}
|
|
@@ -14,7 +14,7 @@ import React, { forwardRef } from "react";
|
|
|
14
14
|
import { getResponsiveProps, } from "../utilities/css";
|
|
15
15
|
export const Stack = forwardRef((_a, ref) => {
|
|
16
16
|
var { as: Component = "div", className, align, justify, wrap = true, gap, style: _style, direction } = _a, rest = __rest(_a, ["as", "className", "align", "justify", "wrap", "gap", "style", "direction"]);
|
|
17
|
-
const style = Object.assign(Object.assign({ "--
|
|
17
|
+
const style = Object.assign(Object.assign(Object.assign({}, _style), { "--__ac-stack-direction": direction, "--__ac-stack-align": align, "--__ac-stack-justify": justify, "--__ac-stack-wrap": wrap ? "wrap" : "nowrap" }), getResponsiveProps(`stack`, "gap", "spacing", gap));
|
|
18
18
|
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, style: style, className: cl("navds-stack", className, {
|
|
19
19
|
"navds-vstack": direction === "column",
|
|
20
20
|
"navds-hstack": direction === "row",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stack.js","sourceRoot":"","sources":["../../../src/layout/stack/Stack.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAE1D,OAAO,EACL,kBAAkB,GAGnB,MAAM,kBAAkB,CAAC;AA+B1B,MAAM,CAAC,MAAM,KAAK,GAChB,UAAU,CACR,CACE,EAUC,EACD,GAAG,EACH,EAAE;QAZF,EACE,EAAE,EAAE,SAAS,GAAG,KAAK,EACrB,SAAS,EACT,KAAK,EACL,OAAO,EACP,IAAI,GAAG,IAAI,EACX,GAAG,EACH,KAAK,EAAE,MAAM,EACb,SAAS,OAEV,EADI,IAAI,cATT,4EAUC,CADQ;IAIT,MAAM,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"Stack.js","sourceRoot":"","sources":["../../../src/layout/stack/Stack.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAE1D,OAAO,EACL,kBAAkB,GAGnB,MAAM,kBAAkB,CAAC;AA+B1B,MAAM,CAAC,MAAM,KAAK,GAChB,UAAU,CACR,CACE,EAUC,EACD,GAAG,EACH,EAAE;QAZF,EACE,EAAE,EAAE,SAAS,GAAG,KAAK,EACrB,SAAS,EACT,KAAK,EACL,OAAO,EACP,IAAI,GAAG,IAAI,EACX,GAAG,EACH,KAAK,EAAE,MAAM,EACb,SAAS,OAEV,EADI,IAAI,cATT,4EAUC,CADQ;IAIT,MAAM,KAAK,GAAG,8CACT,MAAM,KACT,wBAAwB,EAAE,SAAS,EACnC,oBAAoB,EAAE,KAAK,EAC3B,sBAAsB,EAAE,OAAO,EAC/B,mBAAmB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,KAC1C,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAC/B,CAAC;IAEzB,OAAO,CACL,oBAAC,SAAS,oBACJ,IAAI,IACR,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,SAAS,EAAE;YACtC,cAAc,EAAE,SAAS,KAAK,QAAQ;YACtC,cAAc,EAAE,SAAS,KAAK,KAAK;SACpC,CAAC,IACF,CACH,CAAC;AACJ,CAAC,CACF,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export type BreakpointsAlias = "xs" | "sm" | "md" | "lg" | "xl";
|
|
2
2
|
export type SpacingScale = "0" | "05" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "14" | "16" | "18" | "20" | "24" | "32";
|
|
3
|
-
|
|
3
|
+
type ResponsivePropConfig<T = string> = {
|
|
4
4
|
[Breakpoint in BreakpointsAlias]?: T;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type ResponsiveProp<T> = T | ResponsivePropConfig<T>;
|
|
7
|
+
export type ResponsiveValue<T = string> = undefined | ResponsiveProp<T>;
|
|
8
|
+
export declare function getResponsiveProps<T = string>(componentName: string, componentProp: string, tokenSubgroup: string, responsiveProp?: ResponsiveProp<T>): {
|
|
9
9
|
[x: string]: string;
|
|
10
10
|
};
|
|
11
|
+
export declare function getResponsiveValue<T = string>(componentName: string, componentProp: string, responsiveProp?: ResponsiveValue<T>): {
|
|
12
|
+
[k: string]: T;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
export function getResponsiveProps(componentName, componentProp, tokenSubgroup, responsiveProp) {
|
|
2
|
-
if (!responsiveProp)
|
|
2
|
+
if (!responsiveProp) {
|
|
3
3
|
return {};
|
|
4
|
+
}
|
|
4
5
|
if (typeof responsiveProp === "string") {
|
|
5
6
|
return {
|
|
6
|
-
[`--
|
|
7
|
+
[`--__ac-${componentName}-${componentProp}-xs`]: `var(--a-${tokenSubgroup}-${responsiveProp})`,
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
return Object.fromEntries(Object.entries(responsiveProp).map(([breakpointAlias, aliasOrScale]) => [
|
|
10
|
-
`--
|
|
11
|
+
`--__ac-${componentName}-${componentProp}-${breakpointAlias}`,
|
|
11
12
|
`var(--a-${tokenSubgroup}-${aliasOrScale})`,
|
|
12
13
|
]));
|
|
13
14
|
}
|
|
15
|
+
export function getResponsiveValue(componentName, componentProp, responsiveProp) {
|
|
16
|
+
if (!responsiveProp) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
if (typeof responsiveProp === "string") {
|
|
20
|
+
return {
|
|
21
|
+
[`--__ac-${componentName}-${componentProp}-xs`]: responsiveProp,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return Object.fromEntries(Object.entries(responsiveProp).map(([breakpointAlias, responsiveValue]) => [
|
|
25
|
+
`--__ac-${componentName}-${componentProp}-${breakpointAlias}`,
|
|
26
|
+
responsiveValue,
|
|
27
|
+
]));
|
|
28
|
+
}
|
|
14
29
|
//# sourceMappingURL=css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../../src/layout/utilities/css.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../../src/layout/utilities/css.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,kBAAkB,CAChC,aAAqB,EACrB,aAAqB,EACrB,aAAqB,EACrB,cAAkC;IAElC,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACtC,OAAO;YACL,CAAC,UAAU,aAAa,IAAI,aAAa,KAAK,CAAC,EAAE,WAAW,aAAa,IAAI,cAAc,GAAG;SAC/F,CAAC;KACH;IAED,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC;QACtE,UAAU,aAAa,IAAI,aAAa,IAAI,eAAe,EAAE;QAC7D,WAAW,aAAa,IAAI,YAAY,GAAG;KAC5C,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,aAAqB,EACrB,aAAqB,EACrB,cAAmC;IAEnC,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACtC,OAAO;YACL,CAAC,UAAU,aAAa,IAAI,aAAa,KAAK,CAAC,EAAE,cAAc;SAChE,CAAC;KACH;IAED,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,EAAE,EAAE,CAAC;QACzE,UAAU,aAAa,IAAI,aAAa,IAAI,eAAe,EAAE;QAC7D,eAAe;KAChB,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.1",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@floating-ui/react": "0.24.1",
|
|
41
|
-
"@navikt/aksel-icons": "^4.
|
|
41
|
+
"@navikt/aksel-icons": "^4.11.1",
|
|
42
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
43
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
44
44
|
"clsx": "^1.2.1",
|
|
@@ -37,6 +37,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
37
37
|
ariaDescribedBy,
|
|
38
38
|
moveFocusToInput,
|
|
39
39
|
moveFocusToEnd,
|
|
40
|
+
setFilteredOptionsIndex,
|
|
40
41
|
shouldAutocomplete,
|
|
41
42
|
} = useFilteredOptionsContext();
|
|
42
43
|
|
|
@@ -139,6 +140,10 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
139
140
|
[filteredOptions.length, onChange, toggleIsListOpen]
|
|
140
141
|
);
|
|
141
142
|
|
|
143
|
+
const onBlur = () => {
|
|
144
|
+
setFilteredOptionsIndex(-1);
|
|
145
|
+
};
|
|
146
|
+
|
|
142
147
|
return (
|
|
143
148
|
<input
|
|
144
149
|
{...rest}
|
|
@@ -148,6 +153,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
148
153
|
onChange={onChangeHandler}
|
|
149
154
|
type="text"
|
|
150
155
|
role="combobox"
|
|
156
|
+
onBlur={onBlur}
|
|
151
157
|
onKeyUp={handleKeyUp}
|
|
152
158
|
onKeyDown={handleKeyDown}
|
|
153
159
|
aria-controls={`${inputProps.id}-filtered-options`}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Chips } from "../../..";
|
|
3
3
|
import { useSelectedOptionsContext } from "./selectedOptionsContext";
|
|
4
|
+
import { useInputContext } from "../Input/inputContext";
|
|
4
5
|
|
|
5
6
|
interface SelectedOptionsProps {
|
|
6
7
|
selectedOptions?: string[];
|
|
@@ -10,10 +11,12 @@ interface SelectedOptionsProps {
|
|
|
10
11
|
|
|
11
12
|
const Option = ({ option }: { option: string }) => {
|
|
12
13
|
const { isMultiSelect, removeSelectedOption } = useSelectedOptionsContext();
|
|
14
|
+
const { focusInput } = useInputContext();
|
|
13
15
|
|
|
14
16
|
const onClick = (e) => {
|
|
15
17
|
e.stopPropagation();
|
|
16
18
|
removeSelectedOption(option);
|
|
19
|
+
focusInput();
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
if (!isMultiSelect) {
|
|
@@ -365,12 +365,20 @@ export const RemoveSelectedMultiSelectTest = {
|
|
|
365
365
|
await sleep(250);
|
|
366
366
|
userEvent.keyboard("{Enter}");
|
|
367
367
|
await sleep(250);
|
|
368
|
-
userEvent.keyboard("{Escape}");
|
|
369
|
-
await sleep(250);
|
|
370
368
|
|
|
371
369
|
const appleSlett = canvas.getByLabelText("apple slett");
|
|
370
|
+
appleSlett.focus();
|
|
371
|
+
await sleep(250);
|
|
372
372
|
userEvent.click(appleSlett);
|
|
373
373
|
await sleep(250);
|
|
374
|
+
const appleOption = canvas.getByRole("option", {
|
|
375
|
+
name: "apple",
|
|
376
|
+
selected: false,
|
|
377
|
+
});
|
|
378
|
+
expect(appleOption).toBeVisible();
|
|
379
|
+
userEvent.keyboard("{Escape}");
|
|
380
|
+
await sleep(250);
|
|
381
|
+
expect(appleOption).not.toBeVisible();
|
|
374
382
|
|
|
375
383
|
const bananaSlett = canvas.getByLabelText("banana slett");
|
|
376
384
|
expect(bananaSlett).toBeInTheDocument();
|
package/src/grid/Cell.tsx
CHANGED
|
@@ -25,6 +25,10 @@ export interface CellProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
25
25
|
lg?: Column;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use <HGrid /> instead. <Grid /> will be removed in the future.
|
|
30
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/hgrid)
|
|
31
|
+
*/
|
|
28
32
|
export const Cell = forwardRef<HTMLDivElement, CellProps>(
|
|
29
33
|
({ children, xs, sm, md, lg, className, ...rest }, ref) => {
|
|
30
34
|
return (
|
package/src/grid/Grid.tsx
CHANGED
|
@@ -8,6 +8,10 @@ export interface GridProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use <HGrid /> instead. <Grid /> will be removed in the future.
|
|
13
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/hgrid)
|
|
14
|
+
*/
|
|
11
15
|
export const Grid = forwardRef<HTMLDivElement, GridProps>(
|
|
12
16
|
({ children, className, ...rest }, ref) => (
|
|
13
17
|
<div ref={ref} className={cl("navds-grid", className)} {...rest}>
|
package/src/grid/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { forwardRef, HTMLAttributes } from "react";
|
|
2
|
+
import cl from "clsx";
|
|
3
|
+
import {
|
|
4
|
+
getResponsiveProps,
|
|
5
|
+
getResponsiveValue,
|
|
6
|
+
ResponsiveProp,
|
|
7
|
+
SpacingScale,
|
|
8
|
+
} from "../utilities/css";
|
|
9
|
+
|
|
10
|
+
export interface HGridProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Number of columns to display. Can be a number, a string with a unit or tokens for spesific breakpoints.
|
|
14
|
+
* Sets `grid-template-columns`, so `fr`, `minmax` etc. works.
|
|
15
|
+
* @example
|
|
16
|
+
* columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}
|
|
17
|
+
* @example
|
|
18
|
+
* columns={3}
|
|
19
|
+
* @example
|
|
20
|
+
* columns="repeat(3, minmax(0, 1fr))"
|
|
21
|
+
*/
|
|
22
|
+
columns?: ResponsiveProp<number | string>;
|
|
23
|
+
/** Spacing between columns. Based on spacing-tokens.
|
|
24
|
+
* @example
|
|
25
|
+
* gap="6"
|
|
26
|
+
* gap={{ sm: "2", md: "2", lg: "6", xl: "6"}}
|
|
27
|
+
*/
|
|
28
|
+
gap?: ResponsiveProp<SpacingScale>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Horizontal Grid Primitive with dynamic columns and gap based on breakpoints.
|
|
32
|
+
*
|
|
33
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/hgrid)
|
|
34
|
+
* @see 🏷️ {@link HGridProps}
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* <HGrid gap="6" columns={3}>
|
|
38
|
+
* <div />
|
|
39
|
+
* <div />
|
|
40
|
+
* <div />
|
|
41
|
+
* </HGrid>
|
|
42
|
+
* @example
|
|
43
|
+
* <HGrid gap={{xs: "2", md: "6"}} columns={3}>
|
|
44
|
+
* <div />
|
|
45
|
+
* <div />
|
|
46
|
+
* <div />
|
|
47
|
+
* </HGrid>
|
|
48
|
+
* @example
|
|
49
|
+
* <HGrid gap="6" columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}>
|
|
50
|
+
* <div />
|
|
51
|
+
* <div />
|
|
52
|
+
* <div />
|
|
53
|
+
* </HGrid>
|
|
54
|
+
*/
|
|
55
|
+
export const HGrid = forwardRef<HTMLDivElement, HGridProps>(
|
|
56
|
+
({ className, columns, gap, style, ...rest }, ref) => {
|
|
57
|
+
const styles: React.CSSProperties = {
|
|
58
|
+
...style,
|
|
59
|
+
...getResponsiveProps(`hgrid`, "gap", "spacing", gap),
|
|
60
|
+
...getResponsiveValue(`hgrid`, "columns", formatGrid(columns)),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
{...rest}
|
|
66
|
+
ref={ref}
|
|
67
|
+
className={cl("navds-hgrid", className)}
|
|
68
|
+
style={styles}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
function formatGrid(
|
|
75
|
+
props?: ResponsiveProp<number | string>
|
|
76
|
+
): ResponsiveProp<number | string> {
|
|
77
|
+
if (!props) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (typeof props === "string" || typeof props === "number") {
|
|
82
|
+
return getColumnValue(props);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return Object.fromEntries(
|
|
86
|
+
Object.entries(props).map(([breakpointToken, columnValue]) => [
|
|
87
|
+
breakpointToken,
|
|
88
|
+
getColumnValue(columnValue),
|
|
89
|
+
])
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const getColumnValue = (prop: number | string) => {
|
|
94
|
+
if (typeof prop === "number") {
|
|
95
|
+
return `repeat(${prop}, minmax(0, 1fr))`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return prop;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default HGrid;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { HGrid } from ".";
|
|
3
|
+
|
|
4
|
+
const columnsVariants = {
|
|
5
|
+
Number: "columnNumber",
|
|
6
|
+
String: "columnString",
|
|
7
|
+
Object: "columnObject",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: "ds-react/HGrid",
|
|
12
|
+
component: HGrid,
|
|
13
|
+
parameters: {
|
|
14
|
+
layout: "fullscreen",
|
|
15
|
+
},
|
|
16
|
+
argTypes: {
|
|
17
|
+
columnsType: {
|
|
18
|
+
defaultValue: Object.keys(columnsVariants)[0],
|
|
19
|
+
options: Object.keys(columnsVariants),
|
|
20
|
+
control: { type: "radio" },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/* const getColumnsProp = () */
|
|
26
|
+
|
|
27
|
+
export const Default = {
|
|
28
|
+
render: (props) => (
|
|
29
|
+
<HGrid
|
|
30
|
+
gap={props?.gap ?? 4}
|
|
31
|
+
columns={props[columnsVariants[props.columnsType]]}
|
|
32
|
+
>
|
|
33
|
+
<Placeholder text="1" />
|
|
34
|
+
<Placeholder text="2" />
|
|
35
|
+
<Placeholder text="3" />
|
|
36
|
+
<Placeholder text="4" />
|
|
37
|
+
</HGrid>
|
|
38
|
+
),
|
|
39
|
+
args: {
|
|
40
|
+
columnNumber: 4,
|
|
41
|
+
columnObject: { xs: 1, md: 4 },
|
|
42
|
+
columnString: "repeat(3, minmax(0, 1fr))",
|
|
43
|
+
gap: "4",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Gap = {
|
|
48
|
+
render: () => (
|
|
49
|
+
<HGrid gap="6">
|
|
50
|
+
<Placeholder text="1" />
|
|
51
|
+
<Placeholder text="2" />
|
|
52
|
+
<Placeholder text="3" />
|
|
53
|
+
<Placeholder text="4" />
|
|
54
|
+
</HGrid>
|
|
55
|
+
),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const DynamicGap = {
|
|
59
|
+
render: () => (
|
|
60
|
+
<HGrid gap={{ xs: "2", md: "8" }}>
|
|
61
|
+
<Placeholder text="1" />
|
|
62
|
+
<Placeholder text="2" />
|
|
63
|
+
<Placeholder text="3" />
|
|
64
|
+
<Placeholder text="4" />
|
|
65
|
+
</HGrid>
|
|
66
|
+
),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const Columns = {
|
|
70
|
+
render: () => (
|
|
71
|
+
<HGrid gap="4" columns={2}>
|
|
72
|
+
<Placeholder text="1" />
|
|
73
|
+
<Placeholder text="2" />
|
|
74
|
+
<Placeholder text="3" />
|
|
75
|
+
<Placeholder text="4" />
|
|
76
|
+
</HGrid>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const DynamicColumns = {
|
|
81
|
+
render: () => (
|
|
82
|
+
<HGrid gap="4" columns={{ sm: "1fr 5fr", md: "2fr 2fr" }}>
|
|
83
|
+
<Placeholder text="1" />
|
|
84
|
+
<Placeholder text="2" />
|
|
85
|
+
</HGrid>
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function Placeholder({ text }) {
|
|
90
|
+
return (
|
|
91
|
+
<div
|
|
92
|
+
style={{
|
|
93
|
+
background: "var(--a-deepblue-900)",
|
|
94
|
+
height: "5rem",
|
|
95
|
+
width: "auto",
|
|
96
|
+
color: "white",
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{text}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HGrid, type HGridProps } from "./HGrid";
|
|
@@ -53,12 +53,12 @@ export const Stack: OverridableComponent<StackProps, HTMLDivElement> =
|
|
|
53
53
|
ref
|
|
54
54
|
) => {
|
|
55
55
|
const style = {
|
|
56
|
-
"--ac-stack-direction": direction,
|
|
57
|
-
"--ac-stack-align": align,
|
|
58
|
-
"--ac-stack-justify": justify,
|
|
59
|
-
"--ac-stack-wrap": wrap ? "wrap" : "nowrap",
|
|
60
|
-
...getResponsiveProps(`stack`, "gap", "spacing", gap),
|
|
61
56
|
..._style,
|
|
57
|
+
"--__ac-stack-direction": direction,
|
|
58
|
+
"--__ac-stack-align": align,
|
|
59
|
+
"--__ac-stack-justify": justify,
|
|
60
|
+
"--__ac-stack-wrap": wrap ? "wrap" : "nowrap",
|
|
61
|
+
...getResponsiveProps(`stack`, "gap", "spacing", gap),
|
|
62
62
|
} as React.CSSProperties;
|
|
63
63
|
|
|
64
64
|
return (
|