Skip to content

Commit 2a088f8

Browse files
committed
Merge branch 'master' into rebeaseMasterMUI5
2 parents 8b56ab7 + 82b9673 commit 2a088f8

File tree

28 files changed

+272
-129
lines changed

28 files changed

+272
-129
lines changed

packages/ant-component-mapper/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@data-driven-forms/ant-component-mapper",
3-
"version": "3.15.3",
3+
"version": "3.15.7",
44
"description": "Ant Design React component mapper for Data Driven Forms.",
55
"main": "index.js",
66
"module": "esm/index.js",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Meta } from "@data-driven-forms/react-form-renderer";
22

3-
export type validationError = (meta: Meta<any>, validateOnMount?: boolean) => boolean | any | undefined
3+
export function validationError(meta: Meta<any>, validateOnMount?: boolean): boolean | any | undefined
44

55
export default validationError;

packages/blueprint-component-mapper/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@data-driven-forms/blueprint-component-mapper",
3-
"version": "3.15.3",
3+
"version": "3.15.7",
44
"description": "BlueprintJS React component mapper for Data Driven Forms.",
55
"main": "index.js",
66
"module": "esm/index.js",
@@ -36,7 +36,9 @@
3636
"peerDependencies": {
3737
"@blueprintjs/core": "^3.26.1",
3838
"@blueprintjs/datetime": "^3.17.0",
39-
"@blueprintjs/select": "^3.12.3"
39+
"@blueprintjs/select": "^3.12.3",
40+
"react": "^16.13.1 || ^17.0.2",
41+
"react-dom": "^16.13.1 || ^17.0.2"
4042
},
4143
"dependencies": {
4244
"@data-driven-forms/common": "*",

packages/carbon-component-mapper/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@data-driven-forms/carbon-component-mapper",
3-
"version": "3.15.3",
3+
"version": "3.15.7",
44
"description": "Carbon React component mapper for Data Driven Forms.",
55
"main": "index.js",
66
"module": "esm/index.js",
@@ -35,7 +35,10 @@
3535
"carbon-components-react": "^7.46.0",
3636
"carbon-icons": "^7.0.7"
3737
},
38-
"peerDependencies": {},
38+
"peerDependencies": {
39+
"react": "^16.13.1 || ^17.0.2",
40+
"react-dom": "^16.13.1 || ^17.0.2"
41+
},
3942
"dependencies": {
4043
"@data-driven-forms/common": "*",
4144
"clsx": "^1.1.1",

packages/carbon-component-mapper/src/tests/time-picker-string.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ describe('TimePicker<String>', () => {
193193
onSubmit.mockReset();
194194

195195
await act(async () => {
196-
wrapper.find('select#time-picker-12h').simulate('change', { target: { value: 'UTC' } });
196+
wrapper.find('select#time-picker-timezones').simulate('change', { target: { value: 'UTC' } });
197197
});
198198
wrapper.update();
199199

@@ -203,7 +203,7 @@ describe('TimePicker<String>', () => {
203203
wrapper.update();
204204

205205
expect(wrapper.find('input').props().value).toEqual('00:35');
206-
expect(onSubmit).toHaveBeenLastCalledWith({ 'time-picker': '00:35 UTC EST' });
206+
expect(onSubmit).toHaveBeenLastCalledWith({ 'time-picker': '00:35 AM UTC' });
207207
});
208208

209209
it('handles initial value', async () => {

packages/carbon-component-mapper/src/tests/time-picker.test.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('TimePicker', () => {
194194
onSubmit.mockReset();
195195

196196
await act(async () => {
197-
wrapper.find('select#time-picker-12h').simulate('change', { target: { value: 'UTC' } });
197+
wrapper.find('select#time-picker-timezones').simulate('change', { target: { value: 'UTC' } });
198198
});
199199
wrapper.update();
200200

@@ -203,8 +203,47 @@ describe('TimePicker', () => {
203203
});
204204
wrapper.update();
205205

206-
expect(wrapper.find('input').props().value).toEqual('10:35');
207-
expect(onSubmit.mock.calls[0][0]['time-picker'].getHours()).toEqual(10);
206+
expect(wrapper.find('input').props().value).toEqual('05:35');
207+
expect(onSubmit.mock.calls[0][0]['time-picker'].getHours()).toEqual(5);
208208
expect(onSubmit.mock.calls[0][0]['time-picker'].getMinutes()).toEqual(35);
209209
});
210+
211+
it('handles initial value', async () => {
212+
schema = {
213+
fields: [
214+
{
215+
component: componentTypes.TIME_PICKER,
216+
name: 'time-picker',
217+
initialValue: new Date('December 17, 1995 16:00:00'),
218+
twelveHoursFormat: true,
219+
},
220+
],
221+
};
222+
223+
await act(async () => {
224+
wrapper = mount(<FormRenderer schema={schema} {...initialProps} />);
225+
});
226+
wrapper.update();
227+
228+
expect(wrapper.find('input').props().value).toEqual('04:00');
229+
expect(wrapper.find('select').props().defaultValue).toEqual('PM');
230+
231+
await act(async () => {
232+
wrapper.find('input').simulate('change', { target: { value: '03:00' } });
233+
});
234+
wrapper.update();
235+
236+
await act(async () => {
237+
wrapper.find('input').simulate('blur');
238+
});
239+
wrapper.update();
240+
241+
await act(async () => {
242+
wrapper.find('form').simulate('submit');
243+
});
244+
wrapper.update();
245+
246+
expect(onSubmit.mock.calls[0][0]['time-picker'].getHours()).toEqual(15);
247+
expect(onSubmit.mock.calls[0][0]['time-picker'].getMinutes()).toEqual(0);
248+
});
210249
});

packages/carbon-component-mapper/src/time-picker-base/time-picker-base.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ interface InternalTimePickerBaseProps extends CarbonTimePickerProps, AnyObject {
2020
warnText?: ReactNode;
2121
selectFormat: (value: 'AM' | 'PM') => void;
2222
selectTimezone: (value: string) => void;
23+
format?: 'AM' | 'PM';
24+
defaultTimezone?: string;
2325
}
2426

2527
export type TimePickerBaseProps = InternalTimePickerBaseProps & FormGroupProps;

packages/carbon-component-mapper/src/time-picker-base/time-picker-base.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const TimePickerBase = ({
1818
warnText,
1919
selectFormat,
2020
selectTimezone,
21+
format,
22+
timezone,
2123
...rest
2224
}) => (
2325
<div {...WrapperProps}>
@@ -34,13 +36,23 @@ const TimePickerBase = ({
3436
{...rest}
3537
>
3638
{twelveHoursFormat && (
37-
<TimePickerSelect labelText="Period" id={`${rest.id || input.name}-12h`} onChange={({ target: { value } }) => selectFormat(value)}>
39+
<TimePickerSelect
40+
defaultValue={format}
41+
labelText="Period"
42+
id={`${rest.id || input.name}-12h`}
43+
onChange={({ target: { value } }) => selectFormat(value)}
44+
>
3845
<SelectItem value="AM" text="AM" />
3946
<SelectItem value="PM" text="PM" />
4047
</TimePickerSelect>
4148
)}
4249
{timezones && (
43-
<TimePickerSelect labelText="Timezone" id={`${rest.id || input.name}-timezones`} onChange={({ target: { value } }) => selectTimezone(value)}>
50+
<TimePickerSelect
51+
defaultValue={timezone}
52+
labelText="Timezone"
53+
id={`${rest.id || input.name}-timezones`}
54+
onChange={({ target: { value } }) => selectTimezone(value)}
55+
>
4456
{timezones.map(({ showAs, ...tz }) => (
4557
<SelectItem key={tz.value} text={tz.label} {...tz} />
4658
))}
@@ -78,6 +90,8 @@ TimePickerBase.propTypes = {
7890
warnText: PropTypes.node,
7991
selectFormat: PropTypes.func.isRequired,
8092
selectTimezone: PropTypes.func.isRequired,
93+
format: PropTypes.oneOf(['AM', 'PM']),
94+
timezone: PropTypes.string,
8195
};
8296

8397
export default TimePickerBase;

packages/carbon-component-mapper/src/time-picker-date/time-picker-date.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface Timezone extends SelectItemProps {
1212
interface InternalTimePickerProps extends CarbonTimePickerProps {
1313
twelveHoursFormat?: boolean;
1414
timezones?: Timezone[];
15+
defaultTimezone?: string;
1516
}
1617

1718
export type TimePickerDateProps = InternalTimePickerProps & FormGroupProps & UseFieldApiComponentConfig;

packages/carbon-component-mapper/src/time-picker-date/time-picker-date.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import prepareProps from '../prepare-props';
66
import TimePickerBase from '../time-picker-base';
77

88
const TimePickerDate = (props) => {
9-
const { input, meta, twelveHoursFormat, timezones, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps(props));
9+
const { input, meta, twelveHoursFormat, timezones, validateOnMount, helperText, WrapperProps, defaultTimezone, ...rest } = useFieldApi(
10+
prepareProps(props)
11+
);
1012

11-
const [timezone, selectTimezone] = useState(timezones ? timezones[0]?.value : '');
12-
const [format, selectFormat] = useState('AM');
13+
const [timezone, selectTimezone] = useState(defaultTimezone || timezones ? timezones[0]?.value : '');
14+
const [format, selectFormat] = useState(() => (input.value?.getHours?.() >= 12 ? 'PM' : 'AM'));
1315
const isMounted = useRef(false);
1416

1517
const invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
@@ -75,6 +77,8 @@ const TimePickerDate = (props) => {
7577
warnText={warnText}
7678
selectFormat={selectFormat}
7779
selectTimezone={selectTimezone}
80+
format={format}
81+
timezone={timezone}
7882
{...rest}
7983
/>
8084
);
@@ -96,6 +100,7 @@ TimePickerDate.propTypes = {
96100
})
97101
),
98102
WrapperProps: PropTypes.object,
103+
defaultTimezone: PropTypes.string,
99104
};
100105

101106
export default TimePickerDate;

0 commit comments

Comments
 (0)