### Scaffold Nube App with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Commands to create a new Nube App using different package managers. This process downloads and runs the create-nube-app CLI to guide you through project setup. ```bash npm create nube-app@latest ``` ```bash yarn create nube-app ``` ```bash pnpm create nube-app ``` ```bash bun create nube-app ``` -------------------------------- ### Example Development Mode Response Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started An example of the expected output when the development mode is active and the verification command is executed. It shows the structure of the application's state within the NubeSDK. ```json { "1028": { "id": "1028", "script": "http://localhost:8080/main.min.js", "registered": true } } ``` -------------------------------- ### Tsup Configuration for Nube SDK Projects Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Example tsup configuration file (tsup.config.js) for building Nube SDK projects. It specifies entry points, formats, target, minification, and JSX aliasing. ```javascript //tsup.config.js import { defineConfig } from "tsup"; export default defineConfig({ entry: ["src/main.tsx"], format: ["esm"], target: "esnext", clean: true, minify: true, bundle: true, sourcemap: false, splitting: false, skipNodeModulesBundle: false, esbuildOptions(options) { // ONLY IF YOU USE JSX options.alias = { "@tiendanube/nube-sdk-jsx/dist/jsx-runtime": "@tiendanube/nube-sdk-jsx/jsx-runtime", }; }, outExtension: ({ options }) => ({ js: options.minify ? ".min.js" : ".js" }) }); ``` -------------------------------- ### Install Tsup for Building with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Installs tsup as a development dependency, a tool recommended for building Nube SDK projects, as it comes pre-configured in official templates. ```bash npm install -D tsup ``` ```bash yarn add -D tsup ``` ```bash pnpm add -D tsup ``` ```bash bun add -D tsup ``` -------------------------------- ### Install Nube SDK UI Package with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Installs the @tiendanube/nube-sdk-ui package, which is necessary for developing applications with a user interface. ```bash npm install @tiendanube/nube-sdk-ui ``` ```bash yarn add @tiendanube/nube-sdk-ui ``` ```bash pnpm add @tiendanube/nube-sdk-ui ``` ```bash bun add @tiendanube/nube-sdk-ui ``` -------------------------------- ### Install Nube SDK JSX Package with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Installs the @tiendanube/nube-sdk-jsx package for projects that utilize JSX/TSX syntax. ```bash npm install @tiendanube/nube-sdk-jsx ``` ```bash yarn add @tiendanube/nube-sdk-jsx ``` ```bash pnpm add @tiendanube/nube-sdk-jsx ``` ```bash bun add @tiendanube/nube-sdk-jsx ``` -------------------------------- ### Start Development Server (Bun) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Starts the local development server using Bun. Bun is a fast all-in-one JavaScript runtime, bundler, transpiler, and package manager. ```bash bun run dev ``` -------------------------------- ### Start Development Server (npm) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Starts the local development server using npm. This command is typically used after creating an application with the create-nube-app CLI. ```bash npm run dev ``` -------------------------------- ### Nube App Entrypoint Example (main.ts) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started An example of a main entry point file for a Nube App using TypeScript. It imports the NubeSDK type and exports an async function to initialize the app. ```typescript // main.ts import type { NubeSDK } from "@tiendanube/nube-sdk-types"; export async function App(nube: NubeSDK) { // your code } ``` -------------------------------- ### Install Nube SDK Types with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Installs TypeScript and the @tiendanube/nube-sdk-types package as development dependencies. This is required for accessing all Nube SDK functionalities. ```bash npm install -D typescript @tiendanube/nube-sdk-types ``` ```bash yarn add -D typescript @tiendanube/nube-sdk-types ``` ```bash pnpm add -D typescript @tiendanube/nube-sdk-types ``` ```bash bun add -D typescript @tiendanube/nube-sdk-types ``` -------------------------------- ### Start Development Server (Yarn) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Starts the local development server using Yarn. This command is an alternative to npm for managing project dependencies and running scripts. ```bash yarn dev ``` -------------------------------- ### Start Development Server (pnpm) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Starts the local development server using pnpm. pnpm is a performant package manager that enforces a strict node_modules structure. ```bash pnpm run dev ``` -------------------------------- ### Build Script with npm, Yarn, pnpm, Bun Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Commands to execute the build process for your Nube application script using various package managers. This step is crucial before adding your script to the application. ```bash npm run build ``` ```bash yarn build ``` ```bash pnpm run build ``` ```bash bun run build ``` -------------------------------- ### TypeScript Compiler Options for Nube SDK Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Recommended TypeScript compiler options for Nube SDK projects. Includes settings for target, JSX, module resolution, and strictness. ```json { "compilerOptions": { "target": "esnext", "jsx": "react-jsx", "jsxImportSource": "@tiendanube/nube-sdk-jsx/dist", // ONLY IF YOU USE JSX "module": "commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true } } ``` -------------------------------- ### Verify Development Mode Configuration Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/getting-started Executes a command in the browser console to verify if the development mode is active and correctly configured. It checks the NubeSDK state for application details. ```javascript nubeSDK.getState().apps; ``` -------------------------------- ### Access Available Theme Tokens Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Provides examples of accessing various theme tokens for colors, borders, and component-specific styling properties from the `theme` object. ```javascript import { theme } from "@tiendanube/nube-sdk-ui"; // Colors theme.color.accent // Primary accent color theme.color.main.foreground // Main text color theme.color.main.background // Main background color // Borders theme.border.color // Default border color theme.border.radius // Default border radius // Component-specific tokens theme.button.foreground // Button text color theme.button.background // Button background color theme.button.borderColor // Button border color theme.button.borderRadius // Button border radius theme.input.border.color // Input border color theme.header.foreground // Header text color theme.header.background // Header background color theme.header.logo.maxWidth // Header logo max width theme.header.logo.fontSize // Header logo font size theme.footer.foreground // Footer text color theme.footer.background // Footer background color theme.heading.font // Heading font family theme.heading.fontWeight // Heading font weight ``` -------------------------------- ### Complete Component with Multiple Styling Approaches Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Provides a comprehensive example of a React component that utilizes both `StyleSheet.create` for reusable styles and `styled()` for dynamic styling, demonstrating a complete integration of NubeSDK UI styling features. ```jsx import { styled, StyleSheet, theme } from "@tiendanube/nube-sdk-ui"; import { Box, Button, Text } from "@tiendanube/nube-sdk-jsx"; // Reusable styles const styles = StyleSheet.create({ container: { backgroundColor: theme.color.main.background, borderRadius: theme.border.radius, padding: "24px", }, title: { color: theme.color.main.foreground, fontSize: "24px", fontWeight: "bold", marginBottom: "16px", }, }); // Static styled component const StyledButton = styled(Button)` background-color: ${theme.color.accent}; color: white; padding: 12px 24px; border-radius: ${theme.border.radius}; border: 1px solid ${theme.border.color}; transition: all 0.2s; &:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } `; // Usage Welcome to NubeSDK Get Started ``` -------------------------------- ### Accordion Usage Example Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/accordion Demonstrates how to use the Accordion component with its subcomponents. It shows how to set a default expanded item and apply custom styles. ```jsx import { Accordion } from "@tiendanube/nube-sdk-jsx"; Accordion Item 1 Accordion Content 1 Accordion Item 2 Accordion Content 2 ; ``` -------------------------------- ### Display Image with Nuvemshop SDK JSX Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/image This example demonstrates how to use the Image component from the Nuvemshop SDK JSX to display a basic image. It requires the 'src' and 'alt' properties for the image source and accessibility. ```jsx import { Image } from "@tiendanube/nube-sdk-jsx"; function MyComponent() { return ( Nuvemshop Logo ); } ``` -------------------------------- ### Render Toast Component in UI Slot Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/toast This example demonstrates how to import and use the Toast component from '@tiendanube/nube-sdk-jsx'. It shows how to create a Toast with a title and description, and then send it to a specific UI slot (corner_bottom_right) using the NubeSDK. ```JavaScript import type { NubeSDK } from "@tiendanube/nube-sdk-types"; import { Toast } from "@tiendanube/nube-sdk-jsx"; const ToastComponent = () => ( Success! Your changes have been saved. ); export function App(nube: NubeSDK) { nube.send("ui:slot:set", () => ({ ui: { slots: { corner_bottom_right: , }, }, })); } ``` -------------------------------- ### Configuring Cart Validation - TypeScript Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/script-structure Demonstrates how to configure the script's behavior by dispatching the 'config:set' event. This example enables cart content validation. ```TypeScript import type { NubeSDK } from "@tiendanube/nube-sdk-types"; export function App(nube: NubeSDK) { // Tell NubeSDK that this script wants to validate the content of the cart nube.send("config:set", () => ({ config: { has_cart_validation: true }, })); } ``` -------------------------------- ### Render Text with Color and Background Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/text Demonstrates how to use the Text component to display text with specified color and background styles. This example utilizes the '@tiendanube/nube-sdk-jsx' library. ```jsx import { Box, Text } from "@tiendanube/nube-sdk-jsx"; function MyComponent() { return ( Hello!! ); } ``` -------------------------------- ### Render and Clear Components in Slots using NubeSDK Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components Demonstrates how to render UI components into specific slots within the application and how to clear them. This is achieved using the `nube.render()` and `nube.clearSlot()` methods, respectively. The example uses the `Text` component from the `@tiendanube/nube-sdk` library. ```javascript import { Text } from "@tiendanube/nube-sdk"; // Render a component into a slot nube.render("after_address_form", Hello World); // Clear a component from a slot nube.clearSlot("after_address_form"); ``` -------------------------------- ### Styled Component with Complex Animations Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Provides an example of creating a styled component with complex animations using multiple keyframes. It defines 'bounce' and 'fadeInUp' animations and applies them conditionally on hover. ```javascript const bounce = keyframes` 0%, 20%, 53%, 80%, 100% { transform: translate3d(0, 0, 0); } 40%, 43% { transform: translate3d(0, -30px, 0); } 70% { transform: translate3d(0, -15px, 0); } 90% { transform: translate3d(0, -4px, 0); } `; const fadeInUp = keyframes` 0% { opacity: 0; transform: translate3d(0, 40px, 0); } 100% { opacity: 1; transform: translate3d(0, 0, 0); } `; const AnimatedComponent = styled(box)` animation: ${bounce} 1s ease-in-out infinite; &:hover { animation: ${fadeInUp} 0.6s ease-out; } `; ``` -------------------------------- ### Display Image with Responsive Sources in Nuvemshop SDK JSX Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/image This example shows how to configure the Image component with responsive sources using media queries. The 'sources' property accepts an array of ImageSource objects, each with a 'src' and an optional 'media' query to adapt the image based on screen size. ```jsx export function Logo() { return ( Hello ); } ``` -------------------------------- ### Get Browser APIs with Nuvemshop SDK Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/script-structure Demonstrates how to retrieve browser-specific APIs using the `getBrowserAPIs()` method provided by the Nuvemshop SDK. These APIs enable interactions with the browser environment, including making HTTP requests and accessing `localStorage`. ```typescript import type { NubeSDK } from "@tiendanube/nube-sdk-types"; export function App(nube: NubeSDK) { // Get browser APIs const browser = nube.getBrowserAPIs(); // Use browser APIs for various operations // Example: Making HTTP requests, accessing localStorage, etc. } ``` -------------------------------- ### Rendering Static and Dynamic Components - TypeScript Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/script-structure Illustrates how to use the 'render' method to display components in UI slots. It shows rendering a static 'Hello World' text and a dynamic component that displays the number of items in the cart. ```TypeScript import type { NubeSDK } from "@tiendanube/nube-sdk-types"; import { Text } from "@tiendanube/nube-sdk"; export function App(nube: NubeSDK) { // Render a static component nube.render("after_address_form", Hello World); // Render a dynamic component based on state nube.render("after_contact_form", (state) => { const cartItems = state.cart.items.length; return ( You have {cartItems} items in your cart ); }); } ``` -------------------------------- ### Responsive Design with Media Queries Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Shows how to implement responsive layouts using media queries within styled components to adapt styles based on screen size. ```javascript const ResponsiveContainer = styled(box)` padding: 16px; flex-direction: column; @media (min-width: 768px) { padding: 24px; flex-direction: row; } `; ``` -------------------------------- ### Configure Script Initialization Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/events This snippet shows how to use the `config:set` event, dispatched by `script`, to set initial configuration for the script. This includes enabling features like cart validation. ```javascript nube.send("config:set", () => ({ config: { has_cart_validation: true }, })); ``` -------------------------------- ### Responsive Box with Media Queries Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Illustrates how to apply responsive styles to a Box component using media queries within the `styled()` function. It changes padding and background color based on screen width. ```javascript const ResponsiveBox = styled(Box)` background-color: red; padding: 16px; @media (max-width: 768px) { padding: 8px; background-color: blue; } @media (min-width: 1024px) { padding: 24px; background-color: green; } `; ``` -------------------------------- ### Create Reusable Styles with StyleSheet.create (UI SDK) Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/styling Demonstrates using `StyleSheet.create` with components from the UI SDK for creating type-safe styles. Requires `@tiendanube/nube-sdk-ui`. ```javascript import { StyleSheet } from "@tiendanube/nube-sdk-ui"; import { box, button } from "@tiendanube/nube-sdk-ui"; const styles = StyleSheet.create({ container: { backgroundColor: "red", padding: "16px", borderRadius: "8px", }, button: { backgroundColor: "blue", color: "white", padding: "12px 24px", }, }); box({ style: styles.container, children: [ button({ style: styles.button, children: "Click me" }) ] }); ``` -------------------------------- ### Get Current Nuvemshop SDK State Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/state Demonstrates how to retrieve the current application state using the `getState` function from the Nuvemshop SDK. This is useful for accessing initial application data and configurations. ```typescript import { NubeSDK, NubeSDKState } from '@tiendanube/nube-sdk-types'; export function App(nube: NubeSDK) { // Get current state const currentState: Readonly = nube.getState(); // Access state properties const cartTotal = currentState.cart.total; const storeCurrency = currentState.store.currency; const currentPage = currentState.location.pageType; } ``` -------------------------------- ### Implement Select Dropdown with JSX Source: https://dev.nuvemshop.com.br/es/docs/applications/nube-sdk/components/select Demonstrates how to use the Select component from the Nuvemshop SDK (nube-sdk-jsx) to create a dropdown input. It shows how to define options, set an initial value, and handle the onChange event. ```jsx import { Box, Select } from "@tiendanube/nube-sdk-jsx"; function MyComponent() { return (