Skip to content

Commit 05d308f

Browse files
committed
PrimeReact theme:
Remove unused util functions Default form test Add grid test
1 parent d768271 commit 05d308f

File tree

4 files changed

+174
-188
lines changed

4 files changed

+174
-188
lines changed

packages/primereact/src/Theme/Theme.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22
import { ThemeProps } from '@rjsf/core';
3-
import { Form as SuiForm } from 'semantic-ui-react';
43

54
import { generateTemplates } from '../Templates';
65
import { generateWidgets } from '../Widgets';

packages/primereact/src/util.tsx

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,3 @@
1-
import { ElementType } from 'react';
2-
import {
3-
UiSchema,
4-
GenericObjectType,
5-
getUiOptions,
6-
FormContextType,
7-
RJSFSchema,
8-
StrictRJSFSchema,
9-
UIOptionsType,
10-
} from '@rjsf/utils';
11-
12-
export type PrimePropsTypes<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
13-
formContext?: F;
14-
uiSchema?: UiSchema<T, S, F>;
15-
options?: UIOptionsType<T, S, F>;
16-
defaultSchemaProps?: GenericObjectType;
17-
defaultContextProps?: GenericObjectType;
18-
};
19-
20-
export type PrimeErrorPropsType<
21-
T = any,
22-
S extends StrictRJSFSchema = RJSFSchema,
23-
F extends FormContextType = any,
24-
> = {
25-
formContext?: F;
26-
uiSchema?: UiSchema<T, S, F>;
27-
options?: UIOptionsType<T, S, F>;
28-
defaultProps?: GenericObjectType;
29-
};
30-
31-
export type WrapProps = GenericObjectType & {
32-
wrap: boolean;
33-
component?: ElementType;
34-
};
35-
36-
/**
37-
* Extract props meant for prime UI components from props that are
38-
* passed to Widgets, Templates and Fields.
39-
* @param {Object} params
40-
* @param {Object?} params.formContext
41-
* @param {Object?} params.uiSchema
42-
* @param {Object?} params.options
43-
* @param {Object?} params.defaultSchemaProps
44-
* @param {Object?} params.defaultContextProps
45-
* @returns {any}
46-
*/
47-
export function getPrimeProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
48-
formContext = {} as F,
49-
uiSchema = {},
50-
options = {},
51-
defaultSchemaProps = {
52-
fluid: true,
53-
inverted: false,
54-
},
55-
defaultContextProps = {},
56-
}: PrimePropsTypes<T, S, F>) {
57-
const formContextProps = formContext.semantic;
58-
const schemaProps = getUiOptions<T, S, F>(uiSchema).semantic;
59-
const optionProps = options.semantic;
60-
// formContext props should overide other props
61-
return Object.assign(
62-
{},
63-
{ ...defaultSchemaProps },
64-
{ ...defaultContextProps },
65-
schemaProps,
66-
optionProps,
67-
formContextProps,
68-
);
69-
}
70-
71-
/**
72-
* Extract error props meant for prime UI components from props that are
73-
* passed to Widgets, Templates and Fields.
74-
* @param {Object} params
75-
* @param {Object?} params.formContext
76-
* @param {Object?} params.uiSchema
77-
* @param {Object?} params.defaultProps
78-
* @returns {any}
79-
*/
80-
export function getPrimeErrorProps<
81-
T = any,
82-
S extends StrictRJSFSchema = RJSFSchema,
83-
F extends FormContextType = any,
84-
>({
85-
formContext = {} as F,
86-
uiSchema = {},
87-
options = {},
88-
defaultProps = { size: 'small', pointing: 'above' },
89-
}: PrimeErrorPropsType<T, S, F>) {
90-
const formContextProps = formContext.semantic && formContext.semantic.errorOptions;
91-
const semanticOptions: GenericObjectType = getUiOptions<T, S, F>(uiSchema).semantic as GenericObjectType;
92-
const schemaProps = semanticOptions && semanticOptions.errorOptions;
93-
const optionProps = options.semantic && (options.semantic as GenericObjectType).errorOptions;
94-
95-
return Object.assign({}, { ...defaultProps }, schemaProps, optionProps, formContextProps);
96-
}
97-
98-
/**
99-
* Combine multiple strings containing class names into a single string,
100-
* removing duplicates. E.g.
101-
* cleanClassNames('bar', 'baz bar', 'x y ', undefined)
102-
* // 'bar baz x y'
103-
* @param {Array} classNameArr
104-
* @param {Array} omit
105-
* @returns {string}
106-
*/
107-
export function cleanClassNames(classNameArr: Array<string | undefined>, omit: string[] = []) {
108-
// Split each arg on whitespace, and add it to an array. Skip false-y args
109-
// like "" and undefined.
110-
const classList = classNameArr
111-
.filter(Boolean)
112-
.reduce<string[]>((previous, current) => previous.concat(current!.trim().split(/\s+/)), []);
113-
114-
// Remove any class names from omit, and make the rest unique before
115-
// returning them as a string
116-
return [...new Set(classList.filter((cn) => !omit.includes(cn)))].join(' ');
117-
}
118-
119-
/**
120-
*
121-
* @param {boolean} wrap
122-
* @param Component
123-
* @param {Object} props
124-
* @returns {*}
125-
* @constructor
126-
*/
127-
export function MaybeWrap({ wrap, component: Component = 'div', ...props }: WrapProps) {
128-
return wrap ? <Component {...props} /> : props.children;
129-
}
130-
1311
export function Label({ id, text, required }: { id: string; text?: string; required?: boolean }) {
1322
if (!text) {
1333
return null;
Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,5 @@
1-
import { formTests, SLIDER_CUSTOMIZE, TEXTAREA_CUSTOMIZE } from '@rjsf/snapshot-tests';
1+
import { formTests } from '@rjsf/snapshot-tests';
22

33
import Form from '../src';
44

5-
// The `TextareaAutosize` code reads the following data from the `getComputedStyle()` function in a useEffect hook
6-
jest.spyOn(window, 'getComputedStyle').mockImplementation(() => {
7-
return {
8-
width: 100,
9-
'box-sizing': 10,
10-
'padding-bottom': 1,
11-
'padding-top': 1,
12-
'border-bottom-width': 1,
13-
'border-top-width': 1,
14-
} as unknown as CSSStyleDeclaration;
15-
});
16-
17-
formTests(Form, {
18-
[TEXTAREA_CUSTOMIZE]: {
19-
createNodeMock: (element) => {
20-
if (element.type === 'textarea') {
21-
// the `TextareaAutosize` code expects a ref for two textareas to exist, so use the feature of
22-
// react-test-renderer to create one
23-
// See: https://reactjs.org/docs/test-renderer.html#ideas
24-
if (element.props['aria-hidden']) {
25-
// The hidden one reads the following values
26-
return {
27-
style: { width: 10 },
28-
scrollHeight: 100,
29-
};
30-
}
31-
// The other one needs to look like an input node with focus and style elements
32-
return {
33-
nodeName: 'INPUT',
34-
focus: jest.fn(),
35-
style: {},
36-
};
37-
}
38-
return null;
39-
},
40-
},
41-
[SLIDER_CUSTOMIZE]: {
42-
createNodeMock: (element) => {
43-
// the `Slider` code expects a ref for a span.root to exist, so use the feature of
44-
// react-test-renderer to create one
45-
// See: https://reactjs.org/docs/test-renderer.html#ideas
46-
if (element.type === 'span' && element.props.id === 'root') {
47-
// Pretend to be an event listening component inside of an event listening document
48-
return {
49-
addEventListener: jest.fn(),
50-
removeEventListener: jest.fn(),
51-
ownerDocument: {
52-
addEventListener: jest.fn(),
53-
removeEventListener: jest.fn(),
54-
},
55-
};
56-
}
57-
return null;
58-
},
59-
},
60-
});
5+
formTests(Form);
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import { gridTests } from '@rjsf/snapshot-tests';
2+
3+
import Form from '../src';
4+
5+
gridTests(Form, {
6+
ColumnWidthAll: { xs: 12 },
7+
ColumnWidth4: { xs: 4 },
8+
ColumnWidth6: { xs: 6 },
9+
ColumnWidth8: { xs: 8 },
10+
Row2Columns: {},
11+
Row3Columns: {},
12+
ComplexUiSchema: {
13+
'ui:field': 'LayoutGridField',
14+
'ui:layoutGrid': {
15+
'ui:row': {
16+
children: [
17+
{
18+
'ui:col': {
19+
children: ['person'],
20+
},
21+
},
22+
{
23+
'ui:columns': {
24+
xs: 4,
25+
children: ['person.name.first', 'person.name.middle', 'person.name.last'],
26+
},
27+
},
28+
{
29+
'ui:col': {
30+
sm: 4,
31+
children: ['person.birth_date'],
32+
},
33+
},
34+
{
35+
'ui:col': {
36+
sm: 8,
37+
children: ['person.race'],
38+
},
39+
},
40+
{
41+
'ui:col': {
42+
sm: 6,
43+
children: [
44+
{
45+
'ui:row': {
46+
children: [
47+
{
48+
'ui:columns': {
49+
children: ['person.address.line_1', 'person.address.line_2', 'person.address.city'],
50+
},
51+
},
52+
{
53+
'ui:columns': {
54+
sm: 6,
55+
children: ['person.address.state', 'person.address.postal_code'],
56+
},
57+
},
58+
],
59+
},
60+
},
61+
],
62+
},
63+
},
64+
{
65+
'ui:col': {
66+
sm: 6,
67+
children: [
68+
{
69+
'ui:row': {
70+
children: [
71+
{
72+
'ui:columns': {
73+
children: ['employment'],
74+
},
75+
},
76+
{
77+
'ui:condition': {
78+
field: 'employment.job_type',
79+
value: 'company',
80+
operator: 'all',
81+
children: [
82+
{
83+
'ui:columns': {
84+
children: ['employment.business', 'employment.title'],
85+
},
86+
},
87+
{
88+
'ui:col': {
89+
children: ['employment.location.city'],
90+
},
91+
},
92+
{
93+
'ui:col': {
94+
children: ['employment.location.state'],
95+
},
96+
},
97+
],
98+
},
99+
},
100+
{
101+
'ui:condition': {
102+
field: 'employment.job_type',
103+
value: 'education',
104+
operator: 'all',
105+
children: [
106+
{
107+
'ui:columns': {
108+
children: ['employment.district', 'employment.school', 'employment.title'],
109+
},
110+
},
111+
{
112+
'ui:col': {
113+
children: ['employment.location.city'],
114+
},
115+
},
116+
{
117+
'ui:col': {
118+
children: ['employment.location.state'],
119+
},
120+
},
121+
],
122+
},
123+
},
124+
{
125+
'ui:condition': {
126+
field: 'employment.job_type',
127+
value: 'other',
128+
operator: 'all',
129+
children: [
130+
{
131+
'ui:columns': {
132+
children: [
133+
{
134+
name: 'employment.description',
135+
rows: 6,
136+
},
137+
],
138+
},
139+
},
140+
],
141+
},
142+
},
143+
],
144+
},
145+
},
146+
],
147+
},
148+
},
149+
],
150+
},
151+
},
152+
person: {
153+
'ui:field': 'LayoutHeaderField',
154+
race: {
155+
'ui:options': {
156+
widget: 'checkboxes',
157+
},
158+
},
159+
address: {
160+
'ui:field': 'LayoutGridField',
161+
},
162+
},
163+
employment: {
164+
'ui:options': {
165+
inline: true,
166+
},
167+
description: {
168+
'ui:widget': 'textarea',
169+
},
170+
},
171+
},
172+
});

0 commit comments

Comments
 (0)