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

Remove withAdaptivity #2601

Merged
merged 22 commits into from
Jun 2, 2022
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
2 changes: 1 addition & 1 deletion src/components/ActionSheet/ActionSheet.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { ActionSheet, ActionSheetProps } from "./ActionSheet";
import { ActionSheetItem } from "../ActionSheetItem/ActionSheetItem";
import { describeScreenshotFuzz } from "../../testing/e2e/utils";
import { withPlatform } from "../../hoc/withPlatform";
import { ViewWidth, SizeType } from "../../hoc/withAdaptivity";
import { HasPlatform } from "../../types";
import { VKCOM } from "../../lib/platform";
import { TooltipContainer } from "../Tooltip/TooltipContainer";
import { ViewWidth, SizeType } from "../AdaptivityProvider/AdaptivityContext";

describe("ActionSheet", () => {
const cancel = <ActionSheetItem mode="cancel">Отменить</ActionSheetItem>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ActionSheet/ActionSheet.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from "@testing-library/react";
import { ViewWidth } from "../../hoc/withAdaptivity";
import { ViewWidth } from "../AdaptivityProvider/AdaptivityContext";
import {
baselineComponent,
waitForPopper,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Alert/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { AdaptivityProvider } from "../AdaptivityProvider/AdaptivityProvider";
import { ViewWidth } from "../../hoc/withAdaptivity";
import { ViewWidth } from "../AdaptivityProvider/AdaptivityContext";
import { baselineComponent, runAllTimers } from "../../testing/utils";
import { Alert } from "./Alert";
import { ANDROID, IOS } from "../../lib/platform";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PopoutWrapper } from "../PopoutWrapper/PopoutWrapper";
import { getClassName } from "../../helpers/getClassName";
import { classNames } from "../../lib/classNames";
import { ANDROID, VKCOM, IOS } from "../../lib/platform";
import { ViewWidth } from "../../hoc/withAdaptivity";
import { Button, ButtonProps } from "../Button/Button";
import { hasReactNode, stopPropagation } from "../../lib/utils";
import { Headline } from "../Typography/Headline/Headline";
Expand All @@ -16,6 +15,7 @@ import { useScrollLock } from "../AppRoot/ScrollContext";
import { useWaitTransitionFinish } from "../../hooks/useWaitTransitionFinish";
import { usePlatform } from "../../hooks/usePlatform";
import { useAdaptivity } from "../../hooks/useAdaptivity";
import { ViewWidth } from "../AdaptivityProvider/AdaptivityContext";
import "./Alert.css";

export type AlertActionInterface = AlertAction &
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppRoot/AppRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from "@testing-library/react";
import { baselineComponent } from "../../testing/utils";
import { AppRootContext } from "./AppRootContext";
import { AppRoot } from "./AppRoot";
import { SizeType } from "../../hoc/withAdaptivity";
import { SizeType } from "../AdaptivityProvider/AdaptivityContext";
import { AdaptivityProvider } from "../../components/AdaptivityProvider/AdaptivityProvider";

describe("AppRoot", () => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/Banner/Banner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { screen, render } from "@testing-library/react";
import { AdaptivityProps } from "../../hoc/withAdaptivity";
import {
AdaptivityProps,
SizeType,
} from "../AdaptivityProvider/AdaptivityContext";
import { baselineComponent } from "../../testing/utils";
import { SizeType } from "../AdaptivityProvider/AdaptivityContext";
import { AdaptivityProvider } from "../AdaptivityProvider/AdaptivityProvider";
import Banner, { BannerProps } from "./Banner";

Expand Down
2 changes: 1 addition & 1 deletion src/components/CalendarHeader/CalendarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Tappable from "../Tappable/Tappable";
import { classNames } from "../../lib/classNames";
import { SelectType } from "../Select/Select";
import { CustomSelect } from "../CustomSelect/CustomSelect";
import { SizeType } from "../../hoc/withAdaptivity";
import { SizeType } from "../AdaptivityProvider/AdaptivityContext";
import { getMonths, getYears } from "../../lib/calendar";
import { LocaleProviderContext } from "../LocaleProviderContext/LocaleProviderContext";
import { Paragraph } from "../Typography/Paragraph/Paragraph";
Expand Down
2 changes: 1 addition & 1 deletion src/components/CalendarTime/CalendarTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { setHours, setMinutes } from "../../lib/date";
import { CustomSelect } from "../CustomSelect/CustomSelect";
import { Button } from "../Button/Button";
import { SizeType } from "../../hoc/withAdaptivity";
import { SizeType } from "../AdaptivityProvider/AdaptivityContext";
import { AdaptivityProvider } from "../AdaptivityProvider/AdaptivityProvider";
import "./CalendarTime.css";

Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomSelect/CustomSelect.e2e.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describeScreenshotFuzz } from "../../testing/e2e/utils";
import { CustomSelect, CustomSelectProps } from "../CustomSelect/CustomSelect";
import { CustomSelect, SelectProps } from "../CustomSelect/CustomSelect";
import { SelectType } from "../Select/Select";

describe("CustomSelect", () => {
describeScreenshotFuzz(
(props: CustomSelectProps) => (
(props: SelectProps) => (
<CustomSelect
placeholder="Не выбрана"
{...props}
Expand Down
14 changes: 7 additions & 7 deletions src/components/CustomSelect/CustomSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface CustomSelectState {
popperPlacement?: Placement;
}

export interface CustomSelectProps
export interface SelectProps
extends NativeSelectProps,
HasPlatform,
FormFieldProps {
Expand Down Expand Up @@ -151,10 +151,10 @@ export interface CustomSelectProps
type MouseEventHandler = (event: React.MouseEvent<HTMLElement>) => void;

class CustomSelectComponent extends React.Component<
CustomSelectProps,
SelectProps,
CustomSelectState
> {
static defaultProps: Partial<CustomSelectProps> = {
static defaultProps: Partial<SelectProps> = {
searchable: false,
renderOption({ option, ...props }): React.ReactNode {
return <CustomSelectOption {...props} />;
Expand All @@ -167,7 +167,7 @@ class CustomSelectComponent extends React.Component<
fixDropdownWidth: true,
};

public constructor(props: CustomSelectProps) {
public constructor(props: SelectProps) {
super(props);

const { value, defaultValue } = props;
Expand Down Expand Up @@ -221,9 +221,9 @@ class CustomSelectComponent extends React.Component<
}

filter = (
options: CustomSelectProps["options"],
options: SelectProps["options"],
inputValue: string,
filterFn: CustomSelectProps["filterFn"]
filterFn: SelectProps["filterFn"]
) => {
return typeof filterFn === "function"
? options.filter((option) => filterFn(inputValue, option))
Expand Down Expand Up @@ -543,7 +543,7 @@ class CustomSelectComponent extends React.Component<

handleKeyUp = debounce(this.resetKeyboardInput, 1000);

componentDidUpdate(prevProps: CustomSelectProps) {
componentDidUpdate(prevProps: SelectProps) {
// Внутри useEffect и так is, можно убрать
if (
!is(prevProps.value, this.props.value) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomSelectOption } from "./CustomSelectOption";
import { describeScreenshotFuzz } from "../../testing/e2e/utils";
import Avatar from "../Avatar/Avatar";
import { SizeType } from "../../hoc/withAdaptivity";
import { SizeType } from "../AdaptivityProvider/AdaptivityContext";

describe("CustomSelectOption", () => {
describeScreenshotFuzz(
Expand Down
18 changes: 5 additions & 13 deletions src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Input } from "../Input/Input";
import { withAdaptivity, AdaptivityProps } from "../../hoc/withAdaptivity";
import { useAdaptivity } from "../../hooks/useAdaptivity";
import { HasPlatform } from "../../types";
import { leadingZero } from "../../lib/utils";
import { CustomSelect } from "../CustomSelect/CustomSelect";
Expand Down Expand Up @@ -32,8 +32,7 @@ export interface DatePickerProps
React.HTMLAttributes<HTMLDivElement>,
"defaultValue" | "min" | "max"
>,
HasPlatform,
AdaptivityProps {
HasPlatform {
min?: DatePickerDateFormat;
max?: DatePickerDateFormat;
name?: string;
Expand Down Expand Up @@ -91,7 +90,6 @@ const DatePickerCustom: React.FC<
yearPlaceholder,
popupDirection,
defaultValue,
hasMouse,
monthNames,
day = 0,
month = 0,
Expand Down Expand Up @@ -177,7 +175,6 @@ const DatePickerNative: React.FC<
yearPlaceholder,
popupDirection,
defaultValue,
hasMouse,
day,
month,
year,
Expand Down Expand Up @@ -210,11 +207,8 @@ const DatePickerNative: React.FC<
/**
* @see https://vkcom.github.io/VKUI/#/DatePicker
*/
const DatePicker: React.FC<DatePickerProps> = ({
hasMouse,
defaultValue,
...props
}) => {
const DatePicker: React.FC<DatePickerProps> = ({ defaultValue, ...props }) => {
const { hasMouse } = useAdaptivity();
const [value, setValue] = React.useState<Partial<DatePickerDateFormat>>(
() => ({
day: defaultValue?.day || 0,
Expand All @@ -236,6 +230,4 @@ const DatePicker: React.FC<DatePickerProps> = ({
};

// eslint-disable-next-line import/no-default-export
export default withAdaptivity(DatePicker, {
hasMouse: true,
});
export default DatePicker;
2 changes: 1 addition & 1 deletion src/components/Epic/Epic.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop } from "../../lib/utils";
import { baselineComponent } from "../../testing/utils";
import Epic from "./Epic";
import { Epic } from "./Epic";

describe("Epic", () => {
beforeAll(() => {
Expand Down
23 changes: 6 additions & 17 deletions src/components/Epic/Epic.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import * as React from "react";
import { getClassName } from "../../helpers/getClassName";
import { usePlatform } from "../../hooks/usePlatform";
import { withAdaptivity, ViewWidth } from "../../hoc/withAdaptivity";
import { useAdaptivity } from "../../hooks/useAdaptivity";
import { ScrollSaver } from "./ScrollSaver";
import { getNavId } from "../../lib/getNavId";
import { warnOnce } from "../../lib/warnOnce";
import {
AdaptivityContextInterface,
AdaptivityProps,
} from "../AdaptivityProvider/AdaptivityContext";
import { ViewWidth } from "../AdaptivityProvider/AdaptivityContext";
import "./Epic.css";

export interface EpicProps
extends React.HTMLAttributes<HTMLDivElement>,
AdaptivityProps {
export interface EpicProps extends React.HTMLAttributes<HTMLDivElement> {
tabbar?: React.ReactNode;
activeStory: string;
}
Expand All @@ -23,12 +18,11 @@ const warn = warnOnce("Epic");
/**
* @see https://vkcom.github.io/VKUI/#/Epic
*/
export const Epic: React.FC<EpicProps & AdaptivityContextInterface> = (
props
) => {
export const Epic: React.FC<EpicProps> = (props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Заметил, что сейчас в файлик сразу и именованный экспорт, и экспорт по умолчанию

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оставил только именованный

const platform = usePlatform();
const { viewWidth } = useAdaptivity();
const scroll = React.useRef<{ [key: string]: number }>({}).current;
const { activeStory, tabbar, children, viewWidth, ...restProps } = props;
const { activeStory, tabbar, children, ...restProps } = props;

if (
process.env.NODE_ENV === "development" &&
Expand Down Expand Up @@ -59,8 +53,3 @@ export const Epic: React.FC<EpicProps & AdaptivityContextInterface> = (
</div>
);
};

// eslint-disable-next-line import/no-default-export
export default withAdaptivity(Epic, {
viewWidth: true,
});
Loading