@pingux/astro 2.170.1-alpha.0 → 2.172.0-alpha.0
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/lib/cjs/components/Avatar/Avatar.js +13 -2
- package/lib/cjs/components/Avatar/Avatar.test.js +95 -1
- package/lib/cjs/components/Avatar/constants.d.ts +2 -0
- package/lib/cjs/components/Avatar/constants.js +8 -0
- package/lib/cjs/components/Avatar/getColorFromUuid.d.ts +2 -0
- package/lib/cjs/components/Avatar/getColorFromUuid.js +37 -0
- package/lib/cjs/components/Icon/Icon.js +15 -49
- package/lib/cjs/components/Icon/Icon.test.js +7 -36
- package/lib/cjs/components/Icon/IconDefault.d.ts +4 -0
- package/lib/cjs/components/Icon/IconDefault.js +63 -0
- package/lib/cjs/components/Icon/IconDefault.test.js +92 -0
- package/lib/cjs/components/Icon/IconSymbol.d.ts +4 -0
- package/lib/cjs/components/Icon/IconSymbol.js +60 -0
- package/lib/cjs/components/Icon/IconSymbol.mdx +46 -0
- package/lib/cjs/components/Icon/IconSymbol.test.js +80 -0
- package/lib/cjs/components/Icon/MaterialSymbolIcon.stories.d.ts +7 -0
- package/lib/cjs/components/Icon/MaterialSymbolIcon.stories.js +207 -0
- package/lib/cjs/hooks/useGetTheme/useGetTheme.d.ts +31 -31
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/customProperties/icons.d.ts +31 -31
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/customProperties/index.d.ts +31 -31
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/variants.d.ts +18 -20
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/variants.js +18 -20
- package/lib/cjs/styles/themeOverrides/onyxSideNav.d.ts +32 -29
- package/lib/cjs/styles/themeOverrides/onyxSideNav.js +3 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.d.ts +1 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +3 -2
- package/lib/cjs/styles/themes/next-gen/customProperties/icons.d.ts +32 -32
- package/lib/cjs/styles/themes/next-gen/customProperties/icons.js +1 -32
- package/lib/cjs/styles/themes/next-gen/customProperties/index.d.ts +32 -32
- package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +60 -56
- package/lib/cjs/styles/themes/next-gen/variants/variants.d.ts +28 -24
- package/lib/cjs/styles/themes/next-gen/variants/variants.js +28 -24
- package/lib/cjs/types/avatar.d.ts +2 -0
- package/lib/cjs/types/icon.d.ts +3 -1
- package/lib/cjs/types/navBar.d.ts +2 -1
- package/lib/components/Avatar/Avatar.js +14 -3
- package/lib/components/Avatar/Avatar.test.js +95 -1
- package/lib/components/Avatar/constants.js +2 -0
- package/lib/components/Avatar/getColorFromUuid.js +29 -0
- package/lib/components/Icon/Icon.js +11 -47
- package/lib/components/Icon/Icon.test.js +5 -34
- package/lib/components/Icon/IconDefault.js +53 -0
- package/lib/components/Icon/IconDefault.test.js +84 -0
- package/lib/components/Icon/IconSymbol.js +50 -0
- package/lib/components/Icon/IconSymbol.mdx +46 -0
- package/lib/components/Icon/IconSymbol.test.js +77 -0
- package/lib/components/Icon/MaterialSymbolIcon.stories.js +200 -0
- package/lib/index.js +1 -1
- package/lib/styles/themeOverrides/nextGenDarkMode/variants/variants.js +18 -20
- package/lib/styles/themeOverrides/onyxSideNav.js +3 -0
- package/lib/styles/themes/next-gen/convertedComponentList.js +3 -2
- package/lib/styles/themes/next-gen/customProperties/icons.js +1 -32
- package/lib/styles/themes/next-gen/variants/variants.js +28 -24
- package/lib/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -2
|
@@ -3084,47 +3084,47 @@ declare const _default: {
|
|
|
3084
3084
|
};
|
|
3085
3085
|
};
|
|
3086
3086
|
icons: {
|
|
3087
|
-
[x: number]:
|
|
3087
|
+
[x: number]: string;
|
|
3088
3088
|
aic: (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
3089
|
-
applicationsIcon:
|
|
3090
|
-
Ascending:
|
|
3091
|
-
authenticationIcon:
|
|
3092
|
-
clipboard:
|
|
3093
|
-
CreateIcon:
|
|
3094
|
-
daVinci:
|
|
3095
|
-
DefaultCircle:
|
|
3096
|
-
Descending:
|
|
3097
|
-
popoverMenuIcon:
|
|
3098
|
-
ErrorCircle:
|
|
3099
|
-
integrationsIcon:
|
|
3100
|
-
listViewMenu:
|
|
3101
|
-
mdiAccountCog:
|
|
3102
|
-
mdiAccountMultiple:
|
|
3089
|
+
applicationsIcon: string;
|
|
3090
|
+
Ascending: string;
|
|
3091
|
+
authenticationIcon: string;
|
|
3092
|
+
clipboard: string;
|
|
3093
|
+
CreateIcon: string;
|
|
3094
|
+
daVinci: string;
|
|
3095
|
+
DefaultCircle: string;
|
|
3096
|
+
Descending: string;
|
|
3097
|
+
popoverMenuIcon: string;
|
|
3098
|
+
ErrorCircle: string;
|
|
3099
|
+
integrationsIcon: string;
|
|
3100
|
+
listViewMenu: string;
|
|
3101
|
+
mdiAccountCog: string;
|
|
3102
|
+
mdiAccountMultiple: string;
|
|
3103
3103
|
mdiEarth: import("@pingux/mdi-react").MdiReactIconComponentType;
|
|
3104
3104
|
mdiEmoticonHappyOutline: import("@pingux/mdi-react").MdiReactIconComponentType;
|
|
3105
|
-
mdiFingerprint:
|
|
3106
|
-
mdiPlayCircleIcon:
|
|
3107
|
-
mdiScaleBalance:
|
|
3108
|
-
mdiShoCard:
|
|
3105
|
+
mdiFingerprint: string;
|
|
3106
|
+
mdiPlayCircleIcon: string;
|
|
3107
|
+
mdiScaleBalance: string;
|
|
3108
|
+
mdiShoCard: string;
|
|
3109
3109
|
mdiTransitConnectionVariant: import("@pingux/mdi-react").MdiReactIconComponentType;
|
|
3110
|
-
mdiViewDashboard:
|
|
3111
|
-
mdiWeb:
|
|
3112
|
-
MenuDown:
|
|
3113
|
-
MenuUp:
|
|
3110
|
+
mdiViewDashboard: string;
|
|
3111
|
+
mdiWeb: string;
|
|
3112
|
+
MenuDown: string;
|
|
3113
|
+
MenuUp: string;
|
|
3114
3114
|
monitoringIcon: import("@pingux/mdi-react").MdiReactIconComponentType;
|
|
3115
|
-
openInNew:
|
|
3116
|
-
overviewIcon:
|
|
3117
|
-
p1verify:
|
|
3115
|
+
openInNew: string;
|
|
3116
|
+
overviewIcon: string;
|
|
3117
|
+
p1verify: string;
|
|
3118
3118
|
pam: (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
3119
|
-
PingAuthorize:
|
|
3119
|
+
PingAuthorize: string;
|
|
3120
3120
|
pingLogoHorizontalSmall: import("react/jsx-runtime").JSX.Element;
|
|
3121
3121
|
protect: (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
3122
|
-
rocketLaunchIcon:
|
|
3123
|
-
shareFeedbackIcon:
|
|
3122
|
+
rocketLaunchIcon: string;
|
|
3123
|
+
shareFeedbackIcon: string;
|
|
3124
3124
|
shieldStar: import("@pingux/mdi-react").MdiReactIconComponentType;
|
|
3125
|
-
SuccessCircle:
|
|
3126
|
-
userExperienceIcon:
|
|
3127
|
-
WarningIcon:
|
|
3125
|
+
SuccessCircle: string;
|
|
3126
|
+
userExperienceIcon: string;
|
|
3127
|
+
WarningIcon: string;
|
|
3128
3128
|
};
|
|
3129
3129
|
fonts: {
|
|
3130
3130
|
standard: string;
|
|
@@ -6206,10 +6206,8 @@ declare const _default: {
|
|
|
6206
6206
|
backgroundColor: string;
|
|
6207
6207
|
'& > div.status-icon': {
|
|
6208
6208
|
bg: string;
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
fill: string;
|
|
6212
|
-
};
|
|
6209
|
+
span: {
|
|
6210
|
+
color: string;
|
|
6213
6211
|
};
|
|
6214
6212
|
};
|
|
6215
6213
|
};
|
|
@@ -6452,58 +6450,64 @@ declare const _default: {
|
|
|
6452
6450
|
base: {
|
|
6453
6451
|
'&.is-default': {
|
|
6454
6452
|
bg: string;
|
|
6455
|
-
|
|
6456
|
-
|
|
6453
|
+
span: {
|
|
6454
|
+
fontSize: string;
|
|
6455
|
+
color: string;
|
|
6457
6456
|
};
|
|
6458
6457
|
};
|
|
6459
6458
|
'&.is-critical': {
|
|
6460
6459
|
bg: string;
|
|
6461
|
-
|
|
6462
|
-
|
|
6460
|
+
span: {
|
|
6461
|
+
fontSize: string;
|
|
6462
|
+
color: string;
|
|
6463
6463
|
};
|
|
6464
6464
|
};
|
|
6465
6465
|
'&.is-warning': {
|
|
6466
6466
|
bg: string;
|
|
6467
|
-
|
|
6468
|
-
|
|
6467
|
+
span: {
|
|
6468
|
+
fontSize: string;
|
|
6469
|
+
color: string;
|
|
6469
6470
|
};
|
|
6470
6471
|
};
|
|
6471
6472
|
'&.is-info': {
|
|
6472
6473
|
bg: string;
|
|
6473
|
-
|
|
6474
|
-
|
|
6474
|
+
span: {
|
|
6475
|
+
fontSize: string;
|
|
6476
|
+
color: string;
|
|
6475
6477
|
};
|
|
6476
6478
|
};
|
|
6477
6479
|
'&.is-major': {
|
|
6478
6480
|
bg: string;
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
+
span: {
|
|
6482
|
+
fontSize: string;
|
|
6483
|
+
color: string;
|
|
6481
6484
|
};
|
|
6482
6485
|
};
|
|
6483
6486
|
'&.is-minor': {
|
|
6484
6487
|
bg: string;
|
|
6485
|
-
|
|
6486
|
-
|
|
6488
|
+
span: {
|
|
6489
|
+
fontSize: string;
|
|
6490
|
+
color: string;
|
|
6487
6491
|
};
|
|
6488
6492
|
};
|
|
6489
6493
|
'&.is-warning-neutral': {
|
|
6490
6494
|
bg: string;
|
|
6491
|
-
|
|
6492
|
-
|
|
6495
|
+
span: {
|
|
6496
|
+
fontSize: string;
|
|
6497
|
+
color: string;
|
|
6493
6498
|
};
|
|
6494
6499
|
};
|
|
6495
6500
|
'&.is-fatal': {
|
|
6496
6501
|
bg: string;
|
|
6497
|
-
|
|
6498
|
-
|
|
6502
|
+
span: {
|
|
6503
|
+
fontSize: string;
|
|
6504
|
+
color: string;
|
|
6499
6505
|
};
|
|
6500
6506
|
};
|
|
6501
6507
|
'&.is-selected.is-selected': {
|
|
6502
6508
|
bg: string;
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
fill: string;
|
|
6506
|
-
};
|
|
6509
|
+
span: {
|
|
6510
|
+
color: string;
|
|
6507
6511
|
};
|
|
6508
6512
|
};
|
|
6509
6513
|
};
|
|
@@ -1593,10 +1593,8 @@ declare const _default: {
|
|
|
1593
1593
|
backgroundColor: string;
|
|
1594
1594
|
'& > div.status-icon': {
|
|
1595
1595
|
bg: string;
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
fill: string;
|
|
1599
|
-
};
|
|
1596
|
+
span: {
|
|
1597
|
+
color: string;
|
|
1600
1598
|
};
|
|
1601
1599
|
};
|
|
1602
1600
|
};
|
|
@@ -1839,58 +1837,64 @@ declare const _default: {
|
|
|
1839
1837
|
base: {
|
|
1840
1838
|
'&.is-default': {
|
|
1841
1839
|
bg: string;
|
|
1842
|
-
|
|
1843
|
-
|
|
1840
|
+
span: {
|
|
1841
|
+
fontSize: string;
|
|
1842
|
+
color: string;
|
|
1844
1843
|
};
|
|
1845
1844
|
};
|
|
1846
1845
|
'&.is-critical': {
|
|
1847
1846
|
bg: string;
|
|
1848
|
-
|
|
1849
|
-
|
|
1847
|
+
span: {
|
|
1848
|
+
fontSize: string;
|
|
1849
|
+
color: string;
|
|
1850
1850
|
};
|
|
1851
1851
|
};
|
|
1852
1852
|
'&.is-warning': {
|
|
1853
1853
|
bg: string;
|
|
1854
|
-
|
|
1855
|
-
|
|
1854
|
+
span: {
|
|
1855
|
+
fontSize: string;
|
|
1856
|
+
color: string;
|
|
1856
1857
|
};
|
|
1857
1858
|
};
|
|
1858
1859
|
'&.is-info': {
|
|
1859
1860
|
bg: string;
|
|
1860
|
-
|
|
1861
|
-
|
|
1861
|
+
span: {
|
|
1862
|
+
fontSize: string;
|
|
1863
|
+
color: string;
|
|
1862
1864
|
};
|
|
1863
1865
|
};
|
|
1864
1866
|
'&.is-major': {
|
|
1865
1867
|
bg: string;
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
+
span: {
|
|
1869
|
+
fontSize: string;
|
|
1870
|
+
color: string;
|
|
1868
1871
|
};
|
|
1869
1872
|
};
|
|
1870
1873
|
'&.is-minor': {
|
|
1871
1874
|
bg: string;
|
|
1872
|
-
|
|
1873
|
-
|
|
1875
|
+
span: {
|
|
1876
|
+
fontSize: string;
|
|
1877
|
+
color: string;
|
|
1874
1878
|
};
|
|
1875
1879
|
};
|
|
1876
1880
|
'&.is-warning-neutral': {
|
|
1877
1881
|
bg: string;
|
|
1878
|
-
|
|
1879
|
-
|
|
1882
|
+
span: {
|
|
1883
|
+
fontSize: string;
|
|
1884
|
+
color: string;
|
|
1880
1885
|
};
|
|
1881
1886
|
};
|
|
1882
1887
|
'&.is-fatal': {
|
|
1883
1888
|
bg: string;
|
|
1884
|
-
|
|
1885
|
-
|
|
1889
|
+
span: {
|
|
1890
|
+
fontSize: string;
|
|
1891
|
+
color: string;
|
|
1886
1892
|
};
|
|
1887
1893
|
};
|
|
1888
1894
|
'&.is-selected.is-selected': {
|
|
1889
1895
|
bg: string;
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
fill: string;
|
|
1893
|
-
};
|
|
1896
|
+
span: {
|
|
1897
|
+
color: string;
|
|
1894
1898
|
};
|
|
1895
1899
|
};
|
|
1896
1900
|
};
|
|
@@ -326,10 +326,8 @@ var rockerButton = {
|
|
|
326
326
|
backgroundColor: 'active',
|
|
327
327
|
'& > div.status-icon': {
|
|
328
328
|
bg: 'white',
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
fill: 'active'
|
|
332
|
-
}
|
|
329
|
+
span: {
|
|
330
|
+
color: 'active'
|
|
333
331
|
}
|
|
334
332
|
}
|
|
335
333
|
},
|
|
@@ -368,58 +366,64 @@ var statusIcon = {
|
|
|
368
366
|
base: {
|
|
369
367
|
'&.is-default': {
|
|
370
368
|
bg: 'gray-100',
|
|
371
|
-
|
|
372
|
-
|
|
369
|
+
span: {
|
|
370
|
+
fontSize: 'md',
|
|
371
|
+
color: 'gray-700'
|
|
373
372
|
}
|
|
374
373
|
},
|
|
375
374
|
'&.is-critical': {
|
|
376
375
|
bg: 'red-100',
|
|
377
|
-
|
|
378
|
-
|
|
376
|
+
span: {
|
|
377
|
+
fontSize: 'md',
|
|
378
|
+
color: 'red-700'
|
|
379
379
|
}
|
|
380
380
|
},
|
|
381
381
|
'&.is-warning': {
|
|
382
382
|
bg: 'yellow-100',
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
span: {
|
|
384
|
+
fontSize: 'md',
|
|
385
|
+
color: 'yellow-800'
|
|
385
386
|
}
|
|
386
387
|
},
|
|
387
388
|
'&.is-info': {
|
|
388
389
|
bg: 'blue-100',
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
span: {
|
|
391
|
+
fontSize: 'md',
|
|
392
|
+
color: 'blue-600'
|
|
391
393
|
}
|
|
392
394
|
},
|
|
393
395
|
'&.is-major': {
|
|
394
396
|
bg: 'orange-100',
|
|
395
|
-
|
|
396
|
-
|
|
397
|
+
span: {
|
|
398
|
+
fontSize: 'md',
|
|
399
|
+
color: 'orange-700'
|
|
397
400
|
}
|
|
398
401
|
},
|
|
399
402
|
'&.is-minor': {
|
|
400
403
|
bg: 'yellow-100',
|
|
401
|
-
|
|
402
|
-
|
|
404
|
+
span: {
|
|
405
|
+
fontSize: 'md',
|
|
406
|
+
color: 'yellow-800'
|
|
403
407
|
}
|
|
404
408
|
},
|
|
405
409
|
'&.is-warning-neutral': {
|
|
406
410
|
bg: 'gray-100',
|
|
407
|
-
|
|
408
|
-
|
|
411
|
+
span: {
|
|
412
|
+
fontSize: 'md',
|
|
413
|
+
color: 'gray-700'
|
|
409
414
|
}
|
|
410
415
|
},
|
|
411
416
|
'&.is-fatal': {
|
|
412
417
|
bg: 'gray-700',
|
|
413
|
-
|
|
414
|
-
|
|
418
|
+
span: {
|
|
419
|
+
fontSize: 'md',
|
|
420
|
+
color: 'gray-100'
|
|
415
421
|
}
|
|
416
422
|
},
|
|
417
423
|
'&.is-selected.is-selected': {
|
|
418
424
|
bg: 'white',
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
fill: 'active'
|
|
422
|
-
}
|
|
425
|
+
span: {
|
|
426
|
+
color: 'active'
|
|
423
427
|
}
|
|
424
428
|
}
|
|
425
429
|
}
|
package/lib/cjs/types/icon.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import type { MaterialSymbol } from '@material-symbols/font-400';
|
|
2
3
|
import { TestingAttributes } from './shared/test';
|
|
3
4
|
import { DOMAttributes, IconSize, StyleProps } from './shared';
|
|
4
5
|
export type SVGComponentProps = {
|
|
@@ -23,8 +24,9 @@ export interface IconProps extends StyleProps, DOMAttributes, TestingAttributes
|
|
|
23
24
|
name: string;
|
|
24
25
|
};
|
|
25
26
|
/** The icon to render. */
|
|
26
|
-
icon?: IconTypeExtended;
|
|
27
|
+
icon?: IconTypeExtended | MaterialSymbol | string;
|
|
27
28
|
size?: IconSize;
|
|
28
29
|
/** A theme-aware prop to set the icon's color. */
|
|
29
30
|
color?: string;
|
|
31
|
+
hasFill?: boolean;
|
|
30
32
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { Key } from 'react';
|
|
2
|
+
import type { MaterialSymbol } from '@material-symbols/font-400';
|
|
2
3
|
import { ThemeUICSSObject } from 'theme-ui';
|
|
3
4
|
import { IconProps, IconTypeExtended } from './icon';
|
|
4
5
|
import { DOMAttributes, StyleProps } from './shared';
|
|
@@ -27,7 +28,7 @@ export interface NavBarItemProps extends StyleProps, DOMAttributes {
|
|
|
27
28
|
/** Handler that is called when the press is released over the target. */
|
|
28
29
|
onPress?: () => void;
|
|
29
30
|
/** The icon to render in between each node. */
|
|
30
|
-
icon?: IconTypeExtended;
|
|
31
|
+
icon?: IconTypeExtended | MaterialSymbol | string;
|
|
31
32
|
/** The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */
|
|
32
33
|
id?: string;
|
|
33
34
|
/** Text that will render within the component */
|
|
@@ -9,12 +9,14 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
12
|
-
var _excluded = ["alt", "defaultText", "color", "className", "size", "src", "sx", "children", "isSquare", "isLogo"];
|
|
12
|
+
var _excluded = ["alt", "defaultText", "color", "colorId", "className", "size", "src", "sx", "children", "isSquare", "isLogo"];
|
|
13
13
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
-
import React, { forwardRef } from 'react';
|
|
15
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
16
16
|
import { Avatar as ThemeUIAvatar, Box } from 'theme-ui';
|
|
17
17
|
import { useStatusClasses } from '../../hooks';
|
|
18
|
+
import { avatarColors } from './constants';
|
|
19
|
+
import getColorFromUUID from './getColorFromUuid';
|
|
18
20
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
19
21
|
var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
20
22
|
var _props$alt = props.alt,
|
|
@@ -22,6 +24,7 @@ var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
22
24
|
_props$defaultText = props.defaultText,
|
|
23
25
|
defaultText = _props$defaultText === void 0 ? 'AA' : _props$defaultText,
|
|
24
26
|
color = props.color,
|
|
27
|
+
colorId = props.colorId,
|
|
25
28
|
className = props.className,
|
|
26
29
|
_props$size = props.size,
|
|
27
30
|
size = _props$size === void 0 ? 'sm' : _props$size,
|
|
@@ -31,7 +34,15 @@ var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
31
34
|
isSquare = props.isSquare,
|
|
32
35
|
isLogo = props.isLogo,
|
|
33
36
|
others = _objectWithoutProperties(props, _excluded);
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
// this will use color prop if provided,
|
|
39
|
+
// else will map colorId to a color, else defaults to 'green'
|
|
40
|
+
var finalColor = useMemo(function () {
|
|
41
|
+
if (color) return color;
|
|
42
|
+
if (colorId) return getColorFromUUID(colorId, avatarColors);
|
|
43
|
+
return 'green';
|
|
44
|
+
}, [color, colorId, avatarColors]);
|
|
45
|
+
var _useStatusClasses = useStatusClasses(className, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "is-".concat(finalColor), finalColor), "size-".concat(size), size), "font-size-".concat(size), src ? false : size), 'is-square', isSquare), 'is-image', src), 'is-logo', isLogo)),
|
|
35
46
|
classNames = _useStatusClasses.classNames;
|
|
36
47
|
if (src) {
|
|
37
48
|
return ___EmotionJSX(Box, _extends({
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
2
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
3
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
4
|
+
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
2
6
|
import React from 'react';
|
|
3
7
|
import { faker } from '@faker-js/faker';
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
4
9
|
import { render, screen } from '../../utils/testUtils/testWrapper';
|
|
5
10
|
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
|
11
|
+
import { avatarColors as colors } from './constants';
|
|
12
|
+
import getColorFromUUID from './getColorFromUuid';
|
|
6
13
|
import Avatar from '.';
|
|
7
14
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
8
15
|
var src = faker.image.lorempicsum.imageUrl(150, 150, false, undefined, '1');
|
|
16
|
+
var datatestId = 'avatar-component';
|
|
9
17
|
var defaultProps = {
|
|
10
|
-
src: src
|
|
18
|
+
src: src,
|
|
19
|
+
'data-testid': datatestId
|
|
11
20
|
};
|
|
12
21
|
var getComponent = function getComponent() {
|
|
13
22
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -40,4 +49,89 @@ test('an avatar is rendered with custom alt', function () {
|
|
|
40
49
|
});
|
|
41
50
|
var avatar = screen.getByText('KL');
|
|
42
51
|
expect(avatar).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
describe('getColorFromUUID', function () {
|
|
54
|
+
test('returns a consistent color for the same UUID', function () {
|
|
55
|
+
var uuid = '123e4567-e89b-12d3-a456-426614174000';
|
|
56
|
+
var result1 = getColorFromUUID(uuid, colors);
|
|
57
|
+
var result2 = getColorFromUUID(uuid, colors);
|
|
58
|
+
expect(result1).toBe(result2);
|
|
59
|
+
});
|
|
60
|
+
test('returns a color from the provided array', function () {
|
|
61
|
+
var uuid = 'random-id';
|
|
62
|
+
var result = getColorFromUUID(uuid, colors);
|
|
63
|
+
expect(colors).toContain(result);
|
|
64
|
+
});
|
|
65
|
+
test('distributes colors differently for different UUIDs', function () {
|
|
66
|
+
var colorA = getColorFromUUID('id-1', colors);
|
|
67
|
+
var colorB = getColorFromUUID('id-2', colors);
|
|
68
|
+
|
|
69
|
+
// While collisions are mathematically possible, for 2 items in a 10-item list,
|
|
70
|
+
// these specific IDs yield different results in FNV-1a.
|
|
71
|
+
expect(colorA).not.toBe(colorB);
|
|
72
|
+
});
|
|
73
|
+
test('throws error if color array is empty', function () {
|
|
74
|
+
expect(function () {
|
|
75
|
+
return getColorFromUUID('uuid', []);
|
|
76
|
+
}).toThrow('Color array cannot be empty.');
|
|
77
|
+
});
|
|
78
|
+
test('uses the specific color class when color prop is provided', function () {
|
|
79
|
+
getComponent({
|
|
80
|
+
color: 'blue',
|
|
81
|
+
colorId: 'some-id'
|
|
82
|
+
});
|
|
83
|
+
var avatar = screen.getByTestId(datatestId);
|
|
84
|
+
|
|
85
|
+
// Checking for 'is-blue'
|
|
86
|
+
expect(avatar).toHaveClass('is-blue');
|
|
87
|
+
});
|
|
88
|
+
test('applies a hashed color class from colorId', function () {
|
|
89
|
+
var uuid = '550e8400-e29b-41d4-a716-446655440000';
|
|
90
|
+
getComponent({
|
|
91
|
+
colorId: uuid
|
|
92
|
+
});
|
|
93
|
+
var avatar = screen.getByTestId(datatestId);
|
|
94
|
+
|
|
95
|
+
// We check that it has *a* class starting with 'is-'
|
|
96
|
+
// and specifically isn't the default 'is-green'
|
|
97
|
+
var classList = _Array$from(avatar.classList);
|
|
98
|
+
var colorClass = _findInstanceProperty(classList).call(classList, function (cls) {
|
|
99
|
+
return _startsWithInstanceProperty(cls).call(cls, 'is-');
|
|
100
|
+
});
|
|
101
|
+
expect(colorClass).toBeDefined();
|
|
102
|
+
expect(avatar).not.toHaveClass('is-green');
|
|
103
|
+
});
|
|
104
|
+
test('defaults to is-green when no color props are passed', function () {
|
|
105
|
+
getComponent();
|
|
106
|
+
var avatar = screen.getByTestId(datatestId);
|
|
107
|
+
expect(avatar).toHaveClass('is-green');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('getColorFromUUID Distribution', function () {
|
|
111
|
+
test('distributes 10,000 UUIDs evenly across 10 colors', function () {
|
|
112
|
+
var iterations = 10000;
|
|
113
|
+
var distribution = {};
|
|
114
|
+
|
|
115
|
+
// Initialize counts
|
|
116
|
+
_forEachInstanceProperty(colors).call(colors, function (c) {
|
|
117
|
+
distribution[c] = 0;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Generate and hash
|
|
121
|
+
for (var i = 0; i < iterations; i += 1) {
|
|
122
|
+
// Use the imported randomUUID function directly
|
|
123
|
+
var uuid = randomUUID();
|
|
124
|
+
var selectedColor = getColorFromUUID(uuid, colors);
|
|
125
|
+
distribution[selectedColor] += 1;
|
|
126
|
+
}
|
|
127
|
+
var expectedMean = iterations / colors.length;
|
|
128
|
+
// 15% variance is a safe threshold for 10k iterations
|
|
129
|
+
var allowedVariance = 0.15;
|
|
130
|
+
_forEachInstanceProperty(colors).call(colors, function (color) {
|
|
131
|
+
var count = distribution[color];
|
|
132
|
+
// Assert that each color is roughly 10% of the total
|
|
133
|
+
expect(count).toBeGreaterThan(expectedMean * (1 - allowedVariance));
|
|
134
|
+
expect(count).toBeLessThan(expectedMean * (1 + allowedVariance));
|
|
135
|
+
});
|
|
136
|
+
});
|
|
43
137
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _Math$imul from "@babel/runtime-corejs3/core-js-stable/math/imul";
|
|
2
|
+
// * Maps a UUID to a specific color from a provided array.
|
|
3
|
+
// * @param uuid - The unique identifier string.
|
|
4
|
+
// * @param colors - An array of color strings/objects.
|
|
5
|
+
// * @returns A single color from the array.
|
|
6
|
+
|
|
7
|
+
var getColorFromUUID = function getColorFromUUID(uuid, colors) {
|
|
8
|
+
if (colors.length === 0) {
|
|
9
|
+
throw new Error('Color array cannot be empty.');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// FNV-1a Hash implementation
|
|
13
|
+
// This spreads the bits of the UUID string evenly across a 32-bit integer
|
|
14
|
+
var hash = 2166136261;
|
|
15
|
+
for (var i = 0; i < uuid.length; i += 1) {
|
|
16
|
+
/* eslint-disable no-bitwise */
|
|
17
|
+
hash ^= uuid.charCodeAt(i);
|
|
18
|
+
// Standard FNV prime (using Math.imul for 32-bit integer multiplication)
|
|
19
|
+
|
|
20
|
+
hash = _Math$imul(hash, 16777619);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Convert to an unsigned index using the modulo operator
|
|
24
|
+
// The >>> 0 ensures we are dealing with an unsigned 32-bit integer
|
|
25
|
+
/* eslint-disable no-bitwise */
|
|
26
|
+
var index = (hash >>> 0) % colors.length;
|
|
27
|
+
return colors[index];
|
|
28
|
+
};
|
|
29
|
+
export default getColorFromUUID;
|