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.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* @flow */
  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 { IconSearch, Icon } from '../../../base/icons';
  7. import { getFieldValue } from '../../../base/react';
  8. import BaseTheme from '../../../base/ui/components/BaseTheme';
  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. ...theme.typography.bodyShortRegular,
  40. lineHeight: `${theme.typography.bodyShortRegular.lineHeight}px`
  41. },
  42. [theme.breakpoints.down(MOBILE_BREAKPOINT)]: {
  43. height: 48,
  44. padding: '13px 16px 13px 44px',
  45. '&::placeholder': {
  46. ...theme.typography.bodyShortRegularLarge,
  47. lineHeight: `${theme.typography.bodyShortRegular.lineHeightLarge}px`
  48. }
  49. }
  50. }
  51. };
  52. });
  53. /**
  54. * The type of the React {@code Component} props of {@link SpeakerStatsSearch}.
  55. */
  56. type Props = {
  57. /**
  58. * The function to initiate the change in the speaker stats table.
  59. */
  60. onSearch: Function,
  61. };
  62. /**
  63. * React component for display an individual user's speaker stats.
  64. *
  65. * @returns {React$Element<any>}
  66. */
  67. function SpeakerStatsSearch({ onSearch }: Props) {
  68. const classes = useStyles();
  69. const { t } = useTranslation();
  70. const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
  71. const [ searchValue, setSearchValue ] = useState<string>('');
  72. /**
  73. * Callback for the onChange event of the field.
  74. *
  75. * @param {Object} evt - The static event.
  76. * @returns {void}
  77. */
  78. const onChange = useCallback((evt: Event) => {
  79. const value = getFieldValue(evt);
  80. setSearchValue(value);
  81. onSearch && onSearch(value);
  82. }, []);
  83. const preventDismiss = useCallback((evt: KeyboardEvent) => {
  84. if (evt.key === 'Enter') {
  85. evt.preventDefault();
  86. }
  87. }, []);
  88. if (disableSpeakerStatsSearch) {
  89. return null;
  90. }
  91. return (
  92. <div className = { classes.speakerStatsSearchContainer }>
  93. <Icon
  94. className = { classes.searchIcon }
  95. color = { BaseTheme.palette.surface07 }
  96. src = { IconSearch } />
  97. <input
  98. autoComplete = 'off'
  99. autoFocus = { false }
  100. className = { classes.speakerStatsSearch }
  101. id = 'speaker-stats-search'
  102. name = 'speakerStatsSearch'
  103. onChange = { onChange }
  104. onKeyPress = { preventDismiss }
  105. placeholder = { t('speakerStats.search') }
  106. tabIndex = { 0 }
  107. value = { searchValue } />
  108. </div>
  109. );
  110. }
  111. export default SpeakerStatsSearch;