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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import ReducerRegistry from '../redux/ReducerRegistry';
  2. import { HIDE_TOOLTIP, SHOW_TOOLTIP } from './actionTypes';
  3. export interface ITooltipState {
  4. content: string;
  5. previousContent: string;
  6. visible: boolean;
  7. }
  8. const DEFAULT_STATE = {
  9. content: '',
  10. previousContent: '',
  11. visible: false
  12. };
  13. /**
  14. * Reduces redux actions which mark the tooltip as displayed or hidden.
  15. *
  16. * @param {IDialogState} state - The current redux state.
  17. * @param {Action} action - The redux action to reduce.
  18. * @param {string} action.type - The type of the redux action to reduce..
  19. * @returns {State} The next redux state that is the result of reducing the
  20. * specified action.
  21. */
  22. ReducerRegistry.register<ITooltipState>('features/base/tooltip', (state = DEFAULT_STATE, action): ITooltipState => {
  23. switch (action.type) {
  24. case SHOW_TOOLTIP:
  25. return {
  26. content: action.content,
  27. previousContent: state.content,
  28. visible: true
  29. };
  30. case HIDE_TOOLTIP: {
  31. // The tooltip can be marked as hidden only if the hide action
  32. // is dispatched by the tooltip that is displayed.
  33. if (action.content === state.content) {
  34. return {
  35. content: '',
  36. previousContent: '',
  37. visible: false
  38. };
  39. }
  40. return state;
  41. }
  42. }
  43. return state;
  44. });