Skip to content

Commit

Permalink
fix(Form): Remove last usages of default props
Browse files Browse the repository at this point in the history
  • Loading branch information
lordrip committed Oct 14, 2024
1 parent 8626e3c commit af8d39f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/BoolField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ export type BoolFieldProps = FieldProps<
}
>;

function BoolField({ appearance, disabled, id, inputRef, label, name, onChange, value, deprecated, ...props }: BoolFieldProps) {
function BoolField({ appearance = ComponentType.checkbox, disabled, id, inputRef, label, name, onChange, value, deprecated, ...props }: BoolFieldProps) {
const Component = appearance === ComponentType.switch ? Switch : Checkbox;
let defaultValue;

if (typeof props.field === 'object' && props.field !== null && 'default' in props.field && typeof props.field.default === 'boolean') {
defaultValue = props.field.default.toString();
}

return wrapField(
{ id, ...props },
<div style={{ display: 'flex', alignItems: 'center' }}>
Expand All @@ -73,6 +75,4 @@ function BoolField({ appearance, disabled, id, inputRef, label, name, onChange,
);
}

BoolField.defaultProps = { appearance: ComponentType.checkbox };

export default connectField(BoolField);
34 changes: 18 additions & 16 deletions src/ErrorField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,36 @@
* under the License.
*/

import * as React from "react";
import { HTMLProps } from "react";
import { connectField, filterDOMProps, Override } from "uniforms";
import * as React from 'react';
import { HTMLProps } from 'react';
import { connectField, filterDOMProps, Override } from 'uniforms';

export type ErrorFieldProps = Override<
HTMLProps<HTMLDivElement>,
{
error?: boolean;
errorMessage?: string;
style?: React.CSSProperties;
}
>;

function ErrorField({ children, error, errorMessage, ...props }: ErrorFieldProps) {
const defaultStyle: React.CSSProperties = {
backgroundColor: 'rgba(255, 85, 0, 0.2)',
border: '1px solid rgb(255, 85, 0)',
borderRadius: '7px',
margin: '20px 0px',
padding: '10px',
};

function ErrorField({ children, error, errorMessage, style = {}, ...props }: ErrorFieldProps) {
// Merge default styles with any styles passed via props
const combinedStyle: React.CSSProperties = { ...defaultStyle, ...style };

return !error ? null : (
<div data-testid={"error-field"} {...filterDOMProps(props)}>
{children ? children : <div style={{ margin: "3px" }}>{errorMessage}</div>}
<div data-testid={'error-field'} style={combinedStyle} {...filterDOMProps(props)}>
{children ? children : <div style={{ margin: '3px' }}>{errorMessage}</div>}
</div>
);
}

ErrorField.defaultProps = {
style: {
backgroundColor: "rgba(255, 85, 0, 0.2)",
border: "1px solid rgb(255, 85, 0)",
borderRadius: "7px",
margin: "20px 0px",
padding: "10px",
},
};

export default connectField<ErrorFieldProps>(ErrorField, { initialValue: false });
12 changes: 5 additions & 7 deletions src/SubmitField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
* under the License.
*/

import * as React from "react";
import { Button, ButtonProps } from "@patternfly/react-core/dist/js/components/Button";
import { Override, useForm } from "uniforms";
import { Button, ButtonProps } from '@patternfly/react-core/dist/js/components/Button';
import * as React from 'react';
import { Override, useForm } from 'uniforms';

export type SubmitFieldProps = Override<ButtonProps, { inputRef?: React.RefObject<HTMLButtonElement> }>;

function SubmitField({ disabled, inputRef, value, ...props }: SubmitFieldProps) {
function SubmitField({ disabled, inputRef, value = 'Submit', ...props }: SubmitFieldProps) {
const { error, state } = useForm();

return (
<Button
data-testid={"submit-field"}
data-testid={'submit-field'}
isDisabled={disabled === undefined ? !!(error || state.disabled) : disabled}
type="submit"
ref={inputRef}
Expand All @@ -39,6 +39,4 @@ function SubmitField({ disabled, inputRef, value, ...props }: SubmitFieldProps)
);
}

SubmitField.defaultProps = { value: "Submit" };

export default SubmitField;

0 comments on commit af8d39f

Please sign in to comment.