Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some common issues to README #214

Merged
merged 1 commit into from
Jan 22, 2022
Merged

Add some common issues to README #214

merged 1 commit into from
Jan 22, 2022

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Jan 21, 2022

Closes #213.

In response to #213, I thought it might be good to mention some of the more common issues that folks experience to the README.

@IanVS IanVS merged commit c797c89 into main Jan 22, 2022
@IanVS IanVS deleted the add-known-issues branch January 22, 2022 21:45
@ryota-murakami
Copy link

@IanVS Thank you so much! 😄

@reintroducing
Copy link

@IanVS I'm trying to track down why my controls are not showing up but it seems that the Known Issue in your PR has been removed from the README. I'm only seeing controls show up for the args that I'm passing to each story, not all of the possible controls that a story has. Am I missing something in the docs? I don't see anything about controls being limited to only those that the story is using and ignoring all the other possible controls.

@joshwooding
Copy link
Member

@reintroducing Are you using prop types?

@reintroducing
Copy link

@joshwooding Yes, here is an example button component, for instance:

import {forwardRef} from 'react';
import PropTypes from 'prop-types';
import {cnb} from 'cnbuilder';
import Loader from '../Loader';
import css from './Button.module.scss';

const Button = forwardRef(
    (
        {
            className,
            testAttr,
            children,
            type,
            variant,
            size,
            block,
            icon,
            iconPosition,
            disabled,
            loading,
            onClick,
            ...attrs
        },
        ref
    ) => (
        <button
            ref={ref}
            className={cnb(
                css.root,
                {[css[variant]]: variant},
                {[css[size]]: size},
                {[css.block]: block},
                {[css[`${iconPosition}Icon`]]: Boolean(icon)},
                className
            )}
            data-test={testAttr}
            type={type}
            disabled={disabled}
            onClick={onClick}
            {...attrs}
        >
            {iconPosition === 'left' &&
                (loading ? (
                    <Loader
                        className={css.leftLoader}
                        testAttr="loader"
                        inline
                    />
                ) : (
                    icon
                ))}
            {children}
            {iconPosition === 'right' &&
                (loading ? (
                    <Loader
                        className={css.rightLoader}
                        testAttr="loader"
                        inline
                    />
                ) : (
                    icon
                ))}
        </button>
    )
);

Button.propTypes = {
    /** Additional class(es) to add to the component. */
    className: PropTypes.string,
    /** The name of the test attribute to associate to the component. */
    testAttr: PropTypes.string,
    /** The markup node to insert into the button. */
    children: PropTypes.node.isRequired,
    /** The type of button that is rendered. */
    type: PropTypes.oneOf(['button', 'submit', 'reset']),
    /** The variant of the button. */
    variant: PropTypes.oneOf([
        'primary-link',
        'neutral-link',
        'destructive-link',
        'primary',
        'secondary',
        'tertiary',
        'neutral',
        'tertiary-neutral',
        'primary-destructive',
        'secondary-destructive',
        'tertiary-destructive',
        'neutral-destructive',
    ]),
    /** The size of the button. */
    size: PropTypes.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
    /** Whether the button should display as a block level element. */
    block: PropTypes.bool,
    /** A custom icon (typically one of the Icon components) to show in the button. */
    icon: PropTypes.element,
    /** If an icon is provided, whether it should appear on the left or right side of the button children. */
    iconPosition: PropTypes.oneOf(['left', 'right']),
    /** Whether the button is disabled or not. */
    disabled: PropTypes.bool,
    /** Whether to show a loading animation inside of the button. */
    loading: PropTypes.bool,
    /**
     * The handler to execute when the button is clicked.
     *
     * @param {SyntheticEvent} evt - The React `SyntheticEvent`.
     */
    onClick: PropTypes.func,
};

Button.defaultProps = {
    testAttr: 'button',
    type: 'button',
    variant: 'primary-link',
    size: 'lg',
    iconPosition: 'left',
};

export default Button;

The default story looks like this:

export const Default = Template.bind({});

Default.args = {
    children: 'Button Label',
};

This produces the control with children in it, but all other prop types are ignored. I'm migrating from webpack and this was working correctly in the webpack variant of my stories.

@joshwooding
Copy link
Member

@reintroducing Unfortunately docgen for PropTypes isn't currently supported. This should be fixed with #190

@reintroducing
Copy link

@joshwooding Ah, thank you, so it works for TS but not just regular ole JS from what I gather. I'll watch that PR, appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please pinned issue "Controls not automatically generated for Single File Components #46"
4 participants