Skip to content

Commit e3773e9

Browse files
authored
Merge pull request #748 from gadget-inc/feature/shadcn-auto-richtext
Feature/AutoRichTexts
2 parents 91ffa65 + 6199648 commit e3773e9

28 files changed

+631
-97
lines changed

packages/react/cypress/support/auto.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ONLY_RUN_SUITES = {
2424
"AutoForm - Default model field values",
2525
"AutoForm - FindBy object parameters",
2626
"AutoForm - Global actions",
27-
// "AutoForm - HasManyThrough fields",
27+
"AutoForm - HasManyThrough fields",
2828
"AutoForm - Dynamic form input changes",
2929
"AutoForm - Dynamic form input changes - FindBy object parameters",
3030
"AutoForm - Dynamic form input changes - Global actions",

packages/react/spec/auto/polaris/inputs/PolarisJsonInput.stories.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PolarisAutoForm } from "../../../../src/auto/polaris/PolarisAutoForm.ts
66
import { PolarisAutoJSONInput } from "../../../../src/auto/polaris/inputs/PolarisAutoJSONInput.tsx";
77
import { FormProvider, useForm } from "../../../../src/useActionForm.ts";
88
import { testApi as api } from "../../../apis.ts";
9+
910
const Component = (props) => {
1011
return (
1112
<PolarisAutoForm action={api.widget.create}>

packages/react/spec/auto/shadcn-defaults/components/Command.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ const CommandItem = React.forwardRef<
8989
/>
9090
));
9191

92+
const CommandLoading = React.forwardRef<
93+
React.ElementRef<typeof CommandPrimitive.Loading>,
94+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Loading>
95+
>((props, ref) => <CommandPrimitive.Loading ref={ref} className="py-6 text-center text-sm" {...props} />);
96+
97+
CommandLoading.displayName = CommandPrimitive.Loading.displayName;
98+
9299
CommandItem.displayName = CommandPrimitive.Item.displayName;
93100

94-
export { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator };
101+
export { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandLoading, CommandSeparator };

packages/react/spec/auto/shadcn-defaults/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ import { Button } from "./components/Button.js";
66
import { Calendar } from "./components/Calendar.js";
77
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./components/Card.js";
88
import { Checkbox } from "./components/Checkbox.js";
9-
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from "./components/Command.js";
9+
import {
10+
Command,
11+
CommandEmpty,
12+
CommandGroup,
13+
CommandInput,
14+
CommandItem,
15+
CommandList,
16+
CommandLoading,
17+
CommandSeparator,
18+
} from "./components/Command.js";
1019
import { Form } from "./components/Form.js";
1120
import { Input } from "./components/Input.js";
1221
import { Label } from "./components/Label.js";
@@ -47,7 +56,7 @@ export const elements: ShadcnElements = {
4756
CommandItem,
4857
CommandList,
4958
CommandSeparator,
50-
59+
CommandLoading,
5160
Popover,
5261
PopoverAnchor,
5362
PopoverContent,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from "react";
2+
import { Provider } from "../../../../src/GadgetProvider.tsx";
3+
import { FormProvider, useForm } from "../../../../src/useActionForm.ts";
4+
import { testApi as api } from "../../../apis.ts";
5+
import { makeAutocomponents } from "../../../../src/auto/shadcn/index.ts";
6+
import { elements } from "../index";
7+
import { makeShadcnAutoJSONInput } from "../../../../src/auto/shadcn/inputs/ShadcnAutoJSONInput.tsx";
8+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
9+
10+
const ShadcnAutoForm = makeAutocomponents(elements).AutoForm;
11+
const ShadcnAutoJSONInput = makeShadcnAutoJSONInput(elements);
12+
13+
const Component = (props) => {
14+
return (
15+
<ShadcnAutoForm action={api.widget.create}>
16+
<ShadcnAutoJSONInput {...props} />
17+
</ShadcnAutoForm>
18+
);
19+
};
20+
export default {
21+
title: "Shadcn/JsonInput",
22+
component: Component,
23+
decorators: [
24+
(Story, { parameters }) => {
25+
const { theme = "light" } = parameters;
26+
return (
27+
<Provider api={api}>
28+
<FormProvider {...useForm()}>
29+
<elements.Card className="p-6 w-full bg-white shadow-lg rounded-lg">
30+
<Story />
31+
</elements.Card>
32+
</FormProvider>
33+
</Provider>
34+
);
35+
},
36+
],
37+
38+
parameters: {
39+
layout: "centered",
40+
},
41+
tags: ["autodocs"],
42+
};
43+
44+
export const Primary = {
45+
args: {
46+
field: "metafields",
47+
},
48+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from "react";
2+
import { Provider } from "../../../../src/GadgetProvider.tsx";
3+
import { FormProvider, useForm } from "../../../../src/useActionForm.ts";
4+
import { testApi as api } from "../../../apis.ts";
5+
import { makeAutocomponents } from "../../../../src/auto/shadcn/index.ts";
6+
import { elements } from "../index";
7+
import { makeShadcnAutoFileInput } from "../../../../src/auto/shadcn/inputs/ShadcnAutoFileInput.tsx";
8+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
9+
10+
const ShadcnAutoForm = makeAutocomponents(elements).AutoForm;
11+
const ShadcnAutoFileInput = makeShadcnAutoFileInput(elements);
12+
13+
const Component = (props) => {
14+
return (
15+
<ShadcnAutoForm action={api.widget.create}>
16+
<ShadcnAutoFileInput {...props} />
17+
</ShadcnAutoForm>
18+
);
19+
};
20+
21+
export default {
22+
title: "Shadcn/FileInput",
23+
component: Component,
24+
decorators: [
25+
(Story, { parameters }) => {
26+
const { theme = "light" } = parameters;
27+
return (
28+
<Provider api={api}>
29+
<FormProvider {...useForm()}>
30+
<elements.Card className="p-6 w-full bg-white shadow-lg rounded-lg">
31+
<Story />
32+
</elements.Card>
33+
</FormProvider>
34+
</Provider>
35+
);
36+
},
37+
],
38+
39+
parameters: {
40+
layout: "centered",
41+
},
42+
tags: ["autodocs"],
43+
};
44+
45+
export const Primary = {
46+
args: {
47+
field: "metafields",
48+
},
49+
};

packages/react/src/auto/polaris/inputs/PolarisAutoRichTextInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from "react";
44
import { autoInput } from "../../AutoInput.js";
55
import { useStringInputController } from "../../hooks/useStringInputController.js";
66
import AutoRichTextInput from "../../shared/AutoRichTextInput.js";
7-
import "../styles/rich-text.css";
7+
import "../../shared/styles/rich-text.css";
88

99
/**
1010
* Prefer using the LazyLoadedMUIAutoRichTextInput.tsx variant of this component to reduce the bundle size by default.

packages/react/src/auto/shadcn/ShadcnAutoForm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
3030
CommandInput,
3131
CommandItem,
3232
CommandList,
33+
CommandLoading,
3334
CommandEmpty,
3435
CommandGroup,
3536
Calendar,
@@ -61,6 +62,7 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
6162
Checkbox,
6263
Badge,
6364
Command,
65+
CommandLoading,
6466
CommandInput,
6567
CommandItem,
6668
CommandList,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
export const ShadcnRequired = ({ children }: { children: React.ReactNode }) => {
4+
return <span className="text-red-500">{children}</span>;
5+
};

packages/react/src/auto/shadcn/elements.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export interface ShadcnElements {
139139
/** The Calendar component from shadcn */
140140
Calendar: React.ComponentType<any>;
141141

142+
/** The CommandLoading component from shadcn */
143+
CommandLoading: React.ComponentType<React.HTMLAttributes<HTMLDivElement>>;
144+
142145
/** The CardHeader component from shadcn */
143146
CardHeader: React.ComponentType<CardHeaderProps>;
144147
/** The CardFooter component from shadcn */

0 commit comments

Comments
 (0)