@hashicorp/react-components 0.0.0-nightly.ad81ac2 → 0.0.0-nightly.b154bf4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.eslintrc.js +1 -2
  2. package/.stylelintrc.js +1 -1
  3. package/README.md +1 -1
  4. package/package.json +3 -8
  5. package/postcss.config.js +1 -1
  6. package/src/components/nav-panel/components/flight-icon/index.tsx +51 -0
  7. package/src/components/nav-panel/components/flight-icon/style.module.css +3 -0
  8. package/src/components/nav-panel/components/link/index.tsx +127 -0
  9. package/src/components/nav-panel/components/link/style.module.css +64 -0
  10. package/src/components/nav-panel/components/link-list/index.tsx +13 -65
  11. package/src/components/nav-panel/components/link-list/style.module.css +1 -50
  12. package/src/components/nav-panel/components/panel/column/style.module.css +2 -2
  13. package/src/components/nav-panel/components/panel/root/style.module.css +5 -5
  14. package/src/components/nav-panel/components/promo/index.tsx +31 -11
  15. package/src/components/nav-panel/components/promo/style.module.css +26 -12
  16. package/src/components/nav-panel/components/text/index.tsx +34 -0
  17. package/src/components/nav-panel/product-panel/index.tsx +54 -17
  18. package/src/components/nav-panel/product-panel/style.module.css +116 -36
  19. package/src/components/nav-panel/standard-panel/index.tsx +3 -0
  20. package/src/components/nav-panel/standard-panel/style.module.css +2 -2
  21. package/src/lib/get-localized-link-props/index.test.ts +30 -0
  22. package/src/lib/get-localized-link-props/index.ts +45 -0
  23. package/src/lib/parse-url/index.ts +0 -2
  24. package/src/lib/send-posthog-event/index.ts +22 -0
  25. package/src/lib/supported-locales/index.ts +10 -0
  26. package/src/lib/track-nav-click-event/index.ts +4 -4
  27. package/src/components/actions/index.tsx +0 -107
  28. package/src/components/actions/style.module.css +0 -28
  29. package/src/components/actions/types.ts +0 -73
  30. package/src/components/call-to-action/index.tsx +0 -205
  31. package/src/components/call-to-action/styles/variant-centered.module.css +0 -93
  32. package/src/components/call-to-action/styles/variant-compact-grid.module.css +0 -88
  33. package/src/components/call-to-action/styles/variant-compact.module.css +0 -91
  34. package/src/components/call-to-action/styles/variant-links.module.css +0 -85
  35. package/src/components/card/README.md +0 -11
  36. package/src/components/card/card.tsx +0 -45
  37. package/src/components/card/index.test.tsx +0 -69
  38. package/src/components/card/index.tsx +0 -14
  39. package/src/components/card/newsroom-card/index.test.tsx +0 -39
  40. package/src/components/card/newsroom-card/index.tsx +0 -37
  41. package/src/components/card/newsroom-card/style.module.css +0 -12
  42. package/src/components/card/partner-card/index.test.tsx +0 -57
  43. package/src/components/card/partner-card/index.tsx +0 -69
  44. package/src/components/card/partner-card/style.module.css +0 -24
  45. package/src/components/card/person-card/index.test.tsx +0 -71
  46. package/src/components/card/person-card/index.tsx +0 -93
  47. package/src/components/card/person-card/style.module.css +0 -33
  48. package/src/components/card/primitives.tsx +0 -177
  49. package/src/components/card/promo-card/index.tsx +0 -51
  50. package/src/components/card/resource-card/index.test.tsx +0 -48
  51. package/src/components/card/resource-card/index.tsx +0 -40
  52. package/src/components/card/style.module.css +0 -145
  53. package/src/components/card/types.ts +0 -66
  54. package/src/components/card/unified-card/index.spec.tsx +0 -40
  55. package/src/components/card/unified-card/index.tsx +0 -58
  56. package/src/components/intro/index.tsx +0 -82
  57. package/src/components/intro/style.module.css +0 -67
  58. package/src/components/intro/types.ts +0 -44
  59. package/src/components/marketo-form/CHANGELOG.md +0 -122
  60. package/src/components/marketo-form/README.md +0 -1
  61. package/src/components/marketo-form/contexts/FormMetadata.ts +0 -13
  62. package/src/components/marketo-form/docs.mdx +0 -197
  63. package/src/components/marketo-form/fixtures/index.ts +0 -185
  64. package/src/components/marketo-form/form/index.tsx +0 -371
  65. package/src/components/marketo-form/index.test.tsx +0 -320
  66. package/src/components/marketo-form/index.ts +0 -11
  67. package/src/components/marketo-form/package.original.json +0 -30
  68. package/src/components/marketo-form/partials/error-message/index.tsx +0 -12
  69. package/src/components/marketo-form/partials/error-message/style.module.css +0 -13
  70. package/src/components/marketo-form/partials/field/index.tsx +0 -90
  71. package/src/components/marketo-form/partials/field-wrapper/index.tsx +0 -26
  72. package/src/components/marketo-form/partials/fields/checkbox-field/index.tsx +0 -32
  73. package/src/components/marketo-form/partials/fields/email-field/index.tsx +0 -35
  74. package/src/components/marketo-form/partials/fields/form-page-url-field/index.tsx +0 -23
  75. package/src/components/marketo-form/partials/fields/hidden-field/index.tsx +0 -38
  76. package/src/components/marketo-form/partials/fields/htmltext-field/index.tsx +0 -21
  77. package/src/components/marketo-form/partials/fields/htmltext-field/style.module.css +0 -18
  78. package/src/components/marketo-form/partials/fields/name-field/index.tsx +0 -19
  79. package/src/components/marketo-form/partials/fields/name-field/style.module.css +0 -13
  80. package/src/components/marketo-form/partials/fields/radio-buttons-field/index.tsx +0 -48
  81. package/src/components/marketo-form/partials/fields/select-field/index.tsx +0 -39
  82. package/src/components/marketo-form/partials/fields/select-field/style.module.css +0 -5
  83. package/src/components/marketo-form/partials/fields/telephone-field/index.tsx +0 -30
  84. package/src/components/marketo-form/partials/fields/text-field/index.tsx +0 -30
  85. package/src/components/marketo-form/partials/fields/textarea-field/index.tsx +0 -29
  86. package/src/components/marketo-form/partials/label/index.tsx +0 -24
  87. package/src/components/marketo-form/partials/label/style.module.css +0 -12
  88. package/src/components/marketo-form/partials/visibility-rule/index.tsx +0 -84
  89. package/src/components/marketo-form/props.js +0 -66
  90. package/src/components/marketo-form/server/api-routes.ts +0 -109
  91. package/src/components/marketo-form/server/client.ts +0 -98
  92. package/src/components/marketo-form/server/index.ts +0 -8
  93. package/src/components/marketo-form/types.ts +0 -267
  94. package/src/components/marketo-form/utils.test.tsx +0 -103
  95. package/src/components/marketo-form/utils.ts +0 -449
  96. package/src/components/next-steps/index.tsx +0 -138
  97. package/src/components/next-steps/style.module.css +0 -270
  98. package/src/components/next-steps/types.ts +0 -63
  99. package/src/components/product-badge/index.test.tsx +0 -11
  100. package/src/components/product-badge/index.tsx +0 -42
  101. package/src/components/product-badge/style.module.css +0 -76
  102. package/src/components/products-used/index.tsx +0 -84
  103. package/src/components/products-used/style.module.css +0 -87
  104. package/src/components/products-used/types.ts +0 -31
  105. package/src/components/related-content/index.test.tsx +0 -74
  106. package/src/components/related-content/index.tsx +0 -56
  107. package/src/components/related-content/style.module.css +0 -89
  108. package/src/components/related-content/types.ts +0 -21
  109. package/src/components/subnav/helpers/areBasePathsMatching.ts +0 -13
  110. package/src/components/subnav/helpers/traverse/index.ts +0 -42
  111. package/src/components/subnav/helpers/useHeightRef.ts +0 -42
  112. package/src/components/subnav/helpers/useNavRef.ts +0 -30
  113. package/src/components/subnav/helpers/useOverflowRef.ts +0 -85
  114. package/src/components/subnav/helpers/useStuckRef.ts +0 -51
  115. package/src/components/subnav/index.tsx +0 -204
  116. package/src/components/subnav/partials/CtaLinks/github-stars-link/formatStarCount/index.test.ts +0 -26
  117. package/src/components/subnav/partials/CtaLinks/github-stars-link/formatStarCount/index.ts +0 -22
  118. package/src/components/subnav/partials/CtaLinks/github-stars-link/index.tsx +0 -87
  119. package/src/components/subnav/partials/CtaLinks/github-stars-link/parseGithubUrl/index.test.ts +0 -29
  120. package/src/components/subnav/partials/CtaLinks/github-stars-link/parseGithubUrl/index.ts +0 -32
  121. package/src/components/subnav/partials/CtaLinks/github-stars-link/style.module.css +0 -81
  122. package/src/components/subnav/partials/CtaLinks/icons/github-logo.js +0 -20
  123. package/src/components/subnav/partials/CtaLinks/icons/github.svg.js +0 -7
  124. package/src/components/subnav/partials/CtaLinks/icons/star.js +0 -20
  125. package/src/components/subnav/partials/CtaLinks/index.tsx +0 -131
  126. package/src/components/subnav/partials/CtaLinks/style.module.css +0 -45
  127. package/src/components/subnav/partials/DropdownTrigger/index.tsx +0 -35
  128. package/src/components/subnav/partials/DropdownTrigger/style.module.css +0 -39
  129. package/src/components/subnav/partials/MenuItemsDefault/index.tsx +0 -158
  130. package/src/components/subnav/partials/MenuItemsDefault/style.module.css +0 -104
  131. package/src/components/subnav/partials/MenuItemsOverflow/index.tsx +0 -143
  132. package/src/components/subnav/partials/MenuItemsOverflow/style.module.css +0 -88
  133. package/src/components/subnav/partials/TitleLink/index.tsx +0 -113
  134. package/src/components/subnav/partials/TitleLink/mktg-logos/all-community-product-logos_on-dark.ts +0 -10
  135. package/src/components/subnav/partials/TitleLink/mktg-logos/all-community-product-logos_on-light.ts +0 -10
  136. package/src/components/subnav/partials/TitleLink/mktg-logos/all-primary-logos_on-dark.ts +0 -23
  137. package/src/components/subnav/partials/TitleLink/mktg-logos/all-primary-logos_on-light.ts +0 -23
  138. package/src/components/subnav/partials/TitleLink/style.module.css +0 -43
  139. package/src/components/subnav/partials/nav-item-text/index.tsx +0 -37
  140. package/src/components/subnav/partials/nav-item-text/style.module.css +0 -13
  141. package/src/components/subnav/style.module.css +0 -66
  142. package/src/components/subnav/subnav-consts.ts +0 -1
@@ -1,84 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { useMemo } from 'react'
7
- import { useFormContext } from 'react-hook-form'
8
- import Field from '../field'
9
- import type {
10
- MarketoFormField,
11
- MarketoFormComponents,
12
- VisibilityRule as VisibilityRuleType,
13
- } from '../../types'
14
-
15
- function ruleApplies(rule: VisibilityRuleType, value: any): boolean {
16
- switch (rule.operator) {
17
- case 'is':
18
- return (
19
- rule.values.includes(value) ||
20
- (value === false && rule.values.includes('no')) ||
21
- (value === true && rule.values.includes('yes'))
22
- )
23
- case 'isNot':
24
- return !rule.values.includes(value)
25
- case 'isEmpty':
26
- return value === null || typeof value === 'undefined' || value === ''
27
- default:
28
- return false
29
- }
30
- }
31
-
32
- const FieldWithVisibilityRule = ({
33
- field,
34
- components,
35
- }: {
36
- field: MarketoFormField
37
- components?: MarketoFormComponents
38
- }) => {
39
- const { watch } = useFormContext()
40
-
41
- // Currently we only support the first defined rule.
42
- const value = watch(field.visibilityRules!.rules![0].subjectField)
43
-
44
- const hasMatchingRule = useMemo(() => {
45
- return field.visibilityRules!.rules!.some((rule) =>
46
- ruleApplies(rule, value)
47
- )
48
- }, [field, value])
49
-
50
- if (
51
- hasMatchingRule &&
52
- (field.visibilityRules!.ruleType === 'show' ||
53
- field.visibilityRules!.ruleType === 'hide')
54
- ) {
55
- return field.visibilityRules!.ruleType === 'show' ? (
56
- <Field field={field} components={components} />
57
- ) : null
58
- }
59
-
60
- // If the ruleType is show, that means the field is hidden by default.
61
- return field.visibilityRules!.ruleType === 'show' ? null : (
62
- <Field field={field} components={components} />
63
- )
64
- }
65
-
66
- const VisibilityRule = ({
67
- field,
68
- components,
69
- }: {
70
- field: MarketoFormField
71
- components?: MarketoFormComponents
72
- }) => {
73
- if (
74
- field.visibilityRules &&
75
- (field.visibilityRules.ruleType === 'show' ||
76
- field.visibilityRules.ruleType === 'hide')
77
- ) {
78
- return <FieldWithVisibilityRule field={field} components={components} />
79
- }
80
-
81
- return <Field field={field} components={components} />
82
- }
83
-
84
- export default VisibilityRule
@@ -1,66 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- module.exports = {
7
- formId: {
8
- type: 'number',
9
- required: true,
10
- description:
11
- 'The numeric ID of the Marketo form that this component is rendering.',
12
- },
13
- marketoForm: {
14
- type: 'object',
15
- required: true,
16
- description:
17
- 'The API response containing the fields of the form this component should render.',
18
- },
19
- groups: {
20
- type: 'object',
21
- description:
22
- 'Mapping of fields that should be rendered with a single component.',
23
- },
24
- components: {
25
- type: 'object',
26
- description: 'Custom components to use instead of the built-in components',
27
- properties: {
28
- text: {
29
- type: 'React.ComponentType',
30
- description: 'Component to use for text fields',
31
- },
32
- email: {
33
- type: 'React.ComponentType',
34
- description: 'Component to use for email fields',
35
- },
36
- select: {
37
- type: 'React.ComponentType',
38
- description: 'Component to use for select fields',
39
- },
40
- checkbox: {
41
- type: 'React.ComponentType',
42
- description: 'Component to use for checkbox fields',
43
- },
44
- hidden: {
45
- type: 'React.ComponentType',
46
- description: 'Component to use for hidden fields',
47
- },
48
- },
49
- },
50
- submitTitle: {
51
- type: 'string',
52
- description: 'Title to use for the submit button',
53
- },
54
- className: {
55
- type: 'string',
56
- description: 'Additional classNames passed to the form element.',
57
- },
58
- onSubmitSuccess: {
59
- type: 'function',
60
- description: 'Callback function invoked on submission success',
61
- },
62
- onSubmitFailure: {
63
- type: 'function',
64
- description: 'Callback function invoked on submission failure',
65
- },
66
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import * as client from './client'
7
- import { includesSkippedRecords } from '../utils'
8
- import type { SubmissionFilter, MarketoSubmissionResponse } from '../types'
9
- import type { NextApiRequest, NextApiResponse } from 'next'
10
-
11
- async function notifyError(body: unknown, err: unknown) {
12
- if (process.env.MARKETO_ERROR_ZAPIER_WEBHOOK) {
13
- try {
14
- await fetch(process.env.MARKETO_ERROR_ZAPIER_WEBHOOK, {
15
- method: 'POST',
16
- headers: {
17
- 'Content-Type': 'application/json',
18
- },
19
- body: JSON.stringify({ body, err }, null, 2),
20
- })
21
- } catch (err) {
22
- console.error({ body, err })
23
- }
24
- }
25
-
26
- return Promise.resolve()
27
- }
28
-
29
- function isE2ETest(req: NextApiRequest): boolean {
30
- // running e2e tests locally
31
- if (process.env.E2E_TESTS === 'true') {
32
- return true
33
- }
34
-
35
- // running e2e tests against a Vercel preview
36
- if (
37
- 'input' in req.body &&
38
- req.body.input.length > 0 &&
39
- req.body.input[0].leadFormFields.email === 'daniela.rod@example.com'
40
- ) {
41
- return true
42
- }
43
-
44
- return false
45
- }
46
-
47
- async function submitForm(
48
- req: NextApiRequest,
49
- res: NextApiResponse,
50
- {
51
- submissionFilter,
52
- }: {
53
- submissionFilter?: SubmissionFilter
54
- }
55
- ) {
56
- // Don't submit forms to the Marketo API when using E2E tests.
57
- if (isE2ETest(req)) {
58
- res.status(200).json({
59
- requestId: '7d85#181a7ae5e56',
60
- result: [
61
- {
62
- id: 25325329,
63
- status: 'updated',
64
- },
65
- ],
66
- success: true,
67
- })
68
- return
69
- }
70
-
71
- try {
72
- const passesSubmissionFilter = submissionFilter
73
- ? await submissionFilter(req)
74
- : true
75
- if (!passesSubmissionFilter) {
76
- // trick spammers into thinking their form submitted successfully
77
- res.status(200).json({ success: true })
78
- return
79
- }
80
- const marketoRes = await client.submitForm(req.body)
81
- const form = (await marketoRes.json()) as MarketoSubmissionResponse
82
- if (!form.success || includesSkippedRecords(form)) {
83
- await notifyError(req.body, form)
84
- }
85
- res.status(marketoRes.status).json(form)
86
- } catch (err) {
87
- await notifyError(req.body, err)
88
- res.status(500).json({ error: 'internal server error' })
89
- throw err
90
- }
91
- }
92
-
93
- export function buildApiRoutes({
94
- submissionFilter,
95
- }: {
96
- submissionFilter?: SubmissionFilter
97
- } = {}) {
98
- return async function apiRoutes(req: NextApiRequest, res: NextApiResponse) {
99
- const route = Array.isArray(req.query.marketo)
100
- ? req.query.marketo[0]
101
- : req.query.marketo
102
- switch (route) {
103
- case 'submit':
104
- return submitForm(req, res, { submissionFilter })
105
- default:
106
- return res.status(404).json({ error: 'not found' })
107
- }
108
- }
109
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import moize from 'moize'
7
- import type {
8
- MarketoFormFieldsResponse,
9
- MarketoFormMetadataResponse,
10
- MarketoFormAPIResponse,
11
- } from '../types'
12
-
13
- interface MarketoTokenResponse {
14
- access_token: string
15
- }
16
-
17
- export async function getToken(): Promise<MarketoTokenResponse> {
18
- const url = new URL(`${process.env.MARKETO_IDENTITY}/oauth/token`)
19
- url.searchParams.append('grant_type', 'client_credentials')
20
- url.searchParams.append('client_id', process.env.MARKETO_CLIENT_ID!)
21
- url.searchParams.append('client_secret', process.env.MARKETO_CLIENT_SECRET!)
22
- const res = await fetch(url.toString())
23
- return await res.json()
24
- }
25
-
26
- export async function getForm(formId: number) {
27
- return await fetch(`https://content.hashicorp.com/api/marketo?id=${formId}`)
28
- }
29
-
30
- export async function getDraftFormProps(formId: number) {
31
- const { access_token } = await getToken()
32
-
33
- const fieldsResponse = await fetch(
34
- `${process.env.MARKETO_ENDPOINT}/asset/v1/form/${formId}/fields.json?status=draft`,
35
- {
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- Authorization: `Bearer ${access_token}`,
39
- },
40
- }
41
- )
42
-
43
- const metadataResponse = await fetch(
44
- `${process.env.MARKETO_ENDPOINT}/asset/v1/form/${formId}.json?status=draft`,
45
- {
46
- headers: {
47
- 'Content-Type': 'application/json',
48
- Authorization: `Bearer ${access_token}`,
49
- },
50
- }
51
- )
52
-
53
- const [fields, metadata] = await Promise.all([
54
- fieldsResponse.json(),
55
- metadataResponse.json(),
56
- ])
57
-
58
- return { fields, metadata }
59
- }
60
-
61
- export async function getFormProps(
62
- id: number
63
- ): Promise<MarketoFormAPIResponse> {
64
- const res = await getForm(id)
65
- if (res.status !== 200) {
66
- throw new Error(
67
- `[marketo-form] non-200 status code when requesting form ${id}: ${res.status}`
68
- )
69
- }
70
-
71
- const form = (await res.json()) as {
72
- result: {
73
- fields: MarketoFormFieldsResponse
74
- metadata: MarketoFormMetadataResponse
75
- }
76
- }
77
-
78
- return form.result
79
- }
80
- export const memoizedGetFormProps = moize(getFormProps, {
81
- isPromise: true,
82
- maxAge: 60 * 1000, // 60 seconds
83
- })
84
-
85
- export async function submitForm(body: unknown) {
86
- const { access_token } = await getToken()
87
- return await fetch(
88
- `${process.env.MARKETO_ENDPOINT}/v1/leads/submitForm.json`,
89
- {
90
- method: 'POST',
91
- headers: {
92
- 'Content-Type': 'application/json',
93
- Authorization: `Bearer ${access_token}`,
94
- },
95
- body: JSON.stringify(body),
96
- }
97
- )
98
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { buildApiRoutes } from './api-routes'
7
-
8
- export { buildApiRoutes }
@@ -1,267 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import type { NextApiRequest } from 'next'
7
-
8
- export type MarketoFormDatatype =
9
- | 'text'
10
- | 'email'
11
- | 'telephone'
12
- | 'textArea'
13
- | 'select'
14
- | 'checkbox'
15
- | 'hidden'
16
- | 'htmltext'
17
- | 'radioButtons'
18
- | 'fieldset'
19
-
20
- export interface Autofill {
21
- value: string
22
- valueFrom: string
23
- parameterName: string
24
- }
25
-
26
- export interface VisibilityRule {
27
- subjectField: string
28
- operator: 'is' | 'isNot' | 'isEmpty'
29
- values: string[]
30
- altLabel: string
31
- }
32
-
33
- export interface VisibilityRules {
34
- rules?: VisibilityRule[]
35
- ruleType: 'alwaysShow' | 'show' | 'hide'
36
- }
37
-
38
- export interface MarketoBaseFormField {
39
- id: string
40
- dataType: MarketoFormDatatype
41
- rowNumber: number
42
- columnNumber: number
43
- defaultValue?: string
44
- label?: string
45
- required?: boolean
46
- validationMessage?: string
47
- autoFill?: Autofill
48
- visibilityRules?: VisibilityRules
49
- /**
50
- * Properties that are not part of the Marketo API response but are
51
- * attached to the field at runtime for additional functionality
52
- */
53
- runtimeAttributes?: Record<string, unknown>
54
- }
55
-
56
- export interface MarketoFormTextField extends MarketoBaseFormField {
57
- dataType: 'text'
58
- hintText?: string
59
- maxLength?: number
60
- formPrefill?: boolean
61
- }
62
-
63
- export interface MarketoFormEmailField extends MarketoBaseFormField {
64
- dataType: 'email'
65
- hintText?: string
66
- formPrefill: boolean
67
- }
68
-
69
- export interface MarketoFormTelephoneField extends MarketoBaseFormField {
70
- dataType: 'telephone'
71
- hintText?: string
72
- formPrefill: boolean
73
- }
74
-
75
- export interface MarketoFormTextAreaField extends MarketoBaseFormField {
76
- dataType: 'textArea'
77
- hintText?: string
78
- formPrefill: boolean
79
- }
80
-
81
- export interface SelectValue {
82
- label: string
83
- value: string
84
- selected?: boolean
85
- isDefault?: boolean
86
- }
87
-
88
- export interface SelectFieldMetaData {
89
- values?: SelectValue[]
90
- visibleLines?: number
91
- multiSelect?: boolean
92
- }
93
-
94
- export interface MarketoFormSelectField extends MarketoBaseFormField {
95
- dataType: 'select'
96
- fieldMetaData: SelectFieldMetaData
97
- formPrefill: boolean
98
- labelWidth?: number
99
- }
100
-
101
- export interface CheckboxFieldMetaData {
102
- initiallyChecked: boolean
103
- }
104
-
105
- export interface MarketoFormCheckboxField extends MarketoBaseFormField {
106
- dataType: 'checkbox'
107
- fieldMetaData: CheckboxFieldMetaData
108
- formPrefill: boolean
109
- }
110
-
111
- export interface MarketoFormHiddenField extends MarketoBaseFormField {
112
- dataType: 'hidden'
113
- }
114
-
115
- export interface MarketoFormHtmltextField extends MarketoBaseFormField {
116
- dataType: 'htmltext'
117
- labelWidth: number
118
- visibilityRules?: VisibilityRules
119
- text: string
120
- }
121
-
122
- export interface MarketoFormRadioButtonsField extends MarketoBaseFormField {
123
- dataType: 'radioButtons'
124
- fieldWidth?: number
125
- formPrefill?: boolean
126
- fieldMetaData: {
127
- values: Array<{ label: string; value: string }>
128
- }
129
- }
130
-
131
- export interface MarketoFormFieldset extends MarketoBaseFormField {
132
- dataType: 'fieldset'
133
- visibilityRules?: VisibilityRules
134
- fields: Array<string>
135
- }
136
-
137
- export type MarketoFormField =
138
- | MarketoFormTextField
139
- | MarketoFormEmailField
140
- | MarketoFormTelephoneField
141
- | MarketoFormTextAreaField
142
- | MarketoFormSelectField
143
- | MarketoFormCheckboxField
144
- | MarketoFormHiddenField
145
- | MarketoFormHtmltextField
146
- | MarketoFormRadioButtonsField
147
- | MarketoFormFieldset
148
-
149
- export interface MarketoFormMetadata {
150
- id: number
151
- name: string
152
- description: string
153
- createdAt: string
154
- updatedAt: string
155
- url: string
156
- status: string
157
- theme: string
158
- language: string
159
- locale: string
160
- progressiveProfiling: boolean
161
- labelPosition: string
162
- fontFamily: string
163
- fontSize: string
164
- folder?: {
165
- type: string
166
- value: number
167
- folderName: string
168
- }
169
- knownVisitor?: {
170
- type: string
171
- template: unknown
172
- }
173
- thankYouList?: {
174
- followupType: string
175
- followupValue: string | null
176
- default: boolean
177
- }[]
178
- buttonLocation: number
179
- buttonLabel: string
180
- waitingLabel: string
181
- workSpaceId: number
182
- }
183
-
184
- /**
185
- * The Marketo API response containing form fields.
186
- */
187
- export interface MarketoFormResponse<T> {
188
- success: boolean
189
- errors: { code: string; message: string }[]
190
- warnings?: string[]
191
- requestId?: string
192
- result: T[]
193
- }
194
-
195
- export type MarketoFormFieldsResponse = MarketoFormResponse<MarketoFormField>
196
- export type MarketoFormMetadataResponse =
197
- MarketoFormResponse<MarketoFormMetadata>
198
- export interface MarketoFormAPIResponse {
199
- fields: MarketoFormFieldsResponse
200
- metadata: MarketoFormMetadataResponse
201
- }
202
-
203
- /**
204
- * Custom components to be used in lieu of the default built-in components.
205
- */
206
- export interface MarketoFormComponents {
207
- text?: (props: { field: MarketoFormTextField }) => JSX.Element
208
- email?: (props: { field: MarketoFormEmailField }) => JSX.Element
209
- telephone?: (props: { field: MarketoFormTelephoneField }) => JSX.Element
210
- textArea?: (props: { field: MarketoFormTextAreaField }) => JSX.Element
211
- select?: (props: { field: MarketoFormSelectField }) => JSX.Element
212
- checkbox?: (props: { field: MarketoFormCheckboxField }) => JSX.Element
213
- hidden?: (props: { field: MarketoFormHiddenField }) => JSX.Element
214
- htmltext?: (props: { field: MarketoFormHtmltextField }) => JSX.Element
215
- radioButtons?: (props: { field: MarketoFormRadioButtonsField }) => JSX.Element
216
- }
217
-
218
- /**
219
- * Configuration on which fields to render with a single component. Can be used
220
- * to render multiple default components on one row (such as First Name and
221
- * Last Name) or to render a particular set of fields with a single component.
222
- */
223
- export type MarketoFormGroups = Record<
224
- string,
225
- {
226
- fields: string[]
227
- component: (props: { fields: MarketoFormField[] }) => JSX.Element
228
- }
229
- >
230
-
231
- export type SubmissionFilter = (req: NextApiRequest) => Promise<boolean>
232
-
233
- export interface MarketoSubmissionResponse {
234
- success: boolean
235
- result: { status: 'created' | 'updated' | 'skipped' }[]
236
- }
237
-
238
- export type OnSubmitData = Record<string, unknown>
239
-
240
- export interface OnSubmitProps {
241
- /**
242
- * Whether to reset the form after a successful submission.
243
- * Default: false
244
- */
245
- resetOnSubmission?: boolean
246
-
247
- /**
248
- * Callback called when form has started submission process.
249
- * Form will submit with the transformed data returned.
250
- */
251
- transformData?: (data: OnSubmitData) => OnSubmitData
252
-
253
- /**
254
- * Callback called when form has started submission process.
255
- */
256
- onSubmitStart?: () => void
257
-
258
- /**
259
- * Callback called when form has been successfully submitted.
260
- */
261
- onSubmitSuccess?: (data?: OnSubmitData) => void
262
-
263
- /**
264
- * Callback called when form submission results in an error.
265
- */
266
- onSubmitError?: () => void
267
- }