All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.MultiLineInput-AcwuO_FT.js.map Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
{"version":3,"file":"MultiLineInput-AcwuO_FT.js","sources":["../../src/components/multi-line-input/MultiLineInput.tsx"],"sourcesContent":["import {\n  Button,\n  ButtonVariant,\n  InputGroup,\n  TextInput,\n  TextInputProps,\n  InputGroupItem,\n} from \"@patternfly/react-core\";\nimport { MinusCircleIcon, PlusCircleIcon } from \"@patternfly/react-icons\";\nimport { Fragment, useEffect, useMemo } from \"react\";\nimport { useFormContext, useWatch } from \"react-hook-form\";\nimport { useTranslation } from \"react-i18next\";\n\nfunction stringToMultiline(value?: string): string[] {\n  return typeof value === \"string\" ? value.split(\"##\") : [value || \"\"];\n}\n\nfunction toStringValue(formValue: string[]): string {\n  return formValue.join(\"##\");\n}\n\nexport type MultiLineInputProps = Omit & {\n  name: string;\n  addButtonLabel?: string;\n  isDisabled?: boolean;\n  defaultValue?: string[];\n  stringify?: boolean;\n};\n\nexport const MultiLineInput = ({\n  name,\n  addButtonLabel,\n  isDisabled = false,\n  defaultValue,\n  stringify = false,\n  id,\n  ...rest\n}: MultiLineInputProps) => {\n  const { t } = useTranslation();\n  const { register, setValue, control } = useFormContext();\n  const value = useWatch({\n    name,\n    control,\n    defaultValue: defaultValue || \"\",\n  });\n\n  const fields = useMemo(() => {\n    let values = stringify\n      ? stringToMultiline(\n          Array.isArray(value) && value.length === 1 ? value[0] : value,\n        )\n      : value;\n\n    values =\n      Array.isArray(values) && values.length !== 0\n        ? values\n        : (stringify\n            ? stringToMultiline(defaultValue as string)\n            : defaultValue) || [\"\"];\n\n    return values;\n  }, [value]);\n\n  const remove = (index: number) => {\n    update([...fields.slice(0, index), ...fields.slice(index + 1)]);\n  };\n\n  const append = () => {\n    update([...fields, \"\"]);\n  };\n\n  const updateValue = (index: number, value: string) => {\n    update([...fields.slice(0, index), value, ...fields.slice(index + 1)]);\n  };\n\n  const update = (values: string[]) => {\n    const fieldValue = values.flatMap((field) => field);\n    setValue(name, stringify ? toStringValue(fieldValue) : fieldValue, {\n      shouldDirty: true,\n    });\n  };\n\n  useEffect(() => {\n    register(name);\n  }, [register]);\n\n  return (\n    
\n {fields.map((value, index) => (\n \n \n \n updateValue(index, value)}\n name={`${name}.${index}.value`}\n value={value}\n isDisabled={isDisabled}\n {...rest}\n />\n \n \n remove(index)}\n tabIndex={-1}\n aria-label={t(\"remove\")}\n isDisabled={fields.length === 1 || isDisabled}\n >\n \n \n \n \n {index === fields.length - 1 && (\n \n {t(addButtonLabel || \"add\")}\n \n )}\n \n ))}\n
\n );\n};\n"],"names":["stringToMultiline","value","toStringValue","formValue","MultiLineInput","name","addButtonLabel","isDisabled","defaultValue","stringify","id","rest","t","useTranslation","register","setValue","control","useFormContext","useWatch","fields","useMemo","values","remove","index","update","append","updateValue","fieldValue","field","useEffect","jsx","jsxs","Fragment","InputGroup","InputGroupItem","TextInput","_event","Button","ButtonVariant","MinusCircleIcon","PlusCircleIcon"],"mappings":"6NAaA,SAASA,EAAkBC,EAA0B,CAC5C,OAAA,OAAOA,GAAU,SAAWA,EAAM,MAAM,IAAI,EAAI,CAACA,GAAS,EAAE,CACrE,CAEA,SAASC,EAAcC,EAA6B,CAC3C,OAAAA,EAAU,KAAK,IAAI,CAC5B,CAUO,MAAMC,EAAiB,CAAC,CAC7B,KAAAC,EACA,eAAAC,EACA,WAAAC,EAAa,GACb,aAAAC,EACA,UAAAC,EAAY,GACZ,GAAAC,EACA,GAAGC,CACL,IAA2B,CACnB,KAAA,CAAE,EAAAC,GAAMC,IACR,CAAE,SAAAC,EAAU,SAAAC,EAAU,QAAAC,GAAYC,EAAe,EACjDhB,EAAQiB,EAAS,CACrB,KAAAb,EACA,QAAAW,EACA,aAAcR,GAAgB,EAAA,CAC/B,EAEKW,EAASC,EAAkB,IAAM,CACrC,IAAIC,EAASZ,EACTT,EACE,MAAM,QAAQC,CAAK,GAAKA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