Skip to content

Commit 0f89f4c

Browse files
fix: export form context in a new file (#948)
1 parent 85356ca commit 0f89f4c

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

src/components/form/components/input/switch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styled from '@emotion/styled';
33
import type { ChangeEvent } from 'react';
44

55
import { useFieldContext } from '../../context/use_ts_form.js';
6-
import type { Layout } from '../input_groups/form.js';
6+
import type { Layout } from '../input_groups/form_context.js';
77
import { FormGroup } from '../input_groups/form_group.js';
88

99
interface SwitchProps {

src/components/form/components/input_groups/form.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import type { FormHTMLAttributes, ReactNode } from 'react';
2-
import { createContext, useContext, useMemo } from 'react';
2+
import { useMemo } from 'react';
33

4-
export type Layout = 'inline' | 'stacked';
4+
import type { Layout } from './form_context.js';
5+
import { formContext } from './form_context.js';
56

67
export interface FormProps extends FormHTMLAttributes<HTMLFormElement> {
78
children: ReactNode;
89
layout?: Layout;
910
}
1011

11-
const formContext = createContext<{ layout: Layout }>({
12-
layout: 'stacked',
13-
});
14-
15-
// eslint-disable-next-line react-refresh/only-export-components
16-
export function useFormContext() {
17-
return useContext(formContext);
18-
}
19-
2012
export function Form(props: FormProps) {
2113
const { children, layout = 'stacked', ...otherProps } = props;
2214

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createContext, useContext } from 'react';
2+
3+
export type Layout = 'inline' | 'stacked';
4+
5+
export const formContext = createContext<{ layout: Layout }>({
6+
layout: 'stacked',
7+
});
8+
9+
export function useFormContext() {
10+
return useContext(formContext);
11+
}

src/components/form/components/input_groups/form_group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Classes } from '@blueprintjs/core';
33
import styled from '@emotion/styled';
44
import type { ReactNode } from 'react';
55

6-
import type { Layout } from './form.js';
7-
import { useFormContext } from './form.js';
6+
import type { Layout } from './form_context.js';
7+
import { useFormContext } from './form_context.js';
88

99
const INPUT_HEIGHT = 30;
1010

stories/components/form/tanstack/input.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { FormEvent } from 'react';
44
import { action } from 'storybook/actions';
55
import { z } from 'zod';
66

7-
import type { Layout } from '../../../../src/components/form/components/input_groups/form.js';
7+
import type { Layout } from '../../../../src/components/form/components/input_groups/form_context.js';
88
import { Section } from '../../../../src/components/form/components/layout/Section.js';
99
import { useForm } from '../../../../src/components/index.js';
1010

stories/components/form/tanstack/new-general-settings.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { revalidateLogic } from '@tanstack/react-form';
44
import { action } from 'storybook/actions';
55
import { z } from 'zod';
66

7-
import type { Layout } from '../../../../src/components/form/components/input_groups/form.js';
87
import { Form } from '../../../../src/components/form/components/input_groups/form.js';
8+
import type { Layout } from '../../../../src/components/form/components/input_groups/form_context.js';
99
import { useForm } from '../../../../src/components/index.js';
1010

1111
export default {

0 commit comments

Comments
 (0)