mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(web/input): description tooltip on fields
This commit is contained in:
@@ -14,6 +14,7 @@ interface InputDialogRowProps {
|
|||||||
min?: number;
|
min?: number;
|
||||||
max?: number;
|
max?: number;
|
||||||
step?: number;
|
step?: number;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type inputDialog = (
|
type inputDialog = (
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ local input
|
|||||||
---@field min? number
|
---@field min? number
|
||||||
---@field max? number
|
---@field max? number
|
||||||
---@field step? number
|
---@field step? number
|
||||||
|
---@field description? string
|
||||||
|
|
||||||
---@param heading string
|
---@param heading string
|
||||||
---@param rows string[] | InputDialogRowProps[]
|
---@param rows string[] | InputDialogRowProps[]
|
||||||
@@ -57,4 +58,4 @@ RegisterNUICallback('inputData', function(data, cb)
|
|||||||
local promise = input
|
local promise = input
|
||||||
input = nil
|
input = nil
|
||||||
promise:resolve(data)
|
promise:resolve(data)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ export const debugInput = () => {
|
|||||||
data: {
|
data: {
|
||||||
heading: 'Police locker',
|
heading: 'Police locker',
|
||||||
rows: [
|
rows: [
|
||||||
{ type: 'input', label: 'Locker number', placeholder: '420' },
|
{
|
||||||
|
type: 'input',
|
||||||
|
label: 'Locker number',
|
||||||
|
placeholder: '420',
|
||||||
|
description: 'Description that tells you what this input field does',
|
||||||
|
},
|
||||||
{ type: 'checkbox', label: 'Some checkbox' },
|
{ type: 'checkbox', label: 'Some checkbox' },
|
||||||
{ type: 'input', label: 'Locker PIN', password: true, icon: 'lock' },
|
{ type: 'input', label: 'Locker PIN', password: true, icon: 'lock' },
|
||||||
{ type: 'checkbox', label: 'Some other checkbox', checked: true },
|
{ type: 'checkbox', label: 'Some other checkbox', checked: true },
|
||||||
@@ -29,7 +34,13 @@ export const debugInput = () => {
|
|||||||
max: 10,
|
max: 10,
|
||||||
icon: 'receipt',
|
icon: 'receipt',
|
||||||
},
|
},
|
||||||
{ type: 'slider', label: 'Slide bar', min: 10, max: 50, step: 2 },
|
{
|
||||||
|
type: 'slider',
|
||||||
|
label: 'Slide bar',
|
||||||
|
min: 10,
|
||||||
|
max: 50,
|
||||||
|
step: 2,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
23
web/src/features/dialog/components/InfoTooltip.tsx
Normal file
23
web/src/features/dialog/components/InfoTooltip.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Box, Tooltip } from '@chakra-ui/react';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
|
||||||
|
const InfoTooltip: React.FC<{ description: string }> = ({ description }) => {
|
||||||
|
return (
|
||||||
|
<Tooltip label={description} placement="top" hasArrow arrowSize={4} maxW={220}>
|
||||||
|
<Box
|
||||||
|
borderRadius="full"
|
||||||
|
bg="whiteAlpha.200"
|
||||||
|
p={0.5}
|
||||||
|
w={18}
|
||||||
|
h={18}
|
||||||
|
display="flex"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon="question" fixedWidth fontSize={10} />
|
||||||
|
</Box>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InfoTooltip;
|
||||||
13
web/src/features/dialog/components/Label.tsx
Normal file
13
web/src/features/dialog/components/Label.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { HStack, Text } from '@chakra-ui/react';
|
||||||
|
import InfoTooltip from './InfoTooltip';
|
||||||
|
|
||||||
|
const Label: React.FC<{ label: string; description?: string }> = ({ label, description }) => {
|
||||||
|
return (
|
||||||
|
<HStack spacing={1}>
|
||||||
|
<Text>{label}</Text>
|
||||||
|
{description && <InfoTooltip description={description} />}
|
||||||
|
</HStack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Label;
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Box, Checkbox } from '@chakra-ui/react';
|
import { Box, Checkbox, HStack, Text } from '@chakra-ui/react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { ICheckbox } from '../../../interfaces/dialog';
|
import { ICheckbox } from '../../../interfaces/dialog';
|
||||||
|
import InfoTooltip from './InfoTooltip';
|
||||||
|
import Label from './Label';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
row: ICheckbox;
|
row: ICheckbox;
|
||||||
@@ -20,7 +22,7 @@ const CheckboxField: React.FC<Props> = (props) => {
|
|||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => props.handleChange(e.target.checked, props.index)}
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => props.handleChange(e.target.checked, props.index)}
|
||||||
defaultChecked={props.row.checked}
|
defaultChecked={props.row.checked}
|
||||||
>
|
>
|
||||||
{props.row.label}
|
<Label label={props.row.label} description={props.row.description} />
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Box, InputGroup, InputLeftElement, InputRightElement, Text, Input } from '@chakra-ui/react';
|
import { Box, InputGroup, InputLeftElement, InputRightElement, Input } from '@chakra-ui/react';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { IInput } from '../../../interfaces/dialog';
|
import { IInput } from '../../../interfaces/dialog';
|
||||||
|
import Label from './Label';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
row: IInput;
|
row: IInput;
|
||||||
@@ -19,7 +20,7 @@ const InputField: React.FC<Props> = (props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box mb={3} textAlign="left">
|
<Box mb={3} textAlign="left">
|
||||||
<Text>{props.row.label}</Text>
|
<Label label={props.row.label} description={props.row.description} />
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
{props.row.icon && (
|
{props.row.icon && (
|
||||||
<InputLeftElement pointerEvents="none" children={<FontAwesomeIcon icon={props.row.icon} fixedWidth />} />
|
<InputLeftElement pointerEvents="none" children={<FontAwesomeIcon icon={props.row.icon} fixedWidth />} />
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { INumber } from '../../../interfaces/dialog';
|
import { INumber } from '../../../interfaces/dialog';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import Label from './Label';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
row: INumber;
|
row: INumber;
|
||||||
@@ -25,7 +26,7 @@ const NumberField: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box mb={3}>
|
<Box mb={3}>
|
||||||
<Text>{props.row.label}</Text>
|
<Label label={props.row.label} description={props.row.description} />
|
||||||
<NumberInput
|
<NumberInput
|
||||||
onChange={(val: string) => props.handleChange(+val, props.index)}
|
onChange={(val: string) => props.handleChange(+val, props.index)}
|
||||||
defaultValue={props.row.default}
|
defaultValue={props.row.default}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Box, Text, Slider, SliderTrack, SliderFilledTrack, SliderThumb, HStack, Tooltip } from '@chakra-ui/react';
|
import { Box, Text, Slider, SliderTrack, SliderFilledTrack, SliderThumb, HStack, Tooltip } from '@chakra-ui/react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { ISlider } from '../../../interfaces/dialog';
|
import { ISlider } from '../../../interfaces/dialog';
|
||||||
|
import Label from './Label';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
row: ISlider;
|
row: ISlider;
|
||||||
@@ -18,7 +19,7 @@ const SliderField: React.FC<Props> = (props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box mb={3} key={`slider-${props.index}`}>
|
<Box mb={3} key={`slider-${props.index}`}>
|
||||||
<Text>{props.row.label}</Text>
|
<Label label={props.row.label} description={props.row.description} />
|
||||||
<Slider
|
<Slider
|
||||||
onChangeEnd={(val: number) => props.handleChange(val, props.index)}
|
onChangeEnd={(val: number) => props.handleChange(val, props.index)}
|
||||||
onChange={(val: number) => setSliderValue(val)}
|
onChange={(val: number) => setSliderValue(val)}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export interface IInput {
|
|||||||
password?: boolean;
|
password?: boolean;
|
||||||
icon?: IconProp;
|
icon?: IconProp;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICheckbox {
|
export interface ICheckbox {
|
||||||
@@ -15,6 +16,7 @@ export interface ICheckbox {
|
|||||||
label: string;
|
label: string;
|
||||||
checked?: boolean;
|
checked?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISelect {
|
export interface ISelect {
|
||||||
@@ -23,6 +25,7 @@ export interface ISelect {
|
|||||||
default?: string;
|
default?: string;
|
||||||
options?: { value: string; label?: string }[];
|
options?: { value: string; label?: string }[];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface INumber {
|
export interface INumber {
|
||||||
@@ -34,6 +37,7 @@ export interface INumber {
|
|||||||
min?: number;
|
min?: number;
|
||||||
max?: number;
|
max?: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISlider {
|
export interface ISlider {
|
||||||
@@ -44,4 +48,5 @@ export interface ISlider {
|
|||||||
max?: number;
|
max?: number;
|
||||||
step?: number;
|
step?: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user