Skip to content

Commit a6cebc3

Browse files
authored
feat: update inputs (#187)
1 parent 0596bbc commit a6cebc3

File tree

62 files changed

+610
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+610
-58
lines changed

docs/spec.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
9494
| viewSpec.oneOfParams | `object` | | [Parameters](#oneofparams) that must be passed to oneof input |
9595
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
9696
| viewSpec.hidden | `boolean` | | Hide field and view |
97+
| viewSpec.delimiter | `Record<string, string>` | | Values of delimiters of inline object input elements |
9798

9899
### StringSpec
99100

@@ -144,9 +145,10 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
144145

145146
#### OneOfParams
146147

147-
| Property | Type | Required | Description |
148-
| :------- | :---------------------------- | :------: | :---------- |
149-
| toggler | `'select'` `'radio'` `'card'` | | Switch type |
148+
| Property | Type | Required | Description |
149+
| :--------- | :----------------------------------------- | :------: | :--------------------------------------------- |
150+
| toggler | `'select'` `'radio'` `'card'` `'checkbox'` | | Switch type |
151+
| booleanMap | `Record<'true' 'false', string>` | | Special object for oneof toggler type checkbox |
150152

151153
#### FileInput
152154

src/lib/core/types/specs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ export interface ObjectSpec<
118118
order?: string[];
119119
link?: LinkType;
120120
oneOfParams?: {
121-
toggler?: 'select' | 'radio' | 'card';
121+
toggler?: 'select' | 'radio' | 'card' | 'checkbox';
122+
booleanMap?: Record<'true' | 'false', string>;
122123
};
123124
placeholder?: string;
124125
hidden?: boolean;
125126
inputProps?: InputComponentProps;
126127
layoutProps?: LayoutComponentProps;
128+
delimiter?: Record<string, string>;
127129
};
128130
}
129131

src/lib/kit/components/Inputs/ObjectBase/ObjectBase.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@
1616
}
1717
}
1818
}
19+
20+
&__delimiter {
21+
display: flex;
22+
margin-right: 8px;
23+
align-items: center;
24+
white-space: nowrap;
25+
}
1926
}

src/lib/kit/components/Inputs/ObjectBase/ObjectBase.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22

33
import {Plus} from '@gravity-ui/icons';
4-
import {Button, Icon} from '@gravity-ui/uikit';
5-
import _ from 'lodash';
4+
import {Button, Icon, Text} from '@gravity-ui/uikit';
5+
import isObjectLike from 'lodash/isObjectLike';
6+
import set from 'lodash/set';
67

78
import {
89
Controller,
@@ -53,7 +54,7 @@ export const ObjectBase: React.FC<ObjectBaseProps> = ({
5354
(childName: string, childValue: FieldValue, childErrors?: Record<string, ValidateError>) =>
5455
restProps.input.onChange(
5556
(currentValue) =>
56-
_.set(
57+
set(
5758
{...currentValue},
5859
childName.split(`${restProps.input.name}.`).join(''),
5960
childValue,
@@ -66,7 +67,7 @@ export const ObjectBase: React.FC<ObjectBaseProps> = ({
6667
const content = React.useMemo(() => {
6768
if (
6869
!spec.properties ||
69-
!_.isObjectLike(spec.properties) ||
70+
!isObjectLike(spec.properties) ||
7071
!Object.keys(spec.properties || {}).length
7172
) {
7273
return null;
@@ -80,24 +81,32 @@ export const ObjectBase: React.FC<ObjectBaseProps> = ({
8081
? filterPropertiesForObjectInline(spec.properties)
8182
: spec.properties;
8283

84+
const delimiter = spec.viewSpec.delimiter;
85+
const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
86+
8387
return (
8488
<div className={b('content', {inline})}>
85-
{(spec.viewSpec.order || Object.keys(specProperties)).map((property: string) =>
89+
{orderProperties.map((property: string) =>
8690
specProperties[property] ? (
87-
<Controller
88-
value={restProps.input.value?.[property]}
89-
spec={specProperties[property]}
90-
name={`${name ? name + '.' : ''}${property}`}
91-
parentOnChange={parentOnChange}
92-
parentOnUnmount={restProps.input.parentOnUnmount}
93-
key={`${name ? name + '.' : ''}${property}`}
94-
/>
91+
<React.Fragment key={`${name ? name + '.' : ''}${property}`}>
92+
<Controller
93+
value={restProps.input.value?.[property]}
94+
spec={specProperties[property]}
95+
name={`${name ? name + '.' : ''}${property}`}
96+
parentOnChange={parentOnChange}
97+
parentOnUnmount={restProps.input.parentOnUnmount}
98+
/>
99+
{delimiter && delimiter[property] ? (
100+
<Text className={b('delimiter')}>{delimiter[property]}</Text>
101+
) : null}
102+
</React.Fragment>
95103
) : null,
96104
)}
97105
</div>
98106
);
99107
}, [
100108
spec.properties,
109+
spec.viewSpec.delimiter,
101110
spec.viewSpec.order,
102111
restProps.input.value,
103112
restProps.input.parentOnUnmount,
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)