@rn-styled/styled
v0.2.0
Published
React Native styled-components inspired library — TypeScript-first, high performance
Maintainers
Readme
@rn-styled/styled
TypeScript-first styling library for React Native with template-literal syntax, typed themes, typed variants, and cached runtime style resolution.
Installation
pnpm add @rn-styled/styled react react-nativeQuick start
import { ThemeProvider, createTheme, styled, t, v } from '@rn-styled/styled';
const theme = createTheme({
__id: 'light-v1',
colors: {
primary: '#245CFF',
onPrimary: '#FFFFFF',
background: '#F7F9FF',
},
space: { 3: 12, 4: 16 },
radii: { md: 12 },
fontSizes: { md: 16, lg: 22 },
});
type AppTheme = typeof theme;
const Button = styled.Pressable.withConfig({
defaultVariants: { tone: 'primary' },
})`
padding-vertical: ${t<AppTheme>('space.3')};
padding-horizontal: ${t<AppTheme>('space.4')};
border-radius: ${t<AppTheme>('radii.md')};
background-color: ${v('tone', {
primary: 'colors.primary',
ghost: 'transparent',
})};
`;
const Label = styled.Text`
color: ${v('tone', {
primary: 'colors.onPrimary',
ghost: 'colors.primary',
})};
font-size: ${t<AppTheme>('fontSizes.md')};
`;
export default function App() {
return (
<ThemeProvider theme={theme}>
<Button tone="primary">
<Label tone="primary">Press me</Label>
</Button>
</ThemeProvider>
);
}What it includes
styledfactory for React Native components and custom components withstylecreateThemefor typed theme creationThemeProvideranduseThemet()for typed token referencesv()for typed variant slotswithConfig()for default variants and display names
Notes
theme.__idshould be unique per theme instance so cached variant styles stay correct when switching themes.- Prefer
v()for dynamic style branches instead of arbitrary function interpolations. - For components without a direct
styled.Xshortcut, usestyled(Component)if the component accepts astyleprop.
