Links

Components

This guide will help developers understand what is a component and how to use them.
<?php
STM_LMS_Templates::show_lms_template(
'components/tabs',
    array(
    'items' => array(
        array(
            'id'    => 'lesson',
                'title' => __( 'Lesson', 'masterstudy-lms-learning-management-system' ),
            ),
            array(
                'id'    => 'materials',
                'title' => __( 'Materials', 'masterstudy-lms-learning-management-system' ),
            ),
        ),
        'style'            => 'nav-sm',
        'active_tab_index' => 0,
        'dark_mode'        => false,
    )
);
?>
<?php
/**
 * @var array $items
 * @var string $style
 * @var int $active_tab_index
 * @var boolean $dark_mode
 *
 * masterstudy-tabs_dark-mode - for dark mode
 * masterstudy-tabs__item_active - for item active state
 * masterstudy-tabs_style-default|nav-sm|nav-md - for tabs style change
 */
wp_enqueue_style( 'masterstudy-tabs', STM_LMS_URL . '/assets/css/components/tabs.css', null, MS_LMS_VERSION );
?>
<ul class="masterstudy-tabs <?php echo esc_attr( $dark_mode ? 'masterstudy-tabs_dark-mode' : '' ); ?> <?php echo esc_attr( 'masterstudy-tabs_style-' . $style ); ?>">
    <?php foreach ( $items as $index => $item ) { ?>
        <li class="masterstudy-tabs__item <?php echo $active_tab_index === $index ? 'masterstudy-tabs__item_active' : ''; ?>" data-id="<?php echo esc_attr( $item['id'] ); ?>">
            <?php echo esc_html( $item['title'] ); ?>
        </li>
    <?php } ?>
</ul>
But sometimes there are cases when you need to modify a component via javascript, like changing the style, or color theme of the component or highlighting the active tab when you click on it. For such cases, all the names of modifier classes are contained in the comments at the top of the component template. You can assign them via custom JavaScript code on the page.
Example:
// tabs toggler depending on the visibility in the window
$('.masterstudy-course-player-content__wrapper').on('scroll', function() {
let materialsTab = $('.masterstudy-course-player-header .masterstudy-tabs__item[data-id="materials"]'),
    lessonTab = $('.masterstudy-course-player-header .masterstudy-tabs__item[data-id="lesson"]'),
    materialsInView = isElementInView('.masterstudy-course-player-lesson-materials');
           
    if (materialsInView) {
    materialsTab.addClass('masterstudy-tabs__item_active');
    lessonTab.removeClass('masterstudy-tabs__item_active');
    } else {
    materialsTab.removeClass('masterstudy-tabs__item_active');
    lessonTab.addClass('masterstudy-tabs__item_active');
    }
});
function isElementInView(selector) {
let element = document.querySelector(selector),
        rect = element.getBoundingClientRect();
    return (
    rect.top >= 0 &&
        rect.left >= 0 &&
    rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
}