Skip to content

Commit

Permalink
refactor: run eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
vyductan committed Aug 22, 2024
1 parent 1980866 commit c651032
Show file tree
Hide file tree
Showing 81 changed files with 13,466 additions and 496 deletions.
2 changes: 1 addition & 1 deletion @acme/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"prettier": "@acme/prettier-config",
"dependencies": {
"@tanstack/react-router": "^1.48.1"
"@tanstack/react-router": "^1.49.1"
},
"devDependencies": {
"@acme/eslint-config": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions @acme/hooks/src/next/useNavigate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { useRouter } from "next/navigation";

export const useNavigate = <
TDefaultFrom extends string = string,
>(_defaultOpts?: {
>(_defaultOptions?: {
from?: RegisteredRouter["routeTree"];
// from?: RoutePathsAutoComplete<RegisteredRouter["routeTree"], TDefaultFrom>;
//
}): UseNavigateResult<TDefaultFrom> => {
const router = useRouter();
const navigate: UseNavigateResult<TDefaultFrom> = async (params) => {
const href = params.to;
const navigate: UseNavigateResult<TDefaultFrom> = async (parameters) => {
const href = parameters.to;
if (href) router.push(href);
};
return navigate;
Expand Down
8 changes: 4 additions & 4 deletions @acme/hooks/src/use-resize-observer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export function useResizeObserver<T extends HTMLElement = HTMLElement>() {

const observer = useMemo(
() =>
typeof window !== "undefined"
? new ResizeObserver((entries) => {
typeof window === "undefined"
? null
: new ResizeObserver((entries) => {
const entry = entries[0];

if (entry) {
Expand All @@ -34,8 +35,7 @@ export function useResizeObserver<T extends HTMLElement = HTMLElement>() {
}
});
}
})
: null,
}),
[],
);

Expand Down
2 changes: 1 addition & 1 deletion @acme/hooks/src/useResponsive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useEffect, useState } from "react";
import { theme } from "tailwindcss/defaultConfig";

import isBrowser from "../utils/isBrowser";
import isBrowser from "../utils/is-browser";

type Subscriber = () => void;

Expand Down
5 changes: 5 additions & 0 deletions @acme/hooks/src/utils/is-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// May 16, 2022
const isBrowser =
typeof window !== "undefined" && !!window.document.createElement;

export default isBrowser;
6 changes: 4 additions & 2 deletions @acme/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
"dev": "tsc",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"trace": "tsc --generateTrace .",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"prettier": "@acme/prettier-config",
"dependencies": {
"@acme/hooks": "workspace:*",
"@acme/utils": "workspace:*",
"@hookform/resolvers": "^3.9.0",
"@iconify/json": "^2.2.238",
"@iconify/json": "^2.2.239",
"@lexical/react": "^0.17.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
Expand All @@ -53,11 +54,12 @@
"@radix-ui/react-tooltip": "^1.1.2",
"@rc-component/mini-decimal": "^1.1.0",
"@tanstack/react-table": "^8.20.1",
"@typescript/analyze-trace": "^0.10.1",
"ahooks": "^3.8.1",
"class-variance-authority": "^0.7.0",
"cmdk": "^1.0.0",
"date-fns": "^3.6.0",
"embla-carousel-react": "^8.1.8",
"embla-carousel-react": "^8.2.0",
"framer-motion": "^11.3.28",
"lexical": "^0.17.0",
"next-themes": "^0.3.0",
Expand Down
6 changes: 3 additions & 3 deletions @acme/ui/src/_util/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export function triggerNativeEventFor<T>(
element: T,
{
event,
...valueObj
...valueObject
}: { event: keyof HTMLElementEventMap; [key: string]: string },
) {
if (!(element instanceof Element)) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Expected an Element but received ${element} instead!`);
throw new TypeError(`Expected an Element but received ${element} instead!`);
}

const [prop, value] = Object.entries(valueObj)[0] ?? [];
const [prop, value] = Object.entries(valueObject)[0] ?? [];

const prototype = Object.getPrototypeOf(element);
const desc = Object.getOwnPropertyDescriptor(prototype, prop!);
Expand Down
26 changes: 13 additions & 13 deletions @acme/ui/src/_util/wave/WaveEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { render, unmount } from "rc-util/lib/React/render";
import type { ShowWaveEffect, WaveAllowedComponent } from "./interface";
import { getTargetWaveColor, isNotGrey } from "./util";

function validateNum(value: number) {
function validateNumber(value: number) {
return Number.isNaN(value) ? 0 : value;
}

Expand Down Expand Up @@ -52,10 +52,10 @@ const WaveEffect: React.FC<WaveEffectProps> = (props) => {
// Rect
const { borderLeftWidth, borderTopWidth } = nodeStyle;
setLeft(
isStatic ? target.offsetLeft : validateNum(-parseFloat(borderLeftWidth)),
isStatic ? target.offsetLeft : validateNumber(-Number.parseFloat(borderLeftWidth)),
);
setTop(
isStatic ? target.offsetTop : validateNum(-parseFloat(borderTopWidth)),
isStatic ? target.offsetTop : validateNumber(-Number.parseFloat(borderTopWidth)),
);
setWidth(target.offsetWidth);
setHeight(target.offsetHeight);
Expand All @@ -74,7 +74,7 @@ const WaveEffect: React.FC<WaveEffectProps> = (props) => {
borderTopRightRadius,
borderBottomRightRadius,
borderBottomLeftRadius,
].map((radius) => validateNum(parseFloat(radius))),
].map((radius) => validateNumber(Number.parseFloat(radius))),
);
}

Expand Down Expand Up @@ -128,25 +128,25 @@ const WaveEffect: React.FC<WaveEffectProps> = (props) => {
position: "absolute",
boxShadow: "0 0 0 6px " + color,
opacity: 0,
transition: !isSmallComponent
transition: isSmallComponent
? {
boxShadow: {
ease: easeOutCirc,
duration: 0.4,
ease: easeInOut,
duration: 0.3,
},
opacity: {
ease: easeOutCirc,
duration: 2,
ease: easeInOut,
duration: 0.35,
},
}
: {
boxShadow: {
ease: easeInOut,
duration: 0.3,
ease: easeOutCirc,
duration: 0.4,
},
opacity: {
ease: easeInOut,
duration: 0.35,
ease: easeOutCirc,
duration: 2,
},
},
}}
Expand Down
2 changes: 1 addition & 1 deletion @acme/ui/src/alert/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Alert";
export * from "./alert";
6 changes: 4 additions & 2 deletions @acme/ui/src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { IconProps } from "../icons";
import { clsm } from "..";
import Wave from "../_util/wave";
import { GenericSlot } from "../slot";
import { LoadingIcon } from "./LoadingIcon";
import { LoadingIcon } from "./loading-icon";

const buttonVariants = cva(
[
Expand Down Expand Up @@ -284,7 +284,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
buttonVariants({
color,
disabled,
primary: !primary && !!variant ? null : !primary ? true : primary,
primary: !primary && !!variant ? undefined : (primary ?? true),
size,
shape: (icon && !children) || srOnly ? (shape ?? "icon") : shape,
// shape:
Expand Down Expand Up @@ -314,3 +314,5 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
Button.displayName = "Button";

export { Button, buttonVariants };

export { LoadingIcon } from "./loading-icon";
6 changes: 4 additions & 2 deletions @acme/ui/src/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "./Button";
export * from "./LoadingIcon";
export type { ButtonProps } from "./button";

export { Button, buttonVariants } from "./button";
export { LoadingIcon } from "./loading-icon";
61 changes: 61 additions & 0 deletions @acme/ui/src/button/loading-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { clsm } from "..";

export const LoadingIcon = ({
className,
...props
}: React.SVGProps<SVGSVGElement>) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 24 24"
className={clsm("animate-spin", className)}
{...props}
>
<defs>
<linearGradient
id="mingcuteLoadingFill0"
x1="50%"
x2="50%"
y1="5.271%"
y2="91.793%"
>
<stop offset="0%" stopColor="currentColor"></stop>
<stop
offset="100%"
stopColor="currentColor"
stopOpacity={0.55}
></stop>
</linearGradient>
<linearGradient
id="mingcuteLoadingFill1"
x1="50%"
x2="50%"
y1="15.24%"
y2="87.15%"
>
<stop offset="0%" stopColor="currentColor" stopOpacity={0}></stop>
<stop
offset="100%"
stopColor="currentColor"
stopOpacity={0.55}
></stop>
</linearGradient>
</defs>
<g fill="none">
<path d="M24 0v24H0V0zM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427c-.002-.01-.009-.017-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093c.012.004.023 0 .029-.008l.004-.014l-.034-.614c-.003-.012-.01-.02-.02-.022m-.715.002a.023.023 0 0 0-.027.006l-.006.014l-.034.614c0 .012.007.02.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z"></path>
<path
fill="url(#mingcuteLoadingFill0)"
d="M8.749.021a1.5 1.5 0 0 1 .497 2.958A7.502 7.502 0 0 0 3 10.375a7.5 7.5 0 0 0 7.5 7.5v3c-5.799 0-10.5-4.7-10.5-10.5C0 5.23 3.726.865 8.749.021"
transform="translate(1.5 1.625)"
></path>
<path
fill="url(#mingcuteLoadingFill1)"
d="M15.392 2.673a1.5 1.5 0 0 1 2.119-.115A10.475 10.475 0 0 1 21 10.375c0 5.8-4.701 10.5-10.5 10.5v-3a7.5 7.5 0 0 0 5.007-13.084a1.5 1.5 0 0 1-.115-2.118"
transform="translate(1.5 1.625)"
></path>
</g>
</svg>
);
};
4 changes: 2 additions & 2 deletions @acme/ui/src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CardProps = CardRootProps & {
};
const Card = ({
classNames,
bordered,
bordered = true,
className,
title,
description,
Expand All @@ -34,7 +34,7 @@ const Card = ({
}: CardProps) => {
return (
<CardRoot
className={clsm(!bordered ? "border-none" : "", className)}
className={clsm(bordered ? "" : "border-none", className)}
{...props}
>
{(!!title || !!description) && (
Expand Down
2 changes: 1 addition & 1 deletion @acme/ui/src/card/_components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CardRoot = React.forwardRef<HTMLDivElement, CardRootProps>(
<div
ref={ref}
className={clsm(
"rounded-lg border bg-card text-card-foreground shadow-sm",
"text-card-foreground rounded-lg border bg-surface shadow-sm",
className,
)}
{...props}
Expand Down
4 changes: 2 additions & 2 deletions @acme/ui/src/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const Checkbox = React.forwardRef<
checked={
indeterminate
? "indeterminate"
: typeof props.value === "boolean"
: (typeof props.value === "boolean"
? props.value
: checked
: checked)
}
defaultChecked={indeterminate ? "indeterminate" : defaultChecked}
className={clsm(
Expand Down
2 changes: 1 addition & 1 deletion @acme/ui/src/command/Command.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { clsm } from "@acme/ui";

import type { ValueType } from "../form";
import type { ValueType } from "../form/types";
import type { Option } from "../select/types";
import type { CommandRootProps } from "./_components";
import { Icon } from "../icons";
Expand Down
30 changes: 14 additions & 16 deletions @acme/ui/src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ const DatePickerInternal = (
) => {
const [open, setOpen] = React.useState(false);
const [month, setMonth] = React.useState<Date | undefined>(
defaultValue !== undefined
? isValid(defaultValue)
? defaultValue
: new Date()
: isValid(value)
defaultValue === undefined
? (isValid(value)
? value
: new Date(),
: new Date())
: (isValid(defaultValue)
? defaultValue
: new Date()),
);

const inputId = React.useId();

// ====================== Value =======================
const preValue =
defaultValue !== undefined
? isValid(defaultValue)
? formatDate(defaultValue, format)
: ""
: isValid(value)
defaultValue === undefined
? (isValid(value)
? formatDate(value!, format)
: "";
: "")
: (isValid(defaultValue)
? formatDate(defaultValue, format)
: "");
const [inputValue, setInputValue] = useMergedState(preValue);

// set input value if date value change
Expand Down Expand Up @@ -103,16 +103,14 @@ const DatePickerInternal = (

useClickAway(
(e) => {
if (isFocused) {
// check if choose a day in panel or not
if (!(e.target && "name" in e.target && e.target.name === "day")) {
if (isFocused && // check if choose a day in panel or not
!(e.target && "name" in e.target && e.target.name === "day")) {
if (inputValue.length === 10) {
handleChange(inputValue);
} else {
setInputValue(preValue);
}
}
}
},
() => document.getElementById(inputId),
);
Expand Down
Loading

0 comments on commit c651032

Please sign in to comment.