Skip to content

Updated chakra-ui theme to use new @rjsf/utils and @rjsf/validator #2917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38,177 changes: 10,808 additions & 27,369 deletions packages/antd/package-lock.json

Large diffs are not rendered by default.

56 changes: 22 additions & 34 deletions packages/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "rimraf dist && tsdx build --format cjs,es,umd",
"test": "tsdx test",
"test:update": "tsdx test --u"
},
},
"files": [
"dist"
],
Expand All @@ -24,52 +24,37 @@
},
"peerDependencies": {
"@ant-design/icons": "^4.0.0",
"@rjsf/core": "^4.0.0",
"@rjsf/core": "^4.2.0",
"@rjsf/utils": "^4.2.0",
"antd": "^4.0.0",
"antd-dayjs-webpack-plugin": "1.0.0",
"dayjs": "^1.8.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.15",
"react": ">=16"
},
"devDependencies": {
"@ant-design/icons": "^4.0.0",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.10.3",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.4.4",
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.18.6",
"@rjsf/core": "^4.2.0",
"@rjsf/utils": "^4.2.0",
"@rjsf/validator-ajv6": "^4.2.0",
"antd": "^4.0.0",
"atob": "^2.0.3",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.6",
"concurrently": "^5.1.0",
"cross-env": "^2.0.1",
"css-loader": "^3.2.0",
"dayjs": "^1.8.0",
"eslint": "^4.9.0",
"eslint-config-react-app": "^2.0.1",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.4.0",
"jest": "24.9.0",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"dayjs": "^1.11.3",
"eslint": "^8.19.0",
"eslint-plugin-import": "^2.26.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.15",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-test-renderer": "^16.13.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-test-renderer": "^16.14.0",
"rimraf": "^3.0.2",
"style-loader": "^2.0.0",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-middleware": "^3.4.0",
"webpack-hot-middleware": "^2.13.2"
"tsdx": "^0.14.1"
},
"repository": {
"type": "git",
Expand All @@ -86,6 +71,9 @@
"rjsf-antd"
],
"author": "Delyan Ruskov <[email protected]>",
"contributors": [
"Heath Chiavettone <[email protected]"
],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/rjsf-team/react-jsonschema-form/issues"
Expand Down
3 changes: 1 addition & 2 deletions packages/antd/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { utils, withTheme } from '@rjsf/core';
import { withTheme, getDefaultRegistry } from '@rjsf/core';

import DescriptionField from './fields/DescriptionField';
import TitleField from './fields/TitleField';
Expand Down Expand Up @@ -29,7 +29,6 @@ import ErrorList from './ErrorList';

// import './index.less';

const { getDefaultRegistry } = utils;
const { fields, widgets } = getDefaultRegistry();

export const Fields = {
Expand Down
22 changes: 6 additions & 16 deletions packages/antd/src/templates/ArrayFieldTemplate/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React from 'react';

import { utils } from '@rjsf/core';
import { getUiOptions, getWidget, isFixedItems, optionsList, ITEMS_KEY } from '@rjsf/utils';

import FixedArrayFieldTemplate from './FixedArrayFieldTemplate';
import NormalArrayFieldTemplate from './NormalArrayFieldTemplate';

const {
getUiOptions,
getWidget,
isFilesArray,
isFixedItems,
isMultiSelect,
optionsList,
retrieveSchema,
} = utils;

const ArrayFieldTemplate = ({
DescriptionField,
TitleField,
Expand All @@ -41,7 +31,7 @@ const ArrayFieldTemplate = ({
title,
uiSchema,
}) => {
const { fields, rootSchema, widgets } = registry;
const { fields, schemaUtils, widgets } = registry;
const { UnsupportedField } = fields;

const renderFiles = () => {
Expand Down Expand Up @@ -71,7 +61,7 @@ const ArrayFieldTemplate = ({
};

const renderMultiSelect = () => {
const itemsSchema = retrieveSchema(schema.items, rootSchema, formData);
const itemsSchema = schemaUtils.retrieveSchema(schema.items, formData);
const enumOptions = optionsList(itemsSchema);
const { widget = 'select', ...options } = {
...getUiOptions(uiSchema),
Expand Down Expand Up @@ -103,7 +93,7 @@ const ArrayFieldTemplate = ({
);
};

if (!Object.prototype.hasOwnProperty.call(schema, 'items')) {
if (!(ITEMS_KEY in schema)) {
return (
<UnsupportedField
idSchema={idSchema}
Expand Down Expand Up @@ -135,10 +125,10 @@ const ArrayFieldTemplate = ({
/>
);
}
if (isFilesArray(schema, uiSchema, rootSchema)) {
if (schemaUtils.isFilesArray(schema, uiSchema)) {
return renderFiles();
}
if (isMultiSelect(schema, rootSchema)) {
if (schemaUtils.isMultiSelect(schema)) {
return renderMultiSelect();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';

import { utils } from '@rjsf/core';
import { ADDITIONAL_PROPERTY_FLAG } from '@rjsf/utils';
import Button from 'antd/lib/button';
import Col from 'antd/lib/col';
import Form from 'antd/lib/form';
import Input from 'antd/lib/input';
import Row from 'antd/lib/row';
import DeleteOutlined from '@ant-design/icons/DeleteOutlined';

const { ADDITIONAL_PROPERTY_FLAG } = utils;

const VERTICAL_LABEL_COL = { span: 24 };
const VERTICAL_WRAPPER_COL = { span: 24 };

Expand Down
4 changes: 1 addition & 3 deletions packages/antd/src/templates/ObjectFieldTemplate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import React from 'react';
import classNames from 'classnames';
import _ from 'lodash';

import { utils } from '@rjsf/core';
import { canExpand } from '@rjsf/utils';
import Button from 'antd/lib/button';
import Col from 'antd/lib/col';
import Row from 'antd/lib/row';
import { withConfigConsumer } from 'antd/lib/config-provider/context';
import PlusCircleOutlined from '@ant-design/icons/PlusCircleOutlined';

const { canExpand } = utils;

const DESCRIPTION_COL_STYLE = {
paddingBottom: '8px',
};
Expand Down
4 changes: 1 addition & 3 deletions packages/antd/src/widgets/AltDateWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useEffect, useState } from "react";

import { utils } from '@rjsf/core';
import { pad, parseDateString, toDateString } from '@rjsf/utils';
import Button from 'antd/lib/button';
import Col from 'antd/lib/col';
import Row from 'antd/lib/row';

const { pad, parseDateString, toDateString } = utils;

const rangeOptions = (start, stop) => {
let options = [];
for (let i = start; i <= stop; i++) {
Expand Down
4 changes: 1 addition & 3 deletions packages/antd/src/widgets/RangeWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-else-return */
import React from 'react';

import { utils } from '@rjsf/core';
import { rangeSpec } from '@rjsf/utils';
import Slider from 'antd/lib/slider';

const { rangeSpec } = utils;

const RangeWidget = ({
autofocus,
disabled,
Expand Down
43 changes: 4 additions & 39 deletions packages/antd/src/widgets/SelectWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
/* eslint-disable no-else-return */
import React from 'react';

import { utils } from '@rjsf/core';
import { processSelectValue } from '@rjsf/utils';
import Select from 'antd/lib/select';

const { asNumber, guessType } = utils;

const SELECT_STYLE = {
width: '100%',
};

const nums = new Set(['number', 'integer']);

/**
* This is a silly limitation in the DOM where option change event values are
* always retrieved as strings.
*/
const processValue = (schema, value) => {
// "enum" is a reserved word, so only "type" and "items" can be destructured
const { type, items } = schema;

if (value === '') {
return undefined;
} else if (type === 'array' && items && nums.has(items.type)) {
return value.map(asNumber);
} else if (type === 'boolean') {
return value === 'true';
} else if (type === 'number') {
return asNumber(value);
}

// If type is undefined, but an enum is present, try and infer the type from
// the enum values
if (schema.enum) {
if (schema.enum.every((x) => guessType(x) === 'number')) {
return asNumber(value);
} else if (schema.enum.every((x) => guessType(x) === 'boolean')) {
return value === 'true';
}
}

return value;
};

const SelectWidget = ({
autofocus,
disabled,
Expand All @@ -64,11 +29,11 @@ const SelectWidget = ({

const { enumOptions, enumDisabled } = options;

const handleChange = (nextValue) => onChange(processValue(schema, nextValue));
const handleChange = (nextValue) => onChange(processSelectValue(schema, nextValue));

const handleBlur = () => onBlur(id, processValue(schema, value));
const handleBlur = () => onBlur(id, processSelectValue(schema, value));

const handleFocus = () => onFocus(id, processValue(schema, value));
const handleFocus = () => onFocus(id, processSelectValue(schema, value));

const getPopupContainer = (node) => node.parentNode;

Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/widgets/SubmitButton/SubmitButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from '@rjsf/core';
import { getSubmitButtonOptions } from '@rjsf/utils';
import React from "react";
import Button from 'antd/lib/button';
const { getSubmitButtonOptions } = utils;

export default ({ uiSchema }) => {
const { submitText, norender, props: submitButtonProps }= getSubmitButtonOptions(uiSchema);
if (norender) {return null;}
Expand Down
7 changes: 4 additions & 3 deletions packages/antd/test/Array.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import renderer from 'react-test-renderer';
import validator from '@rjsf/validator-ajv6';

import '../__mocks__/matchMedia.mock';
import Form from '../src';
Expand All @@ -15,7 +16,7 @@ describe("array fields", () => {
}
};
const tree = renderer
.create(<Form schema={schema} />)
.create(<Form schema={schema} validator={validator} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
Expand All @@ -32,7 +33,7 @@ describe("array fields", () => {
]
};
const tree = renderer
.create(<Form schema={schema} />)
.create(<Form schema={schema} validator={validator} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
Expand All @@ -46,7 +47,7 @@ describe("array fields", () => {
uniqueItems: true
};
const tree = renderer
.create(<Form schema={schema} />)
.create(<Form schema={schema} validator={validator} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down
Loading