Pular para o conteúdo principal

UI Components

danger

This SDK is a Work In Progress! All features are subject to change.

We support multiple UI components built in JSX, some of which support nesting, to enable the creation of rich user interfaces. The UI components are assigned to slots by sending the ui:slot:set event.

Box

Box container, supports multiple sizes, styling and alignment options. It's used mostly to embed other components that don't have their own layout options (fields, texts, images, etc..)

Box

Example
import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { Box, Txt } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box width={100} height={200}>
<Txt>Hello!!</Txt>
</Box>
);
}

export function App(nube: NubeSDK) {
nube.send("ui:slot:set", () => ({
ui: {
slots: {
after_line_items: <MyComponent />,
},
},
}));
}

Checkbox

Checkbox allows the user to select one or more items from a set. Checkboxes can be used to turn an option on or off.

Example
import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { Box, Checkbox } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box>
<Checkbox
id="my-checkbox"
label="Checkbox"
name="checkbox"
onChange={(e) => {
console.log(`User name: ${e.value}`);
}}
/>
</Box>
);
}

export function App(nube: NubeSDK) {
nube.send("ui:slot:set", () => ({
ui: {
slots: {
after_line_items: <MyComponent />,
},
},
}));
}

Column

Column container, layouts children in a column, supports multiple sizes, styling and alignment options.

Column

Example
import { Column, Text } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Column width={100} height={200}>
<Text>Hello 1</Text>
<Text>Hello 2</Text>
</Column>
);
}

Row

Row container, layouts children in a row, supports multiple sizes, styling and alignment options.

Row

Example
import { Row, Txt } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Row width={100} height={200}>
<Txt>Hello!!</Txt>
</Row>
);
}

Text

Text component supports multiple styles. It needs to be embedded inside a box to control anything related to layout.

Text

Example
import { Box, Text } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box>
<Text color="red" background="blue">Hello!!</Text>
</Box>
);
}

Button

Button supports multiple styles and click event. It should be embedded inside a container to control layout.

Button

Button Props

PropTypeDefaultDescription
idstringUnique identifier for the Button.
childrenstringText displayed on the Button.
onClick(event) => voidFunction called when the Button is clicked.
variantstring"primary"Defines the style variation of the Button (e.g., primary, secondary).
disabledbooleanfalseDisables the Button when true.
Example
import { Button } from "@tiendanube/nube-sdk-jsx";

export function Component() {
return (
<Button
onClick={() => {
console.log("Button clicked!");
}}
variant="primary"
>
Hello World!
</Button>
);
}

Field

Text input field, supports multiple styles and change events / focus events. It needs to be embedded inside a box to control anything related to layout.

Properties

PropertyTypeRequiredDescription
namestringYesThe name of the field, used to identify it in forms.
labelstringYesThe label text displayed above the field.
valuestringNoThe current value of the field input.
autoFocusbooleanNoWhether the field should automatically receive focus when mounted.
onChangeNubeComponentFieldEventHandlerNoFunction called when the field value changes.
onBlurNubeComponentFieldEventHandlerNoFunction called when the field loses focus.
onFocusNubeComponentFieldEventHandlerNoFunction called when the field receives focus.

Field

Example
import { Box, Field } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box>
<Field
id="myField"
label="Field"
value="value"
name="field"
onChange={(e) => {
console.log(`value: ${e.value}`);
}}
/>
</Box>
);
}

Textarea

Multi-line text input for extended content.

Properties

PropertyTypeRequiredDescription
namestringYesThe name of the textarea, used to identify it in forms.
labelstringYesThe label text displayed above the textarea.
valuestringNoThe current value of the textarea.
maxLengthnumberNoThe maximum number of characters allowed in the textarea.
rowsnumberNoThe number of visible text lines in the textarea.
autoFocusbooleanNoWhether the textarea should automatically receive focus when mounted.
onChangeNubeComponentTextareaEventHandlerNoFunction called when the textarea value changes.
onBlurNubeComponentTextareaEventHandlerNoFunction called when the textarea loses focus.
onFocusNubeComponentTextareaEventHandlerNoFunction called when the textarea receives focus.
Example
import { Box, Textarea } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box>
<Textarea
id="my-textarea"
maxLength={300}
row={3}
label="Textarea"
name="txtarea"
onChange={(e) => {
console.log(`value: ${e.value}`);
}}
/>
</Box>
);
}

Image

Displays an image. It needs to be embedded inside a box to control anything related to layout.

Field

Example
import { Col, Image } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Col width={100} height={200}>
<Image
src="https://app-insti-cdn.nuvemshop.com.br/site/dist/images/widgets/closing-cta/image-3.webp"
alt="Nuvemshop Logo"
/>
</Col>
);
}

Optionally, the Img component can receive alternative sources loaded by media query.

Example
export function Logo() {
return (
<Image
src="https://hostname/default.png"
alt="Hello"
sources={[
{
src: "https://hostname/desktop.png",
media: "(min-width: 769px)",
},
{
src: "https://hostname/mobile.png",
media: "(max-width: 768px)",
},
]}
/>
);
}