Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Boolean props to false values #6286

Merged
merged 6 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/vkui/src/components/ActionSheet/ActionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export const ActionSheet = ({
className={className}
style={style}
onClick={onClose}
hasMask
fixed
>
{actionSheet}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const AvatarPlayground = (props: ComponentPlaygroundProps) => {
fallbackIcon: [<IconExampleForFallbackBasedOnImageBaseSize key="icon-fallback" />],
},
{
withBorder: [undefined, false],
noBorder: [undefined, true],
},
{
gradientColor: [1, 2, 3, 5, 6, 'blue'],
Expand Down
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.
46 changes: 25 additions & 21 deletions packages/vkui/src/components/BaseGallery/BaseGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
children,
slideWidth = '100%',
slideIndex = 0,
isDraggable: isDraggableProp = true,
dragDisabled = false,

Check warning on line 45 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L45

Added line #L45 was not covered by tests
onDragStart,
onDragEnd,
onChange,
Expand Down Expand Up @@ -236,14 +236,18 @@
return targetIndex;
};

const isDraggable = !dragDisabled && !layoutState.current.isFullyVisible;

const onStart = (e: TouchEvent) => {
e.originalEvent.stopPropagation();
onDragStart?.(e);
setShiftState((prevState) => ({ ...prevState, animation: false }));
if (isDraggable) {
onDragStart?.(e);

Check warning on line 244 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L244

Added line #L244 was not covered by tests
setShiftState((prevState) => ({ ...prevState, animation: false }));
}
};

const onMoveX = (e: TouchEvent) => {
if (isDraggableProp && !layoutState.current.isFullyVisible) {
if (isDraggable) {
e.originalEvent.preventDefault();

if (e.isSlideX) {
Expand All @@ -259,24 +263,26 @@
};

const onEnd = (e: TouchEvent) => {
const targetIndex = e.isSlide ? getTarget(e) : slideIndex ?? 0;
onDragEnd?.(e, targetIndex);
if (isDraggable) {
const targetIndex = e.isSlide ? getTarget(e) : slideIndex ?? 0;
onDragEnd?.(e, targetIndex);

Check warning on line 268 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L267-L268

Added lines #L267 - L268 were not covered by tests

const nextShiftState: Partial<ShiftingState> = {
animation: true,
dragging: false,
deltaX: 0,
};
const nextShiftState: Partial<ShiftingState> = {

Check warning on line 270 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L270

Added line #L270 was not covered by tests
animation: true,
dragging: false,
deltaX: 0,
};

const shiftXStick = calculateDragIndent();
if (targetIndex !== slideIndex) {
// Сохраняем сдвиг слайда в том положении, в каком его оставили после драга (fix issue #2185)
nextShiftState.shiftX = shiftXStick;
}
const shiftXStick = calculateDragIndent();
if (targetIndex !== slideIndex) {

Check warning on line 277 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L276-L277

Added lines #L276 - L277 were not covered by tests
// Сохраняем сдвиг слайда в том положении, в каком его оставили после драга (fix issue #2185)
nextShiftState.shiftX = shiftXStick;

Check warning on line 279 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L279

Added line #L279 was not covered by tests
}

setShiftState((prevState) => ({ ...prevState, ...nextShiftState }));
if (targetIndex !== slideIndex) {
onChange?.(targetIndex);
setShiftState((prevState) => ({ ...prevState, ...nextShiftState }));
if (targetIndex !== slideIndex) {
onChange?.(targetIndex);

Check warning on line 284 in packages/vkui/src/components/BaseGallery/BaseGallery.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/BaseGallery.tsx#L282-L284

Added lines #L282 - L284 were not covered by tests
}
}
};

Expand Down Expand Up @@ -309,8 +315,6 @@
// otherwise we need to check current slide index (align = right or align = center)
(align !== 'left' && slideIndex < layoutState.current.slides.length - 1));

const isDraggable = isDraggableProp && !layoutState.current.isFullyVisible;

return (
<RootComponent
{...restProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
children,
slideWidth = '100%',
slideIndex = 0,
isDraggable: isDraggableProp = true,
dragDisabled = false,

Check warning on line 32 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L32

Added line #L32 was not covered by tests
onDragStart,
onDragEnd,
onChange,
Expand Down Expand Up @@ -159,7 +159,7 @@
setControlElementsState({
canSlideLeft: !slidesManager.current.isFullyVisible,
canSlideRight: !slidesManager.current.isFullyVisible,
isDraggable: isDraggableProp && !slidesManager.current.isFullyVisible,
isDraggable: !(dragDisabled || slidesManager.current.isFullyVisible),

Check warning on line 162 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L162

Added line #L162 was not covered by tests
});

shiftXCurrentRef.current = snaps[slideIndex];
Expand Down Expand Up @@ -266,13 +266,15 @@

const onStart = (e: TouchEvent) => {
e.originalEvent.stopPropagation();
onDragStart?.(e);
shiftXCurrentRef.current = slidesManager.current.snaps[slideIndex];
shiftXDeltaRef.current = 0;
if (controlElementsState.isDraggable) {
onDragStart?.(e);
shiftXCurrentRef.current = slidesManager.current.snaps[slideIndex];
shiftXDeltaRef.current = 0;

Check warning on line 272 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L269-L272

Added lines #L269 - L272 were not covered by tests
}
};

const onMoveX = (e: TouchEvent) => {
if (isDraggableProp && !slidesManager.current.isFullyVisible) {
if (controlElementsState.isDraggable) {

Check warning on line 277 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L277

Added line #L277 was not covered by tests
e.originalEvent.preventDefault();

if (e.isSlideX) {
Expand All @@ -285,23 +287,25 @@
};

const onEnd = (e: TouchEvent) => {
let targetIndex = slideIndex;
if (e.isSlide) {
targetIndex = getTargetIndex(
slidesManager.current.slides,
slideIndex,
shiftXCurrentRef.current,
shiftXDeltaRef.current,
);
}
onDragEnd?.(e, targetIndex);

if (targetIndex !== slideIndex) {
shiftXCurrentRef.current = shiftXCurrentRef.current + shiftXDeltaRef.current;
onChange?.(targetIndex);
} else {
const initialShiftX = slidesManager.current.snaps[targetIndex];
requestTransform(initialShiftX, true);
if (controlElementsState.isDraggable) {
let targetIndex = slideIndex;
if (e.isSlide) {
targetIndex = getTargetIndex(

Check warning on line 293 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L290-L293

Added lines #L290 - L293 were not covered by tests
slidesManager.current.slides,
slideIndex,
shiftXCurrentRef.current,
shiftXDeltaRef.current,
);
}
onDragEnd?.(e, targetIndex);

Check warning on line 300 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L300

Added line #L300 was not covered by tests

if (targetIndex !== slideIndex) {
shiftXCurrentRef.current = shiftXCurrentRef.current + shiftXDeltaRef.current;
onChange?.(targetIndex);
} else {
const initialShiftX = slidesManager.current.snaps[targetIndex];
requestTransform(initialShiftX, true);

Check warning on line 307 in packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/BaseGallery/CarouselBase/CarouselBase.tsx#L302-L307

Added lines #L302 - L307 were not covered by tests
}
}
};

Expand Down
5 changes: 4 additions & 1 deletion packages/vkui/src/components/BaseGallery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export interface BaseGalleryProps
*/
onNextClick?(event: React.MouseEvent): void;
bullets?: 'dark' | 'light' | false;
isDraggable?: boolean;
/**
* Позволяет отключить реагирование на тач-события
*/
dragDisabled?: boolean;
showArrows?: boolean;
hasPointer?: boolean;
arrowSize?: ScrollArrowProps['size'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from '@testing-library/react';
import { noop } from '@vkontakte/vkjs';
import { baselineComponent } from '../../testing/utils';
import { CalendarHeader } from './CalendarHeader';
import styles from './CalendarHeader.module.css';

describe('CalendarHeader', () => {
baselineComponent((props) => (
Expand All @@ -15,22 +16,36 @@ describe('CalendarHeader', () => {
/>
));

it('displays prev month button', () => {
it('displays prev month button by default', () => {
const viewDate = new Date('1970-01-01');
const onChange = jest.fn();
const { container } = render(
<CalendarHeader viewDate={viewDate} onChange={onChange} prevMonth />,
);
const { container } = render(<CalendarHeader viewDate={viewDate} onChange={onChange} />);

expect(
container.getElementsByClassName(styles['CalendarHeader__nav-icon-prev'])[0],
).toBeTruthy();
});
it('displays next month button by default', () => {
const viewDate = new Date('1970-01-01');
const onChange = jest.fn();
const { container } = render(<CalendarHeader viewDate={viewDate} onChange={onChange} />);

expect(container.getElementsByClassName('vkuiCalendarHeader__nav-icon-prev')[0]).toBeTruthy();
expect(
container.getElementsByClassName(styles['CalendarHeader__nav-icon-next'])[0],
).toBeTruthy();
});
it('displays next month button', () => {
it('do not display prev month and next month buttons if they hidden', () => {
const viewDate = new Date('1970-01-01');
const onChange = jest.fn();
const { container } = render(
<CalendarHeader viewDate={viewDate} onChange={onChange} nextMonth />,
<CalendarHeader viewDate={viewDate} onChange={onChange} prevMonthHidden nextMonthHidden />,
);

expect(container.getElementsByClassName('vkuiCalendarHeader__nav-icon-next')[0]).toBeTruthy();
expect(
container.getElementsByClassName(styles['CalendarHeader__nav-icon-prev'])[0],
).not.toBeTruthy();
expect(
container.getElementsByClassName(styles['CalendarHeader__nav-icon-next'])[0],
).not.toBeTruthy();
});
});
22 changes: 14 additions & 8 deletions packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ type ArrowMonthProps = Omit<React.AllHTMLAttributes<HTMLElement>, 'onClick' | 'a
export interface CalendarHeaderProps
extends Omit<HTMLAttributesWithRootRef<HTMLDivElement>, 'onChange'> {
viewDate: Date;
prevMonth?: boolean;
nextMonth?: boolean;
/**
* Скрывает иконку для переключения на предыдущий месяц
*/
prevMonthHidden?: boolean;
/**
* Скрывает иконку для переключения на следующий месяц
*/
nextMonthHidden?: boolean;
disablePickers?: boolean;
prevMonthLabel?: string;
nextMonthLabel?: string;
Expand All @@ -47,8 +53,8 @@ export interface CalendarHeaderProps
export const CalendarHeader = ({
viewDate,
onChange,
prevMonth = true,
nextMonth = true,
prevMonthHidden = false,
nextMonthHidden = false,
disablePickers = false,
onNextMonth,
onPrevMonth,
Expand Down Expand Up @@ -109,7 +115,7 @@ export const CalendarHeader = ({

return (
<RootComponent baseClassName={styles['CalendarHeader']} {...restProps}>
{prevMonth && (
{!prevMonthHidden && (
<AdaptivityProvider sizeX="regular">
<Tappable
className={classNames(
Expand Down Expand Up @@ -161,7 +167,7 @@ export const CalendarHeader = ({
value={viewDate.getMonth()}
options={months}
dropdownOffsetDistance={4}
fixDropdownWidth={false}
dropdownAutoWidth
icon={<Icon12Dropdown />}
onChange={onMonthsChange}
forceDropdownPortal={false}
Expand All @@ -176,7 +182,7 @@ export const CalendarHeader = ({
value={viewDate.getFullYear()}
options={years}
dropdownOffsetDistance={4}
fixDropdownWidth={false}
dropdownAutoWidth
icon={<Icon12Dropdown />}
onChange={onYearChange}
forceDropdownPortal={false}
Expand All @@ -186,7 +192,7 @@ export const CalendarHeader = ({
</div>
</AdaptivityProvider>
)}
{nextMonth && (
{!nextMonthHidden && (
<AdaptivityProvider sizeX="regular">
<Tappable
className={classNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const CalendarRange = ({
<CalendarHeader
viewDate={viewDate}
onChange={setViewDate}
nextMonth={false}
nextMonthHidden
onPrevMonth={setPrevMonth}
disablePickers={disablePickers}
className={styles['CalendarRange__header']}
Expand Down Expand Up @@ -221,7 +221,7 @@ export const CalendarRange = ({
<CalendarHeader
viewDate={secondViewDate}
onChange={setViewDate}
prevMonth={false}
prevMonthHidden
onNextMonth={setNextMonth}
disablePickers={disablePickers}
className={styles['CalendarRange__header']}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const CardScrollPlayground = (props: ComponentPlaygroundProps) => {
showArrows: [true, false, 'always'],
},
{
withSpaces: [true, false],
noSpaces: [false, true],
},
]}
>
Expand Down
Loading
Loading