Skip to main content

Theming

The package UI is neutral on purpose: it should look like the host app. You re-theme it through design tokens, never by editing the components.

Web: the --od-* tokens​

<OfflineDetector> renders one inline <style> element with the --od-* custom properties (light, and dark through prefers-color-scheme). Override any of them in your own CSS:

:root {
--od-color-action: #6d28d9;
--od-radius-md: 2px;
--od-font-family: 'Inter', system-ui, sans-serif;
}

The package's own --od-* declarations sit under :where() selectors, which weigh nothing, so a :root { ... } rule of yours like the one above wins wherever it sits in the cascade. Under a Content Security Policy, pass the same nonce your other inline styles use: <OfflineDetector nonce={nonce}> (or <OfflineTokens nonce={nonce} />).

Force a scheme with the colorScheme prop ('auto', 'light' or 'dark'). Anything but 'auto' wraps the tree in an element with data-od-theme and display: contents. You can also set data-od-theme="light" or "dark" yourself on <html>, on a [data-od-root] element or on any subtree.

Some tokens are for layout rather than looks: --od-offset-top and --od-offset-bottom move the pieces away from your own fixed bars, and --od-banner-height is published while the banner shows so other elements can stack against it.

No font is ever downloaded. Branding the type is your job, through --od-font-family.

All tokens​

Values are the defaults. An equals sign means the dark value is the same as the light one.

Colour​

TokenLightDark
--od-color-surface#ffffff#1c1c1e
--od-color-surface-raised#f4f5f7#2c2c2e
--od-color-surface-inverse#1f2328#f2f3f5
--od-color-text#1b1f23#f2f3f5
--od-color-text-muted#545b64#a8aeb7
--od-color-text-inverse#ffffff#1b1f23
--od-color-text-muted-inverse#c4c9d0#4a5058
--od-color-border#80878f#8a9099
--od-color-border-subtle#d9dce1#3a3a3c
--od-color-status-offline#b3261e#ff8a80
--od-color-status-offline-subtle#fdecea#4a1f1c
--od-color-status-online#1a7f37#4cc38a
--od-color-status-checking#8a5a00#f0b429
--od-color-action#0b5fd1#8ab4ff
--od-color-on-action#ffffff#0b1b33
--od-color-action-inverse#8ab4ff#0b5fd1
--od-color-focus-ring#0b5fd1#8ab4ff
--od-color-scrimrgba(0, 0, 0, 0.4)rgba(0, 0, 0, 0.6)

Spacing​

TokenLightDark
--od-space-xs4px=
--od-space-sm8px=
--od-space-md12px=
--od-space-lg16px=
--od-space-xl24px=
--od-space-2xl32px=

Radius​

TokenLightDark
--od-radius-sm4px=
--od-radius-md8px=
--od-radius-lg12px=
--od-radius-full999px=

Shadow​

TokenLightDark
--od-shadow-nonenone=
--od-shadow-chip0 1px 3px rgba(0, 0, 0, 0.2)=
--od-shadow-snackbar0 2px 8px rgba(0, 0, 0, 0.24), 0 1px 2px rgba(0, 0, 0, 0.16)=

Type​

TokenLightDark
--od-font-familysystem-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif=
--od-font-size-label12px=
--od-font-size-body14px=
--od-font-size-title16px=
--od-font-size-headline22px=
--od-font-weight-regular400=
--od-font-weight-medium500=
--od-font-weight-semibold600=

Line height​

TokenLightDark
--od-line-height-label16px=
--od-line-height-body20px=
--od-line-height-title24px=
--od-line-height-headline28px=

Size and border​

TokenLightDark
--od-size-touch-target44px=
--od-size-indicator-dot14px=
--od-size-icon20px=
--od-size-snackbar-min-height48px=
--od-size-snackbar-max-width560px=
--od-size-fullscreen-measure36ch=
--od-border-width1px=
--od-focus-ring-width2px=

Motion​

TokenLightDark
--od-duration-fast120ms=
--od-duration-base200ms=
--od-duration-slow320ms=
--od-duration-exit150ms=
--od-duration-pulse1200ms=
--od-ease-outcubic-bezier(0.16, 1, 0.3, 1)=
--od-ease-incubic-bezier(0.7, 0, 0.84, 0)=
--od-ease-standardcubic-bezier(0.4, 0, 0.2, 1)=

Layers​

TokenLightDark
--od-z-banner1000=
--od-z-indicator1010=
--od-z-snackbar1020=
--od-z-fullscreen1100=

Offsets​

TokenLightDark
--od-offset-top0px=
--od-offset-bottom0px=

Native: the OfflineTheme object​

React Native has no CSS variables. The same tokens exist as a typed object, with the names in camelCase and without the prefix (--od-color-action is colorAction). Pass overrides with the theme prop, build a theme with createTheme, or start from lightTheme and darkTheme:

import { OfflineDetector, createTheme } from '@rogeriodocarmo/offline-detector-native';

const theme = createTheme({ colorAction: '#6d28d9', radiusMd: 2 });

<OfflineDetector netInfo={NetInfo} theme={theme}>
<App />
</OfflineDetector>;

useOfflineTheme returns the resolved theme inside your own components. Every key of OfflineTheme:

KeyType
colorSurfacestring
colorSurfaceRaisedstring
colorSurfaceInversestring
colorTextstring
colorTextMutedstring
colorTextInversestring
colorTextMutedInversestring
colorBorderstring
colorBorderSubtlestring
colorStatusOfflinestring
colorStatusOfflineSubtlestring
colorStatusOnlinestring
colorStatusCheckingstring
colorActionstring
colorOnActionstring
colorActionInversestring
colorFocusRingstring
colorScrimstring
spaceXsnumber
spaceSmnumber
spaceMdnumber
spaceLgnumber
spaceXlnumber
space2xlnumber
radiusSmnumber
radiusMdnumber
radiusLgnumber
radiusFullnumber
fontFamilystring | undefined
fontSizeLabelnumber
fontSizeBodynumber
fontSizeTitlenumber
fontSizeHeadlinenumber
lineHeightLabelnumber
lineHeightBodynumber
lineHeightTitlenumber
lineHeightHeadlinenumber
fontWeightRegular'400'
fontWeightMedium'500'
fontWeightSemibold'600'
sizeTouchTargetnumber
sizeIndicatorDotnumber
sizeIconnumber
sizeSnackbarMinHeightnumber
sizeSnackbarMaxWidthnumber
sizeFullscreenMeasurenumber
focusRingWidthnumber
durationFastnumber
durationBasenumber
durationSlownumber
durationExitnumber
durationPulsenumber
easeOutBezier
easeInBezier
easeStandardBezier
zBannernumber
zIndicatornumber
zSnackbarnumber
zFullscreennumber
shadowChipShadowStyle
shadowSnackbarShadowStyle

Keep the contrast​

If you change colours, keep text at 4.5 to 1 and interface components at 3 to 1, in both schemes. Status colours (offline, online, checking) mark a glyph or a dot; do not use them for sentences. See Accessibility.