Elements React Components
The @shipengine/elements
package provides the full suite of ShipEngine Elements as React components.
Quick Start
Install Peer Dependencies:
Elements Provider
Render an Elements provider at the root of your React app so that it is available everywhere you need it.
Available to all descendants of the ElementsProvider
:
A batteries-included client for accessing ShipeEngine API endpoints with a shared cache and lifecycle management via react hooks.
A theme, which can be re-defined at instantiation via the
themeConfig
prop.Configurable features, available via the
features
prop.
Initialize Elements
Args/Props | Description |
---|---|
getToken | function, required A callback function that fetches and refreshes the tokens used by Elements. Check out the Elements Getting Started guide for more detailed information about generating Elements tokens. |
baseURL | string, optional A fully qualified domain name used as the base URL to route all API calls from the Elements. This is defaulted to https://elements.shipengine.com |
container | HTMLElement, optional A DOM element that the components will be mounted to. A shadow root will be created on this container. If not provided, the components will be mounted to a div with the ID elements-container , and a shadow root will be created on that div . |
defaultQueryClientOptions | object, optional Initialization options of the ReactQuery client. See the QueryClient Docs for more info. |
emotionCacheShadowRootContainer | ShadowRoot, optional Deprecated A reference to a shadow root used for isolating the Elements style sheets, CSS resets, and emotion.js cache. |
features | object, optional A feature flag configuration object for turning features on and off. See Configuring Elements Features for a comprehensive list of features. |
headers | object, optional Optional HTTP headers to be sent with all requests. |
locale | string, optional Defaults to en-us |
onApiError | object, optional Callback function that will be executed whenever there is an error within the API. |
onError | function, optional An optional callback function to be invoked when an error occurs during a request to the API. |
scope | string, optional Element id to apply the theme, font family, and CSS reset. By default, the font will be applied to the body element, and the reset will be applied to the root HTML element.configured. |
themeConfig | object, optional The theme configuration object. Check out the theming documentation to learn more about theming your Elements integration. |
Configuring Elements Features
Global Features
The following properties are configured within the globalFeatures
property.
Params | Description |
---|---|
enabledExternalCarriers | string[], optional List external carrier codes for carriers that can be registered through the Connect External Carrier Element. If this is omitted, external carriers cannot be registered. See the carriers section in the getting started guide for more information. IMPORTANT: If you exclude this property, or set the value to an empty array without including any supported carrier codes, users will not be able to view and connect External Carriers in the Account Settings Element. or the Manage External Carriers Element |
enabledShipEngineCarriers | string[], optional List of ShipEngine carrier codes for carriers that can be registered through the Onboarding Element. See the carriers section in the getting started guide for more information. IMPORTANT: If you exclude this property, or set the value to an empty array without including any supported carrier codes, users will encounter an error that will prevent them from advancing through the onboarding process within the Onboarding Element and will not be able to access the Carrier Services Element. |
poweredByShipEngine | boolean, optional Enables the Powered by ShipEngine logo in the footer various elements. |
Element specific Features
We recommend configuring the features you want to use in the Elements Provider or the SDK constructor for the Element. However, if you need to override features for a specific Element, you can use the feature prop for that Element, provided the Element supports it.
Params | Description |
---|---|
purchaseLabelFeatures | string[], optional See Purchase Label Features for a comprehensive list. |
shipmentSummaryFeatures | string[], optional See Shipment Summary Features for a comprehensive list. |
accountSettingsFeatures | string[], optional See Account Settings Features for a comprehensive list. |
labelsGridFeatures | string[], optional See Labels Grid Features for a comprehensive list. |
Creating Shipments
If you wish to purchase a label using pre-populated values in the PurchaseLabel forms, the recommended way to define the shipment values is to create a new shipment using the ShipEngine API, and then pass the new Shipment ID to the PurchaseLabel or LabelWorkflow Element.
The @shipengine/react-api package required by Elements includes hooks that can be used to perform API operations such as creating shipments. Note that these hooks must be used from a component within the context of your <ElementsProvider>
See the example below:
Only the shipTo
and shipFrom
properties are required; The rest may be left blank to be filled in by the user in the Element. The packages.products
array is used for Customs information, and is not generally required for local shipments.
For more information on the available fields within the Shipment object, see the ShipEngine API documentation. For additional functionality provided by the ShipEngine API React Hooks provided by Elements, see the Shipengine Elements API Clients documentation.