2.0.14 • Published 1 month ago

@b-cedric/react-common-bootstrap v2.0.14

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

Librairie de composants React

Compilation du style : npm run build:style Démarrage de storybook: npm run storybook => démarrage sur localhost:6006 Publication du package sur NPM (nécessite npm login): npm publish:npm

Form

CustomForm

props : |nom|type|defaut| |---|---|---| |onSubmit|fonction|() => Promise| |submitLabel|string|'Valider| |cancelLabel|string|'Annuler| |className|string|''| |disabled|boolean|false| |isLoading|boolean|false| |onCancel|fonction|null| |errorMessage|string|null| |isFormValid|boolean|false| |formFields|object|{}| |setFormFields|function|() => {}|

exemple :

<CustomForm
  onSubmit={submit}
  onCancel={cancel}
  isValid={isFormValid}
  errorMessage={errorMessage}
  formFields={formFields}
  setFormFields={setFormFields}
>
  <CustomFormField type="text" fieldName="libelle" />
</CustomForm>

CustomFormField

props : |nom|type|defaut| |---|---|---| |label|string / template|null| |fieldName|string|''| |value||null| |onChange|fonction|() => {}| |type|string|'text'| |options|array|[]| |className|string|''| |name|string|''| |disabled|bool|false| |isValid|bool|true| |feedback|string|''| |emptySelectOption|bool|false| |prefix|string / fonction|null| |placeholder|string|''|

exemple :

<CustomFormField
  value={name}
  onChange={(e) => setName(e.target.value)}
  label="Nom du modèle"
  isValid={name != ''}
/>
<CustomFormField
  fieldName="name"
  label="Nom du modèle"
  isValid={formFields.name != ''}
/>

Info-bulle

props : |nom|type|defaut| |---|---|---| |info|string|''|

exemple :

<InfoBulle info={info} />

ListFormControl

props : |nom|type|defaut| |---|---|---| |label|string|''| |list|array|[]| |setList|fonction|() => {}| |titleActions|array|[]| |fields|array|[]| |titleClass|string|''| |canSwitch|boolean|false|

exemple:

<ListFormControl
  label="Composantes essentielles"
  list={composantes}
  setList={setComposantes}
  titleActions={[
    {
      label: 'Ajouter une composante',
      onClick: () => setComposantes([...composantes, { libelle: '' }])
    }
  ]}
  fields={[{ propName: 'libelle', label: 'Libellé', required: true }]}
/>

Steps

Ce composant permet d'afficher les étapes d'avancement du remplissage d'un formulaire sur plusieurs pages.

props : |nom|type|defaut| |---|---|---| |currentStep|number| 0| |steps |array| []| |pendingIcon|string|warning|

<Steps currentStep={1} steps={['step 1', 'step 2']} />

Subtitle

props : |nom|type|defaut| |---|---|---| |actions |array| []| |className |string| ''|

exemple:

    <SubTitle
        actions={[
          {
            label: 'Ajouter un niveau',
            onClick: () => ...
          }
        ]}
      >
      Niveaux de développement
    </SubTitle>

useFormField

paramètres:

  • valeur par défaut
  • callback de validité du champ de formulaire : val => bool

retourne:

  • valeur
  • set de la valeur
  • is valeur valide

exemple:

const [composantes, setComposantes, isComposantesValid] = useFormField(
  [{ libelle: '' }],
  (val) => val.length > 0 && val.every((obj) => obj.libelle != '')
)

Modal

Confirm

ConfirmContext, initConfirm et Confirm

ConfirmContext permet l'utilisation du hook useConfirm dans un composant sous jacent. la fonction initConfirm renvoie une valeur par défaut à passer au ConfirmContext. Il faut que dans ce context, le composant Confirm soit instancié.

    const Composant = () => {
        const contextValue = initConfirm()
        return (
        <ConfirmContext.Provider value={contextValue}>
        <Confirm />
            ...
        <ConfirmContext.Provider/>
        )
    }

useConfirm

Retourne une fonction :
    * paramètres:
        * Message de confirmation
        * Fonction éxecutée à la confirmation

L'exécution de cette fonction permet l'affichage d'une fenêtre de confirmation

exemple:

const confirm = useConfirm()
confirm('Veuillez confirmer la suppression', () => remove())

CustomModal

props : |nom|type|defaut| |---|---|---| |show|bool|false| |title|string|''| |content| HTML |''| |onValidate|fonction|() => {}| |setShow|fonction|() => {}| |validateLabel|string|'Enregistrer'| |cancelLabel|string|'Annuler'| |validateDisabled|bool|false| |hideCancel|bool|false| |width|string|''|

exemple:

<CustomModal
  title={'Ajouter un partenaire'}
  content={
    <PartenaireForm
      show={show}
      setShow={setShow}
      formfields={formfields}
      setFormFields={setFormFields}
    />
  }
  show={show}
  setShow={setShow}
  onValidate={submit}
/>

Hooks

useSetField

Lorsque une liste de champs est définie sous forme d'un objet :

const [fields, setFields] = useState({
  propA: '',
  propB: ''
})

useSetField fourni une fonction qui permet de changer la valeur d'une propriété de l'objet 'fields' :

;(propName, value) => null
1.1.13

1 month ago

2.0.13

1 month ago

2.0.14

1 month ago

1.1.12

1 month ago

2.0.12

1 month ago

2.0.9

1 month ago

1.1.11

1 month ago

1.1.10

1 month ago

2.0.11

1 month ago

2.0.10

1 month ago

2.0.5

2 months ago

2.0.7

2 months ago

2.0.6

2 months ago

2.0.8

2 months ago

2.0.3

2 months ago

2.0.2

2 months ago

2.0.4

2 months ago

2.0.1

2 months ago

1.1.9

3 months ago

1.1.8

3 months ago

1.1.7

3 months ago

1.1.6

3 months ago

1.0.79

6 months ago

1.1.1

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.0.77

7 months ago

1.0.76

10 months ago

1.0.75

10 months ago

1.0.78

7 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.70

11 months ago

1.0.74

11 months ago

1.0.62

12 months ago

1.0.61

12 months ago

1.0.60

1 year ago

1.0.64

12 months ago

1.0.63

12 months ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.37

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.40

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.49

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago