Skip to content

Type definitions #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*

# except the lib and src files
!index.d.ts
!lib/**/*
!src/**/*
200 changes: 200 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@

export interface IHandorgelOptions {

/**
* Whether multiple folds can be opened at once
*/
multiSelectable: boolean,

/**
* Whether the folds are collapsible
*/
collapsible: boolean,

/**
* Whether ARIA attributes are enabled
*/
ariaEnabled: boolean,

/**
* Whether W3C keyboard shortcuts are enabled
*/
keyboardInteraction: boolean,

/**
* Whether to loop header focus. Sets focus back
* to first/last header when end/start reached.
*/
carouselFocus: boolean,

/**
* attribute for the header or content to open folds at initialization
*/
initialOpenAttribute: string,

/**
* Whether to use transition at initial open
*/
initialOpenTransition: boolean,

/**
* Delay used to show initial transition
*/
initialOpenTransitionDelay: number,

/**
* Header class if fold is open
*/
headerOpenClass: string,

/**
* Content class if fold is open
*/
contentOpenClass: string,

/**
* Header class if fold has been opened (transition finished)
*/
headerOpenedClass: string,

/**
* Content class if fold has been opened (transition finished)
*/
contentOpenedClass: string,

/**
* Header class if fold has been focused
*/
headerFocusClass: string,

/**
* Content class if fold has been focused
*/
contentFocusClass: string,

/**
* Header class if fold is disabled
*/
headerDisabledClass: string,

/**
* Content class if fold is disabled
*/
contentDisabledClass: string,

}

export interface IFolds {

/**
* Open content.
*/
open(transition?: boolean):void

/**
* Close content.
*/
close(transition?: boolean):void

/**
* Toggle content.
*/
toggle(transition?: boolean):void

/**
* Disable fold.
*/
disable(): void

/**
* Enable fold.
*/
enable(): void

/**
* Set focus to fold button.
*/
focus(): void

/**
* Remove focus from fold button.
*/
blur(): void

/**
* Remove event listeners and ARIA attributes.
*/
destroy(): void
}

export type IEvents = (

/** Accordion is about to be destroyed */
| 'destroy'

/** Accordion has been destroyed. */
| 'destroyed'

/** Fold is about to be opened. */
| 'fold:open'

/** Fold has opened. */
| 'fold:opened'

/** Fold is about to be closed */
| 'fold:close'

/** Fold has closed. */
| 'fold:closed'

/** Fold button has been focused. */
| 'fold:focus'

/** Fold button has lost focus. */
| 'fold:blur'
)

export class IHandorgel {

constructor(selector: Element, options?: IHandorgelOptions)

/**
* Update fold instances - Use if you dynamically append/remove DOM nodes.
*/
public update(): void

/**
* Set focus to a new header button. You can also directly
* use the native `focus()` method on the button).
*/
public focus(target: 'next' | 'previous' | 'last' | 'first'): void

/**
* Destroy fold instances, remove event listeners and ARIA attributes.
*/
public destroy(): void

/**
* Event Listener
*/
public on(events: IEvents, fn?:(fold: IFolds) => void): void

/**
* Event Listener
*/
public once(events: IEvents, fn?:(fold: IFolds) => void): void

/**
* Event Listener (OFF)
*/
public off(events: IEvents, fn?:(fold: IFolds) => void): void

/**
* Panel Folds
*/
public folds: IFolds[]

}

export default class Handorgel extends IHandorgel {}

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "lib/js/umd/handorgel.js",
"module": "lib/js/esm/handorgel.js",
"jsnext:main": "lib/js/esm/handorgel.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/oncode/handorgel.git"
Expand All @@ -15,6 +16,13 @@
"accessible"
],
"author": "Manuel Sommerhalder",
"contributors": [
{
"name": "Nikolas Savvidis",
"email": "[email protected]",
"url": "https://github.com/panoply"
}
],
"license": "MIT",
"scripts": {
"build": "run-s compile minify",
Expand Down