diff --git a/.npmignore b/.npmignore index b639079..055fe28 100644 --- a/.npmignore +++ b/.npmignore @@ -2,5 +2,6 @@ * # except the lib and src files +!index.d.ts !lib/**/* !src/**/* diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..1303357 --- /dev/null +++ b/index.d.ts @@ -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 {} + diff --git a/package.json b/package.json index 1866bb5..f3a99a4 100644 --- a/package.json +++ b/package.json @@ -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" @@ -15,6 +16,13 @@ "accessible" ], "author": "Manuel Sommerhalder", + "contributors": [ + { + "name": "Nikolas Savvidis", + "email": "n.savvidis@gmx.com", + "url": "https://github.com/panoply" + } + ], "license": "MIT", "scripts": { "build": "run-s compile minify",