generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add date picker string type (#205)
Co-authored-by: denis-vlasov <[email protected]>
- Loading branch information
Showing
50 changed files
with
391 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
## Supported input props map | ||
|
||
| Config type | Config name | Storybook | Type | Original component | | ||
| :---------- | :---------- | :----------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------- | :----------------------------------------------------------------------------- | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| Config type | Config name | Storybook | Type | Original component | | ||
| :---------- | :----------- | :--------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `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 | | ||
| `string` | `date_input` | [DatePicker](https://preview.gravity-ui.com/dynamic-forms/?path=/story/string-dateinput--date-input) | [DatePickerProps](https://preview.gravity-ui.com/date-components/?path=/docs/components-datepicker--docs) | https://github.com/gravity-ui/date-components/tree/main/src/components/DatePicker | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import '../../../styles/variables'; | ||
|
||
.#{$ns}date-input { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, {useCallback} from 'react'; | ||
|
||
import {DatePicker, DatePickerProps} from '@gravity-ui/date-components'; | ||
import {StringInputProps} from '../../../../core'; | ||
import {DateTime, dateTimeParse} from '@gravity-ui/date-utils'; | ||
import {block} from '../../../utils'; | ||
|
||
import './DateInput.scss'; | ||
|
||
export const DEFAULT_DATE_FORMAT = 'DD-MM-YYYY'; | ||
|
||
const b = block('date-input'); | ||
|
||
export interface DateProps | ||
extends Omit<DatePickerProps, 'value' | 'disabled' | 'placeholder' | 'qa'> {} | ||
|
||
export const DateInput: React.FC<StringInputProps<DateProps>> = ({ | ||
name, | ||
input, | ||
spec, | ||
inputProps, | ||
}) => { | ||
const {value, onChange, onBlur, onFocus} = input; | ||
const dateInput = spec.viewSpec.dateInput; | ||
const outputFormat = dateInput?.outputFormat; | ||
|
||
const onUpdate = useCallback( | ||
(date: DateTime | null) => { | ||
if (!date) { | ||
onChange(undefined as any); | ||
} else { | ||
switch (outputFormat) { | ||
case 'date_time': | ||
onChange(date as any); | ||
break; | ||
case 'date': | ||
onChange(date.toDate() as any); | ||
break; | ||
case 'timestamp': | ||
onChange({ | ||
seconds: Math.floor(date?.toDate().getTime() / 1000), | ||
nanos: 0, | ||
} as any); | ||
break; | ||
case 'string': | ||
case undefined: | ||
case '': | ||
onChange(date.toISOString()); | ||
break; | ||
default: | ||
onChange(date.format(outputFormat)); | ||
break; | ||
} | ||
} | ||
}, | ||
[outputFormat], | ||
); | ||
|
||
const props: DatePickerProps = { | ||
hasClear: true, | ||
format: dateInput?.printFormat || DEFAULT_DATE_FORMAT, | ||
...inputProps, | ||
onBlur: onBlur as (e: React.FocusEvent<HTMLElement>) => void, | ||
onFocus: onFocus as (e: React.FocusEvent<HTMLElement>) => void, | ||
value: value | ||
? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value) || null | ||
: null, | ||
onUpdate, | ||
disabled: spec.viewSpec.disabled, | ||
placeholder: spec.viewSpec.placeholder, | ||
}; | ||
|
||
return <DatePicker className={b()} data-qa={name} {...props} />; | ||
}; | ||
|
||
export default DateInput; |
Binary file added
BIN
+6.97 KB
..._/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.81 KB
...s__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.6 KB
.../DateInput.visual.test.tsx-snapshots/DateInput-default-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.55 KB
...__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.38 KB
...Input.visual.test.tsx-snapshots/DateInput-default-value-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.37 KB
...teInput.visual.test.tsx-snapshots/DateInput-default-value-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.02 KB
...nput.visual.test.tsx-snapshots/DateInput-default-value-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.16 KB
...eInput.visual.test.tsx-snapshots/DateInput-default-value-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.45 KB
...ts__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.58 KB
...hots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.3 KB
...s__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.42 KB
...ots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.02 KB
....visual.test.tsx-snapshots/DateInput-layout-transparent-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.28 KB
...ut.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.78 KB
...visual.test.tsx-snapshots/DateInput-layout-transparent-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3 KB
...t.visual.test.tsx-snapshots/DateInput-layout-transparent-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.1 KB
...teInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.17 KB
...DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.6 KB
...eInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.85 KB
...ateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.71 KB
...eInput.visual.test.tsx-snapshots/DateInput-view-default-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.06 KB
...ateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.58 KB
...Input.visual.test.tsx-snapshots/DateInput-view-default-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3 KB
...teInput.visual.test.tsx-snapshots/DateInput-view-default-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions
47
src/lib/kit/components/Inputs/DateInput/__tests__/DateInput.visual.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
|
||
import {DATE_INPUT, VALUE} from './helpers'; | ||
|
||
import {test} from '~playwright/core'; | ||
import {DynamicForm} from '~playwright/core/DynamicForm'; | ||
import {DynamicView} from '~playwright/core/DynamicView'; | ||
|
||
test.describe('DateInput', () => { | ||
test('default', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={DATE_INPUT.default} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('full', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={DATE_INPUT.full} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('default value', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={DATE_INPUT.defaultValue} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('row verbose', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={DATE_INPUT.row_verbose} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('layout transparent', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={DATE_INPUT.layoutTransparent} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
}); | ||
|
||
test.describe('DateInput view', () => { | ||
test('default', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicView spec={DATE_INPUT.default} value={VALUE} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
src/lib/kit/components/Inputs/DateInput/__tests__/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {FormValue, SpecTypes, StringSpec} from '../../../../../core'; | ||
|
||
export const DATE_INPUT: Record<string, StringSpec> = { | ||
default: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'date_input', | ||
layout: 'row', | ||
layoutTitle: 'Flag', | ||
}, | ||
}, | ||
full: { | ||
type: SpecTypes.String, | ||
required: true, | ||
viewSpec: { | ||
disabled: true, | ||
type: 'date_input', | ||
layout: 'row', | ||
layoutTitle: 'Flag', | ||
layoutDescription: 'description', | ||
}, | ||
}, | ||
defaultValue: { | ||
defaultValue: '2020-01-01', | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'date_input', | ||
layout: 'row', | ||
layoutTitle: 'File Input', | ||
}, | ||
}, | ||
layoutTransparent: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'date_input', | ||
layout: 'transparent', | ||
layoutTitle: 'Flag', | ||
}, | ||
}, | ||
row_verbose: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'date_input', | ||
layout: 'row_verbose', | ||
layoutTitle: 'File Input', | ||
layoutDescription: 'description', | ||
}, | ||
}, | ||
}; | ||
|
||
export const VALUE: FormValue = '2020-01-01'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DateInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.