close.js 756 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* @flow */
import { applyStyles } from '../utils/dom/css';
import { hintsStyle, hintStyle, closeButtonStyle } from '../styles';

function createHint(document: Document, hint: string) {
  const span = document.createElement('span');
  span.appendChild(document.createTextNode(hint));
  applyStyles(span, hintStyle);
  return span;
}

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

  const close = createHint(document, '×');
  close.addEventListener('click', () => callback());
  applyStyles(close, closeButtonStyle);
  hints.appendChild(close);
  return hints;
}

export type { CloseCallback };
export { createClose };