reactjs / reactjs/react-docgen

How do I extend docgen to parse non-exported styled-components?

Ouverte
#308 1 commentaire 4 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
TypeScript
Étoiles
3.8k
Forks
316
Merge moyen
5 h 7 min
PR mergées (30 j)
4

Description

I have the following component CheckBox. Notice I have styled-components that I create in this file and use in this file: Wrapper, Input, and Label. I haven't seen a way to use react-docgen to pickup each props.theme.VAR_NAME and be displayed with the CheckBox documentation.

I have seen examples of creating styled-components in their own files and then doing:

/** @component */
export default Wrapper;

CheckBox.js

import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

const Wrapper = styled.div`
  margin: ${props => props.theme.checkbox_margin};
  position: relative;
  text-align: left;
`;

const Input = styled.input`
  outline: 0;
  visibility: hidden;
  width: ${props => props.theme.checkbox_size};
  margin: 0;
  display: block;
  float: left;
  font-size: inherit;

  &:checked {
     + label:before {
      background: ${props => props.theme.checkbox_checked_color};
      border:none;
    }
    
    + label:after {
      transform: translate(${props => props.theme.checkbox_padding}, calc(calc(${props => props.theme.checkbox_size} / 2) - calc(calc(${props => props.theme.checkbox_size} - 2 * ${props => props.theme.checkbox_padding}) / 2.6))) rotate(-45deg);
      width: calc(${props => props.theme.checkbox_size} - 2 * ${props => props.theme.checkbox_padding});
      height: calc(calc(${props => props.theme.checkbox_size} - 2 * ${props => props.theme.checkbox_padding}) / 2);
      border: ${props => props.theme.checkmark_width} solid ${props => props.theme.checkmark_color};
      border-top-style: none;
      border-right-style: none;
    } 
  }
  
  &:disabled {
    + label:before{
      border-color: ${props => props.theme.checkbox_border_color_disabled};
    }
    
    &:checked {
      + label:before{
        background: ${props => props.theme.checkbox_checked_color_disabled};
      }
    }
  }
`;

const Label = styled.label`
  cursor: pointer;
  display: inline;
  line-height: ${props => props.theme.checkbox_size};
  vertical-align: top;
  clear: both;
  padding-left: 1px;
  
  &:not(:empty) {
    padding-left: ${props => props.theme.checkbox_label_padding};
  }
  
  &:before, &:after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
  }
  
  &:before {
    // box
    width: ${props => props.theme.checkbox_size};
    height: ${props => props.theme.checkbox_size};
    background: #fff;
    border: ${props => props.theme.checkbox_border_width} solid ${props => props.theme.checkbox_border_color};
    border-radius: ${props => props.theme.checkbox_border_radius};
    cursor: pointer;
    transition: background .3s;
  }

  &:after {
    // checkmark
  }
`;

/**
 * A checkbox with a label on the right side.
 */
const CheckBox = ({id, label, ...props}) => (
  <Wrapper>
    <Input id={id} type={'checkbox'}/>
    <Label htmlFor={id}>{label}</Label>
  </Wrapper>
);

CheckBox.propTypes = {
  /** The HTML id attribute value. This will need to be unique as the label uses it to define what the label is attached to. */
  id: PropTypes.string.isRequired,
  /** The string of text that's displayed as the checkbox label. */
  label: PropTypes.string.isRequired,
};

CheckBox.defaultProps = {
  id: "cb1",
  label: "Label Name",
};

export default CheckBox;

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’exemple CheckBox.js et examinez comment react-docgen gère le CheckBox exporté par rapport aux styled-components Wrapper, Input et Label non exportés. Déterminez si les theme props peuvent être représentées dans la documentation générée ; le résultat doit être soit une approche documentée et prise en charge, soit une limitation claire.

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

Évaluation

Stack technique
javascript, react
Domaine
documentation
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

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