@navikt/ds-react 6.0.0-alpha.7 → 6.0.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/cjs/date/parts/DateWrapper.js +2 -2
- package/cjs/date/parts/DateWrapper.js.map +1 -1
- package/cjs/form/error-summary/ErrorSummary.d.ts +3 -9
- package/cjs/form/error-summary/ErrorSummary.js +9 -4
- package/cjs/form/error-summary/ErrorSummary.js.map +1 -1
- package/cjs/form/error-summary/ErrorSummaryItem.d.ts +1 -1
- package/cjs/form/error-summary/ErrorSummaryItem.js +1 -2
- package/cjs/form/error-summary/ErrorSummaryItem.js.map +1 -1
- package/cjs/form/search/Search.d.ts +1 -1
- package/cjs/form/search/Search.js +1 -1
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/modal/Modal.context.d.ts +9 -0
- package/cjs/modal/Modal.context.js +10 -0
- package/cjs/modal/Modal.context.js.map +1 -0
- package/cjs/modal/Modal.js +3 -6
- package/cjs/modal/Modal.js.map +1 -1
- package/cjs/modal/ModalHeader.js +2 -6
- package/cjs/modal/ModalHeader.js.map +1 -1
- package/cjs/modal/types.d.ts +24 -3
- package/cjs/panel/Panel.d.ts +9 -16
- package/cjs/panel/Panel.js +6 -16
- package/cjs/panel/Panel.js.map +1 -1
- package/cjs/popover/Popover.js +2 -2
- package/cjs/popover/Popover.js.map +1 -1
- package/cjs/table/types.d.ts +1 -1
- package/cjs/tooltip/Tooltip.js +3 -3
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/cjs/util/create-context.d.ts +2 -5
- package/cjs/util/create-context.js +9 -5
- package/cjs/util/create-context.js.map +1 -1
- package/cjs/util/types/OverridableComponent.d.ts +1 -1
- package/esm/date/parts/DateWrapper.js +3 -3
- package/esm/date/parts/DateWrapper.js.map +1 -1
- package/esm/form/error-summary/ErrorSummary.d.ts +3 -9
- package/esm/form/error-summary/ErrorSummary.js +10 -5
- package/esm/form/error-summary/ErrorSummary.js.map +1 -1
- package/esm/form/error-summary/ErrorSummaryItem.d.ts +1 -1
- package/esm/form/error-summary/ErrorSummaryItem.js +1 -2
- package/esm/form/error-summary/ErrorSummaryItem.js.map +1 -1
- package/esm/form/search/Search.d.ts +1 -1
- package/esm/form/search/Search.js +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/modal/Modal.context.d.ts +9 -0
- package/esm/modal/Modal.context.js +6 -0
- package/esm/modal/Modal.context.js.map +1 -0
- package/esm/modal/Modal.js +3 -6
- package/esm/modal/Modal.js.map +1 -1
- package/esm/modal/ModalHeader.js +3 -7
- package/esm/modal/ModalHeader.js.map +1 -1
- package/esm/modal/types.d.ts +24 -3
- package/esm/panel/Panel.d.ts +9 -16
- package/esm/panel/Panel.js +6 -16
- package/esm/panel/Panel.js.map +1 -1
- package/esm/popover/Popover.js +2 -2
- package/esm/popover/Popover.js.map +1 -1
- package/esm/table/types.d.ts +1 -1
- package/esm/tooltip/Tooltip.js +4 -4
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/util/create-context.d.ts +2 -5
- package/esm/util/create-context.js +10 -6
- package/esm/util/create-context.js.map +1 -1
- package/esm/util/types/OverridableComponent.d.ts +1 -1
- package/package.json +6 -6
- package/src/accordion/accordion.stories.tsx +121 -135
- package/src/button/button.stories.tsx +88 -185
- package/src/chat/chat.stories.tsx +285 -186
- package/src/date/datepicker/datepicker.stories.tsx +6 -2
- package/src/date/monthpicker/monthpicker.stories.tsx +2 -1
- package/src/date/parts/DateWrapper.tsx +3 -3
- package/src/dropdown/dropdown.stories.tsx +1 -1
- package/src/form/error-summary/ErrorSummary.tsx +11 -15
- package/src/form/error-summary/ErrorSummaryItem.tsx +8 -10
- package/src/form/error-summary/error-summary.stories.tsx +2 -56
- package/src/form/search/Search.tsx +4 -4
- package/src/form/stories/confirmation-panel.stories.tsx +1 -1
- package/src/form/stories/textarea.stories.tsx +1 -1
- package/src/help-text/help-text.stories.tsx +2 -1
- package/src/index.ts +1 -0
- package/src/internal-header/header.stories.tsx +2 -1
- package/src/layout/bleed/Bleed.stories.tsx +2 -1
- package/src/layout/box/Box.stories.tsx +2 -1
- package/src/layout/sidemal-test/navno-sidemal.stories.tsx +4 -1
- package/src/link/stories/link.stories.tsx +20 -22
- package/src/link-panel/link-panel.stories.tsx +1 -1
- package/src/list/list.stories.tsx +2 -1
- package/src/loader/loader.stories.tsx +1 -1
- package/src/modal/Modal.context.ts +13 -0
- package/src/modal/Modal.test.tsx +2 -2
- package/src/modal/Modal.tsx +6 -8
- package/src/modal/ModalHeader.tsx +3 -7
- package/src/modal/modal.stories.tsx +33 -6
- package/src/modal/types.ts +21 -4
- package/src/panel/Panel.tsx +9 -16
- package/src/popover/Popover.tsx +2 -2
- package/src/stepper/stepper.stories.tsx +1 -1
- package/src/table/stories/{table.stories.tsx → table-1.stories.tsx} +118 -92
- package/src/table/stories/{table-expandable.stories.tsx → table-2-expandable.stories.tsx} +10 -34
- package/src/table/stories/{table-async.stories.tsx → table-3-async.stories.tsx} +5 -3
- package/src/table/stories/tests/table.stories.tsx +4 -1
- package/src/table/types.ts +1 -1
- package/src/tabs/Tabs.test.tsx +109 -0
- package/src/toggle-group/ToggleGroup.test.tsx +54 -0
- package/src/tooltip/Tooltip.tsx +4 -10
- package/src/tooltip/tooltip.stories.tsx +4 -1
- package/src/typography/stories/bodylong.stories.tsx +49 -3
- package/src/typography/stories/bodyshort.stories.tsx +50 -4
- package/src/typography/stories/detail.stories.tsx +32 -3
- package/src/typography/stories/error-message.stories.tsx +34 -3
- package/src/typography/stories/heading.stories.tsx +32 -3
- package/src/typography/stories/label.stories.tsx +38 -3
- package/src/util/create-context.tsx +26 -15
- package/src/util/types/OverridableComponent.ts +1 -1
- package/_docs.json +0 -20247
- package/cjs/modal/ModalContext.d.ts +0 -7
- package/cjs/modal/ModalContext.js +0 -9
- package/cjs/modal/ModalContext.js.map +0 -1
- package/esm/modal/ModalContext.d.ts +0 -7
- package/esm/modal/ModalContext.js +0 -3
- package/esm/modal/ModalContext.js.map +0 -1
- package/src/modal/ModalContext.ts +0 -7
- package/src/panel/panel.stories.tsx +0 -63
- package/src/typography/stories/ingress.stories.tsx +0 -50
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "@storybook/test";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { VStack } from "../../layout/stack";
|
|
5
|
+
import { BodyShort } from "../BodyShort";
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: "ds-react/Typography/BodyShort",
|
|
9
9
|
component: BodyShort,
|
|
10
|
-
decorators: [(story) => <div style={{ maxWidth: "
|
|
10
|
+
decorators: [(story) => <div style={{ maxWidth: "250px" }}>{story()}</div>],
|
|
11
|
+
parameters: {
|
|
12
|
+
chromatic: { disable: true },
|
|
13
|
+
},
|
|
11
14
|
} satisfies Meta<typeof BodyShort>;
|
|
12
15
|
|
|
13
16
|
export default meta;
|
|
@@ -16,7 +19,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
16
19
|
|
|
17
20
|
const lorem = "Du må gjøre en filtrering for å se brukere i listen.";
|
|
18
21
|
|
|
19
|
-
export const
|
|
22
|
+
export const Controls: Story = {
|
|
20
23
|
args: {
|
|
21
24
|
spacing: false,
|
|
22
25
|
children: lorem,
|
|
@@ -161,3 +164,46 @@ export const OverrideTag: Story = {
|
|
|
161
164
|
expect(legendBodyShort.tagName).toEqual("LEGEND");
|
|
162
165
|
},
|
|
163
166
|
};
|
|
167
|
+
|
|
168
|
+
export const Chromatic: Story = {
|
|
169
|
+
render: (...props) => (
|
|
170
|
+
<div>
|
|
171
|
+
<div>
|
|
172
|
+
<h2>Large</h2>
|
|
173
|
+
<h3>Size</h3>
|
|
174
|
+
{SizeLarge.render?.(...props)}
|
|
175
|
+
<h3>Spacing</h3>
|
|
176
|
+
{SpacingLarge.render?.(...props)}
|
|
177
|
+
</div>
|
|
178
|
+
<div>
|
|
179
|
+
<h2>Medium</h2>
|
|
180
|
+
<h3>Size</h3>
|
|
181
|
+
{SizeMedium.render?.(...props)}
|
|
182
|
+
<h3>Spacing</h3>
|
|
183
|
+
{SpacingMedium.render?.(...props)}
|
|
184
|
+
</div>
|
|
185
|
+
<div>
|
|
186
|
+
<h2>Small</h2>
|
|
187
|
+
<h3>Size</h3>
|
|
188
|
+
{SizeSmall.render?.(...props)}
|
|
189
|
+
<h3>Spacing</h3>
|
|
190
|
+
{SpacingSmall.render?.(...props)}
|
|
191
|
+
</div>
|
|
192
|
+
<div>
|
|
193
|
+
<h2>Colors</h2>
|
|
194
|
+
{Colors.render?.(...props)}
|
|
195
|
+
</div>
|
|
196
|
+
<div>
|
|
197
|
+
<h2>Align</h2>
|
|
198
|
+
{Align.render?.(...props)}
|
|
199
|
+
</div>
|
|
200
|
+
<div>
|
|
201
|
+
<h2>Override Tag</h2>
|
|
202
|
+
{OverrideTag.render?.(...props)}
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
),
|
|
206
|
+
parameters: {
|
|
207
|
+
chromatic: { disable: false },
|
|
208
|
+
},
|
|
209
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "@storybook/test";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { VStack } from "../../layout/stack";
|
|
5
|
+
import Detail from "../Detail";
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: "ds-react/Typography/Detail",
|
|
9
9
|
component: Detail,
|
|
10
10
|
decorators: [(story) => <div style={{ maxWidth: "200px" }}>{story()}</div>],
|
|
11
|
+
parameters: {
|
|
12
|
+
chromatic: { disable: true },
|
|
13
|
+
},
|
|
11
14
|
} satisfies Meta<typeof Detail>;
|
|
12
15
|
|
|
13
16
|
export default meta;
|
|
@@ -16,7 +19,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
16
19
|
|
|
17
20
|
const lorem = "Du må gjøre en filtrering for å se brukere i listen.";
|
|
18
21
|
|
|
19
|
-
export const
|
|
22
|
+
export const Controls: Story = {
|
|
20
23
|
args: {
|
|
21
24
|
spacing: false,
|
|
22
25
|
children: lorem,
|
|
@@ -85,3 +88,29 @@ export const OverrideTag: Story = {
|
|
|
85
88
|
expect(legendDetail.tagName).toEqual("LEGEND");
|
|
86
89
|
},
|
|
87
90
|
};
|
|
91
|
+
|
|
92
|
+
export const Chromatic: Story = {
|
|
93
|
+
render: (...props) => (
|
|
94
|
+
<div>
|
|
95
|
+
<div>
|
|
96
|
+
<h2>Spacing</h2>
|
|
97
|
+
{Spacing.render?.(...props)}
|
|
98
|
+
</div>
|
|
99
|
+
<div>
|
|
100
|
+
<h2>Colors</h2>
|
|
101
|
+
{Colors.render?.(...props)}
|
|
102
|
+
</div>
|
|
103
|
+
<div>
|
|
104
|
+
<h2>Align</h2>
|
|
105
|
+
{Align.render?.(...props)}
|
|
106
|
+
</div>
|
|
107
|
+
<div>
|
|
108
|
+
<h2>Override Tag</h2>
|
|
109
|
+
{OverrideTag.render?.(...props)}
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
),
|
|
113
|
+
parameters: {
|
|
114
|
+
chromatic: { disable: false },
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "@storybook/test";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { VStack } from "../../layout/stack";
|
|
5
|
+
import ErrorMessage from "../ErrorMessage";
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: "ds-react/Typography/ErrorMessage",
|
|
9
9
|
component: ErrorMessage,
|
|
10
|
+
parameters: {
|
|
11
|
+
chromatic: { disable: true },
|
|
12
|
+
},
|
|
10
13
|
} satisfies Meta<typeof ErrorMessage>;
|
|
11
14
|
|
|
12
15
|
export default meta;
|
|
@@ -16,7 +19,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
16
19
|
const lorem =
|
|
17
20
|
"Du må fylle ut: Oppgi årsaken til at du har ventet mer enn 6 måneder med å søke om refusjon";
|
|
18
21
|
|
|
19
|
-
export const
|
|
22
|
+
export const Controls: Story = {
|
|
20
23
|
args: {
|
|
21
24
|
spacing: false,
|
|
22
25
|
children: lorem,
|
|
@@ -90,3 +93,31 @@ export const OverrideTag: Story = {
|
|
|
90
93
|
expect(legendErrorMessage.tagName).toEqual("LEGEND");
|
|
91
94
|
},
|
|
92
95
|
};
|
|
96
|
+
|
|
97
|
+
export const Chromatic: Story = {
|
|
98
|
+
render: (...props) => (
|
|
99
|
+
<div>
|
|
100
|
+
<div>
|
|
101
|
+
<h2>Medium</h2>
|
|
102
|
+
<h3>Size</h3>
|
|
103
|
+
{SizeMedium.render?.(...props)}
|
|
104
|
+
<h3>Spacing</h3>
|
|
105
|
+
{SpacingMedium.render?.(...props)}
|
|
106
|
+
</div>
|
|
107
|
+
<div>
|
|
108
|
+
<h2>Small</h2>
|
|
109
|
+
<h3>Size</h3>
|
|
110
|
+
{SizeSmall.render?.(...props)}
|
|
111
|
+
<h3>Spacing</h3>
|
|
112
|
+
{SpacingSmall.render?.(...props)}
|
|
113
|
+
</div>
|
|
114
|
+
<div>
|
|
115
|
+
<h2>Override Tag</h2>
|
|
116
|
+
{OverrideTag.render?.(...props)}
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
),
|
|
120
|
+
parameters: {
|
|
121
|
+
chromatic: { disable: false },
|
|
122
|
+
},
|
|
123
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "@storybook/test";
|
|
3
3
|
import { default as React } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { VStack } from "../../layout/stack";
|
|
5
|
+
import Heading from "../Heading";
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: "ds-react/Typography/Heading",
|
|
9
9
|
component: Heading,
|
|
10
10
|
decorators: [(story) => <div style={{ maxWidth: "300px" }}>{story()}</div>],
|
|
11
|
+
parameters: {
|
|
12
|
+
chromatic: { disable: true },
|
|
13
|
+
},
|
|
11
14
|
} satisfies Meta<typeof Heading>;
|
|
12
15
|
|
|
13
16
|
export default meta;
|
|
@@ -16,7 +19,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
16
19
|
|
|
17
20
|
const lorem = "Hva kan vi hjelpe deg med?";
|
|
18
21
|
|
|
19
|
-
export const
|
|
22
|
+
export const Controls: Story = {
|
|
20
23
|
args: {
|
|
21
24
|
spacing: false,
|
|
22
25
|
children: lorem,
|
|
@@ -139,3 +142,29 @@ export const OverrideTag: Story = {
|
|
|
139
142
|
expect(legendHeading.tagName).toEqual("LEGEND");
|
|
140
143
|
},
|
|
141
144
|
};
|
|
145
|
+
|
|
146
|
+
export const Chromatic: Story = {
|
|
147
|
+
render: (...props) => (
|
|
148
|
+
<div>
|
|
149
|
+
<div>
|
|
150
|
+
<h2>Sizes</h2>
|
|
151
|
+
{Sizes.render?.(...props)}
|
|
152
|
+
</div>
|
|
153
|
+
<div>
|
|
154
|
+
<h2>Colors</h2>
|
|
155
|
+
{Colors.render?.(...props)}
|
|
156
|
+
</div>
|
|
157
|
+
<div>
|
|
158
|
+
<h2>Align</h2>
|
|
159
|
+
{Align.render?.(...props)}
|
|
160
|
+
</div>
|
|
161
|
+
<div>
|
|
162
|
+
<h2>Override Tag</h2>
|
|
163
|
+
{OverrideTag.render?.(...props)}
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
),
|
|
167
|
+
parameters: {
|
|
168
|
+
chromatic: { disable: false },
|
|
169
|
+
},
|
|
170
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { expect, within } from "@storybook/test";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { VStack } from "../../layout/stack";
|
|
5
|
+
import Label from "../Label";
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: "ds-react/Typography/Label",
|
|
9
9
|
component: Label,
|
|
10
10
|
decorators: [(story) => <div style={{ maxWidth: "400px" }}>{story()}</div>],
|
|
11
|
+
parameters: {
|
|
12
|
+
chromatic: { disable: true },
|
|
13
|
+
},
|
|
11
14
|
} satisfies Meta<typeof Label>;
|
|
12
15
|
|
|
13
16
|
export default meta;
|
|
@@ -17,7 +20,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
17
20
|
const lorem =
|
|
18
21
|
"Oppgi årsaken til at du har ventet mer enn 6 måneder med å søke om refusjon";
|
|
19
22
|
|
|
20
|
-
export const
|
|
23
|
+
export const Controls: Story = {
|
|
21
24
|
args: {
|
|
22
25
|
spacing: false,
|
|
23
26
|
children: lorem,
|
|
@@ -95,3 +98,35 @@ export const OverrideTag: Story = {
|
|
|
95
98
|
expect(legendLabel.tagName).toEqual("LEGEND");
|
|
96
99
|
},
|
|
97
100
|
};
|
|
101
|
+
|
|
102
|
+
export const Chromatic: Story = {
|
|
103
|
+
render: (...props) => (
|
|
104
|
+
<div>
|
|
105
|
+
<div>
|
|
106
|
+
<h2>Medium</h2>
|
|
107
|
+
<h3>Size</h3>
|
|
108
|
+
{SizeMedium.render?.(...props)}
|
|
109
|
+
<h3>Spacing</h3>
|
|
110
|
+
{SpacingMedium.render?.(...props)}
|
|
111
|
+
</div>
|
|
112
|
+
<div>
|
|
113
|
+
<h2>Small</h2>
|
|
114
|
+
<h3>Size</h3>
|
|
115
|
+
{SizeSmall.render?.(...props)}
|
|
116
|
+
<h3>Spacing</h3>
|
|
117
|
+
{SpacingSmall.render?.(...props)}
|
|
118
|
+
</div>
|
|
119
|
+
<div>
|
|
120
|
+
<h2>Colors</h2>
|
|
121
|
+
{Colors.render?.(...props)}
|
|
122
|
+
</div>
|
|
123
|
+
<div>
|
|
124
|
+
<h2>Override Tag</h2>
|
|
125
|
+
{OverrideTag.render?.(...props)}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
),
|
|
129
|
+
parameters: {
|
|
130
|
+
chromatic: { disable: false },
|
|
131
|
+
},
|
|
132
|
+
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React, {
|
|
8
8
|
createContext as createReactContext,
|
|
9
|
+
forwardRef,
|
|
9
10
|
useContext as useReactContext,
|
|
10
11
|
} from "react";
|
|
11
12
|
|
|
@@ -19,11 +20,6 @@ export interface CreateContextOptions<T> {
|
|
|
19
20
|
|
|
20
21
|
type ProviderProps<T> = T & { children: React.ReactNode };
|
|
21
22
|
|
|
22
|
-
export type CreateContextReturn<T> = [
|
|
23
|
-
(contextValues: ProviderProps<T>) => React.JSX.Element,
|
|
24
|
-
() => T,
|
|
25
|
-
];
|
|
26
|
-
|
|
27
23
|
function getErrorMessage(hook: string, provider: string) {
|
|
28
24
|
return `${hook} returned \`undefined\`. Seems you forgot to wrap component within ${provider}`;
|
|
29
25
|
}
|
|
@@ -39,17 +35,30 @@ export function createContext<T>(options: CreateContextOptions<T> = {}) {
|
|
|
39
35
|
|
|
40
36
|
const Context = createReactContext<T | undefined>(defaultValue);
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
/**
|
|
39
|
+
* We use forwardRef to allow `ref` to be used as a regular context value
|
|
40
|
+
* @see https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components
|
|
41
|
+
*/
|
|
42
|
+
const Provider = forwardRef(
|
|
43
|
+
({ children, ...context }: ProviderProps<T>, ref) => {
|
|
44
|
+
// Only re-memoize when prop values change
|
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
|
+
const value = React.useMemo(() => context, Object.values(context)) as T;
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return (
|
|
49
|
+
<Context.Provider value={ref ? { ...value, ref } : value}>
|
|
50
|
+
{children}
|
|
51
|
+
</Context.Provider>
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
function useContext<S extends boolean = true>(
|
|
57
|
+
strict: S = true as S,
|
|
58
|
+
): Context<S, T> {
|
|
50
59
|
const context = useReactContext(Context);
|
|
51
60
|
|
|
52
|
-
if (!context) {
|
|
61
|
+
if (!context && strict) {
|
|
53
62
|
const error = new Error(
|
|
54
63
|
errorMessage ?? getErrorMessage(hookName, providerName),
|
|
55
64
|
);
|
|
@@ -58,10 +67,12 @@ export function createContext<T>(options: CreateContextOptions<T> = {}) {
|
|
|
58
67
|
throw error;
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
return context
|
|
70
|
+
return context as Context<S, T>;
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
Context.displayName = name;
|
|
65
74
|
|
|
66
|
-
return [Provider, useContext] as
|
|
75
|
+
return [Provider, useContext] as const;
|
|
67
76
|
}
|
|
77
|
+
|
|
78
|
+
type Context<S, T> = S extends true ? T : T | undefined;
|
|
@@ -22,7 +22,7 @@ export interface OverridableComponent<Component, Element extends HTMLElement> {
|
|
|
22
22
|
*/
|
|
23
23
|
<As extends React.ElementType>(
|
|
24
24
|
props: {
|
|
25
|
-
as
|
|
25
|
+
as: As;
|
|
26
26
|
} & Component &
|
|
27
27
|
Omit<React.ComponentPropsWithRef<As>, keyof Component | "as">,
|
|
28
28
|
): ReturnType<React.FC>;
|