Skip to content

Commit

Permalink
feat(plasma-new-hope): rename DatePicker folders
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanKuzmich committed Jun 28, 2024
1 parent 83e4430 commit 3b00441
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useMemo, forwardRef, HTMLAttributes } from 'react';
import React, { useState, useCallback, useMemo, forwardRef, HTMLAttributes, useEffect } from 'react';

import type { Calendar, DateObject } from '../Calendar.types';
import { getDateFromValue, getNextDate, getPrevDate, isValueUpdate } from '../utils';
Expand Down Expand Up @@ -129,6 +129,12 @@ export const calendarDoubleRoot = (Root: RootProps<HTMLDivElement, HTMLAttribute
setPrevValue(value);
}

useEffect(() => {
if (!prevValue) {
setPrevValue(value);
}
}, [value, prevValue]);

return (
<Root ref={outerRootRef} aria-label="Выбор даты" {...rest}>
<CalendarHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const StyledDayRoot = styled.div<DayProps & FocusProps>`
outlineSize: '0.063rem',
outlineOffset: '-0.1875rem',
outlineColor: `var(${tokens.calendarOutlineFocusColor})`,
outlineRadius: `calc(var(${tokens.calendarDayItemBorderRadius}) - 0.125rem)`,
outlineRadius: `calc(var(${tokens.calendarDayItemBorderRadius}) + 0.125rem)`,
})};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const StyledMonthRoot = styled.div`
outlineSize: '0.063rem',
outlineOffset: '-0.1875rem',
outlineColor: `var(${tokens.calendarOutlineFocusColor})`,
outlineRadius: `calc(var(${tokens.calendarMonthItemBorderRadius}) - 0.125rem)`,
outlineRadius: `calc(var(${tokens.calendarMonthItemBorderRadius}) + 0.125rem)`,
})};
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const StyledYearRoot = styled.div`
outlineSize: '0.063rem',
outlineOffset: '-0.1875rem',
outlineColor: `var(${tokens.calendarOutlineFocusColor})`,
outlineRadius: `calc(var(${tokens.calendarYearItemBorderRadius}) - 0.125rem)`,
outlineRadius: `calc(var(${tokens.calendarYearItemBorderRadius}) + 0.125rem)`,
})};
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { useDatePicker } from '../hooks/useDatePicker';
import type { RangeInputRefs } from '../../Range/Range.types';
import { classes } from '../DatePicker.tokens';

import type { DatePickerRangeProps } from './DatePicker.types';
import type { DatePickerRangeProps } from './RangeDate.types';
import { base as sizeCSS } from './variations/_size/base';
import { base as viewCSS } from './variations/_view/base';
import { base as disabledCSS } from './variations/_disabled/base';
import { base as readOnlyCSS } from './variations/_readonly/base';
import { LeftHelper, StyledLabel, StyledRange, base } from './DatePicker.styles';
import { LeftHelper, StyledLabel, StyledRange, base } from './RangeDate.styles';
import { RangeDatePopover } from './RangeDatePopover/RangeDatePopover';

export const datePickerRangeRoot = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CalendarStateType } from '../../Calendar';
import type { DisabledDay, EventDay } from '../../Calendar/Calendar.types';
import type { RangeInnerProps } from '../../Range/Range.types';
import type { DatePickerdVariationProps } from '../DatePickerBase.types';
import { DatePickerPopoverProps } from '../SingleDate/DatePicker.types';
import { DatePickerPopoverProps } from '../SingleDate/SingleDate.types';

export type DatePickerRangePlacement = 'top' | 'bottom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import { getPlacements } from '../../../../utils';
import { StyledPopover } from '../DatePicker.styles';
import { StyledPopover } from '../RangeDate.styles';

import type { RangeDatePopoverProps } from './RangeDatePopover.types';
import { StyledCalendar, StyledCalendarDouble } from './RangeDatePopover.styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactNode } from 'react';

import type { DatePickerCalendarProps, DatePickerPopoverProps } from '../../SingleDate/DatePicker.types';
import type { DatePickerCalendarProps, DatePickerPopoverProps } from '../../SingleDate/SingleDate.types';

export type RangeDatePopoverProps = DatePickerCalendarProps &
DatePickerPopoverProps & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@linaria/core';

import { tokens } from '../../../DatePicker.tokens';
import { LeftHelper, StyledLabel } from '../../DatePicker.styles';
import { LeftHelper, StyledLabel } from '../../RangeDate.styles';

export const base = css`
&[readonly] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@linaria/core';

import { tokens } from '../../../DatePicker.tokens';
import { StyledLabel, LeftHelper } from '../../DatePicker.styles';
import { StyledLabel, LeftHelper } from '../../RangeDate.styles';

export const base = css`
width: var(${tokens.width});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@linaria/core';

import { LeftHelper, StyledLabel } from '../../DatePicker.styles';
import { LeftHelper, StyledLabel } from '../../RangeDate.styles';
import { tokens } from '../../../DatePicker.tokens';

export const base = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { useDatePicker } from '../hooks/useDatePicker';
import { classes } from '../DatePicker.tokens';
import { StyledCalendar } from '../DatePickerBase.styles';

import type { DatePickerProps } from './DatePicker.types';
import type { DatePickerProps } from './SingleDate.types';
import { base as sizeCSS } from './variations/_size/base';
import { base as viewCSS } from './variations/_view/base';
import { base as disabledCSS } from './variations/_disabled/base';
import { base as readOnlyCSS } from './variations/_readonly/base';
import { LeftHelper, StyledInput, StyledLabel, StyledPopover, base } from './DatePicker.styles';
import { LeftHelper, StyledInput, StyledLabel, StyledPopover, base } from './SingleDate.styles';

export const datePickerRoot = (
Root: RootProps<HTMLDivElement, Omit<DatePickerProps, 'isOpen' | 'defaultValue' | 'onChangeValue'>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@linaria/core';

import { tokens } from '../../../DatePicker.tokens';
import { LeftHelper, StyledLabel } from '../../DatePicker.styles';
import { LeftHelper, StyledLabel } from '../../SingleDate.styles';

export const base = css`
&[readonly] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@linaria/core';

import { tokens } from '../../../DatePicker.tokens';
import { StyledLabel, LeftHelper } from '../../DatePicker.styles';
import { StyledLabel, LeftHelper } from '../../SingleDate.styles';

export const base = css`
width: var(${tokens.width});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@linaria/core';

import { LeftHelper, StyledLabel } from '../../DatePicker.styles';
import { LeftHelper, StyledLabel } from '../../SingleDate.styles';
import { tokens } from '../../../DatePicker.tokens';

export const base = css`
Expand Down
8 changes: 4 additions & 4 deletions packages/plasma-new-hope/src/components/DatePicker/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { datePickerRoot, datePickerConfig } from './SingleDate/DatePicker';
export type { DatePickerProps, DatePickerPlacementBasic, DatePickerPlacement } from './SingleDate/DatePicker.types';
export { datePickerRoot, datePickerConfig } from './SingleDate/SingleDate';
export type { DatePickerProps, DatePickerPlacementBasic, DatePickerPlacement } from './SingleDate/SingleDate.types';

export { datePickerRangeRoot, datePickerRangeConfig } from './RangeDate/DatePicker';
export type { DatePickerRangeProps, DatePickerRangePlacement } from './RangeDate/DatePicker.types';
export { datePickerRangeRoot, datePickerRangeConfig } from './RangeDate/RangeDate';
export type { DatePickerRangeProps, DatePickerRangePlacement } from './RangeDate/RangeDate.types';

export { classes as datePickerClasses, tokens as datePickerTokens } from './DatePicker.tokens';
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const StoryRange = ({
const rangeRef = useRef<RangeInputRefs>(null);

const [isOpen, setIsOpen] = useState(false);
const [firstDate, setFirstDate] = useState<string | Date>('');

const iconSize = size === 'xs' ? 'xs' : 's';
const showDividerIcon = dividerVariant === 'icon';
Expand Down Expand Up @@ -201,7 +202,12 @@ const StoryRange = ({
onChangeSecondValue={(e, currentValue) => {
onChangeSecondValue(e, currentValue);
}}
onCommitSecondDate={() => setIsOpen(false)}
onCommitFirstDate={(currentValue) => {
setFirstDate(currentValue);
}}
onCommitSecondDate={(currentValue) => {
firstDate && currentValue && setIsOpen(false);
}}
{...dividerIconProps}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const StoryRange = ({
const rangeRef = useRef<RangeInputRefs>(null);

const [isOpen, setIsOpen] = useState(false);
const [firstDate, setFirstDate] = useState<string | Date>('');

const iconSize = size === 'xs' ? 'xs' : 's';
const showDividerIcon = dividerVariant === 'icon';
Expand Down Expand Up @@ -201,7 +202,12 @@ const StoryRange = ({
onChangeSecondValue={(e, currentValue) => {
onChangeSecondValue(e, currentValue);
}}
onCommitSecondDate={() => setIsOpen(false)}
onCommitFirstDate={(currentValue) => {
setFirstDate(currentValue);
}}
onCommitSecondDate={(currentValue) => {
firstDate && currentValue && setIsOpen(false);
}}
{...dividerIconProps}
{...rest}
/>
Expand Down

0 comments on commit 3b00441

Please sign in to comment.