@greenbone/ui-lib 2.1.1-alpha0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/lib/cjs/components/Accordion/Accordion.js +1 -1
  2. package/lib/cjs/components/Accordion/Accordion.js.map +1 -1
  3. package/lib/cjs/components/Alert/Alert.js +1 -1
  4. package/lib/cjs/components/Alert/Alert.js.map +1 -1
  5. package/lib/cjs/components/ConfirmationDialog/ConfirmationDialog.js +1 -1
  6. package/lib/cjs/components/ConfirmationDialog/ConfirmationDialog.js.map +1 -1
  7. package/lib/cjs/components/Drawer/Drawer.js +1 -1
  8. package/lib/cjs/components/Drawer/Drawer.js.map +1 -1
  9. package/lib/cjs/components/Filter/TermContainer/Term/TermBadge.js +1 -1
  10. package/lib/cjs/components/Filter/TermContainer/Term/TermBadge.js.map +1 -1
  11. package/lib/cjs/components/Filter/persistence/FilterPersistent.js +1 -1
  12. package/lib/cjs/components/Filter/persistence/FilterPersistent.js.map +1 -1
  13. package/lib/cjs/components/Filter/utils/FilterSelect.js +1 -1
  14. package/lib/cjs/components/Filter/utils/FilterSelect.js.map +1 -1
  15. package/lib/cjs/components/Filter/utils/Select.js +1 -1
  16. package/lib/cjs/components/Filter/utils/Select.js.map +1 -1
  17. package/lib/cjs/components/Form/Button/Button.js +1 -1
  18. package/lib/cjs/components/Form/Button/Button.js.map +1 -1
  19. package/lib/cjs/components/Form/Checkbox/Checkbox.js +1 -1
  20. package/lib/cjs/components/Form/Checkbox/Checkbox.js.map +1 -1
  21. package/lib/cjs/components/Form/DateTimePicker/DateTimePicker.js +1 -1
  22. package/lib/cjs/components/Form/DateTimePicker/DateTimePicker.js.map +1 -1
  23. package/lib/cjs/components/Form/DateTimePicker/TimePicker.js +1 -1
  24. package/lib/cjs/components/Form/DateTimePicker/TimePicker.js.map +1 -1
  25. package/lib/cjs/components/Form/FileInput/FileInput.js +1 -1
  26. package/lib/cjs/components/Form/FileInput/FileInput.js.map +1 -1
  27. package/lib/cjs/components/Form/Form/Form.js +1 -1
  28. package/lib/cjs/components/Form/Form/Form.js.map +1 -1
  29. package/lib/cjs/components/Form/Input/Input.js +1 -1
  30. package/lib/cjs/components/Form/Input/Input.js.map +1 -1
  31. package/lib/cjs/components/Form/MenuButton/index.js +1 -1
  32. package/lib/cjs/components/Form/MenuButton/index.js.map +1 -1
  33. package/lib/cjs/components/Form/PasswordInput/PasswordInput.js +1 -1
  34. package/lib/cjs/components/Form/PasswordInput/PasswordInput.js.map +1 -1
  35. package/lib/cjs/components/Form/RadioButton/RadioButton.js +1 -1
  36. package/lib/cjs/components/Form/RadioButton/RadioButton.js.map +1 -1
  37. package/lib/cjs/components/Form/Select/Cascade/CascadeMenu.js +1 -1
  38. package/lib/cjs/components/Form/Select/Cascade/CascadeMenu.js.map +1 -1
  39. package/lib/cjs/components/Form/Select/Cascade/CascadeOption.js +1 -1
  40. package/lib/cjs/components/Form/Select/Cascade/CascadeOption.js.map +1 -1
  41. package/lib/cjs/components/Form/Select/Cascade/index.js +1 -1
  42. package/lib/cjs/components/Form/Select/Cascade/index.js.map +1 -1
  43. package/lib/cjs/components/Form/Select/CreatableSelect.js +1 -1
  44. package/lib/cjs/components/Form/Select/CreatableSelect.js.map +1 -1
  45. package/lib/cjs/components/Form/Select/Select.js +1 -1
  46. package/lib/cjs/components/Form/Select/Select.js.map +1 -1
  47. package/lib/cjs/components/Form/Switch/Switch.js +1 -1
  48. package/lib/cjs/components/Form/Switch/Switch.js.map +1 -1
  49. package/lib/cjs/components/Form/Textarea/Textarea.js +1 -1
  50. package/lib/cjs/components/Form/Textarea/Textarea.js.map +1 -1
  51. package/lib/cjs/components/Icon/Icon.js +1 -1
  52. package/lib/cjs/components/Icon/Icon.js.map +1 -1
  53. package/lib/cjs/components/InfoTip/InfoTip.js +1 -1
  54. package/lib/cjs/components/InfoTip/InfoTip.js.map +1 -1
  55. package/lib/cjs/components/InformationList/InformationList.js +1 -1
  56. package/lib/cjs/components/InformationList/InformationList.js.map +1 -1
  57. package/lib/cjs/components/Layout/AppNavigation/AppNavigationLink.js +1 -1
  58. package/lib/cjs/components/Layout/AppNavigation/AppNavigationLink.js.map +1 -1
  59. package/lib/cjs/components/Layout/SimplePageLayout/SimpleGrid.js +1 -1
  60. package/lib/cjs/components/Layout/SimplePageLayout/SimpleGrid.js.map +1 -1
  61. package/lib/cjs/components/Layout/SimplePageLayout/index.js +1 -1
  62. package/lib/cjs/components/Layout/SimplePageLayout/index.js.map +1 -1
  63. package/lib/cjs/components/Modal/Modal.js +1 -1
  64. package/lib/cjs/components/Modal/Modal.js.map +1 -1
  65. package/lib/cjs/components/Notification/notifications.js +1 -1
  66. package/lib/cjs/components/Notification/notifications.js.map +1 -1
  67. package/lib/cjs/components/Table/TableClientSide/TableClientSidePersistent/index.js +1 -1
  68. package/lib/cjs/components/Table/TableClientSide/TableClientSidePersistent/index.js.map +1 -1
  69. package/lib/cjs/components/Table/TableServerSide/TableServerSidePersistent/index.js +1 -1
  70. package/lib/cjs/components/Table/TableServerSide/TableServerSidePersistent/index.js.map +1 -1
  71. package/lib/cjs/components/Table/components/ActionMenu/ActionMenu.js +1 -1
  72. package/lib/cjs/components/Table/components/ActionMenu/ActionMenu.js.map +1 -1
  73. package/lib/cjs/components/Tag/Tag.js +1 -1
  74. package/lib/cjs/components/Tag/Tag.js.map +1 -1
  75. package/lib/cjs/components/TimeZoneInfo/index.js +1 -1
  76. package/lib/cjs/components/TimeZoneInfo/index.js.map +1 -1
  77. package/lib/cjs/components/Tooltip/Tooltip.js +1 -1
  78. package/lib/cjs/components/Tooltip/Tooltip.js.map +1 -1
  79. package/lib/cjs/components/Typo/Typo.js +1 -1
  80. package/lib/cjs/components/Typo/Typo.js.map +1 -1
  81. package/lib/cjs/icons/StatusIcon/StatusIcon.js +1 -1
  82. package/lib/cjs/icons/StatusIcon/StatusIcon.js.map +1 -1
  83. package/lib/esm/components/Accordion/Accordion.js +1 -1
  84. package/lib/esm/components/Accordion/Accordion.js.map +1 -1
  85. package/lib/esm/components/Alert/Alert.js +1 -1
  86. package/lib/esm/components/Alert/Alert.js.map +1 -1
  87. package/lib/esm/components/ConfirmationDialog/ConfirmationDialog.js +1 -1
  88. package/lib/esm/components/ConfirmationDialog/ConfirmationDialog.js.map +1 -1
  89. package/lib/esm/components/Drawer/Drawer.js +1 -1
  90. package/lib/esm/components/Drawer/Drawer.js.map +1 -1
  91. package/lib/esm/components/Filter/TermContainer/Term/TermBadge.js +1 -1
  92. package/lib/esm/components/Filter/TermContainer/Term/TermBadge.js.map +1 -1
  93. package/lib/esm/components/Filter/persistence/FilterPersistent.js +1 -1
  94. package/lib/esm/components/Filter/persistence/FilterPersistent.js.map +1 -1
  95. package/lib/esm/components/Filter/utils/FilterSelect.js +1 -1
  96. package/lib/esm/components/Filter/utils/FilterSelect.js.map +1 -1
  97. package/lib/esm/components/Filter/utils/Select.js +1 -1
  98. package/lib/esm/components/Filter/utils/Select.js.map +1 -1
  99. package/lib/esm/components/Form/Button/Button.js +1 -1
  100. package/lib/esm/components/Form/Button/Button.js.map +1 -1
  101. package/lib/esm/components/Form/Checkbox/Checkbox.js +1 -1
  102. package/lib/esm/components/Form/Checkbox/Checkbox.js.map +1 -1
  103. package/lib/esm/components/Form/DateTimePicker/DateTimePicker.js +1 -1
  104. package/lib/esm/components/Form/DateTimePicker/DateTimePicker.js.map +1 -1
  105. package/lib/esm/components/Form/DateTimePicker/TimePicker.js +1 -1
  106. package/lib/esm/components/Form/DateTimePicker/TimePicker.js.map +1 -1
  107. package/lib/esm/components/Form/FileInput/FileInput.js +1 -1
  108. package/lib/esm/components/Form/FileInput/FileInput.js.map +1 -1
  109. package/lib/esm/components/Form/Form/Form.js +1 -1
  110. package/lib/esm/components/Form/Form/Form.js.map +1 -1
  111. package/lib/esm/components/Form/Input/Input.js +1 -1
  112. package/lib/esm/components/Form/Input/Input.js.map +1 -1
  113. package/lib/esm/components/Form/MenuButton/index.js +1 -1
  114. package/lib/esm/components/Form/MenuButton/index.js.map +1 -1
  115. package/lib/esm/components/Form/PasswordInput/PasswordInput.js +1 -1
  116. package/lib/esm/components/Form/PasswordInput/PasswordInput.js.map +1 -1
  117. package/lib/esm/components/Form/RadioButton/RadioButton.js +1 -1
  118. package/lib/esm/components/Form/RadioButton/RadioButton.js.map +1 -1
  119. package/lib/esm/components/Form/Select/Cascade/CascadeMenu.js +1 -1
  120. package/lib/esm/components/Form/Select/Cascade/CascadeMenu.js.map +1 -1
  121. package/lib/esm/components/Form/Select/Cascade/CascadeOption.js +1 -1
  122. package/lib/esm/components/Form/Select/Cascade/CascadeOption.js.map +1 -1
  123. package/lib/esm/components/Form/Select/Cascade/index.js +1 -1
  124. package/lib/esm/components/Form/Select/Cascade/index.js.map +1 -1
  125. package/lib/esm/components/Form/Select/CreatableSelect.js +1 -1
  126. package/lib/esm/components/Form/Select/CreatableSelect.js.map +1 -1
  127. package/lib/esm/components/Form/Select/Select.js +1 -1
  128. package/lib/esm/components/Form/Select/Select.js.map +1 -1
  129. package/lib/esm/components/Form/Switch/Switch.js +1 -1
  130. package/lib/esm/components/Form/Switch/Switch.js.map +1 -1
  131. package/lib/esm/components/Form/Textarea/Textarea.js +1 -1
  132. package/lib/esm/components/Form/Textarea/Textarea.js.map +1 -1
  133. package/lib/esm/components/Icon/Icon.js +1 -1
  134. package/lib/esm/components/Icon/Icon.js.map +1 -1
  135. package/lib/esm/components/InfoTip/InfoTip.js +1 -1
  136. package/lib/esm/components/InfoTip/InfoTip.js.map +1 -1
  137. package/lib/esm/components/InformationList/InformationList.js +1 -1
  138. package/lib/esm/components/InformationList/InformationList.js.map +1 -1
  139. package/lib/esm/components/Layout/AppNavigation/AppNavigationLink.js +1 -1
  140. package/lib/esm/components/Layout/AppNavigation/AppNavigationLink.js.map +1 -1
  141. package/lib/esm/components/Layout/SimplePageLayout/SimpleGrid.js +1 -1
  142. package/lib/esm/components/Layout/SimplePageLayout/SimpleGrid.js.map +1 -1
  143. package/lib/esm/components/Layout/SimplePageLayout/index.js +1 -1
  144. package/lib/esm/components/Layout/SimplePageLayout/index.js.map +1 -1
  145. package/lib/esm/components/Modal/Modal.js +1 -1
  146. package/lib/esm/components/Modal/Modal.js.map +1 -1
  147. package/lib/esm/components/Notification/notifications.js +1 -1
  148. package/lib/esm/components/Notification/notifications.js.map +1 -1
  149. package/lib/esm/components/Table/TableClientSide/TableClientSidePersistent/index.js +1 -1
  150. package/lib/esm/components/Table/TableClientSide/TableClientSidePersistent/index.js.map +1 -1
  151. package/lib/esm/components/Table/TableServerSide/TableServerSidePersistent/index.js +1 -1
  152. package/lib/esm/components/Table/TableServerSide/TableServerSidePersistent/index.js.map +1 -1
  153. package/lib/esm/components/Table/components/ActionMenu/ActionMenu.js +1 -1
  154. package/lib/esm/components/Table/components/ActionMenu/ActionMenu.js.map +1 -1
  155. package/lib/esm/components/Tag/Tag.js +1 -1
  156. package/lib/esm/components/Tag/Tag.js.map +1 -1
  157. package/lib/esm/components/TimeZoneInfo/index.js +1 -1
  158. package/lib/esm/components/TimeZoneInfo/index.js.map +1 -1
  159. package/lib/esm/components/Tooltip/Tooltip.js +1 -1
  160. package/lib/esm/components/Tooltip/Tooltip.js.map +1 -1
  161. package/lib/esm/components/Typo/Typo.js +1 -1
  162. package/lib/esm/components/Typo/Typo.js.map +1 -1
  163. package/lib/esm/icons/StatusIcon/StatusIcon.js +1 -1
  164. package/lib/esm/icons/StatusIcon/StatusIcon.js.map +1 -1
  165. package/package.json +22 -22
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/Button/Button.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Button as MantineButton, ButtonProps } from \"@mantine/core\"\nimport classes from \"./Button.module.css\"\nimport { forwardRef } from \"react\"\nimport { LucideIcon } from \"lucide-react\"\nimport { ICON_SIZES } from \"../../../theme\"\n\nexport type TButtonProps = {\n variant?: \"filled\" | \"outline\" | \"default\" | \"subtle\" | \"danger\"\n size?: \"sm\" | \"md\" | \"lg\"\n icon?: LucideIcon\n} & ButtonProps &\n React.ComponentPropsWithoutRef<\"button\">\n\n/**\n * Provides a Button component of various variants\n * @param variant Variant string of the button using filled, outline, default, subtle or danger\n * @param size Size of the Button using sm, md or lg\n * @param icon If an icon is given, it will be included in the Button\n */\nexport const Button = forwardRef<HTMLButtonElement, TButtonProps>(\n ({ variant = \"filled\", size = \"md\", children, icon, ...rest }, ref) => {\n const Icon = icon\n return (\n <MantineButton\n variant={variant}\n size={size}\n classNames={{ ...classes }}\n {...rest}\n color={\"red\"}\n leftSection={Icon && <Icon size={ICON_SIZES.MEDIUM} />}\n ref={ref}\n >\n {children}\n </MantineButton>\n )\n }\n)\n\nButton.displayName = \"Button\"\n"],"names":["Button","MantineButton","classes","forwardRef","ICON_SIZES","variant","size","children","icon","rest","ref","Icon","classNames","color","leftSection","MEDIUM","displayName"],"mappings":"0zEAIA,QAASA,UAAUC,aAAa,KAAqB,eAAe,AACpE,QAAOC,YAAa,qBAAqB,AACzC,QAASC,UAAU,KAAQ,OAAO,AAElC,QAASC,UAAU,KAAQ,gBAAgB,AAe3C,QAAO,MAAMJ,OAASG,WACpB,iDAAC,CAAEE,QAAU,QAAQ,CAAEC,KAAO,IAAI,CAAEC,QAAQ,CAAEC,IAAI,CAAW,OAANC,6EAAQC,WAC7D,MAAMC,KAAOH,KACb,OACE,KAACP,mDACCI,QAASA,QACTC,KAAMA,KACNM,WAAY,kBAAKV,UACbO,OACJI,MAAO,MACPC,YAAaH,MAAQ,KAACA,MAAKL,KAAMF,WAAWW,MAAM,GAClDL,IAAKA,aAEJH,WAGP,EACD,AAEDP,CAAAA,OAAOgB,WAAW,CAAG"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/Button/Button.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Button as MantineButton, ButtonProps } from \"@mantine/core\"\nimport classes from \"./Button.module.css\"\nimport { forwardRef } from \"react\"\nimport { LucideIcon } from \"lucide-react\"\nimport { ICON_SIZES } from \"../../../theme\"\n\nexport type TButtonProps = {\n variant?: \"filled\" | \"outline\" | \"default\" | \"subtle\" | \"danger\"\n size?: \"sm\" | \"md\" | \"lg\"\n icon?: LucideIcon\n} & ButtonProps &\n React.ComponentPropsWithoutRef<\"button\">\n\n/**\n * Provides a Button component of various variants\n * @param variant Variant string of the button using filled, outline, default, subtle or danger\n * @param size Size of the Button using sm, md or lg\n * @param icon If an icon is given, it will be included in the Button\n */\nexport const Button = forwardRef<HTMLButtonElement, TButtonProps>(\n ({ variant = \"filled\", size = \"md\", children, icon, ...rest }, ref) => {\n const Icon = icon\n return (\n <MantineButton\n variant={variant}\n size={size}\n classNames={{ ...classes }}\n {...rest}\n color={\"red\"}\n leftSection={Icon && <Icon size={ICON_SIZES.MEDIUM} />}\n ref={ref}\n >\n {children}\n </MantineButton>\n )\n }\n)\n\nButton.displayName = \"Button\"\n"],"names":["Button","MantineButton","classes","forwardRef","ICON_SIZES","variant","size","children","icon","rest","ref","Icon","classNames","color","leftSection","MEDIUM","displayName"],"mappings":"k0EAIA,QAASA,UAAUC,aAAa,KAAqB,eAAe,AACpE,QAAOC,YAAa,qBAAqB,AACzC,QAASC,UAAU,KAAQ,OAAO,AAElC,QAASC,UAAU,KAAQ,gBAAgB,AAe3C,QAAO,MAAMJ,OAASG,WACpB,iDAAC,CAAEE,QAAU,QAAQ,CAAEC,KAAO,IAAI,CAAEC,QAAQ,CAAEC,IAAI,CAAW,OAANC,6EAAQC,WAC7D,MAAMC,KAAOH,KACb,OACE,KAACP,mDACCI,QAASA,QACTC,KAAMA,KACNM,WAAY,kBAAKV,UACbO,OACJI,MAAO,MACPC,YAAaH,MAAQ,KAACA,MAAKL,KAAMF,WAAWW,MAAM,GAClDL,IAAKA,aAEJH,WAGP,EACD,AAEDP,CAAAA,OAAOgB,WAAW,CAAG"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};return _extends.apply(this,arguments)}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import React,{forwardRef}from"react";import{Checkbox as CheckboxMantine}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import{useErrorContext}from"../Form";import{FormErrors}from"../Form/FormErrors";import classes from"./Checkbox.module.css";const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{label:`${defaultFormStyles.label} ${classes.label}`})};export const Checkbox=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{}=_ref1,props=_extends({},_ref1),[ref]=_rest;const classes=useStyles();return _jsx(CheckboxMantine,_object_spread({ref:ref,classNames:{root:classes.root,label:classes.label,input:classes.input}},props))});export const FormCheckbox=_0=>{let{name,validation={}}=_0,checkboxProps=_object_without_properties(_0,["name","validation"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formErrors=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formErrors===null||formErrors===void 0?void 0:formErrors.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Checkbox,_object_spread_props(_object_spread({},checkboxProps,register(name,{validate:validation,disabled:checkboxProps.disabled})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};return _extends.apply(this,arguments)}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import React,{forwardRef}from"react";import{Checkbox as CheckboxMantine}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import{useErrorContext}from"../Form";import{FormErrors}from"../Form/FormErrors";import classes from"./Checkbox.module.css";const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{label:`${defaultFormStyles.label} ${classes.label}`})};export const Checkbox=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{}=_ref1,props=_extends({},_ref1),[ref]=_rest;const classes=useStyles();return _jsx(CheckboxMantine,_object_spread({ref:ref,classNames:{root:classes.root,label:classes.label,input:classes.input}},props))});export const FormCheckbox=_0=>{let{name,validation={}}=_0,checkboxProps=_object_without_properties(_0,["name","validation"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formErrors=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formErrors===null||formErrors===void 0?void 0:formErrors.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Checkbox,_object_spread_props(_object_spread({},checkboxProps,register(name,{validate:validation,disabled:checkboxProps.disabled})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
2
2
  //# sourceMappingURL=Checkbox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/Checkbox/Checkbox.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport React, { forwardRef } from \"react\"\nimport { Checkbox as CheckboxMantine, CheckboxProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl, useErrorContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport classes from \"./Checkbox.module.css\"\n\nconst useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n return {\n ...defaultFormStyles,\n label: `${defaultFormStyles.label} ${classes.label}`,\n }\n}\n\n/**\n * Provides a Checkbox component\n * @param color Color string\n * @param CheckboxProps Additional props as defined by Mantine\n */\n// eslint-disable-next-line react/display-name\nexport const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(({ ...props }, ref) => {\n const classes = useStyles()\n return (\n <CheckboxMantine\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n }}\n {...props}\n />\n )\n})\n\n/**\n * **Form** wrapper for a checkbox component that automatically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show client-side and server-side validation errors.\n * @param name Name of the checkbox\n * @param validation Validation rules for the client-side validation\n * @param checkboxProps Props passed to checkbox component\n */\nexport const FormCheckbox: React.FC<CheckboxProps & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n ...checkboxProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n\n const formErrors = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formErrors?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Checkbox\n {...checkboxProps}\n {...register(name, {\n validate: validation,\n disabled: checkboxProps.disabled,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["React","forwardRef","Checkbox","CheckboxMantine","getDefaultFormStyles","useFormContext","useErrorContext","FormErrors","classes","useStyles","defaultFormStyles","label","props","ref","classNames","root","input","FormCheckbox","name","validation","checkboxProps","register","formState","errorContext","formErrors","errors","fetchErrors","message","flat","filter","ent","validate","disabled","error","length"],"mappings":"8kFAIA,QAAOA,OAASC,UAAU,KAAQ,OAAO,AACzC,QAASC,YAAYC,eAAe,KAAuB,eAAe,AAC1E,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAC7C,QAAuBC,eAAe,KAAQ,SAAS,AACvD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAAOC,YAAa,uBAAuB,CAE3C,MAAMC,UAAY,KAChB,MAAMC,kBAAoBN,uBAC1B,OAAO,uCACFM,oBACHC,MAAO,CAAC,EAAED,kBAAkBC,KAAK,CAAC,CAAC,EAAEH,QAAQG,KAAK,CAAC,CAAC,EAExD,CAQA,QAAO,MAAMT,SAAWD,WAA4C,iDAAC,EAAY,OAAPW,0BAASC,WACjF,MAAML,QAAUC,YAChB,OACE,KAACN,gCACCU,IAAKA,IACLC,WAAY,CACVC,KAAMP,QAAQO,IAAI,CAClBJ,MAAOH,QAAQG,KAAK,CACpBK,MAAOR,QAAQQ,KAAK,AACtB,GACIJ,OAGV,EAAE,AASF,QAAO,MAAMK,aAAyE,QAAC,CACrFC,IAAI,CACJC,WAAa,CAAC,CAAC,CAEhB,IADIC,mEAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGjB,iBAChC,MAAMkB,aAAejB,kBAErB,MAAMkB,WAAaF,UAAUG,MAAM,CAACP,KAAK,CACzC,MAAMQ,YAAcH,aAAaE,MAAM,CAACP,KAAK,CAC7C,MAAMO,OAAS,CAACD,mBAAAA,2BAAAA,WAAYG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAEnF,OACE,KAAC5B,gDACKkB,cACAC,SAASH,KAAM,CACjBa,SAAUZ,WACVa,SAAUZ,cAAcY,QAAQ,AAClC,KACAC,MAAOR,OAAOS,MAAM,CAAG,GAAK,KAAC3B,YAAWkB,OAAQA,WAGtD,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/Checkbox/Checkbox.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport React, { forwardRef } from \"react\"\nimport { Checkbox as CheckboxMantine, CheckboxProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl, useErrorContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport classes from \"./Checkbox.module.css\"\n\nconst useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n return {\n ...defaultFormStyles,\n label: `${defaultFormStyles.label} ${classes.label}`,\n }\n}\n\n/**\n * Provides a Checkbox component\n * @param color Color string\n * @param CheckboxProps Additional props as defined by Mantine\n */\n// eslint-disable-next-line react/display-name\nexport const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(({ ...props }, ref) => {\n const classes = useStyles()\n return (\n <CheckboxMantine\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n }}\n {...props}\n />\n )\n})\n\n/**\n * **Form** wrapper for a checkbox component that automatically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show client-side and server-side validation errors.\n * @param name Name of the checkbox\n * @param validation Validation rules for the client-side validation\n * @param checkboxProps Props passed to checkbox component\n */\nexport const FormCheckbox: React.FC<CheckboxProps & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n ...checkboxProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n\n const formErrors = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formErrors?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Checkbox\n {...checkboxProps}\n {...register(name, {\n validate: validation,\n disabled: checkboxProps.disabled,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["React","forwardRef","Checkbox","CheckboxMantine","getDefaultFormStyles","useFormContext","useErrorContext","FormErrors","classes","useStyles","defaultFormStyles","label","props","ref","classNames","root","input","FormCheckbox","name","validation","checkboxProps","register","formState","errorContext","formErrors","errors","fetchErrors","message","flat","filter","ent","validate","disabled","error","length"],"mappings":"slFAIA,QAAOA,OAASC,UAAU,KAAQ,OAAO,AACzC,QAASC,YAAYC,eAAe,KAAuB,eAAe,AAC1E,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAC7C,QAAuBC,eAAe,KAAQ,SAAS,AACvD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAAOC,YAAa,uBAAuB,CAE3C,MAAMC,UAAY,KAChB,MAAMC,kBAAoBN,uBAC1B,OAAO,uCACFM,oBACHC,MAAO,CAAC,EAAED,kBAAkBC,KAAK,CAAC,CAAC,EAAEH,QAAQG,KAAK,CAAC,CAAC,EAExD,CAQA,QAAO,MAAMT,SAAWD,WAA4C,iDAAC,EAAY,OAAPW,0BAASC,WACjF,MAAML,QAAUC,YAChB,OACE,KAACN,gCACCU,IAAKA,IACLC,WAAY,CACVC,KAAMP,QAAQO,IAAI,CAClBJ,MAAOH,QAAQG,KAAK,CACpBK,MAAOR,QAAQQ,KAAK,AACtB,GACIJ,OAGV,EAAE,AASF,QAAO,MAAMK,aAAyE,QAAC,CACrFC,IAAI,CACJC,WAAa,CAAC,CAAC,CAEhB,IADIC,mEAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGjB,iBAChC,MAAMkB,aAAejB,kBAErB,MAAMkB,WAAaF,UAAUG,MAAM,CAACP,KAAK,CACzC,MAAMQ,YAAcH,aAAaE,MAAM,CAACP,KAAK,CAC7C,MAAMO,OAAS,CAACD,mBAAAA,2BAAAA,WAAYG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAEnF,OACE,KAAC5B,gDACKkB,cACAC,SAASH,KAAM,CACjBa,SAAUZ,WACVa,SAAUZ,cAAcY,QAAQ,AAClC,KACAC,MAAOR,OAAOS,MAAM,CAAG,GAAK,KAAC3B,YAAWkB,OAAQA,WAGtD,CAAC"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{DateTimePicker as MantineDateTimePicker}from"@mantine/dates";import{Controller}from"react-hook-form";import{CalendarDays}from"lucide-react";import{useErrorContext,useFormContext}from"..";import{FormErrors}from"../Form/FormErrors";import{getDefaultFormStyles}from"../sharedStyles";import{DateTimePickerOnly}from"./DateTimePickerOnly";import{useTranslation}from"react-i18next";import{getDayJsFormatString}from"../../../helper";import classes from"./DateTimePicker.module.css";import{ICON_SIZES}from"../../../theme";import"@mantine/dates/styles.layer.css";import"@mantine/dates/styles.css";import{useRef}from"react";export const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{icon:classes.displayNone,displayNone:classes.displayNone})};const DateTimePickerRaw=_0=>{let{onChange,size="md"}=_0,props=_object_without_properties(_0,["onChange","size"]);const classes=useStyles();const{i18n}=useTranslation();const language=i18n.language||"en";const Component=props.dateOnly?DateTimePickerOnly:MantineDateTimePicker;const pickerInputRef=useRef(null);return _jsx(Component,_object_spread_props(_object_spread({placeholder:"",locale:language,rightSection:_jsx(CalendarDays,{color:"var(--mantine-color-gray-5)",onClick:()=>{var _pickerInputRef_current;return(_pickerInputRef_current=pickerInputRef.current)===null||_pickerInputRef_current===void 0?void 0:_pickerInputRef_current.click()},size:ICON_SIZES.MEDIUM,style:{cursor:"pointer"}})},props),{ref:pickerInputRef,size:size,classNames:_object_spread({input:classes.input,label:classes.label,root:classes.root},props.classNames),onChange:e=>onChange===null||onChange===void 0?void 0:onChange(e?new Date(e).getTime():0),valueFormat:getDayJsFormatString(language)}))};const DateTimePicker=DateTimePickerRaw;const FormDatetimePicker=_0=>{let{name,size="md"}=_0,props=_object_without_properties(_0,["name","size"]);const form=useFormContext();const _form_register=form.register(name,{validate:props.validation,disabled:props.disabled}),{onChange}=_form_register,register=_object_without_properties(_form_register,["onChange"]);const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{render:({field})=>_jsx(DateTimePicker,_object_spread_props(_object_spread({value:field.value?new Date(parseInt(field.value)):undefined,size:size},props,register),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:timestamp=>{onChange({target:{value:timestamp,name}})}})),defaultValue:props.defaultValue,control:form.control,name:name})};export{DateTimePicker,FormDatetimePicker};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{DateTimePicker as MantineDateTimePicker}from"@mantine/dates";import{Controller}from"react-hook-form";import{CalendarDays}from"lucide-react";import{useErrorContext,useFormContext}from"..";import{FormErrors}from"../Form/FormErrors";import{getDefaultFormStyles}from"../sharedStyles";import{DateTimePickerOnly}from"./DateTimePickerOnly";import{useTranslation}from"react-i18next";import{getDayJsFormatString}from"../../../helper";import classes from"./DateTimePicker.module.css";import{ICON_SIZES}from"../../../theme";import"@mantine/dates/styles.layer.css";import"@mantine/dates/styles.css";import{useRef}from"react";export const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{icon:classes.displayNone,displayNone:classes.displayNone})};const DateTimePickerRaw=_0=>{let{onChange,size="md"}=_0,props=_object_without_properties(_0,["onChange","size"]);const classes=useStyles();const{i18n}=useTranslation();const language=i18n.language||"en";const Component=props.dateOnly?DateTimePickerOnly:MantineDateTimePicker;const pickerInputRef=useRef(null);return _jsx(Component,_object_spread_props(_object_spread({placeholder:"",locale:language,rightSection:_jsx(CalendarDays,{color:"var(--mantine-color-gray-5)",onClick:()=>{var _pickerInputRef_current;return(_pickerInputRef_current=pickerInputRef.current)===null||_pickerInputRef_current===void 0?void 0:_pickerInputRef_current.click()},size:ICON_SIZES.MEDIUM,style:{cursor:"pointer"}})},props),{ref:pickerInputRef,size:size,classNames:_object_spread({input:classes.input,label:classes.label,root:classes.root},props.classNames),onChange:e=>onChange===null||onChange===void 0?void 0:onChange(e?new Date(e).getTime():0),valueFormat:getDayJsFormatString(language)}))};const DateTimePicker=DateTimePickerRaw;const FormDatetimePicker=_0=>{let{name,size="md"}=_0,props=_object_without_properties(_0,["name","size"]);const form=useFormContext();const _form_register=form.register(name,{validate:props.validation,disabled:props.disabled}),{onChange}=_form_register,register=_object_without_properties(_form_register,["onChange"]);const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{render:({field})=>_jsx(DateTimePicker,_object_spread_props(_object_spread({value:field.value?new Date(parseInt(field.value)):undefined,size:size},props,register),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:timestamp=>{onChange({target:{value:timestamp,name}})}})),defaultValue:props.defaultValue,control:form.control,name:name})};export{DateTimePicker,FormDatetimePicker};
2
2
  //# sourceMappingURL=DateTimePicker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/DateTimePicker/DateTimePicker.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { DateTimePicker as MantineDateTimePicker, DateTimePickerProps } from \"@mantine/dates\"\nimport { Controller } from \"react-hook-form\"\nimport { CalendarDays } from \"lucide-react\"\nimport { TFormControl } from \"../Form\"\nimport { useErrorContext, useFormContext } from \"..\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { DateTimePickerOnly } from \"./DateTimePickerOnly\"\nimport { useTranslation } from \"react-i18next\"\nimport { getDayJsFormatString } from \"../../../helper\"\nimport { ELanguage } from \"../../../helper/Language\"\nimport classes from \"./DateTimePicker.module.css\"\nimport { ICON_SIZES } from \"../../../theme\"\nimport \"@mantine/dates/styles.layer.css\"\nimport \"@mantine/dates/styles.css\"\nimport { useRef } from \"react\"\n\nexport const useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n\n return {\n ...defaultFormStyles,\n icon: classes.displayNone,\n displayNone: classes.displayNone,\n }\n}\n\nexport type TDatetimePickerProps = Omit<DateTimePickerProps, \"onChange\"> & {\n onChange?: (timestamp: number) => void\n dateOnly?: boolean\n placeholder?: string\n}\n/**\n * Provides a raw DateTimePicker component\n * @param size Size of the DateTimePicker using sm, md or lg\n * @param dateOnly Control if only the date should be shown, omitting time\n * @param placeholder A placeholder string used in the component\n * @param onChange callback when date or time are changed\n */\nconst DateTimePickerRaw = ({ onChange, size = \"md\", ...props }: TDatetimePickerProps) => {\n const classes = useStyles()\n const { i18n } = useTranslation()\n const language = (i18n.language || \"en\") as ELanguage\n const Component = props.dateOnly ? DateTimePickerOnly : MantineDateTimePicker\n // Create a local ref\n const pickerInputRef = useRef<HTMLButtonElement>(null)\n return (\n <Component\n placeholder={\"\"}\n locale={language}\n rightSection={\n <CalendarDays\n color=\"var(--mantine-color-gray-5)\"\n onClick={() => pickerInputRef.current?.click()} // Use the local ref\n size={ICON_SIZES.MEDIUM}\n style={{ cursor: \"pointer\" }}\n />\n }\n {...props}\n ref={pickerInputRef} // Use the local ref here\n size={size}\n classNames={{\n input: classes.input,\n label: classes.label,\n root: classes.root,\n ...props.classNames,\n }}\n onChange={(e) => onChange?.(e ? new Date(e).getTime() : 0)}\n valueFormat={getDayJsFormatString(language)}\n />\n )\n}\nconst DateTimePicker = DateTimePickerRaw\n\n/**\n * **Form** wrapper for a DatetimePicker component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name name of the DateTimePicker used as identifier in the form\n * @param size Size of the DateTimePicker using sm, md or lg\n * @param DateTimePickerProps Additional props as defined by library DateTimePicker\n * @param onChange callback when date or time are changed\n */\nconst FormDatetimePicker = ({\n name,\n size = \"md\",\n ...props\n}: TDatetimePickerProps & TFormControl<HTMLInputElement>) => {\n const form = useFormContext()\n const { onChange, ...register } = form.register(name, {\n validate: props.validation,\n disabled: props.disabled,\n })\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n render={({ field }) => (\n <DateTimePicker\n value={field.value ? new Date(parseInt(field.value)) : undefined}\n size={size}\n {...props}\n {...register}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={(timestamp) => {\n onChange({\n target: {\n value: timestamp,\n name,\n },\n })\n }}\n />\n )}\n defaultValue={props.defaultValue}\n control={form.control}\n name={name}\n />\n )\n}\n\nexport { DateTimePicker, FormDatetimePicker }\n"],"names":["DateTimePicker","MantineDateTimePicker","Controller","CalendarDays","useErrorContext","useFormContext","FormErrors","getDefaultFormStyles","DateTimePickerOnly","useTranslation","getDayJsFormatString","classes","ICON_SIZES","useRef","useStyles","defaultFormStyles","icon","displayNone","DateTimePickerRaw","onChange","size","props","i18n","language","Component","dateOnly","pickerInputRef","placeholder","locale","rightSection","color","onClick","current","click","MEDIUM","style","cursor","ref","classNames","input","label","root","e","Date","getTime","valueFormat","FormDatetimePicker","name","form","register","validate","validation","disabled","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","render","field","value","parseInt","undefined","error","length","timestamp","target","defaultValue","control"],"mappings":"0zEAIA,QAASA,kBAAkBC,qBAAqB,KAA6B,gBAAgB,AAC7F,QAASC,UAAU,KAAQ,iBAAiB,AAC5C,QAASC,YAAY,KAAQ,cAAc,AAE3C,QAASC,eAAe,CAAEC,cAAc,KAAQ,IAAI,AACpD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,kBAAkB,KAAQ,sBAAsB,AACzD,QAASC,cAAc,KAAQ,eAAe,AAC9C,QAASC,oBAAoB,KAAQ,iBAAiB,AAEtD,QAAOC,YAAa,6BAA6B,AACjD,QAASC,UAAU,KAAQ,gBAAgB,AAC3C,OAAO,iCAAiC,AACxC,OAAO,2BAA2B,AAClC,QAASC,MAAM,KAAQ,OAAO,AAE9B,QAAO,MAAMC,UAAY,KACvB,MAAMC,kBAAoBR,uBAE1B,OAAO,uCACFQ,oBACHC,KAAML,QAAQM,WAAW,CACzBA,YAAaN,QAAQM,WAAW,EAEpC,CAAC,CAcD,MAAMC,kBAAoB,QAAC,CAAEC,QAAQ,CAAEC,KAAO,IAAI,CAAkC,IAA7BC,yDACrD,MAAMV,QAAUG,YAChB,KAAM,CAAEQ,IAAI,CAAE,CAAGb,iBACjB,MAAMc,SAAYD,KAAKC,QAAQ,EAAI,KACnC,MAAMC,UAAYH,MAAMI,QAAQ,CAAGjB,mBAAqBP,sBAExD,MAAMyB,eAAiBb,OAA0B,MACjD,OACE,KAACW,+CACCG,YAAa,GACbC,OAAQL,SACRM,aACE,KAAC1B,cACC2B,MAAM,8BACNC,QAAS,SAAML,+BAAAA,wBAAAA,eAAeM,OAAO,UAAtBN,wCAAAA,wBAAwBO,KAAK,IAC5Cb,KAAMR,WAAWsB,MAAM,CACvBC,MAAO,CAAEC,OAAQ,SAAU,KAG3Bf,QACJgB,IAAKX,eACLN,KAAMA,KACNkB,WAAY,gBACVC,MAAO5B,QAAQ4B,KAAK,CACpBC,MAAO7B,QAAQ6B,KAAK,CACpBC,KAAM9B,QAAQ8B,IAAI,EACfpB,MAAMiB,UAAU,EAErBnB,SAAU,AAACuB,GAAMvB,iBAAAA,yBAAAA,SAAWuB,EAAI,IAAIC,KAAKD,GAAGE,OAAO,GAAK,GACxDC,YAAanC,qBAAqBa,YAGxC,EACA,MAAMvB,eAAiBkB,kBAUvB,MAAM4B,mBAAqB,QAAC,CAC1BC,IAAI,CACJ3B,KAAO,IAAI,CAE2C,IADnDC,qDAEH,MAAM2B,KAAO3C,iBACb,MAAkC2C,eAAAA,KAAKC,QAAQ,CAACF,KAAM,CACpDG,SAAU7B,MAAM8B,UAAU,CAC1BC,SAAU/B,MAAM+B,QAAQ,AAC1B,GAHM,CAAEjC,QAAQ,CAAe,CAAG6B,eAAbC,oCAAaD,6BAIlC,MAAMK,aAAejD,kBAErB,MAAMkD,UAAYN,KAAKO,SAAS,CAACC,MAAM,CAACT,KAAK,CAC7C,MAAMU,YAAcJ,aAAaG,MAAM,CAACT,KAAK,CAC7C,MAAMS,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAAC3D,YACC4D,OAAQ,CAAC,CAAEC,KAAK,CAAE,GAChB,KAAC/D,oDACCgE,MAAOD,MAAMC,KAAK,CAAG,IAAIrB,KAAKsB,SAASF,MAAMC,KAAK,GAAKE,UACvD9C,KAAMA,MACFC,MACA4B,WACJkB,MAAOX,OAAOY,MAAM,CAAG,GAAK,KAAC9D,YAAWkD,OAAQA,SAChDrC,SAAU,AAACkD,YACTlD,SAAS,CACPmD,OAAQ,CACNN,MAAOK,UACPtB,IACF,CACF,EACF,KAGJwB,aAAclD,MAAMkD,YAAY,CAChCC,QAASxB,KAAKwB,OAAO,CACrBzB,KAAMA,MAGZ,CAEA,QAAS/C,cAAc,CAAE8C,kBAAkB,CAAE"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/DateTimePicker/DateTimePicker.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { DateTimePicker as MantineDateTimePicker, DateTimePickerProps } from \"@mantine/dates\"\nimport { Controller } from \"react-hook-form\"\nimport { CalendarDays } from \"lucide-react\"\nimport { TFormControl } from \"../Form\"\nimport { useErrorContext, useFormContext } from \"..\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { DateTimePickerOnly } from \"./DateTimePickerOnly\"\nimport { useTranslation } from \"react-i18next\"\nimport { getDayJsFormatString } from \"../../../helper\"\nimport { ELanguage } from \"../../../helper/Language\"\nimport classes from \"./DateTimePicker.module.css\"\nimport { ICON_SIZES } from \"../../../theme\"\nimport \"@mantine/dates/styles.layer.css\"\nimport \"@mantine/dates/styles.css\"\nimport { useRef } from \"react\"\n\nexport const useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n\n return {\n ...defaultFormStyles,\n icon: classes.displayNone,\n displayNone: classes.displayNone,\n }\n}\n\nexport type TDatetimePickerProps = Omit<DateTimePickerProps, \"onChange\"> & {\n onChange?: (timestamp: number) => void\n dateOnly?: boolean\n placeholder?: string\n}\n/**\n * Provides a raw DateTimePicker component\n * @param size Size of the DateTimePicker using sm, md or lg\n * @param dateOnly Control if only the date should be shown, omitting time\n * @param placeholder A placeholder string used in the component\n * @param onChange callback when date or time are changed\n */\nconst DateTimePickerRaw = ({ onChange, size = \"md\", ...props }: TDatetimePickerProps) => {\n const classes = useStyles()\n const { i18n } = useTranslation()\n const language = (i18n.language || \"en\") as ELanguage\n const Component = props.dateOnly ? DateTimePickerOnly : MantineDateTimePicker\n // Create a local ref\n const pickerInputRef = useRef<HTMLButtonElement>(null)\n return (\n <Component\n placeholder={\"\"}\n locale={language}\n rightSection={\n <CalendarDays\n color=\"var(--mantine-color-gray-5)\"\n onClick={() => pickerInputRef.current?.click()} // Use the local ref\n size={ICON_SIZES.MEDIUM}\n style={{ cursor: \"pointer\" }}\n />\n }\n {...props}\n ref={pickerInputRef} // Use the local ref here\n size={size}\n classNames={{\n input: classes.input,\n label: classes.label,\n root: classes.root,\n ...props.classNames,\n }}\n onChange={(e) => onChange?.(e ? new Date(e).getTime() : 0)}\n valueFormat={getDayJsFormatString(language)}\n />\n )\n}\nconst DateTimePicker = DateTimePickerRaw\n\n/**\n * **Form** wrapper for a DatetimePicker component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name name of the DateTimePicker used as identifier in the form\n * @param size Size of the DateTimePicker using sm, md or lg\n * @param DateTimePickerProps Additional props as defined by library DateTimePicker\n * @param onChange callback when date or time are changed\n */\nconst FormDatetimePicker = ({\n name,\n size = \"md\",\n ...props\n}: TDatetimePickerProps & TFormControl<HTMLInputElement>) => {\n const form = useFormContext()\n const { onChange, ...register } = form.register(name, {\n validate: props.validation,\n disabled: props.disabled,\n })\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n render={({ field }) => (\n <DateTimePicker\n value={field.value ? new Date(parseInt(field.value)) : undefined}\n size={size}\n {...props}\n {...register}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={(timestamp) => {\n onChange({\n target: {\n value: timestamp,\n name,\n },\n })\n }}\n />\n )}\n defaultValue={props.defaultValue}\n control={form.control}\n name={name}\n />\n )\n}\n\nexport { DateTimePicker, FormDatetimePicker }\n"],"names":["DateTimePicker","MantineDateTimePicker","Controller","CalendarDays","useErrorContext","useFormContext","FormErrors","getDefaultFormStyles","DateTimePickerOnly","useTranslation","getDayJsFormatString","classes","ICON_SIZES","useRef","useStyles","defaultFormStyles","icon","displayNone","DateTimePickerRaw","onChange","size","props","i18n","language","Component","dateOnly","pickerInputRef","placeholder","locale","rightSection","color","onClick","current","click","MEDIUM","style","cursor","ref","classNames","input","label","root","e","Date","getTime","valueFormat","FormDatetimePicker","name","form","register","validate","validation","disabled","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","render","field","value","parseInt","undefined","error","length","timestamp","target","defaultValue","control"],"mappings":"k0EAIA,QAASA,kBAAkBC,qBAAqB,KAA6B,gBAAgB,AAC7F,QAASC,UAAU,KAAQ,iBAAiB,AAC5C,QAASC,YAAY,KAAQ,cAAc,AAE3C,QAASC,eAAe,CAAEC,cAAc,KAAQ,IAAI,AACpD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,kBAAkB,KAAQ,sBAAsB,AACzD,QAASC,cAAc,KAAQ,eAAe,AAC9C,QAASC,oBAAoB,KAAQ,iBAAiB,AAEtD,QAAOC,YAAa,6BAA6B,AACjD,QAASC,UAAU,KAAQ,gBAAgB,AAC3C,OAAO,iCAAiC,AACxC,OAAO,2BAA2B,AAClC,QAASC,MAAM,KAAQ,OAAO,AAE9B,QAAO,MAAMC,UAAY,KACvB,MAAMC,kBAAoBR,uBAE1B,OAAO,uCACFQ,oBACHC,KAAML,QAAQM,WAAW,CACzBA,YAAaN,QAAQM,WAAW,EAEpC,CAAC,CAcD,MAAMC,kBAAoB,QAAC,CAAEC,QAAQ,CAAEC,KAAO,IAAI,CAAkC,IAA7BC,yDACrD,MAAMV,QAAUG,YAChB,KAAM,CAAEQ,IAAI,CAAE,CAAGb,iBACjB,MAAMc,SAAYD,KAAKC,QAAQ,EAAI,KACnC,MAAMC,UAAYH,MAAMI,QAAQ,CAAGjB,mBAAqBP,sBAExD,MAAMyB,eAAiBb,OAA0B,MACjD,OACE,KAACW,+CACCG,YAAa,GACbC,OAAQL,SACRM,aACE,KAAC1B,cACC2B,MAAM,8BACNC,QAAS,SAAML,+BAAAA,wBAAAA,eAAeM,OAAO,UAAtBN,wCAAAA,wBAAwBO,KAAK,IAC5Cb,KAAMR,WAAWsB,MAAM,CACvBC,MAAO,CAAEC,OAAQ,SAAU,KAG3Bf,QACJgB,IAAKX,eACLN,KAAMA,KACNkB,WAAY,gBACVC,MAAO5B,QAAQ4B,KAAK,CACpBC,MAAO7B,QAAQ6B,KAAK,CACpBC,KAAM9B,QAAQ8B,IAAI,EACfpB,MAAMiB,UAAU,EAErBnB,SAAU,AAACuB,GAAMvB,iBAAAA,yBAAAA,SAAWuB,EAAI,IAAIC,KAAKD,GAAGE,OAAO,GAAK,GACxDC,YAAanC,qBAAqBa,YAGxC,EACA,MAAMvB,eAAiBkB,kBAUvB,MAAM4B,mBAAqB,QAAC,CAC1BC,IAAI,CACJ3B,KAAO,IAAI,CAE2C,IADnDC,qDAEH,MAAM2B,KAAO3C,iBACb,MAAkC2C,eAAAA,KAAKC,QAAQ,CAACF,KAAM,CACpDG,SAAU7B,MAAM8B,UAAU,CAC1BC,SAAU/B,MAAM+B,QAAQ,AAC1B,GAHM,CAAEjC,QAAQ,CAAe,CAAG6B,eAAbC,oCAAaD,6BAIlC,MAAMK,aAAejD,kBAErB,MAAMkD,UAAYN,KAAKO,SAAS,CAACC,MAAM,CAACT,KAAK,CAC7C,MAAMU,YAAcJ,aAAaG,MAAM,CAACT,KAAK,CAC7C,MAAMS,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAAC3D,YACC4D,OAAQ,CAAC,CAAEC,KAAK,CAAE,GAChB,KAAC/D,oDACCgE,MAAOD,MAAMC,KAAK,CAAG,IAAIrB,KAAKsB,SAASF,MAAMC,KAAK,GAAKE,UACvD9C,KAAMA,MACFC,MACA4B,WACJkB,MAAOX,OAAOY,MAAM,CAAG,GAAK,KAAC9D,YAAWkD,OAAQA,SAChDrC,SAAU,AAACkD,YACTlD,SAAS,CACPmD,OAAQ,CACNN,MAAOK,UACPtB,IACF,CACF,EACF,KAGJwB,aAAclD,MAAMkD,YAAY,CAChCC,QAASxB,KAAKwB,OAAO,CACrBzB,KAAMA,MAGZ,CAEA,QAAS/C,cAAc,CAAE8C,kBAAkB,CAAE"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{TimeInput}from"@mantine/dates";import{forwardRef}from"react";import{useMantineTheme}from"@mantine/core";import{Clock4}from"lucide-react";import{useErrorContext,useFormContext}from"../index";import{Controller}from"react-hook-form";import{FormErrors}from"../Form/FormErrors";import{useStyles}from"./DateTimePicker";const TimePickerRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{onChange}=_ref1,props=_object_without_properties(_ref1,["onChange"]),[ref]=_rest;const classes=useStyles();const theme=useMantineTheme();return _jsx(TimeInput,_object_spread_props(_object_spread({rightSection:_jsx(Clock4,{color:theme.colors.gray[5],size:theme.other.iconSizes.MEDIUM})},props),{ref:ref,classNames:{input:classes.input,label:classes.label},onChange:e=>{onChange===null||onChange===void 0?void 0:onChange(e.target.value)}}))};export const TimePicker=forwardRef(TimePickerRaw);export const FormTimePicker=_0=>{let{name,size="md"}=_0,props=_object_without_properties(_0,["name","size"]);const form=useFormContext();const _form_register=form.register(name,{validate:props.validation,disabled:props.disabled}),{onChange}=_form_register,register=_object_without_properties(_form_register,["onChange"]);const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{render:({field})=>_jsx(TimePicker,_object_spread_props(_object_spread({value:field.value,size:size},props,register),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:timestamp=>{onChange({target:{value:timestamp,name}})}})),disabled:props.disabled,defaultValue:props.defaultValue,control:form.control,name:name})};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{TimeInput}from"@mantine/dates";import{forwardRef}from"react";import{useMantineTheme}from"@mantine/core";import{Clock4}from"lucide-react";import{useErrorContext,useFormContext}from"../index";import{Controller}from"react-hook-form";import{FormErrors}from"../Form/FormErrors";import{useStyles}from"./DateTimePicker";const TimePickerRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{onChange}=_ref1,props=_object_without_properties(_ref1,["onChange"]),[ref]=_rest;const classes=useStyles();const theme=useMantineTheme();return _jsx(TimeInput,_object_spread_props(_object_spread({rightSection:_jsx(Clock4,{color:theme.colors.gray[5],size:theme.other.iconSizes.MEDIUM})},props),{ref:ref,classNames:{input:classes.input,label:classes.label},onChange:e=>{onChange===null||onChange===void 0?void 0:onChange(e.target.value)}}))};export const TimePicker=forwardRef(TimePickerRaw);export const FormTimePicker=_0=>{let{name,size="md"}=_0,props=_object_without_properties(_0,["name","size"]);const form=useFormContext();const _form_register=form.register(name,{validate:props.validation,disabled:props.disabled}),{onChange}=_form_register,register=_object_without_properties(_form_register,["onChange"]);const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{render:({field})=>_jsx(TimePicker,_object_spread_props(_object_spread({value:field.value,size:size},props,register),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:timestamp=>{onChange({target:{value:timestamp,name}})}})),disabled:props.disabled,defaultValue:props.defaultValue,control:form.control,name:name})};
2
2
  //# sourceMappingURL=TimePicker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/DateTimePicker/TimePicker.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { TimeInput, TimeInputProps } from \"@mantine/dates\"\nimport { ForwardedRef, forwardRef } from \"react\"\nimport { useMantineTheme } from \"@mantine/core\"\nimport { Clock4 } from \"lucide-react\"\nimport { TFormControl } from \"../Form/types\"\nimport { useErrorContext, useFormContext } from \"../index\"\nimport { Controller } from \"react-hook-form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { useStyles } from \"./DateTimePicker\"\n\ntype TTimePickerRawProps = Omit<TimeInputProps, \"onChange\"> & {\n onChange?: (value: string) => void\n}\n\n/**\n * Provides a TimePicker component\n * @param onChange Callback when time is changed\n * @param props Additional props as defined by library\n */\nconst TimePickerRaw = (\n { onChange, ...props }: TTimePickerRawProps,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const classes = useStyles()\n const theme = useMantineTheme()\n\n return (\n <TimeInput\n rightSection={<Clock4 color={theme.colors.gray[5]} size={theme.other.iconSizes.MEDIUM} />}\n {...props}\n ref={ref}\n classNames={{\n input: classes.input,\n label: classes.label,\n }}\n onChange={(e) => {\n onChange?.(e.target.value)\n }}\n />\n )\n}\n\nexport const TimePicker = forwardRef(TimePickerRaw)\n\nexport const FormTimePicker = ({\n name,\n size = \"md\",\n ...props\n}: TTimePickerRawProps & TFormControl<HTMLInputElement>) => {\n const form = useFormContext()\n const { onChange, ...register } = form.register(name, {\n validate: props.validation,\n disabled: props.disabled,\n })\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n render={({ field }) => (\n <TimePicker\n value={field.value}\n size={size}\n {...props}\n {...register}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={(timestamp) => {\n onChange({\n target: {\n value: timestamp,\n name,\n },\n })\n }}\n />\n )}\n disabled={props.disabled}\n defaultValue={props.defaultValue}\n control={form.control}\n name={name}\n />\n )\n}\n"],"names":["TimeInput","forwardRef","useMantineTheme","Clock4","useErrorContext","useFormContext","Controller","FormErrors","useStyles","TimePickerRaw","onChange","props","ref","classes","theme","rightSection","color","colors","gray","size","other","iconSizes","MEDIUM","classNames","input","label","e","target","value","TimePicker","FormTimePicker","name","form","register","validate","validation","disabled","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","render","field","error","length","timestamp","defaultValue","control"],"mappings":"0zEAIA,QAASA,SAAS,KAAwB,gBAAgB,AAC1D,QAAuBC,UAAU,KAAQ,OAAO,AAChD,QAASC,eAAe,KAAQ,eAAe,AAC/C,QAASC,MAAM,KAAQ,cAAc,AAErC,QAASC,eAAe,CAAEC,cAAc,KAAQ,UAAU,AAC1D,QAASC,UAAU,KAAQ,iBAAiB,AAC5C,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,SAAS,KAAQ,kBAAkB,CAW5C,MAAMC,cAAgB,iDACpB,CAAEC,QAAQ,CAAiC,OAA5BC,sDACfC,WAEA,MAAMC,QAAUL,YAChB,MAAMM,MAAQZ,kBAEd,OACE,KAACF,+CACCe,aAAc,KAACZ,QAAOa,MAAOF,MAAMG,MAAM,CAACC,IAAI,CAAC,EAAE,CAAEC,KAAML,MAAMM,KAAK,CAACC,SAAS,CAACC,MAAM,IACjFX,QACJC,IAAKA,IACLW,WAAY,CACVC,MAAOX,QAAQW,KAAK,CACpBC,MAAOZ,QAAQY,KAAK,AACtB,EACAf,SAAU,AAACgB,IACThB,iBAAAA,yBAAAA,SAAWgB,EAAEC,MAAM,CAACC,KAAK,CAC3B,IAGN,CAEA,QAAO,MAAMC,WAAa5B,WAAWQ,cAAc,AAEnD,QAAO,MAAMqB,eAAiB,QAAC,CAC7BC,IAAI,CACJZ,KAAO,IAAI,CAE0C,IADlDR,qDAEH,MAAMqB,KAAO3B,iBACb,MAAkC2B,eAAAA,KAAKC,QAAQ,CAACF,KAAM,CACpDG,SAAUvB,MAAMwB,UAAU,CAC1BC,SAAUzB,MAAMyB,QAAQ,AAC1B,GAHM,CAAE1B,QAAQ,CAAe,CAAGsB,eAAbC,oCAAaD,6BAIlC,MAAMK,aAAejC,kBAErB,MAAMkC,UAAYN,KAAKO,SAAS,CAACC,MAAM,CAACT,KAAK,CAC7C,MAAMU,YAAcJ,aAAaG,MAAM,CAACT,KAAK,CAE7C,MAAMS,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAACvC,YACCwC,OAAQ,CAAC,CAAEC,KAAK,CAAE,GAChB,KAAClB,gDACCD,MAAOmB,MAAMnB,KAAK,CAClBT,KAAMA,MACFR,MACAsB,WACJe,MAAOR,OAAOS,MAAM,CAAG,GAAK,KAAC1C,YAAWiC,OAAQA,SAChD9B,SAAU,AAACwC,YACTxC,SAAS,CACPiB,OAAQ,CACNC,MAAOsB,UACPnB,IACF,CACF,EACF,KAGJK,SAAUzB,MAAMyB,QAAQ,CACxBe,aAAcxC,MAAMwC,YAAY,CAChCC,QAASpB,KAAKoB,OAAO,CACrBrB,KAAMA,MAGZ,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/DateTimePicker/TimePicker.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { TimeInput, TimeInputProps } from \"@mantine/dates\"\nimport { ForwardedRef, forwardRef } from \"react\"\nimport { useMantineTheme } from \"@mantine/core\"\nimport { Clock4 } from \"lucide-react\"\nimport { TFormControl } from \"../Form/types\"\nimport { useErrorContext, useFormContext } from \"../index\"\nimport { Controller } from \"react-hook-form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { useStyles } from \"./DateTimePicker\"\n\ntype TTimePickerRawProps = Omit<TimeInputProps, \"onChange\"> & {\n onChange?: (value: string) => void\n}\n\n/**\n * Provides a TimePicker component\n * @param onChange Callback when time is changed\n * @param props Additional props as defined by library\n */\nconst TimePickerRaw = (\n { onChange, ...props }: TTimePickerRawProps,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const classes = useStyles()\n const theme = useMantineTheme()\n\n return (\n <TimeInput\n rightSection={<Clock4 color={theme.colors.gray[5]} size={theme.other.iconSizes.MEDIUM} />}\n {...props}\n ref={ref}\n classNames={{\n input: classes.input,\n label: classes.label,\n }}\n onChange={(e) => {\n onChange?.(e.target.value)\n }}\n />\n )\n}\n\nexport const TimePicker = forwardRef(TimePickerRaw)\n\nexport const FormTimePicker = ({\n name,\n size = \"md\",\n ...props\n}: TTimePickerRawProps & TFormControl<HTMLInputElement>) => {\n const form = useFormContext()\n const { onChange, ...register } = form.register(name, {\n validate: props.validation,\n disabled: props.disabled,\n })\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n render={({ field }) => (\n <TimePicker\n value={field.value}\n size={size}\n {...props}\n {...register}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={(timestamp) => {\n onChange({\n target: {\n value: timestamp,\n name,\n },\n })\n }}\n />\n )}\n disabled={props.disabled}\n defaultValue={props.defaultValue}\n control={form.control}\n name={name}\n />\n )\n}\n"],"names":["TimeInput","forwardRef","useMantineTheme","Clock4","useErrorContext","useFormContext","Controller","FormErrors","useStyles","TimePickerRaw","onChange","props","ref","classes","theme","rightSection","color","colors","gray","size","other","iconSizes","MEDIUM","classNames","input","label","e","target","value","TimePicker","FormTimePicker","name","form","register","validate","validation","disabled","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","render","field","error","length","timestamp","defaultValue","control"],"mappings":"k0EAIA,QAASA,SAAS,KAAwB,gBAAgB,AAC1D,QAAuBC,UAAU,KAAQ,OAAO,AAChD,QAASC,eAAe,KAAQ,eAAe,AAC/C,QAASC,MAAM,KAAQ,cAAc,AAErC,QAASC,eAAe,CAAEC,cAAc,KAAQ,UAAU,AAC1D,QAASC,UAAU,KAAQ,iBAAiB,AAC5C,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,SAAS,KAAQ,kBAAkB,CAW5C,MAAMC,cAAgB,iDACpB,CAAEC,QAAQ,CAAiC,OAA5BC,sDACfC,WAEA,MAAMC,QAAUL,YAChB,MAAMM,MAAQZ,kBAEd,OACE,KAACF,+CACCe,aAAc,KAACZ,QAAOa,MAAOF,MAAMG,MAAM,CAACC,IAAI,CAAC,EAAE,CAAEC,KAAML,MAAMM,KAAK,CAACC,SAAS,CAACC,MAAM,IACjFX,QACJC,IAAKA,IACLW,WAAY,CACVC,MAAOX,QAAQW,KAAK,CACpBC,MAAOZ,QAAQY,KAAK,AACtB,EACAf,SAAU,AAACgB,IACThB,iBAAAA,yBAAAA,SAAWgB,EAAEC,MAAM,CAACC,KAAK,CAC3B,IAGN,CAEA,QAAO,MAAMC,WAAa5B,WAAWQ,cAAc,AAEnD,QAAO,MAAMqB,eAAiB,QAAC,CAC7BC,IAAI,CACJZ,KAAO,IAAI,CAE0C,IADlDR,qDAEH,MAAMqB,KAAO3B,iBACb,MAAkC2B,eAAAA,KAAKC,QAAQ,CAACF,KAAM,CACpDG,SAAUvB,MAAMwB,UAAU,CAC1BC,SAAUzB,MAAMyB,QAAQ,AAC1B,GAHM,CAAE1B,QAAQ,CAAe,CAAGsB,eAAbC,oCAAaD,6BAIlC,MAAMK,aAAejC,kBAErB,MAAMkC,UAAYN,KAAKO,SAAS,CAACC,MAAM,CAACT,KAAK,CAC7C,MAAMU,YAAcJ,aAAaG,MAAM,CAACT,KAAK,CAE7C,MAAMS,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAACvC,YACCwC,OAAQ,CAAC,CAAEC,KAAK,CAAE,GAChB,KAAClB,gDACCD,MAAOmB,MAAMnB,KAAK,CAClBT,KAAMA,MACFR,MACAsB,WACJe,MAAOR,OAAOS,MAAM,CAAG,GAAK,KAAC1C,YAAWiC,OAAQA,SAChD9B,SAAU,AAACwC,YACTxC,SAAS,CACPiB,OAAQ,CACNC,MAAOsB,UACPnB,IACF,CACF,EACF,KAGJK,SAAUzB,MAAMyB,QAAQ,CACxBe,aAAcxC,MAAMwC,YAAY,CAChCC,QAASpB,KAAKoB,OAAO,CACrBrB,KAAMA,MAGZ,CAAC"}
@@ -1,2 +1,2 @@
1
- function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{FileInput as FileInputMantine}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import React from"react";import{useErrorContext,useFormContext}from"../Form";import{Controller}from"react-hook-form";import{FormErrors}from"../Form/FormErrors";import{UploadIcon}from"lucide-react";import classes from"./FileInput.module.css";const FileInputRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;var _props_value;const defaultStyles=getDefaultFormStyles();return _jsx(FileInputMantine,_object_spread({ref:ref,classNames:{root:defaultStyles.root,label:defaultStyles.label,input:`${defaultStyles.input} ${classes.input}`,error:defaultStyles.error,section:classes.section},size:size,clearable:(props===null||props===void 0?void 0:(_props_value=props.value)===null||_props_value===void 0?void 0:_props_value.value)!=="",leftSection:_jsx(UploadIcon,{size:14})},props))};export const FileInput=React.forwardRef(FileInputRaw);const convertBase64=file=>{return new Promise((resolve,reject)=>{const fileReader=new FileReader;fileReader.readAsDataURL(file);fileReader.onload=()=>{if(typeof fileReader.result==="string"){const[,base64String]=fileReader.result.split(",");resolve(base64String)}};fileReader.onerror=error=>{reject(error)}})};export const FormFileInput=_0=>{let{name}=_0,props=_object_without_properties(_0,["name"]);const form=useFormContext();const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{control:form.control,name:name,rules:{validate:props.validation},disabled:props.disabled,render:_0=>{let{field:_ref}=_0,{onChange}=_ref,field=_object_without_properties(_ref,["onChange"]);return _jsx(FileInput,_object_spread_props(_object_spread({},field,props),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:file=>_async_to_generator(function*(){const fileValue=file?{name:file.name,value:yield convertBase64(file)}:"";onChange(fileValue)})()}))}})};
1
+ function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{FileInput as FileInputMantine}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import React from"react";import{useErrorContext,useFormContext}from"../Form";import{Controller}from"react-hook-form";import{FormErrors}from"../Form/FormErrors";import{UploadIcon}from"lucide-react";import classes from"./FileInput.module.css";const FileInputRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;var _props_value;const defaultStyles=getDefaultFormStyles();return _jsx(FileInputMantine,_object_spread({ref:ref,classNames:{root:defaultStyles.root,label:defaultStyles.label,input:`${defaultStyles.input} ${classes.input}`,error:defaultStyles.error,section:classes.section},size:size,clearable:(props===null||props===void 0?void 0:(_props_value=props.value)===null||_props_value===void 0?void 0:_props_value.value)!=="",leftSection:_jsx(UploadIcon,{size:14})},props))};export const FileInput=React.forwardRef(FileInputRaw);const convertBase64=file=>{return new Promise((resolve,reject)=>{const fileReader=new FileReader;fileReader.readAsDataURL(file);fileReader.onload=()=>{if(typeof fileReader.result==="string"){const[,base64String]=fileReader.result.split(",");resolve(base64String)}};fileReader.onerror=error=>{reject(error)}})};export const FormFileInput=_0=>{let{name}=_0,props=_object_without_properties(_0,["name"]);const form=useFormContext();const errorContext=useErrorContext();const formError=form.formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Controller,{control:form.control,name:name,rules:{validate:props.validation},disabled:props.disabled,render:_0=>{let{field:_ref}=_0,{onChange}=_ref,field=_object_without_properties(_ref,["onChange"]);return _jsx(FileInput,_object_spread_props(_object_spread({},field,props),{error:errors.length>0&&_jsx(FormErrors,{errors:errors}),onChange:file=>_async_to_generator(function*(){const fileValue=file?{name:file.name,value:yield convertBase64(file)}:"";onChange(fileValue)})()}))}})};
2
2
  //# sourceMappingURL=FileInput.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/FileInput/FileInput.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { FileInput as FileInputMantine, FileInputProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport React, { ForwardedRef } from \"react\"\nimport { useErrorContext, useFormContext } from \"../Form\"\nimport { Controller } from \"react-hook-form\"\nimport { TFormControl } from \"../Form/types\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { UploadIcon } from \"lucide-react\"\nimport classes from \"./FileInput.module.css\"\n\n/**\n * Provides a raw FileInput component\n * @param size Size of the FileInput based on sm, md, and lg\n * @param FileInputProps Additional props as defined by library\n */\nconst FileInputRaw = ({ size = \"md\", ...props }, ref: ForwardedRef<HTMLButtonElement>) => {\n const defaultStyles = getDefaultFormStyles()\n\n return (\n <FileInputMantine\n ref={ref}\n classNames={{\n root: defaultStyles.root,\n label: defaultStyles.label,\n input: `${defaultStyles.input} ${classes.input}`,\n error: defaultStyles.error,\n section: classes.section,\n }}\n size={size}\n clearable={props?.value?.value !== \"\"}\n leftSection={<UploadIcon size={14} />}\n {...props}\n />\n )\n}\n\nexport const FileInput = React.forwardRef(FileInputRaw)\n\nconst convertBase64 = (file: File): Promise<string> => {\n return new Promise((resolve, reject) => {\n const fileReader = new FileReader()\n fileReader.readAsDataURL(file)\n\n fileReader.onload = () => {\n if (typeof fileReader.result === \"string\") {\n const [, base64String] = fileReader.result.split(\",\")\n resolve(base64String)\n }\n }\n fileReader.onerror = (error) => {\n reject(error)\n }\n })\n}\n\n/**\n * **Form** wrapper for a FileInput component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name name of the input used as identifier in the form\n * @param size Size of the input using sm, md or lg\n * @param FileInputProps Additional props as defined by Mantine FileInput\n */\nexport const FormFileInput: React.FC<FileInputProps & TFormControl<HTMLInputElement>> = ({\n name,\n ...props\n}) => {\n const form = useFormContext()\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n control={form.control}\n name={name}\n rules={{\n validate: props.validation,\n }}\n disabled={props.disabled}\n render={({ field: { onChange, ...field } }) => (\n <FileInput\n {...field}\n {...props}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={async (file: File) => {\n const fileValue = file\n ? {\n name: file.name,\n value: await convertBase64(file),\n }\n : \"\"\n onChange(fileValue)\n }}\n />\n )}\n />\n )\n}\n"],"names":["FileInput","FileInputMantine","getDefaultFormStyles","React","useErrorContext","useFormContext","Controller","FormErrors","UploadIcon","classes","FileInputRaw","size","props","ref","defaultStyles","classNames","root","label","input","error","section","clearable","value","leftSection","forwardRef","convertBase64","file","Promise","resolve","reject","fileReader","FileReader","readAsDataURL","onload","result","base64String","split","onerror","FormFileInput","name","form","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","control","rules","validate","validation","disabled","render","field","onChange","length","fileValue"],"mappings":"s3FAIA,QAASA,aAAaC,gBAAgB,KAAwB,eAAe,AAC7E,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAAOC,UAA6B,OAAO,AAC3C,QAASC,eAAe,CAAEC,cAAc,KAAQ,SAAS,AACzD,QAASC,UAAU,KAAQ,iBAAiB,AAE5C,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,UAAU,KAAQ,cAAc,AACzC,QAAOC,YAAa,wBAAwB,CAO5C,MAAMC,aAAe,iDAAC,CAAEC,KAAO,IAAI,CAAY,OAAPC,kDAASC,eAchCD,aAbf,MAAME,cAAgBZ,uBAEtB,OACE,KAACD,iCACCY,IAAKA,IACLE,WAAY,CACVC,KAAMF,cAAcE,IAAI,CACxBC,MAAOH,cAAcG,KAAK,CAC1BC,MAAO,CAAC,EAAEJ,cAAcI,KAAK,CAAC,CAAC,EAAET,QAAQS,KAAK,CAAC,CAAC,CAChDC,MAAOL,cAAcK,KAAK,CAC1BC,QAASX,QAAQW,OAAO,AAC1B,EACAT,KAAMA,KACNU,UAAWT,CAAAA,cAAAA,uBAAAA,aAAAA,MAAOU,KAAK,UAAZV,6BAAAA,aAAcU,KAAK,IAAK,GACnCC,YAAa,KAACf,YAAWG,KAAM,MAC3BC,OAGV,CAEA,QAAO,MAAMZ,UAAYG,MAAMqB,UAAU,CAACd,aAAa,CAEvD,MAAMe,cAAgB,AAACC,OACrB,OAAO,IAAIC,QAAQ,CAACC,QAASC,UAC3B,MAAMC,WAAa,IAAIC,WACvBD,WAAWE,aAAa,CAACN,KAEzBI,CAAAA,WAAWG,MAAM,CAAG,KAClB,GAAI,OAAOH,WAAWI,MAAM,GAAK,SAAU,CACzC,KAAM,EAAGC,aAAa,CAAGL,WAAWI,MAAM,CAACE,KAAK,CAAC,KACjDR,QAAQO,aACV,CACF,CACAL,CAAAA,WAAWO,OAAO,CAAG,AAAClB,QACpBU,OAAOV,MACT,CACF,EACF,CASA,QAAO,MAAMmB,cAA2E,QAAC,CACvFC,IAAI,CAEL,IADI3B,8CAEH,MAAM4B,KAAOnC,iBACb,MAAMoC,aAAerC,kBAErB,MAAMsC,UAAYF,KAAKG,SAAS,CAACC,MAAM,CAACL,KAAK,CAC7C,MAAMM,YAAcJ,aAAaG,MAAM,CAACL,KAAK,CAE7C,MAAMK,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAAC3C,YACC4C,QAASV,KAAKU,OAAO,CACrBX,KAAMA,KACNY,MAAO,CACLC,SAAUxC,MAAMyC,UAAU,AAC5B,EACAC,SAAU1C,MAAM0C,QAAQ,CACxBC,OAAQ,QAAC,CAAEC,UAAAA,CAA+B,IAAxB,CAAEC,QAAQ,CAAY,MAAPD,2DAC/B,KAACxD,iDACKwD,MACA5C,QACJO,MAAOyB,OAAOc,MAAM,CAAG,GAAK,KAACnD,YAAWqC,OAAQA,SAChDa,SAAU,AAAO/B,sCACf,MAAMiC,UAAYjC,KACd,CACEa,KAAMb,KAAKa,IAAI,CACfjB,MAAO,MAAMG,cAAcC,KAC7B,EACA,GACJ+B,SAASE,UACX,UAKV,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/FileInput/FileInput.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { FileInput as FileInputMantine, FileInputProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport React, { ForwardedRef } from \"react\"\nimport { useErrorContext, useFormContext } from \"../Form\"\nimport { Controller } from \"react-hook-form\"\nimport { TFormControl } from \"../Form/types\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { UploadIcon } from \"lucide-react\"\nimport classes from \"./FileInput.module.css\"\n\n/**\n * Provides a raw FileInput component\n * @param size Size of the FileInput based on sm, md, and lg\n * @param FileInputProps Additional props as defined by library\n */\nconst FileInputRaw = ({ size = \"md\", ...props }, ref: ForwardedRef<HTMLButtonElement>) => {\n const defaultStyles = getDefaultFormStyles()\n\n return (\n <FileInputMantine\n ref={ref}\n classNames={{\n root: defaultStyles.root,\n label: defaultStyles.label,\n input: `${defaultStyles.input} ${classes.input}`,\n error: defaultStyles.error,\n section: classes.section,\n }}\n size={size}\n clearable={props?.value?.value !== \"\"}\n leftSection={<UploadIcon size={14} />}\n {...props}\n />\n )\n}\n\nexport const FileInput = React.forwardRef(FileInputRaw)\n\nconst convertBase64 = (file: File): Promise<string> => {\n return new Promise((resolve, reject) => {\n const fileReader = new FileReader()\n fileReader.readAsDataURL(file)\n\n fileReader.onload = () => {\n if (typeof fileReader.result === \"string\") {\n const [, base64String] = fileReader.result.split(\",\")\n resolve(base64String)\n }\n }\n fileReader.onerror = (error) => {\n reject(error)\n }\n })\n}\n\n/**\n * **Form** wrapper for a FileInput component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name name of the input used as identifier in the form\n * @param size Size of the input using sm, md or lg\n * @param FileInputProps Additional props as defined by Mantine FileInput\n */\nexport const FormFileInput: React.FC<FileInputProps & TFormControl<HTMLInputElement>> = ({\n name,\n ...props\n}) => {\n const form = useFormContext()\n const errorContext = useErrorContext()\n\n const formError = form.formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Controller\n control={form.control}\n name={name}\n rules={{\n validate: props.validation,\n }}\n disabled={props.disabled}\n render={({ field: { onChange, ...field } }) => (\n <FileInput\n {...field}\n {...props}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n onChange={async (file: File) => {\n const fileValue = file\n ? {\n name: file.name,\n value: await convertBase64(file),\n }\n : \"\"\n onChange(fileValue)\n }}\n />\n )}\n />\n )\n}\n"],"names":["FileInput","FileInputMantine","getDefaultFormStyles","React","useErrorContext","useFormContext","Controller","FormErrors","UploadIcon","classes","FileInputRaw","size","props","ref","defaultStyles","classNames","root","label","input","error","section","clearable","value","leftSection","forwardRef","convertBase64","file","Promise","resolve","reject","fileReader","FileReader","readAsDataURL","onload","result","base64String","split","onerror","FormFileInput","name","form","errorContext","formError","formState","errors","fetchErrors","message","flat","filter","ent","control","rules","validate","validation","disabled","render","field","onChange","length","fileValue"],"mappings":"83FAIA,QAASA,aAAaC,gBAAgB,KAAwB,eAAe,AAC7E,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAAOC,UAA6B,OAAO,AAC3C,QAASC,eAAe,CAAEC,cAAc,KAAQ,SAAS,AACzD,QAASC,UAAU,KAAQ,iBAAiB,AAE5C,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,UAAU,KAAQ,cAAc,AACzC,QAAOC,YAAa,wBAAwB,CAO5C,MAAMC,aAAe,iDAAC,CAAEC,KAAO,IAAI,CAAY,OAAPC,kDAASC,eAchCD,aAbf,MAAME,cAAgBZ,uBAEtB,OACE,KAACD,iCACCY,IAAKA,IACLE,WAAY,CACVC,KAAMF,cAAcE,IAAI,CACxBC,MAAOH,cAAcG,KAAK,CAC1BC,MAAO,CAAC,EAAEJ,cAAcI,KAAK,CAAC,CAAC,EAAET,QAAQS,KAAK,CAAC,CAAC,CAChDC,MAAOL,cAAcK,KAAK,CAC1BC,QAASX,QAAQW,OAAO,AAC1B,EACAT,KAAMA,KACNU,UAAWT,CAAAA,cAAAA,uBAAAA,aAAAA,MAAOU,KAAK,UAAZV,6BAAAA,aAAcU,KAAK,IAAK,GACnCC,YAAa,KAACf,YAAWG,KAAM,MAC3BC,OAGV,CAEA,QAAO,MAAMZ,UAAYG,MAAMqB,UAAU,CAACd,aAAa,CAEvD,MAAMe,cAAgB,AAACC,OACrB,OAAO,IAAIC,QAAQ,CAACC,QAASC,UAC3B,MAAMC,WAAa,IAAIC,WACvBD,WAAWE,aAAa,CAACN,KAEzBI,CAAAA,WAAWG,MAAM,CAAG,KAClB,GAAI,OAAOH,WAAWI,MAAM,GAAK,SAAU,CACzC,KAAM,EAAGC,aAAa,CAAGL,WAAWI,MAAM,CAACE,KAAK,CAAC,KACjDR,QAAQO,aACV,CACF,CACAL,CAAAA,WAAWO,OAAO,CAAG,AAAClB,QACpBU,OAAOV,MACT,CACF,EACF,CASA,QAAO,MAAMmB,cAA2E,QAAC,CACvFC,IAAI,CAEL,IADI3B,8CAEH,MAAM4B,KAAOnC,iBACb,MAAMoC,aAAerC,kBAErB,MAAMsC,UAAYF,KAAKG,SAAS,CAACC,MAAM,CAACL,KAAK,CAC7C,MAAMM,YAAcJ,aAAaG,MAAM,CAACL,KAAK,CAE7C,MAAMK,OAAS,CAACF,kBAAAA,0BAAAA,UAAWI,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAAC3C,YACC4C,QAASV,KAAKU,OAAO,CACrBX,KAAMA,KACNY,MAAO,CACLC,SAAUxC,MAAMyC,UAAU,AAC5B,EACAC,SAAU1C,MAAM0C,QAAQ,CACxBC,OAAQ,QAAC,CAAEC,UAAAA,CAA+B,IAAxB,CAAEC,QAAQ,CAAY,MAAPD,2DAC/B,KAACxD,iDACKwD,MACA5C,QACJO,MAAOyB,OAAOc,MAAM,CAAG,GAAK,KAACnD,YAAWqC,OAAQA,SAChDa,SAAU,AAAO/B,sCACf,MAAMiC,UAAYjC,KACd,CACEa,KAAMb,KAAKa,IAAI,CACfjB,MAAO,MAAMG,cAAcC,KAC7B,EACA,GACJ+B,SAASE,UACX,UAKV,CAAC"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{forwardRef,useImperativeHandle}from"react";import{useForm as useRHForm,FormProvider as RHFormProvider,useFormContext,useWatch}from"react-hook-form";import classes from"./Form.module.css";export function FormProvider({form,children}){return _jsx(RHFormProvider,_object_spread_props(_object_spread({},form),{children:children}))}function FormRaw(_0,_1){let _ref=[_0,_1],[_ref1,..._rest]=_ref,{onSubmit,children,options}=_ref1,formProps=_object_without_properties(_ref1,["onSubmit","children","options"]),[ref]=_rest;const form=useRHForm(options);useImperativeHandle(ref,()=>({getForm:()=>form}));return _jsx(FormProvider,{form:form,children:_jsx("form",_object_spread_props(_object_spread({onSubmit:form.handleSubmit(args=>onSubmit(args,form)),className:classes.form},formProps),{children:children}))})}const Form=forwardRef(FormRaw);export{useWatch,useFormContext,Form};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{forwardRef,useImperativeHandle}from"react";import{useForm as useRHForm,FormProvider as RHFormProvider,useFormContext,useWatch}from"react-hook-form";import classes from"./Form.module.css";export function FormProvider({form,children}){return _jsx(RHFormProvider,_object_spread_props(_object_spread({},form),{children:children}))}function FormRaw(_0,_1){let _ref=[_0,_1],[_ref1,..._rest]=_ref,{onSubmit,children,options}=_ref1,formProps=_object_without_properties(_ref1,["onSubmit","children","options"]),[ref]=_rest;const form=useRHForm(options);useImperativeHandle(ref,()=>({getForm:()=>form}));return _jsx(FormProvider,{form:form,children:_jsx("form",_object_spread_props(_object_spread({onSubmit:form.handleSubmit(args=>onSubmit(args,form)),className:classes.form},formProps),{children:children}))})}const Form=forwardRef(FormRaw);export{useWatch,useFormContext,Form};
2
2
  //# sourceMappingURL=Form.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/Form/Form.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport {\n DetailedHTMLProps,\n FormHTMLAttributes,\n ForwardedRef,\n forwardRef,\n ReactNode,\n useImperativeHandle,\n} from \"react\"\nimport {\n useForm as useRHForm,\n FormProvider as RHFormProvider,\n useFormContext,\n FieldValues,\n UseFormProps,\n UseFormReturn,\n useWatch,\n} from \"react-hook-form\"\nimport { ThandleSubmit } from \"./types\"\nimport classes from \"./Form.module.css\"\n\nexport type TuseFormProps<TFormData extends FieldValues> = Omit<\n DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>,\n \"onSubmit\" | \"ref\"\n> & {\n children?: ReactNode\n onSubmit: ThandleSubmit<TFormData>\n options?: UseFormProps<TFormData>\n}\n\nexport function FormProvider<TFormData extends FieldValues>({\n form,\n children,\n}: {\n form: UseFormReturn<TFormData, any, TFormData>\n children: ReactNode\n}) {\n return <RHFormProvider {...form}>{children}</RHFormProvider>\n}\n\nexport type TFormForwardRef<TFormData extends FieldValues> = {\n getForm: () => UseFormReturn<TFormData, any, TFormData> | undefined\n}\n\n/**\n * The **Form** is a simple wrapper for @react-hook-form made for easier and developer-friendlier Form creation.\n * With RHF you have to manually register all inputs and pass the field-validation on the useForm({validation}) hook.\n * Using this **Form** You can simply wrap this **Form** around your form body that contains the FormXXXX UI form-elements.\n * The FormXXX elements automatically connect to the form context and register their local validations without hustle.\n * It looks like this:<br/>\n * ```typescript\n * <Form onSubmit={(data, form) => handleSubmit(data)}>\n * <FormInput name=\"name\" />\n * <FormInput type=\"number\" name=\"age\" />\n * <button type=\"submit\">submit</button>\n * </Form>\n * ```\n * @param onSubmit Callback when form is submitted\n * @param children\n * @param options Options that are passed to @react-hook-forms useForm\n * @param formProps Props for the native form element\n * @param ref ForwardRef to get the form as a parent component {getForm()}\n */\nfunction FormRaw<TFormData extends FieldValues>(\n { onSubmit, children, options, ...formProps }: Omit<TuseFormProps<TFormData>, \"ref\">,\n ref: ForwardedRef<TFormForwardRef<TFormData>>\n) {\n const form = useRHForm<TFormData>(options)\n useImperativeHandle(ref, () => ({\n getForm: () => form,\n }))\n return (\n <FormProvider form={form}>\n <form\n onSubmit={form.handleSubmit((args) => onSubmit(args, form))}\n className={classes.form}\n {...formProps}\n >\n {children}\n </form>\n </FormProvider>\n )\n}\n\nconst Form = forwardRef(FormRaw) as <TFormFields extends FieldValues>(\n props: TuseFormProps<TFormFields> & {\n ref?: React.ForwardedRef<TFormForwardRef<TFormFields>>\n }\n) => ReturnType<typeof FormRaw>\n\nexport { useWatch, useFormContext, Form }\n"],"names":["forwardRef","useImperativeHandle","useForm","useRHForm","FormProvider","RHFormProvider","useFormContext","useWatch","classes","form","children","FormRaw","ref","onSubmit","options","formProps","getForm","handleSubmit","args","className","Form"],"mappings":"0zEAIA,QAIEA,UAAU,CAEVC,mBAAmB,KACd,OAAO,AACd,QACEC,WAAWC,SAAS,CACpBC,gBAAgBC,cAAc,CAC9BC,cAAc,CAIdC,QAAQ,KACH,iBAAiB,AAExB,QAAOC,YAAa,mBAAmB,AAWvC,QAAO,SAASJ,aAA4C,CAC1DK,IAAI,CACJC,QAAQ,CAIT,EACC,OAAO,KAACL,sDAAmBI,gBAAOC,WACpC,CAyBA,SAASC,QACP,EAAoF,CACpFC,EAA6C,yCAD7C,CAAEC,QAAQ,CAAEH,QAAQ,CAAEI,OAAO,CAAuD,OAAlDC,+EAClCH,WAEA,MAAMH,KAAON,UAAqBW,SAClCb,oBAAoBW,IAAK,IAAO,CAAA,CAC9BI,QAAS,IAAMP,IACjB,CAAA,GACA,OACE,KAACL,cAAaK,KAAMA,cAClB,KAACA,4CACCI,SAAUJ,KAAKQ,YAAY,CAAC,AAACC,MAASL,SAASK,KAAMT,OACrDU,UAAWX,QAAQC,IAAI,EACnBM,qBAEHL,aAIT,CAEA,MAAMU,KAAOpB,WAAWW,QAMxB,QAASJ,QAAQ,CAAED,cAAc,CAAEc,IAAI,CAAE"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/Form/Form.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport {\n DetailedHTMLProps,\n FormHTMLAttributes,\n ForwardedRef,\n forwardRef,\n ReactNode,\n useImperativeHandle,\n} from \"react\"\nimport {\n useForm as useRHForm,\n FormProvider as RHFormProvider,\n useFormContext,\n FieldValues,\n UseFormProps,\n UseFormReturn,\n useWatch,\n} from \"react-hook-form\"\nimport { ThandleSubmit } from \"./types\"\nimport classes from \"./Form.module.css\"\n\nexport type TuseFormProps<TFormData extends FieldValues> = Omit<\n DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>,\n \"onSubmit\" | \"ref\"\n> & {\n children?: ReactNode\n onSubmit: ThandleSubmit<TFormData>\n options?: UseFormProps<TFormData>\n}\n\nexport function FormProvider<TFormData extends FieldValues>({\n form,\n children,\n}: {\n form: UseFormReturn<TFormData, any, TFormData>\n children: ReactNode\n}) {\n return <RHFormProvider {...form}>{children}</RHFormProvider>\n}\n\nexport type TFormForwardRef<TFormData extends FieldValues> = {\n getForm: () => UseFormReturn<TFormData, any, TFormData> | undefined\n}\n\n/**\n * The **Form** is a simple wrapper for @react-hook-form made for easier and developer-friendlier Form creation.\n * With RHF you have to manually register all inputs and pass the field-validation on the useForm({validation}) hook.\n * Using this **Form** You can simply wrap this **Form** around your form body that contains the FormXXXX UI form-elements.\n * The FormXXX elements automatically connect to the form context and register their local validations without hustle.\n * It looks like this:<br/>\n * ```typescript\n * <Form onSubmit={(data, form) => handleSubmit(data)}>\n * <FormInput name=\"name\" />\n * <FormInput type=\"number\" name=\"age\" />\n * <button type=\"submit\">submit</button>\n * </Form>\n * ```\n * @param onSubmit Callback when form is submitted\n * @param children\n * @param options Options that are passed to @react-hook-forms useForm\n * @param formProps Props for the native form element\n * @param ref ForwardRef to get the form as a parent component {getForm()}\n */\nfunction FormRaw<TFormData extends FieldValues>(\n { onSubmit, children, options, ...formProps }: Omit<TuseFormProps<TFormData>, \"ref\">,\n ref: ForwardedRef<TFormForwardRef<TFormData>>\n) {\n const form = useRHForm<TFormData>(options)\n useImperativeHandle(ref, () => ({\n getForm: () => form,\n }))\n return (\n <FormProvider form={form}>\n <form\n onSubmit={form.handleSubmit((args) => onSubmit(args, form))}\n className={classes.form}\n {...formProps}\n >\n {children}\n </form>\n </FormProvider>\n )\n}\n\nconst Form = forwardRef(FormRaw) as <TFormFields extends FieldValues>(\n props: TuseFormProps<TFormFields> & {\n ref?: React.ForwardedRef<TFormForwardRef<TFormFields>>\n }\n) => ReturnType<typeof FormRaw>\n\nexport { useWatch, useFormContext, Form }\n"],"names":["forwardRef","useImperativeHandle","useForm","useRHForm","FormProvider","RHFormProvider","useFormContext","useWatch","classes","form","children","FormRaw","ref","onSubmit","options","formProps","getForm","handleSubmit","args","className","Form"],"mappings":"k0EAIA,QAIEA,UAAU,CAEVC,mBAAmB,KACd,OAAO,AACd,QACEC,WAAWC,SAAS,CACpBC,gBAAgBC,cAAc,CAC9BC,cAAc,CAIdC,QAAQ,KACH,iBAAiB,AAExB,QAAOC,YAAa,mBAAmB,AAWvC,QAAO,SAASJ,aAA4C,CAC1DK,IAAI,CACJC,QAAQ,CAIT,EACC,OAAO,KAACL,sDAAmBI,gBAAOC,WACpC,CAyBA,SAASC,QACP,EAAoF,CACpFC,EAA6C,yCAD7C,CAAEC,QAAQ,CAAEH,QAAQ,CAAEI,OAAO,CAAuD,OAAlDC,+EAClCH,WAEA,MAAMH,KAAON,UAAqBW,SAClCb,oBAAoBW,IAAK,IAAO,CAAA,CAC9BI,QAAS,IAAMP,IACjB,CAAA,GACA,OACE,KAACL,cAAaK,KAAMA,cAClB,KAACA,4CACCI,SAAUJ,KAAKQ,YAAY,CAAC,AAACC,MAASL,SAASK,KAAMT,OACrDU,UAAWX,QAAQC,IAAI,EACnBM,qBAEHL,aAIT,CAEA,MAAMU,KAAOpB,WAAWW,QAMxB,QAASJ,QAAQ,CAAED,cAAc,CAAEc,IAAI,CAAE"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{TextInput}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import React,{forwardRef}from"react";import{useErrorContext}from"../Form";import{FormErrors}from"../Form/FormErrors";export const Input=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;const classes=getDefaultFormStyles();return _jsx(TextInput,_object_spread_props(_object_spread({ref:ref},props),{size:size,classNames:_object_spread({root:classes.root,label:classes.label,input:classes.input,error:classes.error},props.classNames)}))});export const FormInput=_0=>{let{name,validation={},min,max,minLength,maxLength}=_0,inputProps=_object_without_properties(_0,["name","validation","min","max","minLength","maxLength"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formErrors=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formErrors===null||formErrors===void 0?void 0:formErrors.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Input,_object_spread_props(_object_spread({},inputProps,register(name,{validate:validation,disabled:inputProps.disabled,min,max,minLength,maxLength})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{TextInput}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import React,{forwardRef}from"react";import{useErrorContext}from"../Form";import{FormErrors}from"../Form/FormErrors";export const Input=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;const classes=getDefaultFormStyles();return _jsx(TextInput,_object_spread_props(_object_spread({ref:ref},props),{size:size,classNames:_object_spread({root:classes.root,label:classes.label,input:classes.input,error:classes.error},props.classNames)}))});export const FormInput=_0=>{let{name,validation={},min,max,minLength,maxLength}=_0,inputProps=_object_without_properties(_0,["name","validation","min","max","minLength","maxLength"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formErrors=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formErrors===null||formErrors===void 0?void 0:formErrors.message,fetchErrors].flat().filter(ent=>ent);return _jsx(Input,_object_spread_props(_object_spread({},inputProps,register(name,{validate:validation,disabled:inputProps.disabled,min,max,minLength,maxLength})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
2
2
  //# sourceMappingURL=Input.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/Input/Input.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { TextInput, TextInputProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl } from \"../Form\"\nimport React, { forwardRef } from \"react\"\nimport { useErrorContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\n\n// eslint-disable-next-line react/display-name\nexport const Input = forwardRef<HTMLInputElement, TextInputProps>(\n ({ size = \"md\", ...props }, ref) => {\n const classes = getDefaultFormStyles()\n return (\n <TextInput\n ref={ref}\n {...props}\n size={size}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n error: classes.error,\n ...props.classNames,\n }}\n />\n )\n }\n)\n\n/**\n * **Form** wrapper for an input component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name Name of the input\n * @param validation Validation rules for this field's client-side validation\n * @param min Quick validation for numbers\n * @param max Quick validation for numbers\n * @param minLength Quick validation for strings\n * @param maxLength Quick validation for strings\n * @param inputProps Props passed to input component\n */\nexport const FormInput: React.FC<TextInputProps & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n min,\n max,\n minLength,\n maxLength,\n ...inputProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n\n const formErrors = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formErrors?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Input\n {...inputProps}\n {...register(name, {\n validate: validation,\n disabled: inputProps.disabled,\n min,\n max,\n minLength,\n maxLength,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["TextInput","getDefaultFormStyles","useFormContext","React","forwardRef","useErrorContext","FormErrors","Input","size","props","ref","classes","classNames","root","label","input","error","FormInput","name","validation","min","max","minLength","maxLength","inputProps","register","formState","errorContext","formErrors","errors","fetchErrors","message","flat","filter","ent","validate","disabled","length"],"mappings":"0zEAIA,QAASA,SAAS,KAAwB,eAAe,AACzD,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAE7C,QAAOC,OAASC,UAAU,KAAQ,OAAO,AACzC,QAASC,eAAe,KAAQ,SAAS,AACzC,QAASC,UAAU,KAAQ,oBAAoB,AAG/C,QAAO,MAAMC,MAAQH,WACnB,iDAAC,CAAEI,KAAO,IAAI,CAAY,OAAPC,kDAASC,WAC1B,MAAMC,QAAUV,uBAChB,OACE,KAACD,+CACCU,IAAKA,KACDD,QACJD,KAAMA,KACNI,WAAY,gBACVC,KAAMF,QAAQE,IAAI,CAClBC,MAAOH,QAAQG,KAAK,CACpBC,MAAOJ,QAAQI,KAAK,CACpBC,MAAOL,QAAQK,KAAK,EACjBP,MAAMG,UAAU,IAI3B,EACD,AAaD,QAAO,MAAMK,UAAuE,QAAC,CACnFC,IAAI,CACJC,WAAa,CAAC,CAAC,CACfC,GAAG,CACHC,GAAG,CACHC,SAAS,CACTC,SAAS,CAEV,IADIC,oGAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGxB,iBAChC,MAAMyB,aAAetB,kBAErB,MAAMuB,WAAaF,UAAUG,MAAM,CAACX,KAAK,CACzC,MAAMY,YAAcH,aAAaE,MAAM,CAACX,KAAK,CAC7C,MAAMW,OAAS,CAACD,mBAAAA,2BAAAA,WAAYG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAEnF,OACE,KAAC3B,6CACKiB,WACAC,SAASP,KAAM,CACjBiB,SAAUhB,WACViB,SAAUZ,WAAWY,QAAQ,CAC7BhB,IACAC,IACAC,UACAC,SACF,KACAP,MAAOa,OAAOQ,MAAM,CAAG,GAAK,KAAC/B,YAAWuB,OAAQA,WAGtD,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/Input/Input.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { TextInput, TextInputProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl } from \"../Form\"\nimport React, { forwardRef } from \"react\"\nimport { useErrorContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\n\n// eslint-disable-next-line react/display-name\nexport const Input = forwardRef<HTMLInputElement, TextInputProps>(\n ({ size = \"md\", ...props }, ref) => {\n const classes = getDefaultFormStyles()\n return (\n <TextInput\n ref={ref}\n {...props}\n size={size}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n error: classes.error,\n ...props.classNames,\n }}\n />\n )\n }\n)\n\n/**\n * **Form** wrapper for an input component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name Name of the input\n * @param validation Validation rules for this field's client-side validation\n * @param min Quick validation for numbers\n * @param max Quick validation for numbers\n * @param minLength Quick validation for strings\n * @param maxLength Quick validation for strings\n * @param inputProps Props passed to input component\n */\nexport const FormInput: React.FC<TextInputProps & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n min,\n max,\n minLength,\n maxLength,\n ...inputProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n\n const formErrors = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formErrors?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <Input\n {...inputProps}\n {...register(name, {\n validate: validation,\n disabled: inputProps.disabled,\n min,\n max,\n minLength,\n maxLength,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["TextInput","getDefaultFormStyles","useFormContext","React","forwardRef","useErrorContext","FormErrors","Input","size","props","ref","classes","classNames","root","label","input","error","FormInput","name","validation","min","max","minLength","maxLength","inputProps","register","formState","errorContext","formErrors","errors","fetchErrors","message","flat","filter","ent","validate","disabled","length"],"mappings":"k0EAIA,QAASA,SAAS,KAAwB,eAAe,AACzD,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAE7C,QAAOC,OAASC,UAAU,KAAQ,OAAO,AACzC,QAASC,eAAe,KAAQ,SAAS,AACzC,QAASC,UAAU,KAAQ,oBAAoB,AAG/C,QAAO,MAAMC,MAAQH,WACnB,iDAAC,CAAEI,KAAO,IAAI,CAAY,OAAPC,kDAASC,WAC1B,MAAMC,QAAUV,uBAChB,OACE,KAACD,+CACCU,IAAKA,KACDD,QACJD,KAAMA,KACNI,WAAY,gBACVC,KAAMF,QAAQE,IAAI,CAClBC,MAAOH,QAAQG,KAAK,CACpBC,MAAOJ,QAAQI,KAAK,CACpBC,MAAOL,QAAQK,KAAK,EACjBP,MAAMG,UAAU,IAI3B,EACD,AAaD,QAAO,MAAMK,UAAuE,QAAC,CACnFC,IAAI,CACJC,WAAa,CAAC,CAAC,CACfC,GAAG,CACHC,GAAG,CACHC,SAAS,CACTC,SAAS,CAEV,IADIC,oGAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGxB,iBAChC,MAAMyB,aAAetB,kBAErB,MAAMuB,WAAaF,UAAUG,MAAM,CAACX,KAAK,CACzC,MAAMY,YAAcH,aAAaE,MAAM,CAACX,KAAK,CAC7C,MAAMW,OAAS,CAACD,mBAAAA,2BAAAA,WAAYG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAEnF,OACE,KAAC3B,6CACKiB,WACAC,SAASP,KAAM,CACjBiB,SAAUhB,WACViB,SAAUZ,WAAWY,QAAQ,CAC7BhB,IACAC,IACAC,UACAC,SACF,KACAP,MAAOa,OAAOQ,MAAM,CAAG,GAAK,KAAC/B,YAAWuB,OAAQA,WAGtD,CAAC"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Menu}from"@mantine/core";import{Button}from"../Button";import{forwardRef}from"react";import{ChevronDown}from"lucide-react";import{Icon}from"../../Icon";import classes from"./index.module.css";export const MenuButton=forwardRef((props,ref)=>{return _jsxs(Menu,{children:[_jsx(Menu.Target,{children:_jsx(Button,{ref:ref,rightSection:_jsx(Icon,{size:"md",icon:ChevronDown}),children:props.buttonText})}),_jsx(Menu.Dropdown,{className:classes.dropdown,children:props.children})]})});MenuButton.displayName="MenuButton";export const MenuItem=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{icon}=_ref1,props=_object_without_properties(_ref1,["icon"]),[ref]=_rest;const ItemIcon=icon?_jsx(Icon,{size:"sm",icon:icon}):null;return _jsx(Menu.Item,_object_spread_props(_object_spread({},props),{leftSection:ItemIcon,ref:ref}))});MenuItem.displayName="MenuItem";
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Menu}from"@mantine/core";import{Button}from"../Button";import{forwardRef}from"react";import{ChevronDown}from"lucide-react";import{Icon}from"../../Icon";import classes from"./index.module.css";export const MenuButton=forwardRef((props,ref)=>{return _jsxs(Menu,{children:[_jsx(Menu.Target,{children:_jsx(Button,{ref:ref,rightSection:_jsx(Icon,{size:"md",icon:ChevronDown}),children:props.buttonText})}),_jsx(Menu.Dropdown,{className:classes.dropdown,children:props.children})]})});MenuButton.displayName="MenuButton";export const MenuItem=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{icon}=_ref1,props=_object_without_properties(_ref1,["icon"]),[ref]=_rest;const ItemIcon=icon?_jsx(Icon,{size:"sm",icon:icon}):null;return _jsx(Menu.Item,_object_spread_props(_object_spread({},props),{leftSection:ItemIcon,ref:ref}))});MenuItem.displayName="MenuItem";
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/MenuButton/index.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Menu, MenuProps } from \"@mantine/core\"\nimport { Button } from \"../Button\"\nimport { forwardRef, ReactNode } from \"react\"\nimport { ChevronDown, LucideIcon } from \"lucide-react\"\nimport { Icon } from \"../../Icon\"\nimport classes from \"./index.module.css\"\n\ntype TMenuButtonProps = MenuProps & {\n buttonText: string\n children: ReactNode\n}\n/**\n * Provides a menu entry giving a button and its target\n * @param buttonText String used as button label\n * @param children\n */\nexport const MenuButton = forwardRef<HTMLButtonElement, TMenuButtonProps>((props, ref) => {\n return (\n <Menu>\n <Menu.Target>\n <Button ref={ref} rightSection={<Icon size={\"md\"} icon={ChevronDown} />}>\n {props.buttonText}\n </Button>\n </Menu.Target>\n <Menu.Dropdown className={classes.dropdown}>{props.children}</Menu.Dropdown>\n </Menu>\n )\n})\n\nMenuButton.displayName = \"MenuButton\"\n\ntype TMenuItemProps = ReturnType<typeof Menu.Item>[\"props\"] & {\n icon?: LucideIcon\n}\n\n/**\n * Provides a menu entry giving an icon and its target\n * @param icon Icon to be used in the menu item\n * @param props as defined by Mantine for menu items\n */\nexport const MenuItem = forwardRef<HTMLButtonElement, TMenuItemProps>(({ icon, ...props }, ref) => {\n const ItemIcon = icon ? <Icon size={\"sm\"} icon={icon} /> : null\n return <Menu.Item {...props} leftSection={ItemIcon} ref={ref} />\n})\n\nMenuItem.displayName = \"MenuItem\"\n"],"names":["Menu","Button","forwardRef","ChevronDown","Icon","classes","MenuButton","props","ref","Target","rightSection","size","icon","buttonText","Dropdown","className","dropdown","children","displayName","MenuItem","ItemIcon","Item","leftSection"],"mappings":"w0EAIA,QAASA,IAAI,KAAmB,eAAe,AAC/C,QAASC,MAAM,KAAQ,WAAW,AAClC,QAASC,UAAU,KAAmB,OAAO,AAC7C,QAASC,WAAW,KAAoB,cAAc,AACtD,QAASC,IAAI,KAAQ,YAAY,AACjC,QAAOC,YAAa,oBAAoB,AAWxC,QAAO,MAAMC,WAAaJ,WAAgD,CAACK,MAAOC,OAChF,OACE,MAACR,gBACC,KAACA,KAAKS,MAAM,WACV,KAACR,QAAOO,IAAKA,IAAKE,aAAc,KAACN,MAAKO,KAAM,KAAMC,KAAMT,uBACrDI,MAAMM,UAAU,KAGrB,KAACb,KAAKc,QAAQ,EAACC,UAAWV,QAAQW,QAAQ,UAAGT,MAAMU,QAAQ,KAGjE,EAAE,AAEFX,CAAAA,WAAWY,WAAW,CAAG,YAWzB,QAAO,MAAMC,SAAWjB,WAA8C,iDAAC,CAAEU,IAAI,CAAY,OAAPL,kDAASC,WACzF,MAAMY,SAAWR,KAAO,KAACR,MAAKO,KAAM,KAAMC,KAAMA,OAAW,KAC3D,OAAO,KAACZ,KAAKqB,IAAI,wCAAKd,QAAOe,YAAaF,SAAUZ,IAAKA,MAC3D,EAAE,AAEFW,CAAAA,SAASD,WAAW,CAAG"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/MenuButton/index.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Menu, MenuProps } from \"@mantine/core\"\nimport { Button } from \"../Button\"\nimport { forwardRef, ReactNode } from \"react\"\nimport { ChevronDown, LucideIcon } from \"lucide-react\"\nimport { Icon } from \"../../Icon\"\nimport classes from \"./index.module.css\"\n\ntype TMenuButtonProps = MenuProps & {\n buttonText: string\n children: ReactNode\n}\n/**\n * Provides a menu entry giving a button and its target\n * @param buttonText String used as button label\n * @param children\n */\nexport const MenuButton = forwardRef<HTMLButtonElement, TMenuButtonProps>((props, ref) => {\n return (\n <Menu>\n <Menu.Target>\n <Button ref={ref} rightSection={<Icon size={\"md\"} icon={ChevronDown} />}>\n {props.buttonText}\n </Button>\n </Menu.Target>\n <Menu.Dropdown className={classes.dropdown}>{props.children}</Menu.Dropdown>\n </Menu>\n )\n})\n\nMenuButton.displayName = \"MenuButton\"\n\ntype TMenuItemProps = ReturnType<typeof Menu.Item>[\"props\"] & {\n icon?: LucideIcon\n}\n\n/**\n * Provides a menu entry giving an icon and its target\n * @param icon Icon to be used in the menu item\n * @param props as defined by Mantine for menu items\n */\nexport const MenuItem = forwardRef<HTMLButtonElement, TMenuItemProps>(({ icon, ...props }, ref) => {\n const ItemIcon = icon ? <Icon size={\"sm\"} icon={icon} /> : null\n return <Menu.Item {...props} leftSection={ItemIcon} ref={ref} />\n})\n\nMenuItem.displayName = \"MenuItem\"\n"],"names":["Menu","Button","forwardRef","ChevronDown","Icon","classes","MenuButton","props","ref","Target","rightSection","size","icon","buttonText","Dropdown","className","dropdown","children","displayName","MenuItem","ItemIcon","Item","leftSection"],"mappings":"g1EAIA,QAASA,IAAI,KAAmB,eAAe,AAC/C,QAASC,MAAM,KAAQ,WAAW,AAClC,QAASC,UAAU,KAAmB,OAAO,AAC7C,QAASC,WAAW,KAAoB,cAAc,AACtD,QAASC,IAAI,KAAQ,YAAY,AACjC,QAAOC,YAAa,oBAAoB,AAWxC,QAAO,MAAMC,WAAaJ,WAAgD,CAACK,MAAOC,OAChF,OACE,MAACR,gBACC,KAACA,KAAKS,MAAM,WACV,KAACR,QAAOO,IAAKA,IAAKE,aAAc,KAACN,MAAKO,KAAM,KAAMC,KAAMT,uBACrDI,MAAMM,UAAU,KAGrB,KAACb,KAAKc,QAAQ,EAACC,UAAWV,QAAQW,QAAQ,UAAGT,MAAMU,QAAQ,KAGjE,EAAE,AAEFX,CAAAA,WAAWY,WAAW,CAAG,YAWzB,QAAO,MAAMC,SAAWjB,WAA8C,iDAAC,CAAEU,IAAI,CAAY,OAAPL,kDAASC,WACzF,MAAMY,SAAWR,KAAO,KAACR,MAAKO,KAAM,KAAMC,KAAMA,OAAW,KAC3D,OAAO,KAACZ,KAAKqB,IAAI,wCAAKd,QAAOe,YAAaF,SAAUZ,IAAKA,MAC3D,EAAE,AAEFW,CAAAA,SAASD,WAAW,CAAG"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{PasswordInput as PasswordInputMantine,useMantineTheme}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import React,{forwardRef}from"react";import{useErrorContext,useFormContext}from"../Form";import{FormErrors}from"../Form/FormErrors";import{Eye,EyeOff}from"lucide-react";import classes from"./PasswordInput.module.css";import{ICON_SIZES}from"../../../theme";const useStyles=()=>{const defaultStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({innerInput:classes["inner-input"]},defaultStyles),{root:`${defaultStyles.root} ${classes.root}`})};const PasswordToggleIcon=props=>{const theme=useMantineTheme();const Icon=props.reveal?Eye:EyeOff;return _jsx(Icon,{size:ICON_SIZES.MEDIUM,color:theme.colors.gray[5]})};const PasswordInputRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;const classes=useStyles();return _jsx(PasswordInputMantine,_object_spread({ref:ref,classNames:{root:classes.root,label:classes.label,input:classes.input,innerInput:classes.innerInput,error:classes.error},size:size,visibilityToggleIcon:PasswordToggleIcon},props))};const PasswordInput=forwardRef(PasswordInputRaw);PasswordInput.displayName="PasswordInput";export{PasswordInput};export const FormPasswordInput=_0=>{let{name,validation={},min,max,minLength,maxLength}=_0,inputProps=_object_without_properties(_0,["name","validation","min","max","minLength","maxLength"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formError=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(PasswordInput,_object_spread_props(_object_spread({},inputProps,register(name,{validate:validation,min,max,minLength,maxLength})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{PasswordInput as PasswordInputMantine,useMantineTheme}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import React,{forwardRef}from"react";import{useErrorContext,useFormContext}from"../Form";import{FormErrors}from"../Form/FormErrors";import{Eye,EyeOff}from"lucide-react";import classes from"./PasswordInput.module.css";import{ICON_SIZES}from"../../../theme";const useStyles=()=>{const defaultStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({innerInput:classes["inner-input"]},defaultStyles),{root:`${defaultStyles.root} ${classes.root}`})};const PasswordToggleIcon=props=>{const theme=useMantineTheme();const Icon=props.reveal?Eye:EyeOff;return _jsx(Icon,{size:ICON_SIZES.MEDIUM,color:theme.colors.gray[5]})};const PasswordInputRaw=(_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{size="md"}=_ref1,props=_object_without_properties(_ref1,["size"]),[ref]=_rest;const classes=useStyles();return _jsx(PasswordInputMantine,_object_spread({ref:ref,classNames:{root:classes.root,label:classes.label,input:classes.input,innerInput:classes.innerInput,error:classes.error},size:size,visibilityToggleIcon:PasswordToggleIcon},props))};const PasswordInput=forwardRef(PasswordInputRaw);PasswordInput.displayName="PasswordInput";export{PasswordInput};export const FormPasswordInput=_0=>{let{name,validation={},min,max,minLength,maxLength}=_0,inputProps=_object_without_properties(_0,["name","validation","min","max","minLength","maxLength"]);const{register,formState}=useFormContext();const errorContext=useErrorContext();const formError=formState.errors[name];const fetchErrors=errorContext.errors[name];const errors=[formError===null||formError===void 0?void 0:formError.message,fetchErrors].flat().filter(ent=>ent);return _jsx(PasswordInput,_object_spread_props(_object_spread({},inputProps,register(name,{validate:validation,min,max,minLength,maxLength})),{error:errors.length>0&&_jsx(FormErrors,{errors:errors})}))};
2
2
  //# sourceMappingURL=PasswordInput.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/PasswordInput/PasswordInput.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport {\n PasswordInput as PasswordInputMantine,\n PasswordInputProps,\n MantineSize,\n useMantineTheme,\n} from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport React, { ForwardedRef, forwardRef } from \"react\"\nimport { TFormControl } from \"../Form\"\nimport { useErrorContext, useFormContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { Eye, EyeOff } from \"lucide-react\"\nimport classes from \"./PasswordInput.module.css\"\nimport { ICON_SIZES } from \"../../../theme\"\n\nconst useStyles = () => {\n const defaultStyles = getDefaultFormStyles()\n return {\n innerInput: classes[\"inner-input\"],\n ...defaultStyles,\n root: `${defaultStyles.root} ${classes.root}`,\n }\n}\n\ntype TInput = Modify<\n PasswordInputProps,\n {\n size?: MantineSize\n }\n>\n\nconst PasswordToggleIcon = (props: { reveal?: boolean }) => {\n const theme = useMantineTheme()\n const Icon = props.reveal ? Eye : EyeOff\n\n return <Icon size={ICON_SIZES.MEDIUM} color={theme.colors.gray[5]} />\n}\n\nconst PasswordInputRaw = (\n { size = \"md\", ...props }: TInput,\n ref?: ForwardedRef<HTMLInputElement>\n) => {\n const classes = useStyles()\n\n return (\n <PasswordInputMantine\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n innerInput: classes.innerInput,\n error: classes.error,\n }}\n size={size}\n visibilityToggleIcon={PasswordToggleIcon}\n {...props}\n />\n )\n}\n\nconst PasswordInput = forwardRef(PasswordInputRaw)\nPasswordInput.displayName = \"PasswordInput\"\nexport { PasswordInput }\n\n/**\n * **Form** wrapper for a PasswordInput component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name Name of the input\n * @param validation Validation rules for this field's client-side validation\n * @param min Quick validation for numbers\n * @param max Quick validation for numbers\n * @param minLength Quick validation for strings\n * @param maxLength Quick validation for strings\n * @param inputProps Props passed to input component\n */\nexport const FormPasswordInput: React.FC<TInput & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n min,\n max,\n minLength,\n maxLength,\n ...inputProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n const formError = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <PasswordInput\n {...inputProps}\n {...register(name, {\n validate: validation,\n min,\n max,\n minLength,\n maxLength,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["PasswordInput","PasswordInputMantine","useMantineTheme","getDefaultFormStyles","React","forwardRef","useErrorContext","useFormContext","FormErrors","Eye","EyeOff","classes","ICON_SIZES","useStyles","defaultStyles","innerInput","root","PasswordToggleIcon","props","theme","Icon","reveal","size","MEDIUM","color","colors","gray","PasswordInputRaw","ref","classNames","label","input","error","visibilityToggleIcon","displayName","FormPasswordInput","name","validation","min","max","minLength","maxLength","inputProps","register","formState","errorContext","formError","errors","fetchErrors","message","flat","filter","ent","validate","length"],"mappings":"0zEAIA,QACEA,iBAAiBC,oBAAoB,CAGrCC,eAAe,KACV,eAAe,AACtB,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAAOC,OAAuBC,UAAU,KAAQ,OAAO,AAEvD,QAASC,eAAe,CAAEC,cAAc,KAAQ,SAAS,AACzD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,GAAG,CAAEC,MAAM,KAAQ,cAAc,AAC1C,QAAOC,YAAa,4BAA4B,AAChD,QAASC,UAAU,KAAQ,gBAAgB,CAE3C,MAAMC,UAAY,KAChB,MAAMC,cAAgBX,uBACtB,OAAO,qCACLY,WAAYJ,OAAO,CAAC,cAAc,EAC/BG,gBACHE,KAAM,CAAC,EAAEF,cAAcE,IAAI,CAAC,CAAC,EAAEL,QAAQK,IAAI,CAAC,CAAC,EAEjD,EASA,MAAMC,mBAAqB,AAACC,QAC1B,MAAMC,MAAQjB,kBACd,MAAMkB,KAAOF,MAAMG,MAAM,CAAGZ,IAAMC,OAElC,OAAO,KAACU,MAAKE,KAAMV,WAAWW,MAAM,CAAEC,MAAOL,MAAMM,MAAM,CAACC,IAAI,CAAC,EAAE,EACnE,EAEA,MAAMC,iBAAmB,iDACvB,CAAEL,KAAO,IAAI,CAAoB,OAAfJ,kDAClBU,WAEA,MAAMjB,QAAUE,YAEhB,OACE,KAACZ,qCACC2B,IAAKA,IACLC,WAAY,CACVb,KAAML,QAAQK,IAAI,CAClBc,MAAOnB,QAAQmB,KAAK,CACpBC,MAAOpB,QAAQoB,KAAK,CACpBhB,WAAYJ,QAAQI,UAAU,CAC9BiB,MAAOrB,QAAQqB,KAAK,AACtB,EACAV,KAAMA,KACNW,qBAAsBhB,oBAClBC,OAGV,EAEA,MAAMlB,cAAgBK,WAAWsB,iBACjC3B,CAAAA,cAAckC,WAAW,CAAG,eAC5B,QAASlC,aAAa,CAAE,AAaxB,QAAO,MAAMmC,kBAAuE,QAAC,CACnFC,IAAI,CACJC,WAAa,CAAC,CAAC,CACfC,GAAG,CACHC,GAAG,CACHC,SAAS,CACTC,SAAS,CAEV,IADIC,oGAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGrC,iBAChC,MAAMsC,aAAevC,kBACrB,MAAMwC,UAAYF,UAAUG,MAAM,CAACX,KAAK,CACxC,MAAMY,YAAcH,aAAaE,MAAM,CAACX,KAAK,CAC7C,MAAMW,OAAS,CAACD,kBAAAA,0BAAAA,UAAWG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAACpD,qDACK0C,WACAC,SAASP,KAAM,CACjBiB,SAAUhB,WACVC,IACAC,IACAC,UACAC,SACF,KACAT,MAAOe,OAAOO,MAAM,CAAG,GAAK,KAAC9C,YAAWuC,OAAQA,WAGtD,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/PasswordInput/PasswordInput.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport {\n PasswordInput as PasswordInputMantine,\n PasswordInputProps,\n MantineSize,\n useMantineTheme,\n} from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport React, { ForwardedRef, forwardRef } from \"react\"\nimport { TFormControl } from \"../Form\"\nimport { useErrorContext, useFormContext } from \"../Form\"\nimport { FormErrors } from \"../Form/FormErrors\"\nimport { Eye, EyeOff } from \"lucide-react\"\nimport classes from \"./PasswordInput.module.css\"\nimport { ICON_SIZES } from \"../../../theme\"\n\nconst useStyles = () => {\n const defaultStyles = getDefaultFormStyles()\n return {\n innerInput: classes[\"inner-input\"],\n ...defaultStyles,\n root: `${defaultStyles.root} ${classes.root}`,\n }\n}\n\ntype TInput = Modify<\n PasswordInputProps,\n {\n size?: MantineSize\n }\n>\n\nconst PasswordToggleIcon = (props: { reveal?: boolean }) => {\n const theme = useMantineTheme()\n const Icon = props.reveal ? Eye : EyeOff\n\n return <Icon size={ICON_SIZES.MEDIUM} color={theme.colors.gray[5]} />\n}\n\nconst PasswordInputRaw = (\n { size = \"md\", ...props }: TInput,\n ref?: ForwardedRef<HTMLInputElement>\n) => {\n const classes = useStyles()\n\n return (\n <PasswordInputMantine\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n input: classes.input,\n innerInput: classes.innerInput,\n error: classes.error,\n }}\n size={size}\n visibilityToggleIcon={PasswordToggleIcon}\n {...props}\n />\n )\n}\n\nconst PasswordInput = forwardRef(PasswordInputRaw)\nPasswordInput.displayName = \"PasswordInput\"\nexport { PasswordInput }\n\n/**\n * **Form** wrapper for a PasswordInput component that automagically registers the input to the current form context (from **Form**).\n * It also connects to the error-context from **ConnectedForm** to show server-side validation errors.\n * @param name Name of the input\n * @param validation Validation rules for this field's client-side validation\n * @param min Quick validation for numbers\n * @param max Quick validation for numbers\n * @param minLength Quick validation for strings\n * @param maxLength Quick validation for strings\n * @param inputProps Props passed to input component\n */\nexport const FormPasswordInput: React.FC<TInput & TFormControl<HTMLInputElement>> = ({\n name,\n validation = {},\n min,\n max,\n minLength,\n maxLength,\n ...inputProps\n}) => {\n const { register, formState } = useFormContext()\n const errorContext = useErrorContext()\n const formError = formState.errors[name]\n const fetchErrors = errorContext.errors[name]\n const errors = [formError?.message as string, fetchErrors].flat().filter((ent) => ent)\n\n return (\n <PasswordInput\n {...inputProps}\n {...register(name, {\n validate: validation,\n min,\n max,\n minLength,\n maxLength,\n })}\n error={errors.length > 0 && <FormErrors errors={errors} />}\n />\n )\n}\n"],"names":["PasswordInput","PasswordInputMantine","useMantineTheme","getDefaultFormStyles","React","forwardRef","useErrorContext","useFormContext","FormErrors","Eye","EyeOff","classes","ICON_SIZES","useStyles","defaultStyles","innerInput","root","PasswordToggleIcon","props","theme","Icon","reveal","size","MEDIUM","color","colors","gray","PasswordInputRaw","ref","classNames","label","input","error","visibilityToggleIcon","displayName","FormPasswordInput","name","validation","min","max","minLength","maxLength","inputProps","register","formState","errorContext","formError","errors","fetchErrors","message","flat","filter","ent","validate","length"],"mappings":"k0EAIA,QACEA,iBAAiBC,oBAAoB,CAGrCC,eAAe,KACV,eAAe,AACtB,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAAOC,OAAuBC,UAAU,KAAQ,OAAO,AAEvD,QAASC,eAAe,CAAEC,cAAc,KAAQ,SAAS,AACzD,QAASC,UAAU,KAAQ,oBAAoB,AAC/C,QAASC,GAAG,CAAEC,MAAM,KAAQ,cAAc,AAC1C,QAAOC,YAAa,4BAA4B,AAChD,QAASC,UAAU,KAAQ,gBAAgB,CAE3C,MAAMC,UAAY,KAChB,MAAMC,cAAgBX,uBACtB,OAAO,qCACLY,WAAYJ,OAAO,CAAC,cAAc,EAC/BG,gBACHE,KAAM,CAAC,EAAEF,cAAcE,IAAI,CAAC,CAAC,EAAEL,QAAQK,IAAI,CAAC,CAAC,EAEjD,EASA,MAAMC,mBAAqB,AAACC,QAC1B,MAAMC,MAAQjB,kBACd,MAAMkB,KAAOF,MAAMG,MAAM,CAAGZ,IAAMC,OAElC,OAAO,KAACU,MAAKE,KAAMV,WAAWW,MAAM,CAAEC,MAAOL,MAAMM,MAAM,CAACC,IAAI,CAAC,EAAE,EACnE,EAEA,MAAMC,iBAAmB,iDACvB,CAAEL,KAAO,IAAI,CAAoB,OAAfJ,kDAClBU,WAEA,MAAMjB,QAAUE,YAEhB,OACE,KAACZ,qCACC2B,IAAKA,IACLC,WAAY,CACVb,KAAML,QAAQK,IAAI,CAClBc,MAAOnB,QAAQmB,KAAK,CACpBC,MAAOpB,QAAQoB,KAAK,CACpBhB,WAAYJ,QAAQI,UAAU,CAC9BiB,MAAOrB,QAAQqB,KAAK,AACtB,EACAV,KAAMA,KACNW,qBAAsBhB,oBAClBC,OAGV,EAEA,MAAMlB,cAAgBK,WAAWsB,iBACjC3B,CAAAA,cAAckC,WAAW,CAAG,eAC5B,QAASlC,aAAa,CAAE,AAaxB,QAAO,MAAMmC,kBAAuE,QAAC,CACnFC,IAAI,CACJC,WAAa,CAAC,CAAC,CACfC,GAAG,CACHC,GAAG,CACHC,SAAS,CACTC,SAAS,CAEV,IADIC,oGAEH,KAAM,CAAEC,QAAQ,CAAEC,SAAS,CAAE,CAAGrC,iBAChC,MAAMsC,aAAevC,kBACrB,MAAMwC,UAAYF,UAAUG,MAAM,CAACX,KAAK,CACxC,MAAMY,YAAcH,aAAaE,MAAM,CAACX,KAAK,CAC7C,MAAMW,OAAS,CAACD,kBAAAA,0BAAAA,UAAWG,OAAO,CAAYD,YAAY,CAACE,IAAI,GAAGC,MAAM,CAAC,AAACC,KAAQA,KAElF,OACE,KAACpD,qDACK0C,WACAC,SAASP,KAAM,CACjBiB,SAAUhB,WACVC,IACAC,IACAC,UACAC,SACF,KACAT,MAAOe,OAAOO,MAAM,CAAG,GAAK,KAAC9C,YAAWuC,OAAQA,WAGtD,CAAC"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};return _extends.apply(this,arguments)}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{Radio}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import React,{forwardRef}from"react";import classes from"./RadioButton.module.css";const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{label:`${defaultFormStyles.label} ${classes.label}`})};export const RadioButton=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{}=_ref1,props=_extends({},_ref1),[ref]=_rest;const classes=useStyles();return _jsx(Radio,_object_spread({ref:ref,classNames:_object_spread({root:classes.root,label:classes.label},props.classNames)},props))});export const FormRadioButton=_0=>{let{name}=_0,props=_object_without_properties(_0,["name"]);const{register}=useFormContext();return _jsx(RadioButton,_object_spread({},props,register(name)))};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};return _extends.apply(this,arguments)}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx}from"react/jsx-runtime";import{Radio}from"@mantine/core";import{getDefaultFormStyles}from"../sharedStyles";import{useFormContext}from"../Form/Form";import React,{forwardRef}from"react";import classes from"./RadioButton.module.css";const useStyles=()=>{const defaultFormStyles=getDefaultFormStyles();return _object_spread_props(_object_spread({},defaultFormStyles),{label:`${defaultFormStyles.label} ${classes.label}`})};export const RadioButton=forwardRef((_0,_1)=>{let _ref=[_0,_1],[_ref1,..._rest]=_ref,{}=_ref1,props=_extends({},_ref1),[ref]=_rest;const classes=useStyles();return _jsx(Radio,_object_spread({ref:ref,classNames:_object_spread({root:classes.root,label:classes.label},props.classNames)},props))});export const FormRadioButton=_0=>{let{name}=_0,props=_object_without_properties(_0,["name"]);const{register}=useFormContext();return _jsx(RadioButton,_object_spread({},props,register(name)))};
2
2
  //# sourceMappingURL=RadioButton.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/Form/RadioButton/RadioButton.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Radio, RadioProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl } from \"../Form/types\"\nimport React, { forwardRef } from \"react\"\nimport classes from \"./RadioButton.module.css\"\n\nconst useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n return {\n ...defaultFormStyles,\n label: `${defaultFormStyles.label} ${classes.label}`,\n }\n}\n\n/**\n * Provides a RadioButton\n * @param props Additional props as defined by Mantine\n */\n// eslint-disable-next-line react/display-name\nexport const RadioButton = forwardRef<HTMLInputElement, RadioProps>(({ ...props }, ref) => {\n const classes = useStyles()\n return (\n <Radio\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n ...props.classNames,\n }}\n {...props}\n />\n )\n})\n/**\n * **Form** wrapper for a RadioButton component that automagically registers the input to the current form context (from **Form**).\n * @param name Name of the input as identification in the form\n * @param props Additional props as defined by Mantine to be used in RadioButton\n */\nexport const FormRadioButton: React.FC<RadioProps & TFormControl<HTMLInputElement>> = ({\n name,\n ...props\n}) => {\n const { register } = useFormContext()\n\n return <RadioButton {...props} {...register(name)} />\n}\n"],"names":["Radio","getDefaultFormStyles","useFormContext","React","forwardRef","classes","useStyles","defaultFormStyles","label","RadioButton","props","ref","classNames","root","FormRadioButton","name","register"],"mappings":"8kFAIA,QAASA,KAAK,KAAoB,eAAe,AACjD,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAE7C,QAAOC,OAASC,UAAU,KAAQ,OAAO,AACzC,QAAOC,YAAa,0BAA0B,CAE9C,MAAMC,UAAY,KAChB,MAAMC,kBAAoBN,uBAC1B,OAAO,uCACFM,oBACHC,MAAO,CAAC,EAAED,kBAAkBC,KAAK,CAAC,CAAC,EAAEH,QAAQG,KAAK,CAAC,CAAC,EAExD,CAOA,QAAO,MAAMC,YAAcL,WAAyC,iDAAC,EAAY,OAAPM,0BAASC,WACjF,MAAMN,QAAUC,YAChB,OACE,KAACN,sBACCW,IAAKA,IACLC,WAAY,gBACVC,KAAMR,QAAQQ,IAAI,CAClBL,MAAOH,QAAQG,KAAK,EACjBE,MAAME,UAAU,GAEjBF,OAGV,EAAE,AAMF,QAAO,MAAMI,gBAAyE,QAAC,CACrFC,IAAI,CAEL,IADIL,8CAEH,KAAM,CAAEM,QAAQ,CAAE,CAAGd,iBAErB,OAAO,KAACO,8BAAgBC,MAAWM,SAASD,OAC9C,CAAC"}
1
+ {"version":3,"sources":["../../../../../src/components/Form/RadioButton/RadioButton.tsx"],"sourcesContent":["/* Copyright (C) Greenbone AG\n *\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { Radio, RadioProps } from \"@mantine/core\"\nimport { getDefaultFormStyles } from \"../sharedStyles\"\nimport { useFormContext } from \"../Form/Form\"\nimport { TFormControl } from \"../Form/types\"\nimport React, { forwardRef } from \"react\"\nimport classes from \"./RadioButton.module.css\"\n\nconst useStyles = () => {\n const defaultFormStyles = getDefaultFormStyles()\n return {\n ...defaultFormStyles,\n label: `${defaultFormStyles.label} ${classes.label}`,\n }\n}\n\n/**\n * Provides a RadioButton\n * @param props Additional props as defined by Mantine\n */\n// eslint-disable-next-line react/display-name\nexport const RadioButton = forwardRef<HTMLInputElement, RadioProps>(({ ...props }, ref) => {\n const classes = useStyles()\n return (\n <Radio\n ref={ref}\n classNames={{\n root: classes.root,\n label: classes.label,\n ...props.classNames,\n }}\n {...props}\n />\n )\n})\n/**\n * **Form** wrapper for a RadioButton component that automagically registers the input to the current form context (from **Form**).\n * @param name Name of the input as identification in the form\n * @param props Additional props as defined by Mantine to be used in RadioButton\n */\nexport const FormRadioButton: React.FC<RadioProps & TFormControl<HTMLInputElement>> = ({\n name,\n ...props\n}) => {\n const { register } = useFormContext()\n\n return <RadioButton {...props} {...register(name)} />\n}\n"],"names":["Radio","getDefaultFormStyles","useFormContext","React","forwardRef","classes","useStyles","defaultFormStyles","label","RadioButton","props","ref","classNames","root","FormRadioButton","name","register"],"mappings":"slFAIA,QAASA,KAAK,KAAoB,eAAe,AACjD,QAASC,oBAAoB,KAAQ,iBAAiB,AACtD,QAASC,cAAc,KAAQ,cAAc,AAE7C,QAAOC,OAASC,UAAU,KAAQ,OAAO,AACzC,QAAOC,YAAa,0BAA0B,CAE9C,MAAMC,UAAY,KAChB,MAAMC,kBAAoBN,uBAC1B,OAAO,uCACFM,oBACHC,MAAO,CAAC,EAAED,kBAAkBC,KAAK,CAAC,CAAC,EAAEH,QAAQG,KAAK,CAAC,CAAC,EAExD,CAOA,QAAO,MAAMC,YAAcL,WAAyC,iDAAC,EAAY,OAAPM,0BAASC,WACjF,MAAMN,QAAUC,YAChB,OACE,KAACN,sBACCW,IAAKA,IACLC,WAAY,gBACVC,KAAMR,QAAQQ,IAAI,CAClBL,MAAOH,QAAQG,KAAK,EACjBE,MAAME,UAAU,GAEjBF,OAGV,EAAE,AAMF,QAAO,MAAMI,gBAAyE,QAAC,CACrFC,IAAI,CAEL,IADIL,8CAEH,KAAM,CAAEM,QAAQ,CAAE,CAAGd,iBAErB,OAAO,KAACO,8BAAgBC,MAAWM,SAASD,OAC9C,CAAC"}
@@ -1,2 +1,2 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{createElement as _createElement}from"react";import{forwardRef,useEffect,useImperativeHandle,useRef,useState}from"react";import{createPortal}from"react-dom";import{components}from"react-select";import{CascadeOption}from"./CascadeOption";import classes from"./CascadeMenu.module.css";import{cx}from"../../../../helper/cx";function shouldIncreasePaddingBecauseOfScrollbarBehaviourBasedOnBrowser(){if((navigator.userAgent.indexOf("Opera")||navigator.userAgent.indexOf("OPR"))!=-1){return true}else if(navigator.userAgent.indexOf("Edg")!=-1){return true}else if(navigator.userAgent.indexOf("Chrome")!=-1){return true}else if(navigator.userAgent.indexOf("Safari")!=-1){return false}else if(navigator.userAgent.indexOf("Firefox")!=-1){return false}else if(navigator.userAgent.indexOf("MSIE")!=-1||!!document.documentMode){return true}else{return false}}export function CascadeMenuBaseRaw(_0,_1){let _ref=[_0,_1],[_ref1,..._rest]=_ref,{isInitiallyOpen,openerMenuRef}=_ref1,props=_object_without_properties(_ref1,["isInitiallyOpen","openerMenuRef"]),[ref]=_rest;var _props_openerOptionNode,_props_menuPortalTarget,_props_openerOptionNode1,_props_index;const innerMenuRef=useRef(null);const[open,setOpen]=useState(isInitiallyOpen||false);const showScrollbar=value=>{if(innerMenuRef.current){innerMenuRef.current.style.overflowY=value?"auto":"hidden"}};const handleMouseExit=()=>{showScrollbar(false);props.setFocusList([])};const handleMouseEnter=()=>{showScrollbar(true)};let isScrolling=false;const handleScroll=()=>{if(isScrolling)return;for(const node of props.nodes){var _node_cascadeOptionForwardRef_current;(_node_cascadeOptionForwardRef_current=node.cascadeOptionForwardRef.current)===null||_node_cascadeOptionForwardRef_current===void 0?void 0:_node_cascadeOptionForwardRef_current.setFocused(false)}isScrolling=true};const handleScrollEnd=()=>{isScrolling=false};useEffect(()=>{var _innerMenuRef_current,_innerMenuRef_current1,_innerMenuRef_current2,_innerMenuRef_current3;(_innerMenuRef_current=innerMenuRef.current)===null||_innerMenuRef_current===void 0?void 0:_innerMenuRef_current.addEventListener("mouseleave",handleMouseExit);(_innerMenuRef_current1=innerMenuRef.current)===null||_innerMenuRef_current1===void 0?void 0:_innerMenuRef_current1.addEventListener("mouseenter",handleMouseEnter);(_innerMenuRef_current2=innerMenuRef.current)===null||_innerMenuRef_current2===void 0?void 0:_innerMenuRef_current2.addEventListener("wheel",handleScroll);(_innerMenuRef_current3=innerMenuRef.current)===null||_innerMenuRef_current3===void 0?void 0:_innerMenuRef_current3.addEventListener("scrollend",handleScrollEnd);return()=>{var _innerMenuRef_current,_innerMenuRef_current1,_innerMenuRef_current2,_innerMenuRef_current3;(_innerMenuRef_current=innerMenuRef.current)===null||_innerMenuRef_current===void 0?void 0:_innerMenuRef_current.removeEventListener("mouseleave",handleMouseExit);(_innerMenuRef_current1=innerMenuRef.current)===null||_innerMenuRef_current1===void 0?void 0:_innerMenuRef_current1.removeEventListener("mouseenter",handleMouseEnter);(_innerMenuRef_current2=innerMenuRef.current)===null||_innerMenuRef_current2===void 0?void 0:_innerMenuRef_current2.removeEventListener("wheel",handleScroll);(_innerMenuRef_current3=innerMenuRef.current)===null||_innerMenuRef_current3===void 0?void 0:_innerMenuRef_current3.removeEventListener("scrollend",handleScrollEnd)}},[]);const setMenuOpen=value=>{setOpen(value)};useImperativeHandle(ref,()=>({setOpen:value=>setMenuOpen(value)}));const relocateMenu=()=>{var _props_openerOptionNode,_refable_current,_props_openerOptionNode1,_props_openerOptionNode2,_document_scrollingElement;const refable=props.openerOptionNode?(_props_openerOptionNode=props.openerOptionNode)===null||_props_openerOptionNode===void 0?void 0:_props_openerOptionNode.elementRef:props.openerOptionElementRef;const rect=refable===null||refable===void 0?void 0:(_refable_current=refable.current)===null||_refable_current===void 0?void 0:_refable_current.getBoundingClientRect();if(!rect){return}const isScrollable=openerMenuRef&&openerMenuRef.current&&openerMenuRef.current.offsetHeight<openerMenuRef.current.scrollHeight;const xOffset=shouldIncreasePaddingBecauseOfScrollbarBehaviourBasedOnBrowser()&&isScrollable?7:0;const width=((_props_openerOptionNode1=props.openerOptionNode)===null||_props_openerOptionNode1===void 0?void 0:_props_openerOptionNode1.level)?rect.width+xOffset:0;const height=((_props_openerOptionNode2=props.openerOptionNode)===null||_props_openerOptionNode2===void 0?void 0:_props_openerOptionNode2.level)?-8:rect.height;updatePosition(rect.top+height+(((_document_scrollingElement=document.scrollingElement)===null||_document_scrollingElement===void 0?void 0:_document_scrollingElement.scrollTop)||0),rect.left+width)};useEffect(()=>{relocateMenu()});const updatePosition=(yPixel,xPixel)=>{if(!innerMenuRef.current)return;innerMenuRef.current.style.top=yPixel+"px";innerMenuRef.current.style.left=xPixel+"px"};return _jsx(_Fragment,{children:_jsx("div",{className:cx(classes["menu-container"]),"data-testid":`cascade-menu-for-${((_props_openerOptionNode=props.openerOptionNode)===null||_props_openerOptionNode===void 0?void 0:_props_openerOptionNode.id)||"root"}`,children:createPortal(_jsx(components.Menu,_object_spread_props(_object_spread({},props.menuProps),{innerRef:innerMenuRef,className:cx(classes.menu,(props.openerOptionNode?props.openerOptionNode.focused:true)||open?classes["menu-open"]:classes["menu-hidden"]),style:{zIndex:props.level},isLoading:false,placement:"bottom",minMenuHeight:200,maxMenuHeight:200,menuPlacement:"bottom",menuPosition:"fixed",menuShouldScrollIntoView:true,children:props.options.map((op,index)=>_createElement(CascadeOption,_object_spread_props(_object_spread({},props),{level:props.level+1,index:index,OptionComponent:props.OptionComponent,onSelect:value=>{props.onSelect(value)},option:op,key:op.value,openerMenuRef:innerMenuRef})))})),((_props_menuPortalTarget=props.menuPortalTarget)===null||_props_menuPortalTarget===void 0?void 0:_props_menuPortalTarget.current)||document.body,((_props_openerOptionNode1=props.openerOptionNode)===null||_props_openerOptionNode1===void 0?void 0:_props_openerOptionNode1.id)||((_props_index=props.index)===null||_props_index===void 0?void 0:_props_index.toString()))})})}export const CascadeMenuBase=forwardRef(CascadeMenuBaseRaw);export function CascadeMenuOpenerRaw(props,ref){return _jsxs(_Fragment,{children:[props.children,_jsx(CascadeMenuBase,_object_spread_props(_object_spread({},props),{ref:ref}))]})}export const CascadeMenuOpener=forwardRef(CascadeMenuOpenerRaw);
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target={},sourceKeys,key,i;if(typeof Reflect!=="undefined"&&Reflect.ownKeys){sourceKeys=Reflect.ownKeys(Object(source));for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}target=_object_without_properties_loose(source,excluded);if(Object.getOwnPropertySymbols){sourceKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={},sourceKeys=Object.getOwnPropertyNames(source),key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}return target}import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{createElement as _createElement}from"react";import{forwardRef,useEffect,useImperativeHandle,useRef,useState}from"react";import{createPortal}from"react-dom";import{components}from"react-select";import{CascadeOption}from"./CascadeOption";import classes from"./CascadeMenu.module.css";import{cx}from"../../../../helper/cx";function shouldIncreasePaddingBecauseOfScrollbarBehaviourBasedOnBrowser(){if((navigator.userAgent.indexOf("Opera")||navigator.userAgent.indexOf("OPR"))!=-1){return true}else if(navigator.userAgent.indexOf("Edg")!=-1){return true}else if(navigator.userAgent.indexOf("Chrome")!=-1){return true}else if(navigator.userAgent.indexOf("Safari")!=-1){return false}else if(navigator.userAgent.indexOf("Firefox")!=-1){return false}else if(navigator.userAgent.indexOf("MSIE")!=-1||!!document.documentMode){return true}else{return false}}export function CascadeMenuBaseRaw(_0,_1){let _ref=[_0,_1],[_ref1,..._rest]=_ref,{isInitiallyOpen,openerMenuRef}=_ref1,props=_object_without_properties(_ref1,["isInitiallyOpen","openerMenuRef"]),[ref]=_rest;var _props_openerOptionNode,_props_menuPortalTarget,_props_openerOptionNode1,_props_index;const innerMenuRef=useRef(null);const[open,setOpen]=useState(isInitiallyOpen||false);const showScrollbar=value=>{if(innerMenuRef.current){innerMenuRef.current.style.overflowY=value?"auto":"hidden"}};const handleMouseExit=()=>{showScrollbar(false);props.setFocusList([])};const handleMouseEnter=()=>{showScrollbar(true)};let isScrolling=false;const handleScroll=()=>{if(isScrolling)return;for(const node of props.nodes){var _node_cascadeOptionForwardRef_current;(_node_cascadeOptionForwardRef_current=node.cascadeOptionForwardRef.current)===null||_node_cascadeOptionForwardRef_current===void 0?void 0:_node_cascadeOptionForwardRef_current.setFocused(false)}isScrolling=true};const handleScrollEnd=()=>{isScrolling=false};useEffect(()=>{var _innerMenuRef_current,_innerMenuRef_current1,_innerMenuRef_current2,_innerMenuRef_current3;(_innerMenuRef_current=innerMenuRef.current)===null||_innerMenuRef_current===void 0?void 0:_innerMenuRef_current.addEventListener("mouseleave",handleMouseExit);(_innerMenuRef_current1=innerMenuRef.current)===null||_innerMenuRef_current1===void 0?void 0:_innerMenuRef_current1.addEventListener("mouseenter",handleMouseEnter);(_innerMenuRef_current2=innerMenuRef.current)===null||_innerMenuRef_current2===void 0?void 0:_innerMenuRef_current2.addEventListener("wheel",handleScroll);(_innerMenuRef_current3=innerMenuRef.current)===null||_innerMenuRef_current3===void 0?void 0:_innerMenuRef_current3.addEventListener("scrollend",handleScrollEnd);return()=>{var _innerMenuRef_current,_innerMenuRef_current1,_innerMenuRef_current2,_innerMenuRef_current3;(_innerMenuRef_current=innerMenuRef.current)===null||_innerMenuRef_current===void 0?void 0:_innerMenuRef_current.removeEventListener("mouseleave",handleMouseExit);(_innerMenuRef_current1=innerMenuRef.current)===null||_innerMenuRef_current1===void 0?void 0:_innerMenuRef_current1.removeEventListener("mouseenter",handleMouseEnter);(_innerMenuRef_current2=innerMenuRef.current)===null||_innerMenuRef_current2===void 0?void 0:_innerMenuRef_current2.removeEventListener("wheel",handleScroll);(_innerMenuRef_current3=innerMenuRef.current)===null||_innerMenuRef_current3===void 0?void 0:_innerMenuRef_current3.removeEventListener("scrollend",handleScrollEnd)}},[]);const setMenuOpen=value=>{setOpen(value)};useImperativeHandle(ref,()=>({setOpen:value=>setMenuOpen(value)}));const relocateMenu=()=>{var _props_openerOptionNode,_refable_current,_props_openerOptionNode1,_props_openerOptionNode2,_document_scrollingElement;const refable=props.openerOptionNode?(_props_openerOptionNode=props.openerOptionNode)===null||_props_openerOptionNode===void 0?void 0:_props_openerOptionNode.elementRef:props.openerOptionElementRef;const rect=refable===null||refable===void 0?void 0:(_refable_current=refable.current)===null||_refable_current===void 0?void 0:_refable_current.getBoundingClientRect();if(!rect){return}const isScrollable=openerMenuRef&&openerMenuRef.current&&openerMenuRef.current.offsetHeight<openerMenuRef.current.scrollHeight;const xOffset=shouldIncreasePaddingBecauseOfScrollbarBehaviourBasedOnBrowser()&&isScrollable?7:0;const width=((_props_openerOptionNode1=props.openerOptionNode)===null||_props_openerOptionNode1===void 0?void 0:_props_openerOptionNode1.level)?rect.width+xOffset:0;const height=((_props_openerOptionNode2=props.openerOptionNode)===null||_props_openerOptionNode2===void 0?void 0:_props_openerOptionNode2.level)?-8:rect.height;updatePosition(rect.top+height+(((_document_scrollingElement=document.scrollingElement)===null||_document_scrollingElement===void 0?void 0:_document_scrollingElement.scrollTop)||0),rect.left+width)};useEffect(()=>{relocateMenu()});const updatePosition=(yPixel,xPixel)=>{if(!innerMenuRef.current)return;innerMenuRef.current.style.top=yPixel+"px";innerMenuRef.current.style.left=xPixel+"px"};return _jsx(_Fragment,{children:_jsx("div",{className:cx(classes["menu-container"]),"data-testid":`cascade-menu-for-${((_props_openerOptionNode=props.openerOptionNode)===null||_props_openerOptionNode===void 0?void 0:_props_openerOptionNode.id)||"root"}`,children:createPortal(_jsx(components.Menu,_object_spread_props(_object_spread({},props.menuProps),{innerRef:innerMenuRef,className:cx(classes.menu,(props.openerOptionNode?props.openerOptionNode.focused:true)||open?classes["menu-open"]:classes["menu-hidden"]),style:{zIndex:props.level},isLoading:false,placement:"bottom",minMenuHeight:200,maxMenuHeight:200,menuPlacement:"bottom",menuPosition:"fixed",menuShouldScrollIntoView:true,children:props.options.map((op,index)=>_createElement(CascadeOption,_object_spread_props(_object_spread({},props),{level:props.level+1,index:index,OptionComponent:props.OptionComponent,onSelect:value=>{props.onSelect(value)},option:op,key:op.value,openerMenuRef:innerMenuRef})))})),((_props_menuPortalTarget=props.menuPortalTarget)===null||_props_menuPortalTarget===void 0?void 0:_props_menuPortalTarget.current)||document.body,((_props_openerOptionNode1=props.openerOptionNode)===null||_props_openerOptionNode1===void 0?void 0:_props_openerOptionNode1.id)||((_props_index=props.index)===null||_props_index===void 0?void 0:_props_index.toString()))})})}export const CascadeMenuBase=forwardRef(CascadeMenuBaseRaw);export function CascadeMenuOpenerRaw(props,ref){return _jsxs(_Fragment,{children:[props.children,_jsx(CascadeMenuBase,_object_spread_props(_object_spread({},props),{ref:ref}))]})}export const CascadeMenuOpener=forwardRef(CascadeMenuOpenerRaw);
2
2
  //# sourceMappingURL=CascadeMenu.js.map