Skip to main content

Change Email Block

ChangeEmail is a controlled change-email form block built on MUI.

Installationโ€‹

npm install @nodeblocks/frontend-change-email-block

What You Needโ€‹

ItemWhy it matters
dataSingle source of truth for form state (newEmail)
onDataChangeReceives updated state + metadata on field changes
currentEmail (optional)Read-only current address shown above the new-email field
errors (optional)Displays field-level error feedback
Controlled component

ChangeEmail does not own form state. Keep state in your app and pass it through data.

Code Examplesโ€‹

Live Editor
function Example() {
  const defaultData = {newEmail: ''};

  const [data, setData] = React.useState(defaultData);
  const [errors, setErrors] = React.useState({});

  const handleDataChange = (nextData, meta) => {
    const {[meta.name]: _removed, ...restErrors} = errors;
    let nextErrors = restErrors;

    // Validate required fields on blur (same pattern as storybook)
    if (meta.cause === 'blur' && meta.name === 'newEmail') {
      if (!String(nextData.newEmail || '').trim()) {
        nextErrors = {...restErrors, newEmail: 'New email is required.'};
      }
    }

    setErrors(nextErrors);
    setData(nextData);
  };

  return (
    <ChangeEmail
      data={data}
      errors={Object.keys(errors).length ? errors : undefined}
      currentEmail="user@example.com"
      onDataChange={handleDataChange}
      onSubmit={e => {
        e.preventDefault();
        alert(`Submit:\n${JSON.stringify(data, null, 2)}`);
      }}
    />
  );
}
Result
Loading...

Important Propsโ€‹

Core Propsโ€‹

PropTypeRequiredDefaultDescription
dataChangeEmailFormData ({ newEmail? } or extended Record<string, unknown>)Yes-Current form data object
onDataChange(data, meta) => voidYes-Called on updates; meta includes name, value, cause (input, change, blur, clear, reset, programmatic), optional event
errors{ [fieldName: string]: string | string[] }NoundefinedField errors keyed by data field name (e.g. newEmail)

Content Propsโ€‹

PropTypeRequiredDefaultDescription
currentEmailstringNoundefinedRead-only current email address
labels{ currentEmailDisplay?: string }NocurrentEmailDisplay: '็พๅœจใฎใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚น'Label for the current-email display only. Override title, field, and button copy through subcomponent props.

Layout and Composition Propsโ€‹

PropTypeRequiredDefaultDescription
childrenBlocksOverride | ReactNodeNoundefinedOverride default blocks or provide custom JSX children
componentReact.ElementTypeNo'form'Root element type
classNamestringNoundefinedClass name for the root container
sxSxPropsNoundefinedMUI system styles for the root container

ChangeEmail also inherits StackProps<'form'> (except children), so standard form props like onSubmit, id, and noValidate are supported. Default block order without overrides: title, form (defaultBlockOrder).

Default UI Blocksโ€‹

BlockBuilt onNotes
ChangeEmail (root)Stack (component="form")Controlled form container; inner content max width 684px
ChangeEmail.TitleTypographyTitle (variant="h6"); default ใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚นใ‚’ๅค‰ๆ›ด
ChangeEmail.FormStackForm fields container (submit handled by root form)
ChangeEmail.Form.CurrentEmailDisplayTypography + StackRead-only current email; label default ็พๅœจใฎใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚น via labels.currentEmailDisplay and value from root currentEmail
ChangeEmail.Form.NewEmailFieldTextFieldNew email (name="newEmail", type="text", autoComplete="new-email", fullWidth); defaults ๆ–ฐใ—ใ„ใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚น / ๆ–ฐใ—ใ„ใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚นใ‚’ๅ…ฅๅŠ›
ChangeEmail.Form.ChangeEmailButtonButtonSubmit (variant="contained", type="submit"); default ใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚นใ‚’ๅค‰ๆ›ด

TypeScriptโ€‹

import {ChangeEmail, ChangeEmailFormData} from '@nodeblocks/frontend-change-email-block';

type MyChangeEmailData = ChangeEmailFormData & {
confirmToken?: string;
};