Basic Information Block
The BasicInformation Component is a fully customizable and accessible form for collecting user's basic information built with React, TypeScript, and MUI. It provides a complete address and contact information interface with modern design patterns, form validation using react-hook-form, and flexible customization options.
๐ Installationโ
npm install @nodeblocks/frontend-basic-information-block@0.2.0
๐ Usageโ
import {BasicInformation} from '@nodeblocks/frontend-basic-information-block';
- Basic Usage
- Advanced Usage
function BasicInformationForm() { return ( <BasicInformation onChange={(setError, getValues) => { console.log('Form values:', getValues()); const values = getValues(); if (!values.NameInput) { setError('NameInput', {message: 'Name is required', type: 'required'}); } }} onSubmit={formData => { console.log('Form submitted:', formData); }} onInvalid={errors => { console.log('Form validation errors:', errors); }}> <BasicInformation.Title>Basic Information</BasicInformation.Title> <BasicInformation.Subtitle>Please fill in your basic information</BasicInformation.Subtitle> <BasicInformation.NameInput /> <BasicInformation.FuriganaInput /> <BasicInformation.PostalCodeInput /> <BasicInformation.PrefectureSelect /> <BasicInformation.CityInput /> <BasicInformation.AddressInput /> <BasicInformation.PhoneInput /> <BasicInformation.SubmitButton>Submit</BasicInformation.SubmitButton> </BasicInformation> ); }
function AdvancedBasicInformationForm() { return ( <BasicInformation sx={{ maxWidth: '800px', margin: '0 auto', background: 'linear-gradient(145deg, #f8fafc 0%, #f1f5f9 100%)', borderRadius: '20px', border: '1px solid #e2e8f0', }} onChange={(setError, getValues) => { const values = getValues(); if (!values.NameInput) { setError('NameInput', {message: 'ๆฐๅใฏๅฟ ้ ้ ็ฎใงใ', type: 'required'}); } if (values.PhoneInput && !/^[\d-+()]*$/.test(values.PhoneInput)) { setError('PhoneInput', {message: 'ๆๅนใช้ป่ฉฑ็ชๅทใๅ ฅๅใใฆใใ ใใ', type: 'pattern'}); } }} onSubmit={formData => { console.log('Form submitted:', formData); }} onInvalid={errors => { console.log('Form validation errors:', errors); }} > {({defaultBlocks, defaultBlockOrder}) => { return { blocks: { ...defaultBlocks, title: { ...defaultBlocks.title, props: { ...defaultBlocks.title.props, sx: { fontSize: '2rem', fontWeight: 'bold', textAlign: 'center', marginBottom: '8px', background: 'linear-gradient(135deg, #0f172a, #1e293b)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', backgroundClip: 'text', }, children: 'ใใญใใฃใผใซไฝๆ', }, }, subtitle: { ...defaultBlocks.subtitle, props: { ...defaultBlocks.subtitle.props, sx: {textAlign: 'center', color: '#64748b', marginBottom: '2rem'}, children: ( <div style={{display: 'flex', flexDirection: 'column', gap: '1rem'}}> <p>ใๅฎขๆงใฎๅบๆฌๆ ๅ ฑใใๅ ฅๅใใ ใใ</p> <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px'}}> <div style={{display: 'flex', alignItems: 'center', gap: '4px'}}> <div style={{ width: '32px', height: '32px', backgroundColor: '#3b82f6', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: '14px', fontWeight: '500', }} > 1 </div> <span style={{fontSize: '14px', fontWeight: '500', color: '#3b82f6'}}>ๅบๆฌๆ ๅ ฑ</span> </div> <div style={{width: '48px', height: '2px', backgroundColor: '#cbd5e1'}}></div> <div style={{display: 'flex', alignItems: 'center', gap: '4px'}}> <div style={{ width: '32px', height: '32px', backgroundColor: '#cbd5e1', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#64748b', fontSize: '14px', fontWeight: '500', }} > 2 </div> <span style={{fontSize: '14px', color: '#64748b'}}>่ฉณ็ดฐ่จญๅฎ</span> </div> </div> </div> ), }, }, nameInput: { ...defaultBlocks.nameInput, props: { ...defaultBlocks.nameInput.props, label: 'ๆฐๅ', placeholder: 'ไพ: ๅฑฑ็ฐ ๅคช้', sx: { '& .MuiOutlinedInput-root': { borderRadius: '10px', background: 'white', }, }, }, }, furiganaInput: { ...defaultBlocks.furiganaInput, props: { ...defaultBlocks.furiganaInput.props, label: 'ใใชใฌใ', placeholder: 'ไพ: ใคใใ ใฟใญใฆ', sx: { '& .MuiOutlinedInput-root': { borderRadius: '10px', background: 'white', }, }, }, }, submitButton: { ...defaultBlocks.submitButton, props: { ...defaultBlocks.submitButton.props, sx: { width: '100%', padding: '14px 32px', background: 'linear-gradient(135deg, #3b82f6, #2563eb)', borderRadius: '10px', fontWeight: 'bold', boxShadow: '0 8px 20px rgba(59, 130, 246, 0.3)', '&:hover': { background: 'linear-gradient(135deg, #2563eb, #1d4ed8)', boxShadow: '0 12px 25px rgba(59, 130, 246, 0.4)', }, }, children: 'ๆฌกใฎในใใใใธ้ฒใ', }, }, }, blockOrder: defaultBlockOrder, }; }} </BasicInformation> ); }
๐ง Props Referenceโ
Main Component Propsโ
| Prop | Type | Default | Description |
|---|---|---|---|
onSubmit | (data: T) => void | Required | Callback function triggered when form is submitted with valid data |
onChange | (setError, getValues) => void | Required | Callback function triggered when form values change. Provides form control functions for validation |
onInvalid | (errors: FieldErrors<T>) => void | Required | Callback function triggered when form submission fails validation |
defaultValues | DefaultValues<T> | undefined | Default form values to populate fields on initial render |
children | BlocksOverride | undefined | Custom block components to override default rendering |
className | string | undefined | Additional CSS class name for styling the form container |
sx | SxProps | undefined | MUI sx prop for custom styling |
spacing | number | 4 | Spacing between child elements |
Note: This component extends MUI StackProps<'form'> with component="form", inheriting all Stack component props.
Sub-Componentsโ
The BasicInformation component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
BasicInformation.Titleโ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | "ๅบๆฌๆ
ๅ ฑ" | Content to display as the title |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps | undefined | MUI sx prop for custom styling |
Note: This component extends MUI TypographyProps with variant="h4" and component="h2".
BasicInformation.Subtitleโ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | "* ใฏๅฟ
้ ไบ้
ใงใ" | Content to display as the subtitle |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TypographyProps with variant="body2".
BasicInformation.NameInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "NameInput" | Field name for form data |
label | string | "ๆฐๅ" | Label of the input field |
placeholder | string | "ๆฐๅใๅ
ฅๅ" | Placeholder text |
required | boolean | true | Whether the field is required |
disabled | boolean | false | Whether the input is disabled |
error | boolean | false | Whether to show error state |
helperText | string | undefined | Helper text displayed below the input |
fullWidth | boolean | true | Whether the input takes full width |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TextFieldProps.
BasicInformation.FuriganaInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "FuriganaInput" | Field name for form data |
label | string | "ใใชใฌใ" | Label of the input field |
placeholder | string | "ใใชใฌใใๅ
ฅๅ" | Placeholder text |
required | boolean | true | Whether the field is required |
Note: This component extends MUI TextFieldProps.
BasicInformation.PostalCodeInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "PostalCodeInput" | Field name for form data |
label | string | "้ตไพฟ็ชๅท" | Label of the input field |
placeholder | string | "้ตไพฟ็ชๅทใๅ
ฅๅ" | Placeholder text |
required | boolean | true | Whether the field is required |
inputMode | string | "numeric" | Input mode for mobile keyboards |
Note: This component extends MUI TextFieldProps.
BasicInformation.PrefectureSelectโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "PrefectureSelect" | Field name for form data |
label | string | "้ฝ้ๅบ็" | Field label |
placeholder | string | "้ฝ้ๅบ็ใ้ธๆ" | Placeholder text |
options | Array<{value: string, label: string}> | PREFECTURES (47 prefectures) | Array of prefecture options |
required | boolean | true | Whether the field is required |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI SelectProps.
BasicInformation.CityInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "CityInput" | Field name for form data |
label | string | "ๅธๅบ็บๆ" | Label of the input field |
placeholder | string | "ๅธๅบ็บๆใๅ
ฅๅ" | Placeholder text |
required | boolean | true | Whether the field is required |
Note: This component extends MUI TextFieldProps.
BasicInformation.AddressInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "AddressInput" | Field name for form data |
label | string | "็บๅใป็ชๅฐใปๅปบ็ฉ" | Label of the input field |
placeholder | string | "็บๅใป็ชๅฐใปๅปบ็ฉใๅ
ฅๅ" | Placeholder text |
required | boolean | true | Whether the field is required |
Note: This component extends MUI TextFieldProps.
BasicInformation.PhoneInputโ
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "PhoneInput" | Field name for form data |
label | string | "้ฃ็ตกๅ
้ป่ฉฑ็ชๅท" | Label of the input field |
placeholder | string | "้ป่ฉฑ็ชๅทใๅ
ฅๅ๏ผใใคใใณใชใใงๅ
ฅๅ๏ผ" | Placeholder text |
required | boolean | true | Whether the field is required |
inputMode | string | "numeric" | Input mode for mobile keyboards |
Note: This component extends MUI TextFieldProps.
BasicInformation.SubmitButtonโ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | "ๆฌกใธ" | Button text content |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps | undefined | MUI sx prop for custom styling |
disabled | boolean | !formState.isValid | Whether the button is disabled |
variant | string | "contained" | MUI Button variant |
size | string | "large" | MUI Button size |
type | string | "submit" | Button type |
Note: This component extends MUI ButtonProps. The button is automatically disabled when form is invalid.
BasicInformation.Inputโ
Generic input component for creating custom fields.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | Required | Field name for form data (required for form binding) |
label | string | undefined | Label of the input field |
placeholder | string | undefined | Placeholder text |
required | boolean | false | Whether the field is required |
disabled | boolean | false | Whether the input is disabled |
error | boolean | false | Whether to show error state |
helperText | string | undefined | Helper text displayed below the input |
fullWidth | boolean | true | Whether the input takes full width |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TextFieldProps.
๐จ Configuration examplesโ
Custom Field Labelsโ
<BasicInformation.NameInput
label="Full Name"
placeholder="Enter your full name"
required={true}
/>
Custom Prefecture Optionsโ
const customPrefectures = [
{value: 'tokyo', label: 'ๆฑไบฌ้ฝ'},
{value: 'osaka', label: 'ๅคง้ชๅบ'},
{value: 'kyoto', label: 'ไบฌ้ฝๅบ'},
];
<BasicInformation
onSubmit={data => console.log(data)}
onChange={() => {}}
onInvalid={errors => console.log(errors)}
>
<BasicInformation.Title>Custom Prefectures</BasicInformation.Title>
<BasicInformation.NameInput label="Full Name" placeholder="Enter your full name" required={true} />
<BasicInformation.PrefectureSelect options={customPrefectures} placeholder="Select your prefecture" />
<BasicInformation.CityInput />
<BasicInformation.AddressInput />
<BasicInformation.SubmitButton
sx={{
background: 'linear-gradient(135deg, #3b82f6, #2563eb)',
borderRadius: '12px',
'&:hover': {
background: 'linear-gradient(135deg, #2563eb, #1d4ed8)',
},
}}
>
้ไฟกใใ
</BasicInformation.SubmitButton>
</BasicInformation>
Styled Submit Buttonโ
<BasicInformation.SubmitButton
sx={{
background: 'linear-gradient(135deg, #3b82f6, #2563eb)',
borderRadius: '12px',
'&:hover': {
background: 'linear-gradient(135deg, #2563eb, #1d4ed8)',
}
}}
>
้ไฟกใใ
</BasicInformation.SubmitButton>
Block Override Patternโ
<BasicInformation
onSubmit={data => console.log(data)}
onChange={() => {}}
onInvalid={errors => console.log(errors)}
>
{({defaultBlocks, defaultBlockOrder}) => ({
blocks: {
...defaultBlocks,
title: {
...defaultBlocks.title,
props: {
...defaultBlocks.title.props,
children: 'Custom Title',
sx: {color: 'primary.main'},
},
},
// Add custom block
customInfo: (
<div
style={{
padding: '12px 16px',
backgroundColor: '#e3f2fd',
borderRadius: '8px',
color: '#1976d2',
}}
>
All fields are required for registration
</div>
),
},
blockOrder: [
'title',
'customInfo',
'subtitle',
...defaultBlockOrder.filter((k) => k !== 'title' && k !== 'subtitle'),
],
})}
</BasicInformation>
Adding a Custom Input Fieldโ
<BasicInformation
onSubmit={data => console.log(data)}
onChange={() => {}}
onInvalid={errors => console.log(errors)}
>
<BasicInformation.Title>Extended Form</BasicInformation.Title>
<BasicInformation.Subtitle />
<BasicInformation.NameInput />
<BasicInformation.Input name="CompanyName" label="ไผ็คพๅ" placeholder="ไผ็คพๅใๅ
ฅๅ" required={false} />
<BasicInformation.PhoneInput />
<BasicInformation.SubmitButton />
</BasicInformation>
๐ง TypeScript Supportโ
Full TypeScript support with comprehensive type definitions:
import {BasicInformation} from '@nodeblocks/frontend-basic-information-block';
import {DefaultValues, FieldErrors, UseFormGetValues, UseFormSetError} from 'react-hook-form';
// Default form data structure
interface DefaultBasicInformationFormData {
NameInput: string;
FuriganaInput: string;
PostalCodeInput: string;
PrefectureSelect: string;
CityInput: string;
AddressInput: string;
PhoneInput: string;
}
// Select option type for custom options
interface SelectOption {
value: string;
label: string;
}
const TypedBasicInformationExample = () => {
const handleSubmit = (formData: DefaultBasicInformationFormData): void => {
console.log('Form submitted:', formData);
};
const handleInvalid = (errors: FieldErrors<DefaultBasicInformationFormData>): void => {
console.log('Validation errors:', errors);
};
const handleChange = (
setError: UseFormSetError<DefaultBasicInformationFormData>,
getValues: UseFormGetValues<DefaultBasicInformationFormData>,
): void => {
const values = getValues();
// Custom validation
if (values.PhoneInput && values.PhoneInput.length < 10) {
setError('PhoneInput', {message: 'Phone number too short'});
}
};
const defaultValues: DefaultValues<DefaultBasicInformationFormData> = {
NameInput: 'John Doe',
PrefectureSelect: 'ๆฑไบฌ้ฝ',
};
return (
<BasicInformation<DefaultBasicInformationFormData>
onSubmit={handleSubmit}
onInvalid={handleInvalid}
onChange={handleChange}
defaultValues={defaultValues}
sx={{maxWidth: 600, mx: 'auto'}}
>
<BasicInformation.Title>Basic Information</BasicInformation.Title>
<BasicInformation.Subtitle>Please provide your details</BasicInformation.Subtitle>
<BasicInformation.NameInput />
<BasicInformation.FuriganaInput />
<BasicInformation.PostalCodeInput />
<BasicInformation.PrefectureSelect />
<BasicInformation.CityInput />
<BasicInformation.AddressInput />
<BasicInformation.PhoneInput />
<BasicInformation.SubmitButton>Submit</BasicInformation.SubmitButton>
</BasicInformation>
);
};
๐ Notesโ
- The component uses MUI's
Stackcomponent withcomponent="form"as its base - Form validation is powered by
react-hook-formwithmode: 'onBlur' - All input fields are automatically connected to the form context via
Controller - The submit button is automatically disabled when
formState.isValidisfalse - Default blocks are:
title,subtitle,nameInput,furiganaInput,postalCodeInput,prefectureSelect,cityInput,addressInput,phoneInput,submitButton,input - The
PrefectureSelectcomponent includes all 47 Japanese prefectures by default - CSS classes follow BEM-style naming:
nbb-basic-information,nbb-basic-information-title, etc. - Input fields use MUI
TextFieldinternally and support all TextField props - The
onChangecallback is triggered on every form value change for real-time validation - Default padding is
p: 5(40px) and spacing between elements is4(32px)
Built with โค๏ธ using React, TypeScript, and MUI.