close.js 845 Bytes
Newer Older
1
2
3
4
/* @flow */
import { applyStyles } from '../utils/dom/css';
import { hintsStyle, hintStyle, closeButtonStyle } from '../styles';

5
function createHint(document: Document, hint: string, title: string) {
6
7
  const span = document.createElement('span');
  span.appendChild(document.createTextNode(hint));
8
  span.setAttribute('title', title);
9
10
11
12
13
14
15
16
17
  applyStyles(span, hintStyle);
  return span;
}

type CloseCallback = () => void;
function createClose(document: Document, callback: CloseCallback) {
  const hints = document.createElement('div');
  applyStyles(hints, hintsStyle);

18
  const close = createHint(document, '×', 'Click or press Escape to dismiss.');
19
20
21
22
23
24
25
26
  close.addEventListener('click', () => callback());
  applyStyles(close, closeButtonStyle);
  hints.appendChild(close);
  return hints;
}

export type { CloseCallback };
export { createClose };