HeroUI Native

repository·main·Indexed 25 days ago

https://github.com/heroui-inc/heroui-native

A beautiful, fast, and modern UI library for React Native development. It features a comprehensive set of accessible components, a theme system using CSS variables and Tailwind CSS v4 (via Uniwind), and a robust portal system. The library includes a wide range of components for layout, form inputs, feedback, data display, and navigation, all built upon unstyled primitives adapted from rn-primitives.

Tokens
111.4K
Snippets
299
Records
687
Agent score
85%

What's inside heroui-native

  1. Understand HeroUI Native Primitives

    main

    HeroUI Native primitives are unstyled, accessible base components designed to serve as the foundation for the HeroUI Native component library. They provide flexible composition patterns and support both controlled and uncontrolled component behavior while maintaining React Native compatibility.

    These primitives are adapted from the rn-primitives library with the following enhancements:

    • Stricter TypeScript compatibility and typing.
    • Integration with the HeroUI Native theme system.
    • Enhanced accessibility features.
    • Custom styling patterns aligned with HeroUI design principles.
  2. Understand HeroUI variable types

    main

    HeroUI uses three distinct categories of CSS variables to manage its design system:

    1. Base Variables: Static, non-changing values (e.g., --white, --black).
    2. Theme Variables: Semantic colors that automatically adapt between light and dark themes (e.g., --background, --foreground, --accent).
    3. Calculated Variables: Automatically generated values for interactive states (like hover/pressed) and size variants (like radius scales). These are often created using Tailwind's @theme directive and color-mix to ensure consistent contrast.
  3. Browse HeroUI Native components documentation

    main

    The heroui-native library provides a comprehensive set of UI primitives. You can find detailed documentation for each component in the src/components directory.

    Available components include:

    • Layout & Containers: Card, Surface, ScrollShadow, Tabs, Accordion, BottomSheet, Dialog, Popover, ListGroup.
    • Form Inputs: Button, Checkbox, Input, InputOTP, InputGroup, Radio, RadioGroup, Select, Slider, Switch, TextArea, TextField, SearchField.
    • Feedback & Status: Alert, Chip, Spinner, Toast, FieldError, PressableFeedback.
    • Data Display: Avatar, Description, Skeleton, SkeletonGroup, TagGroup, Text, Separator.
    • Navigation & Menus: Menu, LinkButton, CloseButton.
    • Form Helpers: ControlField, Label.
  4. Anatomy of the Radio component

    main

    The Radio component is composed of several parts that allow for deep customization of its visual structure:

    • Radio: The main container handling selection state and interaction. It can operate in standalone mode (using isSelected and onSelectedChange) or derive state automatically when placed inside a RadioGroup.Item.
    • Radio.Indicator: An optional container for the radio circle. It manages visual selection and invalid states.
    • Radio.IndicatorBackground: A theme-aware background container (e.g., glass) rendered behind the indicator. It is automatically mounted for the secondary variant when unselected and not invalid. You can control it via the background prop on Radio.Indicator.
    • Radio.IndicatorThumb: The inner circle that appears when the radio is selected. It features built-in scale animations.
    <Radio>
      <Radio.Indicator>
        <Radio.IndicatorThumb />
      </Radio.Indicator>
    </Radio>
  5. Anatomy of BottomSheet

    main

    The BottomSheet component uses a composition pattern with several sub-components:

    • BottomSheet: Root component managing open state and context.
    • BottomSheet.Trigger: Pressable element that opens the sheet.
    • BottomSheet.Portal: Renders content in a full window overlay.
    • BottomSheet.Overlay: Background overlay (typically closes the sheet when pressed).
    • BottomSheet.Content: Main container using @gorhom/bottom-sheet for gestures.
    • BottomSheet.Close: Close button (supports custom children).
    • BottomSheet.Title: Semantic heading for accessibility.
    • BottomSheet.Description: Description text for accessibility context.
  6. Anatomy of the Select component

    main

    The Select component is a compound component consisting of several parts that manage state, presentation, and item selection:

    • Select: Main container managing open/close state and value selection.
    • Select.Trigger: Clickable element to toggle visibility. Supports variant prop ('default' or 'unstyled').
    • Select.Value: Displays the selected value or placeholder text.
    • Select.TriggerIndicator: Optional animated chevron icon showing open/close state.
    • Select.Portal: Renders content in a portal layer for proper stacking.
    • Select.Overlay: Optional background overlay to capture outside clicks.
    • Select.Content: Container for items. Supports presentation modes: popover, bottom-sheet, or dialog.
    • Select.Close: Close button for the select.
    • Select.ListLabel: Styled typography for grouping items.
    • Select.Item: Selectable option. Contains Select.ItemLabel, Select.ItemDescription, and Select.ItemIndicator (default check icon).
  7. Anatomy of TagGroup

    main

    The TagGroup is a compound component consisting of the following parts:

    • TagGroup: The main container managing selection state, disabledKeys, and removal functionality. It provides size and variant context to children.
    • TagGroup.List: A container for rendering the list of tags. Supports renderEmptyState for custom empty state rendering.
    • TagGroup.Item: An individual tag. It can accept string children (auto-wrapped in TagGroup.ItemLabel), render function children, or custom layouts. Requires an id prop.
    • TagGroup.ItemBackground: An optional theme-aware background container. Can be replaced or removed via the background prop on TagGroup.Item.
    • TagGroup.ItemLabel: The text label for the tag. Use this explicitly if not providing string children.
    • TagGroup.ItemRemoveButton: A button to remove the tag. It only functions if onRemove is provided to the parent TagGroup.
    <TagGroup>
      <TagGroup.List>
        <TagGroup.Item id="tag-1">
          <TagGroup.ItemLabel>...</TagGroup.ItemLabel>
          <TagGroup.ItemRemoveButton />
        </TagGroup.Item>
      </TagGroup.List>
    </TagGroup>
  8. Anatomy of the Slider component

    main

    The Slider is a compound component consisting of several sub-components that manage state, orientation, and visual representation:

    • Slider: The main container managing value state and orientation. Supports single value and range modes.
    • Slider.Output: Displays the current value(s). Supports render functions for custom formatting.
    • Slider.Track: The sizing container for Fill and Thumb. Supports tap-to-position and render-function children for dynamic content like multiple thumbs.
    • Slider.TrackBackground: An optional theme-aware background container rendered behind the track. Can be replaced or removed via the background prop on Slider.Track.
    • Slider.Fill: A responsive bar that stretches along the track's main axis.
    • Slider.Thumb: The draggable element. Uses react-native-gesture-handler for interaction and react-native-reanimated for scale animations on press.
    <Slider>
      <Slider.Output />
      <Slider.Track>
        <Slider.Fill />
        <Slider.Thumb />
      </Slider.Track>
    </Slider>
  9. Anatomy of the Menu component

    main

    The Menu component is a compound component. Its structure typically includes:

    • Menu: Main container managing state and positioning.
    • Menu.Trigger: The element that toggles the menu.
    • Menu.Portal: Renders content in a portal layer.
    • Menu.Overlay: Optional background overlay to capture outside clicks.
    • Menu.Content: The container for items. Supports presentation="popover" or presentation="bottom-sheet".
    • Menu.Close: A button to dismiss the menu.
    • Menu.Label: Non-interactive section headings.
    • Menu.Group: Groups items and manages selection modes (none, single, or multiple).
    • Menu.Item: Individual pressable items.
    • Menu.ItemTitle: Primary text for an item.
    • Menu.ItemDescription: Secondary text for an item.
    • Menu.ItemIndicator: Visual selection indicator (checkmark or dot).
    • SubMenu: Container for nested menus.
    • SubMenu.Trigger: The row that toggles the submenu.
    • SubMenu.TriggerIndicator: Animated chevron icon.
    • SubMenu.Content: The container for items within a submenu.
    <Menu>
      <Menu.Trigger>...</Menu.Trigger>
      <Menu.Portal>
        <Menu.Overlay />
        <Menu.Content presentation="popover">
          <Menu.Close />
          <Menu.Label>...</Menu.Label>
          <Menu.Group>
            <Menu.Item>
              <Menu.ItemIndicator />
              <Menu.ItemTitle>...</Menu.ItemTitle>
              <Menu.ItemDescription>...</Menu.ItemDescription>
            </Menu.Item>
          </Menu.Group>
          <SubMenu>
            <SubMenu.Trigger textValue="...">
              <SubMenu.TriggerIndicator />
              ...
            </SubMenu.Trigger>
            <SubMenu.Content>
              <Menu.Item>...</Menu.Item>
              <Menu.Item>...</Menu.Item>
            </SubMenu.Content>
          </SubMenu>
        </Menu.Content>
      </Menu.Portal>
    </Menu>
  10. Setup Portals in HeroUI Native

    main

    Portals allow you to render children into a different part of your application, which is essential for components like modals, overlays, and popups that must appear above other content.

    By default, PortalHost is automatically included in the HeroUINativeProvider. This means the portal system is pre-configured and ready to use for all components that rely on portals without any manual setup.

  11. Create custom portal implementations with Portal and PortalHost

    main

    For advanced use cases, you can manually define where content is rendered by using Portal and PortalHost.

    1. Place a PortalHost with a specific name in the desired location of your component tree.
    2. Use a Portal component with a hostName prop that matches the name of the PortalHost to direct its children to that location.
    import { Portal, PortalHost } from "heroui-native";
    import { View, Text } from "react-native";
    
    function AppLayout() {
      return (
        <View className="flex-1">
          <View className="p-5">
            <Text>Header Content</Text>
          </View>
          
          <View className="flex-1 p-5">
            <Text>Main Content Area</Text>
            <CustomNotification />
          </View>
          
          {/* Portal host positioned at the top of the screen */}
          <PortalHost name="notification-host" />
        </View>
      );
    }
    
    function CustomNotification() {
      return (
        <Portal name="notification-portal" hostName="notification-host">
          <View className="absolute top-0 left-0 right-0 bg-blue-500 p-4">
            <Text>This notification appears at the top via Portal</Text>
          </View>
        </Portal>
      );
    }