1.0.2 • Published 5 months ago

dubl-shared-components v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Dubl Shared Components

A reusable React Native component library for the Dubl project. Built with React Native and Tailwind via tailwind-rn.

Table of Contents


Overview

The Dubl Shared Components repository provides a set of React Native UI components that can be consumed by multiple Dubl apps (e.g., Android-only and iOS-only apps).

  • TypeScript for type safety
  • ESLint + Prettier for consistent code formatting and linting
  • Jest for unit testing
  • Tailwind styling via tailwind-rn

Features

  • Reusable Components: Common UI elements (buttons, inputs, forms, etc.) shared across Dubl apps.
  • Tailwind-based: Consistent, utility-first styling for React Native.
  • Modular: Exported as a library for easy consumption in other projects.
  • Type Declarations: Ships .d.ts files for seamless integration with TypeScript apps.

Installation

  1. Clone the repository or include it as a submodule in your monorepo.
  2. Install dependencies:
    yarn
  3. Build the library to generate TypeScript declaration files:
    yarn build

Consuming in Another Project

If you’re linking locally:

# From the main app
yarn add file:../dubl-shared-components

You can then import shared components as:

import { Button } from 'dubl-shared-components';

Usage

In your React Native application:

  1. Install the library (local or via a private registry).
  2. Import the component you need:

    import React from 'react';
    import { View } from 'react-native';
    import { Button } from 'dubl-shared-components';
    
    export function HomeScreen() {
      return (
        <View>
          <Button label="Click Me" onPress={() => alert('Hello from Dubl!')} />
        </View>
      );
    }
  3. Run your React Native app (yarn android or yarn ios) to see the shared component in action.


Development

  1. Clone or open the dubl-shared-components repo.
  2. Install Dependencies:
    yarn
3. **Start coding**. All source files live in the `src/` folder.

### Creating New Components

To create a new component:

1. **Create the component structure**:

src/components/your-component/ ├─ YourComponent.tsx # Main component file ├─ YourComponent.styles.ts # Component styles └─ your-component.stories.tsx # Storybook stories

2. **Implement the component** (`YourComponent.tsx`):
```tsx
import React from 'react';
import { View } from 'react-native';
import { styles } from './YourComponent.styles';

interface YourComponentProps {
// Define your props here
testID?: string;
}

export function YourComponent({ testID }: YourComponentProps) {
return (
<View style={styles.container} testID={testID}>
    {/* Your component content */}
</View>
);
}
  1. Add styles (YourComponent.styles.ts):
import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({
container: {
// Your styles here
},
});
  1. Create Storybook stories (your-component.stories.tsx):
import type { Meta, StoryObj } from '@storybook/react';
import { YourComponent } from './YourComponent';

const meta: Meta<typeof YourComponent> = {
title: 'Components/YourComponent',
component: YourComponent,
};

export default meta;
type Story = StoryObj<typeof YourComponent>;

export const Default: Story = {
args: {
// Your default props
},
};
  1. Export the component in src/index.ts:
export * from './components/your-component/YourComponent';

Testing in Storybook

  1. Start Storybook:
yarn storybook
  1. View your component:
  • Open http://localhost:6006
  • Find your component under the Components section
  • Interact with different stories and props
  • Test various states and configurations
  1. Testing tips:
  • Use the Controls panel to modify props in real-time
  • Create multiple stories for different states/variations
  • Test edge cases and error states
  • Verify responsive behavior using the viewport controls

Linting & Formatting

  • Lint your code:
    yarn lint
  • Auto-format with Prettier:
    yarn format

Testing

  • Run all tests with Jest:
    yarn test
  • Write your unit tests in __tests__ directories or alongside components as *.test.ts or *.spec.ts.

Building

  • Generate .d.ts files (and optionally .js if you remove emitDeclarationOnly) in dist/:
    yarn build

Scripts

Below are the main npm/yarn scripts defined in package.json:

ScriptCommandDescription
linteslint 'src/**/*.{js,ts,tsx}'Runs ESLint on all source files.
formatprettier --write 'src/**/*.{js,ts,tsx}'Formats all source files with Prettier.
testjestRuns the unit test suite using Jest.
buildtscCompiles TypeScript and emits declaration files to dist/.

Project Structure

dubl-shared-components/
├─ .vscode/                # VS Code workspace settings (optional)
│   ├─ extensions.json
│   └─ settings.json
├─ src/
│   ├─ components/
│   │   └─ Button.tsx      # Example shared Button component
│   └─ tailwind.ts         # tailwind-rn config
├─ __tests__/              # Jest tests (optional structure)
├─ dist/                   # Output folder (after build)
├─ .gitignore
├─ .nvmrc                  # Optional Node version file for nvm
├─ package.json
├─ tsconfig.json
└─ yarn.lock

License

MIT


Happy coding! If you have any questions or issues, please feel free to open an issue or submit a pull request.