For the complete documentation index, see llms.txt. This page is also available as Markdown.

Composables

The Crane API provides Vue 3 composables for accessing content and design data inside your section components. These composables return reactive objects that update automatically when merchants edit values in the Instant Site Editor.

import { useInputboxElementContent, useTextElementDesign } from '@lightspeed/crane-api';

Content Composables

Content composables provide access to user-editable content defined in Content Editors.

Available Composables

Composable
Editor Type
Return Type
Purpose

useInputboxElementContent

INPUTBOX

Reactive<InputBoxContent>

Single-line text input

useTextareaElementContent

TEXTAREA

Reactive<TextAreaContent>

Multi-line text input

useButtonElementContent

BUTTON

Reactive<ButtonContentData>

Button with text and link

useImageElementContent

IMAGE

Reactive<ImageContent>

Image upload and settings

useToggleElementContent

TOGGLE

Reactive<ToggleContent>

Boolean toggle switch

useSelectboxElementContent

SELECTBOX

Reactive<SelectBoxContent>

Dropdown selection

useDeckElementContent

DECK

Reactive<DeckContent>

Collection of cards

useCategorySelectorElementContent

CATEGORY_SELECTOR

Reactive<CategorySelector>

Category picker

useProductSelectorElementContent

PRODUCT_SELECTOR

Reactive<ProductSelector>

Product picker

useLogoElementContent

LOGO

Reactive<LogoContent>

Logo image

useAccordionElementDesign

ACCORDION

Reactive<AccordionDesignData>

Accordion nested editors

useMenuElementContent

MENU

Reactive<MenuContent>

Menu items

useNavigationMenuElementContent

NAVIGATION_MENU

Reactive<MenuContent>

Navigation menu

useTranslation

Translation helper

Multi-language support

Return Properties

Text Composables (useInputboxElementContent, useTextareaElementContent):

  • hasContenttrue if field has non-empty text

  • value — the text string

Button Composable (useButtonElementContent):

  • title — button text label

  • hasTitletrue if button has text

  • hasLinktrue if button has a link configured

  • performAction() — triggers the button action (navigation, scroll, etc.)

  • type — action type (HYPER_LINK, MAIL_LINK, TEL_LINK, etc.)

  • link, email, phone — target values based on type

Image Composable (useImageElementContent):

  • hasContenttrue if an image is uploaded

  • lowResolutionMobileImage — URL for mobile placeholder (100x200)

  • highResolutionMobileImage — URL for mobile full quality (1000x2000)

  • lowResolutionDesktopImage — URL for desktop placeholder (200x200)

  • highResolutionDesktopImage — URL for desktop full quality (2000x2000)

Example

sliders

Key Mapping

The string passed to each composable (e.g., 'title', 'hero_image') must match a key in your content.ts settings file.

Design Composables

Design composables provide access to styling settings defined in Design Editors

Available Composables

Composable
Editor Type
Return Type
Purpose

useTextElementDesign

TEXT

Reactive<TextDesignData>

Text styling (font, size, color)

useTextareaElementDesign

TEXTAREA

Reactive<TextareaDesignData>

Textarea styling

useButtonElementDesign

BUTTON

Reactive<ButtonDesignData>

Button styling

useBackgroundElementDesign

BACKGROUND

Reactive<BackgroundDesignData>

Background color/image

useImageElementDesign

IMAGE

Reactive<ImageDesignData>

Image styling

useToggleElementDesign

TOGGLE

Reactive<ToggleDesignData>

Toggle styling

useSelectboxElementDesign

SELECTBOX

Reactive<SelectboxDesignData>

Selectbox styling

useLayoutElementDesign

Reactive<LayoutDesignData>

Layout settings

useLogoElementDesign

LOGO

ComputedRef<LogoDesignData>

Logo styling

Return Properties

Text Composables (useTextElementDesign, useTextareaElementDesign):

  • visibletrue if element should be displayed

  • size — font size as number (append 'px' for CSS)

  • font — font family string

  • color — Color object with .hex, .rgba, .hsl properties

  • boldtrue if text should be bold

  • italictrue if text should be italic

  • whiteSpace — (textarea only) white-space CSS value

Background Composable (useBackgroundElementDesign):

  • background.type'solid' or 'gradient'

  • background.solid.color — Color object for solid backgrounds

  • background.gradient.fromColor / toColor — Color objects for gradients

Button Composable (useButtonElementDesign):

  • visibletrue if button should be displayed

  • appearance'solid-button', 'outline-button', or 'text-link'

  • size'small', 'medium', or 'large'

  • style'pill', 'rectangle', or 'round-corner'

  • color — Color object

  • font — font family string

Example

Accordion Composable

The useAccordionElementDesign composable provides access to design editors nested inside an ACCORDION design editor. It returns a reactive object containing items, where each item holds a label and an editors map of nested design editor values.

Usage

tag

Key Mapping

The first argument to useAccordionElementDesign (e.g., 'styling') must match the key in your design.ts settings file. Access nested editors via items?.['itemKey']?.editors?.editorKey.

Responsive Images

The image composable provides multiple resolution variants for responsive designs:

For programmatic control, use a reactive width check:

Working with DECK

The DECK composable returns a collection of cards. Use getReactiveRef to access individual card fields. When a card’s settings include a nested DECK – slides with link decks – pass EditorTypes.DECK as the editor type to get a reactive deck content object with the same shape (hasContent, cards, getReactiveRef), subject to the max nesting depth of one level.

Type Casting

Use the as unknown as Type casting pattern for getReactiveRef results, as shown above.

Translation

Use useTranslation for static multi-language text defined in your translations file:

Static Text Only

Use useTranslation for static text only — text that is the same across all instances of the section. For merchant-editable text, use content composables like useInputboxElementContent.

TypeScript Types

Use InferContentType and InferDesignType to derive types from your settings files:

These utility types ensure type safety — the generic parameter on composables (e.g., useInputboxElementContent<Content>('title')) validates that the key exists in your settings.

Global Types

InferContentType and InferDesignType are globally available — no import needed.

Advanced Composables

These composables are exported from @lightspeed/crane-api for advanced use cases. Most sections won't need them.

useVueBaseProps

Low-level composable providing reactive access to the full section context:

  • context — store and environment information

  • content — raw content data

  • design — raw design data

  • defaults — default values

  • site — site configuration (languages, currency, etc.)

  • category — current category data (on category pages)

  • storeData — store metadata

  • globalDesign — global design settings (colors, fonts, text sizes)

  • tileId — the section's tile identifier

Use this when the typed content/design composables are not sufficient — for example, when accessing global design tokens directly or reading site-level configuration.

useInstantsiteJsApi

Returns window.instantsite — the platform's JavaScript API for interacting with the storefront runtime (e.g., triggering cart updates, navigation events).

Best Practices

Conditional Rendering

Always check hasContent or visible before rendering elements:

Computed Styles

Use computed properties for style objects to ensure reactivity:

SSR vs Client-Only Rendering

Sections use server-side rendering (SSR) — the Vue component renders to HTML on the server first, then hydrates in the browser. Browser APIs like window, document, and addEventListener are not available during SSR.

Guard browser values with typeof window:

Use onMounted for client-only logic:

Code inside onMounted only runs in the browser after hydration. Use it for event listeners, DOM measurements, animations, and any browser-API-dependent setup:

General rule: Keep <script setup> top-level code SSR-safe — composables, computed properties, and reactive refs with safe defaults. Move all browser-specific logic into onMounted. If a piece of UI should only render on the client, guard it with a ref that flips in onMounted:

Last updated

Was this helpful?