npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-french-ssn

v1.4.1

Published

React component for French Social Security Numbers (NIR) with automatic formatting and validation

Readme

react-french-ssn

React component for French Social Security Numbers (NIR)

npm version License: MIT TypeScript

🚀 Overview

react-french-ssn is a React library specialized in handling French Social Security Numbers (NIR - Numéro d'Identification au Répertoire). It provides a SocialSecurityInput component with automatic formatting, validation, and advanced features, built with TypeScript for an optimal development experience.

✨ Features

  • 🔢 Automatic Formatting - Guided input by Social Security Number segments
  • Built-in Validation - Automatic control key verification
  • 📋 Copy Button - Easy copying of the complete number to clipboard
  • 🎯 TypeScript First - Fully typed with complete type definitions
  • 🎨 Modular Styling - CSS Modules for encapsulated and customizable styling
  • 🌙 Dark Mode Support - Automatic dark mode detection
  • 🧪 Complete Testing - Jest and React Testing Library with high coverage
  • 📚 Interactive Documentation - Storybook to explore the component
  • 🔧 Code Quality - ESLint, Prettier, and strict TypeScript configuration

📦 Installation

npm install react-french-ssn
yarn add react-french-ssn
pnpm add react-french-ssn

🎯 Quick Start

import React from 'react';
import { SocialSecurityInput } from 'react-french-ssn';

function App() {
  return (
    <SocialSecurityInput 
      label="Social Security Number"
      placeholder="269054958815780"
      onChange={(value) => console.log(value)}
    />
  );
}

📋 Examples

Basic Usage

import { SocialSecurityInput } from 'react-french-ssn';

function BasicExample() {
  const [ssn, setSsn] = useState('');

  return (
    <SocialSecurityInput
      label="Numéro de sécurité sociale"
      placeholder="269054958815780"
      value={ssn}
      onChange={setSsn}
    />
  );
}

With Error Handling

import { SocialSecurityInput } from 'react-french-ssn';

function ErrorExample() {
  const [ssn, setSsn] = useState('');
  const [error, setError] = useState('');

  const handleChange = (value) => {
    setSsn(value);
    if (value.length === 15) {
      setError('');
    } else if (value.length > 0) {
      setError('Le numéro doit contenir 15 chiffres');
    }
  };

  return (
    <SocialSecurityInput
      label="Numéro de sécurité sociale"
      value={ssn}
      onChange={handleChange}
      error={error}
    />
  );
}

With Copy Button

import { SocialSecurityInput } from 'react-french-ssn';

function CopyExample() {
  return (
    <SocialSecurityInput
      label="Numéro de sécurité sociale"
      placeholder="269054958815780"
      showCopyButton={true}
      onChange={(value) => console.log('SSN:', value)}
    />
  );
}

Custom Styling

import { SocialSecurityInput } from 'react-french-ssn';
import './custom-styles.css';

function StyledExample() {
  return (
    <SocialSecurityInput
      label="Numéro de sécurité sociale"
      className="custom-ssn-input"
      showCopyButton={true}
      onChange={(value) => console.log(value)}
    />
  );
}

Internationalization

import { SocialSecurityInput } from 'react-french-ssn';

function I18nExample() {
  return (
    <SocialSecurityInput
      label="Social Security Number"
      placeholder="269054958815780"
      showCopyButton={true}
      texts={{
        description: 'Enter your French social security number (15 digits)',
        fieldDescriptions: {
          sex: 'Gender (1 for male, 2 for female)',
          year: 'Birth year (last 2 digits)',
          month: 'Birth month (01 to 12)',
          department: 'Birth department (2 digits or 2A/2B)',
          insee: 'INSEE municipality code (3 digits)',
          order: 'Order number (3 digits)',
          controlKey: 'Control key (calculated automatically)'
        },
        copyButton: {
          copy: 'Copy',
          copied: 'Copied!',
          copyLabel: 'Copy the complete social security number',
          copiedLabel: 'Number copied successfully'
        }
      }}
      onChange={(value) => console.log(value)}
    />
  );
}

🧩 Main Component

SocialSecurityInput

The main component of this library, specifically designed for French Social Security Number input. It automatically divides input into logical segments and calculates the control key.

import { SocialSecurityInput } from 'react-french-ssn';

<SocialSecurityInput 
  label="Social Security Number"
  placeholder="269054958815780"
  value={ssnValue}
  onChange={handleSSNChange}
  error={errorMessage}
  showCopyButton={true}
  disabled={false}
  className="custom-class"
/>

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | label | string | 'Social Security Number' | Field label | | placeholder | string | '269054958815780' | Placeholder text | | value | string | - | Controlled value | | onChange | (value: string) => void | - | Change callback | | error | string | - | Error message | | disabled | boolean | false | Disabled state | | className | string | '' | Custom CSS classes | | showCopyButton | boolean | false | Show copy button |

Optional ThemeProvider

Optional context provider for theme configuration (not required for basic usage).

import { ThemeProvider, SocialSecurityInput } from 'react-french-ssn';

<ThemeProvider theme={{ colors: { primary: '#custom-color' } }}>
  <SocialSecurityInput />
</ThemeProvider>

🎣 Custom Hook

useSocialSecurityInput

Internal hook that handles the formatting and validation logic for Social Security Numbers.

import { useSocialSecurityInput } from 'react-french-ssn';

const { values, handlers, placeholders } = useSocialSecurityInput({
  onChange: handleChange,
  placeholder: '269054958815780',
  value: currentValue,
});

🛠️ Utilities

Global Configuration

import { setGlobalConfig, getGlobalConfig, resetGlobalConfig } from 'react-french-ssn';

setGlobalConfig({
  theme: 'light',
  locale: 'fr-FR',
});

const config = getGlobalConfig();

CSS Variables

import { getCSSVariable, createCSSVariables } from 'react-french-ssn';

const primaryColor = getCSSVariable('--primary-color');
const variables = createCSSVariables({
  '--primary-color': '#007bff',
  '--secondary-color': '#6c757d'
});

🎯 Use Cases

This component is perfect for:

  • Administrative Forms - Social Security Number input
  • HR Applications - Employee data management
  • Healthcare Systems - Patient identification
  • Government Applications - Public services online

📝 TypeScript Support

This library is fully built with TypeScript and provides complete type definitions.

import type { 
  SocialSecurityInputProps, 
  GlobalConfig, 
  ThemeConfig 
} from 'react-french-ssn';

const props: SocialSecurityInputProps = {
  label: 'Social Security Number',
  onChange: (value: string) => console.log(value)
};

📄 License

MIT © JatoCool Company

🎮 Testez le composant interactivement

🚀 Démo en ligne

🎮 Testez le composant directement dans votre navigateur

Cette démo interactive vous permet de :

  • ✅ Tester le formatage automatique en temps réel
  • ✅ Voir la validation et les messages d'erreur
  • ✅ Comprendre la structure du numéro de sécurité sociale
  • ✅ Essayer différents exemples de numéros

📦 Démo CodeSandbox

Edit react-french-ssn-demo

Cliquez sur le bouton ci-dessus pour tester le composant dans CodeSandbox !

🎯 Fonctionnalités à tester

  • Formatage automatique - Tapez 269054958815780 pour voir le découpage
  • Validation en temps réel - Essayez des numéros invalides
  • Bouton de copie - Copiez le numéro formaté
  • Accessibilité - Testez avec le clavier et lecteurs d'écran
  • Mode sombre - Détection automatique du thème

🏠 Démo locale avec Storybook

# Cloner le repository
git clone https://github.com/Johanna1506/ui.git
cd ui

# Installer les dépendances
npm install

# Lancer Storybook
npm run storybook

Puis ouvrez http://localhost:6006 dans votre navigateur.

📚 Stories disponibles

  • Interactive - Composant entièrement interactif pour tester toutes les fonctionnalités
  • Default - Version basique du composant
  • WithLabel - Avec label personnalisé
  • WithError - Avec gestion d'erreur
  • Disabled - État désactivé
  • WithCopyButton - Avec bouton de copie
  • WithCustomTexts - Textes personnalisés

🔗 Links


Specialized in French Social Security Numbers
Built with ❤️ by JatoCool Company