MOLECULAR COMPONENTS

Paragraph Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Paragraph class:

    
        class Paragraph {
            
            constructor (opts = false) { ... }

            get_class_defaults () { ... }

            get_generate_options (options) { ... }

            generate (options = false) { ... }

        }
    

Default Settings

The following object properties and values are all of the defaults for this class:

                                
                                    {
                                        attributes: {},
                                        text: ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut condimentum vitae risus vitae semper. Donec consectetur felis et mollis tristique. Nunc consequat lacus in urna congue, eu lacinia est placerat.']
                                    }
                                
                            

Methods

The following class methods allow you to interact with the Paragraph class object.

constructor(opts)

Class constructor with an optional argument expecting an object with class-specific properties/values. Any matching properties passed will override the default values. The constructor function exposes a .defaults object containing various default settings for the component.

                                
                                    <script type="module">
                                    
                                        // import module
                                        import { Paragraph } from './js/modules/html_elements.js';

                                        // create an object with your overrides specified
                                        let paragraph_default_settings = {
                                            text: ['This is my new paragraph text. It is dynamically generated by the OBE:WDS Molecular Components functionality.']
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let paragraphs = new Paragraph(paragraph_default_settings);

                                        // confirm your changes
                                        console.log( paragraphs.defaults.text );

                                    </script>
                                
                            

get_class_defaults()

Returns an object with all of the default properties of the Paragraph class.

    
        <script type="module">
        
            // import module
            import { Paragraph } from './js/modules/form_components.js';

            // initialize the class and call the method
            console.log( new Paragraph().get_class_defaults() );

        </script>
    

Conversely, you can also access the Class defaults directly after initializing the class, and without the get_class_defaults() method:

    
        <script type="module">
        
            // import module
            import { Paragraph } from './js/modules/form_components.js';

            // initialize the class and call the method
            console.log( new Paragraph().defaults );

        </script>
    

get_generate_options()

Requires an object to be passed as an argument. The argument will override the default settings of the class, but ONLY in the scope of this method. This method is mainly provided for debugging purposes.

                                
                                    <script type="module">
                                    
                                        // import module
                                        import { Paragraph } from './js/modules/html_elements.js';

                                        // initialize the class and pass your settings as an argument
                                        let paragraphs = new Paragraph();

                                        let my_test_settings = {
                                            text: ['This is my new paragraph text. It is dynamically generated by the OBE:WDS Molecular Components functionality.']
                                        };

                                        // initialize the class and call the method
                                        console.log( paragraphs.get_generate_options( my_test_settings ) );

                                    </script>
                                
                            

generate()

Takes an optional argument expecting an object with class-specific properties/values. Any matching properties passed will override the default values. This method returns a node list of DOM element(s), configured according to the class defaults and any overridden settings.

                                
                                    <script type="module">
                                    
                                        // import module
                                        import { Paragraph } from './js/modules/html_elements.js';

                                        // initialize the class and pass your settings as an argument
                                        let paragraphs = new Paragraph();

                                        // set your desired settings for the component elements you're about to generate
                                        let paragraph_settings = {
                                            text: ['This is my new paragraph text. It is dynamically generated by the OBE:WDS Molecular Components functionality.']
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let paragraph = paragraphs.generate( paragraph_settings );

                                    </script>