ReactUi.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { arrowIcon, layersIcon, starIcon, userIcon } from '@cds/core/icon';
  2. import { NotificationService } from '@vendure/admin-ui/core';
  3. import {
  4. ActionBar,
  5. Card,
  6. CdsIcon,
  7. FormField,
  8. Link,
  9. PageBlock,
  10. PageDetailLayout,
  11. useInjector,
  12. usePageMetadata,
  13. } from '@vendure/admin-ui/react';
  14. import React, { PropsWithChildren, useState } from 'react';
  15. export function ReactUi() {
  16. const notificationService = useInjector(NotificationService);
  17. const { setTitle } = usePageMetadata();
  18. const [titleModified, setTitleModified] = useState(false);
  19. const [titleValue, setTitleValue] = useState('React UI');
  20. function updateTitle() {
  21. setTitle(titleValue);
  22. setTitleModified(false);
  23. notificationService.success(`Updated title to "${titleValue}"`);
  24. }
  25. return (
  26. <>
  27. <PageBlock>
  28. <ActionBar leftContent={<div>Action bar left contents</div>}>
  29. <button className="button primary" onClick={updateTitle} disabled={!titleModified}>
  30. Update page title
  31. </button>
  32. </ActionBar>
  33. </PageBlock>
  34. <PageDetailLayout
  35. sidebar={
  36. <div>
  37. <Card>Sidebar content</Card>
  38. </div>
  39. }
  40. >
  41. <PageBlock>
  42. <Card title="Card">
  43. This is a card. On a detail page, content should usually be placed inside a card.
  44. </Card>
  45. <Card title="Form inputs">
  46. <div className="form-grid">
  47. <FormField label="Page title">
  48. <input
  49. value={titleValue}
  50. onInput={e => {
  51. setTitleValue((e.target as any).value);
  52. setTitleModified(true);
  53. }}
  54. />
  55. </FormField>
  56. <FormField label="Select input">
  57. <select>
  58. <option>Option 1</option>
  59. <option>Option 2</option>
  60. </select>
  61. </FormField>
  62. <FormField label="Checkbox input">
  63. <input type="checkbox" />
  64. </FormField>
  65. <FormField label="Textarea input">
  66. <textarea></textarea>
  67. </FormField>
  68. <FormField label="With tooltip" tooltip="This is a tooltip for the form input">
  69. <input type="text" />
  70. </FormField>
  71. <FormField label="Invalid with error" invalid={true}>
  72. <input type="text" />
  73. </FormField>
  74. </div>
  75. </Card>
  76. <Card title="Icons">
  77. <DemoBlock label="Sizes">
  78. <CdsIcon icon={starIcon} size={'xs'}></CdsIcon>
  79. <CdsIcon icon={starIcon} size={'sm'}></CdsIcon>
  80. <CdsIcon icon={starIcon} size={'md'}></CdsIcon>
  81. <CdsIcon icon={starIcon} size={'lg'}></CdsIcon>
  82. <CdsIcon icon={starIcon} size={'xl'}></CdsIcon>
  83. <CdsIcon icon={starIcon} size={'xxl'}></CdsIcon>
  84. </DemoBlock>
  85. <DemoBlock label="Badges">
  86. <CdsIcon icon={userIcon} badge={'success'}></CdsIcon>
  87. <CdsIcon icon={userIcon} badge={'info'}></CdsIcon>
  88. <CdsIcon icon={userIcon} badge={'warning'}></CdsIcon>
  89. <CdsIcon icon={userIcon} badge={'danger'}></CdsIcon>
  90. </DemoBlock>
  91. <DemoBlock label="Status colors">
  92. <CdsIcon icon={userIcon} status={'success'}></CdsIcon>
  93. <CdsIcon icon={userIcon} status={'info'}></CdsIcon>
  94. <CdsIcon icon={userIcon} status={'warning'}></CdsIcon>
  95. <CdsIcon icon={userIcon} status={'danger'}></CdsIcon>
  96. </DemoBlock>
  97. </Card>
  98. <Card title={'Buttons'}>
  99. <DemoBlock label="Regular">
  100. <button className="button primary">Primary</button>
  101. <button className="button secondary">Secondary</button>
  102. <button className="button success">Success</button>
  103. <button className="button warning">Warning</button>
  104. <button className="button danger">Danger</button>
  105. </DemoBlock>
  106. <DemoBlock label="Ghost">
  107. <button className="button-ghost">Ghost</button>
  108. <Link className="button-ghost" href="/extensions/ui-library/react-ui">
  109. <CdsIcon icon={arrowIcon} direction="right" />
  110. John Smith
  111. </Link>
  112. </DemoBlock>
  113. <DemoBlock label="Small">
  114. <button className="button-small">Small</button>
  115. <button className="button-small">
  116. <CdsIcon icon={layersIcon} />
  117. Assign to channel
  118. </button>
  119. </DemoBlock>
  120. </Card>
  121. </PageBlock>
  122. </PageDetailLayout>
  123. </>
  124. );
  125. }
  126. function DemoBlock(props: PropsWithChildren<{ label: string }>) {
  127. return (
  128. <div className="mb-4">
  129. <label>{props.label}</label>
  130. <div className="mt-1 flex" style={{ gap: '12px' }}>
  131. {props.children}
  132. </div>
  133. </div>
  134. );
  135. }