@dr.pogodin/react-utils 1.57.1 → 1.58.0

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 (126) hide show
  1. package/build/development/server/Cache.js +7 -7
  2. package/build/development/server/Cache.js.map +1 -1
  3. package/build/development/server/index.js +6 -3
  4. package/build/development/server/index.js.map +1 -1
  5. package/build/development/server/renderer.js +18 -7
  6. package/build/development/server/renderer.js.map +1 -1
  7. package/build/development/server/server.js +12 -6
  8. package/build/development/server/server.js.map +1 -1
  9. package/build/development/server/utils/errors.js +10 -10
  10. package/build/development/server/utils/errors.js.map +1 -1
  11. package/build/development/shared/components/Button/index.js +1 -1
  12. package/build/development/shared/components/Button/index.js.map +1 -1
  13. package/build/development/shared/components/Checkbox/index.js +5 -5
  14. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  15. package/build/development/shared/components/Input/index.js +3 -3
  16. package/build/development/shared/components/Input/index.js.map +1 -1
  17. package/build/development/shared/components/Modal/index.js +3 -0
  18. package/build/development/shared/components/Modal/index.js.map +1 -1
  19. package/build/development/shared/components/TextArea/index.js +3 -3
  20. package/build/development/shared/components/TextArea/index.js.map +1 -1
  21. package/build/development/shared/components/WithTooltip/Tooltip.js +2 -2
  22. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  23. package/build/development/shared/components/WithTooltip/index.js +3 -1
  24. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  25. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +4 -1
  26. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  27. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -4
  28. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/NativeDropdown/index.js +3 -3
  30. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/Switch/index.js +2 -2
  32. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  33. package/build/development/shared/utils/config.js.map +1 -1
  34. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +7 -6
  35. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  36. package/build/development/shared/utils/jest/index.js +2 -1
  37. package/build/development/shared/utils/jest/index.js.map +1 -1
  38. package/build/development/shared/utils/splitComponent.js +10 -8
  39. package/build/development/shared/utils/splitComponent.js.map +1 -1
  40. package/build/development/shared/utils/webpack.js +2 -1
  41. package/build/development/shared/utils/webpack.js.map +1 -1
  42. package/build/production/server/Cache.js +3 -3
  43. package/build/production/server/Cache.js.map +1 -1
  44. package/build/production/server/index.js +1 -1
  45. package/build/production/server/index.js.map +1 -1
  46. package/build/production/server/renderer.js +9 -9
  47. package/build/production/server/renderer.js.map +1 -1
  48. package/build/production/server/server.js +6 -6
  49. package/build/production/server/server.js.map +1 -1
  50. package/build/production/server/utils/errors.js +1 -1
  51. package/build/production/server/utils/errors.js.map +1 -1
  52. package/build/production/shared/components/Button/index.js +1 -1
  53. package/build/production/shared/components/Button/index.js.map +1 -1
  54. package/build/production/shared/components/Checkbox/index.js +1 -1
  55. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  56. package/build/production/shared/components/Input/index.js +1 -1
  57. package/build/production/shared/components/Input/index.js.map +1 -1
  58. package/build/production/shared/components/Modal/index.js +1 -1
  59. package/build/production/shared/components/Modal/index.js.map +1 -1
  60. package/build/production/shared/components/TextArea/index.js +1 -1
  61. package/build/production/shared/components/TextArea/index.js.map +1 -1
  62. package/build/production/shared/components/WithTooltip/Tooltip.js +1 -1
  63. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  64. package/build/production/shared/components/WithTooltip/index.js +2 -2
  65. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  66. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  67. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  68. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  69. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  70. package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
  71. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  72. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  73. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  74. package/build/production/shared/utils/config.js.map +1 -1
  75. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +2 -2
  76. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  77. package/build/production/shared/utils/jest/index.js +2 -2
  78. package/build/production/shared/utils/jest/index.js.map +1 -1
  79. package/build/production/shared/utils/splitComponent.js +3 -3
  80. package/build/production/shared/utils/splitComponent.js.map +1 -1
  81. package/build/production/shared/utils/webpack.js +3 -2
  82. package/build/production/shared/utils/webpack.js.map +1 -1
  83. package/build/types-code/shared/utils/config.d.ts +1 -1
  84. package/build/web/server/Cache.js +3 -3
  85. package/build/web/server/Cache.js.map +1 -1
  86. package/build/web/server/index.js +1 -1
  87. package/build/web/server/index.js.map +1 -1
  88. package/build/web/server/renderer.js +9 -9
  89. package/build/web/server/renderer.js.map +1 -1
  90. package/build/web/server/server.js +6 -6
  91. package/build/web/server/server.js.map +1 -1
  92. package/build/web/server/utils/errors.js +1 -1
  93. package/build/web/server/utils/errors.js.map +1 -1
  94. package/build/web/shared/components/Button/index.js +1 -1
  95. package/build/web/shared/components/Button/index.js.map +1 -1
  96. package/build/web/shared/components/Checkbox/index.js +1 -1
  97. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  98. package/build/web/shared/components/Input/index.js +1 -1
  99. package/build/web/shared/components/Input/index.js.map +1 -1
  100. package/build/web/shared/components/Modal/index.js +1 -1
  101. package/build/web/shared/components/Modal/index.js.map +1 -1
  102. package/build/web/shared/components/TextArea/index.js +1 -1
  103. package/build/web/shared/components/TextArea/index.js.map +1 -1
  104. package/build/web/shared/components/WithTooltip/Tooltip.js +1 -1
  105. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  106. package/build/web/shared/components/WithTooltip/index.js +2 -2
  107. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  108. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  109. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  110. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  111. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  112. package/build/web/shared/components/selectors/NativeDropdown/index.js +2 -2
  113. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  114. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  115. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  116. package/build/web/shared/utils/config.js.map +1 -1
  117. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +2 -2
  118. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  119. package/build/web/shared/utils/jest/index.js +2 -2
  120. package/build/web/shared/utils/jest/index.js.map +1 -1
  121. package/build/web/shared/utils/splitComponent.js +3 -3
  122. package/build/web/shared/utils/splitComponent.js.map +1 -1
  123. package/build/web/shared/utils/webpack.js +3 -2
  124. package/build/web/shared/utils/webpack.js.map +1 -1
  125. package/config/babel/webpack.js +6 -1
  126. package/package.json +19 -19
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../../../src/server/utils/errors.ts"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n// TODO: It could accept the status code as a constructor argument.\nclass ErrorWithStatus extends Error {\n status: number = CODES.INTERNAL_SERVER_ERROR;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(\n message: string,\n statusCode = CODES.INTERNAL_SERVER_ERROR,\n): ErrorWithStatus {\n const error = new ErrorWithStatus(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * Throws an error with given message and HTTP status code.\n */\nexport function fail(\n message: string,\n statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,\n): Error {\n throw newError(message, statusCode);\n}\n\n/**\n * Validates the `value` against the given \"standard\" validation `schema`.\n * Resolves to the correctly typed `value`, if it has passed the validation;\n * otherwise throws an error.\n * @param value The value to validate.\n * @param schema The \"standard\" validation schema to use.\n * @param [message] Optional error message, to prepend the validation error\n * message.\n * @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).\n */\nexport async function assert<T extends StandardSchemaV1>(\n value: unknown,\n schema: T,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n): Promise<StandardSchemaV1.InferOutput<T>> {\n let result = schema['~standard'].validate(value);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n let error = JSON.stringify(result.issues, null, 2);\n if (message) error = `${message}\\n\\n${error}`;\n throw fail(error, statusCode);\n }\n\n return result.value;\n}\n"],"mappings":"oEAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SACE,WAAW,IAAI,KAAK,EACpB,aAAa,IAAI,MAAM,EACvB,eAAe,IAAI,eAAe,QAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,GAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,GAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,GAExB;AACA,MAAM,eAAe,SAAS,KAAM;EAClC,MAAM,GAAW,KAAK,CAAC,qBAAqB;AAC9C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,QAAQ,CACtB,OAAe,EACf,UAAU,GAAG,KAAK,CAAC,qBAAqB,EACvB;EACjB,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC;EAC1C,KAAK,CAAC,MAAM,GAAG,UAAU;EACzB,OAAO,KAAK;AACd,CAEA;AACA;AACA;AACA,OAAO,SAAS,IAAI,CAClB,OAAe,EACf,UAAiB,GAAG,KAAK,CAAC,qBAAqB,EACxC;EACP,MAAM,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;AACrC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe,MAAM,CAC1B,KAAc,EACd,MAAS,EACT,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,KAAK,CAAC,WAAW,EACY;EAC1C,IAAI,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;EAChD,IAAI,MAAM,YAAY,OAAO,EAAE,MAAM,GAAG,MAAM,MAAM;EAEpD,IAAI,MAAM,CAAC,MAAM,EAAE;IACjB,IAAI,KAAK,GAAG,gBAAe,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAI,OAAO,EAAE,KAAK,GAAG,GAAG,OAAO,OAAO,KAAK,EAAE;IAC7C,MAAM,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;EAC/B;EAEA,OAAO,MAAM,CAAC,KAAK;AACrB","ignoreList":[]}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../../src/server/utils/errors.ts"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n// TODO: It could accept the status code as a constructor argument.\nclass ErrorWithStatus extends Error {\n status: number = CODES.INTERNAL_SERVER_ERROR;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(\n message: string,\n statusCode = CODES.INTERNAL_SERVER_ERROR,\n): ErrorWithStatus {\n const error = new ErrorWithStatus(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * Throws an error with given message and HTTP status code.\n */\nexport function fail(\n message: string,\n statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,\n): Error {\n throw newError(message, statusCode);\n}\n\n/**\n * Validates the `value` against the given \"standard\" validation `schema`.\n * Resolves to the correctly typed `value`, if it has passed the validation;\n * otherwise throws an error.\n * @param value The value to validate.\n * @param schema The \"standard\" validation schema to use.\n * @param [message] Optional error message, to prepend the validation error\n * message.\n * @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).\n */\nexport async function assert<T extends StandardSchemaV1>(\n value: unknown,\n schema: T,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n): Promise<StandardSchemaV1.InferOutput<T>> {\n let result = schema['~standard'].validate(value);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n let error = JSON.stringify(result.issues, null, 2);\n if (message) error = `${message}\\n\\n${error}`;\n throw fail(error, statusCode);\n }\n\n return result.value;\n}\n"],"mappings":"sEAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SACE,WAAW,IAAI,KAAK,EACpB,aAAa,IAAI,MAAM,EACvB,eAAe,IAAI,eAAe,QAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,GAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,GAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,GAExB;AACA,MAAM,eAAe,SAAS,KAAM;EAClC,MAAM,GAAW,KAAK,CAAC,qBAAqB;AAC9C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,QAAQ,CACtB,OAAe,EACf,UAAU,GAAG,KAAK,CAAC,qBAAqB,EACvB;EACjB,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC;EAC1C,KAAK,CAAC,MAAM,GAAG,UAAU;EACzB,OAAO,KAAK;AACd,CAEA;AACA;AACA;AACA,OAAO,SAAS,IAAI,CAClB,OAAe,EACf,UAAiB,GAAG,KAAK,CAAC,qBAAqB,EACxC;EACP,MAAM,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;AACrC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe,MAAM,CAC1B,KAAc,EACd,MAAS,EACT,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,KAAK,CAAC,WAAW,EACY;EAC1C,IAAI,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;EAChD,IAAI,MAAM,YAAY,OAAO,EAAE,MAAM,GAAG,MAAM,MAAM;EAEpD,IAAI,MAAM,CAAC,MAAM,EAAE;IACjB,IAAI,KAAK,GAAG,gBAAe,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAI,OAAO,EAAE,KAAK,GAAG,GAAG,OAAO,OAAO,KAAK,EAAE;IAC7C,MAAM,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;EAC/B;EAEA,OAAO,MAAM,CAAC,KAAK;AACrB","ignoreList":[]}
@@ -31,7 +31,7 @@ export const BaseButton = t0 => {
31
31
  theme,
32
32
  to
33
33
  } = t0;
34
- let className = theme.button;
34
+ let className = theme.button ?? "";
35
35
  if (active && theme.active) {
36
36
  className = className + ` ${theme.active}`;
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Button/index.tsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...r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cesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button ?? '';\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...rest} theme={composed} />;\n};\n\nexport default Button;\n"],"mappings":"iDAAA;AAUA,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,OAEzD,IAAI;AAEX;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AA0BxC,OAAO,MAAM,UAAqC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAkBrD;EACC,gBAAgB,KAAK,OAAa,IAAlB,EAAkB;EAClC,IAAI,MAAsB,IAAZ,KAAK,OAAO;IAAE,qBAAS,GAAI,IAAI,KAAK,OAAO,EAAE;EAAA;EAC3D,IAAI,QAAQ;IACV,IAAI,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O;MACL,SAAS,EAAT,SAAS;MACX,OAAO,EAAP,OAAO;MACH,WAAW,EAAX,WAAW;MACb,SAAS,EAAT,SAAS;MACL,aAAa,EAAb,aAAa;MACf,WAAW,EAAX,WAAW;MACnB,IAAQ,EAAR,QAAQ;MACH,QAAC,EAAD,CAAC;MAAA,UAEV;IAAQ,CACN,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAdN,EAcM;AAAA,CAET;AAED,MAAM,MAEL,GAAG;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;IAAA,MAAkB;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EACrB,iBAAiB,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGlD,uBAAC,UAAU;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAzC,EAAyC;AAAA,CACjD;AAED,eAAe,MAAM","ignoreList":[]}
@@ -25,16 +25,16 @@ const Checkbox = t0 => {
25
25
  theme
26
26
  } = t0;
27
27
  const composed = useTheme("Checkbox", defaultTheme, theme);
28
- let containerClassName = composed.container;
28
+ let containerClassName = composed.container ?? "";
29
29
  if (disabled) {
30
- containerClassName = containerClassName + ` ${composed.disabled}`;
30
+ containerClassName = containerClassName + ` ${composed.disabled ?? ""}`;
31
31
  }
32
- let checkboxClassName = composed.checkbox;
32
+ let checkboxClassName = composed.checkbox ?? "";
33
33
  if (checked === "indeterminate") {
34
- checkboxClassName = checkboxClassName + ` ${composed.indeterminate}`;
34
+ checkboxClassName = checkboxClassName + ` ${composed.indeterminate ?? ""}`;
35
35
  }
36
36
  if (error) {
37
- containerClassName = containerClassName + ` ${composed.error}`;
37
+ containerClassName = containerClassName + ` ${composed.error ?? ""}`;
38
38
  }
39
39
  let t1;
40
40
  if ($[0] !== composed.label || $[1] !== label) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Checkbox/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype PropT<ValueT> = {\n checked?: ValueT;\n disabled?: boolean;\n error?: ReactNode;\n label?: React.ReactNode;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n testId?: string;\n theme?: Theme<\n | 'checkbox'\n | 'container'\n | 'disabled'\n | 'error'\n | 'errorMessage'\n | 'indeterminate'\n | 'label'\n >;\n};\n\nconst Checkbox = <ValueT extends 'indeterminate' | boolean = boolean>({\n checked,\n disabled,\n error,\n label,\n onChange,\n testId,\n theme,\n}: PropT<ValueT>): ReactNode => {\n const composed = useTheme('Checkbox', defaultTheme, theme);\n\n let containerClassName = composed.container;\n if (disabled) containerClassName += ` ${composed.disabled}`;\n\n let checkboxClassName = composed.checkbox;\n if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div className={containerClassName}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <input\n checked={checked === undefined ? undefined : checked === true}\n className={checkboxClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onChange={onChange}\n onClick={(e) => {\n e.stopPropagation();\n }}\n type=\"checkbox\"\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default Checkbox;\n"],"mappings":";AAEA,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAoBxC,MAAM,QAAQ,GAAG;EAAA;EAAqD;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAQtD;EACd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CAET;AAED,eAAe,QAAQ;AAzCN;EA8BP,CAAC,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Checkbox/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype PropT<ValueT> = {\n checked?: ValueT;\n disabled?: boolean;\n error?: ReactNode;\n label?: React.ReactNode;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n testId?: string;\n theme?: Theme<\n | 'checkbox'\n | 'container'\n | 'disabled'\n | 'error'\n | 'errorMessage'\n | 'indeterminate'\n | 'label'\n >;\n};\n\nconst Checkbox = <ValueT extends 'indeterminate' | boolean = boolean>({\n checked,\n disabled,\n error,\n label,\n onChange,\n testId,\n theme,\n}: PropT<ValueT>): ReactNode => {\n const composed = useTheme('Checkbox', defaultTheme, theme);\n\n let containerClassName = composed.container ?? '';\n if (disabled) containerClassName += ` ${composed.disabled ?? ''}`;\n\n let checkboxClassName = composed.checkbox ?? '';\n if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate ?? ''}`;\n\n if (error) containerClassName += ` ${composed.error ?? ''}`;\n\n return (\n <div className={containerClassName}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <input\n checked={checked === undefined ? undefined : checked === true}\n className={checkboxClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onChange={onChange}\n onClick={(e) => {\n e.stopPropagation();\n }}\n type=\"checkbox\"\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default Checkbox;\n"],"mappings":";AAEA,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAoBxC,MAAM,QAAQ,GAAG;EAAA;E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kB;MAAA,WAC9B,EACsD,EACxD,EAUE,EACD,EAEO;IAAA,CACL,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAjBN,EAiBM;AAAA,CAET;AAED,eAAe,QAAQ;AAzCN;EA8BP,CAAC,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
@@ -73,15 +73,15 @@ const Input = t0 => {
73
73
  const composed = useTheme("Input", defaultTheme, theme, t1);
74
74
  const [focused, setFocused] = useState(false);
75
75
  const localRef = useRef(null);
76
- let containerClassName = composed.container;
76
+ let containerClassName = composed.container ?? "";
77
77
  if (focused) {
78
- containerClassName = containerClassName + ` ${composed.focused}`;
78
+ containerClassName = containerClassName + ` ${composed.focused ?? ""}`;
79
79
  }
80
80
  if (!rest.value && composed.empty) {
81
81
  containerClassName = containerClassName + ` ${composed.empty}`;
82
82
  }
83
83
  if (error) {
84
- containerClassName = containerClassName + ` ${composed.error}`;
84
+ containerClassName = containerClassName + ` ${composed.error ?? ""}`;
85
85
  }
86
86
  let t2;
87
87
  if ($[11] !== ref) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Input/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type Ref,\n useRef,\n useState,\n} from 'react';\n\nimport { type COMPOSE, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'children' | 'container' | 'empty' | 'error' | 'errorMessage'\n | 'focused' | 'input' | 'label';\n\ntype PropsT = React.InputHTMLAttributes<HTMLInputElement> & {\n children?: ReactNode;\n composeAdhocTheme?: COMPOSE;\n error?: ReactNode;\n label?: React.ReactNode;\n ref?: Ref<HTMLInputElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n};\n\n/**\n * Themeable input field, based on the standard HTML `<input>` element.\n * @param [props.label] Input label.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n * @param [props...] Any other properties are passed to the underlying\n * `<input>` element.\n */\nconst Input: FunctionComponent<PropsT> = ({\n children,\n composeAdhocTheme,\n error,\n label,\n ref,\n testId,\n theme,\n ...rest\n}) => {\n const composed = useTheme('Input', defaultTheme, theme, {\n composeAdhocTheme,\n });\n\n // NOTE: As of now, it is only updated when \"theme.focused\" is defined,\n // as otherwise its value is not used.\n const [focused, setFocused] = useState(false);\n\n const localRef = useRef<HTMLInputElement>(null);\n\n let containerClassName = composed.container;\n\n // NOTE: As of now, \"focused\" can be true only when \"theme.focused\"\n // is provided.\n if (focused /* && theme.focused */) containerClassName += ` ${composed.focused}`;\n\n if (!rest.value && composed.empty) containerClassName += ` ${composed.empty}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n // TODO: It does not really work if a callback-style `ref` is passed in,\n // we need a more complex logic to cover that case, but for now this serves\n // the case we need it for.\n if (typeof ref === 'object') ref?.current?.focus();\n else localRef.current?.focus();\n }}\n >\n {label === undefined\n ? null : <div className={composed.label}>{label}</div>}\n <input\n className={composed.input}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n ref={ref ?? localRef}\n\n // TODO: Avoid the spreading later.\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest}\n\n onBlur={composed.focused ? (e) => {\n setFocused(false);\n rest.onBlur?.(e);\n } : rest.onBlur}\n onFocus={composed.focused ? (e) => {\n setFocused(true);\n rest.onFocus?.(e);\n } : rest.onFocus}\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n {children ? <div className={composed.children}>{children}</div> : null}\n </div>\n );\n};\n\nexport default Input;\n"],"mappings":";AAAA,SAIE,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAmC,QAAQ,QAAQ,0BAA0B;AAE7E;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAA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esContent":["import {\n type FunctionComponent,\n type ReactNode,\n type Ref,\n useRef,\n useState,\n} from 'react';\n\nimport { type COMPOSE, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'children' | 'container' | 'empty' | 'error' | 'errorMessage'\n | 'focused' | 'input' | 'label';\n\ntype PropsT = React.InputHTMLAttributes<HTMLInputElement> & {\n children?: ReactNode;\n composeAdhocTheme?: COMPOSE;\n error?: ReactNode;\n label?: React.ReactNode;\n ref?: Ref<HTMLInputElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n};\n\n/**\n * Themeable input field, based on the standard HTML `<input>` element.\n * @param [props.label] Input label.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n * @param [props...] Any other properties are passed to the underlying\n * `<input>` element.\n */\nconst Input: FunctionComponent<PropsT> = ({\n children,\n composeAdhocTheme,\n error,\n label,\n ref,\n testId,\n theme,\n ...rest\n}) => {\n const composed = useTheme('Input', defaultTheme, theme, {\n composeAdhocTheme,\n });\n\n // NOTE: As of now, it is only updated when \"theme.focused\" is defined,\n // as otherwise its value is not used.\n const [focused, setFocused] = useState(false);\n\n const localRef = useRef<HTMLInputElement>(null);\n\n let containerClassName = composed.container ?? '';\n\n // NOTE: As of now, \"focused\" can be true only when \"theme.focused\"\n // is provided.\n if (focused /* && theme.focused */) containerClassName += ` ${composed.focused ?? ''}`;\n\n if (!rest.value && composed.empty) containerClassName += ` ${composed.empty}`;\n\n if (error) containerClassName += ` ${composed.error ?? ''}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n // TODO: It does not really work if a callback-style `ref` is passed in,\n // we need a more complex logic to cover that case, but for now this serves\n // the case we need it for.\n if (typeof ref === 'object') ref?.current?.focus();\n else localRef.current?.focus();\n }}\n >\n {label === undefined\n ? null : <div className={composed.label}>{label}</div>}\n <input\n className={composed.input}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n ref={ref ?? localRef}\n\n // TODO: Avoid the spreading later.\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest}\n\n onBlur={composed.focused ? (e) => {\n setFocused(false);\n rest.onBlur?.(e);\n } : rest.onBlur}\n onFocus={composed.focused ? (e) => {\n setFocused(true);\n rest.onFocus?.(e);\n } : rest.onFocus}\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n {children ? <div className={composed.children}>{children}</div> : null}\n </div>\n );\n};\n\nexport default Input;\n"],"mappings":";AAAA,SAIE,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAmC,QAAQ,QAAQ,0BAA0B;AAE7E;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC,+DAexC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,KAAgC,GAAG;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;IAAA,MASzC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;EAAA;IACyD;MAAA;IAExD,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAFD,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,EAEvD,CAAC;EAIF,8BAA8B,QAAQ,CAAC,KAAK,CAAC;EAE7C,iBAAiB,MAAM,CAAmB,IAAI,CAAC;EAE/C,yBAAyB,QAAQ,UAAgB,IAAxB,EAAwB;EAIjD,IAAI,OAAO;IAAyB,uCAAkB,GAAI,IAAI,QAAQ,QAAc,IAAtB,EAAsB,EAAE;EAAA;EAEtF,IAAI,CAAC,IAAI,MAAwB,IAAd,QAAQ,MAAM;IAAE,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AK,CAC1C,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACP,cAAQ,gBAAR;MAA2B,SAAiB,EAAjB,QAAQ,SAAS;MAAA,UAAG;IAAQ,CAAa,CAAC,GAArE,IAAqE;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAjCxE;MACa,SAAkB,EAAlB,kBAAkB;MACpB,OAMR,EANQ,EAMR;MAAA,WAEA,EACuD,EACxD,EAiBE,EACD,EAEO,EACP,GAAqE;IAAA,CACnE,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAlCN,GAkCM;AAAA,CAET;AAED,eAAe,KAAK","ignoreList":[]}
@@ -90,6 +90,9 @@ const BaseModal = t0 => {
90
90
  if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
91
91
  t5 = /*#__PURE__*/_jsx("div", {
92
92
  onFocus: () => {
93
+ if (!containerRef.current) {
94
+ throw Error("Missing container reference");
95
+ }
93
96
  const elems = containerRef.current.querySelectorAll("*");
94
97
  for (let i = elems.length - 1; i >= 0; --i) {
95
98
  elems[i].focus();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n const elems = containerRef.current!.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":";AAAA,SAIE,SAAS,EACT,OAAO,EACP,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAExC,SAAqB,QAAQ,QAA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AAuB;EAAA;EAAA;IAZhC;MACa,oBAAM;MACN,SAAe,EAAf,KAAK,UAAU;MACb,kBAA0D;MAC9D,OAER,EAFQ,KAER;MACQ,OAER,EAFQ,MAER;MACI,GAAY,EAAZ,YAAY;MACZ,IAAQ,EAAR,QAAQ;MACN,KAAuB,EAAvB,GAAuB;MAAA,UAE7B;IAAQ,CACN,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACN;MACW,OAER,EAFQ;QACP,UAAU,QAAe,OAAE,CAAD,CAAC;MAAA,CAC5B;MAGS,QAAC,EAAD;IAAC,CACZ,CAAC;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAnED,+BAAY,cAEf;MAAA,WACG,SAAS,EACV,GA4BE,EAYF,GAeM,EACN,GAOE,EACD,SAAS;IAAA,CACP,CAAC,EAER,QAAQ,KACV,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAxEM,GAwEN;AAAA,CACF,CAED;AACA,SAAS,SAAS;AAElB,MAAM,KAEL,GAAG;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;IAAA,MAAkB;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EACrB,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGjD,uBAAC,SAAS;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAxC,EAAwC;AAAA,CAChD;AAED,eAAe,KAAK;AAhJyB;EA0GjC,GAAC,gBAAgB,CAAC,CAAC;AAAA;AA1Gc;EA6GjC,KAAK,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n if (!containerRef.current) throw Error('Missing container reference');\n const elems = containerRef.current.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":";AAAA,SAIE,SAAS,EACT,OAAO,EACP,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAExC,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA;EAAA;AAAA;AAC8B,+DAmB9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,SAAoC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAW7C;EACC,qBAAqB,MAAM,CAAwB,IAAI,CAAC;EACxD,mBAAmB,MAAM,CAAwB,IAAI,CAAC;EAAC;EAAA;EAAA;IAG7C;MACR,IAAI,iBAA6B,IAA7B,QAA6B;QAC/B,MAAM,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC3C,MAAM,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC;MAAA;MAC3C,OACM;QACL,IAAI,iBAA6B,IAA7B,QAA6B;UAC/B,MAAM,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC;UAC9C,MAAM,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC;QAAA;MAC9C,CACF;IAAA,CACF;IAAE,MAAC,iBAAiB,EAAE,QAAQ,CAAC;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EAXhC,SAAS,CAAC,EAWT,EAAE,EAA6B,CAAC;EAAA;EAAA;EAAA;IAGv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A;EAAA;EACrB,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGjD,uBAAC,SAAS;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAxC,EAAwC;AAAA,CAChD;AAED,eAAe,KAAK;AAjJyB;EA2GjC,GAAC,gBAAgB,CAAC,CAAC;AAAA;AA3Gc;EA8GjC,KAAK,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
@@ -82,9 +82,9 @@ const TextArea = t0 => {
82
82
  t4 = $[4];
83
83
  }
84
84
  useLayoutEffect(t3, t4);
85
- let containerClassName = custom.container;
85
+ let containerClassName = custom.container ?? "";
86
86
  if (error) {
87
- containerClassName = containerClassName + ` ${custom.error}`;
87
+ containerClassName = containerClassName + ` ${custom.error ?? ""}`;
88
88
  }
89
89
  let t5;
90
90
  if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
@@ -107,7 +107,7 @@ const TextArea = t0 => {
107
107
  } else {
108
108
  t6 = $[8];
109
109
  }
110
- const t7 = `${custom.textarea} ${custom.hidden}`;
110
+ const t7 = `${custom.textarea ?? ""} ${custom.hidden ?? ""}`;
111
111
  const t8 = localValue || " ";
112
112
  let t9;
113
113
  if ($[9] !== t7 || $[10] !== t8) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [localValue, setLocalValue] = useState(value ?? '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container;\n if (error) containerClassName += ` ${custom.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea} ${custom.hidden}`}\n\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />\n {error && error !== true\n ? <div className={custom.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default TextArea;\n"],"mappings":";AAAA,SAOE,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAmBxC,MAAM,QAAkC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAY3C;EACC,eAAe,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC;EAExD,sBAAsB,MAAM,CAAsB,IAAI,CAAC;EACvD,4BAA4B,QAAQ,CAAqB,CAAC;EAE1D,oBAAoB,MAAM,CAAsB,IAAI,CAAC;EAErD,oCAAoC,QAAQ,CAAC,KAAW,IAAX,EAAW,CAAC;EACzD,IAAI,KAAK,KAAK,SAAiC,IAApB,UAAU,KAAK,KAAK;IAAE,aAAa,CAAC,KA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;IAAA;EAAA;EAAA,OA3DN,GA2DM;AAAA,CAET;AAED,eAAe,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [localValue, setLocalValue] = useState(value ?? '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container ?? '';\n if (error) containerClassName += ` ${custom.error ?? ''}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea ?? ''} ${custom.hidden ?? ''}`}\n\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />\n {error && error !== true\n ? <div className={custom.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default TextArea;\n"],"mappings":";AAAA,SAOE,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAA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;MAEnB,GAOJ,EAPI,GAOJ;MAEM,KAAU,EAAV,GAAU;MACV,KAAU,EAAV;IAAU,CAClB,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACD,WAAuB,IAAd,KAAK,KAAK,IAEZ,gBAFP;MACmB,SAAmB,EAAnB,MAAM,aAAa;MAAA,UAAG;IAAK,CACxC,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IA1DV;MACa,SAAkB,EAAlB,kBAAkB;MACpB,OAER,EAFQ,EAER;MAAA,WAEA,EAAwE,EACzE,EAkBE,EACF,GA6BE,EACD,GAEO;IAAA,CACL,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OA3DN,GA2DM;AAAA,CAET;AAED,eAAe,QAAQ","ignoreList":[]}
@@ -157,9 +157,9 @@ function setComponentPositions(pageX, pageY, placement, element, tooltip) {
157
157
  pos.arrowY -= tooltipRects.container.height + tooltipRects.arrow.height;
158
158
  pos.baseArrowStyle = ARROW_STYLE_UP;
159
159
  }
160
- const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
160
+ const containerStyle = `left:${pos.containerX.toString()}px;top:${pos.containerY.toString()}px`;
161
161
  tooltip.container.setAttribute("style", containerStyle);
162
- const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
162
+ const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX.toString()}px;top:${pos.arrowY.toString()}px`;
163
163
  tooltip.arrow.setAttribute("style", arrowStyle);
164
164
  } /* The Tooltip component itself. */
165
165
  const Tooltip = t0 => {
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function checkViewportFit(pos, tooltipRects, viewportRect) {\n// const { containerX, containerY } = pos;\n// if (containerX < viewportRect.left + 6) return HIT.LEFT;\n// if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n// return HIT.NONE;\n// }\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n// if (pos.containerX < pageXOffset + 6) {\n// pos.containerX = pageXOffset + 6;\n// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n// } else {\n// const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n// if (containerX > maxX) {\n// containerX = maxX;\n// arrowX = Math.min(\n// containerRect.width - 6,\n// pageX - containerX - arrowRect.width / 2,\n// );\n// }\n// }\n// }\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"iDAAA;AACA;AACA;AACA;AACA;AAEA,SAIE,mBAAmB,EACnB,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAAC,+DAIzC;AACA;AACA;AACA;AACA,WAAY,UAAU,0BAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAA,OAAV,UAAU;AAAA;AAOtB,MAAM,gBAAgB,GAAG,CACvB,iCAAiC,EACjC,+BAA+B,EAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC;AAEX,MAAM,cAAc,GAAG,CACrB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAiBX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,OAAoB,EAAiB;EAC7D,OAAO;IACL,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC,SAAS,C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;IAJ/D,8BAAY,cAEf;MAAgB,SAAe,EAAf,KAAK,UAAU;MAAO,GAAY,EAAZ,YAAY;MAAA,WAChD,EAA8C,EAC9C,EAAgE;IAAA,CAC7D,CAAC,EAER,QAAQ,KACV,CAAC;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OARM,EAQN;AAAA,CACF;AAED,eAAe,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"Tooltip.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function checkViewportFit(pos, tooltipRects, viewportRect) {\n// const { containerX, containerY } = pos;\n// if (containerX < viewportRect.left + 6) return HIT.LEFT;\n// if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n// return HIT.NONE;\n// }\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n// if (pos.containerX < pageXOffset + 6) {\n// pos.containerX = pageXOffset + 6;\n// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n// } else {\n// const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n// if (containerX > maxX) {\n// containerX = maxX;\n// arrowX = Math.min(\n// containerRect.width - 6,\n// pageX - containerX - arrowRect.width / 2,\n// );\n// }\n// }\n// }\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX.toString()}px;top:${pos.containerY.toString()}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX.toString()}px;top:${pos.arrowY.toString()}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"iDAAA;AACA;AACA;AACA;AACA;AAEA,SAIE,mBAAmB,EACnB,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAAC,+DAIzC;AACA;AACA;AACA;AACA,WAAY,UAAU,0BAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAV,UAAU;EAAA,OAAV,UAAU;AAAA;AAOtB,MAAM,gBA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,YAAY,QAAQ;QAAA,SACtB,UAAU;MACrB,CAAC,CAAC;IAAA,CACH;IAAA;EAAA;IAAA;EAAA;EAfD,gBAAgB,EAef;EAAC;EAAA;IACuB,YAAO;MAAA;IAAU,CAAC,CAAC;IAAA;EAAA;IAAA;EAAA;EAA5C,mBAAmB,CAAC,GAAG,EAAE,EAAmB,CAAC;EAAA;EAAA;IAKvC;MAAgB,SAAW,EAAX,KAAK,MAAM;MAAO,GAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAC9C;MAAgB,SAAa,EAAb,KAAK,QAAQ;MAAO,GAAU,EAAV,UAAU;MAAA,UAAG;IAAQ,CAAM,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAJ/D,8BAAY,cAEf;MAAgB,SAAe,EAAf,KAAK,UAAU;MAAO,GAAY,EAAZ,YAAY;MAAA,WAChD,EAA8C,EAC9C,EAAgE;IAAA,CAC7D,CAAC,EAER,QAAQ,KACV,CAAC;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OARM,EAQN;AAAA,CACF;AAED,eAAe,OAAO","ignoreList":[]}
@@ -51,6 +51,7 @@ const WithTooltip = ({
51
51
  const [showTooltip, setShowTooltip] = useState(false);
52
52
  const updatePortalPosition = (cursorX, cursorY) => {
53
53
  if (showTooltip) {
54
+ if (!wrapperRef.current) throw Error("Missing reference");
54
55
  const wrapperRect = wrapperRef.current.getBoundingClientRect();
55
56
  if (cursorX < wrapperRect.left || cursorX > wrapperRect.right || cursorY < wrapperRect.top || cursorY > wrapperRect.bottom) {
56
57
  setShowTooltip(false);
@@ -90,6 +91,7 @@ const WithTooltip = ({
90
91
  // cycle due to the implementation).
91
92
  if (tooltipRef.current) {
92
93
  setHeap(prev_0 => {
94
+ if (!wrapperRef.current) throw Error("Missing reference");
93
95
  tooltipRef.current?.pointTo(prev_0.lastCursorX + window.scrollX, prev_0.lastCursorY + window.scrollY, placement, wrapperRef.current);
94
96
  return prev_0;
95
97
  });
@@ -104,7 +106,7 @@ const WithTooltip = ({
104
106
  }
105
107
  return undefined;
106
108
  }, [placement, showTooltip, tip]);
107
- let container = custom.wrapper;
109
+ let container = custom.wrapper ?? "";
108
110
  if (classNameProp) container += ` ${classNameProp}`;
109
111
  useEffect(() => {
110
112
  const listener_0 = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\n });\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n setHeap((prev) => {\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,SAKE,SAAS,EACT,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,OAEzD,OAAO,IACZ,UAAU;AAIZ;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAgD,+DA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAsC,GAAG,CAAC;EAC9C,QAAQ;EACR,SAAS,EAAE,aAAa;EACxB,OAAO;EACP,aAAa;EACb,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS,GAAG,UAAU,CAAC,YAAY;EACnC,GAAG;EACH,KAAK;EACL,KAAK;EACL,GAAG;EACH,GAAG;AACL,CAAC,KAAK;EACJ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,EAAE,YAAY,EAAE,KAAK,CAAC;EAE3D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAQ;IACtC,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE;EACpB,CAAC,CAAC;EAEF,MAAM,UAAU,GAAG,MAAM,CAAc,IAAI,CAAC;EAC5C,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC;EAC/C,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;EAErD,MAAM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KAAC,OAAO;MAAC,GAAG,EAAE,UAAW;MAAC,KAAK,EAAE,MAAO;MAAA,UAAE;IAAG,CAAU,CAAC,GACxD,IAAI,EAET,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAM,CAAU,GAAG,WAAsB;AAEzC,CAAC,CAAC,UAAU,GAAG,UAAU;AAEzB,eAAe,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n if (!wrapperRef.current) throw Error('Missing reference');\n const wrapperRect = wrapperRef.current.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current,\n );\n }\n } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\n });\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n setHeap((prev) => {\n if (!wrapperRef.current) throw Error('Missing reference');\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper ?? '';\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,SAKE,SAAS,EACT,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,OAEzD,OAAO,IACZ,UAAU;AAIZ;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAgD,+DA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAsC,GAAG,CAAC;EAC9C,QAAQ;EACR,SAAS,EAAE,aAAa;EACxB,OAAO;EACP,aAAa;EACb,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS,GAAG,UAAU,CAAC,YAAY;EACnC,GAAG;EACH,KAAK;EACL,KAAK;EACL,GAAG;EACH,GAAG;AACL,CAAC,KAAK;EACJ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,EAAE,YAAY,EAAE,KAAK,CAAC;EAE3D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAQ;IACtC,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE;EACpB,CAAC,CAAC;EAEF,MAAM,UAAU,GAAG,MAAM,CAAc,IAAI,CAAC;EAC5C,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC;EAC/C,MAAM,CAAC,WAAW,EAAE,cAAc,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O,GAAG,IAAI,CAEzB;MACA,IAAI,GAAG,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI;IAC7B,CAAE;IACF,IAAI,EAAC,cAAc;IACnB,KAAK,EAAE,KAEP;IAAA;IAAA,GACI,cAAc;IAAA,WAGhB,WAAW,IAAI,GAAG,KAAK,IAAI,gBACvB,KAAC,OAAO;MAAC,GAAG,EAAE,UAAW;MAAC,KAAK,EAAE,MAAO;MAAA,UAAE;IAAG,CAAU,CAAC,GACxD,IAAI,EAET,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAM,CAAU,GAAG,WAAsB;AAEzC,CAAC,CAAC,UAAU,GAAG,UAAU;AAEzB,eAAe,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import _pushInstanceProperty from "core-js-pure/stable/instance/push.js";
1
+ import _pushInstanceProperty from "core-js-pure/features/instance/push.js";
2
2
  import { c as _c } from "react/compiler-runtime";
3
3
  import { useImperativeHandle, useRef } from "react";
4
4
  import { BaseModal } from "../../../Modal/index.js";
@@ -32,6 +32,9 @@ const Options = t0 => {
32
32
  if (!e) {
33
33
  return;
34
34
  }
35
+ if (!opsRef.current) {
36
+ throw Error("Missing reference");
37
+ }
35
38
  const rect = opsRef.current.getBoundingClientRect();
36
39
  const style = window.getComputedStyle(e);
37
40
  const mBottom = parseFloat(style.marginBottom);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;AAAA,SAIE,mBAAmB,EACnB,MAAM,Q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AKV,EALU;YACT,IAAI,GAAC,IAAI,KAAK,OAAO;cACnB,QAAQ,CAAC,MAAM,CAAC;cAChB,GAAC,gBAAgB,CAAC,CAAC;YAAA;UACpB,CACF;UACI,IAAQ,EAAR,QAAQ;UACH,QAAC,EAAD,CAAC;UAAA,UAEV;QAAK,GAdD,MAeF,CACP,CAAC;MAAA;IACF;IACF;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAaU;MAAA,IACD,EAAE;MAAA,WACK,cAAc;MAAA,SAChB,EAAE;MAAA,KACN,EAAE;MAAA,SACE,CAAC;IACZ,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAED;MAAU,GAAM,EAAN,MAAM;MAAA,UAAG;IAAW,CAAM,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAlBvC,uBAAC,SAAS;MAMR,iBAAiB,EAAjB,IAAiB;MACjB,oBAAoB,EAApB,IAAoB;MACV,QAAQ,EAAR,QAAQ;MACX,KAAc,EAAd,cAAc;MACd,KAMN,EANM,EAMN;MAAA,UAED;IAAqC,CAC5B,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAnBZ,EAmBY;AAAA,CAEf;AAED,eAAe,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n if (!opsRef.current) throw Error('Missing reference');\n const rect = opsRef.current.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;AAAA,SAIE,mBAAmB,EACnB,MAAM,QACD,OAAO;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C,MAAM,CAAC;YAChB,GAAC,gBAAgB,CAAC,CAAC;UAAA,CACpB;UACU,SAKV,EALU;YACT,IAAI,GAAC,IAAI,KAAK,OAAO;cACnB,QAAQ,CAAC,MAAM,CAAC;cAChB,GAAC,gBAAgB,CAAC,CAAC;YAAA;UACpB,CACF;UACI,IAAQ,EAAR,QAAQ;UACH,QAAC,EAAD,CAAC;UAAA,UAEV;QAAK,GAdD,MAeF,CACP,CAAC;MAAA;IACF;IACF;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAaU;MAAA,IACD,EAAE;MAAA,WACK,cAAc;MAAA,SAChB,EAAE;MAAA,KACN,EAAE;MAAA,SACE,CAAC;IACZ,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAED;MAAU,GAAM,EAAN,MAAM;MAAA,UAAG;IAAW,CAAM,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAlBvC,uBAAC,SAAS;MAMR,iBAAiB,EAAjB,IAAiB;MACjB,oBAAoB,EAApB,IAAoB;MACV,QAAQ,EAAR,QAAQ;MACX,KAAc,EAAd,cAAc;MACd,KAMN,EANM,EAMN;MAAA,UAED;IAAqC,CAC5B,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAnBZ,EAmBY;AAAA,CAEf;AAED,eAAe,OAAO","ignoreList":[]}
@@ -80,6 +80,9 @@ const CustomDropdown = t0 => {
80
80
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
81
81
  t3 = e => {
82
82
  const view = window.visualViewport;
83
+ if (!dropdownRef.current) {
84
+ throw Error("Missing dropdown reference");
85
+ }
83
86
  const rect = dropdownRef.current.getBoundingClientRect();
84
87
  setActive(true);
85
88
  setOpsPos({
@@ -121,14 +124,14 @@ const CustomDropdown = t0 => {
121
124
  } else {
122
125
  selected = $[8];
123
126
  }
124
- let containerClassName = custom.container;
127
+ let containerClassName = custom.container ?? "";
125
128
  if (active) {
126
- containerClassName = containerClassName + ` ${custom.active}`;
129
+ containerClassName = containerClassName + ` ${custom.active ?? ""}`;
127
130
  }
128
131
  let opsContainerClass = custom.select ?? "";
129
132
  if (upward) {
130
- containerClassName = containerClassName + ` ${custom.upward}`;
131
- opsContainerClass = opsContainerClass + ` ${custom.upward}`;
133
+ containerClassName = containerClassName + ` ${custom.upward ?? ""}`;
134
+ opsContainerClass = opsContainerClass + ` ${custom.upward ?? ""}`;
132
135
  }
133
136
  let t5;
134
137
  if ($[9] !== custom.label || $[10] !== label) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container;\n if (active) containerClassName += ` ${custom.active}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward}`;\n opsContainerClass += ` ${custom.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":";AAAA,SAGE,SAAS,EACT,MAAM,EAC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EAAA;EAAA,OAlCN,GAkCM;AAAA,CAET;AAED,eAAe,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n if (!dropdownRef.current) throw Error('Missing dropdown reference');\n const rect = dropdownRef.current.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container ?? '';\n if (active) containerClassName += ` ${custom.active ?? ''}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward ?? ''}`;\n opsContainerClass += ` ${custom.upward ?? ''}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":";AAAA,SAGE,SAAS,EACT,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAS,QAAQ,QAAQ,0BAA0B;AAAC,SAEjB,eAAe;AAAA,OAE3C,OAAO,IAAmC,QAAQ;AAEzD;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAExC,MAAM,cAEL,GAAG;EAAA;EAAC;IAAA;IAAA;I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core-js-pure/stable/instance/push.js"; // Implements dropdown based on the native HTML <select> element.
1
+ import _pushInstanceProperty from "core-js-pure/features/instance/push.js"; // Implements dropdown based on the native HTML <select> element.
2
2
  import { useTheme } from "@dr.pogodin/react-themes";
3
3
  import { optionValueName } from "../common.js";
4
4
  const defaultTheme = {
@@ -68,8 +68,8 @@ const Dropdown = ({
68
68
  value: value,
69
69
  children: value
70
70
  }, "__reactUtilsHiddenOption");
71
- let selectClassName = composed.select;
72
- if (!isValidValue) selectClassName += ` ${composed.invalid}`;
71
+ let selectClassName = composed.select ?? "";
72
+ if (!isValidValue) selectClassName += ` ${composed.invalid ?? ""}`;
73
73
  return /*#__PURE__*/_jsxs("div", {
74
74
  className: composed.container,
75
75
  children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {