@ni/nimble-components 11.8.1 → 11.8.2

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.
@@ -14226,58 +14226,6 @@
14226
14226
  observable
14227
14227
  ], TreeView$1.prototype, "slottedTreeItems", void 0);
14228
14228
 
14229
- /**
14230
- * A behavior to add or remove a stylesheet from an element based on a property. The behavior ensures that
14231
- * styles are applied while the property matches and that styles are not applied if the property does
14232
- * not match.
14233
- *
14234
- * @public
14235
- */
14236
- class PropertyStyleSheetBehavior {
14237
- /**
14238
- * Constructs a {@link PropertyStyleSheetBehavior} instance.
14239
- * @param propertyName - The property name to operate from.
14240
- * @param value - The property value to operate from.
14241
- * @param styles - The styles to coordinate with the property.
14242
- */
14243
- constructor(propertyName, value, styles) {
14244
- this.propertyName = propertyName;
14245
- this.value = value;
14246
- this.styles = styles;
14247
- }
14248
- /**
14249
- * Binds the behavior to the element.
14250
- * @param elementInstance - The element for which the property is applied.
14251
- */
14252
- bind(elementInstance) {
14253
- Observable.getNotifier(elementInstance).subscribe(this, this.propertyName);
14254
- this.handleChange(elementInstance, this.propertyName);
14255
- }
14256
- /**
14257
- * Unbinds the behavior from the element.
14258
- * @param source - The element for which the behavior is unbinding.
14259
- * @internal
14260
- */
14261
- unbind(source) {
14262
- Observable.getNotifier(source).unsubscribe(this, this.propertyName);
14263
- source.$fastController.removeStyles(this.styles);
14264
- }
14265
- /**
14266
- * Change event for the provided element.
14267
- * @param source - the element for which to attach or detach styles.
14268
- * @param key - the key to lookup to know if the element already has the styles
14269
- * @internal
14270
- */
14271
- handleChange(source, key) {
14272
- if (source[key] === this.value) {
14273
- source.$fastController.addStyles(this.styles);
14274
- }
14275
- else {
14276
- source.$fastController.removeStyles(this.styles);
14277
- }
14278
- }
14279
- }
14280
-
14281
14229
  /**
14282
14230
  * A CSS fragment to set `display: none;` when the host is hidden using the [hidden] attribute.
14283
14231
  * @public
@@ -14877,28 +14825,24 @@
14877
14825
  return getColorForTheme(element, Black91, Black15, White);
14878
14826
  }
14879
14827
 
14880
- /* eslint-disable max-classes-per-file */
14881
14828
  /**
14882
14829
  * Subscription for {@link ThemeStyleSheetBehavior}
14883
14830
  */
14884
14831
  class ThemeStyleSheetBehaviorSubscription {
14885
- constructor(themeStyles, source) {
14886
- this.themeStyles = themeStyles;
14832
+ constructor(value, styles, source) {
14833
+ this.value = value;
14834
+ this.styles = styles;
14887
14835
  this.source = source;
14888
- this.attached = null;
14889
- }
14890
- handleChange({ target, token }) {
14891
- this.attach(token.getValueFor(target));
14892
14836
  }
14893
- attach(theme) {
14894
- if (this.attached !== this.themeStyles[theme]) {
14895
- if (this.attached !== null) {
14896
- this.source.$fastController.removeStyles(this.attached);
14897
- }
14898
- this.attached = this.themeStyles[theme];
14899
- if (this.attached !== null) {
14900
- this.source.$fastController.addStyles(this.attached);
14901
- }
14837
+ handleChange() {
14838
+ const theme$1 = theme.getValueFor(this.source);
14839
+ if (Array.isArray(this.value)
14840
+ ? this.value.includes(theme$1)
14841
+ : this.value === theme$1) {
14842
+ this.source.$fastController.addStyles(this.styles);
14843
+ }
14844
+ else {
14845
+ this.source.$fastController.removeStyles(this.styles);
14902
14846
  }
14903
14847
  }
14904
14848
  }
@@ -14906,47 +14850,22 @@
14906
14850
  * Behavior to conditionally apply theme-based stylesheets.
14907
14851
  */
14908
14852
  class ThemeStyleSheetBehavior {
14909
- constructor(lightStyle, darkStyleOrAlias, colorStyleOrAlias) {
14853
+ constructor(theme, styles) {
14854
+ this.theme = theme;
14855
+ this.styles = styles;
14910
14856
  this.cache = new WeakMap();
14911
- const light = lightStyle;
14912
- const dark = ThemeStyleSheetBehavior.resolveTheme(darkStyleOrAlias, {
14913
- light,
14914
- dark: null,
14915
- color: null
14916
- });
14917
- const color = ThemeStyleSheetBehavior.resolveTheme(colorStyleOrAlias, {
14918
- light,
14919
- dark,
14920
- color: null
14921
- });
14922
- this.themeStyles = {
14923
- light,
14924
- dark,
14925
- color
14926
- };
14927
- }
14928
- static resolveTheme(value, currentThemeStyles) {
14929
- if (value instanceof ElementStyles || value === null) {
14930
- return value;
14931
- }
14932
- const currentStyle = currentThemeStyles[value];
14933
- if (currentStyle === null) {
14934
- throw new Error(`Tried to alias to theme '${value}' but the theme value is not set to a style.`);
14935
- }
14936
- return currentStyle;
14937
14857
  }
14938
14858
  /**
14939
14859
  * @internal
14940
14860
  */
14941
14861
  bind(source) {
14942
14862
  const subscriber = this.cache.get(source)
14943
- || new ThemeStyleSheetBehaviorSubscription(this.themeStyles, source);
14944
- const value = theme.getValueFor(source);
14863
+ || new ThemeStyleSheetBehaviorSubscription(this.theme, this.styles, source);
14945
14864
  // Currently subscriber from cache may have gone through unbind
14946
14865
  // but still be in cache so always resubscribe
14947
14866
  // See: https://github.com/microsoft/fast/issues/3246#issuecomment-1030424876
14948
14867
  theme.subscribe(subscriber, source);
14949
- subscriber.attach(value);
14868
+ subscriber.handleChange();
14950
14869
  this.cache.set(source, subscriber);
14951
14870
  }
14952
14871
  /**
@@ -14964,22 +14883,20 @@
14964
14883
  /**
14965
14884
  * Behavior to conditionally apply theme-based stylesheets. To determine which to apply,
14966
14885
  * the behavior will use the nearest ThemeProvider's 'theme' design system value.
14967
- * To re-use the same style for multiple themes you can specify the name of an already
14968
- * defined theme to alias them together.
14969
14886
  *
14970
14887
  * @public
14971
14888
  * @example
14972
14889
  * ```ts
14973
14890
  * css`
14974
- * // ...
14975
- * `.withBehaviors(new ThemeStyleSheetBehavior(
14976
- * css`:host { ... Theme.light style... }`),
14977
- * null, // No style needed for Theme.dark style
14978
- * Theme.light // For the Theme.color style, re-use the previously set Theme.light style
14891
+ * // ...
14892
+ * `.withBehaviors(
14893
+ * themeBehavior(Theme.light, css` ... `),
14894
+ * // Apply style for both dark and color theme
14895
+ * themeBehavior([Theme.dark, Theme.color], css` ... `)
14979
14896
  * )
14980
14897
  * ```
14981
14898
  */
14982
- const themeBehavior = (lightStyle, darkStyleOrAlias, colorStyleOrAlias) => new ThemeStyleSheetBehavior(lightStyle, darkStyleOrAlias, colorStyleOrAlias);
14899
+ const themeBehavior = (theme, styles) => new ThemeStyleSheetBehavior(theme, styles);
14983
14900
 
14984
14901
  const styles$s = css `
14985
14902
  ${display('inline-block')}
@@ -15006,8 +14923,7 @@
15006
14923
  ::slotted(*:not([href]):last-child) {
15007
14924
  font: ${bodyEmphasizedFont};
15008
14925
  }
15009
- `.withBehaviors(themeBehavior(css `
15010
- ${'' /* Light theme */}
14926
+ `.withBehaviors(themeBehavior(Theme.light, css `
15011
14927
  :host {
15012
14928
  --ni-private-breadcrumb-link-active-font-color: ${DigitalGreenDark};
15013
14929
  }
@@ -15015,8 +14931,7 @@
15015
14931
  :host(.prominent-links) {
15016
14932
  --ni-private-breadcrumb-link-font-color: ${DigitalGreenDark};
15017
14933
  }
15018
- `, css `
15019
- ${'' /* Dark theme */}
14934
+ `), themeBehavior(Theme.dark, css `
15020
14935
  :host {
15021
14936
  --ni-private-breadcrumb-link-active-font-color: ${PowerGreen};
15022
14937
  }
@@ -15024,8 +14939,7 @@
15024
14939
  :host(.prominent-links) {
15025
14940
  --ni-private-breadcrumb-link-font-color: ${PowerGreen};
15026
14941
  }
15027
- `, css `
15028
- ${'' /* Color theme */}
14942
+ `), themeBehavior(Theme.color, css `
15029
14943
  :host {
15030
14944
  --ni-private-breadcrumb-link-active-font-color: ${hexToRgbaCssColor(White, 0.6)};
15031
14945
  }
@@ -15717,17 +15631,72 @@
15717
15631
  .withPrefix('nimble')
15718
15632
  .register(nimbleBreadcrumbItem());
15719
15633
 
15634
+ /**
15635
+ * A behavior to add or remove a stylesheet from an element based on a property. The behavior ensures that
15636
+ * styles are applied while the property matches and that styles are not applied if the property does
15637
+ * not match.
15638
+ *
15639
+ * @public
15640
+ */
15641
+ class MultivaluePropertyStyleSheetBehavior {
15642
+ /**
15643
+ * Constructs a {@link MultivaluePropertyStyleSheetBehavior} instance.
15644
+ * @param propertyName - The property name to operate from.
15645
+ * @param value - The property value or values to operate from.
15646
+ * @param styles - The styles to coordinate with the property.
15647
+ */
15648
+ constructor(propertyName, value, styles) {
15649
+ this.propertyName = propertyName;
15650
+ this.value = value;
15651
+ this.styles = styles;
15652
+ }
15653
+ /**
15654
+ * Binds the behavior to the element.
15655
+ * @param elementInstance - The element for which the property is applied.
15656
+ */
15657
+ bind(elementInstance) {
15658
+ Observable.getNotifier(elementInstance).subscribe(this, this.propertyName);
15659
+ this.handleChange(elementInstance, this.propertyName);
15660
+ }
15661
+ /**
15662
+ * Unbinds the behavior from the element.
15663
+ * @param source - The element for which the behavior is unbinding.
15664
+ */
15665
+ unbind(source) {
15666
+ Observable.getNotifier(source).unsubscribe(this, this.propertyName);
15667
+ source.$fastController.removeStyles(this.styles);
15668
+ }
15669
+ /**
15670
+ * Change event for the provided element.
15671
+ * @param source - the element for which to attach or detach styles.
15672
+ * @param key - the key to lookup to know if the element already has the styles
15673
+ * @internal
15674
+ */
15675
+ handleChange(source, key) {
15676
+ // @ts-expect-error Accessing arbitrary property of an element
15677
+ const currentValue = source[key];
15678
+ if (Array.isArray(this.value)
15679
+ ? this.value.includes(currentValue)
15680
+ : this.value === currentValue) {
15681
+ source.$fastController.addStyles(this.styles);
15682
+ }
15683
+ else {
15684
+ source.$fastController.removeStyles(this.styles);
15685
+ }
15686
+ }
15687
+ }
15688
+
15720
15689
  /**
15721
15690
  * Behavior that will conditionally apply a stylesheet based on the element's
15722
15691
  * appearance property
15723
15692
  *
15724
- * @param value - The value of the appearance property
15693
+ * @param value - The value or values of the appearance property
15725
15694
  * @param styles - The styles to be applied when condition matches
15726
15695
  *
15727
15696
  * @public
15728
15697
  */
15729
15698
  function appearanceBehavior(value, styles) {
15730
- return new PropertyStyleSheetBehavior('appearance', value, styles);
15699
+ return new MultivaluePropertyStyleSheetBehavior('appearance', value, styles);
15731
15700
  }
15732
15701
 
15733
15702
  /**
@@ -16177,10 +16146,7 @@
16177
16146
  transition-duration: 0s;
16178
16147
  }
16179
16148
  }
16180
- `
16181
- .withBehaviors(themeBehavior(
16182
- // Light theme
16183
- css `
16149
+ `.withBehaviors(themeBehavior(Theme.light, css `
16184
16150
  :host {
16185
16151
  --ni-private-card-button-box-shadow-hover-color: ${hexToRgbaCssColor(Black, 0.3)};
16186
16152
  --ni-private-card-button-background-hover-color: ${hexToRgbaCssColor(White, 0.3)};
@@ -16188,9 +16154,7 @@
16188
16154
  --ni-private-card-button-border-active-color: ${hexToRgbaCssColor(Black91, 0.2)};
16189
16155
  --ni-private-card-button-border-selected-color: ${hexToRgbaCssColor(Black91, 0.6)};
16190
16156
  }
16191
- `,
16192
- // Dark theme
16193
- css `
16157
+ `), themeBehavior(Theme.dark, css `
16194
16158
  :host {
16195
16159
  --ni-private-card-button-box-shadow-hover-color: ${hexToRgbaCssColor(Black, 0.77)};
16196
16160
  --ni-private-card-button-background-hover-color: ${hexToRgbaCssColor(Black15, 0.07)};
@@ -16198,9 +16162,7 @@
16198
16162
  --ni-private-card-button-border-active-color: ${hexToRgbaCssColor(Black15, 0.2)};
16199
16163
  --ni-private-card-button-border-selected-color: ${Black15};
16200
16164
  }
16201
- `,
16202
- // Color theme
16203
- css `
16165
+ `), themeBehavior(Theme.color, css `
16204
16166
  :host {
16205
16167
  --ni-private-card-button-box-shadow-hover-color: ${hexToRgbaCssColor(White, 0.77)};
16206
16168
  --ni-private-card-button-background-hover-color: ${hexToRgbaCssColor(White, 0.2)};
@@ -20926,8 +20888,7 @@
20926
20888
  transition-duration: 0s;
20927
20889
  }
20928
20890
  }
20929
- `.withBehaviors(themeBehavior(css `
20930
- ${'' /* Light theme */}
20891
+ `.withBehaviors(themeBehavior(Theme.light, css `
20931
20892
  :host {
20932
20893
  --ni-private-switch-background-disabled-color: ${hexToRgbaCssColor(Black91, 0.07)};
20933
20894
  --ni-private-switch-indicator-background-color: ${White};
@@ -20935,8 +20896,7 @@
20935
20896
  --ni-private-switch-indicator-border-color: ${Black91};
20936
20897
  --ni-private-switch-indicator-border-disabled-color: ${hexToRgbaCssColor(Black91, 0.3)};
20937
20898
  }
20938
- `, css `
20939
- ${'' /* Dark theme */}
20899
+ `), themeBehavior(Theme.dark, css `
20940
20900
  :host {
20941
20901
  --ni-private-switch-background-disabled-color: ${hexToRgbaCssColor(Black15, 0.07)};
20942
20902
  --ni-private-switch-indicator-background-color: ${hexToRgbaCssColor(Black91, 0.3)};
@@ -20944,8 +20904,7 @@
20944
20904
  --ni-private-switch-indicator-border-color: ${Black7};
20945
20905
  --ni-private-switch-indicator-border-disabled-color: ${hexToRgbaCssColor(Black7, 0.3)};
20946
20906
  }
20947
- `, css `
20948
- ${'' /* Color theme */}
20907
+ `), themeBehavior(Theme.color, css `
20949
20908
  :host {
20950
20909
  --ni-private-switch-background-disabled-color: ${hexToRgbaCssColor(White, 0.07)};
20951
20910
  --ni-private-switch-indicator-background-color: ${hexToRgbaCssColor(White, 0.1)};
@@ -21382,6 +21341,7 @@
21382
21341
  frameless: 'frameless'
21383
21342
  };
21384
21343
 
21344
+ /* eslint-disable @typescript-eslint/indent */
21385
21345
  const styles$4 = css `
21386
21346
  ${display('inline-block')}
21387
21347
  ${styles$k}
@@ -21610,19 +21570,15 @@
21610
21570
  :host([readonly]) .root {
21611
21571
  border-color: transparent;
21612
21572
  }
21613
- `), themeBehavior(css `
21614
- ${'' /* Light theme */}
21573
+ `), themeBehavior(Theme.light, css `
21615
21574
  .control::-ms-reveal {
21616
21575
  filter: invert(0%);
21617
21576
  }
21618
- `, css `
21619
- ${'' /* Dark theme */}
21577
+ `), themeBehavior([Theme.dark, Theme.color], css `
21620
21578
  .control::-ms-reveal {
21621
21579
  filter: invert(100%);
21622
21580
  }
21623
- `,
21624
- // Color theme
21625
- Theme.dark));
21581
+ `));
21626
21582
 
21627
21583
  /**
21628
21584
  * A nimble-styed HTML text input
@@ -21753,11 +21709,7 @@
21753
21709
  display: flex;
21754
21710
  flex: 0 0 auto;
21755
21711
  }
21756
- `.withBehaviors(
21757
- /* Local Theme Behaviors for tooltip borders and backgrounds */
21758
- themeBehavior(
21759
- // Light Theme
21760
- css `
21712
+ `.withBehaviors(themeBehavior(Theme.light, css `
21761
21713
  :host(.fail) {
21762
21714
  --ni-private-tooltip-border-color: ${BannerFail100DarkUi};
21763
21715
  --ni-private-tooltip-background-color: ${White};
@@ -21767,9 +21719,7 @@
21767
21719
  --ni-private-tooltip-border-color: ${Information100LightUi};
21768
21720
  --ni-private-tooltip-background-color: ${White};
21769
21721
  }
21770
- `,
21771
- // Dark Theme
21772
- css `
21722
+ `), themeBehavior(Theme.dark, css `
21773
21723
  :host {
21774
21724
  --ni-private-tooltip-border-color: ${hexToRgbaCssColor(Black15, 0.3)};
21775
21725
  --ni-private-tooltip-background-color: ${Black85};
@@ -21782,9 +21732,7 @@
21782
21732
  :host(.fail) {
21783
21733
  --ni-private-tooltip-border-color: ${BannerFail100DarkUi};
21784
21734
  }
21785
- `,
21786
- // Color Theme
21787
- css `
21735
+ `), themeBehavior(Theme.color, css `
21788
21736
  .anchored-region {
21789
21737
  background-color: ${ForestGreen};
21790
21738
  }