Skip to main content

Build your first app

This guide will walk you through creating a simple application using Apsara components. You’ll learn how to use layouts, buttons, and theme customization.
Make sure you’ve installed Apsara before starting this guide.
1

Import the required components

Start by importing the components and styles you’ll need:
App.tsx
The style.css import provides all the base styles for Apsara components.
2

Create a layout with Flex

Use the Flex component to create a flexible layout container:
App.tsx
The Flex component provides props for controlling flexbox layout:
  • direction: row, column, rowReverse, columnReverse
  • align: start, center, end, stretch, baseline
  • justify: start, center, end, between
  • gap: 1-9, extra-small, small, medium, large, extra-large
3

Add buttons with variants

Add buttons with different variants to your layout:
App.tsx
Buttons support multiple variants and colors:
  • Variants: solid, outline, ghost, text
  • Colors: accent, neutral, danger, success
  • Sizes: small, normal
4

Add loading states and icons

Buttons can show loading states and include icons:
App.tsx
Use loaderText to show text while loading, or omit it to show only the spinner.
5

Set up theme provider

Wrap your application with ThemeProvider to enable theming and dark mode:
App.tsx
The ThemeProvider accepts several props:
  • defaultTheme: “light”, “dark”, or “system”
  • style: Theme style variant
  • accentColor: Primary accent color
  • grayColor: Gray scale variant
  • enableSystem: Enable system theme detection (default: true)

Complete example

Here’s a complete working example that combines everything:
App.tsx

Using the useTheme hook

Access and control the theme programmatically using the useTheme hook:
The useTheme hook returns:
  • theme: Current theme setting (“light”, “dark”, or “system”)
  • setTheme: Function to change the theme
  • resolvedTheme: Actual theme being used (resolves “system” to “light” or “dark”)
  • systemTheme: The system’s preferred theme
  • themes: Array of available themes
Use resolvedTheme when you need to know the actual theme being displayed, especially when using “system” mode.

Layout patterns

Here are some common layout patterns using the Flex component:

Next steps

Now that you’ve built your first app with Apsara, explore more features:

Components

Explore all 55+ available components

Theming

Learn how to customize colors and styles

Dark mode

Implement dark mode in your app

Accessibility

Learn about accessibility features
All Apsara components are accessible by default and follow ARIA best practices.