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

Fix default props #1235

Merged
merged 5 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@ type AvatarProps = {
url?: string;
};

function Avatar(props: AvatarProps) {
function Avatar({
ariaHidden,
colorId,
image,
initials,
large,
name = '',
showAlert,
url,
}: AvatarProps) {
const [imageLoadFailed, setImageLoadFailed] = useState(false);

function onImageLoadError() {
setImageLoadFailed(true);
}

function wrapIfUrlPresent(content) {
if (props.url) {
if (url) {
return (
<a
href={props.url}
href={url}
rel="noopener noreferrer"
target="_blank"
>
Expand All @@ -38,36 +47,36 @@ function Avatar(props: AvatarProps) {
return content;
}

const displayImage = props.image && !imageLoadFailed;
const displayImage = image && !imageLoadFailed;
const content = displayImage ? (
<img
alt={props.name}
src={props.image}
alt={name}
src={image}
onError={onImageLoadError}
/>
) : (
<span className="Avatar__circle__initials">
{props.initials}
{initials}
</span>
);

return (
<div
aria-hidden={props.ariaHidden}
aria-hidden={ariaHidden}
className={classNames(
'Avatar',
{ 'Avatar--large': props.large },
{ 'Avatar--large': large },
)}
>
<div
className={classNames([
'Avatar__circle',
{ [uiModClassName(props.colorId)]: !!props.colorId },
{ [uiModClassName(colorId)]: !!colorId },
])}
>
{wrapIfUrlPresent(content)}
</div>
{props.showAlert && (
{showAlert && (
<div className="Avatar__alert" />
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Col.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Col = ({
xl,
xs,
xxl,
bsPrefix,
bsPrefix = 'col',
...props
}: ColProps) => (
<ReactBootstrapCol
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Container = ({
children,
className,
fluid,
bsPrefix,
bsPrefix = 'container',
...props
}: ContainerProps) => (
<ReactBootstrapContainer
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Row = ({
xl,
xs,
xxl,
bsPrefix,
bsPrefix = 'row',
...props
}: RowProps) => (
<ReactBootstrapRow
Expand Down
2 changes: 1 addition & 1 deletion src/CopyToClipboardButton/CopyToClipboardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CopyToClipboardButtonProps = {

function CopyToClipboardButton({
copyText = '',
displayText = undefined,
displayText,
trackingEvent,
variant = ButtonVariants.NEUTRAL,
}: CopyToClipboardButtonProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DrawerProps = {

const Drawer = ({
behindNav = true,
children = undefined,
children,
className = '',
defaultExpanded = false,
expandable = false,
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/DrawerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type DrawerHeaderProps = {
};

const DrawerHeader = ({
bordered,
bordered = true,
title,
onRequestClose,
}: DrawerHeaderProps) => {
Expand Down
8 changes: 4 additions & 4 deletions src/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ type DropdownProps = {
} & RBDropdownProps;

const Dropdown = ({
align,
align = 'start',
as,
autoClose,
autoClose = true,
bsPrefix = 'dropdown',
children,
className,
drop,
flip,
focusFirstItemOnShow,
navbar,
navbar = false,
onSelect,
onToggle,
show,
bsPrefix,
...props
}: DropdownProps) => (
<RBDropdown
Expand Down
4 changes: 2 additions & 2 deletions src/Dropdown/DropdownDivider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type DropdownDividerProps = {
};

const DropdownDivider = ({
as,
bsPrefix,
as = 'hr',
bsPrefix = 'dropdown',
className,
}: DropdownDividerProps) => (
<RBDropdown.Divider
Expand Down
2 changes: 1 addition & 1 deletion src/Dropdown/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const DropdownMenu = ({
as,
children,
className,
flip,
flip = true,
onSelect,
popperConfig,
renderOnMount,
Expand Down
4 changes: 2 additions & 2 deletions src/Dropdown/DropdownToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type DropdownToggleProps = {

const DropdownToggle = ({
as,
ariaLabel,
bsPrefix,
ariaLabel = 'dropdown-toggle',
bsPrefix = 'dropdown-toggle',
childBsPrefix,
children,
className,
Expand Down
11 changes: 5 additions & 6 deletions src/FormGroup/FormGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ export type FormGroupProps = {
export default function FormGroup({
bordered,
children,
className,
displayErrorText,
className = '',
displayErrorText = true,
elementType = 'div',
errors = {},
helperText,
id,
inline,
inputKey,
label,
labelClassName,
label = '',
labelClassName = '',
labelHelperText,
labelHtmlFor,
labelHtmlFor = '',
labelTooltip,
required,
}: FormGroupProps) {
Expand All @@ -90,7 +90,6 @@ export default function FormGroup({
<InputLegend
className={labelClassName}
labelHelperText={labelHelperText}
labelHtmlFor={labelHtmlFor}
required={required}
text={label}
tooltipText={labelTooltip}
Expand Down
6 changes: 3 additions & 3 deletions src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
id,
leadingIcon,
name,
placeholder,
placeholder = '',
trailingIcon,
trailingIconLabel,
trailingIconLabel = '',
trailingIconOnClick,
kyleshike marked this conversation as resolved.
Show resolved Hide resolved
trailingIconOnClickSubmit,
trailingText,
type,
type = 'text',
value,
onChange,
...rest
Expand Down
6 changes: 3 additions & 3 deletions src/InputLabel/InputLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export type InputLabelProps = {
} & LabelProps;

const InputLabel = ({
className,
labelHtmlFor,
className = '',
labelHtmlFor = '',
text,
required,
labelHelperText,
labelHelperText = '',
tooltipText,
...props
}: InputLabelProps) => {
Expand Down
5 changes: 2 additions & 3 deletions src/InputLegend/InputLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ type LegendProps = React.DetailedHTMLProps<
export type InputLegendProps = {
className?: string;
labelHelperText?: React.ReactNode;
labelHtmlFor?: string;
required?: boolean;
text: string;
tooltipText?: React.ReactNode;
} & LegendProps;

const InputLegend = ({
className,
className = '',
text,
required,
labelHelperText,
labelHelperText = '',
tooltipText,
...props
}: InputLegendProps) => {
Expand Down
6 changes: 3 additions & 3 deletions src/LoadingOverlay/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type LoadingOverlayProps = {
};

const LoadingOverlay = ({
contentCenterOverflow,
contentTop,
contentCenterOverflow = false,
contentTop = false,
dataTestid = 'LoadingOverlay',
header,
kyleshike marked this conversation as resolved.
Show resolved Hide resolved
text,
textClassName,
visible,
visible = true,
}: LoadingOverlayProps) => {
// Only set style if this is not visible to let CSS handle how to display this
const classes = classNames(
Expand Down
2 changes: 1 addition & 1 deletion src/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Main = ({
as = 'main',
className,
children,
fluid,
fluid = true,
id,
...props
}: MainProps) => (
Expand Down
2 changes: 1 addition & 1 deletion src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Modal = ({
className,
...props
}: ModalProps) => {
let componentClassName = '';
let componentClassName = className;

if (size === MODAL_SIZES.MEDIUM) {
componentClassName = classNames(className, 'ReactModal--medium');
Expand Down
8 changes: 8 additions & 0 deletions src/Modal/ModalFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export default class ModalFooter extends Component<ModalFooterProps> {

handleCloseClick = () => this.props.onRequestClose && this.props.onRequestClose();

// eslint-disable-next-line react/static-property-placement
static defaultProps: {
children: undefined;
closingIsDisabled: boolean;
dismissButtonText: string;
onRequestClose: undefined;
};

render() {
return (
<div className="ModalFooter">
Expand Down
15 changes: 14 additions & 1 deletion src/MoneyInput/MoneyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,23 @@ export type MoneyInputProps = CurrencyInputProps & {
};

const MoneyInput = ({
allowDecimals = true,
allowNegativeValue = true,
disabled = false,
className,
intlConfig = { locale: 'en-US', currency: 'USD' },
prefix = '$ ',
...props
}: MoneyInputProps) => (
<CurrencyInput className={classNames(className, 'MoneyInput', 'form-control')} {...props} />
<CurrencyInput
allowDecimals={allowDecimals}
allowNegativeValue={allowNegativeValue}
className={classNames(className, 'MoneyInput', 'form-control')}
disabled={disabled}
intlConfig={intlConfig}
prefix={prefix}
{...props}
/>
);

export default MoneyInput;
4 changes: 2 additions & 2 deletions src/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type RadioButtonProps = {
const RadioButton = React.forwardRef<HTMLInputElement, RadioButtonProps>(({
checked,
className,
disabled,
disabled = false,
id,
name,
name = '',
value,
onChange,
...rest
Expand Down
Loading