diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.yml index 13c3c3e93..414c29b9f 100644 --- a/.github/workflows/chromatic.yml +++ b/.github/workflows/chromatic.yml @@ -43,10 +43,6 @@ jobs: - name: Install dependencies run: yarn - # 👇 Builds the kaoto-next/uniforms-patternfly - - name: Build @kaoto-next/uniforms-patternfly library - run: yarn workspace @kaoto-next/uniforms-patternfly run build - # 👇 Builds the kaoto-next/ui in library mode - name: Build ui library run: yarn workspace @kaoto-next/ui run build:lib diff --git a/.yarnrc.yml b/.yarnrc.yml index a407b9660..225de6ea8 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -13,10 +13,6 @@ packageExtensions: dependencies: "react": "^18.2.0" - "uniforms-bridge-simple-schema-2@*": - dependencies: - "react": "^18.2.0" - "storybook-fixtures@*": peerDependencies: "react-dom": "^18.2.0" diff --git a/packages/ui/package.json b/packages/ui/package.json index 0bfc0015f..202dec361 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -34,7 +34,7 @@ "lint:fix": "yarn eslint \"src/**/*.{ts,tsx}\" --fix" }, "dependencies": { - "@kaoto-next/uniforms-patternfly": "workspace:*", + "@kaoto-next/uniforms-patternfly": "^0.3.2", "@patternfly/patternfly": "^5.0.0", "@patternfly/react-code-editor": "^5.0.0", "@patternfly/react-core": "^5.0.0", diff --git a/packages/uniforms-patternfly/README.md b/packages/uniforms-patternfly/README.md deleted file mode 100644 index 3d4f5ad44..000000000 --- a/packages/uniforms-patternfly/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# Basic usage - -`uniforms` is a plugin for React to be able to create dynamic forms with built-in state management and form validation. -`uniforms` provides you with simple re-usable form components which allows for rapid prototyping and cleaner React components. - -This package extends uniforms to provide [Patternfly React](https://www.patternfly.org/v4/) components inside your forms. -For more information about `uniforms` please go to https://uniforms.tools/ - -Looking for building mobile enabled forms? Check [Uniforms-ionic](https://github.com/aerogear/uniforms-ionic) package that provides Ionic extensions - -### 1. Install the required packages - -To start using uniforms, we have to install three independent packages: - -1. Core -2. Bridge -3. Theme - -In this example, we will use the JSON Schema to describe our desired data format and style our form using the Pattenfly UI theme. - -```shell -npm install uniforms@^3.10.2 -npm install uniforms-bridge-json-schema@^3.10.2 -npm install @kie-tools/uniforms-patternfly -npm install @patternfly/react-core @patternfly/react-icons -``` - -Don't forget that it's necessary to correctly load the styles from Patternfly. To do it, we recommend taking a look into the -[Patternfly React Seed](https://github.com/patternfly/patternfly-react-seed), or you can simply load the styles directly into -your `index.html` like in the example app of this repo. - -Obs: If you use a previous version of the `tslib` indirectly (version 1), it should be necessary to add this dependency as well. - -```shell -npm install tslib@^2.3.1 -``` - -### 2. Start by defining a schema - -After we've installed required packages, it's time to define our schema. We can do it in a plain JSON, which is a valid JSON Schema instance: - -```js -const schema = { - type: "object", - properties: { - foo: { - type: "string", - }, - }, -}; -``` - -### 3. Then create the bridge - -Now that we have the schema, we can create the uniforms bridge of it, by using the corresponding uniforms bridge package. -Creating the bridge instance is necessary - without it, uniforms would not be able to process form generation and validation. -As we are using the JSON Schema, we have to import the `uniforms-bridge-json-schema` package. Also, because we're doing an -example of a JSON Schema, it's necessary to use a JSON Schema validation library, and in this example we'll be using the AJV. - -```js -import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; -import AJV from "ajv"; - -const ajv = new Ajv({ allErrors: true, useDefaults: true }); - -function createValidator(schema) { - const validator = ajv.compile(schema); - - return (model) => { - validator(model); - return validator.errors?.length ? { details: validator.errors } : null; - }; -} - -const bridge = new JSONSchemaBridge(schema, createValidator(schema)); -``` - -### 4. Finally, use it in a form! 🎉 - -Uniforms theme packages provide the `AutoForm` component, which is able to generate the form based on the given schema. -All we have to do now is to pass the previously created Bridge to the `AutoForm`: - -```js -import * as React from "react"; -import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm"; - -import schema from "./schema"; - -export default function MyForm() { - return ; -} -``` - -And that's it! `AutoForm` will generate a complete form with labeled fields, errors list (if any) and a submit button. - -Also, it will take care of validation and handle model changes. In case you need more advanced feature, take a deeper look -into the Uniforms docs. diff --git a/packages/uniforms-patternfly/__mocks__/styleMock.js b/packages/uniforms-patternfly/__mocks__/styleMock.js deleted file mode 100644 index f053ebf79..000000000 --- a/packages/uniforms-patternfly/__mocks__/styleMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; diff --git a/packages/uniforms-patternfly/jest.config.js b/packages/uniforms-patternfly/jest.config.js deleted file mode 100644 index 8a6ed0193..000000000 --- a/packages/uniforms-patternfly/jest.config.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** @type {import('jest').Config} */ -module.exports = { - testEnvironment: "jsdom", - reporters: ["default"], - setupFilesAfterEnv: ["./src/__tests__/jest.setup.ts"], - moduleDirectories: ["node_modules"], - testRegex: "src/__tests__/.*\\.test\\.(jsx?|tsx?)$", - transform: { - "^.+\\.jsx?$": ["babel-jest", { presets: [["@babel/env", { targets: { node: "current" } }], "@babel/react"] }], - "^.+\\.tsx?$": ["ts-jest", { tsconfig: "/tsconfig.esm.json" }], - }, - moduleNameMapper: { - "\\.(css|less|sass|scss)$": "/__mocks__/styleMock.js", - }, -}; diff --git a/packages/uniforms-patternfly/package.json b/packages/uniforms-patternfly/package.json deleted file mode 100644 index 31b5802a2..000000000 --- a/packages/uniforms-patternfly/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@kaoto-next/uniforms-patternfly", - "version": "0.0.0", - "description": "Patternfly forms for uniforms", - "license": "Apache-2.0", - "author": { - "name": "Gianluca", - "email": "gzuccare@redhat.com" - }, - "keywords": [], - "homepage": "https://github.com/KaotoIO/kaoto-next/tree/main/packages/uniforms-patternfly", - "repository": { - "type": "git", - "url": "https://github.com/KaotoIO/kaoto-next.git" - }, - "bugs": { - "url": "https://github.com/KaotoIO/kaoto-next/issues" - }, - "types": "./dist/esm/index.d.ts", - "main": "src/index.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "rimraf dist && tsc --build tsconfig.cjs.json && tsc --build tsconfig.esm.json", - "test": "jest" - }, - "dependencies": { - "@types/invariant": "^2.2.35", - "invariant": "^2.2.4", - "lodash": "^4.17.21", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "uniforms": "4.0.0-alpha.5" - }, - "devDependencies": { - "@babel/core": "^7.21.8", - "@babel/preset-env": "^7.21.5", - "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.21.5", - "@patternfly/react-core": "^5.0.0", - "@patternfly/react-icons": "^5.0.0", - "@testing-library/dom": "^9.3.0", - "@testing-library/jest-dom": "^6.0.0", - "@testing-library/react": "^14.0.0", - "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.4.0", - "@types/lodash": "^4.14.168", - "@types/node": "^18.0.0", - "@types/react": "^18.0.0", - "@types/react-dom": "^18.0.0", - "@types/simpl-schema": "^1.12.0", - "@types/testing-library__jest-dom": "^5.9.1", - "@types/testing-library__react": "^10.0.0", - "babel-jest": "^29.4.2", - "copy-webpack-plugin": "^11.0.0", - "jest": "^29.4.2", - "jest-environment-jsdom": "^29.4.2", - "rimraf": "^5.0.0", - "simpl-schema": "^3.4.1", - "ts-jest": "^29.1.1", - "ts-node": "^10.9.1", - "typescript": "^5.0.2", - "uniforms-bridge-simple-schema-2": "4.0.0-alpha.5", - "webpack": "^5.88.2", - "webpack-cli": "^5.0.0", - "webpack-dev-server": "^4.15.1", - "webpack-merge": "^5.9.0" - } -} diff --git a/packages/uniforms-patternfly/src/AutoField.tsx b/packages/uniforms-patternfly/src/AutoField.tsx deleted file mode 100644 index 45dfc61ad..000000000 --- a/packages/uniforms-patternfly/src/AutoField.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { createAutoField } from "uniforms"; -import invariant from "invariant"; -import BoolField from "./BoolField"; -import DateField from "./DateField"; -import ListField from "./ListField"; -import NestField from "./NestField"; -import NumField from "./NumField"; -import RadioField from "./RadioField"; -import SelectField from "./SelectField"; -import TextField from "./TextField"; - -export type AutoFieldProps = Parameters[0]; - -const AutoField = createAutoField((props) => { - if (props.options) { - return props.checkboxes && props.fieldType !== Array ? RadioField : SelectField; - } - - switch (props.fieldType) { - case Array: - return ListField; - case Boolean: - return BoolField; - case Date: - return DateField; - case Number: - return NumField; - case Object: - return NestField; - case String: - return TextField; - } - - return invariant(false, "Unsupported field type: %s", props.fieldType); -}); - -export default AutoField; diff --git a/packages/uniforms-patternfly/src/AutoFields.tsx b/packages/uniforms-patternfly/src/AutoFields.tsx deleted file mode 100644 index 7599f1d40..000000000 --- a/packages/uniforms-patternfly/src/AutoFields.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { ComponentType, createElement } from "react"; -import { useForm } from "uniforms"; -import AutoField from "./AutoField"; - -export type AutoFieldsProps = { - autoField?: ComponentType<{ name: string }>; - element?: ComponentType | string; - fields?: string[]; - omitFields?: string[]; -}; - -function AutoFields({ autoField = AutoField, element = "div", fields, omitFields = [], ...props }: AutoFieldsProps) { - const { schema } = useForm(); - - return createElement( - element!, - props, - (fields ?? schema.getSubfields()) - .filter((field) => !omitFields!.includes(field)) - .map((field) => createElement(autoField!, { key: field, name: field })) - ); -} - -export default AutoFields; diff --git a/packages/uniforms-patternfly/src/AutoForm.tsx b/packages/uniforms-patternfly/src/AutoForm.tsx deleted file mode 100644 index 665035f81..000000000 --- a/packages/uniforms-patternfly/src/AutoForm.tsx +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { AutoForm } from "uniforms"; -import ValidatedQuickForm from "./ValidatedQuickForm"; - -function Auto(parent: any): any { - class _ extends AutoForm.Auto(parent) { - static Auto = Auto; - } - - return _; -} - -export default Auto(ValidatedQuickForm); diff --git a/packages/uniforms-patternfly/src/BaseForm.tsx b/packages/uniforms-patternfly/src/BaseForm.tsx deleted file mode 100644 index 0cf6271a1..000000000 --- a/packages/uniforms-patternfly/src/BaseForm.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { Form } from "@patternfly/react-core/dist/js/components/Form"; -import { BaseForm, context } from "uniforms"; - -function Patternfly(parent: any): any { - class _ extends parent { - static Patternfly = Patternfly; - - static displayName = `Patternfly${parent.displayName}`; - - render() { - return ( - -
- - ); - } - } - - return _; -} - -export default Patternfly(BaseForm); diff --git a/packages/uniforms-patternfly/src/BoolField.tsx b/packages/uniforms-patternfly/src/BoolField.tsx deleted file mode 100644 index c821f31f7..000000000 --- a/packages/uniforms-patternfly/src/BoolField.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from 'react'; -import { Checkbox, CheckboxProps } from '@patternfly/react-core/dist/js/components/Checkbox'; -import { Switch, SwitchProps } from '@patternfly/react-core/dist/js/components/Switch'; -import { connectField, FieldProps } from 'uniforms'; -import wrapField from './wrapField'; -import { FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core/dist/js'; -import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/js/icons/exclamation-circle-icon'; - -enum ComponentType { - checkbox = 'checkbox', - switch = 'switch', -} - -export type BoolFieldProps = FieldProps< - boolean, - CheckboxProps & SwitchProps, - { - appearance?: ComponentType; - inputRef?: React.RefObject & React.RefObject; - } ->; - -function BoolField({ appearance, disabled, id, inputRef, label, name, onChange, value, ...props }: BoolFieldProps) { - const Component = appearance === ComponentType.switch ? Switch : Checkbox; - return wrapField( - { id, ...props }, - <> - {' '} - disabled || onChange(!value)} - ref={inputRef} - label={label} - /> - - - } variant={props.error ? 'error' : 'default'}> - {!props.error ? '' : props.errorMessage} - - - - , - ); -} - -BoolField.defaultProps = { appearance: ComponentType.checkbox }; - -export default connectField(BoolField); diff --git a/packages/uniforms-patternfly/src/DateField.tsx b/packages/uniforms-patternfly/src/DateField.tsx deleted file mode 100644 index b93494e2a..000000000 --- a/packages/uniforms-patternfly/src/DateField.tsx +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { useMemo } from "react"; -import { connectField, FieldProps } from "uniforms"; -import { TextInput, TextInputProps } from "@patternfly/react-core/dist/js/components/TextInput"; -import wrapField from "./wrapField"; - -export type DateFieldProps = FieldProps< - Date, - TextInputProps, - { - inputRef?: React.RefObject; - labelProps?: object; - max?: Date; - min?: Date; - type?: "date" | "datetime-local"; - } ->; - -type DateFieldType = "date" | "datetime-local"; - -const DateConstructor = (typeof global === "object" ? global : window).Date; - -const dateFormat = (value?: Date | string, type: DateFieldType = "datetime-local") => { - if (typeof value === "string") { - return value?.slice(0, type === "datetime-local" ? -8 : -14); - } - return value?.toISOString().slice(0, type === "datetime-local" ? -8 : -14); -}; - -const dateParse = (value: string, onChange: DateFieldProps["onChange"]) => { - const valueAsNumber = DateConstructor.parse(value); - if (isNaN(valueAsNumber)) { - // Checking if year is too big - const splitedValue = value.split("-"); - if (splitedValue.length > 1) { - // A year can't be bigger than 9999; - splitedValue[0] = parseInt(splitedValue[0]) > 9999 ? "9999" : splitedValue[0]; - onChange(new DateConstructor(`${splitedValue.join("-")}Z`)); - return; - } - onChange(undefined); - } else { - const date = new DateConstructor(`${value}Z`); - if (date.getFullYear() < 10000) { - onChange(date); - } else { - onChange(date); - } - } -}; - -function DateField({ onChange, ...props }: DateFieldProps) { - const isInvalid = useMemo(() => { - if (!props.value) { - return false; - } - - if (props.min) { - const minDate = new Date(props.min); - if (minDate.toString() === "Invalid Date") { - return false; - } else if (props.value < minDate) { - return `Should be after ${minDate.toISOString()}`; - } - } - if (props.max) { - const maxDate = new Date(props.max); - if (maxDate.toString() === "Invalid Date") { - return false; - } else if (props.value > maxDate) { - return `Should be before ${maxDate.toISOString()}`; - } - } - - return false; - }, [props.value, props.min, props.max]); - - return wrapField( - props as any, - <> - { - props.disabled || dateParse(value, onChange); - }} - value={dateFormat(props.value, props.type) ?? ""} - /> - {isInvalid && ( -
- {isInvalid} -
- )} - - ); -} - -export default connectField(DateField); diff --git a/packages/uniforms-patternfly/src/ErrorField.tsx b/packages/uniforms-patternfly/src/ErrorField.tsx deleted file mode 100644 index 26ffaacc1..000000000 --- a/packages/uniforms-patternfly/src/ErrorField.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { HTMLProps } from "react"; -import { connectField, filterDOMProps, Override } from "uniforms"; - -export type ErrorFieldProps = Override< - HTMLProps, - { - error?: boolean; - errorMessage?: string; - } ->; - -function ErrorField({ children, error, errorMessage, ...props }: ErrorFieldProps) { - return !error ? null : ( -
- {children ? children :
{errorMessage}
} -
- ); -} - -ErrorField.defaultProps = { - style: { - backgroundColor: "rgba(255, 85, 0, 0.2)", - border: "1px solid rgb(255, 85, 0)", - borderRadius: "7px", - margin: "20px 0px", - padding: "10px", - }, -}; - -export default connectField(ErrorField, { initialValue: false }); diff --git a/packages/uniforms-patternfly/src/ErrorsField.tsx b/packages/uniforms-patternfly/src/ErrorsField.tsx deleted file mode 100644 index d28151897..000000000 --- a/packages/uniforms-patternfly/src/ErrorsField.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { HTMLProps } from "react"; -import { useForm, filterDOMProps } from "uniforms"; - -export type ErrorsFieldProps = HTMLProps; - -function ErrorsField({ children, ...props }: ErrorsFieldProps) { - const { error, schema } = useForm(); - - return !error && !children ? null : ( -
- {children} -
    - {schema.getErrorMessages(error).map((message, index) => ( -
  • - {message} -
  • - ))} -
-
- ); -} - -ErrorsField.defaultProps = { - style: { - backgroundColor: "rgba(255, 85, 0, 0.2)", - border: "1px solid rgb(255, 85, 0)", - borderRadius: "7px", - margin: "20px 0px", - padding: "10px", - }, -}; - -export default ErrorsField; diff --git a/packages/uniforms-patternfly/src/HiddenField.tsx b/packages/uniforms-patternfly/src/HiddenField.tsx deleted file mode 100644 index e174cfd4b..000000000 --- a/packages/uniforms-patternfly/src/HiddenField.tsx +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { HTMLProps, Ref, useEffect } from "react"; -import { useField, filterDOMProps } from "uniforms"; - -export type HiddenFieldProps = { - inputRef?: Ref; - name: string; - noDOM?: boolean; - value?: any; -} & HTMLProps; - -export default function HiddenField({ value, ...rawProps }: HiddenFieldProps) { - const props = useField(rawProps.name, rawProps, { initialValue: false })[0]; - - useEffect(() => { - if (value !== undefined && value !== props.value) props.onChange(value); - }); - - return props.noDOM ? null : ( - - ); -} diff --git a/packages/uniforms-patternfly/src/ListAddField.tsx b/packages/uniforms-patternfly/src/ListAddField.tsx deleted file mode 100644 index 5c9ad2973..000000000 --- a/packages/uniforms-patternfly/src/ListAddField.tsx +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import cloneDeep from "lodash/cloneDeep"; -import { Button, ButtonProps } from "@patternfly/react-core/dist/js/components/Button"; -import { PlusCircleIcon } from "@patternfly/react-icons/dist/js/icons/plus-circle-icon"; -import { connectField, FieldProps, filterDOMProps, joinName, useField } from "uniforms"; - -export type ListAddFieldProps = FieldProps< - unknown, - ButtonProps, - { - initialCount?: number; - name: string; - disabled?: boolean; - value?: unknown; - } ->; - -function ListAddField({ disabled = false, name, value, ...props }: ListAddFieldProps) { - const nameParts = joinName(null, name); - const parentName = joinName(nameParts.slice(0, -1)); - const parent = useField<{ maxCount?: number }, unknown[]>(parentName, {}, { absoluteName: true })[0]; - - const limitNotReached = !disabled && !(parent.maxCount! <= (parent.value?.length ?? -1)); - - return ( - - ); -} - -export default connectField(ListAddField, { - initialValue: false, - kind: "leaf", -}); diff --git a/packages/uniforms-patternfly/src/ListDelField.tsx b/packages/uniforms-patternfly/src/ListDelField.tsx deleted file mode 100644 index 36c1bde8f..000000000 --- a/packages/uniforms-patternfly/src/ListDelField.tsx +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { ReactNode } from "react"; -import { Button, ButtonProps } from "@patternfly/react-core/dist/js/components/Button"; -import { MinusCircleIcon } from "@patternfly/react-icons/dist/js/icons/minus-circle-icon"; -import { connectField, FieldProps, filterDOMProps, joinName, useField } from "uniforms"; - -export type ListDelFieldProps = FieldProps; - -function ListDelField({ name, disabled, ...props }: ListDelFieldProps) { - const nameParts = joinName(null, name); - const nameIndex = +nameParts[nameParts.length - 1]; - const parentName = joinName(nameParts.slice(0, -1)); - const parent = useField<{ minCount?: number }, unknown[]>(parentName, {}, { absoluteName: true })[0]; - - const limitNotReached = !disabled && !(parent.minCount! >= parent.value!.length); - - return ( - - ); -} - -export default connectField(ListDelField, { - initialValue: false, - kind: "leaf", -}); diff --git a/packages/uniforms-patternfly/src/ListField.tsx b/packages/uniforms-patternfly/src/ListField.tsx deleted file mode 100644 index 1b4e061e4..000000000 --- a/packages/uniforms-patternfly/src/ListField.tsx +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { Children, cloneElement, isValidElement, ReactNode } from "react"; -import { Tooltip } from "@patternfly/react-core/dist/js/components/Tooltip"; -import { Split, SplitItem } from "@patternfly/react-core/dist/js/layouts/Split"; -import { OutlinedQuestionCircleIcon } from "@patternfly/react-icons/dist/js/icons/outlined-question-circle-icon"; -import { connectField, filterDOMProps, HTMLFieldProps } from "uniforms"; -import ListItemField from "./ListItemField"; -import ListAddField from "./ListAddField"; - -export type ListFieldProps = HTMLFieldProps< - unknown[], - HTMLDivElement, - { - children?: ReactNode; - info?: string; - error?: boolean; - initialCount?: number; - itemProps?: object; - showInlineError?: boolean; - } ->; - -declare module "uniforms" { - interface FilterDOMProps { - wrapperCol: never; - labelCol: never; - } -} - -filterDOMProps.register("minCount", "wrapperCol", "labelCol"); - -function ListField({ - children = , - error, - errorMessage, - info, - initialCount, - itemProps, - label, - name, - value, - showInlineError, - ...props -}: ListFieldProps) { - return ( -
- - - {label && ( - - )} - - - - - - - -
- {value?.map((item, itemIndex) => - Children.map(children, (child, childIndex) => - isValidElement(child) - ? cloneElement(child as React.ReactElement<{ name: string }, string>, { - key: `${itemIndex}-${childIndex}`, - name: child.props.name - ?.split(/\$(.*)/s) - .slice(0, -1) - .join(`${itemIndex}`), - ...itemProps, - }) - : child - ) - )} -
-
- ); -} - -export default connectField(ListField); diff --git a/packages/uniforms-patternfly/src/ListItemField.tsx b/packages/uniforms-patternfly/src/ListItemField.tsx deleted file mode 100644 index 4d4d87bac..000000000 --- a/packages/uniforms-patternfly/src/ListItemField.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { ReactNode } from "react"; -import { connectField } from "uniforms"; -import AutoField from "./AutoField"; -import ListDelField from "./ListDelField"; - -export type ListItemFieldProps = { - children?: ReactNode; - value?: unknown; -}; - -function ListItemField({ children = }: ListItemFieldProps) { - return ( -
-
{children}
-
- -
-
- ); -} - -export default connectField(ListItemField, { - initialValue: false, -}); diff --git a/packages/uniforms-patternfly/src/LongTextField.tsx b/packages/uniforms-patternfly/src/LongTextField.tsx deleted file mode 100644 index 8112e70d0..000000000 --- a/packages/uniforms-patternfly/src/LongTextField.tsx +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import * as React from "react"; -import { TextArea } from "@patternfly/react-core/dist/js/components/TextArea"; -import { connectField, filterDOMProps, HTMLFieldProps } from "uniforms"; - -export type LongTextFieldProps = HTMLFieldProps< - string, - HTMLDivElement, - { - inputRef?: React.RefObject; - onChange: (value: string, event: React.ChangeEvent) => void; - value?: string; - prefix?: string; - } ->; - -function LongTextField({ - disabled, - id, - inputRef, - label, - name, - onChange, - placeholder, - value, - ...props -}: LongTextFieldProps) { - return ( -
- {label && } -