Skip to content

Commit

Permalink
feat: add support for htmltext
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley committed Apr 10, 2023
1 parent fc77a08 commit 4ca7cb8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-meals-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-marketo-form': minor
---

Add support for htmltext fields
11 changes: 11 additions & 0 deletions packages/marketo-form/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ Renders a form from Marketo.
ruleType: "alwaysShow",
},
},
{
id: "SHRtbFRleHRfMjAyMy0wNC0wNVQyMjo0NDo0Ny45OTZa",
labelWidth: 260,
dataType: "htmltext",
rowNumber: 9,
columnNumber: 0,
visibilityRules: {
ruleType: "alwaysShow"
},
text: "By submitting this form, you acknowledge and agree that HashiCorp will process your personal information in accordance with the <a href=\\"https://hashicorp.com/privacy\\" target=\\"_blank\\" id=\\"\\">Privacy Policy</a>."
}
],
}}
submitTitle="Download Now"
Expand Down
7 changes: 7 additions & 0 deletions packages/marketo-form/partials/field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SelectField from '../fields/select-field'
import CheckboxField from '../fields/checkbox-field'
import PrivacyPolicyField from '../fields/privacy-policy-field'
import HiddenField from '../fields/hidden-field'
import HtmltextField from '../fields/htmltext-field'
import FormPageUrlField from '../fields/form-page-url-field'
import type { MarketoFormField, MarketoFormComponents } from '../../types'

Expand Down Expand Up @@ -70,6 +71,12 @@ const Field = ({
return <FormPageUrlField field={field} />
}
return <HiddenField field={field} />
case 'htmltext':
if (components && 'htmltext' in components) {
const Component = components.htmltext!
return <Component field={field} />
}
return <HtmltextField field={field} />
default:
console.error(`Unknown form field type: ${(field as any).Datatype}`)
}
Expand Down
21 changes: 21 additions & 0 deletions packages/marketo-form/partials/fields/htmltext-field/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

import FieldWrapper from '../../field-wrapper'
import type { MarketoFormHtmltextField } from '../../../types'
import styles from './style.module.css'

const Index = ({ field }: { field: MarketoFormHtmltextField }) => {
return (
<FieldWrapper fieldId={field.id}>
<span
className={styles.htmltext}
dangerouslySetInnerHTML={{ __html: field.text }}
/>
</FieldWrapper>
)
}

export default Index
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.htmltext {
composes: g-type-body-small from global;
color: var(--wpl-neutral-500);
margin-top: var(--wpl-spacing-02);
margin-bottom: var(--wpl-spacing-05);
}
8 changes: 8 additions & 0 deletions packages/marketo-form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type MarketoFormDatatype =
| 'select'
| 'checkbox'
| 'hidden'
| 'htmltext'

export interface Autofill {
value: string
Expand Down Expand Up @@ -92,6 +93,11 @@ export interface MarketoFormHiddenField extends MarketoBaseFormField {
dataType: 'hidden'
}

export interface MarketoFormHtmltextField extends MarketoBaseFormField {
dataType: 'htmltext'
text: string
}

export type MarketoFormField =
| MarketoFormTextField
| MarketoFormEmailField
Expand All @@ -100,6 +106,7 @@ export type MarketoFormField =
| MarketoFormSelectField
| MarketoFormCheckboxField
| MarketoFormHiddenField
| MarketoFormHtmltextField

export interface MarketoFormMetadata {
id: number
Expand Down Expand Up @@ -150,6 +157,7 @@ export interface MarketoFormComponents {
select?: (props: { field: MarketoFormSelectField }) => JSX.Element
checkbox?: (props: { field: MarketoFormCheckboxField }) => JSX.Element
hidden?: (props: { field: MarketoFormHiddenField }) => JSX.Element
htmltext?: (props: { field: MarketoFormHtmltextField }) => JSX.Element
}

/**
Expand Down

0 comments on commit 4ca7cb8

Please sign in to comment.