@coopdigital/react 1.30.1 → 1.30.2
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/dist/components/Combobox/Combobox.js +19 -3
- package/dist/components/Textarea/Textarea.js +14 -4
- package/dist/components/icons/AccountCircleFilledIcon.d.ts +2 -1
- package/dist/components/icons/AccountCircleIcon.d.ts +2 -1
- package/dist/components/icons/AccountFilledIcon.d.ts +2 -1
- package/dist/components/icons/AccountIcon.d.ts +2 -1
- package/dist/components/icons/AddIcon.d.ts +2 -1
- package/dist/components/icons/AppsFilledIcon.d.ts +2 -1
- package/dist/components/icons/AppsIcon.d.ts +2 -1
- package/dist/components/icons/ArrowDownIcon.d.ts +2 -1
- package/dist/components/icons/ArrowLeftIcon.d.ts +2 -1
- package/dist/components/icons/ArrowRightIcon.d.ts +2 -1
- package/dist/components/icons/ArrowUpIcon.d.ts +2 -1
- package/dist/components/icons/BackspaceFilledIcon.d.ts +2 -1
- package/dist/components/icons/BackspaceIcon.d.ts +2 -1
- package/dist/components/icons/BasketFilledIcon.d.ts +2 -1
- package/dist/components/icons/BasketIcon.d.ts +2 -1
- package/dist/components/icons/BellFilledIcon.d.ts +2 -1
- package/dist/components/icons/BellIcon.d.ts +2 -1
- package/dist/components/icons/BroomIcon.d.ts +2 -1
- package/dist/components/icons/CalendarFilledIcon.d.ts +2 -1
- package/dist/components/icons/CalendarIcon.d.ts +2 -1
- package/dist/components/icons/CashFilledIcon.d.ts +2 -1
- package/dist/components/icons/CashIcon.d.ts +2 -1
- package/dist/components/icons/ChevronDownIcon.d.ts +2 -1
- package/dist/components/icons/ChevronLeftIcon.d.ts +2 -1
- package/dist/components/icons/ChevronRightIcon.d.ts +2 -1
- package/dist/components/icons/ChevronUpIcon.d.ts +2 -1
- package/dist/components/icons/CircleBurgerFilledIcon.d.ts +2 -1
- package/dist/components/icons/CircleBurgerIcon.d.ts +2 -1
- package/dist/components/icons/ClipboardFilledIcon.d.ts +2 -1
- package/dist/components/icons/ClipboardIcon.d.ts +2 -1
- package/dist/components/icons/ClockFilledIcon.d.ts +2 -1
- package/dist/components/icons/ClockIcon.d.ts +2 -1
- package/dist/components/icons/CloseAltFilledIcon.d.ts +2 -1
- package/dist/components/icons/CloseAltIcon.d.ts +2 -1
- package/dist/components/icons/CogIcon.d.ts +2 -1
- package/dist/components/icons/CommunityFilledIcon.d.ts +2 -1
- package/dist/components/icons/CommunityIcon.d.ts +2 -1
- package/dist/components/icons/ComputerIcon.d.ts +2 -1
- package/dist/components/icons/ContactFilledIcon.d.ts +2 -1
- package/dist/components/icons/ContactIcon.d.ts +2 -1
- package/dist/components/icons/ContactlessFilledIcon.d.ts +2 -1
- package/dist/components/icons/ContactlessIcon.d.ts +2 -1
- package/dist/components/icons/CoopLiveIcon.d.ts +2 -1
- package/dist/components/icons/CoopLocationFilledIcon.d.ts +2 -1
- package/dist/components/icons/CoopLogoIcon.d.ts +2 -1
- package/dist/components/icons/CoopMembershipCardFilledIcon.d.ts +2 -1
- package/dist/components/icons/CreditCardFilledIcon.d.ts +2 -1
- package/dist/components/icons/CreditCardIcon.d.ts +2 -1
- package/dist/components/icons/CrossIcon.d.ts +2 -1
- package/dist/components/icons/DocumentIcon.d.ts +2 -1
- package/dist/components/icons/DownloadIcon.d.ts +2 -1
- package/dist/components/icons/EnterStoreIcon.d.ts +2 -1
- package/dist/components/icons/ExitStoreIcon.d.ts +2 -1
- package/dist/components/icons/EyeFilledIcon.d.ts +2 -1
- package/dist/components/icons/EyeIcon.d.ts +2 -1
- package/dist/components/icons/EyeStrikeFilledIcon.d.ts +2 -1
- package/dist/components/icons/EyeStrikeIcon.d.ts +2 -1
- package/dist/components/icons/FeedbackFilledIcon.d.ts +2 -1
- package/dist/components/icons/FeedbackIcon.d.ts +2 -1
- package/dist/components/icons/FilterIcon.d.ts +2 -1
- package/dist/components/icons/GiftCardFilledIcon.d.ts +2 -1
- package/dist/components/icons/GiftCardIcon.d.ts +2 -1
- package/dist/components/icons/GiftFilledIcon.d.ts +2 -1
- package/dist/components/icons/GiftIcon.d.ts +2 -1
- package/dist/components/icons/HelpFilledIcon.d.ts +2 -1
- package/dist/components/icons/HelpIcon.d.ts +2 -1
- package/dist/components/icons/HomeFilledIcon.d.ts +2 -1
- package/dist/components/icons/HomeIcon.d.ts +2 -1
- package/dist/components/icons/HowDoIAssistantIcon.d.ts +2 -1
- package/dist/components/icons/InfoIcon.d.ts +2 -1
- package/dist/components/icons/KebabIcon.d.ts +2 -1
- package/dist/components/icons/LoadingIcon.d.ts +2 -1
- package/dist/components/icons/LocationFilledIcon.d.ts +2 -1
- package/dist/components/icons/LocationIcon.d.ts +2 -1
- package/dist/components/icons/LogoutIcon.d.ts +2 -1
- package/dist/components/icons/MailIcon.d.ts +2 -1
- package/dist/components/icons/MenuIcon.d.ts +2 -1
- package/dist/components/icons/MessageIcon.d.ts +2 -1
- package/dist/components/icons/MinusIcon.d.ts +2 -1
- package/dist/components/icons/NotesFilledIcon.d.ts +2 -1
- package/dist/components/icons/NotesIcon.d.ts +2 -1
- package/dist/components/icons/OpenNewIcon.d.ts +2 -1
- package/dist/components/icons/OwnBagIcon.d.ts +2 -1
- package/dist/components/icons/PadlockIcon.d.ts +2 -1
- package/dist/components/icons/PencilIcon.d.ts +2 -1
- package/dist/components/icons/PhoneIcon.d.ts +2 -1
- package/dist/components/icons/PowerIcon.d.ts +2 -1
- package/dist/components/icons/SaveFilledIcon.d.ts +2 -1
- package/dist/components/icons/SaveIcon.d.ts +2 -1
- package/dist/components/icons/ScooterIcon.d.ts +2 -1
- package/dist/components/icons/SearchFilledIcon.d.ts +2 -1
- package/dist/components/icons/SearchIcon.d.ts +2 -1
- package/dist/components/icons/SendIcon.d.ts +2 -1
- package/dist/components/icons/SpannerIcon.d.ts +2 -1
- package/dist/components/icons/StarFilledIcon.d.ts +2 -1
- package/dist/components/icons/StarIcon.d.ts +2 -1
- package/dist/components/icons/TickAltFilledIcon.d.ts +2 -1
- package/dist/components/icons/TickAltIcon.d.ts +2 -1
- package/dist/components/icons/TickIcon.d.ts +2 -1
- package/dist/components/icons/TruckIcon.d.ts +2 -1
- package/dist/components/icons/UserWipeIcon.d.ts +2 -1
- package/dist/components/icons/VoucherFilledIcon.d.ts +2 -1
- package/dist/components/icons/VoucherIcon.d.ts +2 -1
- package/dist/components/icons/WarningCircleFilledIcon.d.ts +2 -1
- package/dist/components/icons/WarningCircleIcon.d.ts +2 -1
- package/dist/components/icons/WarningFilledIcon.d.ts +2 -1
- package/dist/components/icons/WarningIcon.d.ts +2 -1
- package/dist/components/icons/WifiIcon.d.ts +2 -1
- package/dist/components/icons/WriteIcon.d.ts +2 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useFormReset.d.ts +6 -0
- package/dist/hooks/useFormReset.js +19 -0
- package/dist/hooks/useSlots.d.ts +2 -1
- package/dist/types/index.js +4 -0
- package/dist/utils/slots.d.ts +1 -1
- package/dist/utils/slots.js +20 -12
- package/package.json +18 -15
- package/src/components/Combobox/Combobox.context.ts +3 -1
- package/src/components/Combobox/Combobox.tsx +28 -4
- package/src/components/Textarea/Textarea.tsx +19 -4
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useFormReset.ts +28 -0
- package/src/utils/slots.ts +37 -23
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDebounce } from "./useDebounce.js";
|
|
2
|
+
import { useFormReset } from "./useFormReset.js";
|
|
2
3
|
import { useId } from "./useId.js";
|
|
3
4
|
import { useSlots } from "./useSlots.js";
|
|
4
|
-
export { useDebounce, useId, useSlots };
|
|
5
|
+
export { useDebounce, useFormReset, useId, useSlots };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useId } from "./useId.js";
|
|
2
2
|
import { useSlots } from "./useSlots.js";
|
|
3
3
|
import { useDebounce } from "./useDebounce.js";
|
|
4
|
-
|
|
4
|
+
import { useFormReset } from "./useFormReset.js";
|
|
5
|
+
export { useDebounce, useFormReset, useId, useSlots };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
//#region src/hooks/useFormReset.d.ts
|
|
3
|
+
type FormControl = HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
4
|
+
export declare function useFormReset(ref: RefObject<FormControl | null>, onReset: () => void): void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
//#region src/hooks/useFormReset.ts
|
|
3
|
+
function useFormReset(ref, onReset) {
|
|
4
|
+
const onResetRef = useRef(onReset);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
onResetRef.current = onReset;
|
|
7
|
+
});
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const form = ref.current?.form;
|
|
10
|
+
if (!form) return;
|
|
11
|
+
const handleReset = (event) => {
|
|
12
|
+
if (!event.defaultPrevented) onResetRef.current();
|
|
13
|
+
};
|
|
14
|
+
form.addEventListener("reset", handleReset);
|
|
15
|
+
return () => form.removeEventListener("reset", handleReset);
|
|
16
|
+
}, [ref]);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useFormReset };
|
package/dist/hooks/useSlots.d.ts
CHANGED
package/dist/utils/slots.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { LazyComponent, SlotConfig } from "../types/index.js";
|
|
|
2
2
|
import React, { ReactElement, ReactNode } from "react";
|
|
3
3
|
//#region src/utils/slots.d.ts
|
|
4
4
|
export declare function getSlotProp<R = unknown>(slot: React.ReactNode, prop: string): R | undefined;
|
|
5
|
-
export declare const forEachSlot: (children: ReactNode, fn: (slot: SlotConfig, child: ReactElement) => void) => void;
|
|
6
5
|
export declare function isLazy<T extends React.ComponentType<any>>(type: unknown): type is LazyComponent<T>;
|
|
6
|
+
export declare const forEachSlot: (children: ReactNode, fn: (slot: SlotConfig, child: ReactElement) => void) => void;
|
|
7
7
|
export declare function resolveComponentName(child: React.ReactNode): string | null;
|
|
8
8
|
export declare function getSlotName(node: React.ReactNode): string | false;
|
|
9
9
|
//#endregion
|
package/dist/utils/slots.js
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
|
+
import { REACT_LAZY_TYPE } from "../types/index.js";
|
|
1
2
|
import { isValidElement } from "react";
|
|
2
3
|
//#region src/utils/slots.ts
|
|
3
4
|
function getSlotProp(slot, prop) {
|
|
4
5
|
if (isValidElement(slot) && prop in slot.props) return slot.props[prop];
|
|
5
6
|
}
|
|
7
|
+
function isLazy(type) {
|
|
8
|
+
return typeof type === "object" && type !== null && type.$$typeof === REACT_LAZY_TYPE;
|
|
9
|
+
}
|
|
10
|
+
const resolveType = (type) => {
|
|
11
|
+
if (!isLazy(type)) return type;
|
|
12
|
+
try {
|
|
13
|
+
return type._init(type._payload);
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getSlotConfig = (type) => {
|
|
19
|
+
const resolved = resolveType(type);
|
|
20
|
+
return typeof resolved === "function" && "slot" in resolved ? resolved.slot : void 0;
|
|
21
|
+
};
|
|
6
22
|
const forEachSlot = (children, fn) => {
|
|
7
23
|
Array.from([children].flat()).forEach((child) => {
|
|
8
|
-
if (isValidElement(child)
|
|
24
|
+
if (!isValidElement(child)) return;
|
|
25
|
+
const slot = getSlotConfig(child.type);
|
|
26
|
+
if (slot) fn(slot, child);
|
|
9
27
|
});
|
|
10
28
|
};
|
|
11
|
-
function isLazy(type) {
|
|
12
|
-
return typeof type === "object" && type !== null && "_payload" in type && "_init" in type;
|
|
13
|
-
}
|
|
14
29
|
function resolveComponentName(child) {
|
|
15
30
|
if (child && typeof child === "object" && "type" in child) {
|
|
16
|
-
const type = child.type;
|
|
17
|
-
if (isLazy(type)) try {
|
|
18
|
-
const resolved = type._init(type._payload);
|
|
19
|
-
if ("slot" in resolved) return resolved.slot.name;
|
|
20
|
-
return resolved.displayName ?? resolved.name ?? null;
|
|
21
|
-
} catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
31
|
+
const type = resolveType(child.type);
|
|
24
32
|
if (typeof type === "function") {
|
|
25
33
|
if ("slot" in type) return type.slot.name;
|
|
26
34
|
return type.displayName ?? type.name ?? null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopdigital/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.30.
|
|
4
|
+
"version": "1.30.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"./components/*": {
|
|
15
|
-
"types": "./dist/components
|
|
16
|
-
"default": "./dist/components
|
|
15
|
+
"types": "./dist/components/*/index.d.ts",
|
|
16
|
+
"default": "./dist/components/*/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./components/icons": null,
|
|
18
19
|
"./icons": {
|
|
19
20
|
"types": "./dist/components/icons/index.d.ts",
|
|
20
21
|
"default": "./dist/components/icons/index.js"
|
|
@@ -67,23 +68,25 @@
|
|
|
67
68
|
"license": "MIT",
|
|
68
69
|
"description": "React components for the Experience Library design system",
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@axe-core/playwright": "^4.
|
|
71
|
-
"@playwright/test": "^1.64.
|
|
72
|
-
"@storybook/addon-a11y": "^10.6.
|
|
73
|
-
"@storybook/addon-docs": "^10.6.
|
|
74
|
-
"@storybook/addon-links": "^10.6.
|
|
75
|
-
"@storybook/addon-onboarding": "^10.6.
|
|
76
|
-
"@storybook/react-vite": "^10.6.
|
|
71
|
+
"@axe-core/playwright": "^4.14.0",
|
|
72
|
+
"@playwright/test": "^1.64.1",
|
|
73
|
+
"@storybook/addon-a11y": "^10.6.2",
|
|
74
|
+
"@storybook/addon-docs": "^10.6.2",
|
|
75
|
+
"@storybook/addon-links": "^10.6.2",
|
|
76
|
+
"@storybook/addon-onboarding": "^10.6.2",
|
|
77
|
+
"@storybook/react-vite": "^10.6.2",
|
|
77
78
|
"@testing-library/jest-dom": "^7.0.1",
|
|
78
79
|
"@testing-library/react": "^16.3.3",
|
|
79
80
|
"@types/react": "^19.3.0",
|
|
80
81
|
"@types/react-dom": "^19.3.0",
|
|
81
82
|
"@whitespace/storybook-addon-html": "^9.0.0",
|
|
82
|
-
"react": "^19.3.
|
|
83
|
-
"react-dom": "^19.3.
|
|
83
|
+
"react": "^19.3.1",
|
|
84
|
+
"react-dom": "^19.3.1",
|
|
85
|
+
"react-element-to-jsx-string": "^18.0.0",
|
|
86
|
+
"react-hook-form": "^7.90.0",
|
|
84
87
|
"resize-observer-polyfill": "^1.5.1",
|
|
85
88
|
"serve": "^14.2.6",
|
|
86
|
-
"storybook": "^10.6.
|
|
89
|
+
"storybook": "^10.6.2",
|
|
87
90
|
"storybook-addon-tag-badges": "^3.1.0"
|
|
88
91
|
},
|
|
89
92
|
"peerDependencies": {
|
|
@@ -108,7 +111,7 @@
|
|
|
108
111
|
},
|
|
109
112
|
"dependencies": {
|
|
110
113
|
"@coopdigital/styles": "^1.21.1",
|
|
111
|
-
"@radix-ui/react-popover": "^1.
|
|
114
|
+
"@radix-ui/react-popover": "^1.3.1",
|
|
112
115
|
"clsx": "^2.1.1",
|
|
113
116
|
"date-fns": "^4.4.0",
|
|
114
117
|
"downshift": "^9.4.0",
|
|
@@ -116,5 +119,5 @@
|
|
|
116
119
|
"merge-refs": "^2.0.0",
|
|
117
120
|
"react-day-picker": "^10.0.2"
|
|
118
121
|
},
|
|
119
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "eb06ec9a3ea4bb441c5b6738949da6dfdd9f0ce2"
|
|
120
123
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import type { UseComboboxReturnValue } from "downshift"
|
|
3
3
|
|
|
4
|
-
import { createContext, useContext } from "react"
|
|
4
|
+
import { createContext, type RefObject, useContext } from "react"
|
|
5
5
|
|
|
6
6
|
import type { ComboboxItem } from "@/components/Combobox/combobox-utils"
|
|
7
7
|
|
|
@@ -11,6 +11,8 @@ interface ComboboxContextValue {
|
|
|
11
11
|
disabled: boolean
|
|
12
12
|
downshift: UseComboboxReturnValue<ComboboxItem>
|
|
13
13
|
error: boolean
|
|
14
|
+
// The visible input, which the form reset is looked up from
|
|
15
|
+
inputRef: RefObject<HTMLInputElement | null>
|
|
14
16
|
// The options currently shown, after filtering and the maxResults cap
|
|
15
17
|
items: ComboboxItem[]
|
|
16
18
|
// The number of options that match the input, before the cap
|