@ulu/frontend 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@ export class CssBreakpoints {
25
25
  valueFromPsuedo: false,
26
26
  customProperty: "--breakpoint",
27
27
  psuedoSelector: ':before',
28
- order: ["small", "medium", "large"],
28
+ order: ["none", "small", "medium", "large"],
29
29
  debug: false
30
30
  }
31
31
  /**
@@ -44,11 +44,28 @@ export class CssBreakpoints {
44
44
  this.resizeDirection = null;
45
45
  this.previousIndex = null;
46
46
  this.breakpoints = {};
47
+ this.onChangeCallbacks = [];
47
48
  this.order.forEach(n => this.breakpoints[n] = new Breakpoint(n, this));
48
49
  log(this, this);
49
50
  this.update(); // Run for the first time, then whenever browser resizes
50
51
  CssBreakpoints.instances.push(this);
51
52
  }
53
+ /**
54
+ * Add a callback for everytime a breakpoint changes
55
+ * - Not recommended, possibly use to watch for changes, etc
56
+ * - For more control use intance.at(name) with breakpoint methods
57
+ * @param {Function} callback Function to call, passed one argument current instance which can be used to get information about breakpoints
58
+ */
59
+ onChange(callback) {
60
+ this.onChangeCallbacks.push(callback);
61
+ }
62
+ /**
63
+ * Remove change callback
64
+ * @param {Function} callback Function to remove
65
+ */
66
+ removeOnChange(callback) {
67
+ removeArrayElement(this.onChangeCallbacks, callback);
68
+ }
52
69
  /**
53
70
  * Get breakpoint from a psuedo element
54
71
  */
@@ -76,6 +93,10 @@ export class CssBreakpoints {
76
93
  */
77
94
  update() {
78
95
  const name = this.getBreakpoint();
96
+ if (!name) {
97
+ logError(this, 'Unable to get current breakpoint, maybe order is incorrect? Breakpoint check skipped!');
98
+ return;
99
+ }
79
100
  // console.log('name:\n', name);
80
101
  if (name === this.active) return;
81
102
  // this.log(`current breakpoint: ${ name }`);
@@ -113,6 +134,8 @@ export class CssBreakpoints {
113
134
  if (this.previousIndex !== null) {
114
135
  this.resizeDirection = this.previousIndex < index ? "up" : "down";
115
136
  }
137
+
138
+ this.onChangeCallbacks.forEach(cb => cb(this));
116
139
  }
117
140
  /**
118
141
  * Get a breakpoint by key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulu/frontend",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Theming library",
5
5
  "browser": "js/index.js",
6
6
  "main": "index.js",
@@ -34,6 +34,19 @@ export class CssBreakpoints {
34
34
  resizeDirection: string;
35
35
  previousIndex: any;
36
36
  breakpoints: {};
37
+ onChangeCallbacks: any[];
38
+ /**
39
+ * Add a callback for everytime a breakpoint changes
40
+ * - Not recommended, possibly use to watch for changes, etc
41
+ * - For more control use intance.at(name) with breakpoint methods
42
+ * @param {Function} callback Function to call, passed one argument current instance which can be used to get information about breakpoints
43
+ */
44
+ onChange(callback: Function): void;
45
+ /**
46
+ * Remove change callback
47
+ * @param {Function} callback Function to remove
48
+ */
49
+ removeOnChange(callback: Function): void;
37
50
  /**
38
51
  * Get breakpoint from a psuedo element
39
52
  */
@@ -1 +1 @@
1
- {"version":3,"file":"css-breakpoint.d.ts","sourceRoot":"","sources":["../../js/helpers/css-breakpoint.js"],"names":[],"mappings":"AAeA;;;;GAIG;AACH;IACE,wBAAsB;IACtB;;;;;;;MAOC;IACD;;;;;;;OAOG;IACH;QANyB,KAAK;QACL,cAAc;QACd,eAAe;QAChB,OAAO,EAApB,IAAI;QACW,cAAc;OAcvC;IAVC,YAAkB;IAClB,cAAoB;IACpB,iBAAuB;IACvB,wBAA2B;IAC3B,mBAAyB;IACzB,gBAAqB;IAMvB;;OAEG;IACH,gCAEC;IACD;;OAEG;IACH,kCAEC;IACD;;OAEG;IACH,wBAMC;IACD;;OAEG;IACH,eAuCC;IACD;;;;OAIG;IACH,kBAFY,UAAU,CAQrB;CACF;;AAsED;;;GAGG;AACH;IACE,qCAQC;IAPC;;;;MAIC;IACD,cAAuB;IACvB,UAAgB;IAElB;;;;;OAKG;IACH,wDAEC;IACD;;;;;OAKG;IACH,6BAEC;IACD;;;;;OAKG;IACH,6BAEC;IACD;;;OAGG;IACH,8BAEC;IACD;;;;OAIG;IACH,mDAGC;IAED,yBAGC;CACF;AAnID;;;GAGG;AACH;IACE,6CAMC;IALC,eAA0B;IAC1B,gBAAmB;IACnB,UAAY;IACZ,WAAa;IACb,gBAA4B;IAE9B;;OAEG;IACH,sBAMC;IACD;;OAEG;IACH,4BAIC;IACD;;OAEG;IACH,+BAEC;IACD;;;;;OAKG;IACH,aAJW,cAAe,QAiBzB;IACD;;OAEG;IACH,2BAQC;CACF"}
1
+ {"version":3,"file":"css-breakpoint.d.ts","sourceRoot":"","sources":["../../js/helpers/css-breakpoint.js"],"names":[],"mappings":"AAeA;;;;GAIG;AACH;IACE,wBAAsB;IACtB;;;;;;;MAOC;IACD;;;;;;;OAOG;IACH;QANyB,KAAK;QACL,cAAc;QACd,eAAe;QAChB,OAAO,EAApB,IAAI;QACW,cAAc;OAevC;IAXC,YAAkB;IAClB,cAAoB;IACpB,iBAAuB;IACvB,wBAA2B;IAC3B,mBAAyB;IACzB,gBAAqB;IACrB,yBAA2B;IAM7B;;;;;OAKG;IACH,mCAEC;IACD;;;OAGG;IACH,yCAEC;IACD;;OAEG;IACH,gCAEC;IACD;;OAEG;IACH,kCAEC;IACD;;OAEG;IACH,wBAMC;IACD;;OAEG;IACH,eA6CC;IACD;;;;OAIG;IACH,kBAFY,UAAU,CAQrB;CACF;;AAsED;;;GAGG;AACH;IACE,qCAQC;IAPC;;;;MAIC;IACD,cAAuB;IACvB,UAAgB;IAElB;;;;;OAKG;IACH,wDAEC;IACD;;;;;OAKG;IACH,6BAEC;IACD;;;;;OAKG;IACH,6BAEC;IACD;;;OAGG;IACH,8BAEC;IACD;;;;OAIG;IACH,mDAGC;IAED,yBAGC;CACF;AAnID;;;GAGG;AACH;IACE,6CAMC;IALC,eAA0B;IAC1B,gBAAmB;IACnB,UAAY;IACZ,WAAa;IACb,gBAA4B;IAE9B;;OAEG;IACH,sBAMC;IACD;;OAEG;IACH,4BAIC;IACD;;OAEG;IACH,+BAEC;IACD;;;;;OAKG;IACH,aAJW,cAAe,QAiBzB;IACD;;OAEG;IACH,2BAQC;CACF"}