GridLi.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* eslint-disable react/require-default-props */
  2. import { h, type ComponentChildren } from 'preact'
  3. import classNames from 'classnames'
  4. import type { RestrictionError } from '@uppy/core/lib/Restricter'
  5. import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
  6. type GridListItemProps<M extends Meta, B extends Body> = {
  7. className: string
  8. isDisabled: boolean
  9. restrictionError?: RestrictionError<M, B> | null
  10. isChecked: boolean
  11. title?: string
  12. itemIconEl: any
  13. showTitles?: boolean
  14. toggleCheckbox: (event: Event) => void
  15. recordShiftKeyPress: (event: KeyboardEvent) => void
  16. id: string
  17. children?: ComponentChildren
  18. }
  19. function GridListItem<M extends Meta, B extends Body>(
  20. props: GridListItemProps<M, B>,
  21. ): h.JSX.Element {
  22. const {
  23. className,
  24. isDisabled,
  25. restrictionError,
  26. isChecked,
  27. title,
  28. itemIconEl,
  29. showTitles,
  30. toggleCheckbox,
  31. recordShiftKeyPress,
  32. id,
  33. children,
  34. } = props
  35. const checkBoxClassName = classNames(
  36. 'uppy-u-reset',
  37. 'uppy-ProviderBrowserItem-checkbox',
  38. 'uppy-ProviderBrowserItem-checkbox--grid',
  39. { 'uppy-ProviderBrowserItem-checkbox--is-checked': isChecked },
  40. )
  41. return (
  42. <li
  43. className={className}
  44. title={isDisabled ? restrictionError?.message : undefined}
  45. >
  46. <input
  47. type="checkbox"
  48. className={checkBoxClassName}
  49. onChange={toggleCheckbox}
  50. onKeyDown={recordShiftKeyPress}
  51. // @ts-expect-error this is fine onMouseDown too
  52. onMouseDown={recordShiftKeyPress}
  53. name="listitem"
  54. id={id}
  55. checked={isChecked}
  56. disabled={isDisabled}
  57. data-uppy-super-focusable
  58. />
  59. <label
  60. htmlFor={id}
  61. aria-label={title}
  62. className="uppy-u-reset uppy-ProviderBrowserItem-inner"
  63. >
  64. {itemIconEl}
  65. {showTitles && title}
  66. {children}
  67. </label>
  68. </li>
  69. )
  70. }
  71. export default GridListItem