@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
109 lines (108 loc) • 5.5 kB
JavaScript
export function isUnsupportedColumnDataTypeForIconStyle(dataType) {
switch (dataType) {
case 'textArray':
case 'numberArray':
case 'tupleArray':
case 'objectArray':
return true;
default:
return false;
}
}
const flagEmoji = (countryCodeAlpha2) => {
const cc = countryCodeAlpha2.toUpperCase();
if (cc.length !== 2)
return cc;
const a = 0x1f1a5;
return String.fromCodePoint(a + cc.charCodeAt(0), a + cc.charCodeAt(1));
};
const FLAG_PRESET = [
{ Key: 'AU', Icon: flagEmoji('AU'), Description: 'Australia' },
{ Key: 'BE', Icon: flagEmoji('BE'), Description: 'Belgium' },
{ Key: 'CA', Icon: flagEmoji('CA'), Description: 'Canada' },
{ Key: 'CH', Icon: flagEmoji('CH'), Description: 'Switzerland' },
{ Key: 'CN', Icon: flagEmoji('CN'), Description: 'China' },
{ Key: 'DE', Icon: flagEmoji('DE'), Description: 'Germany' },
{ Key: 'ES', Icon: flagEmoji('ES'), Description: 'Spain' },
{ Key: 'FR', Icon: flagEmoji('FR'), Description: 'France' },
{ Key: 'GB', Icon: flagEmoji('GB'), Description: 'United Kingdom' },
{ Key: 'IE', Icon: flagEmoji('IE'), Description: 'Ireland' },
{ Key: 'IT', Icon: flagEmoji('IT'), Description: 'Italy' },
{ Key: 'JP', Icon: flagEmoji('JP'), Description: 'Japan' },
{ Key: 'NL', Icon: flagEmoji('NL'), Description: 'Netherlands' },
{ Key: 'PT', Icon: flagEmoji('PT'), Description: 'Portugal' },
{ Key: 'US', Icon: flagEmoji('US'), Description: 'United States' },
{ Key: 'Australia', Icon: flagEmoji('AU'), Description: 'Australia' },
{ Key: 'Belgium', Icon: flagEmoji('BE'), Description: 'Belgium' },
{ Key: 'Canada', Icon: flagEmoji('CA'), Description: 'Canada' },
{ Key: 'France', Icon: flagEmoji('FR'), Description: 'France' },
{ Key: 'Germany', Icon: flagEmoji('DE'), Description: 'Germany' },
{ Key: 'Italy', Icon: flagEmoji('IT'), Description: 'Italy' },
{ Key: 'Japan', Icon: flagEmoji('JP'), Description: 'Japan' },
{ Key: 'Spain', Icon: flagEmoji('ES'), Description: 'Spain' },
{ Key: 'Switzerland', Icon: flagEmoji('CH'), Description: 'Switzerland' },
{ Key: 'United Kingdom', Icon: flagEmoji('GB'), Description: 'United Kingdom' },
{ Key: 'United States', Icon: flagEmoji('US'), Description: 'United States' },
];
const CURRENCY_PRESET = [
{ Key: 'AUD', Icon: flagEmoji('AU'), Description: 'Australian Dollar' },
{ Key: 'CAD', Icon: flagEmoji('CA'), Description: 'Canadian Dollar' },
{ Key: 'CHF', Icon: flagEmoji('CH'), Description: 'Swiss Franc' },
{ Key: 'CNY', Icon: flagEmoji('CN'), Description: 'Chinese Yuan' },
{ Key: 'EUR', Icon: flagEmoji('EU'), Description: 'Euro' },
{ Key: 'GBP', Icon: flagEmoji('GB'), Description: 'British Pound' },
{ Key: 'HKD', Icon: flagEmoji('HK'), Description: 'Hong Kong Dollar' },
{ Key: 'INR', Icon: flagEmoji('IN'), Description: 'Indian Rupee' },
{ Key: 'JPY', Icon: flagEmoji('JP'), Description: 'Japanese Yen' },
{ Key: 'KRW', Icon: flagEmoji('KR'), Description: 'South Korean Won' },
{ Key: 'MXN', Icon: flagEmoji('MX'), Description: 'Mexican Peso' },
{ Key: 'NOK', Icon: flagEmoji('NO'), Description: 'Norwegian Krone' },
{ Key: 'NZD', Icon: flagEmoji('NZ'), Description: 'New Zealand Dollar' },
{ Key: 'RUB', Icon: flagEmoji('RU'), Description: 'Russian Ruble' },
{ Key: 'SEK', Icon: flagEmoji('SE'), Description: 'Swedish Krona' },
{ Key: 'SGD', Icon: flagEmoji('SG'), Description: 'Singapore Dollar' },
{ Key: 'TRY', Icon: flagEmoji('TR'), Description: 'Turkish Lira' },
{ Key: 'USD', Icon: flagEmoji('US'), Description: 'US Dollar' },
{ Key: 'ZAR', Icon: flagEmoji('ZA'), Description: 'South African Rand' },
];
const TREND_PRESET = [
{ Key: 'Up', Icon: '⬆', Description: 'Up' },
{ Key: 'Down', Icon: '⬇', Description: 'Down' },
{ Key: 'Flat', Icon: '➡', Description: 'Flat' },
{ Key: 'Buy', Icon: '⬆', Description: 'Buy' },
{ Key: 'Sell', Icon: '⬇', Description: 'Sell' },
{ Key: 'Hold', Icon: '➡', Description: 'Hold' },
{ Key: 'Long', Icon: '⬆', Description: 'Long' },
{ Key: 'Short', Icon: '⬇', Description: 'Short' },
];
const STATUS_PRESET = [
{ Key: 'Pass', Icon: '🟢', Description: 'Pass' },
{ Key: 'Warn', Icon: '🟡', Description: 'Warn' },
{ Key: 'Fail', Icon: '🔴', Description: 'Fail' },
{ Key: 'Completed', Icon: '🟢', Description: 'Completed' },
{ Key: 'In Progress', Icon: '🟡', Description: 'In Progress' },
{ Key: 'Pending', Icon: '🟡', Description: 'Pending' },
{ Key: 'Booked', Icon: '🟢', Description: 'Booked' },
{ Key: 'Rejected', Icon: '🔴', Description: 'Rejected' },
];
export const ICON_STYLE_PRESETS = {
Flags: FLAG_PRESET,
Currencies: CURRENCY_PRESET,
Trend: TREND_PRESET,
Status: STATUS_PRESET,
};
export const getIconStylePresetMappings = (preset) => {
return ICON_STYLE_PRESETS[preset].map((m) => ({ ...m }));
};
export const ICON_STYLE_PRESET_LABELS = {
Flags: 'Country Flags',
Currencies: 'Currencies',
Trend: 'Trend / Direction',
Status: 'Status',
};
export const ICON_STYLE_PRESET_DESCRIPTIONS = {
Flags: 'ISO country code or country name → flag emoji',
Currencies: 'ISO 4217 currency code → issuing country flag',
Trend: 'Up / Down / Flat (and Buy / Sell / Hold) → arrows',
Status: 'Pass / Warn / Fail (and common synonyms) → traffic light',
};