UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

64 lines 2.78 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Icon */ /* eslint-disable @typescript-eslint/no-deprecated */ /** Class used to return an icon. The icon is variable and can be changed in response to subscribed event ids. * @public * @deprecated in 4.16.0. Uses a deprecated {@link IconSpec} type. Use conditional rendering to render different icons. */ export class ConditionalIconItem { iconGetter; syncEventIds; _value; /** Constructor for ConditionalIconItem * @param iconGetter Function to retrieve the icon that matches the condition. Returns an IconSpec. * @param syncEventIds The array of event ids to be monitored. These events are triggered when the condition(s) that control the icon change. * @param value The default IconSpec. If this is not specified, the function is run to get the initial value. */ constructor(iconGetter, syncEventIds, value) { this.iconGetter = iconGetter; this.syncEventIds = syncEventIds; this._value = value; } /** The current IconSpec according to conditions */ get value() { if (undefined !== this._value) return this._value; this._value = this.iconGetter(); return this._value; } /** Called to update the value by running the iconGetter */ refresh() { const newValue = this.iconGetter(); if (newValue !== this._value) { this._value = newValue; return true; } return false; } /** A helper function that updates the IconSpec value when the specified events are triggered */ static refreshValue(conditionalValue, eventIds) { if (undefined === conditionalValue || !(conditionalValue instanceof ConditionalIconItem)) return false; const iconItem = conditionalValue; if (iconItem.syncEventIds.some((value) => eventIds.has(value.toLowerCase()))) return iconItem.refresh(); return false; } /** helper function to get the iconSpec from a ConditionIconItem as IconSpec | undefined*/ static getValue(conditionalValue) { if (undefined === conditionalValue) return undefined; if (conditionalValue instanceof ConditionalIconItem) { const iconItem = conditionalValue; return iconItem.value; } return conditionalValue; } } //# sourceMappingURL=ConditionalIconItem.js.map