Site settings
Change the appearance of the site to suit your preferences
π± How to Create New React Native Componentsβββββο»Ώβο»Ώββββββο»Ώο»Ώβο»Ώβββββββββο»Ώββββββο»Ώββββββο»Ώβββββββο»Ώβο»Ώββββββο»Ώββββββο»Ώβββο»Ώββββο»Ώβββββββο»Ώο»Ώββββββο»Ώββββββββββο»Ώβββββββββββββββο»Ώβββββββββββο»Ώβββο»Ώβββο»Ώβββο»Ώββββο»Ώο»Ώββο»Ώο»Ώββο»Ώβββο»Ώο»Ώβββο»Ώββββββο»Ώβββββββο»Ώο»Ώβο»Ώβο»Ώβο»Ώβββο»Ώβββο»Ώβββο»Ώβββο»Ώβββο»Ώββββο»Ώο»Ώββββββο»Ώββο»Ώββββββββο»Ώββο»Ώββββο»Ώο»Ώβββββββββββββο»Ώββββο»Ώο»Ώββο»Ώβββο»Ώο»Ώβββββββββο»Ώο»Ώββο»Ώβββο»Ώβββββββο»Ώβο»Ώββββββο»Ώββο»Ώβββββββο»Ώββββββββο»Ώο»Ώββο»Ώββο»Ώβο»Ώβββββββββο»Ώο»Ώββββββββββο»Ώβββο»Ώβββο»Ώβββββο»Ώβο»Ώβο»Ώβββο»Ώββο»Ώββββββββββββββο»Ώββββο»Ώββο»Ώβββββββο»Ώβββο»Ώββββο»Ώββο»Ώβββββββο»Ώβο»Ώβο»Ώββββο»Ώββο»Ώβββο»Ώβββο»Ώβββο»Ώβββββββββββββββββο»Ώβο»Ώβο»Ώβο»Ώβββο»Ώβο»Ώβββββο»Ώβο»Ώβο»Ώβββο»Ώβββο»Ώβββββββο»Ώο»Ώββββββο»Ώβββο»Ώβββββββββο»Ώββο»Ώββββββο»Ώβο»Ώβο»Ώβββββββο»Ώβββββββο»Ώο»Ώββο»Ώβββββββο»Ώββββο»Ώββββββο»Ώο»Ώο»Ώβββββββββο»Ώβο»Ώβββββββββο»Ώββββο»Ώββο»Ώο»Ώββββββο»Ώβββο»Ώβββο»Ώβββββββο»Ώβο»Ώβββββββββο»Ώβββββββββββο»Ώββββββββο»Ώβββο»Ώο»Ώβββο»Ώββββββο»Ώβββββββο»Ώο»Ώβο»Ώβο»Ώβο»Ώβββββββο»Ώβο»Ώβββββο»Ώβββο»Ώβββο»Ώβββο»Ώβββββββββββββββο»Ώο»Ώββββββββββο»Ώβββο»Ώβββο»Ώβββββο»Ώβο»Ώβο»Ώβββο»Ώββο»Ώββββββββββββββο»Ώββββο»Ώββο»Ώβββββββο»Ώβββο»Ώββββο»Ώββο»Ώβββββββο»Ώβο»Ώβο»Ώββββο»Ώββο»Ώβββο»Ώβββο»Ώβββο»Ώβββββββββββββββββο»Ώβο»Ώβο»Ώβο»Ώβββο»Ώβο»Ώβββββββββο»Ώβββο»Ώβββο»Ώβββββββο»Ώο»Ώββββββο»Ώβββο»Ώβββββββββο»Ώββο»Ώββββββββββο»Ώβββββββο»Ώβββββββο»Ώο»Ώββο»Ώβββββββο»Ώββββο»Ώββββββββββο»Ώβββββββο»Ώβββο»Ώβο»Ώβο»Ώβββββββββο»Ώβο»Ώβββββββο»Ώβββββββο»Ώο»Ώββο»Ώβββο»Ώββββββββο»Ώββββββο»Ώβο»Ώβββββββββββββββββο»Ώο»Ώβ
Spor also has a React Native implementation! This guide walks you through how to contribute to the codebase and build new React Native components for Spor.
If you're planning to create a new React Native component for Spor, youβre in the right place. This guide covers where to put your code, naming conventions, structure, and best practices.
π Principles
Most of the React Native components in Spor should already exist in the React version. The React implementation serves as a reference, so you donβt need to invent names, abstraction levels, or prop structures from scratch.
- Same component names and props should be used across web and mobile.
- If the component does not exist in React, check with the Spor team or Team Kanaler before you start building.
π€ Naming Conventions
We follow three key naming conventions:
variantβ Defines different visual styles unrelated to color (e.g.,solid,outline,primary,secondary,ghost).colorSchemeβ Defines color-related variations (e.g.,teal,orange,light,dark).sizeβ Defines size variations. Always use t-shirt sizing (sm,md,lg,xl,2xl). If only two sizes exist, usesmandlg.
π Folder Structure & Code Organization
All Spor-related code lives in app/spor/ inside the salgsapp-react-native repository.
π Steps to Create a New Component
1οΈβ£ Create a new folder inside app/spor/ that groups related components (e.g., button, card, layout).
- Always use singular names (
button, notbuttons).
2οΈβ£ Inside that folder, create an index.tsx file to export the component.
- Then, export this new
index.tsxfile inapp/spor/index.tsxso others can import your component like this:
import { Button } from "app/spor";
π Component Structure
A component should be as simple as possible. If it becomes too complex, break it into smaller subcomponents that can be composed together.
For example, a Modal component might be split into:
ModalModalOverlayModalContentModalHeaderModalBodyModalFooter
You could then create a SimpleModal that works for most cases, while still allowing developers to use the parts individually for more flexibility.
π Spacing Props
All components should support spacing props (e.g., margin, sometimes padding).
π Use SpacingProps from app/spor:
type ExampleComponentProps = SpacingProps & { children: React.ReactNode };export const ExampleComponent = (props: ExampleComponentProps) => {return <Box {...props}> {/* Your component code here */} </Box>;};
πΉ These spacing props should typically be spread onto the outermost <Box /> (imported from app/spor).
π¨ Styling with Restyle
We use a customized styling system based on Restyle.
1οΈβ£ Create a theme.tsx file inside the component folder. 2οΈβ£ Use our style helpers to define styles.
Hereβs a complete example:
// Component structure (e.g., outer container + text component)type Structure = {container: BoxStyle;text: TextStyle;};// Component props (e.g., variants and sizes)type Args = {variant: "solid" | "outline";size: "sm" | "md" | "lg";};const { createGetStyles, createStyleConfig } = createStyleHelpers<Structure, Args>();// Base stylesconst baseStyles = createStyleConfig(() => ({container: { backgroundColor: "darkTeal" },text: { color: "white" },}));// Variant stylesconst variantStyles = createStyleConfig(({ variant }) => {switch (variant) {case "outline":return { container: { borderWidth: 1, borderColor: "primaryGreen", borderStyle: "solid" } };default:return {};}});// Combine stylesexport const getStyles = createGetStyles(baseStyles, variantStyles);
π Applying Styles in a Component
const ExampleComponent = ({ children, variant, size }: ExampleComponentProps) => {const styles = getStyles({ variant, size });return (<Box {...styles.container}><Text {...styles.text}>{children}</Text></Box>);};
πΉ If you need to extract individual styles, use useRestyleStyle:
const AnotherExampleComponent = () => {const styles = getStyles();const iconStyles = useRestyleStyle(styles.icon);return <Svg style={iconStyles}>...</Svg>;};
π Exporting Your Component
π Use named exports onlyβno default exports.
Example:
export { Button } from "./button";
π§ Useful Utilities
Check out app/spor/utils/ before writing new utility functionsβmany helpful hooks and helpers already exist!
β Questions? Feedback?
This guide is a starting point for building React Native components in Spor. If you see areas for improvement, feel free to contribute! No suggestion is too small. π