You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpeakerStatsSearch.tsx 3.9KB

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