@navikt/ds-react 6.11.0 → 6.12.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.
Files changed (123) hide show
  1. package/cjs/alert/Alert.d.ts +5 -0
  2. package/cjs/alert/Alert.js +5 -3
  3. package/cjs/alert/Alert.js.map +1 -1
  4. package/cjs/layout/base/BasePrimitive.d.ts +35 -3
  5. package/cjs/layout/base/BasePrimitive.js +33 -3
  6. package/cjs/layout/base/BasePrimitive.js.map +1 -1
  7. package/cjs/layout/base/PrimitiveAsChildProps.d.ts +41 -0
  8. package/cjs/layout/base/PrimitiveAsChildProps.js +3 -0
  9. package/cjs/layout/base/PrimitiveAsChildProps.js.map +1 -0
  10. package/cjs/layout/box/Box.d.ts +5 -32
  11. package/cjs/layout/box/Box.js +15 -4
  12. package/cjs/layout/box/Box.js.map +1 -1
  13. package/cjs/layout/grid/HGrid.d.ts +7 -5
  14. package/cjs/layout/grid/HGrid.js +7 -2
  15. package/cjs/layout/grid/HGrid.js.map +1 -1
  16. package/cjs/layout/stack/HStack.d.ts +2 -1
  17. package/cjs/layout/stack/HStack.js.map +1 -1
  18. package/cjs/layout/stack/Stack.d.ts +8 -5
  19. package/cjs/layout/stack/Stack.js +10 -5
  20. package/cjs/layout/stack/Stack.js.map +1 -1
  21. package/cjs/layout/stack/VStack.d.ts +2 -1
  22. package/cjs/layout/stack/VStack.js.map +1 -1
  23. package/cjs/layout/utilities/css.js +3 -0
  24. package/cjs/layout/utilities/css.js.map +1 -1
  25. package/cjs/toggle-group/parts/useToggleItem.js +1 -1
  26. package/cjs/toggle-group/parts/useToggleItem.js.map +1 -1
  27. package/cjs/util/types/AsChildProps.d.ts +1 -0
  28. package/esm/alert/Alert.d.ts +5 -0
  29. package/esm/alert/Alert.js +5 -3
  30. package/esm/alert/Alert.js.map +1 -1
  31. package/esm/layout/base/BasePrimitive.d.ts +35 -3
  32. package/esm/layout/base/BasePrimitive.js +32 -2
  33. package/esm/layout/base/BasePrimitive.js.map +1 -1
  34. package/esm/layout/base/PrimitiveAsChildProps.d.ts +41 -0
  35. package/esm/layout/base/PrimitiveAsChildProps.js +2 -0
  36. package/esm/layout/base/PrimitiveAsChildProps.js.map +1 -0
  37. package/esm/layout/box/Box.d.ts +5 -32
  38. package/esm/layout/box/Box.js +15 -4
  39. package/esm/layout/box/Box.js.map +1 -1
  40. package/esm/layout/grid/HGrid.d.ts +7 -5
  41. package/esm/layout/grid/HGrid.js +7 -2
  42. package/esm/layout/grid/HGrid.js.map +1 -1
  43. package/esm/layout/stack/HStack.d.ts +2 -1
  44. package/esm/layout/stack/HStack.js.map +1 -1
  45. package/esm/layout/stack/Stack.d.ts +8 -5
  46. package/esm/layout/stack/Stack.js +10 -5
  47. package/esm/layout/stack/Stack.js.map +1 -1
  48. package/esm/layout/stack/VStack.d.ts +2 -1
  49. package/esm/layout/stack/VStack.js.map +1 -1
  50. package/esm/layout/utilities/css.js +3 -0
  51. package/esm/layout/utilities/css.js.map +1 -1
  52. package/esm/toggle-group/parts/useToggleItem.js +1 -1
  53. package/esm/toggle-group/parts/useToggleItem.js.map +1 -1
  54. package/esm/util/types/AsChildProps.d.ts +1 -0
  55. package/package.json +3 -3
  56. package/src/alert/Alert.tsx +23 -2
  57. package/src/layout/base/BasePrimitive.tsx +84 -2
  58. package/src/layout/base/PrimitiveAsChildProps.ts +42 -0
  59. package/src/layout/box/Box.tsx +64 -81
  60. package/src/layout/grid/HGrid.tsx +73 -45
  61. package/src/layout/stack/HStack.tsx +2 -1
  62. package/src/layout/stack/Stack.tsx +80 -62
  63. package/src/layout/stack/VStack.tsx +3 -1
  64. package/src/layout/utilities/css.ts +3 -0
  65. package/src/toggle-group/parts/useToggleItem.ts +4 -1
  66. package/src/util/types/AsChildProps.ts +1 -0
  67. package/cjs/layout/sidemal-test/AvatarPanel.d.ts +0 -4
  68. package/cjs/layout/sidemal-test/AvatarPanel.js +0 -19
  69. package/cjs/layout/sidemal-test/AvatarPanel.js.map +0 -1
  70. package/cjs/layout/sidemal-test/Content.d.ts +0 -2
  71. package/cjs/layout/sidemal-test/Content.js +0 -67
  72. package/cjs/layout/sidemal-test/Content.js.map +0 -1
  73. package/cjs/layout/sidemal-test/Filter.d.ts +0 -2
  74. package/cjs/layout/sidemal-test/Filter.js +0 -49
  75. package/cjs/layout/sidemal-test/Filter.js.map +0 -1
  76. package/cjs/layout/sidemal-test/Header.d.ts +0 -2
  77. package/cjs/layout/sidemal-test/Header.js +0 -49
  78. package/cjs/layout/sidemal-test/Header.js.map +0 -1
  79. package/cjs/layout/sidemal-test/Intro.d.ts +0 -2
  80. package/cjs/layout/sidemal-test/Intro.js +0 -37
  81. package/cjs/layout/sidemal-test/Intro.js.map +0 -1
  82. package/cjs/layout/sidemal-test/Sidebar.d.ts +0 -4
  83. package/cjs/layout/sidemal-test/Sidebar.js +0 -50
  84. package/cjs/layout/sidemal-test/Sidebar.js.map +0 -1
  85. package/cjs/layout/sidemal-test/content-box/ContentBox.d.ts +0 -8
  86. package/cjs/layout/sidemal-test/content-box/ContentBox.js +0 -66
  87. package/cjs/layout/sidemal-test/content-box/ContentBox.js.map +0 -1
  88. package/cjs/layout/sidemal-test/content-box/index.d.ts +0 -1
  89. package/cjs/layout/sidemal-test/content-box/index.js +0 -9
  90. package/cjs/layout/sidemal-test/content-box/index.js.map +0 -1
  91. package/esm/layout/sidemal-test/AvatarPanel.d.ts +0 -4
  92. package/esm/layout/sidemal-test/AvatarPanel.js +0 -12
  93. package/esm/layout/sidemal-test/AvatarPanel.js.map +0 -1
  94. package/esm/layout/sidemal-test/Content.d.ts +0 -2
  95. package/esm/layout/sidemal-test/Content.js +0 -60
  96. package/esm/layout/sidemal-test/Content.js.map +0 -1
  97. package/esm/layout/sidemal-test/Filter.d.ts +0 -2
  98. package/esm/layout/sidemal-test/Filter.js +0 -22
  99. package/esm/layout/sidemal-test/Filter.js.map +0 -1
  100. package/esm/layout/sidemal-test/Header.d.ts +0 -2
  101. package/esm/layout/sidemal-test/Header.js +0 -42
  102. package/esm/layout/sidemal-test/Header.js.map +0 -1
  103. package/esm/layout/sidemal-test/Intro.d.ts +0 -2
  104. package/esm/layout/sidemal-test/Intro.js +0 -30
  105. package/esm/layout/sidemal-test/Intro.js.map +0 -1
  106. package/esm/layout/sidemal-test/Sidebar.d.ts +0 -4
  107. package/esm/layout/sidemal-test/Sidebar.js +0 -41
  108. package/esm/layout/sidemal-test/Sidebar.js.map +0 -1
  109. package/esm/layout/sidemal-test/content-box/ContentBox.d.ts +0 -8
  110. package/esm/layout/sidemal-test/content-box/ContentBox.js +0 -37
  111. package/esm/layout/sidemal-test/content-box/ContentBox.js.map +0 -1
  112. package/esm/layout/sidemal-test/content-box/index.d.ts +0 -1
  113. package/esm/layout/sidemal-test/content-box/index.js +0 -2
  114. package/esm/layout/sidemal-test/content-box/index.js.map +0 -1
  115. package/src/layout/sidemal-test/AvatarPanel.tsx +0 -27
  116. package/src/layout/sidemal-test/Content.tsx +0 -129
  117. package/src/layout/sidemal-test/Filter.tsx +0 -46
  118. package/src/layout/sidemal-test/Header.tsx +0 -96
  119. package/src/layout/sidemal-test/Intro.tsx +0 -91
  120. package/src/layout/sidemal-test/Sidebar.tsx +0 -77
  121. package/src/layout/sidemal-test/content-box/ContentBox.tsx +0 -46
  122. package/src/layout/sidemal-test/content-box/index.ts +0 -1
  123. package/src/layout/sidemal-test/styling.css +0 -43
@@ -29,6 +29,11 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
29
29
  * @default false
30
30
  */
31
31
  fullWidth?: boolean;
32
+ /**
33
+ * Sets max-width on the content to 43.5rem.
34
+ * @default true
35
+ */
36
+ contentMaxWidth?: boolean;
32
37
  /**
33
38
  * Removes background from Alert.
34
39
  * @default false
@@ -85,6 +90,7 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(
85
90
  variant,
86
91
  size = "medium",
87
92
  fullWidth = false,
93
+ contentMaxWidth = true,
88
94
  inline = false,
89
95
  closeButton = false,
90
96
  onClose,
@@ -109,7 +115,14 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(
109
115
  )}
110
116
  >
111
117
  <Icon variant={variant} className="navds-alert__icon" />
112
- <BodyLong as="div" size={size} className="navds-alert__wrapper">
118
+ <BodyLong
119
+ as="div"
120
+ size={size}
121
+ className={cl(
122
+ "navds-alert__wrapper",
123
+ contentMaxWidth && "navds-alert__wrapper--maxwidth",
124
+ )}
125
+ >
113
126
  {children}
114
127
  </BodyLong>
115
128
  {closeButton && !inline && (
@@ -120,7 +133,15 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(
120
133
  variant="tertiary-neutral"
121
134
  onClick={onClose}
122
135
  type="button"
123
- icon={<XMarkIcon title="Lukk Alert" />}
136
+ icon={
137
+ <XMarkIcon
138
+ title={
139
+ ["error", "warning"].includes(variant)
140
+ ? "Lukk varsel"
141
+ : "Lukk melding"
142
+ }
143
+ />
144
+ }
124
145
  />
125
146
  </div>
126
147
  )}
@@ -4,8 +4,7 @@ import { Slot } from "../../slot/Slot";
4
4
  import { getResponsiveProps, getResponsiveValue } from "../utilities/css";
5
5
  import { ResponsiveProp, SpacingScale } from "../utilities/types";
6
6
 
7
- export interface BasePrimitiveProps {
8
- children: React.ReactElement;
7
+ export type PrimitiveProps = {
9
8
  className?: string;
10
9
  /**
11
10
  * Padding around children.
@@ -40,6 +39,47 @@ export interface BasePrimitiveProps {
40
39
  paddingBlock?: ResponsiveProp<
41
40
  SpacingScale | `${SpacingScale} ${SpacingScale}`
42
41
  >;
42
+ /**
43
+ * Margin around element.
44
+ * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
45
+ * or an object of spacing tokens for different breakpoints.
46
+ * @example
47
+ * margin='4'
48
+ * margin={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
49
+ */
50
+ margin?: ResponsiveProp<SpacingScale>;
51
+ /**
52
+ * Horizontal margin around element.
53
+ * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
54
+ * or an object of spacing tokens for different breakpoints.
55
+ * @example
56
+ * marginInline='4'
57
+ * marginInline='4 5'
58
+ * marginInline={{xs: '0 32', sm: '3', md: '4 5', lg: '5', xl: '6'}}
59
+ */
60
+ marginInline?: ResponsiveProp<
61
+ | SpacingScale
62
+ | `${SpacingScale} ${SpacingScale}`
63
+ | "auto"
64
+ | `auto ${SpacingScale}`
65
+ | `${SpacingScale} auto`
66
+ >;
67
+ /**
68
+ * Vertical margin around element.
69
+ * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
70
+ * or an object of spacing tokens for different breakpoints.
71
+ * @example
72
+ * marginBlock='4'
73
+ * marginBlock='4 5'
74
+ * marginBlock={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
75
+ */
76
+ marginBlock?: ResponsiveProp<
77
+ | SpacingScale
78
+ | `${SpacingScale} ${SpacingScale}`
79
+ | "auto"
80
+ | `auto ${SpacingScale}`
81
+ | `${SpacingScale} auto`
82
+ >;
43
83
  /**
44
84
  * CSS `width`
45
85
  */
@@ -140,6 +180,38 @@ export interface BasePrimitiveProps {
140
180
  * CSS `flex-grow`
141
181
  */
142
182
  flexGrow?: ResponsiveProp<string>;
183
+ };
184
+
185
+ export const PRIMITIVE_PROPS: (keyof PrimitiveProps)[] = [
186
+ "className",
187
+ "padding",
188
+ "paddingInline",
189
+ "paddingBlock",
190
+ "margin",
191
+ "marginInline",
192
+ "marginBlock",
193
+ "width",
194
+ "minWidth",
195
+ "maxWidth",
196
+ "height",
197
+ "minHeight",
198
+ "maxHeight",
199
+ "position",
200
+ "inset",
201
+ "top",
202
+ "right",
203
+ "bottom",
204
+ "left",
205
+ "overflow",
206
+ "overflowX",
207
+ "overflowY",
208
+ "flexBasis",
209
+ "flexGrow",
210
+ "flexShrink",
211
+ ];
212
+
213
+ interface BasePrimitiveProps extends PrimitiveProps {
214
+ children: React.ReactElement;
143
215
  }
144
216
 
145
217
  export const BasePrimitive = ({
@@ -148,6 +220,9 @@ export const BasePrimitive = ({
148
220
  padding,
149
221
  paddingInline,
150
222
  paddingBlock,
223
+ margin,
224
+ marginInline,
225
+ marginBlock,
151
226
  width,
152
227
  minWidth,
153
228
  maxWidth,
@@ -172,6 +247,10 @@ export const BasePrimitive = ({
172
247
  ...getResponsiveProps("r", "p", "spacing", padding),
173
248
  ...getResponsiveProps("r", "pi", "spacing", paddingInline),
174
249
  ...getResponsiveProps("r", "pb", "spacing", paddingBlock),
250
+ /* Margin */
251
+ ...getResponsiveProps("r", "m", "spacing", margin),
252
+ ...getResponsiveProps("r", "mi", "spacing", marginInline),
253
+ ...getResponsiveProps("r", "mb", "spacing", marginBlock),
175
254
  /* Width & height */
176
255
  ...getResponsiveValue("r", "w", width),
177
256
  ...getResponsiveValue("r", "minw", minWidth),
@@ -203,6 +282,9 @@ export const BasePrimitive = ({
203
282
  "navds-r-p": padding,
204
283
  "navds-r-pi": paddingInline,
205
284
  "navds-r-pb": paddingBlock,
285
+ "navds-r-m": margin,
286
+ "navds-r-mi": marginInline,
287
+ "navds-r-mb": marginBlock,
206
288
  "navds-r-w": width,
207
289
  "navds-r-minw": minWidth,
208
290
  "navds-r-maxw": maxWidth,
@@ -0,0 +1,42 @@
1
+ export type PrimitiveAsChildProps =
2
+ | {
3
+ children: React.ReactElement | false | null;
4
+ /**
5
+ * Renders the component and its child as a single element,
6
+ * merging the props of the component with the props of the child.
7
+ * @example
8
+ * ```tsx
9
+ * <Component asChild data-prop>
10
+ * <ChildComponent data-child />
11
+ * </Component>
12
+ *
13
+ * // Renders
14
+ * <div data-prop data-child />
15
+ * ```
16
+ */
17
+ asChild: true;
18
+ /**
19
+ * Implements [OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent)
20
+ *
21
+ * When using asChild, the prop is not allowed as it would have no effect.
22
+ */
23
+ as?: never;
24
+ }
25
+ | {
26
+ children?: React.ReactNode;
27
+ /**
28
+ * Renders the component and its child as a single element,
29
+ * merging the props of the component with the props of the child.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * <Component asChild data-prop>
34
+ * <ChildComponent data-child />
35
+ * </Component>
36
+ *
37
+ * // Renders
38
+ * <div data-prop data-child />
39
+ * ```
40
+ */
41
+ asChild?: false;
42
+ };
@@ -1,6 +1,13 @@
1
1
  import cl from "clsx";
2
2
  import React, { forwardRef } from "react";
3
+ import { Slot } from "../../slot/Slot";
4
+ import { omit } from "../../util";
3
5
  import { OverridableComponent } from "../../util/types";
6
+ import BasePrimitive, {
7
+ PRIMITIVE_PROPS,
8
+ PrimitiveProps,
9
+ } from "../base/BasePrimitive";
10
+ import { PrimitiveAsChildProps } from "../base/PrimitiveAsChildProps";
4
11
  import { getResponsiveProps } from "../utilities/css";
5
12
  import {
6
13
  BackgroundColorToken,
@@ -9,77 +16,45 @@ import {
9
16
  ResponsiveProp,
10
17
  ShadowToken,
11
18
  SpaceDelimitedAttribute,
12
- SpacingScale,
13
19
  SurfaceColorToken,
14
20
  } from "../utilities/types";
15
21
 
16
- export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {
17
- /**
18
- * CSS `background-color` property.
19
- * Accepts a [background/surface color token](https://aksel.nav.no/grunnleggende/styling/design-tokens#afff774dad80).
20
- */
21
- background?: BackgroundColorToken | SurfaceColorToken;
22
- /**
23
- * CSS `border-color` property.
24
- * Accepts a [border color token](https://aksel.nav.no/grunnleggende/styling/design-tokens#adb1767e2f87).
25
- */
26
- borderColor?: BorderColorToken;
27
- /**
28
- * CSS `border-radius` property.
29
- * Accepts a [radius token](https://aksel.nav.no/grunnleggende/styling/design-tokens#6d79c5605d31)
30
- * or an object of radius tokens for different breakpoints.
31
- * @example
32
- * borderRadius='full'
33
- * borderRadius='0 full large small'
34
- * borderRadius={{xs: 'small large', sm: '0', md: 'large', lg: 'full'}}
35
- */
36
- borderRadius?: ResponsiveProp<SpaceDelimitedAttribute<BorderRadiiToken>>;
37
- /**
38
- * CSS `border-width` property. If this is not set there will be no border.
39
- * @example
40
- * borderWidth='2'
41
- * borderWidth='1 2 3 4'
42
- */
43
- borderWidth?: SpaceDelimitedAttribute<"0" | "1" | "2" | "3" | "4" | "5">;
44
- /**
45
- * Padding around children.
46
- * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
47
- * or an object of spacing tokens for different breakpoints.
48
- * @example
49
- * padding='4'
50
- * padding={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
51
- */
52
- padding?: ResponsiveProp<SpacingScale>;
53
- /**
54
- * Horizontal padding around children.
55
- * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
56
- * or an object of spacing tokens for different breakpoints.
57
- * @example
58
- * paddingInline='4'
59
- * paddingInline='4 5'
60
- * paddingInline={{xs: '0 32', sm: '3', md: '4 5', lg: '5', xl: '6'}}
61
- */
62
- paddingInline?: ResponsiveProp<
63
- SpacingScale | `${SpacingScale} ${SpacingScale}`
64
- >;
65
- /**
66
- * Vertical padding around children.
67
- * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
68
- * or an object of spacing tokens for different breakpoints.
69
- * @example
70
- * paddingBlock='4'
71
- * paddingBlock='4 5'
72
- * paddingBlock={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
73
- */
74
- paddingBlock?: ResponsiveProp<
75
- SpacingScale | `${SpacingScale} ${SpacingScale}`
76
- >;
77
- /** Shadow on box. Accepts a shadow token.
78
- * @example
79
- * shadow='small'
80
- */
81
- shadow?: ShadowToken;
82
- }
22
+ export type BoxProps = PrimitiveProps &
23
+ PrimitiveAsChildProps &
24
+ React.HTMLAttributes<HTMLDivElement> & {
25
+ /**
26
+ * CSS `background-color` property.
27
+ * Accepts a [background/surface color token](https://aksel.nav.no/grunnleggende/styling/design-tokens#afff774dad80).
28
+ */
29
+ background?: BackgroundColorToken | SurfaceColorToken;
30
+ /**
31
+ * CSS `border-color` property.
32
+ * Accepts a [border color token](https://aksel.nav.no/grunnleggende/styling/design-tokens#adb1767e2f87).
33
+ */
34
+ borderColor?: BorderColorToken;
35
+ /**
36
+ * CSS `border-radius` property.
37
+ * Accepts a [radius token](https://aksel.nav.no/grunnleggende/styling/design-tokens#6d79c5605d31)
38
+ * or an object of radius tokens for different breakpoints.
39
+ * @example
40
+ * borderRadius='full'
41
+ * borderRadius='0 full large small'
42
+ * borderRadius={{xs: 'small large', sm: '0', md: 'large', lg: 'full'}}
43
+ */
44
+ borderRadius?: ResponsiveProp<SpaceDelimitedAttribute<BorderRadiiToken>>;
45
+ /**
46
+ * CSS `border-width` property. If this is not set there will be no border.
47
+ * @example
48
+ * borderWidth='2'
49
+ * borderWidth='1 2 3 4'
50
+ */
51
+ borderWidth?: SpaceDelimitedAttribute<"0" | "1" | "2" | "3" | "4" | "5">;
52
+ /** Shadow on box. Accepts a shadow token.
53
+ * @example
54
+ * shadow='small'
55
+ */
56
+ shadow?: ShadowToken;
57
+ };
83
58
 
84
59
  /**
85
60
  * Foundational Layout-primitive for generic encapsulation & styling.
@@ -111,17 +86,16 @@ export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {
111
86
  export const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(
112
87
  (
113
88
  {
89
+ children,
90
+ className,
114
91
  as: Component = "div",
115
92
  background,
116
93
  borderColor,
117
94
  borderWidth,
118
95
  borderRadius,
119
- className,
120
- padding,
121
- paddingInline,
122
- paddingBlock,
123
96
  shadow,
124
97
  style: _style,
98
+ asChild,
125
99
  ...rest
126
100
  },
127
101
  ref,
@@ -149,18 +123,27 @@ export const Box: OverridableComponent<BoxProps, HTMLDivElement> = forwardRef(
149
123
  false,
150
124
  ["0"],
151
125
  ),
152
- ...getResponsiveProps("box", "padding", "spacing", padding),
153
- ...getResponsiveProps("box", "padding-inline", "spacing", paddingInline),
154
- ...getResponsiveProps("box", "padding-block", "spacing", paddingBlock),
155
126
  };
156
127
 
128
+ const Comp = asChild ? Slot : Component;
129
+
157
130
  return (
158
- <Component
159
- {...rest}
160
- className={cl("navds-box", className)}
161
- ref={ref}
162
- style={style}
163
- />
131
+ <BasePrimitive {...rest}>
132
+ <Comp
133
+ {...omit(rest, PRIMITIVE_PROPS)}
134
+ ref={ref}
135
+ style={style}
136
+ className={cl("navds-box", className, {
137
+ "navds-box-bg": background,
138
+ "navds-box-border-color": borderColor,
139
+ "navds-box-border-width": borderWidth,
140
+ "navds-box-border-radius": borderRadius,
141
+ "navds-box-shadow": shadow,
142
+ })}
143
+ >
144
+ {children}
145
+ </Comp>
146
+ </BasePrimitive>
164
147
  );
165
148
  },
166
149
  );
@@ -1,34 +1,42 @@
1
1
  import cl from "clsx";
2
- import React, { HTMLAttributes, forwardRef } from "react";
2
+ import React, { forwardRef } from "react";
3
+ import { Slot } from "../../slot/Slot";
4
+ import { OverridableComponent, omit } from "../../util";
5
+ import BasePrimitive, {
6
+ PRIMITIVE_PROPS,
7
+ PrimitiveProps,
8
+ } from "../base/BasePrimitive";
9
+ import { PrimitiveAsChildProps } from "../base/PrimitiveAsChildProps";
3
10
  import { getResponsiveProps, getResponsiveValue } from "../utilities/css";
4
11
  import { ResponsiveProp, SpacingScale } from "../utilities/types";
5
12
 
6
- export interface HGridProps extends HTMLAttributes<HTMLDivElement> {
7
- children: React.ReactNode;
8
- /**
9
- * Number of columns to display. Can be a number, a string, or an object with values for specific breakpoints.
10
- * Sets `grid-template-columns`, so `fr`, `minmax` etc. works.
11
- * @example
12
- * columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}
13
- * columns={3}
14
- * columns="repeat(3, minmax(0, 1fr))"
15
- */
16
- columns?: ResponsiveProp<number | string>;
17
- /**
18
- * Spacing between columns.
19
- * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
20
- * or an object of spacing tokens for different breakpoints.
21
- * @example
22
- * gap="6"
23
- * gap="8 4"
24
- * gap={{ sm: "2", md: "2", lg: "6", xl: "6"}}
25
- */
26
- gap?: ResponsiveProp<SpacingScale | `${SpacingScale} ${SpacingScale}`>;
27
- /**
28
- * Vertical alignment of children. Elements will by default stretch to the height of parent-element.
29
- */
30
- align?: "start" | "center" | "end";
31
- }
13
+ export type HGridProps = PrimitiveProps &
14
+ PrimitiveAsChildProps &
15
+ React.HTMLAttributes<HTMLDivElement> & {
16
+ /**
17
+ * Number of columns to display. Can be a number, a string, or an object with values for specific breakpoints.
18
+ * Sets `grid-template-columns`, so `fr`, `minmax` etc. works.
19
+ * @example
20
+ * columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}
21
+ * columns={3}
22
+ * columns="repeat(3, minmax(0, 1fr))"
23
+ */
24
+ columns?: ResponsiveProp<number | string>;
25
+ /**
26
+ * Spacing between columns.
27
+ * Accepts a [spacing token](https://aksel.nav.no/grunnleggende/styling/design-tokens#0cc9fb32f213)
28
+ * or an object of spacing tokens for different breakpoints.
29
+ * @example
30
+ * gap="6"
31
+ * gap="8 4"
32
+ * gap={{ sm: "2", md: "2", lg: "6", xl: "6"}}
33
+ */
34
+ gap?: ResponsiveProp<SpacingScale | `${SpacingScale} ${SpacingScale}`>;
35
+ /**
36
+ * Vertical alignment of children. Elements will by default stretch to the height of parent-element.
37
+ */
38
+ align?: "start" | "center" | "end";
39
+ };
32
40
  /**
33
41
  * Horizontal Grid Primitive with dynamic columns and gap based on breakpoints.
34
42
  *
@@ -54,25 +62,45 @@ export interface HGridProps extends HTMLAttributes<HTMLDivElement> {
54
62
  * <div />
55
63
  * </HGrid>
56
64
  */
57
- export const HGrid = forwardRef<HTMLDivElement, HGridProps>(
58
- ({ className, columns, gap, style, align, ...rest }, ref) => {
59
- const styles: React.CSSProperties = {
60
- ...style,
61
- "--__ac-hgrid-align": align,
62
- ...getResponsiveProps(`hgrid`, "gap", "spacing", gap),
63
- ...getResponsiveValue(`hgrid`, "columns", formatGrid(columns)),
64
- };
65
+ export const HGrid: OverridableComponent<HGridProps, HTMLDivElement> =
66
+ forwardRef(
67
+ (
68
+ {
69
+ children,
70
+ className,
71
+ as: Component = "div",
72
+ columns,
73
+ gap,
74
+ style,
75
+ align,
76
+ asChild,
77
+ ...rest
78
+ },
79
+ ref,
80
+ ) => {
81
+ const styles: React.CSSProperties = {
82
+ ...style,
83
+ "--__ac-hgrid-align": align,
84
+ ...getResponsiveProps(`hgrid`, "gap", "spacing", gap),
85
+ ...getResponsiveValue(`hgrid`, "columns", formatGrid(columns)),
86
+ };
87
+
88
+ const Comp = asChild ? Slot : Component;
65
89
 
66
- return (
67
- <div
68
- {...rest}
69
- ref={ref}
70
- className={cl("navds-hgrid", className)}
71
- style={styles}
72
- />
73
- );
74
- },
75
- );
90
+ return (
91
+ <BasePrimitive {...rest}>
92
+ <Comp
93
+ {...omit(rest, PRIMITIVE_PROPS)}
94
+ ref={ref}
95
+ className={cl("navds-hgrid", className)}
96
+ style={styles}
97
+ >
98
+ {children}
99
+ </Comp>
100
+ </BasePrimitive>
101
+ );
102
+ },
103
+ );
76
104
 
77
105
  function formatGrid(
78
106
  props?: ResponsiveProp<number | string>,
@@ -1,8 +1,9 @@
1
1
  import React, { forwardRef } from "react";
2
2
  import { OverridableComponent } from "../../util/types";
3
+ import { PrimitiveAsChildProps } from "../base/PrimitiveAsChildProps";
3
4
  import { Stack, StackProps } from "./Stack";
4
5
 
5
- export type HStackProps = Omit<StackProps, "direction">;
6
+ export type HStackProps = PrimitiveAsChildProps & Omit<StackProps, "direction">;
6
7
 
7
8
  /**
8
9
  * Layout-primitive for horizontal flexbox