Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
feat(UIKIT-1659,DatePicker): Добавлен пропс startAdornment (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan1caisreal authored Aug 8, 2024
1 parent 1db3fb6 commit 2075a4b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
6 changes: 6 additions & 0 deletions packages/components/src/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const Example = () => {
);
};

export const StartAdornment = () => {
const [date, setDate] = useState<Date | null>();

return <DatePicker startAdornment="c" value={date} onChange={setDate} />;
};

const Template = (props: DatePickerProps) => {
const [date, setDate] = useState<Date | null>();

Expand Down
44 changes: 26 additions & 18 deletions packages/components/src/DatePicker/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ describe('DatePicker', () => {
);
});

it('StartAdornment отображается', () => {
renderWithTheme(<DatePicker startAdornment="по" />);

const startAdornment = screen.getByText('по');

expect(startAdornment).toBeVisible();
});

it('Placeholder по умолчанию отображается если не задан в inputProps', () => {
renderWithTheme(<DatePicker disabled />);

const placeholder = screen.getByPlaceholderText(DEFAULT_PLACEHOLDER);

expect(placeholder).toBeVisible();
});

it('Placeholder заданный в inputProps отображается', () => {
renderWithTheme(
<DatePicker disabled inputProps={{ placeholder: 'Введите дату' }} />,
);

const placeholder = screen.getByPlaceholderText('Введите дату');

expect(placeholder).toBeVisible();
});

describe('Пикер не позволяет выбрать дату', () => {
it('Меньше указанной в minDate', async () => {
const user = userEvents.setup();
Expand Down Expand Up @@ -192,23 +218,5 @@ describe('DatePicker', () => {

expect(popover).not.toBeInTheDocument();
});

it('Placeholder по умолчанию отображается если не задан в inputProps', () => {
renderWithTheme(<DatePicker disabled />);

const placeholder = screen.getByPlaceholderText(DEFAULT_PLACEHOLDER);

expect(placeholder).toBeVisible();
});

it('Placeholder заданный в inputProps отображается', () => {
renderWithTheme(
<DatePicker disabled inputProps={{ placeholder: 'Введите дату' }} />,
);

const placeholder = screen.getByPlaceholderText('Введите дату');

expect(placeholder).toBeVisible();
});
});
});
7 changes: 7 additions & 0 deletions packages/components/src/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export type DatePickerProps = MondayFirst &
* Вспомогательный текст под полем ввода
*/
helperText?: ReactNode;

/**
* Элемент в начале инпута
*/
startAdornment?: ReactNode;
} & Pick<TextFieldProps, 'label' | 'required' | 'helperText'>;

export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
Expand All @@ -102,6 +107,7 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
label,
required,
helperText,
startAdornment,
},
forwardedRef,
) => {
Expand Down Expand Up @@ -141,6 +147,7 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
return (
<div ref={ref} className={className}>
<DatePickerInput
startAdornment={startAdornment}
label={label}
required={required}
helperText={helperText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DatePickerInput = forwardRef<
onFocus,
disabled,
placeholder = DEFAULT_PLACEHOLDER,
startAdornment,
...props
},
ref,
Expand Down Expand Up @@ -86,6 +87,7 @@ export const DatePickerInput = forwardRef<
<CalendarOutlineMd />
</InputAdornment>
),
startAdornment: startAdornment,
}}
inputProps={{
...props.inputProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ export const Example = () => (
/>
);

export const StartAdornment = () => (
<Template
startDateProps={{
startAdornment: 'c',
inputProps: { label: 'startAdornment' },
}}
endDateProps={{
startAdornment: 'по',
inputProps: { label: 'startAdornment' },
}}
/>
);

export const Showcase = () => (
<LegacyGrid container spacing={6} autoFlow="row">
<Template />
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/DateRangePicker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DEFAULT_SPACING = 1;

export type DateItemProps = Pick<
DatePickerProps,
'onChange' | 'value' | 'inputProps'
'onChange' | 'value' | 'inputProps' | 'startAdornment'
>;

export type DateRangePickerProps = Omit<
Expand Down Expand Up @@ -219,6 +219,7 @@ export const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>(
<DatePickerInput
{...startDateProps.inputProps}
ref={startInputRef}
startAdornment={startDateProps.startAdornment}
mask={mask}
size={size}
value={startMaskedValue}
Expand All @@ -228,6 +229,7 @@ export const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>(
/>
<DatePickerInput
{...endDateProps.inputProps}
startAdornment={endDateProps.startAdornment}
ref={endInputRef}
size={size}
mask={mask}
Expand Down

0 comments on commit 2075a4b

Please sign in to comment.