Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SpeakerStatsSearch.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { Theme } from '@mui/material';
  2. import React, { useCallback, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useSelector } from 'react-redux';
  5. import { makeStyles } from 'tss-react/mui';
  6. import Icon from '../../../base/icons/components/Icon';
  7. import { IconSearch } from '../../../base/icons/svg';
  8. import { getFieldValue } from '../../../base/react/functions';
  9. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  10. import { MOBILE_BREAKPOINT } from '../../constants';
  11. import { isSpeakerStatsSearchDisabled } from '../../functions';
  12. const useStyles = makeStyles()((theme: Theme) => {
  13. return {
  14. speakerStatsSearchContainer: {
  15. position: 'relative'
  16. },
  17. searchIcon: {
  18. display: 'none',
  19. [theme.breakpoints.down(MOBILE_BREAKPOINT)]: {
  20. display: 'block',
  21. position: 'absolute',
  22. color: theme.palette.text03,
  23. left: 16,
  24. top: 13,
  25. width: 20,
  26. height: 20
  27. }
  28. },
  29. speakerStatsSearch: {
  30. backgroundColor: theme.palette.field01,
  31. border: '1px solid',
  32. borderRadius: 6,
  33. borderColor: theme.palette.ui05,
  34. color: theme.palette.text01,
  35. padding: '10px 16px',
  36. width: '100%',
  37. height: 40,
  38. '&::placeholder': {
  39. color: theme.palette.text03,
  40. ...withPixelLineHeight(theme.typography.bodyShortRegular)
  41. },
  42. [theme.breakpoints.down(MOBILE_BREAKPOINT)]: {
  43. height: 48,
  44. padding: '13px 16px 13px 44px',
  45. '&::placeholder': {
  46. ...withPixelLineHeight(theme.typography.bodyShortRegular)
  47. }
  48. }
  49. }
  50. };
  51. });
  52. /**
  53. * The type of the React {@code Component} props of {@link SpeakerStatsSearch}.
  54. */
  55. type Props = {
  56. /**
  57. * The function to initiate the change in the speaker stats table.
  58. */
  59. onSearch: Function;
  60. };
  61. /**
  62. * React component for display an individual user's speaker stats.
  63. *
  64. * @returns {React$Element<any>}
  65. */
  66. function SpeakerStatsSearch({ onSearch }: Props) {
  67. const { classes, theme } = useStyles();
  68. const { t } = useTranslation();
  69. const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
  70. const [ searchValue, setSearchValue ] = useState<string>('');
  71. /**
  72. * Callback for the onChange event of the field.
  73. *
  74. * @param {Object} evt - The static event.
  75. * @returns {void}
  76. */
  77. const onChange = useCallback((evt: React.ChangeEvent<HTMLInputElement>) => {
  78. const value = getFieldValue(evt);
  79. setSearchValue(value);
  80. onSearch?.(value);
  81. }, []);
  82. const preventDismiss = useCallback((evt: React.KeyboardEvent) => {
  83. if (evt.key === 'Enter') {
  84. evt.preventDefault();
  85. }
  86. }, []);
  87. if (disableSpeakerStatsSearch) {
  88. return null;
  89. }
  90. return (
  91. <div className = { classes.speakerStatsSearchContainer }>
  92. <Icon
  93. className = { classes.searchIcon }
  94. color = { theme.palette.icon03 }
  95. src = { IconSearch } />
  96. <input
  97. autoComplete = 'off'
  98. autoFocus = { false }
  99. className = { classes.speakerStatsSearch }
  100. id = 'speaker-stats-search'
  101. name = 'speakerStatsSearch'
  102. onChange = { onChange }
  103. onKeyPress = { preventDismiss }
  104. placeholder = { t('speakerStats.search') }
  105. tabIndex = { 0 }
  106. value = { searchValue } />
  107. </div>
  108. );
  109. }
  110. export default SpeakerStatsSearch;