Giter Site home page Giter Site logo

tabpanelwidget / tabpanelwidget Goto Github PK

View Code? Open in Web Editor NEW
98.0 98.0 4.0 4.42 MB

TabPanelWidget is a Semantic, Accessible, Responsive, and Versatile solution to create Tabpanel and Accordion Widgets for the Web.

Home Page: https://tabpanelwidget.com

License: MIT License

JavaScript 39.75% SCSS 23.96% Pug 2.98% CSS 10.13% Vue 22.88% HTML 0.31%
accordion accordion-widget tab-panel tabpanel widget

tabpanelwidget's Introduction

Tabpanelwidget

This module contains the standalone (vanilla) script, a Vue component, and a React component.

TODO

  • rewrite in typescript?
  • split the stylesheet (to create a base + different "skins")

TOC

Vanilla

import * as Tabpanelwidget from "tabpanelwidget"
import "tabpanelwidget/dist/tabpanelwidget.min.css"

// find all .tpw-widget in page and install them
Tabpanelwidget.autoinstall()

// or specify element to install (and uninstall)
const el = document.querySelector('#my-element')
// keep in mind install completes asynchronously so uninstall is returned by promise
const uninstall = await Tabpanelwidget.install(el)
// or worse, can use a callback as second arg (make sure you don't call uninstall before it's set in this case):
// let uninstall; Tabpanelwidget.install(el, _uninstall => (uninstall = _uninstall))
// later...
if (uninstall) uninstall()

Vue

<script>
import VueTabpanelwidget from "tabpanelwidget/vue"
import "tabpanelwidget/dist/tabpanelwidget.min.css"

Vue.use(VueTabpanelwidget)
// or Vue.component("Tabpanelwidget", VueTabpanelwidget)
// or in component, components: { VueTabpanelwidget, ... }
<Tabpanelwidget :heading="2" :mode="accordion" :selected-idxs="[1]" :tabs="['a', 'b', 'c']" rtl animate skin="pills" icon-style="fancy" centered disconnected icons-at-the-end rounded>
  <template v-slot:panel-0="">
    override content for panel 0
  </template>
</Tabpanelwidget>

React

import ReactTabpanelwidget from "tabpanelwidget/react"
import "tabpanelwidget/dist/tabpanelwidget.min.css"

<ReactTabpanelwidget heading={2} mode={'accordion'} selected-idxs={[1]} rtl animate skin={'pills'} icon-style={'fancy'} centered disconnected icons-at-the-end rounded>
  <ReactTabpanelwidget.Heading>heading 1</ReactTabpanelwidget.Heading>
  <ReactTabpanelwidget.Panel>panel 1</ReactTabpanelwidget.Panel>
</ReactTabpanelwidget>

Old School

Download the latest release of tabpanelwidget-x.x.x.zip which includes:

  • The minified Script
  • The minified Polyfill
  • A stylesheet (.scss) that contains "variables"
  • A minified stylesheet that is the output of the above file

Setup

Wrap your headings and their relevant content inside a div (or else) to which you apply the class tpw-widget.

Note: If you are using a Definition List, then simply apply that class to the dl itself.

<!-- .tpw-widget -->
<!-- This wrapper can be anything (article/div/dl/whatever) -->
<div class="tpw-widget">
    <!--
    You CAN use any (and as many) headings (h2/h3/h4/h5/h6)
    You MUST use the SAME heading level throughout a Widget
    You CAN use a <dl> but it has to be made of dt/dd pairs
    -->
    <h3 class="tpw-selected">Lorem</h3>
    <!--
    There is no wrapper requirement. Anything may go in between
    the headings. The script wraps that content inside two divs
    The class (optional) dictates which panel should be visible
    -->
    <h3>Ipsum</h3>
    ...
    <h3>Dolor</h3>
    ...
    <h3>Sit Amet</h3>
    ...
</div>
<!-- /.tpw-widget -->

Include the stylesheet in the <head> of your document:

<link href="/PATH_TO_FILE/tabpanelwidget.min.css" rel="stylesheet" />

Include this before </body>:

<script src="/PATH_TO_FILE/tabpanelwidget.min.js"></script>
<script>
  // remove this if you do not want to serve the polyfill
  if (!window.ResizeObserver) {
    const script = document.createElement("script")
    script.src = "/PATH_TO_FILE/tabpanelwidget-polyfill.min.js"
    document.head.appendChild(src)
  }
  // Instantiate TabPanelWidget
  Tabpanelwidget.autoinstall();
</script>

Or you may choose to load all files from CDN:

<link href="//cdn.jsdelivr.net/npm/[email protected]/dist/tabpanelwidget.min.css" rel="stylesheet" />
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/tabpanelwidget.min.js"></script>
<script>
  // remove this if you do not want to serve the polyfill
  if (!window.ResizeObserver) {
    const script = document.createElement("script")
    script.src = "//cdn.jsdelivr.net/npm/[email protected]/dist/tabpanelwidget-polyfill.min.js"
    document.head.appendChild(src)
  }
  // Instantiate TabPanelWidget
  Tabpanelwidget.autoinstall();
</script>

The above will attach the script to all containers with the class tpw-widget.

Note: The above examples use version 1.0.0 but you should link to the latest version on CDN

Angular

Coming soon...

Ember

Coming soon...

Usage

Classes

"Out-of-the-box", the Widget will appear as shown in the Demo section of TabPanelWidget.com but a few classes gives you different options.

All classes are meant to be applied to the Widget (the wrapper) with the exception of tpw-selected which, applied to a "heading" (or multiple headings in the case of an Accordion), will let you arbitrary choose which panel(s) to open by default (the one(s) associated with that/those heading(s)).

"Variables"

tabpanelwidget.min.css is the output of tabpanelwidget.scss. The latter contains variables that will let you customize the Widget's tabs, its headers, and its panels (their color, background, border, border-radius, padding, margin, etc.).

The comments in the SCSS file contain a great deal of information, make sure to check them out!.

Development

Install dependencies and then opens index.html with vite (hot reload, etc.)

% npm install
% npm run dev

Various build scripts, for example:

% npm run build:css
% npm run build:js

To release new version of npm package:

% npx release-it

To check things post release (open index.html without vite),

% open index.html

tabpanelwidget's People

Contributors

adamwills avatar thierryk avatar tjk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tabpanelwidget's Issues

[WIDGET] React - Returning a fragment results in unexpected output

Describe the bug
When mapping through an array, I return a fragment that contains a Heading and Panel. However, the results are not what I'm expecting.

Perhaps there's a different way of doing this?

To Reproduce
See https://codepen.io/AdamWills/pen/abWNoPL

Expected behavior
When mapping an array to produce multiple tabs, I would expect the correct number of tabs/panels to be displayed.

Screenshots
Screen Shot 2021-07-06 at 12 26 31 PM

Desktop (please complete the following information):

  • OS: iOS
  • Browser: Chrome
  • Version: 91.0.4472.114

Additional context
Add any other context about the problem here.

`aria-expanded` must be explicit (`true`/`false`)

Thank you for reporting this.

The state of the aria-expanded attribute should be explicit (true / false).
Per spec, when it is undefined (default):

The element, or another grouping element it controls, is neither expandable nor collapsible; all its child elements are shown or there are no child elements.

We'll update the script.

Originally posted by @thierryk in #13 (comment)

Emit events from TPW? [OTHER]

Is there any way to get the vue version to emit an event when the tab is changed? I'd do it myself, but I can't figure out how to take these scripts and make a standalone TPW vue component that I can add this to. I've got to have way to track the current tab.

[FR] fix cursor navigation in VO/Safari

In Safari, cursor navigation (VO+arrow) is broken because of the lack of support for aria-owns in Webkit.

In that browser, using VO+arrow does not move the cursor from tab to tab, the cursor goes to the open panel instead. Fixing this would seriously reduce the impact of the Webkit bug on VO/Safari users.

Note that fixing cursor navigation will not fix other issues related to the lack of support in Webkit for aria-owns, for example, there is no numbering of tabs in VO/Safari...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.