@commercelayer/react-components 3.14.0-beta.2 → 3.14.0-beta.3

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,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { ConditionalElement } from '../typings/index';
3
- import { TResources } from './utils/GenericFieldComponent';
4
- declare type SkuFieldChildrenProps = Omit<Props, 'children' | 'attribute' | 'element'>;
3
+ import { TGenericChildrenProps, TResources } from './utils/GenericFieldComponent';
4
+ declare type SkuFieldChildrenProps = TGenericChildrenProps<TResources['Sku']>;
5
5
  declare type TCondition = ConditionalElement<Exclude<TResources['Sku'], 'resource'>>;
6
6
  declare type Props = {
7
7
  children?: (props: SkuFieldChildrenProps) => JSX.Element;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { ConditionalElement } from '../typings/index';
3
- import { TResources } from './utils/GenericFieldComponent';
4
- declare type StockTransferFieldChildrenProps = Omit<Props, 'children' | 'attribute' | 'element'>;
3
+ import { TGenericChildrenProps, TResources } from './utils/GenericFieldComponent';
4
+ declare type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['StockTransfer']>;
5
5
  declare type TCondition = ConditionalElement<Exclude<TResources['StockTransfer'], 'resource'>>;
6
6
  declare type Props = {
7
7
  children?: (props: StockTransferFieldChildrenProps) => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { InitialSkuContext } from '../../context/SkuChildrenContext';
2
2
  import { InitialStockTransferContext } from '../../context/StockTransferChildrenContext';
3
- import { LineItem, Sku } from '@commercelayer/sdk';
3
+ import type { LineItem, Sku } from '@commercelayer/sdk';
4
4
  import { InitialLineItemContext } from '../../context/LineItemChildrenContext';
5
5
  import { Context } from 'react';
6
6
  export declare type TResources = {
@@ -17,8 +17,8 @@ export declare type TResources = {
17
17
  export declare type TResourceKey = {
18
18
  [K in keyof TResources]: K;
19
19
  };
20
- declare type ChildrenProps<E extends TResources[keyof TResources]> = Omit<Props<E>, 'children' | 'attribute'> & {
21
- element: E[keyof E];
20
+ export declare type TGenericChildrenProps<E extends TResources[keyof TResources]> = Omit<Props<E>, 'children' | 'attribute' | 'context' | 'tagElement'> & {
21
+ attributeValue: E[keyof E];
22
22
  };
23
23
  declare type ResourceContext = {
24
24
  stock_transfers: InitialStockTransferContext;
@@ -27,7 +27,7 @@ declare type ResourceContext = {
27
27
  };
28
28
  declare type GenericContext<K extends keyof ResourceContext> = Context<ResourceContext[K]>;
29
29
  declare type Props<E extends TResources[keyof TResources]> = {
30
- children?: (props: ChildrenProps<E>) => JSX.Element;
30
+ children?: (props: TGenericChildrenProps<E>) => JSX.Element;
31
31
  resource: E['resource'];
32
32
  attribute: keyof E;
33
33
  tagElement: keyof JSX.IntrinsicElements;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./Parent";import{useContext}from"react";import{defaultImgUrl}from"../../utils/placeholderImages";export default function GenericFieldComponent(props){const{children,tagElement,attribute,context}=props,p=__rest(props,["children","tagElement","attribute","context"]),resourceContext=useContext(context);let element;for(const key in resourceContext)Object.prototype.hasOwnProperty.call(resourceContext,key)&&(element=resourceContext[key][attribute]);const Tag=tagElement||"span";if(Tag==="img"&&!children)return _jsx("img",Object.assign({alt:"",src:element||defaultImgUrl},p));const parentProps=Object.assign({element,tagElement},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Tag,Object.assign({},p,{children:element}))}
1
+ import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./Parent";import{useContext}from"react";import{defaultImgUrl}from"../../utils/placeholderImages";export default function GenericFieldComponent(props){const{children,tagElement,attribute,context}=props,p=__rest(props,["children","tagElement","attribute","context"]),resourceContext=useContext(context);let attributeValue;for(const key in resourceContext)Object.prototype.hasOwnProperty.call(resourceContext,key)&&(attributeValue=resourceContext[key][attribute]);const Tag=tagElement||"span";if(Tag==="img"&&!children)return _jsx("img",Object.assign({alt:"",src:attributeValue||defaultImgUrl},p));const parentProps=Object.assign({attributeValue,tagElement},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Tag,Object.assign({},p,{children:attributeValue}))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "3.14.0-beta.2",
3
+ "version": "3.14.0-beta.3",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/index.d.ts",