UIPackage React Native
Search

Surface

Themed native surface with optional platform elevation and caller-owned content.

Install

First install? Set up the registry in your app.

npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add surface

Source files

Expand a file to read the source the installer copies into your app.

components/ui/surface/Surface.tsx
import * as React from 'react'
import { View, type ViewProps, type ViewStyle } from 'react-native'
import { cn } from '@/lib/utils'

export interface SurfaceProps extends ViewProps {
  className?: string
  elevation?: 0 | 1 | 2
}

const elevations: Record<NonNullable<SurfaceProps['elevation']>, ViewStyle> = {
  0: {},
  1: {
    elevation: 1,
    shadowColor: '#000000',
    shadowOffset: { width: 0, height: 1 },
    shadowOpacity: 0.08,
    shadowRadius: 2,
  },
  2: {
    elevation: 2,
    shadowColor: '#000000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.12,
    shadowRadius: 4,
  },
}

export const Surface = React.forwardRef<React.ComponentRef<typeof View>, SurfaceProps>(
  ({ className, elevation = 0, style, ...props }, ref) => (
    <View ref={ref} {...props} className={cn('rounded-lg bg-card', className)} style={[elevations[elevation], style]} />
  ),
)
Surface.displayName = 'Surface'
components/ui/surface/index.ts
export * from './Surface'
Browse layout and navigation