Skip to content

Commit

Permalink
document interfaces for intellisense
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkunka committed May 8, 2018
1 parent 2f4d74a commit 4d69e8b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 32 deletions.
86 changes: 79 additions & 7 deletions src/Config/Interfaces/IBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,84 @@
interface IBehavior {
/**
* A boolean dictating whether or not to further
* reduce the `maxVisibleItems` value of the dropdown
* menu when a collision occurs.
*
* @default true
*/

clampMaxVisibleItems?: boolean;

/**
* A boolean dictating whether or not the dropdown
* should close when a value is selected.
*
* @default true
*/

closeOnSelect?: boolean;

/**
* A boolean dictating whether or not the dropdown should
* watch for updates to the underyling `<select>` element
* and reactively update itself. For example, when an
* `<option>` is added or removed, or the `disabled`
* attribute is toggled on.
*
* @default false
*/

liveUpdates?: boolean;

/**
* A boolean dictating whether or not the user should be
* able to loop from the top of the menu to the bottom
* (and vice-versa) when changing the focused option by
* pressing the up/down arrow keys.
*
* @default false
*/

loop?: boolean;

/**
* An integer dictating the maximum visible options
* that should be visible in the dropdown body before
* limiting its height and forcing the user to scroll.
*
* @default 15
*/

maxVisibleItems?: number;

/**
* A boolean dictating whether or not the dropdown
* should open automatically whenever it gains focus.
*
* @default false
*/

openOnFocus?: boolean;

/**
* A boolean dictating whether or not the placeholder text
* (if provided) should be shown whenever the dropdown is
* open (even once a value has been selected).
*
* @default false
*/

showPlaceholderWhenOpen?: boolean;
openOnFocus?: boolean;
closeOnSelect?: boolean;
useNativeUiOnMobile?: boolean;
loop?: boolean;
clampMaxVisibleItems?: boolean;
liveUpdates?: boolean;
maxVisibleItems?: number;

/**
* A boolean dictating whether or not to fall back to
* the native `<select>` UI on mobile devices (while
* maintaing a styled "head").
*
* @default true
*/

useNativeUiOnMobile?: boolean;
}

export default IBehavior;
2 changes: 1 addition & 1 deletion src/Config/Interfaces/ICallback.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type ICallback = (arg?: any) => void;
type ICallback = () => void;

export default ICallback;
25 changes: 22 additions & 3 deletions src/Config/Interfaces/ICallbacks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import ICallback from './ICallback';
import ICallback from './ICallback';
import ISelectCallback from './ISelectCallback';

interface ICallbacks {
onOpen?: ICallback;
/**
* An optional callback function to be invoked whenever
* the dropdown is closed.
*/

onClose?: ICallback;
onSelect?: ICallback;

/**
* An optional callback function to be invoked whenever
* the dropdown is opened.
*/

onOpen?: ICallback;

/**
* An optional callback function to be invoked whenever
* an option is selected. The selected option's value
* is passed as the first argument to the callback.
*/

onSelect?: ISelectCallback;
}

export default ICallbacks;
3 changes: 3 additions & 0 deletions src/Config/Interfaces/ISelectCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type ISelectCallback = (value?: string) => void;

export default ISelectCallback;
51 changes: 30 additions & 21 deletions src/Easydropdown/EasydropdownFacade.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
import Easydropdown from './Easydropdown';

class EasydropdownFacade {
/**
* Programmatically opens the dropdown, closing any
* other open instances.
*/

public open: () => void;

/**
* Programmatically closes the dropdown.
*/

public close: () => void;

/**
* Refreshes the instance and updates the DOM in
* response to a change in the underlying `<select>`
* element (for example, adding or removing an option).
*/

public refresh: () => void;

/**
* Destroys the instance by removing all EasyDropDown-generated
* elements from the DOM, and unbinding all event handlers.
* The underlying select is returned to the root position.
*/

public destroy: () => void;

/**
* An accessor property allowing writing to and reading
* from the dropdown's value.
*/

public value: string;

constructor(implementation: Easydropdown) {
/**
* Programmatically opens the dropdown menu.
*/

this.open = implementation.open.bind(implementation);

/**
* Programmatically closes the dropdown menu.
*/

this.close = implementation.close.bind(implementation);

/**
* Rebuilds the EasyDropDown instance in response to
* options being added or removed.
*/

this.refresh = implementation.refresh.bind(implementation);

/**
* Destroys the EasyDropDown instance, unbinding all event handlers
* and reverting the provided <select> to its original state.
*/

this.destroy = implementation.destroy.bind(implementation);

Object.defineProperties(this, {
Expand Down

0 comments on commit 4d69e8b

Please sign in to comment.