Backpack UI
Components
Subscription

Subscription

The SubscriptionField component is a convenient wrapper for email subscription forms. It includes a FormInput component for email input and a SubscriptionButton component for submitting the form.


Importing


_10
import {
_10
SubscriptionButton,
_10
SubscriptionField,
_10
} from '@ef-global/backpack/Subscription';
_10
import { FormInput } from '@ef-global/backpack/FormInput';

Props

NameTypeDefaultDescription
submittedboolean-Determines if the form is submitted or not
inversebooleanfalseIf set to true, uses inverse styles for the SubscriptionField
classNamestring-Optional custom CSS class to be applied to the SubscriptionField component
childrenArray of FormInput, SubscriptionButton, GradientEllipse-Array of the required child components for the SubscriptionField

Usage

The SubscriptionField component should be used with the FormInput, SubscriptionButton, and optionally, GradientEllipse components as children.

FormInput

For the email input, use the FormInput component. A single FormInput component, or any custom field component that has a data-slot prop set to "FormInput". This component represents the input field within the subscription form. When using a custom field, ensure it has the necessary properties and behavior to function correctly within the subscription form.

SubscriptionButton

For the submit button, use the SubscriptionButton component.

GradientEllipse (optional)

GradientEllipse is an optional circular element with a gradient background that appears and scales up when the form is submitted. In order to see the transition, you need to wrap the SubscriptionField component inside a SubscriptionContainer component.

Examples

Default



_30
const [submitted, setSubmitted] = useState(false);
_30
_30
<div>
_30
<SubscriptionField submitted={submitted} inverse={false}>
_30
<FormInput
_30
type='email'
_30
placeholder='Email'
_30
data-slot='FormInput'
_30
/>
_30
<SubscriptionButton
_30
label='Submit'
_30
data-slot='SubscriptionButton'
_30
onClick={() => setSubmitted(true)}
_30
/>
_30
</SubscriptionField>
_30
_30
{submitted ? (
_30
<Link
_30
variant='standalone'
_30
inverse={false}
_30
asChild={true}
_30
>
_30
<button type='button' onClick={() => setSubmitted(false)}>
_30
<LinkText>Add another email</LinkText>
_30
</button>
_30
</Link>
_30
) : (
_30
''
_30
)}
_30
</div>

Inverse



_30
const [submitted, setSubmitted] = useState(false);
_30
_30
<div>
_30
<SubscriptionField submitted={submitted} inverse={true}>
_30
<FormInput
_30
type='email'
_30
placeholder='Email'
_30
data-slot='FormInput'
_30
/>
_30
<SubscriptionButton
_30
label='Submit'
_30
data-slot='SubscriptionButton'
_30
onClick={() => setSubmitted(true)}
_30
/>
_30
</SubscriptionField>
_30
_30
{submitted ? (
_30
<Link
_30
variant='standalone'
_30
inverse={true}
_30
asChild={true}
_30
>
_30
<button type='button' onClick={() => setSubmitted(false)}>
_30
<LinkText>Add another email</LinkText>
_30
</button>
_30
</Link>
_30
) : (
_30
''
_30
)}
_30
</div>

SubscriptionContainer

The SubscriptionContainer component is a wrapper component for managing the subscription form and its content. It accepts four children components: SubscriptionHeading, SubscriptionResultHeading, SubscriptionDescription, and Form. The Form child should include a SubscriptionField component which contains the form input and button.

The GradientEllipse component is not a direct child of the SubscriptionContainer. Instead, it is a child of the SubscriptionField component. The GradientEllipse is a circle that appears with a scaling transition when the form is submitted. To see the transition, insert the SubscriptionField component inside a SubscriptionContainer component, and include the GradientEllipse component as a child of SubscriptionField.

Here is an overview of the SubscriptionContainer component:

Importing


_12
import {
_12
SubscriptionButton,
_12
SubscriptionField,
_12
GradientEllipse,
_12
} from '@ef-global/backpack/Subscription';
_12
import {
_12
SubscriptionContainer,
_12
SubscriptionDescription,
_12
SubscriptionHeading,
_12
SubscriptionResultHeading,
_12
} from '@ef-global/backpack/SubscriptionContainer';
_12
import { FormInput } from '@ef-global/backpack/FormInput';

Props

NameTypeDefaultDescription
submittedbooleanfalseDetermines if the form is submitted or not
childrenArray of SubscriptionHeading, SubscriptionResultHeading, SubscriptionDescription, Form-Array of the required child components for the SubscriptionContainer

Slots

SubscriptionContainer requires the following slot components:

  • SubscriptionHeading: The main heading for the subscription component.
  • SubscriptionResultHeading: The heading that appears after the form has been submitted.
  • SubscriptionDescription: (Optional) A brief description for the subscription component.
  • Form: The SubscriptionField component wrapped inside an HTML form element.

Usage

To use the SubscriptionContainer, wrap the SubscriptionField component along with other required components inside the SubscriptionContainer component.

Example


Subscribe to our newsletter

Thank you, we'll be in touch!

Ullamcorper sit et est sed suscipit pharetra senectus fermentum parturient blandit fringilla blandit aenean vel sodales in mi sapien a a.


_20
const [submitted, setSubmitted] = useState(false);
_20
_20
return (
_20
<SubscriptionContainer submitted={submitted}>
_20
<Text data-slot="SubscriptionHeading">Subscribe to our newsletter</Text>
_20
<Text data-slot="SubscriptionResultHeading">Thank you for subscribing!</Text>
_20
<Text data-slot="SubscriptionDescription">Stay up to date with our latest news and offers.</Text>
_20
<form
_20
data-slot="Form"
_20
onSubmit={(e) => {
_20
e.preventDefault();
_20
setSubmitted(true);
_20
}}
_20
>
_20
<SubscriptionField submitted={submitted}>
_20
{/* Insert required child components of SubscriptionField here */}
_20
</SubscriptionField>
_20
</form>
_20
</SubscriptionContainer>
_20
);