0.2.5 • Published 5 months ago

@betagouv/les-communs-widget v0.2.5

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

Les Communs Widget

A React widget that displays associated services for ecological transition projects. This widget is designed to be embedded in various platforms to provide a consistent service discovery experience.

Features

  • Displays services associated with a project
  • Responsive design using DSFR (Design System de l'État)
  • TypeScript support
  • Built with Vite

Usage in Other Projects

To use this widget in your project:

pnpm add @betagouv/les-communs-widget

Then import and use the component:

import { ServicesWidget } from "@betagouv/les-communs-widget";

function App() {
  return <ServicesWidget projectId="0195af3a-6b26-7a5c-a091-712901a4498d" />;
}

By default the widget needs to consume the projectId from the Communs database. This ID is a uuid and you will get a 400 if you try any other format

Depending on the widget consumers, you might be able to use your own id as such. For now we only support tet

import { ServicesWidget } from "@betagouv/les-communs-widget";

function App() {
  <ServicesWidget projectId="your-project-id-from-your-base" idType={"tetId"} />;
}

Debug mode

When testing the widget integration in can be useful to check how each service is displayed (since some iframe might have specific CSP rules against your domain)

In order to see all services regardless of their matching with the current project, you can pass prop debug as such:

import { ServicesWidget } from "@betagouv/les-communs-widget";

function App() {
  return <ServicesWidget projectId="your-project-id" debug />;
}

Staging environment

You can test against the staging environment by passing prop isStagingEnv:

import { ServicesWidget } from "@betagouv/les-communs-widget";

function App() {
  return <ServicesWidget projectId="your-project-id" isStagingEnv />;
}

Test Configuration

If you encounter an error related to unknown file extensions in your test (e.g., .css), you may need to adjust your Vite configuration. Add the following to your vite.config.ts file.

The inlined package will be processed and bundled directly into the application rather than being treated as an external dependency. This is particularly useful for dependencies that include non-JavaScript assets (like CSS).

// ... existing code ...
export default defineConfig({
  server: {
    deps: {
      inline: ['@betagouv/les-communs-widget'], // Ensure this dependency is processed correctly
    },
  },
  // ... existing code ...
});

Local Development

Prerequisites

  • Node.js (>= 20)
  • pnpm (>= 9.x)
  • Running instance of Les Communs API (see api/README.md)

Setup

  1. First, build the widget:
cd les-communs-widget
pnpm install
pnpm build
  1. Then, set up the sandbox environment:
cd ../les-communs-widget-widget-sandbox
pnpm install

Development Workflow

  1. Start the API (in a separate terminal):
cd api
pnpm start:dev
  1. Start the sandbox development server:
cd les-communs-widget-widget-sandbox
pnpm dev

The sandbox will automatically reload when you make changes to the widget code.

Testing Your Changes

  1. When you want to test your changes, you need to publish the widget locally (we use yalc):
pnpm dev:widget:publish
  1. Link the widget sandbox to the published yalc package
pnpm dev:widget-sandbox:link
  1. Should you make further updates run the below command to avoid having to re-link the widget sandbox
pnpm dev:widget:push
  1. When your testing is done, unlink the widget sandbox
pnpm dev:widget-sandbox:unlink

Publishing

  1. Increase the version number in your package json
  2. Update the file CHANGELOG.md accordingly
  3. Publish through script below (this will build the widget beforehand)

    pnpm release
0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.9

6 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago