Skip to content

Commit aa0b97f

Browse files
committed
better file input configs
1 parent 1a92396 commit aa0b97f

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src-ts/lib/form/form-groups/form-input/input-image-picker/InputImagePicker.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { InputValue } from '../../../form-input.model'
66
import styles from './InputImagePicker.module.scss'
77

88
interface InputImagePickerProps {
9-
readonly accept?: string
9+
readonly fileConfig?: {
10+
readonly acceptFileType?: string
11+
readonly maxFileSize?: number
12+
}
1013
readonly name: string
1114
readonly onChange: (event: ChangeEvent<HTMLInputElement>) => void
12-
readonly size?: number
1315
readonly value?: InputValue
1416
}
1517

@@ -49,14 +51,14 @@ const InputImagePicker: FC<InputImagePickerProps> = (props: InputImagePickerProp
4951
<input
5052
name={props.name}
5153
type={'file'}
52-
accept={props.accept || '*'}
54+
accept={props.fileConfig?.acceptFileType || '*'}
5355
className={styles.filePickerInput}
5456
ref={fileInputRef}
5557
onChange={event => {
5658
setFiles(event.target.files)
5759
props.onChange(event)
5860
}}
59-
size={props.size || Infinity}
61+
size={props.fileConfig?.maxFileSize || Infinity}
6062
/>
6163
{
6264
fileDataURL ? (

src-ts/lib/form/form-input.model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export interface FormCard {
2020
export type InputValue = string | boolean | FileList | undefined
2121

2222
export interface FormInputModel {
23-
readonly accept?: string
2423
readonly autocomplete?: FormInputAutocompleteOption
2524
readonly cards?: ReadonlyArray<FormCard>
2625
checked?: boolean
@@ -30,6 +29,10 @@ export interface FormInputModel {
3029
disabled?: boolean
3130
error?: string
3231
readonly events?: ReadonlyArray<InputEvent>
32+
readonly fileConfig?: {
33+
readonly acceptFileType?: string
34+
readonly maxFileSize?: number
35+
}
3336
readonly files?: FileList
3437
readonly hideInlineErrors?: boolean
3538
readonly hint?: string
@@ -40,7 +43,6 @@ export interface FormInputModel {
4043
readonly notTabbable?: boolean
4144
options?: ReadonlyArray<FormRadioButtonOption>
4245
readonly placeholder?: string
43-
readonly size?: number
4446
readonly spellCheck?: boolean
4547
readonly title?: string
4648
touched?: boolean

src-ts/tools/gamification-admin/pages/create-badge/create-badge-form/create-badge-form.config.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export const createBadgeFormDef: FormDefinition = {
3333
{
3434
inputs: [
3535
{
36-
accept: GamificationConfig.ACCEPTED_BADGE_MIME_TYPES,
36+
fileConfig: {
37+
acceptFileType: GamificationConfig.ACCEPTED_BADGE_MIME_TYPES,
38+
maxFileSize: GamificationConfig.MAX_BADGE_IMAGE_FILE_SIZE,
39+
},
3740
name: CreateBadgeFormField.file,
38-
size: GamificationConfig.MAX_BADGE_IMAGE_FILE_SIZE,
3941
type: 'image-picker',
4042
validators: [
4143
{

0 commit comments

Comments
 (0)