gajus / gajus/babel-plugin-react-css-modules

Passing multiple style props to a child component

Ouverte
#306 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
2k
Forks
159
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I have a child component, which accepts multiple props for styles, one for the container, and other for one of the internal elements. Generally, I would just name them something like `className` and `elementClassName`, and get different css classes from the parent in each of the props. With `react-css-modules` though, since the default rule only allows converting `styleName` to `className`, I can not pass different local classes in multiple props, as i can only have 1 `styleName` prop.

One of the way around this seems to be to use named imports instead of anonymous imports and then pass `styles.containerClass` in className and `styles.elementClass` in `elementClassName` prop. This does not require using the `styleName` prop at all.

```
import styles from './some.css';

...
...

...
...
```

This seems alright, and the other existing `styleName` in the file do not break, still work alright and do not need to be changed to `styles.soemthing`, but it is slightly confusing that the named import is being only used at one place, and at the rest of the places the anonymous string value in `styleName` still works fine.

Is there another preferred / prescribed approach to handle the above scenario?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Aucun fichier, test ou point d’entrée n’est mentionné. Commencez par examiner la gestion de styleName et des imports nommés de modules CSS par le plugin, puis consultez la documentation et les exemples existants concernant plusieurs props de style. Le travail est considéré comme terminé lorsqu’une approche claire et prise en charge a été identifiée et documentée, ou lorsque le comportement demandé a été défini si la prise en charge est absente.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, react
Domaine
frontend
Type d'issue
Fonctionnalité
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
20/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.