Zeego Documentation

repository·master·Indexed 25 days ago

https://github.com/nandorojo/zeego

A cross-platform menu library for React Native and Web that provides a Radix UI-inspired developer experience while leveraging native UI elements on iOS and Android. Zeego offers a unified API for components like ContextMenu and DropdownMenu, supporting features such as submenus, checkable items, and native icons (SF Symbols and Material Icons). It is 100% unstyled and compatible with Solito, Next.js, Expo, and vanilla React Native.

Tokens
18.7K
Snippets
41
Records
72
Agent score
79%

What's inside Zeego

  1. Overview of Zeego

    master

    Zeego provides beautiful, native menus for React Native and Web applications, drawing inspiration from Radix UI. It offers a unified API that works across platforms, ensuring a consistent developer experience whether you are building for iOS, Android, or the Web.

    Key features include:

    • Cross-platform API: Use the same API for Web, iOS, and Android.
    • Native Elements: Utilizes native elements on iOS and Android where possible.
    • Framework Compatibility: Works with Solito, Next.js, Expo (using custom dev clients), and vanilla React Native.
    • Unstyled Components: 100% unstyled, giving you full control over the visual design.
  2. What is Zeego?

    master

    Zeego is a library for creating beautiful, native menus for React Native and Web applications. It is inspired by Radix UI and provides a unified API that works across different platforms:

    • iOS/Android: Uses native elements for a truly native experience.
    • Web: Uses Radix UI to provide high-quality web menus.
    • Styling: All components are 100% unstyled, allowing you to apply your own designs without fighting default styles.
    • Compatibility: Works with Solito, Next.js, Expo (via custom dev clients), and vanilla React Native.
  3. Use the Context Menu component

    master

    The ContextMenu is a component anchored to an element. Its trigger mechanism varies by platform: on Web, it is triggered by a right-click (using Radix UI), while on iOS & Android, it is triggered by a long press (using native platform components).

    Features

    • Web: Supports submenus, checkable items (single/multiple/indeterminate), modal/non-modal modes, custom alignment/offsets, and full keyboard navigation.
    • Mobile: Supports custom element previews on iOS, SF Symbols with color customization on iOS, and Android system icons.
    • General: Supports items, labels, groups, and images on menu items.
    import * as ContextMenu from 'zeego/context-menu'
    
    export function MyMenu() {
      return (
        <ContextMenu.Root>
          <ContextMenu.Trigger>
            <Button />
          </ContextMenu.Trigger>
    
          <ContextMenu.Content>
            <ContextMenu.Preview>{() => <Preview />}</ContextMenu.Preview>
    
            <ContextMenu.Label />
            <ContextMenu.Item>
              <ContextMenu.ItemTitle />
            </ContextMenu.Item>
    
            <ContextMenu.Group>
              <ContextMenu.Item />
            </ContextMenu.Group>
    
            <ContextMenu.CheckboxItem>
              <ContextMenu.ItemIndicator />
            </ContextMenu.CheckboxItem>
    
            <ContextMenu.Sub>
              <ContextMenu.SubTrigger />
              <ContextMenu.SubContent />
            </ContextMenu.Sub>
    
            <ContextMenu.Separator />
            <ContextMenu.Arrow />
          </ContextMenu.Content>
        </ContextMenu.Root>
      )
    }
  4. Styling Zeego components

    master

    All Zeego primitives are unstyled by default.

    • Web: Styles applied to your primitives will be visible.
    • iOS/Android: Your apps will use native menu components. Aside from the Trigger component (which you style manually), the rest of the menu elements use native system styling.

    Best Practice: Apply styles within your primitive definition file (the file where you use create()) to maintain a consistent design system throughout your application.

  5. How Dropdown Menu platform behavior works

    master

    Zeego's DropdownMenu adapts its implementation based on the target platform:

    • Web: Uses Radix UI's unstyled Dropdown Menu component.
    • iOS & Android: Uses each platform's built-in native menu component.

    This ensures that while you use a unified API, the user experience remains native on mobile devices (including features like SF Symbols on iOS and system icons on Android) and follows standard web patterns on the web.

  6. Avoid direct wrapping of Zeego elements in React components

    master

    Do not attempt to wrap Zeego elements in standard React components without using the create() utility. Doing so will cause the components to fail on iOS and Android.

    Incorrect Pattern:

    const Content = () => {
      return (
        <DropdownMenu.Content>
          <DropdownMenu.Item />
        </DropdownMenu.Content>
      )
    }

    Correct Pattern (Inline):

    export default function Menu() {
      return (
        <DropdownMenu.Root>
          <DropdownMenu.Content>
            <DropdownMenu.Item />
          </DropdownMenu.Content>
        </DropdownMenu.Root>
      )
    }

    Correct Pattern (Custom Component): Use DropdownMenu.create() to define a custom component if you need to abstract the UI.

  7. Zeego Design Philosophy

    master

    Zeego follows several core principles to ensure a high-quality developer and user experience:

    1. Platform-Specific Optimization: Create the best experience for each specific platform (native on mobile, Radix on web).
    2. Composable API: Uses a clean, composable API instead of requiring a single items array for configuration.
    3. Style Independence: Does not attempt to share styles across platforms; instead, it focuses on functional parity.
    4. Native Reliance: Relies on built-in native menus for iOS and Android to ensure accessibility and performance.
    5. Unstyled Components: Everything ships unstyled to give developers full control over the UI.
  8. How to use ItemTitle with React element children

    master

    While DropdownMenu.ItemTitle commonly accepts a string, it can also accept a React element (like a custom <Text> component).

    Requirement: If you pass a React element as a child to ItemTitle, you must provide a textValue prop to the parent DropdownMenu.Item.

    • On Web: textValue is used for typeahead functionality but does not affect rendering.
    • On iOS/Android: textValue is used as the actual title for the native menu item.
    <DropdownMenu.Item
      // this is required when ItemTitle has a React element child
      textValue="Cars"
      key="cars"
    >
      <DropdownMenu.ItemTitle>
        <Text>
          Cars
        </Text>
      </DropdownMenu.ItemTitle>
    </DropdownMenu.Item>