Greeter.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { NotificationService } from '@vendure/admin-ui/core';
  2. import { useInjector, usePageMetadata } from '@vendure/admin-ui/react';
  3. import React, { useState, useEffect } from 'react';
  4. export function Greeter(props: { name: string }) {
  5. const notificationService = useInjector(NotificationService);
  6. const { setTitle, setBreadcrumb } = usePageMetadata();
  7. const [titleValue, setTitleValue] = useState('');
  8. const [breadcrumbValue, setBreadcrumbValue] = useState('Greeter');
  9. useEffect(() => {
  10. setTitle('My Page');
  11. setBreadcrumb([
  12. { link: ['./parent'], label: 'Parent Page' },
  13. { link: ['./'], label: 'This Page' },
  14. ]);
  15. }, []);
  16. function handleClick() {
  17. notificationService.success('You clicked me!');
  18. }
  19. return (
  20. <div className="page-block">
  21. <h2>Hello {props.name}</h2>
  22. <button className="button primary" onClick={handleClick}>
  23. Click me
  24. </button>
  25. <div className="card">
  26. <input value={titleValue} onInput={e => setTitleValue((e.target as any).value)} />
  27. <button className="button secondary" onClick={() => setTitle(titleValue)}>
  28. Set title
  29. </button>
  30. </div>
  31. <div className="card">
  32. <input value={breadcrumbValue} onInput={e => setBreadcrumbValue((e.target as any).value)} />
  33. <button className="button secondary" onClick={() => setBreadcrumb(breadcrumbValue)}>
  34. Set breadcrumb
  35. </button>
  36. </div>
  37. </div>
  38. );
  39. }