Skip to content

Commit

Permalink
add ColumnLayoutProps to ControlUISchema (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiplet authored Sep 16, 2024
1 parent 6f852f8 commit ac66ef2
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"build:cjs": "tsc -p tsconfig.cjs.json",
"prepack": "pnpm run build",
"test": "vitest",
"test:cov": "vitest run --coverage --reporter=junit --outputFile=./junit.xml",
"test:cov": "VITE_CJS_IGNORE_WARNING=true vitest run --coverage --reporter=junit --outputFile=./junit.xml",
"tsc": "tsc",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format:write": "prettier . --write",
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/HorizontalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function HorizontalLayout({
return (
<Form component={form ? false : "form"} form={form}>
{!isEmpty(groupLayout.label) && groupLayout.label}
<Row justify="space-between" gutter={12}>
<Row justify="space-between" gutter={12} align="middle">
<AntDLayout
{...childProps}
direction="row"
Expand Down
11 changes: 10 additions & 1 deletion src/layouts/render-layout-elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "@jsonforms/core"
import { JsonFormsDispatch } from "@jsonforms/react"
import { Col } from "antd"
import { ColumnLayoutProps } from "../ui-schema"

export const renderLayoutElements = (
elements: UISchemaElement[],
Expand All @@ -17,9 +18,17 @@ export const renderLayoutElements = (
direction?: "row" | "column",
) => {
return elements.map((child, index) => {
const cols = {
xs: 24,
sm: 12,
}
if ("layoutProps" in child) {
cols.sm = (child.layoutProps as ColumnLayoutProps).columns ?? 12
}

if (direction === "row") {
return (
<Col key={`${path}-${index}`} xs={24} sm={12}>
<Col key={`${path}-${index}`} xs={cols.xs} sm={cols.sm}>
<JsonFormsDispatch
key={`${path}-${index}`}
uischema={child}
Expand Down
31 changes: 30 additions & 1 deletion src/testSchemas/anyOfSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const splitterUISchema: UISchema<
type: "Control",
scope: "#/properties/column_name",
label: "Column of datetime type",
layoutProps: {
columns: undefined,
},
},
{
type: "Control",
Expand All @@ -23,6 +26,9 @@ const splitterUISchema: UISchema<
effect: RuleEffect.HIDE,
condition: {},
},
layoutProps: {
columns: undefined,
},
},
],
}
Expand Down Expand Up @@ -163,7 +169,15 @@ export const AnyOfWithDefaultsSchema = {

export const AnyOfWithDefaultsBaseUISchema = {
type: "VerticalLayout",
elements: [{ type: "Control", scope: "#/properties/contactMethod" }],
elements: [
{
type: "Control",
scope: "#/properties/contactMethod",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof AnyOfWithDefaultsSchema>

export const AnyOfTooltipUISchema = {
Expand All @@ -173,6 +187,9 @@ export const AnyOfTooltipUISchema = {
type: "Control",
scope: "#/properties/contactMethod",
formItemProps: { tooltip: "Choose wisely" },
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof AnyOfWithDefaultsSchema>
Expand All @@ -184,6 +201,9 @@ const AnyOfWithDefaultsUISchema1 = {
type: "Control",
scope: "#/properties/pattern",
label: "Pattern",
layoutProps: {
columns: undefined,
},
},
{
type: "Control",
Expand All @@ -192,6 +212,9 @@ const AnyOfWithDefaultsUISchema1 = {
effect: RuleEffect.HIDE,
condition: {},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<
Expand All @@ -204,6 +227,9 @@ const AnyOfWithDefaultsUISchema2 = {
type: "Control",
scope: "#/properties/phoneNumber",
label: "Phone Number",
layoutProps: {
columns: undefined,
},
},
{
type: "Control",
Expand All @@ -212,6 +238,9 @@ const AnyOfWithDefaultsUISchema2 = {
effect: RuleEffect.HIDE,
condition: {},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<
Expand Down
21 changes: 21 additions & 0 deletions src/testSchemas/arraySchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const arrayControlUISchema = {
{
type: "Control",
scope: "#/properties/assets",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand All @@ -30,6 +33,9 @@ export const arrayControlSortableUISchema = {
options: {
showSortButtons: true,
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand All @@ -51,6 +57,9 @@ export const arrayControlSortableWithIconsUISchema = {
onClick: () => {}, // Testing to verify this isn't called because the user should be unable to override the onClick event
},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand All @@ -64,6 +73,9 @@ export const arrayControlTooltipUISchema = {
formItemProps: {
tooltip: "Items of value",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand All @@ -87,6 +99,9 @@ export const arrayControlUISchemaWithIcons = {
onClick: () => {}, // User should be unable to override the onClick event
},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand Down Expand Up @@ -260,6 +275,9 @@ const objectArrayWithCombinatorUISchema = {
scope: "#/properties/brownCopperKettle",
label: "Brown Copper Kettle",
type: "Control",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<
Expand Down Expand Up @@ -294,5 +312,8 @@ export const objectArrayWithCombinator_CombinatorUISchemaRegistryEntry: JsonForm
FavoriteThing2: "Favorite Thing 2",
},
},
layoutProps: {
columns: undefined,
},
} satisfies ControlUISchema<{ oneOf: [] }> as UISchemaElement,
}
12 changes: 12 additions & 0 deletions src/testSchemas/enumSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const enumSizeUISchema = {
type: "Control",
scope: "#/properties/size",
options: { optionType: "segmented" },
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof enumSizeSchema>
Expand All @@ -71,6 +74,9 @@ export const enumProfessionUISchema = {
type: "Control",
scope: "#/properties/profession",
options: { optionType: "dropdown" },
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof enumProfessionSchema>
Expand All @@ -82,6 +88,9 @@ export const enumPSIUISchema = {
type: "Control",
scope: "#/properties/psi",
options: { optionType: "radio" },
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof enumPSISchema>
Expand All @@ -100,6 +109,9 @@ export const enumSnakeCaseUISchema = {
option_3: "Option 3",
},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof enumSnakeCaseSchema>
3 changes: 3 additions & 0 deletions src/testSchemas/numericSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export const numericHorizontalUISchema = {
{
type: "Control",
scope: "#/properties/numericValue",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericROISchema>
Expand Down
21 changes: 21 additions & 0 deletions src/testSchemas/numericSliderSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export const numericSliderVerticalUISchema = {
{
type: "Control",
scope: "#/properties/numericRangeValue",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
Expand All @@ -125,6 +128,9 @@ export const numericSliderTooltipUISchema = {
formItemProps: {
tooltip: "°Kelvin = °Celsius + 273.15 or °Fahrenheit + 459.67",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderTemperatureSchema>
Expand All @@ -135,6 +141,9 @@ export const numericSliderHorizontalUISchema = {
{
type: "Control",
scope: "#/properties/numericRangeValue",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
Expand All @@ -148,6 +157,9 @@ export const numericSliderUSDUISchema = {
options: {
addonBefore: "$",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
Expand All @@ -161,6 +173,9 @@ export const numericSliderPercentageUISchema = {
options: {
addonAfter: "%",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
Expand All @@ -174,6 +189,9 @@ export const numericSliderTemperatureUISchema = {
options: {
addonAfter: "°F",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
Expand All @@ -188,6 +206,9 @@ export const numericSliderUISchemaWithRule = {
effect: RuleEffect.HIDE,
condition: {},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof numericSliderDonateNowSchema>
6 changes: 6 additions & 0 deletions src/testSchemas/objectArraySchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const objectArrayControlUISchema = {
{
scope: "#/properties/assets",
type: "Control",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchema>
Expand Down Expand Up @@ -70,6 +73,9 @@ export const objectArrayControlUISchemaWithIcons = {
onClick: () => {}, // User should be unable to override the onClick event
},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectArrayControlJsonSchemaWithRequired>
18 changes: 18 additions & 0 deletions src/testSchemas/objectSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const objectUISchemaWithName = {
{
type: "Control",
scope: "#/properties/name",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectSchema>
Expand All @@ -37,6 +40,9 @@ export const objectUISchemaWithTooltip = {
formItemProps: {
tooltip: "It's what you call yourself",
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectSchema>
Expand All @@ -47,10 +53,16 @@ export const objectUISchemaWithNameAndLastName = {
{
type: "Control",
scope: "#/properties/name",
layoutProps: {
columns: undefined,
},
},
{
type: "Control",
scope: "#/properties/lastName",
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectSchema>
Expand All @@ -61,6 +73,9 @@ export const objectUISchemaWithRule = {
{
type: "Control",
scope: "#/properties/name",
layoutProps: {
columns: undefined,
},
},
{
type: "Control",
Expand All @@ -72,6 +87,9 @@ export const objectUISchemaWithRule = {
schema: { const: "John" },
},
},
layoutProps: {
columns: undefined,
},
},
],
} satisfies UISchema<typeof objectSchema>
Loading

0 comments on commit ac66ef2

Please sign in to comment.