Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SpeakerStatsSearch.js 3.8KB

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