mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-07 01:14:57 +05:30
feat: implement ValidatedToolResult component for improved validation feedback in Epoch Converter tool
This commit is contained in:
parent
ed48d484ec
commit
8a0d757718
2 changed files with 68 additions and 42 deletions
60
src/components/result/ValidatedToolResult.tsx
Normal file
60
src/components/result/ValidatedToolResult.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react';
|
||||
import { Alert } from '@mui/material';
|
||||
|
||||
interface ValidatedToolResultProps {
|
||||
isValid: boolean | null;
|
||||
hasInteracted: boolean;
|
||||
errorMessage?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const ValidatedToolResult: React.FC<ValidatedToolResultProps> = ({
|
||||
isValid,
|
||||
hasInteracted,
|
||||
errorMessage = 'Invalid input.',
|
||||
children
|
||||
}) => (
|
||||
<div style={{ position: 'relative', minHeight: 80 }}>
|
||||
{hasInteracted && isValid === false && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
zIndex: 2,
|
||||
pointerEvents: 'auto',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'transparent'
|
||||
}}
|
||||
>
|
||||
<Alert
|
||||
severity="error"
|
||||
style={{
|
||||
width: '80%',
|
||||
opacity: 0.85,
|
||||
textAlign: 'center',
|
||||
pointerEvents: 'none'
|
||||
}}
|
||||
>
|
||||
{errorMessage}
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
style={{
|
||||
filter: hasInteracted && isValid === false ? 'blur(1px)' : 'none',
|
||||
transition: 'filter 0.2s'
|
||||
}}
|
||||
>
|
||||
{hasInteracted && isValid === false
|
||||
? React.cloneElement(children as React.ReactElement, { value: '' })
|
||||
: children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default ValidatedToolResult;
|
||||
|
|
@ -8,6 +8,7 @@ import { GetGroupsType } from '@components/options/ToolOptions';
|
|||
import { CardExampleType } from '@components/examples/ToolExamples';
|
||||
import { main, epochToDate, dateToEpoch } from './service';
|
||||
import { InitialValuesType } from './types';
|
||||
import ValidatedToolResult from '@components/result/ValidatedToolResult';
|
||||
|
||||
const initialValues: InitialValuesType = {};
|
||||
|
||||
|
|
@ -89,48 +90,13 @@ export default function EpochConverter({
|
|||
</>
|
||||
}
|
||||
resultComponent={
|
||||
<div style={{ position: 'relative', minHeight: 80 }}>
|
||||
{hasInteracted && isValid === false && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
zIndex: 2,
|
||||
pointerEvents: 'auto',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'transparent'
|
||||
}}
|
||||
>
|
||||
<Alert
|
||||
severity="error"
|
||||
style={{
|
||||
width: '80%',
|
||||
opacity: 0.85,
|
||||
textAlign: 'center',
|
||||
pointerEvents: 'none'
|
||||
}}
|
||||
>
|
||||
Invalid input. Please enter a valid epoch timestamp or date
|
||||
string.
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
style={{
|
||||
filter: hasInteracted && isValid === false ? 'blur(1px)' : 'none',
|
||||
transition: 'filter 0.2s'
|
||||
}}
|
||||
>
|
||||
<ToolTextResult
|
||||
value={hasInteracted && isValid === false ? '' : result}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<ValidatedToolResult
|
||||
isValid={isValid}
|
||||
hasInteracted={hasInteracted}
|
||||
errorMessage="Invalid input. Please enter a valid epoch timestamp or date string."
|
||||
>
|
||||
<ToolTextResult value={result} />
|
||||
</ValidatedToolResult>
|
||||
}
|
||||
initialValues={initialValues}
|
||||
exampleCards={exampleCards}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue