ui_helpers.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. User Interface Helpers
  2. ----------------------
  3. JupyterLab comes with helpers to show or request simple information from a user.
  4. Those speed up development and ensure a common look and feel.
  5. Dialogs
  6. ~~~~~~~
  7. Message Dialogs
  8. '''''''''''''''
  9. Helper functions to show a message to the user are available in the ``apputils`` package.
  10. These dialogs return a ``Promise`` resolving when the user dismisses the dialog.
  11. There is one helper:
  12. * ``showErrorMessage`` : show an error message dialog.
  13. Input Dialogs
  14. '''''''''''''
  15. Helper functions to request a single input from the user are available in the ``apputils``
  16. package within the ``InputDialog`` namespace. There are four helpers:
  17. * ``getBoolean`` : request a boolean through a checkbox.
  18. * ``getItem`` : request a item from a list; the list may be editable.
  19. * ``getNumber`` : request a number; if the user input is not a valid number, NaN is returned.
  20. * ``getText`` : request a short text.
  21. All dialogs are built on the standard ``Dialog``. Therefore the helper functions each return
  22. a ``Promise`` resolving in a ``Dialog.IResult`` object.
  23. .. code:: typescript
  24. // Request a boolean
  25. InputDialog.getBoolean({ title: 'Check or not?' }).then(value => {
  26. console.log('boolean ' + value.value);
  27. });
  28. // Request a choice from a list
  29. InputDialog.getItem({
  30. title: 'Pick a choice',
  31. items: ['1', '2']
  32. }).then(value => {
  33. console.log('item ' + value.value);
  34. });
  35. // Request a choice from a list or specify your own choice
  36. InputDialog.getItem({
  37. title: 'Pick a choice or write your own',
  38. items: ['1', '2'],
  39. editable: true
  40. }).then(value => {
  41. console.log('editable item ' + value.value);
  42. });
  43. // Request a number
  44. InputDialog.getNumber({ title: 'How much?' }).then(value => {
  45. console.log('number ' + value.value);
  46. });
  47. // Request a text
  48. InputDialog.getText({ title: 'Provide a text' }).then(value => {
  49. console.log('text ' + value.value);
  50. });