lexgui 0.5.10 → 0.5.11

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.
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  var LX = {
9
- version: "0.5.10",
9
+ version: "0.5.11",
10
10
  ready: false,
11
11
  components: [], // Specific pre-build components
12
12
  signals: {}, // Events and triggers
@@ -204,6 +204,29 @@ function setTheme( colorScheme )
204
204
 
205
205
  LX.setTheme = setTheme;
206
206
 
207
+ /**
208
+ * @method getTheme
209
+ * @description Gets either "dark" or "light" theme value
210
+ */
211
+ function getTheme()
212
+ {
213
+ return document.documentElement.getAttribute( "data-theme" ) ?? "dark";
214
+ }
215
+
216
+ LX.getTheme = getTheme;
217
+
218
+ /**
219
+ * @method switchTheme
220
+ * @description Toggles between "dark" and "light" themes
221
+ */
222
+ function switchTheme()
223
+ {
224
+ const currentTheme = getTheme();
225
+ setTheme( currentTheme == "dark" ? "light" : "dark" );
226
+ }
227
+
228
+ LX.switchTheme = switchTheme;
229
+
207
230
  /**
208
231
  * @method setThemeColor
209
232
  * @description Sets a new value for one of the main theme variables
@@ -1702,35 +1725,52 @@ function badge( text, className, options = {} )
1702
1725
  LX.badge = badge;
1703
1726
 
1704
1727
  /**
1705
- * @method makeContainer
1706
- * @param {Array} size
1728
+ * @method makeElement
1729
+ * @param {String} htmlType
1707
1730
  * @param {String} className
1708
1731
  * @param {String} innerHTML
1709
1732
  * @param {HTMLElement} parent
1710
1733
  * @param {Object} overrideStyle
1711
1734
  */
1712
1735
 
1713
- function makeContainer( size, className, innerHTML, parent, overrideStyle = {} )
1736
+ function makeElement( htmlType, className, innerHTML, parent, overrideStyle = {} )
1714
1737
  {
1715
- const container = document.createElement( "div" );
1716
- container.className = "lexcontainer " + ( className ?? "" );
1717
- container.innerHTML = innerHTML ?? "";
1718
- container.style.width = size && size[ 0 ] ? size[ 0 ] : "100%";
1719
- container.style.height = size && size[ 1 ] ? size[ 1 ] : "100%";
1720
- Object.assign( container.style, overrideStyle );
1738
+ const element = document.createElement( htmlType );
1739
+ element.className = className ?? ""
1740
+ element.innerHTML = innerHTML ?? "";
1741
+ Object.assign( element.style, overrideStyle );
1721
1742
 
1722
1743
  if( parent )
1723
1744
  {
1724
1745
  if( parent.attach ) // Use attach method if possible
1725
1746
  {
1726
- parent.attach( container );
1747
+ parent.attach( element );
1727
1748
  }
1728
1749
  else // its a native HTMLElement
1729
1750
  {
1730
- parent.appendChild( container );
1751
+ parent.appendChild( element );
1731
1752
  }
1732
1753
  }
1733
1754
 
1755
+ return element;
1756
+ }
1757
+
1758
+ LX.makeElement = makeElement;
1759
+
1760
+ /**
1761
+ * @method makeContainer
1762
+ * @param {Array} size
1763
+ * @param {String} className
1764
+ * @param {String} innerHTML
1765
+ * @param {HTMLElement} parent
1766
+ * @param {Object} overrideStyle
1767
+ */
1768
+
1769
+ function makeContainer( size, className, innerHTML, parent, overrideStyle = {} )
1770
+ {
1771
+ const container = LX.makeElement( "div", "lexcontainer " + ( className ?? "" ), innerHTML, parent, overrideStyle );
1772
+ container.style.width = size && size[ 0 ] ? size[ 0 ] : "100%";
1773
+ container.style.height = size && size[ 1 ] ? size[ 1 ] : "100%";
1734
1774
  return container;
1735
1775
  }
1736
1776
 
@@ -7252,12 +7292,17 @@ class Form extends Widget {
7252
7292
  if( entryData.constructor != Object )
7253
7293
  {
7254
7294
  entryData = { };
7295
+ data[ entry ] = entryData;
7255
7296
  }
7256
7297
 
7257
7298
  entryData.placeholder = entryData.placeholder ?? entry;
7258
7299
  entryData.width = "100%";
7259
7300
 
7260
- // this.addLabel( entry, { textClass: "formlabel" } );
7301
+ if( !( options.skipLabels ?? false ) )
7302
+ {
7303
+ const label = new TextInput( null, entry, null, { disabled: true, inputClass: "formlabel nobg" } );
7304
+ container.appendChild( label.root );
7305
+ }
7261
7306
 
7262
7307
  entryData.textWidget = new TextInput( null, entryData.constructor == Object ? entryData.value : entryData, ( value ) => {
7263
7308
  container.formData[ entry ] = value;
@@ -7267,9 +7312,21 @@ class Form extends Widget {
7267
7312
  container.formData[ entry ] = entryData.constructor == Object ? entryData.value : entryData;
7268
7313
  }
7269
7314
 
7270
- container.appendChild( new Blank().root );
7315
+ const buttonContainer = LX.makeContainer( ["100%", "auto"], "flex flex-row", "", container );
7316
+
7317
+ if( options.secondaryActionName || options.secondaryActionCallback )
7318
+ {
7319
+ const secondaryButton = new Button( null, options.secondaryActionName ?? "Cancel", ( value, event ) => {
7320
+ if( callback )
7321
+ {
7322
+ callback( container.formData, event );
7323
+ }
7324
+ }, { width: "100%", minWidth: "0", buttonClass: options.secondaryButtonClass ?? "primary" } );
7325
+
7326
+ buttonContainer.appendChild( secondaryButton.root );
7327
+ }
7271
7328
 
7272
- const submitButton = new Button( null, options.actionName ?? "Submit", ( value, event ) => {
7329
+ const primaryButton = new Button( null, options.primaryActionName ?? "Submit", ( value, event ) => {
7273
7330
 
7274
7331
  for( let entry in data )
7275
7332
  {
@@ -7285,9 +7342,9 @@ class Form extends Widget {
7285
7342
  {
7286
7343
  callback( container.formData, event );
7287
7344
  }
7288
- }, { buttonClass: "primary" } );
7345
+ }, { width: "100%", minWidth: "0", buttonClass: options.primaryButtonClass ?? "contrast" } );
7289
7346
 
7290
- container.appendChild( submitButton.root );
7347
+ buttonContainer.appendChild( primaryButton.root );
7291
7348
  }
7292
7349
  }
7293
7350
 
@@ -11217,7 +11274,12 @@ class Panel {
11217
11274
  * @param {Object} data Form data
11218
11275
  * @param {Function} callback Callback function on submit form
11219
11276
  * @param {Object} options:
11220
- * actionName: Text to be shown in the button
11277
+ * primaryActionName: Text to be shown in the primary action button ['Submit']
11278
+ * primaryButtonClass: Button class for primary action button ['contrast']
11279
+ * secondaryActionName: Text to be shown in the secondary action button ['Cancel']
11280
+ * secondaryActionCallback: Callback function on press secondary button
11281
+ * secondaryButtonClass: Button class for secondary action button ['primary']
11282
+ * skipLabels: Do not show input field labels [false]
11221
11283
  */
11222
11284
 
11223
11285
  addForm( name, data, callback, options = {} ) {