New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kordion

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kordion

Contemporary style and functionality - an accordion that does more.

  • 3.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-85.57%
Maintainers
0
Weekly downloads
 
Created
Source

Deprecated!!!
It is no longer supported soon. I recommend using the new package prismium. It contains Kordion and other packages.


Kordion

Kordion is a library for quickly creating flexible accordions on a page using JavaScript. It allows you to create accordions with various settings and styles, as well as control them using JavaScript. Kordion uses vanilla JavaScript and does not depend on third-party libraries, which makes it lightweight and fast.

npm downloads npm downloads

📋 Table of Contents

Getting started with Kordion

Installation

You have several possible options for installing the Kordion:

Install from NPM

$ npm install kordion
// Import Kordion JS
import Kordion from "kordion";

// Import Kordion styles
import "kordion/css";
// Import Kordion theme
import "kordion/theme/default";

const kordion = new Kordion(...);

Use Kordion from CDN

If you don't want to include Kordion files in your project, you may use it from CDN:

<!-- Default styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kordion/dist/kordion.min.css">
<!-- Theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kordion/dist/themes/default.min.css">

<!-- Script -->
<script src="https://cdn.jsdelivr.net/npm/kordion/dist/kordion.min.js"></script>

If you use ES modules in your browser, there is a CDN version for that:

<script type="module">
  import Kordion from "https://cdn.jsdelivr.net/npm/kordion/dist/kordion.min.mjs"

  const kordion = new Kordion(...)
</script>

Download

If you want to use Kordion locally, you can directly download them from: jsdelivr.com.

Kordion HTML Layout

Now, we need to add basic Kordion layout:

<!-- The accordion itself -->
<div data-kordion>
  <!-- Accordion Open Button -->
  <button data-kordion-current>
    <span>I am a button!</span>
    <!-- Button icon -->
    <svg data-kordion-icon="[plus, minus]">
      <use xlink:href="sprite.svg#plus"></use>
    </svg>
  </button>
  <!-- Technical wrapping of content -->
  <div data-kordion-hidden>
    <!-- Main content wrapper -->
    <div data-kordion-content>
      <!-- Any of your content can be here, for example: -->
      <article class="article">
        <h2>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</h2>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit dolorem optio quaerat assumenda cupiditate quasi incidunt totam expedita voluptatem. Tenetur, dolorum quisquam alias sit asperiores dolorem atque cupiditate numquam magnam?
        </p>
      </article>
    </div>
  </div>
</div>

Initialize Kordion

Next we need to initialize Kordion in JavaScript:

const kordion = new Kordion("[data-kordion]");

It's that easy to start working with the accordion. You can also customize its functionality more flexibly.

const kordion = new Kordion("[data-kordion]", {
  // Options
  speed: 350,
  spritePath: "sprite.svg",
  autoClose: false,
  autoCloseNested: false,
  scrollTo: false,
});

These are not all the settings, below you can read about each of them in more detail or see examples of implementation.

Parameters

OptionTypeDefaultDescription
speedNumber350The speed of the animation when opening and closing the accordion.
themeString"clear"Theme setup. Requires connection of styles of the selected theme.
By default, kordion does not use themes.
autoCloseBooleanfalseAutomatically close accordions in one container when opening a new accordion. To do this, you must additionally add a container selector to the markup.
autoCloseNestedBooleanfalseAutomatically close child accordions when opening a second child accordion in one parent accordion.
spritePathString"sprite.svg"Path to sprite with icons, for automatic icon replacement when opening and closing accordion.
getKordionHeightBooleanfalseWhen set to true, it will use the height of the accordion, not the content inside.
containerObject["[data-kordion-container]", ".section"]Container selectors, multiple selectors allowed.
Used when autoClose: true.
parentString"[kordion-parent]"Added automatically to the parent accordion. Does not require prior specification in HTML markup.
Only data attribute is allowed.
currentString"[data-kordion-current]"Accordion opening button selector. Any type of selector is allowed.
iconString"[data-kordion-icon]"Button icon selector.
Only data attribute is allowed.
Accepts two icon names via ,.
Example: data-kordion-icon="[plus, minus]" or data-kordion-icon="plus, minus".
Works only with sprites.
hiddenString"[data-kordion-hidden]"Technical content wrapper selector.
Any type of selector can be used.
contentString"[data-kordion-content]"Primary content selector.
Any type of selector can be used.
activeClassString"js-kordion-active"Active accordion class. Set on accordion after opening animation starts and removed when closing animation starts.
openedClassString"js-kordion-opened"Class for a fully expanded accordion. Set to hidden after the opening animation ends, and unset when the closing animation starts.
disabledClassString"js-kordion-disabled"Class for disabling interaction with accordion content when it is opened or closed. Set automatically to content
effectStringRegister the animation of opening and closing the accordion. Currently there is only line-by-line animation.
effectLineByLineObjectAn object with line-by-line animation parameters.

const kordion = new Kordion("[data-kordion]", {
  theme: "dark",
  effect: "line-by-line",
  effectLineByLine: {
    speed: 500,
    delay: 20,
    y: 50
  },
});
eventsObjectRegister event handlers

Events

You can register event handlers for the basic accordion actions. Example:

const kordion = new Kordion("[data-kordion]", {
  events: {
    on: {
      init: function (kordion) {
        console.log("kordion initialized");
      },
    },
    before: {
      init: function (kordion) {
        console.log("Accordion initialized");
      },
      hide: function (kordion, instance) {
        console.log("The accordion is fully open");
      },
    },
  }
});

kordion.on("show", (kordion, instance) => {
  console.log("Accordion opening");
});

kordion.on("beforeShow", (kordion, instance) => {
  console.log("Accordion opening");
});

The following events are available:

GroupNameArgumentsDescription
before
init(kordion)Event before accordion initialization
show(kordion, instance)Event before the opening of the accordion
hide(kordion, instance)Event before accordion closing
on
init(kordion)Event immediately after accordions are initialized
show(kordion, instance)Event during the opening of the accordion
hide(kordion, instance)Event during the closing of the accordion
after
init(kordion)Event after accordion initialization
show(kordion, instance)Event after the opening of the accordion
hide(kordion, instance)Event after accordion closing

Methods

After initializing Kordion, you have an initialized instance of it in a variable (like the kordion variable in the example above) with useful methods and properties.

Example:

const kordion = new Kordion("[data-kordion]");

// Open all accordions by clicking on `".show-all-in-container"`
// in the container with the class `.container`
const button = document.querySelector(".show-all-in-container")
button.addEventListener("click", () => {
  kordion.showAll(".container");
});
MethodDescription
kordion.createInstance(element)Creates an accordion instance. Returns an accordion instance.
kordion.toggle(instance)Toggle accordion. Accepts an accordion instance.
kordion.show(instance)Accordion Opening Method.
kordion.showAll(container)Method for opening all accordions in the specified container. Accepts a selector or DOM element of the container in which to search.
kordion.showEverything()Method to open all accordions on a page.
kordion.hide(instance)Accordion closing method.
kordion.hideNested(instance)Method for closing child accordions.
kordion.hideAll(container)Method for closing all accordions in the specified container. Accepts a selector or DOM element of the container in which to search.
kordion.hideEverything(thisSelector)Method to close all accordions on a page. thisSelector takes a Boolean value, if true, it will be called only for the accordions from which the call occurs, if false, then for ALL accordions on the page, without reference to the accordion from which the call occurs. Default: true
kordion.off(eventName, handler)Remove event handler
kordion.offAny(handler)Remove event listener that will be fired on all events
kordion.on(eventName, handler)Add event handler
kordion.replaceIcon(instance, hidden = true)Method for replacing an icon. Accepts an accordion instance and a boolean icon value:
true = open accordion icon;
false = closed accordion icon.

Themes

clear

This is a standard theme, for which it is enough to connect only standard styles. It contains only the most necessary styles for the accordion to work.

Default

Standard Kordion theme made with love for users.

View screenshot

Dark

Dark theme for connoisseurs of greatness.

View screenshot

Effects

Line-By-Line

Line-by-line appearance of accordion content.

Preview GIF
import Kordion from "kordion";

const kordion = new Kordion("[data-kordion]", {
  theme: "dark",
  effect: "line-by-line",
  effectLineByLine: {
    speed: 350,
    easing: "ease",
    delay: 20,
    y: 50,
  },
});
OptionTypeDefaultDescription
speedNumber350Animation speed
easingString"cubic-bezier(.25,.1,.25,1)"Animation timing function
delayNumber30Delay from previous to next element.
scaleNumber0.95The scale value from which the animation will start.
yNumber/String20The offset along the Y axis from which the animation will start.
xNumber/String0The offset along the X axis from which the animation will start.
opacityNumber/String0.6The opacity value at which the animation will start.
clearPropsObject["transform", "opacity", "transition"]Clearing props. Specifies which props will be cleared at the end of the animation. It is acceptable to enter a string or boolean values.

Plugin for Vue.js

Установка:

$ npm install kordion

Использование:

<script setup>
import { Kordion, KordionCurrent, KordionContent, KordionIcon } from 'kordion/vue'
import 'kordion/css'
import 'kordion/theme/dark'

const kordionOptions = {
  speed: 500,
  theme: 'dark',
}
</script>

<template>
  <div data-kordion-container> <!-- Not obligatory. Required for automatic closing to work. -->
    <Kordion 
      :options="kordionOptions"
      @show="console.log('show')"
      @hide="console.log('hide')"
      @before-show="console.log('before-show')"
      @before-hide="console.log('before-hide')"
      @after-show="console.log('after-show')"
      @after-hide="console.log('after-hide')"
    >
      <KordionCurrent selector="button" :attributes="{ type: 'button', title: 'open' }">
        <span>Open</span>
        <KordionIcon value="sprite.svg#plus" icons="plus, minus" /> <!-- It is optional -->
      </KordionCurrent>
      <KordionContent>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
      </KordionContent>
    </Kordion>
  </div>
</template>

Kordion props

PropTypeDefaultRequiredDescription
optionsObject{}falseThe same parameters are passed as in core. It is forbidden to transmit events.

Kordion events

The Kordion component supports all Kordion events except initialization events. For example:

<Kordion @before-show="..." @before-hide="..." @after-hide="...">

KordionCurrent props

PropTypeDefaultRequiredDescription
selectorString"button"falseHTML button selector. It is allowed to pass any existing HTML selector.
attributesObject{}falseThe attributes of the button. For example: type: "button". It is allowed to transfer date attributes, etc.

KordionIcon props

PropTypeDefaultRequiredDescription
valueString"sprite.svg#icon"falseThe initial value of the icon
iconsStringtrueTwo icons separated by a comma. For example: "plus, minus"

Examples

You can see more detailed examples by following the link.

FAQ

How to build ready files?

It's very simple. Make sure you are in the root of the repository and enter the commands in your terminal:

$ npm install
$ npm run build

Done. The collected files are in the ./dist directory.

Keywords

FAQs

Package last updated on 07 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc