Skip to content

Commit

Permalink
run prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewHoo committed Mar 13, 2024
1 parent b77a521 commit 096b30d
Show file tree
Hide file tree
Showing 41 changed files with 508 additions and 508 deletions.
22 changes: 12 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ module.exports = {
ignorePatterns: ["dist", ".eslintrc.cjs", "lib"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh", "testing-library"],
overrides: [ {
files: ["./src/**/*.test.tsx"],
extends: ["plugin:testing-library/react"],
rules: {
"testing-library/prefer-implicit-assert": "error",
"testing-library/prefer-presence-queries": "error",
"testing-library/prefer-user-event": "error"
}
}],
overrides: [
{
files: ["./src/**/*.test.tsx"],
extends: ["plugin:testing-library/react"],
rules: {
"testing-library/prefer-implicit-assert": "error",
"testing-library/prefer-presence-queries": "error",
"testing-library/prefer-user-event": "error",
},
},
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
Expand All @@ -38,4 +40,4 @@ module.exports = {
version: "detect",
},
},
};
}
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Release
on:
push:
Expand Down Expand Up @@ -39,4 +38,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
run: npx semantic-release
8 changes: 4 additions & 4 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { StorybookConfig } from "@storybook/react-vite";
import type { StorybookConfig } from "@storybook/react-vite"

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-onboarding",
],
framework: {
name: "@storybook/react-vite",
Expand All @@ -14,5 +14,5 @@ const config: StorybookConfig = {
docs: {
autodocs: "tag",
},
};
export default config;
}
export default config
6 changes: 3 additions & 3 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Preview } from "@storybook/react";
import type { Preview } from "@storybook/react"

const preview: Preview = {
parameters: {
Expand All @@ -10,6 +10,6 @@ const preview: Preview = {
},
},
},
};
}

export default preview;
export default preview
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.tabSize": 2,
}
"editor.tabSize": 2
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ $ npm install jsonforms-antd-renderers
```

```tsx
import { JsonForms } from "@jsonforms/react";
import { JsonForms } from "@jsonforms/react"
import {
rendererRegistryEntries,
cellRegistryEntries,
} from "jsonforms-antd-renderers";
} from "jsonforms-antd-renderers"

<JsonForms
;<JsonForms
schema={schema}
renderers={rendererRegistryEntries}
cells={cellRegistryEntries}
/>;
/>
```

## Contributing
Expand Down
14 changes: 7 additions & 7 deletions src/antd/Checkbox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect} from "vitest";
import { screen } from "@testing-library/react";
import { render } from "../common/test-render";
import { test, expect } from "vitest"
import { screen } from "@testing-library/react"
import { render } from "../common/test-render"

test("renders Checkbox component with default label", async () => {
render({
Expand All @@ -9,8 +9,8 @@ test("renders Checkbox component with default label", async () => {
properties: { name: { type: "boolean", title: "Name" } },
},
data: { name: true },
});
})

const checkbox = await screen.findByLabelText("Name");
expect(checkbox).toBeChecked();
});
const checkbox = await screen.findByLabelText("Name")
expect(checkbox).toBeChecked()
})
16 changes: 8 additions & 8 deletions src/antd/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CellProps, WithClassname, Helpers } from "@jsonforms/core";
import { Checkbox as AntDCheckbox } from "antd";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import { CellProps, WithClassname, Helpers } from "@jsonforms/core"
import { Checkbox as AntDCheckbox } from "antd"
import { CheckboxChangeEvent } from "antd/es/checkbox"

interface CheckboxProps extends CellProps, WithClassname {
label?: string;
label?: string
}

export function Checkbox({
Expand All @@ -17,10 +17,10 @@ export function Checkbox({
handleChange,
label,
}: CheckboxProps) {
const checked = !!data; // convert undefined to false
const checked = !!data // convert undefined to false

const labelDescription = Helpers.createLabelDescriptionFrom(uischema, schema);
const defaultLabel = labelDescription.show ? labelDescription.text : "";
const labelDescription = Helpers.createLabelDescriptionFrom(uischema, schema)
const defaultLabel = labelDescription.show ? labelDescription.text : ""

return (
<AntDCheckbox
Expand All @@ -34,5 +34,5 @@ export function Checkbox({
>
{label ?? defaultLabel}
</AntDCheckbox>
);
)
}
28 changes: 14 additions & 14 deletions src/common/AntDJsonForm.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { JsonForms } from "@jsonforms/react";
import { JsonForms } from "@jsonforms/react"
import {
JsonFormsRendererRegistryEntry,
JsonFormsUISchemaRegistryEntry,
JsonSchema7,
} from "@jsonforms/core";
import { UISchema } from "../ui-schema";
} from "@jsonforms/core"
import { UISchema } from "../ui-schema"
import {
rendererRegistryEntries as _rendererRegistryEntries,
cellRegistryEntries,
} from "../renderers";
} from "../renderers"

type Props = {
data: Record<string, unknown>;
updateData: (data: Record<string, unknown>) => void;
jsonSchema: JsonSchema7;
uiSchema?: UISchema;
uiSchemaRegistryEntries?: JsonFormsUISchemaRegistryEntry[];
customRendererRegistryEntries?: JsonFormsRendererRegistryEntry[];
rendererRegistryEntries?: JsonFormsRendererRegistryEntry[];
config?: Record<string, unknown>;
};
data: Record<string, unknown>
updateData: (data: Record<string, unknown>) => void
jsonSchema: JsonSchema7
uiSchema?: UISchema
uiSchemaRegistryEntries?: JsonFormsUISchemaRegistryEntry[]
customRendererRegistryEntries?: JsonFormsRendererRegistryEntry[]
rendererRegistryEntries?: JsonFormsRendererRegistryEntry[]
config?: Record<string, unknown>
}

export function AntDJsonForm({
uiSchema,
Expand All @@ -45,5 +45,5 @@ export function AntDJsonForm({
]}
config={config}
/>
);
)
}
30 changes: 15 additions & 15 deletions src/common/FormStateWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { JsonForms } from "@jsonforms/react";
import { JSONSchema } from "json-schema-to-ts";
import { Form } from "antd";
import { JsonForms } from "@jsonforms/react"
import { JSONSchema } from "json-schema-to-ts"
import { Form } from "antd"

import { JsonSchema7 } from "@jsonforms/core";
import { UISchema } from "../ui-schema";
import { cellRegistryEntries, rendererRegistryEntries } from "../renderers";
import { useState } from "react";
import { JsonSchema7 } from "@jsonforms/core"
import { UISchema } from "../ui-schema"
import { cellRegistryEntries, rendererRegistryEntries } from "../renderers"
import { useState } from "react"

type RenderProps<T extends Record<string, unknown>> = {
schema: JSONSchema;
data?: T;
uischema?: UISchema;
onChange?: (result: { data: T }) => void;
};
schema: JSONSchema
data?: T
uischema?: UISchema
onChange?: (result: { data: T }) => void
}

export function FormStateWrapper<T extends Record<string, unknown>>({
schema,
Expand All @@ -21,8 +21,8 @@ export function FormStateWrapper<T extends Record<string, unknown>>({
onChange,
}: RenderProps<T>) {
const [data, setData] = useState<Record<string, unknown> | undefined>(
initialData
);
initialData,
)
return (
<Form>
<JsonForms
Expand All @@ -39,5 +39,5 @@ export function FormStateWrapper<T extends Record<string, unknown>>({
})}
/>
</Form>
);
)
}
34 changes: 17 additions & 17 deletions src/common/StorybookAntDJsonForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import {
JsonFormsRendererRegistryEntry,
JsonFormsUISchemaRegistryEntry,
JsonSchema7,
} from "@jsonforms/core";
import { UISchema } from "../ui-schema";
import { AntDJsonForm } from "./AntDJsonForm";
import { useState } from "react";
} from "@jsonforms/core"
import { UISchema } from "../ui-schema"
import { AntDJsonForm } from "./AntDJsonForm"
import { useState } from "react"

type Props = {
data?: Record<string, unknown>;
jsonSchema: JsonSchema7;
rendererRegistryEntries: JsonFormsRendererRegistryEntry[];
uiSchema?: UISchema;
uiSchemaRegistryEntries?: JsonFormsUISchemaRegistryEntry[];
config?: Record<string, unknown>;
onChange: (data: Record<string, unknown>) => void;
};
data?: Record<string, unknown>
jsonSchema: JsonSchema7
rendererRegistryEntries: JsonFormsRendererRegistryEntry[]
uiSchema?: UISchema
uiSchemaRegistryEntries?: JsonFormsUISchemaRegistryEntry[]
config?: Record<string, unknown>
onChange: (data: Record<string, unknown>) => void
}

// this component exists to facilitate storybook rendering
export function StorybookAntDJsonForm({
Expand All @@ -25,12 +25,12 @@ export function StorybookAntDJsonForm({
uiSchemaRegistryEntries,
rendererRegistryEntries,
config,
onChange
onChange,
}: Props) {
const [data, setData] = useState(initialData);
const [data, setData] = useState(initialData)
const updateData = (newData: Record<string, unknown>) => {
setData(newData);
onChange(newData);
setData(newData)
onChange(newData)
}
return (
<AntDJsonForm
Expand All @@ -42,5 +42,5 @@ export function StorybookAntDJsonForm({
rendererRegistryEntries={rendererRegistryEntries}
config={config}
/>
);
)
}
6 changes: 3 additions & 3 deletions src/common/assert-never.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function assertNever(x: never): never {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Unexpected value '${x}'`)
}
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Unexpected value '${x}'`)
}
24 changes: 13 additions & 11 deletions src/common/test-render.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { render as RTLrender } from "@testing-library/react";
import { JSONSchema } from "json-schema-to-ts";
import { render as RTLrender } from "@testing-library/react"
import { JSONSchema } from "json-schema-to-ts"

import { UISchema } from "../ui-schema";
import { FormStateWrapper } from "./FormStateWrapper";
import { UISchema } from "../ui-schema"
import { FormStateWrapper } from "./FormStateWrapper"

type RenderProps<T extends Record<string, unknown>> = {
schema: JSONSchema;
data?: T;
uischema?: UISchema;
onChange?: (result: { data: T }) => void;
};
schema: JSONSchema
data?: T
uischema?: UISchema
onChange?: (result: { data: T }) => void
}

export function render<T extends Record<string, unknown>>(props: RenderProps<T>) {
return RTLrender(<FormStateWrapper {...props} />);
export function render<T extends Record<string, unknown>>(
props: RenderProps<T>,
) {
return RTLrender(<FormStateWrapper {...props} />)
}
Loading

0 comments on commit 096b30d

Please sign in to comment.