您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SpeakerStatsSearch.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* @flow */
  2. import { FieldTextStateless as TextField } from '@atlaskit/field-text';
  3. import { makeStyles } from '@material-ui/core/styles';
  4. import React, { useCallback, useState } from 'react';
  5. import { useTranslation } from 'react-i18next';
  6. import { useSelector } from 'react-redux';
  7. import { getFieldValue } from '../../base/react';
  8. import { isSpeakerStatsSearchDisabled } from '../functions';
  9. const useStyles = makeStyles(theme => {
  10. return {
  11. speakerStatsSearch: {
  12. position: 'absolute',
  13. right: '80px',
  14. top: '8px',
  15. [theme.breakpoints.down('400')]: {
  16. left: 20,
  17. right: 0,
  18. top: 42
  19. }
  20. }
  21. };
  22. });
  23. /**
  24. * The type of the React {@code Component} props of {@link SpeakerStatsSearch}.
  25. */
  26. type Props = {
  27. /**
  28. * The function to initiate the change in the speaker stats table.
  29. */
  30. onSearch: Function,
  31. };
  32. /**
  33. * React component for display an individual user's speaker stats.
  34. *
  35. * @returns {React$Element<any>}
  36. */
  37. function SpeakerStatsSearch({ onSearch }: Props) {
  38. const classes = useStyles();
  39. const { t } = useTranslation();
  40. const [ searchValue, setSearchValue ] = useState<string>('');
  41. const onChange = useCallback((evt: Event) => {
  42. const value = getFieldValue(evt);
  43. setSearchValue(value);
  44. onSearch && onSearch(value);
  45. }, []);
  46. const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
  47. if (disableSpeakerStatsSearch) {
  48. return null;
  49. }
  50. return (
  51. <div className = { classes.speakerStatsSearch }>
  52. <TextField
  53. autoComplete = 'off'
  54. autoFocus = { false }
  55. compact = { true }
  56. name = 'speakerStatsSearch'
  57. onChange = { onChange }
  58. placeholder = { t('speakerStats.search') }
  59. shouldFitContainer = { false }
  60. type = 'text'
  61. value = { searchValue } />
  62. </div>
  63. );
  64. }
  65. export default SpeakerStatsSearch;