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

@ssplib/react-components

v0.0.349

Published

SSP React Components

Readme

@ssplib/react-components

Biblioteca de componentes React (baseada em MUI v5) para projetos internos da SSP-DF. Inclui campos de formulário com máscara/validação, providers de autenticação (Keycloak/AD e gov.br), tabela com filtros e exportação, mapa (Leaflet), modal e navbars.

Projeto interno em desenvolvimento contínuo. Textos e validações em pt-BR.

Instalação

npm install @ssplib/react-components \
  @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/x-date-pickers @mui/lab

Peer dependencies: react ^18, react-dom ^18, next ^14. Os componentes de autenticação usam next/router (Next.js Pages Router).

Conceito central: os dois sistemas de formulário

Esta é a coisa mais importante de entender. A lib tem dois mecanismos de formulário incompatíveis entre si. Cada componente pertence a um deles — escolha o provider certo conforme o componente que for usar.

| | Sistema "clássico" | Sistema "Generic" | |---|---|---| | Provider | FormProvider | GenericFormProvider | | Contexto | FormContext (custom) — métodos renomeados: formRegister, formWatch, formSetValue, formReset, formControl, formHandleSubmit, formGetValues… | react-hook-form nativo — consome via useFormContext() | | Componentes | Input, Table, CheckBox, Radio, DatePicker, uploads de arquivo, etc. | Os prefixados com Generic: GenericInput, GenericTable, GenericFetchAutoComplete, GenericMaskInput, GenericMultInput, GenericDatePicker | | onSubmit | (data, filesUid) => void | (data) => void |

Os dois não compartilham estado. Não misture Input (clássico) dentro de um GenericFormProvider, nem GenericInput dentro de um FormProvider.

Exemplo — sistema clássico

import { SspComponentsProvider, FormProvider, Input } from '@ssplib/react-components'

export default function MinhaPagina() {
    return (
        <SspComponentsProvider>
            <FormProvider onSubmit={(data, filesUid) => console.log(data, filesUid)}>
                <Input name='nome' title='Nome' type='input' required />
                <Input name='cpf' title='CPF' type='cpf' required />
                <button type='submit'>Enviar</button>
            </FormProvider>
        </SspComponentsProvider>
    )
}

FormProvider já renderiza o elemento <form> e exibe um toast de aviso quando o submit é inválido.

SspComponentsProvider

Wrapper de nível de aplicação. Monte uma vez na raiz. Ele provê o portal de modais (MODAL) e o ToastContainer (react-toastify). Sem ele, modais e toasts não funcionam.

<SspComponentsProvider>{children}</SspComponentsProvider>

Inputs com máscara e validação

Input (e GenericInput) derivam máscara e validação a partir da prop type:

cpf · cnpj · cpf_cnpj (alterna dinamicamente) · phone (fixo/celular dinâmico) · cep · sei · rg · email · number (máscara via numberMask) · input (texto) · além dos tipos nativos de HTML (password, tel, url…).

Props úteis: name (obrigatório), title (label acima do campo), required, customValidate, watchValue (sincroniza o campo com um valor externo), inputMinLength/inputMaxLength, layout via xs/sm/md. O tipo público InputProps estende TextFieldProps do MUI.

Tabela e exportação

Table (clássico) e GenericTable renderizam dados com filtros, ordenação e paginação (inclusive server-side no GenericTable, via serverSidePagination + page/onPageChange). A exportação para .xlsx é configurada por csvConfig (tipo CsvConfigProp) e gerada com write-excel-file (writer mantido, sem as CVEs do antigo SheetJS).

Autenticação

Dois providers alimentam o mesmo AuthContext (formato AuthReturnData): user, isAuth, userLoaded, login, logout, hasRole/hasAnyRole/hasAllRoles, accessToken.

  • KeycloakAuthProvider — Keycloak/Active Directory (type: 'ad'), com refresh automático de token e init de SSO.
  • OAuthProvider — OIDC gov.br (type: 'govbr'). Em localhost (ou um testIP), faz bypass do fluxo real e loga com um testToken.

Ambos guardam o JWT no cookie nextauth.token (exportado como AUTH_COOKIE_NAME).

import { useContext } from 'react'
import { AuthContext } from '@ssplib/react-components'

const { user, isAuth, hasRole, logout } = useContext(AuthContext)

Componentes exportados

Formulário: Input, MaskInput, MultInput, ActiveInput, OtherCheckBox, AutoComplete, FetchAutoComplete, FixedAutoComplete, CheckBox, CheckBoxAdditional, CheckBoxWarning, RequiredCheckBoxGroup, Radio, Switch, ToggleVisibility/SwitchWatch, DatePicker, TimePicker, FileUpload, DropFileUpload, Stepper, StepperBlock, Table. Versões Generic*: GenericInput, GenericMaskInput, GenericMultInput, GenericDatePicker, GenericFetchAutoComplete, GenericTable. Outros: Map, MODAL, NavBar, TabNavBar, Menu, Button, Category/Field/FieldLabel/File (módulo "detalhes"). Providers/contexto: SspComponentsProvider, FormProvider, KeycloakAuthProvider, OAuthProvider, FormContext, AuthContext.

Os tipos de props (InputProps, InputType, CsvConfigProp, FilterValue, TableProps, TableProps2, MapProps, FieldType, FormContextType, etc.) e os tipos de auth são exportados pela raiz do pacote — basta import type { … } from '@ssplib/react-components'.

Desenvolvimento

npm run storybook   # ambiente de dev/preview (Storybook em :6006) — não há app host
npm run api         # mock API (json-server em :7171) para componentes Fetch*
npm run build       # build de produção (microbundle) -> dist/

Não há test runner nem lint. As stories (src/**/*.stories.tsx) são a superfície de verificação. Formatação: Prettier (4 espaços, sem ponto-e-vírgula, aspas simples, printWidth 200).

Publicação / versão

A versão fica em lib-package.json (o package.json que é efetivamente publicado). O hook prebuild (sync-version.cjs) copia essa versão para o package.json raiz. Para lançar: bumpe a versão em lib-package.json e faça push na main (o workflow .github/workflows/publish.yaml builda e publica).

Para detalhes de arquitetura voltados a agentes/IA, veja AGENTS.md.