Skip to content

Commit

Permalink
fixes pt1
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestTeluk committed Jun 14, 2024
1 parent 3ecbdc4 commit e1f7429
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 34 deletions.
1 change: 0 additions & 1 deletion packages/uniforms-mantine/src/BaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function Mantine(parent: any) {
class _ extends parent {
static Mantine = Mantine;

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions -- comes from uniform's core
static displayName = `Mantine${parent.displayName}`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/BoolField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Checkbox, CheckboxProps } from '@mantine/core';
import React, { Ref } from 'react';
import { connectField, filterDOMProps, FieldProps } from 'uniforms';
import { Checkbox, CheckboxProps } from '@mantine/core';

export type BoolFieldProps = FieldProps<
boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/ErrorsField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { List } from '@mantine/core';
import React, { HTMLProps } from 'react';
import { filterDOMProps, useForm } from 'uniforms';
import { List } from '@mantine/core';

export type ErrorsFieldProps = HTMLProps<HTMLDivElement>;

Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-mantine/src/HiddenField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TextInput } from '@mantine/core';
import React, { HTMLProps, Ref, useEffect } from 'react';
import { Override, filterDOMProps, useField } from 'uniforms';

Expand All @@ -21,14 +22,13 @@ export default function HiddenField({ value, ...rawProps }: HiddenFieldProps) {
});

return props.noDOM ? null : (
<input
<TextInput
mb="xs"
disabled={props.disabled}
name={props.name}
readOnly={props.readOnly}
ref={props.inputRef}
type="hidden"
// @ts-expect-error `value` should be serializable.
value={value ?? props.value ?? ''}
{...filterDOMProps(props)}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-mantine/src/ListAddField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Button, ButtonProps } from '@mantine/core';
import { IconSquarePlus } from '@tabler/icons-react';
import cloneDeep from 'lodash/cloneDeep';
import React from 'react';
import {
Expand All @@ -7,8 +9,6 @@ import {
joinName,
useField,
} from 'uniforms';
import { Button, ButtonProps } from '@mantine/core';
import { IconSquarePlus } from '@tabler/icons-react';

export type ListAddFieldProps = FieldProps<
unknown,
Expand Down
14 changes: 10 additions & 4 deletions packages/uniforms-mantine/src/ListDelField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ActionIcon, ActionIconProps } from '@mantine/core';
import { IconTrash } from '@tabler/icons-react';
import React from 'react';
import {
FieldProps,
Expand All @@ -6,12 +8,16 @@ import {
joinName,
useField,
} from 'uniforms';
import { ActionIcon, ActionIconProps } from '@mantine/core';
import { IconTrash } from '@tabler/icons-react';

export type ListDelFieldProps = FieldProps<unknown, ActionIconProps>;

function ListDel({ disabled, name, readOnly, ...props }: ListDelFieldProps) {
function ListDel({
disabled,
name,
readOnly,
icon = <IconTrash size="1rem" color="white" />,
...props
}: ListDelFieldProps) {
const nameParts = joinName(null, name);
const nameIndex = +nameParts[nameParts.length - 1];
const parentName = joinName(nameParts.slice(0, -1));
Expand All @@ -34,7 +40,7 @@ function ListDel({ disabled, name, readOnly, ...props }: ListDelFieldProps) {
parent.onChange(value);
}}
>
<IconTrash size="1rem" color="white" />
{icon}
</ActionIcon>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/ListField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Input, List as ListMantine, ListProps, Tooltip } from '@mantine/core';
import React, { Children, cloneElement, isValidElement } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import { Input, List as ListMantine, ListProps, Tooltip } from '@mantine/core';

import ListAddField from './ListAddField';
import ListItemField from './ListItemField';
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/ListItemField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { List, Group, Box } from '@mantine/core';
import React, { ReactNode } from 'react';
import { connectField } from 'uniforms';
import { List, Group, Box } from '@mantine/core';

import AutoField from './AutoField';
import ListDelField from './ListDelField';
Expand Down
8 changes: 5 additions & 3 deletions packages/uniforms-mantine/src/LongTextField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import { Textarea, TextareaProps } from '@mantine/core';
import React, { ChangeEvent, Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';

export type LongTextFieldProps = FieldProps<
string,
Expand All @@ -25,7 +25,9 @@ function LongText({
label={label}
disabled={disabled}
name={name}
onChange={event => (readOnly ? undefined : onChange(event.target.value))}
onChange={(event: ChangeEvent<HTMLTextAreaElement>) =>
readOnly ? undefined : onChange(event.target.value)
}
placeholder={placeholder}
ref={inputRef}
value={value ?? ''}
Expand Down
3 changes: 2 additions & 1 deletion packages/uniforms-mantine/src/NestField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Text } from '@mantine/core';
import React from 'react';
import { HTMLFieldProps, connectField, filterDOMProps } from 'uniforms';
import { Text } from '@mantine/core';

import AutoField from './AutoField';

export type NestFieldProps = HTMLFieldProps<
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/NumField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Input, NumberInput, NumberInputProps, Tooltip } from '@mantine/core';
import React, { ReactNode, Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import { Input, NumberInput, NumberInputProps, Tooltip } from '@mantine/core';

export type NumFieldProps = FieldProps<
number,
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-mantine/src/RadioField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Radio as RadioMantine, RadioProps, Text, Stack } from '@mantine/core';
import React from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import { Radio as MantineRadio, RadioProps, Text, Stack } from '@mantine/core';

import type { Option } from './types';

Expand All @@ -27,7 +27,7 @@ function Radio({
<Stack mb="xs">
{label && <Text>{label}</Text>}
{options?.map(option => (
<MantineRadio
<RadioMantine
key={option.key ?? option.value}
disabled={!!option?.disabled}
checked={option.value === value}
Expand Down
12 changes: 6 additions & 6 deletions packages/uniforms-mantine/src/SelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import {
Select as SelectMantine,
ComboboxItem,
SelectProps,
MultiSelect,
MultiSelectProps,
} from '@mantine/core';
import React, { Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';

export type SelectFieldProps = FieldProps<
string | string[],
Expand Down Expand Up @@ -47,15 +47,15 @@ function Select({
ref={inputRef}
label={label}
name={name}
onChange={item => {
onChange={(item?: string) => {
if (!readOnly) {
onChange(item);
}
}}
placeholder={placeholder}
required={required ?? false}
defaultValue={[]}
value={value as string[]}
value={value}
mb="xs"
/>
);
Expand All @@ -71,15 +71,15 @@ function Select({
ref={inputRef}
label={label}
name={name}
onChange={item => {
onChange={(item: string) => {
if (!readOnly) {
onChange(item ?? '');
}
}}
placeholder={placeholder}
required={required ?? false}
defaultValue={null}
value={value as string}
value={value}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-mantine/src/SubmitField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, ButtonProps } from '@mantine/core';
import React, { Ref } from 'react';
import { Override, filterDOMProps, useForm } from 'uniforms';
import { Button, ButtonProps } from '@mantine/core';

export type SubmitFieldProps = Override<
ButtonProps,
Expand Down
12 changes: 6 additions & 6 deletions packages/uniforms-mantine/src/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';
import { TextInput, TextInputProps } from '@mantine/core';
import React, { ChangeEvent, Ref } from 'react';
import { FieldProps, connectField, filterDOMProps } from 'uniforms';

export type TextFieldProps = FieldProps<
string,
Expand Down Expand Up @@ -35,11 +35,13 @@ function Text({
disabled={disabled}
id={id}
name={name}
onChange={event => onChange(event.target.value)}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
onChange(event.target.value)
}
placeholder={placeholder}
readOnly={readOnly}
ref={inputRef}
type={type ?? 'text'}
type={type}
value={value ?? ''}
w="100%"
{...filterDOMProps(props)}
Expand All @@ -48,6 +50,4 @@ function Text({
);
}

Text.defaultProps = { type: 'text' };

export default connectField<TextFieldProps>(Text, { kind: 'leaf' });
1 change: 0 additions & 1 deletion packages/uniforms-mui/src/NestField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import FormLabel from '@mui/material/FormLabel';
import React from 'react';
import { connectField, HTMLFieldProps } from 'uniforms';

import AutoField from './AutoField';
Expand Down

0 comments on commit e1f7429

Please sign in to comment.