Skip to content

Commit

Permalink
Merge pull request #1457 from Adslot/fix-radio-checkbox-docs
Browse files Browse the repository at this point in the history
docs: fix propType descriptions
  • Loading branch information
xiaofan2406 authored Jul 11, 2022
2 parents 231c3bc + 0f9a5ca commit 885f7ce
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/components/Anchor/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface AnchorProps extends React.AnchorHTMLAttributes<HTMLAnchorElemen
className?: string;
dts?: string;
disabled?: boolean;
children?: React.ReactNode;
}

declare const Anchor: React.FC<AnchorProps>;
Expand Down
10 changes: 8 additions & 2 deletions src/components/Anchor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { expandDts, invariant } from '../../lib/utils';
import { buttonSharedPropTypes, buttonSharedClasses, colors, variants, sizes } from '../Button';
import { buttonSharedClasses, colors, variants, sizes } from '../Button';

const Anchor = (props) => {
const {
Expand Down Expand Up @@ -66,8 +66,14 @@ Anchor.propTypes = {
color: PropTypes.oneOf(colors),
variant: PropTypes.oneOf(variants),
size: PropTypes.oneOf(sizes),
...buttonSharedPropTypes,
href: PropTypes.string.isRequired,
round: PropTypes.bool,
icon: PropTypes.node,
fullWidth: PropTypes.bool,
className: PropTypes.string,
dts: PropTypes.string,
disabled: PropTypes.bool,
children: PropTypes.node,
};

export default Anchor;
1 change: 1 addition & 0 deletions src/components/Button/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
className?: string;
dts?: string;
disabled?: boolean;
children?: React.ReactNode;
}

declare const Button: React.FC<ButtonProps>;
Expand Down
18 changes: 8 additions & 10 deletions src/components/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Button = (props) => {
} = props;
const isLink = variant === 'link' || className?.match(/\b(aui-link)\b/)?.[0];

// eslint-disable-next-line react/prop-types
invariant(!props.href, 'Button: should not be used for href links. Use an <Anchor/> instead.');
invariant(!theme, 'Button: The theme prop has been deprecated. Please use color instead.');
invariant(!inverse, 'Button: The inverse prop has been deprecated. Please use variant="inverse" instead.');
Expand Down Expand Up @@ -96,15 +97,6 @@ export const colors = ['default', 'primary', 'secondary', 'success', 'danger', '
export const variants = ['solid', 'borderless', 'inverse', 'link'];
export const sizes = ['medium', 'large'];

export const buttonSharedPropTypes = {
round: PropTypes.bool,
icon: PropTypes.node,
fullWidth: PropTypes.bool,
className: PropTypes.string,
dts: PropTypes.string,
disabled: PropTypes.bool,
};

Button.propTypes = {
isLoading: PropTypes.bool,
color: PropTypes.oneOf(colors),
Expand All @@ -120,7 +112,13 @@ Button.propTypes = {
* Please use `variant="inverse"` instead.
*/
inverse: PropTypes.bool,
...buttonSharedPropTypes,
round: PropTypes.bool,
icon: PropTypes.node,
fullWidth: PropTypes.bool,
className: PropTypes.string,
dts: PropTypes.string,
disabled: PropTypes.bool,
children: PropTypes.node,
};

export default Button;
6 changes: 6 additions & 0 deletions src/components/Checkbox/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export interface CheckboxProps {
* checkBox label for the checkbox input
*/
label?: React.ReactNode;
/**
* additional text description to display below the label
*/
text?: React.ReactNode;
/**
* icon to display beside the label when parent group's `variant="box"`
*/
icon?: React.ReactNode;
/**
* checkBox input value
Expand Down
6 changes: 6 additions & 0 deletions src/components/Checkbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ Checkbox.propTypes = {
* checkBox label for the checkbox input
*/
label: PropTypes.node,
/**
* additional text description to display below the label
*/
text: PropTypes.node,
/**
* icon to display beside the label when parent group's `variant="box"`
*/
icon: PropTypes.node,
/**
* checkBox input value
Expand Down
12 changes: 12 additions & 0 deletions src/components/CheckboxGroup/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ export type CheckboxGroupVariant = 'default' | 'box';
export interface CheckboxGroupProps {
value: any[];
name: string;
/**
* @function onChange
* @param {array} newValue - the new checkboxGroup value
* @param {string} name - the checkbox name
* @param {string|number} value - the changed checkbox's value
*/
onChange: (...args: any[]) => any;
/**
* @function getIsChecked overrides the default checked state behaviour
* @param {string|number} itemValue - the checkbox's value
* @param {array} value - the checkbox group's value
*/
getIsChecked?: (...args: any[]) => any;
orientation?: CheckboxGroupOrientation;
children: React.ReactNode;
className?: string;
Expand Down
26 changes: 24 additions & 2 deletions src/components/CheckboxGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { invariant } from '../../lib/utils';
import { radioGroupSharedPropTypes } from '../RadioGroup';
import '../RadioGroup/style.css';

const CheckboxGroupContext = React.createContext({});
Expand Down Expand Up @@ -74,7 +73,30 @@ const CheckboxGroup = ({

CheckboxGroup.propTypes = {
value: PropTypes.array.isRequired,
...radioGroupSharedPropTypes,
name: PropTypes.string.isRequired,
/**
* @function onChange
* @param {array} newValue - the new checkboxGroup value
* @param {string} name - the checkbox name
* @param {string|number} value - the changed checkbox's value
*/
onChange: PropTypes.func.isRequired,
/**
* @function getIsChecked overrides the default checked state behaviour
* @param {string|number} itemValue - the checkbox's value
* @param {array} value - the checkbox group's value
*/
getIsChecked: PropTypes.func,
orientation: PropTypes.oneOf(['vertical', 'horizontal']),
children: PropTypes.node.isRequired,
className: PropTypes.string,
dts: PropTypes.string,
variant: PropTypes.oneOf(['default', 'box']),
id: PropTypes.string,
/**
* @deprecated use orientation="horizontal" instead
**/
inline: PropTypes.bool,
};

export default CheckboxGroup;
9 changes: 9 additions & 0 deletions src/components/Radio/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ export interface RadioProps {
className?: string;
name?: string;
label?: React.ReactNode;
/**
* additional text description to display below the label
*/
text?: React.ReactNode;
/**
* icon to display beside the label when parent group's `variant="box"`
*/
icon?: React.ReactNode;
value?: RadioValue;
dts?: string;
Expand All @@ -17,6 +23,9 @@ export interface RadioProps {
* @param {string|number} value - the radio value
*/
onChange?: (...args: any[]) => any;
/**
* checked status of the radio input
*/
checked?: boolean;
/**
* @deprecated
Expand Down
9 changes: 9 additions & 0 deletions src/components/Radio/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ Radio.propTypes = {
className: PropTypes.string,
name: PropTypes.string,
label: PropTypes.node,
/**
* additional text description to display below the label
*/
text: PropTypes.node,
/**
* icon to display beside the label when parent group's `variant="box"`
*/
icon: PropTypes.node,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
dts: PropTypes.string,
Expand All @@ -111,6 +117,9 @@ Radio.propTypes = {
* @param {string|number} value - the radio value
*/
onChange: PropTypes.func,
/**
* checked status of the radio input
*/
checked: PropTypes.bool,
/**
* @deprecated
Expand Down
8 changes: 2 additions & 6 deletions src/components/RadioGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const RadioGroup = ({
);
};

export const radioGroupSharedPropTypes = {
RadioGroup.propTypes = {
value: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
orientation: PropTypes.oneOf(['vertical', 'horizontal']),
Expand All @@ -83,9 +84,4 @@ export const radioGroupSharedPropTypes = {
inline: PropTypes.bool,
};

RadioGroup.propTypes = {
value: PropTypes.string.isRequired,
...radioGroupSharedPropTypes,
};

export default RadioGroup;
6 changes: 5 additions & 1 deletion www/containers/Props.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const Props = ({ componentName, customMapper }) => {
<td>
<code>{_.get(prop, 'defaultValue.value', '')}</code>
</td>
<td>{HtmlParser(prop.description)}</td>
<td>
{prop.description?.split('\n').map((line, i) => (
<div key={i}>{HtmlParser(line)}</div>
))}
</td>
</tr>
))}
</tbody>
Expand Down
Loading

0 comments on commit 885f7ce

Please sign in to comment.