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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codegouvfr/rjsf-dsfr

v0.1.9

Published

react-jsonschema-form with the DSFR

Downloads

23

Readme

React JSON Schema Form with the DSFR

This is a wrapper around the react-jsonschema-form with the components from react-dsfr.

[!IMPORTANT] For now, this is simply extracted code from catala-dsfr. Therefore, the API is not yet defined and and is likely to be not flexible enough for your use case.

If you want to use this library, please open an issue to discuss your needs!

Installation

yarn add @codegouvfr/rjsf-dsfr

Usage

For now, the API matches the one from react-jsonschema-form and you can overrides some widgets (resp. templates) by specifying them in the props.

import { RJSFSchema } from '@rjsf/utils'
import FormDSFR from '@codegouvfr/rjsf-dsfr'
import { customizeValidator } from '@rjsf/validator-ajv8'
import frenchLocalizer from 'ajv-i18n/localize/fr'

const validator = customizeValidator({}, frenchLocalizer)

const schema: RJSFSchema = {
  type: 'object',
  properties: {
    nom: { title: 'Nom', type: 'string', minLength: 2 },
    prenom: { title: 'Prénom', type: 'string' },
    ddn: { title: 'Date de naissance', type: 'string', format: 'date' },
  },
  required: ['nom'],
}

export default function Form() {
  return <FormDSFR schema={schema} validator={validator} />
}

Notes on writing schemas

Title

The titles must not be defined inside "kind" properties of the object definition but just before the "$ref" of the calling parent:

"categorieEquivalenceLoyerD84216": {
  "title": "Catégorie de personnes résidant en logement-foyer",
  "$ref": "#/definitions/categorie_equivalence_loyer_allocation_logement_foyer"
}

UI Options

As described in the react-jsonschema-form documentation, you can customize the form by providing a uiSchema. In addition to the standard options, you can use the following specific options for rjsf-dsfr.

[!TIP] You can have a look to a real world example here

Global field options

The following options can be set for any field in the uiSchema:

  • ui:heading: set the heading level for the field's title (available values: h2, h3, h4, h5, h6)
  • ui:hideTitle: hide the field's title.

Specific field options

Array fields

The following options can be set for fields of type array:

  • ui:addIcon: set the DSFR icon id for the Add button
  • ui:removeIcon: set the DSFR icon id for the Remove button
  • ui:tabLabel: set the label for the tab in the array field (it needs to be defined at the root of the array field)

[!NOTE] By default, array fields are displayed in a Tabs component. Each tab is labeled with the ui:tabLabel value and the last tab contains the Add button.

[!IMPORTANT] The ui:hideTitle option it's needed for items of type object inside a field of type array to hide the unique title of the array's items.

Example:

"personnesACharge": {
   "ui:tabLabel": "Personne",
   "items": {
       "ui:hideTitle": true,
...

Development

Launch the playground to play with the DSFR theme :

cd demo
yarn
yarn start