Skip to content

Commit

Permalink
Add setOnChange function (samuelmeuli/font-picker-react#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed May 29, 2019
1 parent a45017e commit 8b89a3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/font-manager/FontManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class FontManager {

private readonly options: Options;

private readonly onChange: (font: Font) => void;
private onChange: (font: Font) => void;

// Other class variables

Expand Down Expand Up @@ -172,4 +172,11 @@ export default class FontManager {
},
);
}

/**
* Update the onChange function (executed when changing the active font)
*/
public setOnChange(onChange: (font: Font) => void): void {
this.onChange = onChange;
}
}
7 changes: 7 additions & 0 deletions src/font-picker/FontPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ export default class FontPicker {
) as HTMLButtonElement;
this.activeFontButton.classList.add("active-font");
}

/**
* Update the onChange function (executed when changing the active font)
*/
public setOnChange(onChange: (font: Font) => void): void {
this.fontManager.setOnChange(onChange);
}
}

// Attach FontPicker class to window to make it accessible in <script> tags
Expand Down

0 comments on commit 8b89a3f

Please sign in to comment.