@cleanweb/oore 1.2.0-alpha.5 → 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.
@@ -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
- export declare const getComponentSlotName: (TargetComponent: PotentialSlotComponent) => string | number | symbol | undefined;
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';
@@ -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 ChildComponent = child.type;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/oore",
3
- "version": "1.2.0-alpha.5",
3
+ "version": "1.2.0-alpha.6",
4
4
  "description": "A library of helpers for writing cleaner React function components with object-oriented patterns.",
5
5
  "engines": {
6
6
  "node": ">=20"