import React, { forwardRef } from 'react'; import type { TextInputProps as MantineTextInputProps, NumberInputProps as MantineNumberInputProps, PasswordInputProps as MantinePasswordInputProps, FileInputProps as MantineFileInputProps, JsonInputProps as MantineJsonInputProps, TextareaProps as MantineTextareaProps, } from '@mantine/core'; import { TextInput as MantineTextInput, NumberInput as MantineNumberInput, PasswordInput as MantinePasswordInput, FileInput as MantineFileInput, JsonInput as MantineJsonInput, Textarea as MantineTextarea, } from '@mantine/core'; import styled from 'styled-components'; interface TextInputProps extends MantineTextInputProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } interface NumberInputProps extends MantineNumberInputProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } interface PasswordInputProps extends MantinePasswordInputProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } interface FileInputProps extends MantineFileInputProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } interface JsonInputProps extends MantineJsonInputProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } interface TextareaProps extends MantineTextareaProps { children?: React.ReactNode; maxWidth?: number | string; width?: number | string; } const StyledTextInput = styled(MantineTextInput)` & .mantine-TextInput-wrapper { border-color: var(--primary-color); } & .mantine-TextInput-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-Input-icon { color: var(--input-placeholder-fg); } & .mantine-TextInput-required { color: var(--secondary-color); } & .mantine-TextInput-label { font-family: var(--label-font-faimly); } & .mantine-TextInput-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; const StyledNumberInput = styled(MantineNumberInput)` & .mantine-NumberInput-wrapper { border-color: var(--primary-color); } & .mantine-NumberInput-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-NumberInput-controlUp { svg { color: var(--btn-default-fg); fill: var(--btn-default-fg); } } & .mantine-NumberInput-controlDown { svg { color: var(--btn-default-fg); fill: var(--btn-default-fg); } } & .mantine-Input-icon { color: var(--input-placeholder-fg); } & .mantine-NumberInput-required { color: var(--secondary-color); } & .mantine-NumberInput-label { font-family: var(--label-font-faimly); } & .mantine-NumberInput-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; const StyledPasswordInput = styled(MantinePasswordInput)` & .mantine-PasswordInput-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-PasswordInput-icon { color: var(--input-placeholder-fg); } & .mantine-PasswordInput-required { color: var(--secondary-color); } & .mantine-PasswordInput-label { font-family: var(--label-font-faimly); } & .mantine-PasswordInput-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; const StyledFileInput = styled(MantineFileInput)` & .mantine-FileInput-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-FileInput-icon { color: var(--input-placeholder-fg); } & .mantine-FileInput-required { color: var(--secondary-color); } & .mantine-FileInput-label { font-family: var(--label-font-faimly); } & .mantine-FileInput-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; const StyledJsonInput = styled(MantineJsonInput)` & .mantine-JsonInput-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-JsonInput-icon { color: var(--input-placeholder-fg); } & .mantine-JsonInput-required { color: var(--secondary-color); } & .mantine-JsonInput-label { font-family: var(--label-font-faimly); } & .mantine-JsonInput-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; const StyledTextarea = styled(MantineTextarea)` & .mantine-Textarea-input { color: var(--input-fg); background: var(--input-bg); &::placeholder { color: var(--input-placeholder-fg); } } & .mantine-Textarea-icon { color: var(--input-placeholder-fg); } & .mantine-Textarea-required { color: var(--secondary-color); } & .mantine-Textarea-label { font-family: var(--label-font-faimly); } & .mantine-Textarea-disabled { opacity: 0.6; } transition: width 0.3s ease-in-out; `; export const TextInput = forwardRef( ({ children, width, maxWidth, ...props }: TextInputProps, ref) => { return ( {children} ); }, ); export const NumberInput = forwardRef( ({ children, width, maxWidth, ...props }: NumberInputProps, ref) => { return ( {children} ); }, ); export const PasswordInput = forwardRef( ({ children, width, maxWidth, ...props }: PasswordInputProps, ref) => { return ( {children} ); }, ); export const FileInput = forwardRef( ({ children, width, maxWidth, ...props }: FileInputProps, ref) => { return ( {children} ); }, ); export const JsonInput = forwardRef( ({ children, width, maxWidth, ...props }: JsonInputProps, ref) => { return ( {children} ); }, ); export const Textarea = forwardRef( ({ children, width, maxWidth, ...props }: TextareaProps, ref) => { return ( {children} ); }, ); TextInput.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, }; NumberInput.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, }; PasswordInput.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, }; FileInput.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, }; JsonInput.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, }; Textarea.defaultProps = { children: undefined, maxWidth: undefined, width: undefined, };