ShipEngine Elements is a collection of React components that provide shipping functionality through a standardized interface.
This guide provides the essential steps for creating new elements in the ShipEngine Elements library.
Element Architecture
Each element is composed of:
Component: Your main React component logic
createElement Wrapper: Provides error boundaries, i18n, and styling
Element Provider: Manages global state and configuration
File Structure
libs/elements/src/elements/new-element/├── index.ts # Export file├── new-element.tsx # Main element file├── __stories__/ # Storybook stories│ └── new-element.stories.tsx└── __tests__/ # Jest tests └── new-element.test.tsx
import { ErrorFallback } from "@components/error-fallback";import { Button, Typography } from "@shipengine/giger";import { useTranslation } from "react-i18next";import { createElement } from "../../create-element";import { en } from "../../locales";/** * Props for the NewElement component */export type NewElementProps = { /** Optional title to display */ title?: string; /** Callback function when action is performed */ onClick?: (value: any) => void;};
3. Create the Index File
libs/elements/src/elements/new-element/index.ts
export * as NewElement from "./new-element";export type { NewElementProps } from "./new-element";
4. Add Localization Resources
libs/elements/src/locales/en/new-element.json
{ "description": "This is a new Element!", "actionButton": "Continue"}