Mobile and native apps
One markup for desktops, tablets and phones. Everything is responsive by default; turn on mobile and phones and tablets get the patterns of a native app instead: a tab bar or rail, a back button, a large title, bottom sheets and pinned actions. It is all web: no native code and no second set of components.
What changes where
Native mode is a mode for touch devices. Desktops look the same in both modes, so one build serves your website, your installed app and your app-store shell.
| Screen | Responsive web (default) | Native app (mobile) |
|---|---|---|
| Desktop 64rem and wider | Sidebar, foldable to icons and remembered; or a labelled rail; or a navigation row above the page. Detail pane as a third column. | |
| Tablet 40 to 64rem | Icon sidebar; the menu button opens the full sidebar over the page. Detail pane is a drawer from the end edge. | Labelled rail (icon over label). Back button instead of breadcrumbs. Detail pane beside the page. |
| Phone under 40rem | Drawer opened by the menu button. Breadcrumbs. Centred dialogs and anchored dropdowns. | Bottom tab bar with “More” when there are over five items. Back button, and the page title moves into the bar as you scroll. Search on its own row. Main actions pinned above the tab bar. Detail pane fills the screen. Bottom sheets. |
Sizes follow the width of the window, so a phone turned sideways or a narrow desktop window gets the layout that fits it.
App shell
<pm-app> lays out the navigation, the bar, the page and an optional detail pane, and picks the right navigation for the screen. It never moves or wraps your elements, so it is safe in every framework.
| You write | What it does |
|---|---|
layout="sidebar | rail | top" | Navigation on desktops. |
collapsible, persist="name" | The bar's menu button folds the sidebar to icons; the choice is remembered under that name. |
tablet-nav="rail | sidebar | drawer" | Navigation on tablets. |
mobile-nav="bar | drawer | none", max-tabs="5" | Navigation on native phones, and how many tabs fit before “More”. |
app.showDetail(), hideDetail() | Open and close the detail pane. Where it covers the page it takes focus, and Esc closes it and returns focus. |
<pm-app-bar back="/orders"> | A back button in native mode (a link, or history back when empty). Cancel pm-back to handle it yourself. show-back="always" shows it on the web too. |
<pm-app-bar nav-toggle> | The menu button. It shows only where there is something to open or fold. |
.pm-action-bar | The page's main actions: in the flow on the web, pinned above the tab bar on native phones. Works without the shell too. |
The shell reports what it chose: pm-layout-change carries { size, native, nav }, and the element has data-size, data-native and data-nav attributes to style against. The class names alone (class="pm-app" on a div) still give the responsive web layout without JavaScript.
Components in the two modes
| Responsive web | Native app, on phones | |
|---|---|---|
| Dialog | Centred, fits the width | Bottom sheet, swipe down to close (mobile-variant="center" or "fullscreen" to change) |
| Date, time and colour pickers, select, combobox | Dropdown kept inside the screen | Bottom sheet |
| Menu, context menu | Anchored popover | Action sheet with large rows; a long press opens context menus |
| Nav on its own | Sidebar | Bottom tab bar; parents open a sheet (mobile-variant="sidebar" | "none") |
| Data table | Rows become labelled cards in narrow containers (stack="never" keeps scrolling) | |
| Pagination | Collapses to ‹ 5 / 20 › | |
| Command palette | Full-width top sheet, so the keyboard never covers results | |
| Toasts | Full width, swipe sideways to dismiss, sit above the tab bar | |
| Controls | Touch targets of at least 44 px and 16 px input text on touch screens (no zoom on focus); safe-area insets respected | |
Turn it on
The nearest mobile attribute wins, through shadow roots. mobile="false" opts one area or component out.
Or decide at run time. autoNative() turns native layouts on when the page runs as an installed app or inside a native shell, and leaves the website responsive:
Add viewport-fit=cover to the viewport meta tag, so the safe-area insets (--pm-safe-top, --pm-safe-bottom) are available. A tab bar publishes its height as --pm-bottom-inset on the root for your own floating elements.
Helpers for app-like pages
Small functions in @prismora/elements/native (also exported from the package root). Each does nothing where the browser lacks the feature, and all are safe during server rendering.
Page changes can move like an app. Wrap your router's navigation in viewTransition: a new page slides in, going back slides it away, tabs cross-fade. Without view transitions, or with reduced motion, the update simply runs.
Ship it as an app
| Route | What you add |
|---|---|
| Installable web app | A web app manifest with "display": "standalone" and icons, served over HTTPS. autoNative() then switches layouts once the app is installed. |
| Capacitor (App Store and Google Play) | Build your site as static files and point Capacitor's webDir at them. isStandalone() is true inside the shell. Keep viewport-fit=cover. |
| Trusted Web Activity (Google Play) | The installable web app plus a Digital Asset Links file; Bubblewrap generates the Android project. |
Cost
Native mode adds no second set of components. The sheet helper (swipe and positioning) is about 1 KB gzip, shared by the overlays that use it. The app shell, the app bar and the helpers on this page are separate modules: a page that does not import them does not pay for them.