Skip to content

Commit

Permalink
Rename TypeScript types and export more of them
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Nov 6, 2022
1 parent e5fe910 commit 1d80509
Show file tree
Hide file tree
Showing 46 changed files with 290 additions and 192 deletions.
4 changes: 4 additions & 0 deletions packages/solid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the library will be documented in this file.

## vX.X.X (Month DD, YYYY)

- Rename TypeScript types and export more of them

## v0.5.0 (November 06, 2022)

- Reset form response at `handleSubmit` and `reset` method
Expand Down
15 changes: 1 addition & 14 deletions packages/solid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import type {
FormState as ModularForm,
FieldState as ModularField,
FieldValue as ModularValue,
FieldValues as ModularValues,
FieldArrayState as ModularFieldArray,
} from './types';
export type {
ModularForm,
ModularField,
ModularValue,
ModularValues,
ModularFieldArray,
};
export * from './components';
export * from './methods';
export * from './primitives';
export * from './types';
export * from './validation';
16 changes: 8 additions & 8 deletions packages/website/src/components/Debugger.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
getValues,
ModularValue,
ModularValues,
ModularForm,
FieldValue,
FieldValues,
FormState,
} from '@modular-forms/solid';
import clsx from 'clsx';
import { createMemo, For, Show } from 'solid-js';

type DebuggerProps = {
of: ModularForm<any> | undefined;
of: FormState<any> | undefined;
};

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ export function Debugger(props: DebuggerProps) {
when={Object.keys(values() || {}).length}
fallback={<p>Wait for input...</p>}
>
<FieldValues values={values()} />
<FieldValueList values={values()} />
</Show>
</div>
</div>
Expand All @@ -91,13 +91,13 @@ export function Debugger(props: DebuggerProps) {

type FieldValuesProps = {
class?: string;
values: ModularValue[] | ModularValues | ModularValues[];
values: FieldValue[] | FieldValues | FieldValues[];
};

/**
* Recusive component that displays individual form values.
*/
function FieldValues(props: FieldValuesProps) {
function FieldValueList(props: FieldValuesProps) {
return (
<ul class={clsx('space-y-5', props.class)}>
<For each={Object.entries(props.values)}>
Expand Down Expand Up @@ -136,7 +136,7 @@ function FieldValues(props: FieldValuesProps) {
: String(value)}
</span>
) : (
<FieldValues class="ml-2 mt-3" values={value} />
<FieldValueList class="ml-2 mt-3" values={value} />
)}
</li>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/components/FormFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ModularForm, reset } from '@modular-forms/solid';
import { FormState, reset } from '@modular-forms/solid';
import { ActionButton } from './ActionButton';

type FormFooterProps = {
of: ModularForm<any>;
of: FormState<any>;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/components/FormHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ModularForm, reset } from '@modular-forms/solid';
import { FormState, reset } from '@modular-forms/solid';
import { ActionButton } from './ActionButton';

type FormHeaderProps = {
of: ModularForm<any>;
of: FormState<any>;
heading: string;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/contexts/form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModularForm } from '@modular-forms/solid';
import { FormState } from '@modular-forms/solid';
import {
Accessor,
createContext,
Expand All @@ -8,7 +8,7 @@ import {
useContext,
} from 'solid-js';

type Form = ModularForm<any> | undefined;
type Form = FormState<any> | undefined;

// Create form context
const FormContext = createContext<{ get: Accessor<Form>; set: Setter<Form> }>();
Expand Down
14 changes: 9 additions & 5 deletions packages/website/src/routes/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ export default function ApiLayout() {
{
heading: 'Types',
items: [
'ModularField',
'ModularFieldArray',
'ModularForm',
'ModularValue',
'ModularValues',
'FieldArrayState',
'FieldElement',
'FieldState',
'FieldValue',
'FieldValues',
'FormState',
'Response',
'ValidateField',
'ValidateFieldArray',
],
},
]}
Expand Down
20 changes: 10 additions & 10 deletions packages/website/src/routes/api/Field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ export const properties = {
of: {
type: {
type: 'custom',
name: 'ModularForm',
href: '/api/ModularForm',
name: 'FormState',
href: '/api/FormState',
},
},
initialValue: {
type: [
{
type: 'custom',
name: 'ModularValue',
href: '/api/ModularValue',
name: 'FieldValue',
href: '/api/FieldValue',
},
'undefined',
],
Expand All @@ -71,8 +71,8 @@ export const properties = {
name: 'value',
type: {
type: 'custom',
name: 'ModularValue',
href: '/api/ModularValue',
name: 'FieldValue',
href: '/api/FieldValue',
},
},
],
Expand All @@ -94,8 +94,8 @@ export const properties = {
name: 'value',
type: {
type: 'custom',
name: 'ModularValue',
href: '/api/ModularValue',
name: 'FieldValue',
href: '/api/FieldValue',
},
},
],
Expand Down Expand Up @@ -128,8 +128,8 @@ export const properties = {
name: 'field',
type: {
type: 'custom',
name: 'ModularField',
href: '/api/ModularField',
name: 'FieldState',
href: '/api/FieldState',
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions packages/website/src/routes/api/FieldArray.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const properties = {
of: {
type: {
type: 'custom',
name: 'ModularForm',
href: '/api/ModularForm',
name: 'FormState',
href: '/api/FormState',
},
},
validate: {
Expand Down Expand Up @@ -105,8 +105,8 @@ export const properties = {
name: 'fieldArray',
type: {
type: 'custom',
name: 'ModularFieldArray',
href: '/api/ModularFieldArray',
name: 'FieldArrayState',
href: '/api/FieldArrayState',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Description, Property, Title } from '~/components';

<Title>ModularFieldArray</Title>
<Title>FieldArrayState</Title>
<Description>Type that defines the state of a form field array.</Description>

# ModularFieldArray
# FieldArrayState

Type that defines the state of a form field array.

## Definition

- `ModularFieldArray` <Property type="object" />
- `FieldArrayState` <Property type="object" />
- `name` <Property type="string" />
- `items` <Property type={{ type: 'array', item: 'number' }} />
- `length` <Property type="number" />
Expand Down
31 changes: 31 additions & 0 deletions packages/website/src/routes/api/FieldElement.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Description, Property, Title } from '~/components';

<Title>FieldElement</Title>
<Description>Type that defines the HTML element of a field.</Description>

# FieldElement

Type that defines the HTML element of a field.

## Definition

- `FieldElement` <Property {...properties.FieldElement} />

export const properties = {
FieldElement: {
type: [
{
type: 'custom',
name: 'HTMLInputElement',
},
{
type: 'custom',
name: 'HTMLSelectElement',
},
{
type: 'custom',
name: 'HTMLTextAreaElement',
},
],
},
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Description, Property, Title } from '~/components';

<Title>ModularField</Title>
<Title>FieldState</Title>
<Description>Type that defines the state of a form field.</Description>

# ModularField
# FieldState

Type that defines the state of a form field.

## Definition

- `ModularField` <Property type="object" />
- `FieldState` <Property type="object" />
- `props` <Property type="object" />
- `name` <Property type="string" />
- `ref` <Property {...properties.ref} />
Expand Down Expand Up @@ -40,11 +40,11 @@ export const properties = {
params: [
{
name: 'element',
type: [
{ type: 'custom', name: 'HTMLInputElement' },
{ type: 'custom', name: 'HTMLSelectElement' },
{ type: 'custom', name: 'HTMLTextAreaElement' },
],
type: {
type: 'custom',
name: 'FieldElement',
href: '/api/FieldElement',
},
},
],
return: 'void',
Expand Down Expand Up @@ -98,8 +98,8 @@ export const properties = {
value: {
type: {
type: 'custom',
name: 'ModularValue',
href: '/api/ModularValue',
name: 'FieldValue',
href: '/api/FieldValue',
},
},
};
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { A } from 'solid-start';
import { Description, Property, Title } from '~/components';

<Title>ModularValue</Title>
<Title>FieldValue</Title>
<Description>Type that defines the value of a field.</Description>

# ModularValue
# FieldValue

Type that defines the value of a field.

## Definition

- `ModularValue` <Property {...properties.ModularValue} />
- `FieldValue` <Property {...properties.FieldValue} />

> Make sure to use the correct input fields with the correct setting for the respective values. You can find instructions <A href="/guides/special-inputs">here</A>.
export const properties = {
ModularValue: {
FieldValue: {
type: [
'string',
'number',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { A } from 'solid-start';
import { Description, Property, Title } from '~/components';

<Title>ModularValues</Title>
<Title>FieldValues</Title>
<Description>Type that defines the field values of a form.</Description>

# ModularValues
# FieldValues

Type that defines the field values of a form.

## Definition

- `ModularValues` <Property {...properties.ModularValues} />
- `FieldValues` <Property {...properties.FieldValues} />

> When defining your field values, make sure that the individual values are compatible with the respective input element. You can learn more about this <A href="/guides/special-inputs">here</A>.
export const properties = {
ModularValues: {
FieldValues: {
type: {
type: 'object',
entries: [
{
key: { name: 'name', type: 'string' },
value: [
{ type: 'custom', name: 'ModularValue', href: '/api/ModularValue' },
{ type: 'custom', name: 'FieldValue', href: '/api/FieldValue' },
{
type: 'array',
item: {
type: 'custom',
name: 'ModularValue',
href: '/api/ModularValue',
name: 'FieldValue',
href: '/api/FieldValue',
},
},
{ type: 'custom', name: 'ModularValues' },
{ type: 'custom', name: 'FieldValues' },
{
type: 'array',
item: { type: 'custom', name: 'ModularValues' },
item: { type: 'custom', name: 'FieldValues' },
},
],
},
Expand Down
Loading

0 comments on commit 1d80509

Please sign in to comment.