Skip to content

Commit 799c24d

Browse files
author
Ruben van Leeuwen
committed
1904: Adds EUI integer field
1 parent 8a9eca0 commit 799c24d

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

packages/orchestrator-ui-components/src/components/WfoPydanticForm/WfoPydanticForm.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Row } from './Row';
3030
import {
3131
Checkbox,
3232
Divider,
33+
Integer,
3334
Label,
3435
Radio,
3536
Summary,
@@ -232,6 +233,17 @@ export const WfoPydanticForm = ({
232233
);
233234
},
234235
},
236+
{
237+
id: 'integerfield',
238+
ElementMatch: {
239+
Element: Integer,
240+
isControlledElement: true,
241+
},
242+
matcher(field) {
243+
return field.type === PydanticFormFieldType.INTEGER;
244+
},
245+
validator: zodValidationPresets.integer,
246+
},
235247
...currentMatchers.filter((matcher) => matcher.id !== 'text'),
236248
{
237249
id: 'text',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
3+
import type { PydanticFormControlledElement } from 'pydantic-forms';
4+
5+
import { EuiFieldNumber } from '@elastic/eui';
6+
import { css } from '@emotion/react';
7+
8+
import type { WfoTheme } from '@/hooks';
9+
import { useWithOrchestratorTheme } from '@/hooks';
10+
11+
const getFormFieldsBaseStyle = ({ theme }: WfoTheme) => {
12+
const formFieldBaseStyle = css({
13+
backgroundColor: theme.colors.body,
14+
color: theme.colors.text,
15+
'&:focus': {
16+
backgroundColor: theme.colors.emptyShade,
17+
},
18+
});
19+
20+
return {
21+
formFieldBaseStyle,
22+
};
23+
};
24+
25+
export const Integer: PydanticFormControlledElement = ({
26+
pydanticFormField,
27+
onChange,
28+
value,
29+
disabled,
30+
}) => {
31+
const { formFieldBaseStyle } = useWithOrchestratorTheme(
32+
getFormFieldsBaseStyle,
33+
);
34+
35+
return (
36+
<EuiFieldNumber
37+
css={formFieldBaseStyle}
38+
name={pydanticFormField.id}
39+
onChange={(event) => onChange(parseInt(event.target.value))}
40+
value={value}
41+
disabled={disabled}
42+
/>
43+
);
44+
};

packages/orchestrator-ui-components/src/components/WfoPydanticForm/fields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './Divider';
55
export * from './Checkbox';
66
export * from './Summary';
77
export * from './Radio';
8+
export * from './Integer';

0 commit comments

Comments
 (0)