Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

155 regels
4.8 KiB

  1. import * as React from 'react';
  2. import { NextPage } from 'next';
  3. import { getFormValues } from '@theoryofnekomata/formxtra';
  4. import * as Freeform from '@tesseract-design/web-freeform-react';
  5. import * as Formatted from '@tesseract-design/web-formatted-react';
  6. import * as Action from '@tesseract-design/web-action-react';
  7. import {Refractor} from '@modal-sh/react-refractor';
  8. const RegistrationFormPage: NextPage = () => {
  9. const [values, setValues] = React.useState({} as Record<string, unknown>);
  10. const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
  11. e.preventDefault();
  12. const newValues = getFormValues(e.currentTarget);
  13. setValues(newValues);
  14. };
  15. const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
  16. e.preventDefault();
  17. const form = e.currentTarget.form;
  18. if (!form) {
  19. return;
  20. }
  21. const newValues = getFormValues(form);
  22. setValues(newValues);
  23. };
  24. return (
  25. <main className="my-16 md:my-32">
  26. <div className="container mx-auto px-4">
  27. <h1>
  28. Registration Form
  29. </h1>
  30. <p>
  31. Input your data in order to gain access to the functions of this service.
  32. </p>
  33. <form onSubmit={handleSubmit}>
  34. <fieldset className="contents">
  35. <legend className="sr-only">
  36. Register
  37. </legend>
  38. <div className="grid sm:grid-cols-6 gap-4">
  39. <div className="sm:col-span-2">
  40. <Freeform.TextInput
  41. block
  42. border
  43. label="First Name"
  44. name="firstName"
  45. onChange={handleChange}
  46. />
  47. </div>
  48. <div className="sm:col-span-2">
  49. <Freeform.TextInput
  50. block
  51. border
  52. label="Middle Name"
  53. name="middleName"
  54. onChange={handleChange}
  55. />
  56. </div>
  57. <div className="sm:col-span-2">
  58. <Freeform.TextInput
  59. block
  60. border
  61. label="Last Name"
  62. name="lastName"
  63. onChange={handleChange}
  64. />
  65. </div>
  66. <div className="sm:col-span-3">
  67. <Formatted.EmailInput
  68. block
  69. border
  70. label="Email"
  71. name="email"
  72. onChange={handleChange}
  73. />
  74. </div>
  75. <div className="sm:col-span-3">
  76. <Formatted.UrlInput
  77. block
  78. border
  79. label="Website"
  80. name="website"
  81. onChange={handleChange}
  82. />
  83. </div>
  84. <div className="sm:col-span-2">
  85. <Formatted.PhoneNumberInput
  86. country="PH"
  87. block
  88. border
  89. label="Phone"
  90. name="phone"
  91. onChange={handleChange}
  92. enhanced
  93. />
  94. </div>
  95. <div className="sm:col-span-2">
  96. <Freeform.MaskedTextInput
  97. block
  98. border
  99. label="Password"
  100. name="password"
  101. onChange={handleChange}
  102. enhanced
  103. />
  104. </div>
  105. <div className="sm:col-span-2">
  106. <Freeform.MaskedTextInput
  107. block
  108. border
  109. label="Confirm Password"
  110. name="confirmPassword"
  111. onChange={handleChange}
  112. enhanced
  113. />
  114. </div>
  115. <div className="sm:col-span-6 text-center">
  116. <div
  117. className="sm:flex items-center justify-end space-y-4 sm:space-y-0 sm:space-x-4"
  118. >
  119. <small>
  120. By registering, you agree to the <a href="#">Terms</a> of this service.
  121. </small>
  122. {' '}
  123. <div>
  124. <Action.ActionButton
  125. variant="filled"
  126. block
  127. type="submit"
  128. menuItem
  129. subtext="Registration requires activation"
  130. >
  131. Submit
  132. </Action.ActionButton>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </fieldset>
  138. </form>
  139. <div className="mt-4">
  140. <Refractor
  141. language="json"
  142. code={JSON.stringify(values, null, 2)}
  143. />
  144. </div>
  145. </div>
  146. </main>
  147. )
  148. }
  149. export default RegistrationFormPage;