npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@diplodoc/tabs-extension

v3.5.1

Published

Tabs plugin for Diplodoc transformer and builder

Downloads

10,915

Readme

Diplodoc tabs extension

NPM version

This is an extension of the Diplodoc platform, which allows adding switchable tabs in the documentation.

The extension contains some parts:

Quickstart

Attach the plugin to the transformer:

import tabsExtension from '@diplodoc/tabs-extension';
import transform from '@diplodoc/transform';

const {result} = await transform(`
{% list tabs %}

- Tab 1
- Tab 2
- Tab 3

{% endlist %}
`, {
    plugins: [
        tabsExtension.transform({ bundle: false })
    ]
});

Prepared runtime

It is necessary to add runtime scripts to make tabs interactive on your page. You can add assets files which were generated by the MarkdownIt transform plugin.

<html>
    <head>
        <!-- Read more about '_assets/tabs-extension.js' and '_assets/tabs-extension.css' in 'Transform plugin' section -->
        <script src='_assets/tabs-extension.js' async></script>
        <link rel='stylesheet' href='_assets/tabs-extension.css' />
    </head>
    <body>
        ${result.html}
    </body>
</html>

Or you can just include runtime's source code in your bundle.

import '@diplodoc/tabs-extension/runtime'
import '@diplodoc/tabs-extension/runtime/styles.css'

MarkdownIt transform plugin

Plugin for @diplodoc/transform package.

Options:

  • runtimeJsPath - name on runtime script which will be exposed in results script section. Default: _assets/tabs-extension.js

  • runtimeCssPath - name on runtime css file which will be exposed in results style section. (Default: _assets/tabs-extension.css)

  • bundle - boolean flag to enable/disable copying of bundled runtime to target directory. Where target directore is <transformer output option>/<plugin runtime option> Default: true

  • containerClasses - additional classes which will be added to tab's container node. It allows to customize the tabs view. Example: my-own-class and-other-class Default: undefined

API

Syntax

You can synchronize the opening of tabs between different tabs groups on the page. To do this, you just need to add optional property group=<group_key> in list tab command. The active tabs with the same keys in one tabs group will be synchronized.

Example:

{% list tabs group=group_1 %}

- Tab 1
- Tab 2
- Tab 3

{% endlist %}

{% list tabs group=group_1 %}

- Tab 1
- Tab 2
- Tab 3

{% endlist %}

Additionally, you can use radiobatons using a contruction

{% list tabs radio %}

  - Tab 1

    Text 1.

    * You can use list
    * And **other** features.

  - Tab 2

    Text 2.

{% endlist %}

The keys for the tabs are generated automatically. They are based on the tab's names using the github anchors style.

You can set your own keys for tabs with this statement:

{% list tabs group=group_1 %}

- Tab 1 {#my-tab-1}
- Tab 2 {#my-tab-2}

{% endlist %}

React hook for smart control

You can use the React hook to handle active tab changing or to select opened tab programmatically.

import React, { useEffect } from 'react'
import {UseDiplodocTabsCallback, useDiplodocTabs, Tab} from '@diplodoc/tabs-extension/react';

export const App: React.FC = () => {
    const selectTabHandler = useCallback<UseDiplodocTabsCallback>(
        (tab: Tab, currentTabId?: string) => {
            const {group, key} = tab;
            // Group could be empty
            if (group) {
                // ...
            }
        },
        [],
    );

    const {selectTab, selectTabById} = useDiplodocTabs(selectTabHandler);

    useEffect(() => {
        selectTab({ group: 'group_1', key: 'my-key' });
        // selectTabById('my-key-2');
    }, [selectTab, selectTabById]);

}