@kelvininc/ui-components
Version:
Kelvin UI Components
186 lines (176 loc) • 11.7 kB
JavaScript
import { S as StyleMode, E as ERelativeTimeRangeKey, C as CUSTOM_TIME_RANGE_KEY, a as EUnitReference } from './p-BP5CxQcH.js';
export { l as EAbsoluteTimeError, i as EAbsoluteTimePickerMode, m as EActionButtonType, h as EAlarmSeverity, n as EAlertType, d as EAnchorTarget, o as EBadgeType, e as EComponentSize, p as ECopyToClipboardState, q as EDateTimeInputTypeStyle, t as EIconName, u as EIllustrationName, A as EInputFieldType, k as EInputSource, v as ERelativeTimeComparisonConfig, j as ERelativeTimeInputMode, G as EStepState, x as ETabItemType, y as ETagColor, z as ETagState, D as ETimePickerView, F as EToasterType, w as EToggleState, f as ETooltipPosition, B as EValidationState, g as getAssetPath, r as render, s as setAssetPath, b as setNonce, c as setPlatformOptions } from './p-BP5CxQcH.js';
import { D as DEFAULT_CONFIG } from './p-CRcRM80a.js';
export { C as COPY_TOOLTIP } from './p-BJWqAn4w.js';
export { a as arraysHelper, g as getArrayOfIndexes } from './p-C0GqgbWr.js';
export { c as clipboardHelper, a as copyTextToClipboard, f as fallbackCopyTextToClipboard } from './p-DWmIpAOE.js';
export { c as cssClassHelper, g as getClassList, a as getClassMap } from './p-DCOsOAOy.js';
import { T as TIMEZONES, a as areDatesValid, b as buildTimezoneByOffset, c as calculateOffsetDate, f as formatDate, d as formatDateTime, e as formatForTimezone, g as formatTimezoneName, h as fromDateFields, i as fromDateInput, j as fromISO, k as getDateMonth, l as getDateYear, m as getDatesBetweenRange, n as getDefaultTimezone, o as getDefaultTimezoneSettings, p as getFirstWeekdayIndexOfMonth, q as getMonthAndYearTitle, r as getMonthName, s as getNumberOfDaysInMonth, t as getTimezoneOffset, u as getTimezonesNames, v as getWeekdaysNames, w as isDateAfter, x as isDateBefore, y as isDateInArray, z as isDateInRange, A as isDateSame, B as isDateTimeAfter, C as isDateTimeBefore, D as isDateValid, E as newDate, F as newTimezoneDate, G as newTimezoneDateFromFormat } from './p-BS8xGxWJ.js';
export { g as getUTF8StringLength, a as isSubString, i as isValidLabel, s as stringHelper } from './p-YzSFobpQ.js';
export { f as floatingUIHelper, m as mergeComputePositionConfigs } from './p-tvmoGbWd.js';
export { d as didClickOnElement, g as getSlotElements, i as isTargetOnElement, m as mouseEventHelper } from './p-Cvht_zQn.js';
import { D as DEFAULT_RELATIVE_TIME_OPTIONS_GROUPS, R as RELATIVE_TIME_OFFSETS, b as buildAbsoluteAmountOfUnitsConfigRange, a as buildDayjsRange, c as buildOptionRange, d as buildRelativeAmountOfUnitsConfigRange, e as buildRelativeTimeOption, f as buildSingleDateConfigRange, g as buildStartDateEndDateConfigRange, h as buildTimestampRange, i as getAbsoluteTimeRange, j as getRelativeTimeCalculation, k as getRelativeTimeOption, l as getRelativeTimeRangeISO, m as getRelativeTimeRangeTimestamp, v as validateRelativeTimeOffsets } from './p-BEbvpiII.js';
export { h as buildAllOptionsSelected, j as buildPartialOptionsSelected, e as buildSelectedOptions, f as flattenSelectOptionsArray, c as getFlattenSelectOptions, d as getFlattenSelectOptionsArray, l as getNextHightlightableOption, k as getPreviousHightlightableOption, g as getSelectableOptions, a as getSelectableOptionsFromArray, i as getSelectedCount, b as getSelectedSelectableOptions, m as searchDropdownOptions, s as selectHelper } from './p-BO7qqFHC.js';
const initialize = (userConfig = {}) => {
var _a, _b;
const { window: win } = window;
if (typeof win === 'undefined') {
return;
}
const instance = (win.KvUiComponents = (_a = win.KvUiComponents) !== null && _a !== void 0 ? _a : {});
const actualConfig = (instance.config = (_b = instance.config) !== null && _b !== void 0 ? _b : {});
win.KvUiComponents.config = Object.assign(Object.assign(Object.assign({}, DEFAULT_CONFIG), actualConfig), userConfig);
};
/**
* Dynamically sets the theme mode without requiring a page refresh.
* This updates the mode attribute on the body element, which triggers
* CSS custom properties to update across all components.
*
* @param mode - The StyleMode to set ('night' or 'light')
*/
const setThemeMode = (mode) => {
var _a;
if (!Object.values(StyleMode).includes(mode)) {
console.warn(`Invalid theme mode: ${mode}, expected: ${Object.values(StyleMode).join(',')}`);
return;
}
document.body.setAttribute('mode', mode);
if (typeof window !== 'undefined' && ((_a = window.KvUiComponents) === null || _a === void 0 ? void 0 : _a.config)) {
window.KvUiComponents.config.styleMode = mode;
}
};
/**
* Gets the current theme mode.
*
* @returns The current StyleMode
*/
const getThemeMode = () => {
var _a, _b, _c;
const bodyMode = document.body.getAttribute('mode');
if (bodyMode && Object.values(StyleMode).includes(bodyMode)) {
return bodyMode;
}
return (_c = (_b = (_a = window.KvUiComponents) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.styleMode) !== null && _c !== void 0 ? _c : StyleMode.Night;
};
/**
* Toggles between light and dark theme modes.
*
* @returns The new StyleMode after toggling
*/
const toggleThemeMode = () => {
const currentMode = getThemeMode();
const newMode = currentMode === StyleMode.Night ? StyleMode.Light : StyleMode.Night;
setThemeMode(newMode);
return newMode;
};
const globalScripts = initialize;
var index$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
TIMEZONES: TIMEZONES,
areDatesValid: areDatesValid,
buildTimezoneByOffset: buildTimezoneByOffset,
calculateOffsetDate: calculateOffsetDate,
formatDate: formatDate,
formatDateTime: formatDateTime,
formatForTimezone: formatForTimezone,
formatTimezoneName: formatTimezoneName,
fromDateFields: fromDateFields,
fromDateInput: fromDateInput,
fromISO: fromISO,
getDateMonth: getDateMonth,
getDateYear: getDateYear,
getDatesBetweenRange: getDatesBetweenRange,
getDefaultTimezone: getDefaultTimezone,
getDefaultTimezoneSettings: getDefaultTimezoneSettings,
getFirstWeekdayIndexOfMonth: getFirstWeekdayIndexOfMonth,
getMonthAndYearTitle: getMonthAndYearTitle,
getMonthName: getMonthName,
getNumberOfDaysInMonth: getNumberOfDaysInMonth,
getTimezoneOffset: getTimezoneOffset,
getTimezonesNames: getTimezonesNames,
getWeekdaysNames: getWeekdaysNames,
isDateAfter: isDateAfter,
isDateBefore: isDateBefore,
isDateInArray: isDateInArray,
isDateInRange: isDateInRange,
isDateSame: isDateSame,
isDateTimeAfter: isDateTimeAfter,
isDateTimeBefore: isDateTimeBefore,
isDateValid: isDateValid,
newDate: newDate,
newTimezoneDate: newTimezoneDate,
newTimezoneDateFromFormat: newTimezoneDateFromFormat
});
const searchString = (searchTerm, searchOptions) => {
if (!searchTerm || searchTerm.length <= 0) {
return searchOptions;
}
// filter by search
const lowerCaseSearchTerm = searchTerm.toLowerCase();
return searchOptions.filter(option => option.label.toLowerCase().includes(lowerCaseSearchTerm));
};
var search_helper = /*#__PURE__*/Object.freeze({
__proto__: null,
searchString: searchString
});
const getRelativeTimeRangeName = (time) => ({
[ERelativeTimeRangeKey.Last_5_m]: 'Last 5 minutes',
[ERelativeTimeRangeKey.Last_10_m]: 'Last 10 minutes',
[ERelativeTimeRangeKey.Last_15_m]: 'Last 15 minutes',
[ERelativeTimeRangeKey.Last_30_m]: 'Last 30 minutes',
[ERelativeTimeRangeKey.Last_1_H]: 'Last 1 hour',
[ERelativeTimeRangeKey.Last_6_H]: 'Last 6 hours',
[ERelativeTimeRangeKey.Last_12_H]: 'Last 12 hours',
[ERelativeTimeRangeKey.Last_24_H]: 'Last 24 hours',
[ERelativeTimeRangeKey.Last_48_H]: 'Last 48 hours',
[ERelativeTimeRangeKey.Last_72_H]: 'Last 72 hours',
[ERelativeTimeRangeKey.Last_3_D]: 'Last 3 days',
[ERelativeTimeRangeKey.Last_7_D]: 'Last 7 days',
[ERelativeTimeRangeKey.Last_14_D]: 'Last 14 days',
[ERelativeTimeRangeKey.Last_30_D]: 'Last 30 days',
[ERelativeTimeRangeKey.Last_1_M]: 'Last 30 days',
[ERelativeTimeRangeKey.Last_90_D]: 'Last 90 days',
[ERelativeTimeRangeKey.Last_6_M]: 'Last 6 months',
[ERelativeTimeRangeKey.Last_365_D]: 'Last 365 days',
[ERelativeTimeRangeKey.Last_1_Y]: 'Last year',
[ERelativeTimeRangeKey.Last_2_Y]: 'Last 2 years',
[ERelativeTimeRangeKey.Last_5_Y]: 'Last 5 years',
[ERelativeTimeRangeKey.Next_5_M]: 'Next 5 minutes',
[ERelativeTimeRangeKey.Next_10_M]: 'Next 10 minutes',
[ERelativeTimeRangeKey.Next_15_M]: 'Next 15 minutes',
[ERelativeTimeRangeKey.Next_30_M]: 'Next 30 minutes',
[ERelativeTimeRangeKey.Next_1_H]: 'Next 1 hour',
[ERelativeTimeRangeKey.Next_6_H]: 'Next 6 hours',
[ERelativeTimeRangeKey.Next_12_H]: 'Next 12 hours',
[ERelativeTimeRangeKey.Next_24_H]: 'Next 24 hours',
[ERelativeTimeRangeKey.Next_48_H]: 'Next 48 hours',
[ERelativeTimeRangeKey.Next_72_H]: 'Next 72 hours',
[ERelativeTimeRangeKey.Next_7_D]: 'Next 7 days',
[ERelativeTimeRangeKey.Next_2_W]: 'Next 2 weeks',
[ERelativeTimeRangeKey.Next_1_M]: 'Next 30 days'
})[time];
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
CUSTOM_TIME_RANGE_KEY: CUSTOM_TIME_RANGE_KEY,
DEFAULT_RELATIVE_TIME_OPTIONS_GROUPS: DEFAULT_RELATIVE_TIME_OPTIONS_GROUPS,
get ERelativeTimeRangeKey () { return ERelativeTimeRangeKey; },
get EUnitReference () { return EUnitReference; },
RELATIVE_TIME_OFFSETS: RELATIVE_TIME_OFFSETS,
buildAbsoluteAmountOfUnitsConfigRange: buildAbsoluteAmountOfUnitsConfigRange,
buildDayjsRange: buildDayjsRange,
buildOptionRange: buildOptionRange,
buildRelativeAmountOfUnitsConfigRange: buildRelativeAmountOfUnitsConfigRange,
buildRelativeTimeOption: buildRelativeTimeOption,
buildSingleDateConfigRange: buildSingleDateConfigRange,
buildStartDateEndDateConfigRange: buildStartDateEndDateConfigRange,
buildTimestampRange: buildTimestampRange,
getAbsoluteTimeRange: getAbsoluteTimeRange,
getRelativeTimeCalculation: getRelativeTimeCalculation,
getRelativeTimeOption: getRelativeTimeOption,
getRelativeTimeRangeISO: getRelativeTimeRangeISO,
getRelativeTimeRangeName: getRelativeTimeRangeName,
getRelativeTimeRangeTimestamp: getRelativeTimeRangeTimestamp,
validateRelativeTimeOffsets: validateRelativeTimeOffsets
});
globalScripts();
export { CUSTOM_TIME_RANGE_KEY, DEFAULT_RELATIVE_TIME_OPTIONS_GROUPS, ERelativeTimeRangeKey, EUnitReference, RELATIVE_TIME_OFFSETS, StyleMode, TIMEZONES, areDatesValid, buildAbsoluteAmountOfUnitsConfigRange, buildDayjsRange, buildOptionRange, buildRelativeAmountOfUnitsConfigRange, buildRelativeTimeOption, buildSingleDateConfigRange, buildStartDateEndDateConfigRange, buildTimestampRange, buildTimezoneByOffset, calculateOffsetDate, index$1 as dateHelper, formatDate, formatDateTime, formatForTimezone, formatTimezoneName, fromDateFields, fromDateInput, fromISO, getAbsoluteTimeRange, getDateMonth, getDateYear, getDatesBetweenRange, getDefaultTimezone, getDefaultTimezoneSettings, getFirstWeekdayIndexOfMonth, getMonthAndYearTitle, getMonthName, getNumberOfDaysInMonth, getRelativeTimeCalculation, getRelativeTimeOption, getRelativeTimeRangeISO, getRelativeTimeRangeName, getRelativeTimeRangeTimestamp, getThemeMode, getTimezoneOffset, getTimezonesNames, getWeekdaysNames, initialize, isDateAfter, isDateBefore, isDateInArray, isDateInRange, isDateSame, isDateTimeAfter, isDateTimeBefore, isDateValid, newDate, newTimezoneDate, newTimezoneDateFromFormat, index as relativeTimeHelper, search_helper as searchHelper, searchString, setThemeMode, toggleThemeMode, validateRelativeTimeOffsets };