semantic-forms 5.1.6 → 5.1.8

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.
package/semanticForms.js CHANGED
@@ -241,62 +241,62 @@ const semanticForms = () => {
241
241
  input.style.setProperty('min-height', '0')
242
242
  input.style.setProperty('max-height', 'none')
243
243
  input.style.setProperty('height', 'auto')
244
-
244
+
245
245
  const handleInput = () => {
246
246
  // reset rows attribute to get accurate scrollHeight
247
247
  let maxRows = input.getAttribute('data-max-rows')
248
248
 
249
249
  if (maxRows) {
250
250
  if (isNaN(maxRows) || Number(maxRows) <= 0) {
251
- console.warn(`An invalid value was passed to the "data-max-rows" attribute. This value will be ignored.\n\nProvided value: ${input.getAttribute('data-max-rows')}`, )
251
+ console.warn(`An invalid value was passed to the "data-max-rows" attribute. This value will be ignored.\n\nProvided value: ${input.getAttribute('data-max-rows')}`)
252
252
  maxRows = null
253
253
  }
254
254
  }
255
255
 
256
256
  const minRows = input.getAttribute('data-max-rows') && Number(input.getAttribute('data-max-rows')) < 5 ? input.getAttribute('data-max-rows') : '5'
257
257
  input.setAttribute('rows', minRows)
258
-
258
+
259
259
  // get the computed values object reference
260
260
  const style = window.getComputedStyle(input)
261
-
261
+
262
262
  // force content-box for size accurate line-height calculation, remove scrollbars, lock width (subtract inline padding and inline border widths), and remove inline padding and borders to keep width consistent (for text wrapping accuracy)
263
263
  const inlinePadding = parseFloat(style['padding-left']) + parseFloat(style['padding-right'])
264
264
  const inlineBorderWidth = parseFloat(style['border-left-width']) + parseFloat(style['border-right-width'])
265
265
  input.style.setProperty('overflow', 'hidden', 'important')
266
- input.style.setProperty('width', (parseFloat(style['width']) - inlinePadding - inlineBorderWidth) + 'px')
266
+ input.style.setProperty('width', (parseFloat(style.width) - inlinePadding - inlineBorderWidth) + 'px')
267
267
  input.style.setProperty('box-sizing', 'content-box')
268
268
  input.style.setProperty('padding-inline', '0')
269
269
  input.style.setProperty('border-width', '0')
270
-
270
+
271
271
  // get the base line height, and top / bottom padding
272
272
  const blockPadding = parseFloat(style['padding-top']) + parseFloat(style['padding-bottom'])
273
- const lineHeight = style['line-height'] === 'normal'
274
- ? parseFloat(style['height']) // if line-height is not explicitly set, use the computed height value (ignore padding due to content-box)
273
+ const lineHeight = style['line-height'] === 'normal'
274
+ ? parseFloat(style.height) // if line-height is not explicitly set, use the computed height value (ignore padding due to content-box)
275
275
  : parseFloat(style['line-height']) // otherwise (line-height is explicitly set), use the computed line-height value
276
-
276
+
277
277
  // get the scroll height (rounding to be safe to ensure cross browser consistency)
278
278
  const scrollHeight = Math.round(input.scrollHeight)
279
-
279
+
280
280
  // undo overflow, width, border-width, box-sizing & inline padding overrides
281
281
  input.style.removeProperty('width')
282
282
  input.style.removeProperty('box-sizing')
283
283
  input.style.removeProperty('padding-inline')
284
284
  input.style.removeProperty('border-width')
285
285
  input.style.removeProperty('overflow')
286
-
286
+
287
287
  // subtract blockPadding from scrollHeight and divide that by our lineHeight to get the row count, round to nearest integer as it will always be within ~.1 of the correct whole number
288
288
  const rows = Math.round((scrollHeight - blockPadding) / lineHeight)
289
-
289
+
290
290
  // set the calculated rows attribute (limited by rowLimit)
291
291
  if (maxRows) {
292
- input.setAttribute("rows", "" + Math.min(rows, Number(maxRows)))
292
+ input.setAttribute('rows', '' + Math.min(rows, Number(maxRows)))
293
293
  } else {
294
- input.setAttribute("rows", "" + rows)
294
+ input.setAttribute('rows', '' + rows)
295
295
  }
296
296
  }
297
-
297
+
298
298
  input.addEventListener('input', handleInput)
299
-
299
+
300
300
  // trigger the event to set the initial rows value
301
301
  input.dispatchEvent(new Event('input', { bubbles: true }))
302
302
  }
@@ -1,6 +1,7 @@
1
1
  // #region global styles
2
2
  form.semanticForms, form.semanticForms.light, table.semanticForms {
3
3
  --semanticFormsFontFamily: sans-serif;
4
+ --semanticFormsFontSize: 16px;
4
5
  --semanticFormsFormBgColor: #fff;
5
6
  --semanticFormsFormSubBgColor: #f5f5f5;
6
7
  --semanticFormsTextColor: #000;
@@ -90,6 +91,7 @@ form.semanticForms.light,
90
91
  table.semanticForms,
91
92
  table.semanticForms.light {
92
93
  font-family: var(--semanticFormsFontFamily);
94
+ font-size: var(--semanticFormsFontSize);
93
95
  width: 100%;
94
96
  container-type: inline-size;
95
97
  container-name: semanticForm;
@@ -325,9 +327,11 @@ table.semanticForms.light {
325
327
  font-size: 100%;
326
328
  line-height: 1;
327
329
  user-select: none;
330
+ transform: scale(1);
331
+ transition: transform 180ms;
328
332
 
329
333
  &:active {
330
- background-image: linear-gradient(to bottom, var(--semanticFormsButtonGradientDark) 0%, var(--semanticFormsButtonGradientLight) 100%);
334
+ transform: scale(0.97);
331
335
  }
332
336
  }
333
337
 
@@ -412,6 +416,71 @@ table.semanticForms.light {
412
416
  }
413
417
  }
414
418
 
419
+ // #region summary
420
+ details {
421
+ box-sizing: border-box; // ensure sizings match across browsers
422
+ position: relative;
423
+ background-color: var(--semanticFormsNestedFieldsetBgColor); // TODO: check if this is right
424
+ border: var(--semanticFormsNestedFieldsetBorder);
425
+ border-radius: var(--semanticFormsBorderRadius);
426
+ display: flex;
427
+ flex-direction: column;
428
+ gap: 5px;
429
+ padding: 20px 10px 10px 10px;
430
+ margin-bottom: 15px;
431
+ min-height: calc(var(--semanticFormsFontSize) + 20px);
432
+
433
+ &::details-content {
434
+ visibility: hidden;
435
+ opacity: 0;
436
+ transition: opacity 250ms ease-in, visibility 0ms ease-in 250ms;
437
+ }
438
+
439
+ summary {
440
+ margin: 0;
441
+ line-height: 1;
442
+ position: absolute;
443
+ top: 10px;
444
+ left: 22px;
445
+ transition: top 250ms;
446
+
447
+ &::-webkit-details-marker,
448
+ &::marker {
449
+ content: ''; // hide default arrow, as it cannot be animated
450
+ }
451
+
452
+ &::after {
453
+ // custom arrow
454
+ content: '';
455
+ border-width: .4rem;
456
+ border-style: solid;
457
+ border-color: transparent transparent transparent var(--semanticFormsTextColor);
458
+ position: absolute;
459
+ top: 0;
460
+ left: -10px;
461
+ transform: rotate(0);
462
+ transform-origin: .2rem 50%;
463
+ transition: 250ms transform ease;
464
+ }
465
+ }
466
+ }
467
+
468
+ details[open] {
469
+ padding-top: 35px; // TODO: remove this when animated detail label is reintroduced
470
+
471
+ &::details-content {
472
+ visibility: visible;
473
+ opacity: 1;
474
+ transition: opacity 250ms ease-in, visibility 0ms ease-in 0ms;
475
+ }
476
+
477
+ summary {
478
+ &::after {
479
+ transform: rotate(90deg);
480
+ }
481
+ }
482
+ }
483
+
415
484
  details[open], summary {
416
485
  margin-bottom: 10px;
417
486
  }
@@ -419,6 +488,7 @@ table.semanticForms.light {
419
488
  summary {
420
489
  cursor: pointer;
421
490
  }
491
+ // #endregion
422
492
 
423
493
  // update for scrollbars
424
494
  @supports (scrollbar-color: auto) {