Skip to content

Commit

Permalink
Revert "feat(Calendar): added period (#3258)"
Browse files Browse the repository at this point in the history
This reverts commit 0fce964.
  • Loading branch information
zhzz committed Apr 18, 2024
1 parent 2e06021 commit 90b5e32
Show file tree
Hide file tree
Showing 45 changed files with 336 additions and 846 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 14 additions & 104 deletions packages/react-ui/components/Calendar/Calendar.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


Календарь с заданной датой

```jsx harmony
Expand Down Expand Up @@ -82,69 +81,6 @@ const isHoliday = (day, isWeekend) => {
<Calendar isHoliday={isHoliday} value={date} onValueChange={setDate} />;
```

### Период дат

В календаре можно задать период пропами `periodStartDate` и `periodEndDate`.
Если задан только один из пропов, то при наведении мышью будет подсвечиваться период между заданным пропом и датой под указателем мыши.
```jsx harmony
import { Button, DateInput, Gapped, Radio, RadioGroup, Group } from '@skbkontur/react-ui';

const [periodStartDate, setPeriodStartDate] = React.useState('10.08.2022');
const [periodEndDate, setPeriodEndDate] = React.useState('20.08.2022');
const [period, setPeriod] = React.useState('start');

const onValueChange = (date) => {
if (period === 'start') {
setPeriodStartDate(date);
}
if (period === 'end') {
setPeriodEndDate(date);
}
}
<Gapped verticalAlign="top" wrap>
<Calendar
value={periodStartDate || periodEndDate}
periodStartDate={periodStartDate}
periodEndDate={periodEndDate}
onValueChange={onValueChange}
minDate="05.08.2022"
/>
<RadioGroup value={period} onValueChange={setPeriod}>
<Gapped vertical gap={40}>
<Gapped gap={0} vertical>
<span>Как сохранять дату из <tt>onValueChange</tt></span>
<Radio value="start">Как начало периода</Radio>
<Radio value="end">Как окончание периода</Radio>
</Gapped>
<Gapped vertical>
<span>Начало периода</span>
<Gapped>
<Group>
<DateInput
onValueChange={setPeriodStartDate}
value={periodStartDate}
/>
<Button onClick={() => setPeriodStartDate(null)}>x</Button>
</Group>
</Gapped>
</Gapped>
<Gapped vertical>
<span>Окончание периода</span>
<Gapped>
<Group>
<DateInput
onValueChange={setPeriodEndDate}
value={periodEndDate}
/>
<Button icon={<span>x</span>} onClick={() => setPeriodEndDate(null)} />
</Group>
</Gapped>
</Gapped>
</Gapped>
</RadioGroup>
</Gapped>
```

Календарю можно задать кастомную высоту с помощью переменной темы `calendarWrapperHeight`

- Базовая высота календаря - `330px`
Expand All @@ -167,52 +103,26 @@ const theme = React.useContext(ThemeContext);
</ThemeContext.Provider>
```

### Кастомный рендер дня
### Кастомизирование отображения даты

```jsx harmony
import { Tooltip, Hint } from '@skbkontur/react-ui';

const initialValue = "02.09.2023";
const [day, month, year] = initialValue.split('.').map(Number);

const [value, setValue] = React.useState(initialValue);

const renderDay = (date, defaultProps, RenderDefault) => {
const [dd, mm, yyyy] = date.split('.').map(Number);

if (mm === month && dd > 7 && dd < 11) {
return (
<Tooltip render={() => "Кастомный период"}>
<RenderDefault
{...defaultProps}
isDayInSelectedPeriod={true}
isPeriodStart={dd === 8}
isPeriodEnd={dd === 10}
/>
</Tooltip>
);
}
import MagicWand from '@skbkontur/react-icons/MagicWand';

if (mm === month && dd === 20) {
return (
<Hint text={date} pos="right middle">
<RenderDefault {...defaultProps}>
<b style={{color: 'orange'}}>#</b>
</RenderDefault>
</Hint>
);
}
const [value, setValue] = React.useState('12.05.2022');

const CustomDayItem = ({ date }) => {
const isEven = (num) => num % 2 === 0;

return <RenderDefault {...defaultProps} />
return (
<div>
{isEven(date.date) ? <MagicWand /> : date.date}
</div>
);
};

<Calendar
value={value}
onValueChange={setValue}
renderDay={renderDay}
onMonthSelect={(...args) => console.log('onMonthSelect', ...args)}
onStuckMonth={(...args) => console.log('onStuckMonth', ...args)}
/>;
const renderDay = (date) => <CustomDayItem date={date} />;

<Calendar value={value} onValueChange={setValue} renderDay={renderDay} />;
```

#### Локали по умолчанию
Expand Down
Loading

0 comments on commit 90b5e32

Please sign in to comment.