-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from MiracleHorizon/feat/file-name-input
feat: option (input) to add the name of the output file
- Loading branch information
Showing
26 changed files
with
402 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/components/SettingsPanel/TabDefault/InputOutputFileName/InputOutputFileName.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.root { | ||
max-width: 500px; | ||
} | ||
|
||
.textFieldRoot { | ||
width: 100%; | ||
} |
103 changes: 103 additions & 0 deletions
103
src/components/SettingsPanel/TabDefault/InputOutputFileName/InputOutputFileName.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import dynamic from 'next/dynamic' | ||
import { type ChangeEvent, memo, useCallback, useMemo, useRef, useState } from 'react' | ||
import { Flex, TextField } from '@radix-ui/themes' | ||
|
||
import { ButtonClear } from '@ui/ButtonClear' | ||
import { ButtonInfoSkeleton } from '@ui/skeletons/ButtonInfoSkeleton' | ||
import { useOutputStore } from '@stores/output' | ||
import { useEscapeBlur } from '@hooks/useEscapeBlur' | ||
import { | ||
isValidFileName, | ||
MAX_FILE_NAME_LENGTH, | ||
MIN_FILE_NAME_LENGTH | ||
} from '@helpers/isValidFileName' | ||
import type { TextFieldInputProps } from '@libs/radix' | ||
import styles from './InputOutputFileName.module.css' | ||
|
||
const PopoverOutputFileName = dynamic( | ||
() => import('./PopoverOutputFileName').then(mod => mod.PopoverOutputFileName), | ||
{ | ||
ssr: false, | ||
loading: () => <ButtonInfoSkeleton /> | ||
} | ||
) | ||
|
||
function InputOutputFileName() { | ||
const [isError, setIsError] = useState<boolean>(false) | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
|
||
const outputFileName = useOutputStore(state => state.outputFileName) | ||
const setOutputFileName = useOutputStore(state => state.setOutputFileName) | ||
|
||
const inputProps = useMemo(() => { | ||
if (!isError) return | ||
|
||
return { | ||
color: 'red', | ||
variant: 'soft' | ||
} as TextFieldInputProps | ||
}, [isError]) | ||
|
||
const handleChange = useCallback( | ||
(ev: ChangeEvent<HTMLInputElement>) => { | ||
const value = ev.target.value | ||
|
||
if (value.length === 0) { | ||
setOutputFileName(ev.target.value) | ||
return setIsError(false) | ||
} | ||
|
||
const isValid = isValidFileName(value) | ||
|
||
if (!isValid) { | ||
setIsError(true) | ||
} else { | ||
if (isError !== null) { | ||
setIsError(false) | ||
} | ||
} | ||
|
||
setOutputFileName(ev.target.value) | ||
}, | ||
[isError, setOutputFileName] | ||
) | ||
|
||
const handleClear = useCallback(() => { | ||
setOutputFileName('') | ||
setIsError(false) | ||
}, [setOutputFileName]) | ||
|
||
useEscapeBlur({ | ||
ref: inputRef | ||
}) | ||
|
||
return ( | ||
<Flex gap='2' align='center' width='100%' mb='2' className={styles.root}> | ||
<TextField.Root className={styles.textFieldRoot}> | ||
<TextField.Input | ||
{...inputProps} | ||
ref={inputRef} | ||
mr='1' | ||
type='text' | ||
placeholder='Output file name' | ||
minLength={MIN_FILE_NAME_LENGTH} | ||
maxLength={MAX_FILE_NAME_LENGTH} | ||
value={outputFileName} | ||
onChange={handleChange} | ||
/> | ||
|
||
{outputFileName.length > 0 && ( | ||
<TextField.Slot> | ||
<ButtonClear onClick={handleClear} /> | ||
</TextField.Slot> | ||
)} | ||
</TextField.Root> | ||
|
||
<PopoverOutputFileName /> | ||
</Flex> | ||
) | ||
} | ||
|
||
const Memoized = memo(InputOutputFileName) | ||
|
||
export { Memoized as InputOutputFileName } |
37 changes: 37 additions & 0 deletions
37
...nel/TabDefault/InputOutputFileName/PopoverOutputFileName/PopoverOutputFileName.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.content { | ||
max-width: 370px; | ||
padding: var(--space-2); | ||
} | ||
|
||
.content li { | ||
list-style: disc outside; | ||
padding-left: 4px; | ||
} | ||
|
||
.content li span { | ||
margin-left: -8px; | ||
} | ||
|
||
.spanOptional { | ||
text-decoration: underline; | ||
text-underline-offset: 3px; | ||
} | ||
|
||
.contentText { | ||
line-height: 21px; | ||
} | ||
|
||
@media screen and (max-width: 520px) { | ||
.content { | ||
max-width: 80dvw; | ||
} | ||
|
||
.content li { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
.content li span { | ||
margin-left: 0; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...tingsPanel/TabDefault/InputOutputFileName/PopoverOutputFileName/PopoverOutputFileName.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use client' | ||
|
||
import { Fragment } from 'react' | ||
import { Code, Popover, Separator, Text } from '@radix-ui/themes' | ||
|
||
import { ButtonInfo } from '@ui/ButtonInfo' | ||
import { | ||
MAX_FILE_NAME_LENGTH, | ||
MIN_FILE_NAME_LENGTH, | ||
notAllowedChars | ||
} from '@helpers/isValidFileName' | ||
import styles from './PopoverOutputFileName.module.css' | ||
|
||
export function PopoverOutputFileName() { | ||
return ( | ||
<Popover.Root> | ||
<Popover.Trigger> | ||
<ButtonInfo /> | ||
</Popover.Trigger> | ||
|
||
<Popover.Content size='1' side='bottom' align='center' className={styles.content}> | ||
<Text as='p' size='2' className={styles.contentText}> | ||
The{' '} | ||
<Text as='span' className={styles.spanOptional}> | ||
optional | ||
</Text>{' '} | ||
name of the output file{' '} | ||
<Text as='span' weight='medium'> | ||
(without extension) | ||
</Text> | ||
. | ||
</Text> | ||
|
||
<Separator orientation='horizontal' size='4' mt='2' mb='1' /> | ||
|
||
<li> | ||
<Text size='2'> | ||
Not allowed characters:{' '} | ||
{notAllowedChars.map((chars, index) => ( | ||
<Fragment key={chars}> | ||
<Code variant='ghost'>{chars}</Code> | ||
{index < notAllowedChars.length - 1 && ' '} | ||
</Fragment> | ||
))} | ||
</Text> | ||
</li> | ||
|
||
<li> | ||
<Text size='2'> | ||
Length:{' '} | ||
<Code variant='ghost'> | ||
{MIN_FILE_NAME_LENGTH} - {MAX_FILE_NAME_LENGTH} | ||
</Code>{' '} | ||
characters | ||
</Text> | ||
</li> | ||
</Popover.Content> | ||
</Popover.Root> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
src/components/SettingsPanel/TabDefault/InputOutputFileName/PopoverOutputFileName/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PopoverOutputFileName } from './PopoverOutputFileName' |
1 change: 1 addition & 0 deletions
1
src/components/SettingsPanel/TabDefault/InputOutputFileName/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { InputOutputFileName } from './InputOutputFileName' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.