Skip to content

Commit

Permalink
After review fixes (#674).
Browse files Browse the repository at this point in the history
  • Loading branch information
martachrzanowska committed Dec 7, 2020
1 parent 0e26a21 commit 2f8b865
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 39 deletions.
5 changes: 3 additions & 2 deletions packages/uniforms-antd/src/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function Date({
disabled={props.disabled}
name={props.name}
onChange={value => {
props.onChange(value ? value.toDate() : undefined);
props.readOnly
? undefined
: props.onChange(value ? value.toDate() : undefined);
}}
placeholder={props.placeholder}
readOnly={props.readOnly}
// @ts-ignore: `DatePicker` is an intersection.
ref={props.inputRef}
showTime={showTime}
Expand Down
9 changes: 6 additions & 3 deletions packages/uniforms-antd/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function ListAdd({
disabled,
icon = <PlusSquareOutlined />,
name,
readOnly,
size = 'small',
style = defaultStyle,
type = 'dashed',
Expand All @@ -44,9 +45,11 @@ function ListAdd({
{...filterDOMProps(props)}
disabled={!limitNotReached}
icon={icon}
onClick={() => {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}}
onClick={() =>
readOnly
? undefined
: parent.onChange(parent.value!.concat([cloneDeep(value)]))
}
size={size}
style={style}
type={type}
Expand Down
11 changes: 8 additions & 3 deletions packages/uniforms-antd/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function ListDel({
disabled,
icon = <DeleteOutlined />,
name,
readOnly,
shape = 'circle-outline',
size = 'small',
type = 'ghost',
Expand All @@ -38,9 +39,13 @@ function ListDel({
disabled={!limitNotReached}
icon={icon}
onClick={() => {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
if (readOnly) {
undefined;
} else {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
}
}}
shape={shape}
size={size}
Expand Down
5 changes: 3 additions & 2 deletions packages/uniforms-bootstrap3/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export type ListAddFieldProps = HTMLFieldProps<
>;

function ListAdd({
name,
addIcon,
className,
disabled,
name,
readOnly,
value,
...props
}: ListAddFieldProps) {
Expand All @@ -39,7 +40,7 @@ function ListAdd({
{...filterDOMProps(props)}
className={classnames('badge pull-right', className)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}
}}
Expand Down
5 changes: 3 additions & 2 deletions packages/uniforms-bootstrap3/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export type ListDelFieldProps = HTMLFieldProps<
>;

function ListDel({
name,
className,
disabled,
name,
readOnly,
removeIcon,
...props
}: ListDelFieldProps) {
Expand All @@ -37,7 +38,7 @@ function ListDel({
{...filterDOMProps(props)}
className={classnames('badge', className)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
Expand Down
5 changes: 3 additions & 2 deletions packages/uniforms-bootstrap4/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export type ListAddFieldProps = HTMLFieldProps<
>;

function ListAdd({
name,
addIcon,
className,
disabled,
name,
readOnly,
value,
...props
}: ListAddFieldProps) {
Expand All @@ -39,7 +40,7 @@ function ListAdd({
{...filterDOMProps(props)}
className={classnames('badge badge-pill float-right', className)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}
}}
Expand Down
5 changes: 3 additions & 2 deletions packages/uniforms-bootstrap4/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export type ListDelFieldProps = HTMLFieldProps<
>;

function ListDel({
name,
className,
disabled,
name,
readOnly,
removeIcon,
...props
}: ListDelFieldProps) {
Expand All @@ -38,7 +39,7 @@ function ListDel({
{...filterDOMProps(props)}
className={classnames('badge badge-pill', className)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
Expand Down
9 changes: 6 additions & 3 deletions packages/uniforms-material/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function ListAdd({
icon = '+',
margin = 'dense',
name,
readOnly,
value,
variant,
...props
Expand All @@ -48,9 +49,11 @@ function ListAdd({
<IconButton
{...filterDOMProps(props)}
disabled={!limitNotReached}
onClick={() => {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}}
onClick={() =>
readOnly
? undefined
: parent.onChange(parent.value!.concat([cloneDeep(value)]))
}
>
{icon}
</IconButton>
Expand Down
18 changes: 14 additions & 4 deletions packages/uniforms-material/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export type ListDelFieldProps = FieldProps<
{ icon?: ReactNode }
>;

function ListDel({ disabled, icon = '-', name, ...props }: ListDelFieldProps) {
function ListDel({
disabled,
icon = '-',
name,
readOnly,
...props
}: ListDelFieldProps) {
const nameParts = joinName(null, name);
const nameIndex = +nameParts[nameParts.length - 1];
const parentName = joinName(nameParts.slice(0, -1));
Expand All @@ -32,9 +38,13 @@ function ListDel({ disabled, icon = '-', name, ...props }: ListDelFieldProps) {
{...filterDOMProps(props)}
disabled={!limitNotReached}
onClick={() => {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
if (readOnly) {
undefined;
} else {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
}
}}
>
{icon}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-material/src/wrapField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function wrap(
error: !!error,
fullWidth: !!fullWidth,
margin,
readOnly: !!readOnly,
readOnly,
required,
variant,
};
Expand Down
10 changes: 8 additions & 2 deletions packages/uniforms-semantic/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export type ListAddFieldProps = HTMLFieldProps<
{ initialCount?: number }
>;

function ListAdd({ disabled, name, value, ...props }: ListAddFieldProps) {
function ListAdd({
disabled,
name,
readOnly,
value,
...props
}: ListAddFieldProps) {
const nameParts = joinName(null, name);
const parentName = joinName(nameParts.slice(0, -1));
const parent = useField<{ maxCount?: number }, unknown[]>(
Expand All @@ -37,7 +43,7 @@ function ListAdd({ disabled, name, value, ...props }: ListAddFieldProps) {
'fitted add icon',
)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}
}}
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-semantic/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ListDelFieldProps = HTMLFieldProps<
{ name: string }
>;

function ListDel({ disabled, name, ...props }: ListDelFieldProps) {
function ListDel({ disabled, name, readOnly, ...props }: ListDelFieldProps) {
const nameParts = joinName(null, name);
const nameIndex = +nameParts[nameParts.length - 1];
const parentName = joinName(nameParts.slice(0, -1));
Expand All @@ -37,7 +37,7 @@ function ListDel({ disabled, name, ...props }: ListDelFieldProps) {
'fitted close icon',
)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
Expand Down
8 changes: 1 addition & 7 deletions packages/uniforms-unstyled/src/BoolField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ function Bool({
disabled={disabled}
id={id}
name={name}
onChange={
disabled || readOnly
? undefined
: () => {
onChange(!value);
}
}
onChange={() => (disabled || readOnly ? undefined : onChange(!value))}
ref={inputRef}
type="checkbox"
/>
Expand Down
10 changes: 8 additions & 2 deletions packages/uniforms-unstyled/src/ListAddField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export type ListAddFieldProps = HTMLFieldProps<
{ initialCount?: number }
>;

function ListAdd({ disabled, name, value, ...props }: ListAddFieldProps) {
function ListAdd({
disabled,
name,
readOnly,
value,
...props
}: ListAddFieldProps) {
const nameParts = joinName(null, name);
const parentName = joinName(nameParts.slice(0, -1));
const parent = useField<{ maxCount?: number }, unknown[]>(
Expand All @@ -30,7 +36,7 @@ function ListAdd({ disabled, name, value, ...props }: ListAddFieldProps) {
<span
{...filterDOMProps(props)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
parent.onChange(parent.value!.concat([cloneDeep(value)]));
}
}}
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-unstyled/src/ListDelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

export type ListDelFieldProps = HTMLFieldProps<unknown, HTMLSpanElement>;

function ListDel({ disabled, name, ...props }: ListDelFieldProps) {
function ListDel({ disabled, name, readOnly, ...props }: ListDelFieldProps) {
const nameParts = joinName(null, name);
const nameIndex = +nameParts[nameParts.length - 1];
const parentName = joinName(nameParts.slice(0, -1));
Expand All @@ -26,7 +26,7 @@ function ListDel({ disabled, name, ...props }: ListDelFieldProps) {
<span
{...filterDOMProps(props)}
onClick={() => {
if (limitNotReached) {
if (limitNotReached && !readOnly) {
const value = parent.value!.slice();
value.splice(nameIndex, 1);
parent.onChange(value);
Expand Down

0 comments on commit 2f8b865

Please sign in to comment.