@@ -5,6 +5,7 @@ import './BlnFormular';
55import './BlnInput' ;
66import './BlnButton' ;
77import './BlnCheckBox' ;
8+ import { FormBuilder } from './FormBuilder' ;
89
910interface BlnFormularProps {
1011 ariaLabel : string ;
@@ -432,3 +433,100 @@ export const RetroDesign: Story = {
432433 } ,
433434 } ,
434435} ;
436+
437+ export const WithFormBuilder : Story = {
438+ render : ( args ) => {
439+ const formularId = `formular-fb-${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` ;
440+
441+ // Use setTimeout to ensure the DOM is ready before manipulating it
442+ setTimeout ( ( ) => {
443+ const formular = document . getElementById ( formularId ) as any ;
444+ if ( ! formular ) return ;
445+
446+ // Create FormBuilder instance with fields
447+ const fb = new FormBuilder ( )
448+ . addBlnInput ( {
449+ label : 'Vorname' ,
450+ name : 'firstname' ,
451+ placeholder : 'Ihr Vorname' ,
452+ required : true
453+ } )
454+ . addBlnInput ( {
455+ label : 'E-Mail' ,
456+ name : 'email' ,
457+ type : 'email' ,
458+ placeholder : 'name@example.com' ,
459+ required : true
460+ } )
461+ . addBlnInput ( {
462+ label : 'Alter' ,
463+ name : 'age' ,
464+ type : 'number' ,
465+ value : '25'
466+ } )
467+ . addBlnCheckbox ( {
468+ name : 'newsletter' ,
469+ label : 'Newsletter' ,
470+ checked : true
471+ } ) ;
472+
473+ // Pass FormBuilder fields to BlnFormular
474+ formular . templateResult = fb . getFields ( ) ;
475+ } , 100 ) ;
476+
477+ return html `
478+ < bln-formular
479+ id =${ formularId }
480+ legend ="FormBuilder Integration"
481+ @bln-submit=${ ( e : any ) => console . log ( '📋 FormBuilder Submit:' , e . detail . data ) }
482+ @bln-clear=${ ( ) => console . log ( '🧹 FormBuilder Clear' ) }
483+ @bln-delete=${ ( ) => console . log ( '🗑️ FormBuilder Delete' ) } >
484+
485+ < div slot ="actions " class ="flex gap-2 ">
486+ < bln-button @click =${ ( e : Event ) => ( e . currentTarget as HTMLElement ) . closest ( 'bln-formular' ) ?. submit ?.( ) } > Speichern</ bln-button >
487+ < bln-button variant ="outline " @click =${ ( e : any ) => ( e . currentTarget as any ) . closest ( 'bln-formular' ) ?. delete ?.( ) } > Löschen</ bln-button >
488+ < bln-button variant ="ghost " @click =${ ( e : any ) => ( e . currentTarget as any ) . closest ( 'bln-formular' ) ?. clear ?.( ) } > Leeren</ bln-button >
489+ </ div >
490+ </ bln-formular >
491+ < div class ="mt-4 p-4 bg-gray-50 rounded ">
492+ < h4 class ="font-semibold mb-2 "> FormBuilder Integration Code:</ h4 >
493+ < pre class ="text-sm bg-gray-800 text-green-400 p-3 rounded overflow-x-auto "> < code > import { FormBuilder } from './FormBuilder';
494+
495+ // Create FormBuilder with fields
496+ const fb = new FormBuilder()
497+ .addBlnInput({ label: 'Name', name: 'name', required: true })
498+ .addBlnCheckbox({ name: 'newsletter', checked: true })
499+ .addBlnSelect({ name: 'city', options: [...] });
500+
501+ // Get formular element
502+ const formular = document.getElementById('myForm');
503+
504+ // Pass FormBuilder fields to BlnFormular
505+ formular.templateResult = fb.getFields();</ code > </ pre >
506+ </ div >
507+ ` ;
508+ } ,
509+ parameters : {
510+ docs : {
511+ description : {
512+ story : `
513+ **FormBuilder Integration mit BlnFormular**
514+
515+ Dieses Beispiel zeigt, wie Sie FormBuilder-Felder direkt an ein BlnFormular übergeben können:
516+
517+ **Integration:**
518+ 1. **FormBuilder erstellen:** \`new FormBuilder()\` mit gewünschten Feldern
519+ 2. **Felder übergeben:** \`formular.templateResult = fb.getFields()\`
520+ 3. **Automatische Sammlung:** BlnFormular sammelt alle Daten beim Submit
521+
522+ **Unterstützte FormBuilder-Methoden:**
523+ - \`addBlnInput()\` - Text, Email, Password, Number inputs
524+ - \`addBlnCheckbox()\` - Checkboxen mit boolean values
525+ - \`addBlnSelect()\` - Dropdown-Auswahlen
526+
527+ Die FormBuilder-Felder werden automatisch im BlnFormular gerendert und bei submit() in den Event-Daten erfasst. Öffnen Sie die Browser-Konsole, um die Daten zu sehen.
528+ ` . trim ( ) ,
529+ } ,
530+ } ,
531+ } ,
532+ } ;
0 commit comments