PlaygroundOverview.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. /* eslint-disable zammad/zammad-detect-translatable-string */
  4. import { computed, reactive, ref } from 'vue'
  5. import { EnumSecurityStateType } from '#shared/components/Form/fields/FieldSecurity/types.ts'
  6. import Form from '#shared/components/Form/Form.vue'
  7. import { defineFormSchema } from '#shared/form/defineFormSchema.ts'
  8. import CommonButton from '#mobile/components/CommonButton/CommonButton.vue'
  9. import CommonButtonGroup from '#mobile/components/CommonButtonGroup/CommonButtonGroup.vue'
  10. import CommonStepper from '#mobile/components/CommonStepper/CommonStepper.vue'
  11. import LayoutHeader from '#mobile/components/layout/LayoutHeader.vue'
  12. import { useDialog } from '#mobile/composables/useDialog.ts'
  13. import { useUserCreate } from '#mobile/entities/user/composables/useUserCreate.ts'
  14. const linkSchemaRaw = [
  15. {
  16. type: 'externalDataSource',
  17. name: 'external_data_source',
  18. label: 'External Data Source',
  19. object: 'Ticket',
  20. required: true,
  21. },
  22. {
  23. type: 'security',
  24. name: 'security',
  25. label:
  26. 'Security Long Name Very long Not Truncated Oh no Please Its Too Long',
  27. required: true,
  28. props: {
  29. securityAllowed: {
  30. [EnumSecurityStateType.Smime]: ['sign', 'encryption'],
  31. [EnumSecurityStateType.Pgp]: ['encryption'],
  32. },
  33. },
  34. },
  35. {
  36. type: 'editor',
  37. name: 'editor',
  38. label: 'Editor',
  39. required: true,
  40. // props: editorProps,
  41. },
  42. {
  43. type: 'textarea',
  44. name: 'textarea',
  45. id: 'textarea',
  46. label: 'Textarea',
  47. },
  48. {
  49. type: 'toggle',
  50. name: 'toggle',
  51. label: 'Toggle',
  52. required: true,
  53. // disabled: true,
  54. props: {
  55. value: false,
  56. variants: {
  57. true: 'Yes',
  58. false: 'No',
  59. },
  60. },
  61. },
  62. {
  63. type: 'text',
  64. name: 'some_input',
  65. label: 'Input',
  66. disabled: true,
  67. required: true,
  68. },
  69. {
  70. type: 'textarea',
  71. name: 'select',
  72. label: 'Textarea',
  73. required: true,
  74. },
  75. {
  76. type: 'text',
  77. name: 'some_input_link',
  78. label: 'Linked',
  79. props: {
  80. link: '/',
  81. },
  82. },
  83. {
  84. type: 'datetime',
  85. name: 'some_input_date',
  86. label: 'Date',
  87. props: {
  88. link: '/',
  89. clearable: true,
  90. },
  91. required: true,
  92. },
  93. {
  94. type: 'tags',
  95. name: 'tags',
  96. label: 'Tags',
  97. props: {
  98. link: '/',
  99. options: [
  100. { label: 'test', value: 'test' },
  101. { label: 'support', value: 'support' },
  102. { label: 'paid', value: 'paid' },
  103. { label: 'paid2', value: 'paid2' },
  104. { label: 'paid3', value: 'paid3' },
  105. { label: 'paid4', value: 'paid4' },
  106. { label: 'paid5', value: 'paid5' },
  107. { label: 'paid6', value: 'paid6' },
  108. { label: 'paid7', value: 'paid7' },
  109. { label: 'paid8', value: 'paid8' },
  110. { label: 'paid9', value: 'paid9' },
  111. { label: 'paid10', value: 'paid10' },
  112. { label: 'paid11', value: 'paid11' },
  113. ],
  114. canCreate: true,
  115. },
  116. },
  117. {
  118. type: 'treeselect',
  119. name: 'treeselect',
  120. label: 'TreeSelect',
  121. value: [0, 3, 5, 6, 1, 2, 8, 7],
  122. props: {
  123. clearable: true,
  124. multiple: true,
  125. options: [
  126. {
  127. value: 0,
  128. label: 'Item A',
  129. children: [
  130. {
  131. value: 1,
  132. label: 'Item 1',
  133. children: [
  134. {
  135. value: 2,
  136. label: 'Item I',
  137. },
  138. {
  139. value: 3,
  140. label: 'Item II',
  141. },
  142. {
  143. value: 4,
  144. label: 'Item III',
  145. },
  146. ],
  147. },
  148. {
  149. value: 5,
  150. label: 'Item 2',
  151. children: [
  152. {
  153. value: 6,
  154. label: 'Item IV',
  155. },
  156. ],
  157. },
  158. {
  159. value: 7,
  160. label: 'Item 3',
  161. },
  162. ],
  163. },
  164. {
  165. value: 8,
  166. label: 'Item B',
  167. },
  168. {
  169. value: 9,
  170. label: 'Ítem C',
  171. },
  172. ],
  173. link: '/tickets',
  174. },
  175. },
  176. {
  177. type: 'treeselect',
  178. name: 'treeselect_2',
  179. label: 'TreeSelect 2',
  180. props: {
  181. link: '/',
  182. options: [
  183. {
  184. value: 0,
  185. label: 'Item A',
  186. },
  187. ],
  188. },
  189. },
  190. {
  191. type: 'select',
  192. name: 'select_1',
  193. label: 'Select 1',
  194. disabled: true,
  195. props: {
  196. link: '/',
  197. options: [
  198. {
  199. value: 0,
  200. label: 'Item A',
  201. },
  202. ],
  203. },
  204. },
  205. {
  206. type: 'select',
  207. name: 'select_2',
  208. label: 'Select 2',
  209. props: {
  210. link: '/',
  211. multiple: true,
  212. options: [
  213. {
  214. value: 0,
  215. label: 'Item A',
  216. },
  217. {
  218. value: 1,
  219. label: 'Item B',
  220. },
  221. {
  222. value: 2,
  223. label: 'Item C',
  224. },
  225. ],
  226. },
  227. },
  228. {
  229. type: 'autocomplete',
  230. name: 'autocomplete',
  231. label: 'AutoComplete',
  232. props: {
  233. sorting: 'label',
  234. link: '/tickets',
  235. action: '/tickets',
  236. actionIcon: 'new-customer',
  237. gqlQuery: `
  238. query autocompleteSearchUser($input: AutocompleteSearchInput!) {
  239. autocompleteSearchUser(input: $input) {
  240. value
  241. label
  242. labelPlaceholder
  243. heading
  244. headingPlaceholder
  245. disabled
  246. icon
  247. }
  248. }
  249. `,
  250. },
  251. },
  252. {
  253. type: 'recipient',
  254. name: 'recipient_email',
  255. label: 'Recipient Email',
  256. },
  257. {
  258. type: 'recipient',
  259. name: 'recipient_phone',
  260. label: 'Recipient Phone',
  261. props: {
  262. contact: 'phone',
  263. },
  264. },
  265. {
  266. type: 'organization',
  267. name: 'organization',
  268. label: 'Organization',
  269. props: {
  270. gqlQuery: `
  271. query autocompleteSearchUser($input: AutocompleteSearchInput!) {
  272. autocompleteSearchUser(input: $input) {
  273. value
  274. label
  275. labelPlaceholder
  276. heading
  277. headingPlaceholder
  278. disabled
  279. icon
  280. }
  281. }
  282. `,
  283. },
  284. },
  285. {
  286. type: 'customer',
  287. name: 'customer',
  288. label: 'Customer',
  289. props: {
  290. gqlQuery: `
  291. query autocompleteSearchUser($input: AutocompleteSearchInput!) {
  292. autocompleteSearchUser(input: $input) {
  293. value
  294. label
  295. labelPlaceholder
  296. heading
  297. headingPlaceholder
  298. disabled
  299. icon
  300. }
  301. }
  302. `,
  303. },
  304. },
  305. ]
  306. const linkSchemas = defineFormSchema(linkSchemaRaw, { showDirtyMark: true })
  307. const schema = defineFormSchema([
  308. {
  309. isLayout: true,
  310. component: 'FormGroup',
  311. children: [
  312. {
  313. type: 'file',
  314. name: 'file',
  315. // label: 'File',
  316. props: {
  317. multiple: true,
  318. },
  319. },
  320. ],
  321. },
  322. ])
  323. const dialog = useDialog({
  324. name: 'dialog',
  325. component: () => import('#mobile/components/CommonDialog/CommonDialog.vue'),
  326. })
  327. const { openCreateUserDialog } = useUserCreate()
  328. const currentStep = ref('step2')
  329. const steps = {
  330. step1: {
  331. label: '1',
  332. order: 1,
  333. errorCount: 0,
  334. valid: true,
  335. disabled: false,
  336. completed: true,
  337. },
  338. step2: {
  339. label: '2',
  340. order: 2,
  341. errorCount: 0,
  342. valid: true,
  343. disabled: true,
  344. completed: false,
  345. },
  346. step3: {
  347. label: '3',
  348. order: 3,
  349. errorCount: 0,
  350. valid: true,
  351. completed: true,
  352. disabled: true,
  353. },
  354. step4: {
  355. label: '4',
  356. order: 4,
  357. errorCount: 3,
  358. valid: false,
  359. completed: false,
  360. disabled: true,
  361. },
  362. }
  363. const editorProps = reactive({
  364. contentType: 'text/plain',
  365. meta: {
  366. footer: {
  367. text: '/AB',
  368. maxlength: 276,
  369. warningLength: 30,
  370. },
  371. },
  372. })
  373. const updateEditorProps = () => {
  374. editorProps.contentType =
  375. editorProps.contentType === 'text/plain' ? 'text/html' : 'text/plain'
  376. }
  377. const editorSchema = defineFormSchema([
  378. {
  379. type: 'editor',
  380. name: 'editor',
  381. label: 'Editor',
  382. required: true,
  383. props: Object.keys(editorProps).reduce(
  384. (acc, key) => {
  385. acc[key] = computed(() => editorProps[key as keyof typeof editorProps])
  386. return acc
  387. },
  388. {} as Record<string, unknown>,
  389. ),
  390. },
  391. ])
  392. const logSubmit = console.log
  393. </script>
  394. <template>
  395. <div class="p-4">
  396. <LayoutHeader title="Playground">
  397. <template #before>1 / 3</template>
  398. <template #after>
  399. <CommonButton class="flex-1 px-4 py-2" variant="secondary"
  400. >Click
  401. </CommonButton>
  402. </template>
  403. </LayoutHeader>
  404. <h2 class="text-xl font-bold">Buttons</h2>
  405. <div class="mt-2 flex gap-3">
  406. <CommonButton class="flex-1 py-2" variant="primary" />
  407. <CommonButton class="flex-1 py-2" variant="secondary" />
  408. </div>
  409. <div class="my-4 flex gap-3">
  410. <CommonButton class="flex-1 py-2" variant="submit" />
  411. <CommonButton class="flex-1 py-2" variant="danger" />
  412. </div>
  413. <h3 class="text-gray mb-2 mt-2 text-lg font-semibold">
  414. With transparent background
  415. </h3>
  416. <div class="flex gap-3">
  417. <CommonButton
  418. class="flex-1 py-2"
  419. variant="primary"
  420. transparent-background
  421. />
  422. <CommonButton
  423. class="flex-1 py-2"
  424. variant="secondary"
  425. transparent-background
  426. />
  427. </div>
  428. <div class="my-4 flex gap-3">
  429. <CommonButton
  430. class="flex-1 py-2"
  431. variant="submit"
  432. transparent-background
  433. />
  434. <CommonButton
  435. class="flex-1 py-2"
  436. variant="danger"
  437. transparent-background
  438. />
  439. </div>
  440. <button @click="dialog.toggle({ name: 'dialog', label: 'Hello World' })">
  441. Dialog
  442. </button>
  443. <button type="button" @click="updateEditorProps">
  444. CHANGE EDITOR PROPS
  445. </button>
  446. <button form="form">Submit</button>
  447. <CommonStepper v-model="currentStep" class="mx-20" :steps="steps" />
  448. <button @click="openCreateUserDialog()">Create user</button>
  449. <Form :schema="editorSchema" @submit="logSubmit" />
  450. <CommonButtonGroup
  451. class="py-4"
  452. mode="full"
  453. model-value="subscribe"
  454. :options="[
  455. { label: 'Merge tickets', icon: 'home' },
  456. { label: 'Subscribe', icon: 'home', value: 'subscribe' },
  457. { label: 'Ticket info', icon: 'home' },
  458. ]"
  459. />
  460. <Form id="form" :schema="linkSchemas" />
  461. <Form :schema="schema" />
  462. <FormKit
  463. type="radio"
  464. :buttons="true"
  465. :options="[
  466. { label: 'Incoming Phone', value: 1, icon: 'phone-in' },
  467. { label: 'Outgoing Phone', value: 2, icon: 'phone-out' },
  468. { label: 'Send Email', value: 3, icon: 'mail-out' },
  469. ]"
  470. />
  471. <FormKit
  472. wrapper-class="mt-6 flex grow justify-center items-center"
  473. input-class="py-2 px-4 w-full h-14 text-xl rounded-xl select-none"
  474. variant="submit"
  475. type="submit"
  476. prefix-icon="arrow-right"
  477. suffix-icon="arrow-left"
  478. >
  479. {{ $t('Sign in') }}
  480. </FormKit>
  481. </div>
  482. </template>