@cleanweb/oore 1.2.0-alpha.4 → 1.2.0-alpha.6
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/build/slots/hook.d.ts +4 -1
- package/build/slots/hook.js +11 -3
- package/build/slots/types.d.ts +5 -5
- package/build/slots/types.js +0 -1
- package/package.json +1 -1
package/build/slots/hook.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { IUseSlots, PotentialSlotComponent } from './types';
|
|
3
3
|
export declare const isElementChild: (child: ReactNode) => child is ReactElement<any, any>;
|
|
4
|
-
|
|
4
|
+
interface IGetSlotName {
|
|
5
|
+
(TargetComponent: PotentialSlotComponent, child?: ReactElement): string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare const getComponentSlotName: IGetSlotName;
|
|
5
8
|
export declare const useSlots: IUseSlots;
|
|
6
9
|
export type { SlotNamedComponent, SlottedComponent, TSlotsRecord, PotentialSlotComponent, } from './types';
|
package/build/slots/hook.js
CHANGED
|
@@ -13,7 +13,7 @@ var isElementChild = function (child) {
|
|
|
13
13
|
return false;
|
|
14
14
|
};
|
|
15
15
|
exports.isElementChild = isElementChild;
|
|
16
|
-
var getComponentSlotName = function (TargetComponent) {
|
|
16
|
+
var getComponentSlotName = function (TargetComponent, child) {
|
|
17
17
|
if (typeof TargetComponent === 'string') {
|
|
18
18
|
return TargetComponent;
|
|
19
19
|
}
|
|
@@ -23,6 +23,15 @@ var getComponentSlotName = function (TargetComponent) {
|
|
|
23
23
|
else if ('displayName' in TargetComponent) {
|
|
24
24
|
return TargetComponent.displayName;
|
|
25
25
|
}
|
|
26
|
+
else if (child) {
|
|
27
|
+
var keyTypes = ['string', 'number', 'symbol'];
|
|
28
|
+
var slotName = child.props['data-slot-name'];
|
|
29
|
+
if (keyTypes.includes(typeof slotName)) {
|
|
30
|
+
return slotName;
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
26
35
|
else
|
|
27
36
|
return undefined;
|
|
28
37
|
};
|
|
@@ -65,8 +74,7 @@ var useSlots = function (children, slotComponents) {
|
|
|
65
74
|
return;
|
|
66
75
|
}
|
|
67
76
|
var slotAlias = (function () {
|
|
68
|
-
var
|
|
69
|
-
var slotName = (0, exports.getComponentSlotName)(ChildComponent);
|
|
77
|
+
var slotName = (0, exports.getComponentSlotName)(child.type, child);
|
|
70
78
|
return slotName ? slotsAliasLookup[slotName] : null;
|
|
71
79
|
})();
|
|
72
80
|
console.log('match:', { key: slotAlias });
|
package/build/slots/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode, JSXElementConstructor
|
|
1
|
+
import type { ReactElement, ReactNode, JSXElementConstructor } from 'react';
|
|
2
2
|
export type TComponent = JSXElementConstructor<any>;
|
|
3
3
|
export type TSlotName = keyof any;
|
|
4
4
|
export type TSlotAlias = keyof any;
|
|
5
5
|
export type TSlotsRecord<TKey extends TSlotAlias = TSlotAlias> = {
|
|
6
6
|
[Key in TKey]: (string | SlotComponent);
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
displayName:
|
|
10
|
-
}
|
|
8
|
+
export type DisplayNamedComponent<TComponentArg extends TComponent = TComponent, TDisplayNameArg extends string = string> = TComponentArg & {
|
|
9
|
+
displayName: TDisplayNameArg;
|
|
10
|
+
};
|
|
11
11
|
export type SlotNamedComponent<TComponentArg extends TComponent = TComponent, TSlotNameArg extends TSlotName = TSlotName> = TComponentArg & {
|
|
12
12
|
slotName: TSlotNameArg;
|
|
13
13
|
};
|
|
14
|
-
export type SlotComponent<
|
|
14
|
+
export type SlotComponent<TComponentArg extends TComponent = TComponent> = SlotNamedComponent<TComponentArg> | DisplayNamedComponent<TComponentArg>;
|
|
15
15
|
export type SlottedComponent<TComponentArg extends TComponent = TComponent, TSlotAliasArg extends TSlotAlias = TSlotAlias, TSlotsRecordArg extends TSlotsRecord<TSlotAliasArg> = TSlotsRecord<TSlotAliasArg>> = TComponentArg & {
|
|
16
16
|
Slots: TSlotsRecordArg;
|
|
17
17
|
};
|
package/build/slots/types.js
CHANGED
package/package.json
CHANGED