Skip to content

Commit

Permalink
chore(deps): update conform
Browse files Browse the repository at this point in the history
  • Loading branch information
balzdur committed Jul 19, 2024
1 parent 656ede6 commit 721c58f
Show file tree
Hide file tree
Showing 47 changed files with 2,900 additions and 2,383 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
},
"devDependencies": {
"@vitejs/plugin-react": "4.3.1",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/ui": "1.6.0",
"prettier": "^3.3.2",
"@vitest/coverage-v8": "^2.0.3",
"@vitest/ui": "2.0.3",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"react-refresh": "^0.14.2",
"typescript": "5.5.2",
"typescript": "5.5.3",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.6.0"
"vitest": "2.0.3"
}
}
9 changes: 4 additions & 5 deletions packages/app-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"postcss": "^8.4.38",
"tailwindcss": "3.4.4",
"tsx": "^4.15.7",
"vite": "^5.3.1"
"vite": "^5.3.4"
},
"dependencies": {
"@ariakit/react": "^0.4.7",
"@conform-to/dom": "^0.9.1",
"@conform-to/react": "^0.9.1",
"@conform-to/zod": "^0.9.1",
"@conform-to/dom": "^1.1.5",
"@conform-to/react": "^1.1.5",
"@conform-to/zod": "^1.1.5",
"@dagrejs/dagre": "^1.1.2",
"@hookform/devtools": "^4.3.1",
"@hookform/resolvers": "^3.6.0",
Expand Down Expand Up @@ -105,7 +105,6 @@
"typescript-utils": "workspace:*",
"ui-design-system": "workspace:*",
"ui-icons": "workspace:*",
"winston": "^3.11.0",
"zod": "^3.23.8",
"zustand": "^4.5.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { Icon } from 'ui-icons';

import { filtersI18n } from './filters-i18n';

type AddNewFilterButtonProps = Omit<ButtonProps, 'variant' | 'color' | 'ref'>;

export const AddNewFilterButton = forwardRef<
HTMLButtonElement,
Omit<ButtonProps, 'ref'>
AddNewFilterButtonProps
>(function AddNewFilterButton(props, ref) {
const { t } = useTranslation(filtersI18n);
return (
Expand Down
39 changes: 20 additions & 19 deletions packages/app-builder/src/components/Filters/FiltersButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ import { Icon } from 'ui-icons';

import { filtersI18n } from './filters-i18n';

export const FiltersButton = forwardRef<
HTMLButtonElement,
Omit<ButtonProps, 'ref'>
>(function FiltersButton({ className, ...props }, ref) {
const { t } = useTranslation(filtersI18n);
return (
<Button
className={clsx('flex flex-row gap-2', className)}
variant="secondary"
ref={ref}
{...props}
>
<Icon icon="filters" className="size-5" />
<span className="text-s font-semibold first-letter:capitalize">
{t('filters:filters')}
</span>
</Button>
);
});
type FiltersButtonProps = Omit<ButtonProps, 'variant' | 'color' | 'ref'>;

export const FiltersButton = forwardRef<HTMLButtonElement, FiltersButtonProps>(
function FiltersButton({ className, ...props }, ref) {
const { t } = useTranslation(filtersI18n);
return (
<Button
className={clsx('flex flex-row gap-2', className)}
variant="secondary"
ref={ref}
{...props}
>
<Icon icon="filters" className="size-5" />
<span className="text-s font-semibold first-letter:capitalize">
{t('filters:filters')}
</span>
</Button>
);
},
);
34 changes: 21 additions & 13 deletions packages/app-builder/src/components/Form/FormCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { unstable_useControl, useField } from '@conform-to/react';
import { Checkbox } from 'ui-design-system';

import { useFieldConfig } from './FormField';
import { useFieldName } from './FormField';

interface FormCheckboxProps
extends Omit<React.ComponentProps<typeof Checkbox>, 'checked'> {}

export function FormCheckbox({
children,
onCheckedChange,
...rest
}: Omit<React.ComponentProps<typeof Checkbox>, 'checked'>) {
const config = useFieldConfig();
}: FormCheckboxProps) {
const name = useFieldName();
const [meta] = useField<boolean>(name);

const control = unstable_useControl(meta);

return (
<Checkbox
id={config.id}
name={config.name}
defaultChecked={
typeof config.defaultValue === 'boolean'
? config.defaultValue
: config.defaultValue === 'on'
}
{...rest}
/>
// Radix UI don't expose the input element directly, so we need to query it
<div ref={(element) => control.register(element?.querySelector('input'))}>
<Checkbox
id={meta.id}
name={name}
checked={control.value === 'on'}
onCheckedChange={(state) => control.change(state.valueOf() ? 'on' : '')}
onBlur={control.blur}
{...rest}
/>
</div>
);
}
64 changes: 36 additions & 28 deletions packages/app-builder/src/components/Form/FormError.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import { useField } from '@conform-to/react';
import clsx from 'clsx';
import * as React from 'react';

import { useFieldConfig } from './FormField';

export const FormError = React.forwardRef<
HTMLParagraphElement,
Omit<React.HTMLAttributes<HTMLParagraphElement>, 'id'>
>(function FormError({ className, children, ...props }, ref) {
const { error, errorId } = useFieldConfig();

if (!error) {
return null;
}

const body = children ?? error;

return (
<p
ref={ref}
id={errorId}
className={clsx(
'text-s font-medium text-red-100 transition-opacity duration-200 ease-in-out',
className,
)}
{...props}
>
{body}
</p>
);
});
import { useFieldName } from './FormField';

interface FormErrorProps
extends Omit<React.HTMLAttributes<HTMLParagraphElement>, 'id'> {}

export const FormError = React.forwardRef<HTMLParagraphElement, FormErrorProps>(
function FormError({ className, children, ...props }, ref) {
const name = useFieldName();
const [meta] = useField(name);

const { errors, errorId } = meta;

const error = errors?.at(0);

if (!error) {
return null;
}

const body = children ?? error;

return (
<p
ref={ref}
id={errorId}
className={clsx(
'text-s font-medium text-red-100 transition-opacity duration-200 ease-in-out',
className,
)}
{...props}
>
{body}
</p>
);
},
);
15 changes: 7 additions & 8 deletions packages/app-builder/src/components/Form/FormField.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { createSimpleContext } from '@app-builder/utils/create-context';
import { type FieldConfig } from '@conform-to/react';
import { type FieldName } from '@conform-to/react';
import type * as React from 'react';

const FieldConfigContext =
createSimpleContext<FieldConfig<void>>('FieldConfig');
export const useFieldConfig = FieldConfigContext.useValue;
const FieldNameContext = createSimpleContext<string>('FieldName');
export const useFieldName = FieldNameContext.useValue;

export function FormField<Schema>({
config,
name,
...props
}: {
config: FieldConfig<Schema>;
name: FieldName<Schema>;
} & React.ComponentPropsWithoutRef<'div'>) {
return (
<FieldConfigContext.Provider value={config}>
<FieldNameContext.Provider value={name}>
<div {...props} />
</FieldConfigContext.Provider>
</FieldNameContext.Provider>
);
}
41 changes: 30 additions & 11 deletions packages/app-builder/src/components/Form/FormInput.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
import { conform } from '@conform-to/react';
import { getInputProps, useField } from '@conform-to/react';
import * as React from 'react';
import { Input, type InputProps } from 'ui-design-system';

import { useFieldConfig } from './FormField';
import { extractInputOptions, type InputOptions } from './helpers';
import { useFieldName } from './FormField';

interface FormInputProps extends Omit<InputProps, 'borderColor' | 'type'> {
type:
| 'color'
| 'date'
| 'datetime-local'
| 'email'
| 'file'
| 'hidden'
| 'month'
| 'number'
| 'password'
| 'range'
| 'search'
| 'tel'
| 'text'
| 'time'
| 'url'
| 'week';
}

export const FormInput = React.forwardRef<
React.ElementRef<typeof Input>,
InputOptions & Omit<InputProps, 'borderColor'>
>(function FormInput(props, ref) {
const config = useFieldConfig();

const { options, ...rest } = extractInputOptions(props);
FormInputProps
>(function FormInput({ type, ...inputProps }, ref) {
const name = useFieldName();
const [meta] = useField<string>(name);

return (
<Input
ref={ref}
borderColor={config.error ? 'red-100' : 'grey-10'}
{...rest}
{...conform.input(config, options)}
borderColor={meta.valid ? 'grey-10' : 'red-100'}
{...inputProps}
{...getInputProps(meta, { type })}
key={meta.key}
/>
);
});
19 changes: 13 additions & 6 deletions packages/app-builder/src/components/Form/FormLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { useField } from '@conform-to/react';
import * as LabelPrimitive from '@radix-ui/react-label';
import clsx from 'clsx';
import * as React from 'react';

import { useFieldConfig } from './FormField';
import { useFieldName } from './FormField';

interface FormLabelProps
extends Omit<
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>,
'htmlFor'
> {}

export const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
Omit<React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>, 'htmlFor'>
FormLabelProps
>(function FormLabel({ className, ...props }, ref) {
const { id, error } = useFieldConfig();

const name = useFieldName();
const [meta] = useField(name);
return (
<LabelPrimitive.Root
ref={ref}
htmlFor={id}
className={clsx(!!error && 'text-red-100', className)}
htmlFor={meta.id}
className={clsx(!meta.valid && 'text-red-100', className)}
{...props}
/>
);
Expand Down
Loading

0 comments on commit 721c58f

Please sign in to comment.