@commercelayer/react-components 3.0.0-alpha.2 → 3.0.0-alpha.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.
- package/lib/cjs/components/{ShippingMethod.d.ts → shipping_methods/ShippingMethod.d.ts} +0 -0
- package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -0
- package/lib/cjs/components/{ShippingMethodName.d.ts → shipping_methods/ShippingMethodName.d.ts} +0 -0
- package/lib/cjs/components/shipping_methods/ShippingMethodName.js +1 -0
- package/lib/{esm/components → cjs/components/shipping_methods}/ShippingMethodPrice.d.ts +2 -2
- package/lib/cjs/components/shipping_methods/ShippingMethodPrice.js +1 -0
- package/lib/cjs/components/{ShippingMethodRadioButton.d.ts → shipping_methods/ShippingMethodRadioButton.d.ts} +0 -0
- package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.js +1 -0
- package/lib/cjs/index.d.ts +5 -5
- package/lib/cjs/index.js +1 -1
- package/lib/esm/components/{ShippingMethod.d.ts → shipping_methods/ShippingMethod.d.ts} +0 -0
- package/lib/esm/components/shipping_methods/ShippingMethod.js +1 -0
- package/lib/esm/components/{ShippingMethodName.d.ts → shipping_methods/ShippingMethodName.d.ts} +0 -0
- package/lib/esm/components/shipping_methods/ShippingMethodName.js +1 -0
- package/lib/{cjs/components → esm/components/shipping_methods}/ShippingMethodPrice.d.ts +2 -2
- package/lib/esm/components/shipping_methods/ShippingMethodPrice.js +1 -0
- package/lib/esm/components/{ShippingMethodRadioButton.d.ts → shipping_methods/ShippingMethodRadioButton.d.ts} +0 -0
- package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.js +1 -0
- package/lib/esm/index.d.ts +5 -5
- package/lib/esm/index.js +1 -1
- package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +8 -1
- package/lib/cjs/components/ShippingMethod.js +0 -1
- package/lib/cjs/components/ShippingMethodName.js +0 -1
- package/lib/cjs/components/ShippingMethodPrice.js +0 -1
- package/lib/cjs/components/ShippingMethodRadioButton.js +0 -1
- package/lib/esm/components/ShippingMethod.js +0 -1
- package/lib/esm/components/ShippingMethodName.js +0 -1
- package/lib/esm/components/ShippingMethodPrice.js +0 -1
- package/lib/esm/components/ShippingMethodRadioButton.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"./shipments/*": {
|
|
35
35
|
"require": "./lib/cjs/components/shipments/*.js",
|
|
36
36
|
"import": "./lib/esm/components/shipments/*.js"
|
|
37
|
+
},
|
|
38
|
+
"./shipping_methods/*": {
|
|
39
|
+
"require": "./lib/cjs/components/shipping_methods/*.js",
|
|
40
|
+
"import": "./lib/esm/components/shipping_methods/*.js"
|
|
37
41
|
}
|
|
38
42
|
},
|
|
39
43
|
"typesVersions": {
|
|
@@ -52,6 +56,9 @@
|
|
|
52
56
|
],
|
|
53
57
|
"shipments/*": [
|
|
54
58
|
"lib/esm/components/shipments/*.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"shipping_methods/*": [
|
|
61
|
+
"lib/esm/components/shipping_methods/*.d.ts"
|
|
55
62
|
]
|
|
56
63
|
}
|
|
57
64
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethod=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../context/ShippingMethodChildrenContext")),components_1=tslib_1.__importDefault(require("../config/components")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../context/ShipmentChildrenContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),propTypes=components_1.default.ShippingMethod.propTypes,displayName=components_1.default.ShippingMethod.displayName;function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),[items,setItems]=(0,react_1.useState)([]);(0,react_1.useEffect)(()=>{const methods=shippingMethods&&shippingMethods.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{const deliveryShippingMethodId=delivery.shipping_method?.id;return shippingMethod.id===deliveryShippingMethodId}),shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return(0,jsx_runtime_1.jsx)(ShippingMethodChildrenContext_1.default.Provider,{value:shippingProps,children},k)});methods&&setItems(methods)},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!(0,isEmpty_1.default)(items)&&items||emptyText;return(0,jsx_runtime_1.jsx)(react_1.Fragment,{children:components})}exports.ShippingMethod=ShippingMethod,ShippingMethod.propTypes=propTypes,ShippingMethod.displayName=displayName,exports.default=ShippingMethod;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("./utils/Parent")),components_1=tslib_1.__importDefault(require("../config/components")),propTypes=components_1.default.ShippingMethodName.propTypes,displayName=components_1.default.ShippingMethodName.displayName;function ShippingMethodName(props){const{shippingMethod,deliveryLeadTimeForShipment,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),htmlFor=`shipment-${shipmentId}-${shippingMethod?.id}`||"",labelName=shippingMethod?.name,parentProps={shippingMethod,deliveryLeadTimeForShipment,label:labelName,htmlFor,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("label",{htmlFor,...props,children:labelName})}exports.ShippingMethodName=ShippingMethodName,ShippingMethodName.propTypes=propTypes,ShippingMethodName.displayName=displayName,exports.default=ShippingMethodName;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodPrice=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),getAmount_1=tslib_1.__importDefault(require("../utils/getAmount")),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("./utils/Parent")),components_1=tslib_1.__importDefault(require("../config/components")),propTypes=components_1.default.ShippingMethodPrice.propTypes,displayName=components_1.default.ShippingMethodPrice.displayName;function ShippingMethodPrice(props){const{base="price_amount",type="for_shipment",format="formatted",labelFreeOver="Free",...p}=props,{shippingMethod}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),[price,setPrice]=(0,react_1.useState)(""),[priceCents,setPriceCents]=(0,react_1.useState)(0);(0,react_1.useEffect)(()=>{if(shippingMethod){const p2=(0,getAmount_1.default)({base,type,format,obj:shippingMethod});setPrice(p2);const pCents=(0,getAmount_1.default)({base:"price_amount",type:"for_shipment",format:"cents",obj:shippingMethod});setPriceCents(pCents)}return()=>{setPrice(""),setPriceCents(0)}},[shippingMethod]);const parentProps={price,...p},finalPrice=priceCents===0?labelFreeOver:price;return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("span",{...p,children:finalPrice})}exports.ShippingMethodPrice=ShippingMethodPrice,ShippingMethodPrice.propTypes=propTypes,ShippingMethodPrice.displayName=displayName,exports.default=ShippingMethodPrice;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("./utils/Parent")),components_1=tslib_1.__importDefault(require("../config/components")),ShipmentContext_1=tslib_1.__importDefault(require("../context/ShipmentContext")),propTypes=components_1.default.ShippingMethodRadioButton.propTypes,displayName=components_1.default.ShippingMethodRadioButton.displayName;function ShippingMethodRadioButton(props){const{onChange,...p}=props,[checked,setChecked]=(0,react_1.useState)(!1),{shippingMethod,currentShippingMethodId,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),{setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),shippingMethodId=shippingMethod?.id,name=`shipment-${shipmentId}`,id=`${name}-${shippingMethodId}`;(0,react_1.useEffect)(()=>(setChecked(shippingMethodId===currentShippingMethodId),()=>{setChecked(!1)}),[currentShippingMethodId]);const handleOnChange=async()=>{shipmentId&&shippingMethodId&&(setChecked(!0),await setShippingMethod(shipmentId,shippingMethodId),shippingMethod&&onChange&&onChange(shippingMethod,shipmentId))},parentProps={shippingMethod,shipmentId,handleOnChange,name,id,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("input",{type:"radio",name,id,onChange:handleOnChange,checked,...p})}exports.ShippingMethodRadioButton=ShippingMethodRadioButton,ShippingMethodRadioButton.propTypes=propTypes,ShippingMethodRadioButton.displayName=displayName,exports.default=ShippingMethodRadioButton;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useEffect,useState}from"react";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import components from"../config/components";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";import isEmpty from"lodash/isEmpty";const propTypes=components.ShippingMethod.propTypes,displayName=components.ShippingMethod.displayName;export function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=useContext(ShipmentChildrenContext),[items,setItems]=useState([]);useEffect(()=>{const methods=shippingMethods&&shippingMethods.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{const deliveryShippingMethodId=delivery.shipping_method?.id;return shippingMethod.id===deliveryShippingMethodId}),shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return _jsx(ShippingMethodChildrenContext.Provider,{value:shippingProps,children},k)});methods&&setItems(methods)},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components2=!isEmpty(items)&&items||emptyText;return _jsx(Fragment,{children:components2})}ShippingMethod.propTypes=propTypes,ShippingMethod.displayName=displayName;export default ShippingMethod;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.ShippingMethodName.propTypes,displayName=components.ShippingMethodName.displayName;export function ShippingMethodName(props){const{shippingMethod,deliveryLeadTimeForShipment,shipmentId}=useContext(ShippingMethodChildrenContext),htmlFor=`shipment-${shipmentId}-${shippingMethod?.id}`||"",labelName=shippingMethod?.name,parentProps={shippingMethod,deliveryLeadTimeForShipment,label:labelName,htmlFor,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("label",{htmlFor,...props,children:labelName})}ShippingMethodName.propTypes=propTypes,ShippingMethodName.displayName=displayName;export default ShippingMethodName;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.ShippingMethodPrice.propTypes,displayName=components.ShippingMethodPrice.displayName;export function ShippingMethodPrice(props){const{base="price_amount",type="for_shipment",format="formatted",labelFreeOver="Free",...p}=props,{shippingMethod}=useContext(ShippingMethodChildrenContext),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(shippingMethod){const p2=getAmount({base,type,format,obj:shippingMethod});setPrice(p2);const pCents=getAmount({base:"price_amount",type:"for_shipment",format:"cents",obj:shippingMethod});setPriceCents(pCents)}return()=>{setPrice(""),setPriceCents(0)}},[shippingMethod]);const parentProps={price,...p},finalPrice=priceCents===0?labelFreeOver:price;return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:finalPrice})}ShippingMethodPrice.propTypes=propTypes,ShippingMethodPrice.displayName=displayName;export default ShippingMethodPrice;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import ShipmentContext from"../context/ShipmentContext";const propTypes=components.ShippingMethodRadioButton.propTypes,displayName=components.ShippingMethodRadioButton.displayName;export function ShippingMethodRadioButton(props){const{onChange,...p}=props,[checked,setChecked]=useState(!1),{shippingMethod,currentShippingMethodId,shipmentId}=useContext(ShippingMethodChildrenContext),{setShippingMethod}=useContext(ShipmentContext),shippingMethodId=shippingMethod?.id,name=`shipment-${shipmentId}`,id=`${name}-${shippingMethodId}`;useEffect(()=>(setChecked(shippingMethodId===currentShippingMethodId),()=>{setChecked(!1)}),[currentShippingMethodId]);const handleOnChange=async()=>{shipmentId&&shippingMethodId&&(setChecked(!0),await setShippingMethod(shipmentId,shippingMethodId),shippingMethod&&onChange&&onChange(shippingMethod,shipmentId))},parentProps={shippingMethod,shipmentId,handleOnChange,name,id,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("input",{type:"radio",name,id,onChange:handleOnChange,checked,...p})}ShippingMethodRadioButton.propTypes=propTypes,ShippingMethodRadioButton.displayName=displayName;export default ShippingMethodRadioButton;
|