Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SpeakerStatsSearch.tsx 3.7KB

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