mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
feat(web/dialog): Add option for left icon on input field
This commit is contained in:
@@ -13,9 +13,11 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Select,
|
Select,
|
||||||
|
InputLeftElement,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { IconProp } from "@fortawesome/fontawesome-svg-core";
|
||||||
import { useNuiEvent } from "../../hooks/useNuiEvent";
|
import { useNuiEvent } from "../../hooks/useNuiEvent";
|
||||||
import { useLocales } from "../../providers/LocaleProvider";
|
import { useLocales } from "../../providers/LocaleProvider";
|
||||||
import { debugData } from "../../utils/debugData";
|
import { debugData } from "../../utils/debugData";
|
||||||
@@ -30,6 +32,7 @@ interface Props {
|
|||||||
label: string;
|
label: string;
|
||||||
options?: { value: string; label: string }[];
|
options?: { value: string; label: string }[];
|
||||||
password?: boolean;
|
password?: boolean;
|
||||||
|
icon?: IconProp;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ debugData<Props>([
|
|||||||
rows: [
|
rows: [
|
||||||
{ type: "input", label: "Locker number" },
|
{ type: "input", label: "Locker number" },
|
||||||
{ type: "checkbox", label: "Some checkbox" },
|
{ type: "checkbox", label: "Some checkbox" },
|
||||||
{ type: "input", label: "Locker PIN", password: true },
|
{ type: "input", label: "Locker PIN", password: true, icon: "lock" },
|
||||||
{ type: "checkbox", label: "Some other checkbox" },
|
{ type: "checkbox", label: "Some other checkbox" },
|
||||||
{
|
{
|
||||||
type: "select",
|
type: "select",
|
||||||
@@ -63,15 +66,17 @@ const InputDialog: React.FC = () => {
|
|||||||
rows: [{ type: "input", label: "" }],
|
rows: [{ type: "input", label: "" }],
|
||||||
});
|
});
|
||||||
const [inputData, setInputData] = React.useState<Array<string | boolean>>([]);
|
const [inputData, setInputData] = React.useState<Array<string | boolean>>([]);
|
||||||
|
const [passwordStates, setPasswordStates] = React.useState<boolean[]>([]);
|
||||||
const [visible, setVisible] = React.useState(false);
|
const [visible, setVisible] = React.useState(false);
|
||||||
|
|
||||||
const { locale } = useLocales();
|
const { locale } = useLocales();
|
||||||
|
|
||||||
const [passwordStates, setPasswordStates] = React.useState<Array<boolean>>([]);
|
|
||||||
const handlePasswordStates = (index: number) => {
|
const handlePasswordStates = (index: number) => {
|
||||||
setPasswordStates({
|
setPasswordStates({
|
||||||
...passwordStates, [index]: !passwordStates[index]
|
...passwordStates,
|
||||||
})
|
[index]: !passwordStates[index],
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useNuiEvent<Props>("openDialog", (data) => {
|
useNuiEvent<Props>("openDialog", (data) => {
|
||||||
setPasswordStates([]);
|
setPasswordStates([]);
|
||||||
@@ -117,9 +122,19 @@ const InputDialog: React.FC = () => {
|
|||||||
<Box mb={3} key={`input-${index}`} textAlign="left">
|
<Box mb={3} key={`input-${index}`} textAlign="left">
|
||||||
<Text>{row.label}</Text>
|
<Text>{row.label}</Text>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
|
{row.icon && (
|
||||||
|
<InputLeftElement
|
||||||
|
pointerEvents="none"
|
||||||
|
children={<FontAwesomeIcon icon={row.icon} />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Input
|
<Input
|
||||||
onChange={(e) => handleChange(e.target.value, index)}
|
onChange={(e) => handleChange(e.target.value, index)}
|
||||||
type={!row.password || passwordStates[index] ? "text" : "password"}
|
type={
|
||||||
|
!row.password || passwordStates[index]
|
||||||
|
? "text"
|
||||||
|
: "password"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{row.password && (
|
{row.password && (
|
||||||
<InputRightElement
|
<InputRightElement
|
||||||
|
|||||||
Reference in New Issue
Block a user