diff --git a/widget-src/components/InputField.tsx b/widget-src/components/InputField.tsx new file mode 100644 index 0000000..4ba8a7d --- /dev/null +++ b/widget-src/components/InputField.tsx @@ -0,0 +1,94 @@ +import { COLOR, FONT, GAP, PADDING, RADIUS, SPACE } from '../utilities/Styles'; + +const { widget } = figma; +const { AutoLayout, Input, Text } = widget; + +interface InputFieldProps { + name: string; + action: (val: string) => void; + placeholder?: string; + value?: string; + large?: boolean; + isRequired?: boolean; + behavior?: 'truncate' | 'multiline' | 'wrap'; + textCase?: 'upper' | 'lower' | 'title' | 'original' | 'small-caps' | 'small-caps-forced'; + isAbsolutePos?: boolean; + hasError?: boolean; + errorMessage?: string; + errorPosition?: 'left' | 'right'; + letterSpacing?: string | number; + fontWeight?: WidgetJSX.FontWeight; + width?: WidgetJSX.Size; +} + +export const InputField = ({ + name, + action, + placeholder, + value, + large = false, + isRequired = false, + behavior, + textCase = 'original', + isAbsolutePos = false, + hasError = false, + errorMessage, + errorPosition, + letterSpacing, + fontWeight, + width = 'fill-parent', +}: InputFieldProps) => { + return ( + + { + const trimmedInput = e.characters.trim(); + action(trimmedInput); + }} + /> + {isRequired && + (isAbsolutePos ? ( + + {hasError ? errorMessage : ''} + + ) : ( + + {hasError ? errorMessage : ''} + + ))} + + ); +};