feat: prettier
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
.number-input {
|
||||
width: rem(50);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {ActionIcon, Flex, NumberInput, rem} from "@mantine/core";
|
||||
import {IconMinus, IconPlus} from "@tabler/icons-react";
|
||||
import styles from './PlusMinusInput.module.css';
|
||||
import {FC, useEffect, useState} from "react";
|
||||
import { ActionIcon, Flex, NumberInput, rem } from "@mantine/core";
|
||||
import { IconMinus, IconPlus } from "@tabler/icons-react";
|
||||
import styles from "./PlusMinusInput.module.css";
|
||||
import { FC, useEffect, useState } from "react";
|
||||
|
||||
type ControlledValueProps = {
|
||||
value: number;
|
||||
onChange: (value: number) => void;
|
||||
}
|
||||
};
|
||||
|
||||
type RestProps = {
|
||||
defaultValue?: number;
|
||||
onChange: (value: number) => void;
|
||||
}
|
||||
};
|
||||
|
||||
type Props = RestProps & Partial<ControlledValueProps>;
|
||||
|
||||
@@ -22,7 +22,6 @@ const PlusMinusInput: FC<Props> = (props: Props) => {
|
||||
const value = isControlled ? props.value : internalValue;
|
||||
|
||||
const onMinusClick = () => {
|
||||
|
||||
const newValue = (value || 0) - 1;
|
||||
if (newValue < 0) {
|
||||
return;
|
||||
@@ -32,7 +31,7 @@ const PlusMinusInput: FC<Props> = (props: Props) => {
|
||||
} else {
|
||||
setInternalValue(newValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onPlusClick = () => {
|
||||
const newValue = (value || 0) + 1;
|
||||
@@ -41,7 +40,7 @@ const PlusMinusInput: FC<Props> = (props: Props) => {
|
||||
} else {
|
||||
setInternalValue(newValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (event: number | string) => {
|
||||
let newValue = typeof event === "string" ? 0 : event;
|
||||
@@ -53,7 +52,7 @@ const PlusMinusInput: FC<Props> = (props: Props) => {
|
||||
} else {
|
||||
setInternalValue(newValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isControlled) {
|
||||
@@ -64,34 +63,33 @@ const PlusMinusInput: FC<Props> = (props: Props) => {
|
||||
return (
|
||||
<Flex
|
||||
align={"center"}
|
||||
gap={rem(10)}
|
||||
>
|
||||
gap={rem(10)}>
|
||||
<ActionIcon
|
||||
disabled={value === 0}
|
||||
onClick={onMinusClick}
|
||||
variant={"default"}>
|
||||
<IconMinus/>
|
||||
<IconMinus />
|
||||
</ActionIcon>
|
||||
<NumberInput
|
||||
min={0}
|
||||
styles={{
|
||||
input: {
|
||||
textAlign: "center"
|
||||
}
|
||||
textAlign: "center",
|
||||
},
|
||||
}}
|
||||
allowNegative={false}
|
||||
hideControls
|
||||
value={value}
|
||||
className={styles['number-input']}
|
||||
onChange={(event) => handleInputChange(event)}
|
||||
className={styles["number-input"]}
|
||||
onChange={event => handleInputChange(event)}
|
||||
/>
|
||||
<ActionIcon
|
||||
onClick={onPlusClick}
|
||||
variant={"default"}>
|
||||
<IconPlus/>
|
||||
<IconPlus />
|
||||
</ActionIcon>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default PlusMinusInput;
|
||||
export default PlusMinusInput;
|
||||
|
||||
Reference in New Issue
Block a user