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

fix: changed import style to fix missing api table #296

Merged
merged 3 commits into from
Jan 4, 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
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module.exports = {
rules: {
"react/prop-types": "off",
"@washingtonpost/wpds/theme-colors": "warn",
"no-restricted-syntax": [
"error",
{
selector:
"ImportDeclaration[source.value='react'][specifiers.0.type='ImportDefaultSpecifier']",
message: "Default React import not allowed",
},
],
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion build.washingtonpost.com/pages/working-examples/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import * as React from "react";
import { useState } from "react";
import { useForm, Controller } from "react-hook-form";
import { isPossiblePhoneNumber } from "react-phone-number-input";
import {
Expand Down
8 changes: 4 additions & 4 deletions ui/input-text/src/InputText.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from "react";
import * as React from "react";
import { useEffect, useState } from "react";
import { nanoid } from "nanoid";
import { theme, styled } from "@washingtonpost/wpds-theme";
import { Button } from "@washingtonpost/wpds-button";
Expand Down Expand Up @@ -139,8 +140,6 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(
},
ref
) => {
globalInputAutoFillTriggerAnimations();

const [helperId, setHelperId] = useState<string | undefined>();
const [errorId, setErrorId] = useState<string | undefined>();
const [isAutofilled, setIsAutofilled] = useState<boolean>(false);
Expand All @@ -163,6 +162,7 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(
}, [ref, internalRef]);

useEffect(() => {
globalInputAutoFillTriggerAnimations();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to the API table, but this code was being called every render. Just once in the use effect is all that's strictly necessary.

const element = internalRef.current;

const onAnimationStart = (e) => {
Expand All @@ -179,7 +179,7 @@ export const InputText = React.forwardRef<HTMLInputElement, InputTextProps>(
return () => {
element?.removeEventListener("animationstart", onAnimationStart, false);
};
});
}, []);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the empty array ensures that this only gets called once on the initial render.


const [isFloating, handleOnFocus, handleOnBlur, handleOnChange] =
useFloating(
Expand Down
9 changes: 3 additions & 6 deletions ui/input-textarea/src/InputTextarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import { useEffect, useState } from "react";
import { nanoid } from "nanoid";
import { theme, css, styled } from "@washingtonpost/wpds-theme";
import type * as WPDS from "@washingtonpost/wpds-theme";
Expand All @@ -12,8 +13,6 @@ import { InputLabel } from "@washingtonpost/wpds-input-label";
import { ErrorMessage } from "@washingtonpost/wpds-error-message";
import { HelperText } from "@washingtonpost/wpds-helper-text";

import { useEffect, useState } from "react";

const NAME = "InputTextarea";

const InputTextareaCSS = css({
Expand Down Expand Up @@ -122,8 +121,6 @@ export const InputTextarea = React.forwardRef<
},
ref
) => {
globalInputAutoFillTriggerAnimations();

const [helperId, setHelperId] = useState<string | undefined>();
const [errorId, setErrorId] = useState<string | undefined>();
const [isAutofilled, setIsAutofilled] = useState<boolean>(false);
Expand All @@ -147,10 +144,10 @@ export const InputTextarea = React.forwardRef<
}, [ref, internalRef]);

useEffect(() => {
globalInputAutoFillTriggerAnimations();
const element = internalRef.current;

const onAnimationStart = (e) => {
console.log(e.animationName);
switch (e.animationName) {
case "jsTriggerAutoFillStart":
return setIsAutofilled(true);
Expand All @@ -164,7 +161,7 @@ export const InputTextarea = React.forwardRef<
return () => {
element?.removeEventListener("animationstart", onAnimationStart, false);
};
});
}, []);

const [isFloating, handleFocus, handleBlur, handleChange] = useFloating(
value || defaultValue || placeholder || isAutofilled,
Expand Down