Skip to content

Commit a90a44b

Browse files
authored
feat: add checkbox input props (#193)
1 parent 68ce999 commit a90a44b

23 files changed

+133
-6
lines changed

docs/input-props-map.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Supported input props map
2+
3+
| Config type | Config name | Storybook | Type | Original component |
4+
| :---------- | :---------- | :----------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------- | :----------------------------------------------------------------------------- |
5+
| `array` | `select` | [Select](https://preview.gravity-ui.com/dynamic-forms/?path=/story/array-select--select) | [MultiSelectProps](../src/lib/kit/components/Inputs/MultiSelect/MultiSelect.tsx#L10) | https://github.com/gravity-ui/uikit/tree/main/src/components/Select |
6+
| `boolean` | `base` | [Base](https://preview.gravity-ui.com/dynamic-forms/?path=/story/boolean-base--base) | [CheckboxProps](../src/lib/kit/components/Inputs/Checkbox/Checkbox.tsx#L12) | https://github.com/gravity-ui/uikit/tree/main/src/components/Checkbox |
7+
| `number` | `base` | [Base](https://preview.gravity-ui.com/dynamic-forms/?path=/story/number-base--base) | [TextProps](../src/lib/kit/components/Inputs/Text/Text.tsx#L9) | https://github.com/gravity-ui/uikit/tree/main/src/components/Text |
8+
| `string` | `base` | [Base](https://preview.gravity-ui.com/dynamic-forms/?path=/story/string-base--base) | [TextProps](../src/lib/kit/components/Inputs/Text/Text.tsx#L9) | https://github.com/gravity-ui/uikit/tree/main/src/components/Text |
9+
| `string` | `password` | [Password](https://preview.gravity-ui.com/dynamic-forms/?path=/story/string-password--password) | [TextProps](../src/lib/kit/components/Inputs/Text/Text.tsx#L9) | https://github.com/gravity-ui/uikit/tree/main/src/components/Text |
10+
| `string` | `select` | [Select](https://preview.gravity-ui.com/dynamic-forms/?path=/story/string-select--select) | [SelectProps](../src/lib/kit/components/Inputs/Select/Select.tsx#L12) | https://github.com/gravity-ui/uikit/tree/main/src/components/Select |
11+
| `string` | `textarea` | [TextArea](https://preview.gravity-ui.com/dynamic-forms/?path=/story/string-textarea--text-area) | [TextAreaProps](../src/lib/kit/components/Inputs/TextArea/TextArea.tsx#L7) | https://github.com/gravity-ui/uikit/tree/main/src/components/controls/TextArea |

docs/spec.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
3333
| viewSpec.addButtonPosition | `"down"/"right"` | | The location of the button adding a new element to the array. Default value "down". |
3434
| viewSpec.hidden | `boolean` | | Hide field and view |
3535
| viewSpec.selectParams | `object` | | [Parameters](#selectparams) additional options for the selector |
36+
| viewSpec.inputProps | `object` | | [InputProps](./input-props-map.md) Additional properties for internal input components |
3637

3738
### BooleanSpec
3839

@@ -50,6 +51,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
5051
| viewSpec.layoutOpen | `boolean` | | Expand [Layout](./config.md#layouts) at the first rendering |
5152
| viewSpec.link | `any` | | A field containing information for forming a [link](#link) for a value |
5253
| viewSpec.hidden | `boolean` | | Hide field and view |
54+
| viewSpec.inputProps | `object` | | [InputProps](./input-props-map.md) Additional properties for internal input components |
5355

5456
### NumberSpec
5557

@@ -72,6 +74,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
7274
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
7375
| viewSpec.copy | `boolean` | | For `true`, will add a copy value button |
7476
| viewSpec.hidden | `boolean` | | Hide field and view |
77+
| viewSpec.inputProps | `object` | | [InputProps](./input-props-map.md) Additional properties for internal input components |
7578

7679
### ObjectSpec
7780

@@ -127,6 +130,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
127130
| viewSpec.textContentParams | `object` | | [Parameters](#textcontentparams) that must be passed to text content |
128131
| viewSpec.selectParams | `object` | | [Parameters](#selectparams) additional options for the selector |
129132
| viewSpec.generateRandomValueButton | `boolean` | | Shows a button that allows you to generate a random value depending on the passed [function generateRandomValue](./lib.md#dynamicfield) |
133+
| viewSpec.inputProps | `object` | | [InputProps](./input-props-map.md) Additional properties for internal input components |
130134

131135
#### SizeParams
132136

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

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

3-
import {Checkbox as CheckboxBase} from '@gravity-ui/uikit';
3+
import {Checkbox as CheckboxBase, CheckboxProps as CheckboxBaseProps} from '@gravity-ui/uikit';
44

55
import {BooleanInput} from '../../../../core';
66
import {block} from '../../../utils';
@@ -9,7 +9,13 @@ import './Checkbox.scss';
99

1010
const b = block('checkbox');
1111

12-
export const Checkbox: BooleanInput = ({name, input, spec}) => {
12+
export interface CheckboxProps
13+
extends Omit<
14+
CheckboxBaseProps,
15+
'checked' | 'onChange' | 'onBlur' | 'onFocus' | 'disabled' | 'qa'
16+
> {}
17+
18+
export const Checkbox: BooleanInput<CheckboxProps> = ({name, input, spec, inputProps}) => {
1319
const {value, onBlur, onChange, onFocus} = input;
1420

1521
const handleChange = React.useCallback(
@@ -20,6 +26,7 @@ export const Checkbox: BooleanInput = ({name, input, spec}) => {
2026
return (
2127
<div className={b()}>
2228
<CheckboxBase
29+
{...inputProps}
2330
checked={value}
2431
onChange={handleChange}
2532
onBlur={onBlur}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
}
1919

2020
&__delimiter {
21+
height: 28px;
2122
display: flex;
2223
margin-right: 8px;
2324
align-items: center;

src/stories/ArrayBase.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const excludeOptions = [
3939
'viewSpec.table',
4040
'viewSpec.placeholder',
4141
'viewSpec.selectParams',
42+
'viewSpec.inputProps',
4243
];
4344

4445
const template = () => {

src/stories/ArrayTable.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const excludeOptions = [
6262
'viewSpec.itemPrefix',
6363
'viewSpec.addButtonPosition',
6464
'viewSpec.selectParams',
65+
'viewSpec.inputProps',
6566
];
6667

6768
const value = [

src/stories/BooleanSwitch.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const baseSpec: BooleanSpec = {
1616
viewSpec: {type: 'switch', layout: 'row', layoutTitle: 'Flag'},
1717
};
1818

19-
const excludeOptions = ['viewSpec.type'];
19+
const excludeOptions = ['viewSpec.type', 'viewSpec.inputProps'];
2020

2121
const template = (spec: BooleanSpec = baseSpec) => {
2222
const Template: StoryFn<typeof SwitchBase> = (__, {viewMode}) => (

src/stories/ObjectBase.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const excludeOptions = [
4242
'viewSpec.type',
4343
'viewSpec.oneOfParams',
4444
'viewSpec.delimiter',
45+
'viewSpec.inputProps',
4546
];
4647

4748
const template = (spec: ObjectSpec = baseSpec) => {

src/stories/ObjectCardOneOf.stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ const baseSpec: ObjectSpec = {
5959
},
6060
};
6161

62-
const excludeOptions = ['viewSpec.type', 'viewSpec.placeholder', 'viewSpec.delimiter'];
62+
const excludeOptions = [
63+
'viewSpec.type',
64+
'viewSpec.placeholder',
65+
'viewSpec.delimiter',
66+
'viewSpec.inputProps',
67+
];
6368

6469
const template = (spec: ObjectSpec = baseSpec) => {
6570
const Template: StoryFn<typeof CardOneOfBase> = (__, {viewMode}) => (

src/stories/ObjectInline.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const excludeOptions = [
5959
'viewSpec.type',
6060
'viewSpec.oneOfParams',
6161
'viewSpec.placeholder',
62+
'viewSpec.inputProps',
6263
];
6364

6465
const template = (spec: ObjectSpec = baseSpec) => {

0 commit comments

Comments
 (0)