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

Add mantine theme #1287

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
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
3 changes: 2 additions & 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 Expand Up @@ -34,6 +34,7 @@ function List({
return (
<Input.Wrapper
mb="xs"
w="100%"
label={
tooltip ? (
<>
Expand Down
14 changes: 9 additions & 5 deletions packages/uniforms-mantine/src/ListItemField.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
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';

export type ListItemFieldProps = { children?: ReactNode; value?: unknown };

function ListItem({
children = <AutoField label={null} name="" />,
children = <AutoField label={null} name="" style={{ width: '100%' }} />,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test it with custom children? We don't want to pass width manually to every child component.

}: ListItemFieldProps) {
return (
<List.Item mb={12}>
<Group mt="xs" align="center">
<List.Item
mb={12}
styles={{ itemLabel: { width: '100%' }, itemWrapper: { width: '100%' } }}
pos="relative"
>
<Group mt="xs" align="flex-start" w="100%">
{children}
<Box mt={20}>
<Box pos="absolute" right={0} top={10}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can those styles be moved to the ListDelField component? We can avoid additional nesting with Box.

<ListDelField name="" />
</Box>
</Group>
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
5 changes: 3 additions & 2 deletions packages/uniforms-mantine/src/NestField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Label } from '@mantine/core';
import React from 'react';
piotrpospiech marked this conversation as resolved.
Show resolved Hide resolved
import { HTMLFieldProps, connectField, filterDOMProps } from 'uniforms';
import { Text } from '@mantine/core';

import AutoField from './AutoField';

export type NestFieldProps = HTMLFieldProps<
Expand All @@ -18,7 +19,7 @@ function Nest({
}: NestFieldProps) {
return (
<div {...filterDOMProps(props)}>
{label && <Text>{label}</Text>}
{label && <Label>{label}</Label>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it should be updated also in other fields e.g. RadioField.

{children ||
fields.map(field => (
<AutoField key={field} name={field} {...itemProps} />
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
3 changes: 1 addition & 2 deletions 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 All @@ -18,7 +18,6 @@ export default function SubmitField({

return (
<Button
mb="xs"
disabled={
disabled === undefined
? !!(error || state.disabled || submitting)
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)}
piotrpospiech marked this conversation as resolved.
Show resolved Hide resolved
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
Loading