reactjs / reactjs/react-docgen

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

オープン
#308 コメント 1 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
TypeScript
スター
3.8k
フォーク
316
平均マージ
5時間 7分
マージ済み PR(30日)
4

説明

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;

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

CheckBox.js の例から始め、react-docgen がエクスポートされた CheckBox と、エクスポートされていない Wrapper、Input、Label の styled-components をどのように扱うかを調査します。生成されたドキュメントで theme props を表現できるかどうかを確認します。完了条件は、文書化されたサポート対象の方法、または明確な制限のいずれかが示されていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。