form-old.stories.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {Component} from 'react';
  2. import {action} from '@storybook/addon-actions';
  3. import PropTypes from 'prop-types';
  4. import {
  5. Form as LegacyForm,
  6. TextField as LegacyTextField,
  7. } from 'sentry/components/deprecatedforms';
  8. class UndoButton extends Component {
  9. handleClick(e) {
  10. e.preventDefault();
  11. this.context.form.undo();
  12. }
  13. render() {
  14. return (
  15. <button type="button" onClick={this.handleClick.bind(this)}>
  16. Undo
  17. </button>
  18. );
  19. }
  20. }
  21. UndoButton.contextTypes = {
  22. form: PropTypes.object,
  23. };
  24. export default {
  25. title: 'Deprecated/Form',
  26. };
  27. export const Empty = () => <LegacyForm onSubmit={action('submit')} />;
  28. Empty.storyName = 'empty';
  29. export const WithCancel = () => (
  30. <LegacyForm onCancel={action('cancel')} onSubmit={action('submit')} />
  31. );
  32. WithCancel.storyName = 'with Cancel';
  33. WithCancel.parameters = {
  34. docs: {
  35. description: {
  36. story: 'Adds a "Cancel" button when `onCancel` is defined',
  37. },
  38. },
  39. };
  40. export const SaveOnBlurAndUndo = () => (
  41. <LegacyForm saveOnBlur allowUndo>
  42. <LegacyTextField
  43. name="name"
  44. label="Team Name"
  45. placeholder="e.g. Operations, Web, Desktop"
  46. required
  47. />
  48. <LegacyTextField name="slug" label="Short name" placeholder="e.g. api-team" />
  49. <UndoButton />
  50. </LegacyForm>
  51. );
  52. SaveOnBlurAndUndo.storyName = 'save on blur and undo';
  53. SaveOnBlurAndUndo.parameters = {
  54. docs: {
  55. description: {
  56. story: 'Saves on blur and has undo',
  57. },
  58. },
  59. };