@transferwise/components 46.123.0 → 46.124.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.
@@ -4,12 +4,16 @@ function startsWithParenthesis(part) {
4
4
  return /^[({[<]/.test(part);
5
5
  }
6
6
  // Reuse a single Intl.Segmenter instance to avoid repeated allocations
7
- const GRAPHEME_SEGMENTER = new Intl.Segmenter('en', {
7
+ const GRAPHEME_SEGMENTER = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter('en', {
8
8
  granularity: 'grapheme'
9
- });
9
+ }) : undefined;
10
10
  // Helper to split the string into grapheme clusters, which handles complex characters correctly
11
11
  function getGraphemes(str) {
12
- return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
12
+ if (GRAPHEME_SEGMENTER) {
13
+ return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
14
+ }
15
+ // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
16
+ return Array.from(str);
13
17
  }
14
18
  function getInitials(name) {
15
19
  if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {
@@ -1 +1 @@
1
- {"version":3,"file":"initials.js","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER = new Intl.Segmenter('en', { granularity: 'grapheme' });\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase","graphemes"],"mappings":";;AAAA,SAASA,qBAAqBA,CAACC,IAAY,EAAA;AACzC,EAAA,OAAO,SAAS,CAACC,IAAI,CAACD,IAAI,CAAC;AAC7B;AAEA;AACA,MAAME,kBAAkB,GAAG,IAAIC,IAAI,CAACC,SAAS,CAAC,IAAI,EAAE;AAAEC,EAAAA,WAAW,EAAE;AAAU,CAAE,CAAC;AAEhF;AACA,SAASC,YAAYA,CAACC,GAAW,EAAA;AAC/B,EAAA,OAAOC,KAAK,CAACC,IAAI,CAACP,kBAAkB,CAACQ,OAAO,CAACH,GAAG,CAAC,EAAGI,CAAC,IAAKA,CAAC,CAACD,OAAO,CAAC;AACtE;AAEM,SAAUE,WAAWA,CAACC,IAAY,EAAA;AACtC,EAAA,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,IAAI,YAAY,CAACb,IAAI,CAACY,IAAI,CAAC,EAAE;AAChD,IAAA,OAAOA,IAAI;AACb,EAAA;AAEA,EAAA,MAAME,WAAW,GAAGF,IAAI,CACrBG,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAEjB,IAAI,IAAK,CAACD,qBAAqB,CAACC,IAAI,CAAC,CAAC,CAC9CkB,GAAG,CAAElB,IAAI,IAAKM,YAAY,CAACN,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CACpCmB,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE;AAEhB;AACA,EAAA,MAAMC,SAAS,GAAGf,YAAY,CAACS,WAAW,CAAC;AAE3C,EAAA,IAAIM,SAAS,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAOO,SAAS,CAAC,CAAC,CAAC;AACrB,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAC,CAAC,CAAC,GAAGA,SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
1
+ {"version":3,"file":"initials.js","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter('en', { granularity: 'grapheme' })\n : undefined;\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n if (GRAPHEME_SEGMENTER) {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n }\n // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)\n return Array.from(str);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","undefined","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase","graphemes"],"mappings":";;AAAA,SAASA,qBAAqBA,CAACC,IAAY,EAAA;AACzC,EAAA,OAAO,SAAS,CAACC,IAAI,CAACD,IAAI,CAAC;AAC7B;AAEA;AACA,MAAME,kBAAkB,GACtB,OAAOC,IAAI,CAACC,SAAS,KAAK,UAAU,GAChC,IAAID,IAAI,CAACC,SAAS,CAAC,IAAI,EAAE;AAAEC,EAAAA,WAAW,EAAE;CAAY,CAAC,GACrDC,SAAS;AAEf;AACA,SAASC,YAAYA,CAACC,GAAW,EAAA;AAC/B,EAAA,IAAIN,kBAAkB,EAAE;AACtB,IAAA,OAAOO,KAAK,CAACC,IAAI,CAACR,kBAAkB,CAACS,OAAO,CAACH,GAAG,CAAC,EAAGI,CAAC,IAAKA,CAAC,CAACD,OAAO,CAAC;AACtE,EAAA;AACA;AACA,EAAA,OAAOF,KAAK,CAACC,IAAI,CAACF,GAAG,CAAC;AACxB;AAEM,SAAUK,WAAWA,CAACC,IAAY,EAAA;AACtC,EAAA,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,IAAI,YAAY,CAACd,IAAI,CAACa,IAAI,CAAC,EAAE;AAChD,IAAA,OAAOA,IAAI;AACb,EAAA;AAEA,EAAA,MAAME,WAAW,GAAGF,IAAI,CACrBG,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAElB,IAAI,IAAK,CAACD,qBAAqB,CAACC,IAAI,CAAC,CAAC,CAC9CmB,GAAG,CAAEnB,IAAI,IAAKO,YAAY,CAACP,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CACpCoB,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE;AAEhB;AACA,EAAA,MAAMC,SAAS,GAAGf,YAAY,CAACS,WAAW,CAAC;AAE3C,EAAA,IAAIM,SAAS,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAOO,SAAS,CAAC,CAAC,CAAC;AACrB,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAC,CAAC,CAAC,GAAGA,SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
@@ -2,12 +2,16 @@ function startsWithParenthesis(part) {
2
2
  return /^[({[<]/.test(part);
3
3
  }
4
4
  // Reuse a single Intl.Segmenter instance to avoid repeated allocations
5
- const GRAPHEME_SEGMENTER = new Intl.Segmenter('en', {
5
+ const GRAPHEME_SEGMENTER = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter('en', {
6
6
  granularity: 'grapheme'
7
- });
7
+ }) : undefined;
8
8
  // Helper to split the string into grapheme clusters, which handles complex characters correctly
9
9
  function getGraphemes(str) {
10
- return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
10
+ if (GRAPHEME_SEGMENTER) {
11
+ return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
12
+ }
13
+ // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
14
+ return Array.from(str);
11
15
  }
12
16
  function getInitials(name) {
13
17
  if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {
@@ -1 +1 @@
1
- {"version":3,"file":"initials.mjs","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER = new Intl.Segmenter('en', { granularity: 'grapheme' });\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase","graphemes"],"mappings":"AAAA,SAASA,qBAAqBA,CAACC,IAAY,EAAA;AACzC,EAAA,OAAO,SAAS,CAACC,IAAI,CAACD,IAAI,CAAC;AAC7B;AAEA;AACA,MAAME,kBAAkB,GAAG,IAAIC,IAAI,CAACC,SAAS,CAAC,IAAI,EAAE;AAAEC,EAAAA,WAAW,EAAE;AAAU,CAAE,CAAC;AAEhF;AACA,SAASC,YAAYA,CAACC,GAAW,EAAA;AAC/B,EAAA,OAAOC,KAAK,CAACC,IAAI,CAACP,kBAAkB,CAACQ,OAAO,CAACH,GAAG,CAAC,EAAGI,CAAC,IAAKA,CAAC,CAACD,OAAO,CAAC;AACtE;AAEM,SAAUE,WAAWA,CAACC,IAAY,EAAA;AACtC,EAAA,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,IAAI,YAAY,CAACb,IAAI,CAACY,IAAI,CAAC,EAAE;AAChD,IAAA,OAAOA,IAAI;AACb,EAAA;AAEA,EAAA,MAAME,WAAW,GAAGF,IAAI,CACrBG,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAEjB,IAAI,IAAK,CAACD,qBAAqB,CAACC,IAAI,CAAC,CAAC,CAC9CkB,GAAG,CAAElB,IAAI,IAAKM,YAAY,CAACN,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CACpCmB,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE;AAEhB;AACA,EAAA,MAAMC,SAAS,GAAGf,YAAY,CAACS,WAAW,CAAC;AAE3C,EAAA,IAAIM,SAAS,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAOO,SAAS,CAAC,CAAC,CAAC;AACrB,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAC,CAAC,CAAC,GAAGA,SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
1
+ {"version":3,"file":"initials.mjs","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter('en', { granularity: 'grapheme' })\n : undefined;\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n if (GRAPHEME_SEGMENTER) {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n }\n // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)\n return Array.from(str);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","undefined","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase","graphemes"],"mappings":"AAAA,SAASA,qBAAqBA,CAACC,IAAY,EAAA;AACzC,EAAA,OAAO,SAAS,CAACC,IAAI,CAACD,IAAI,CAAC;AAC7B;AAEA;AACA,MAAME,kBAAkB,GACtB,OAAOC,IAAI,CAACC,SAAS,KAAK,UAAU,GAChC,IAAID,IAAI,CAACC,SAAS,CAAC,IAAI,EAAE;AAAEC,EAAAA,WAAW,EAAE;CAAY,CAAC,GACrDC,SAAS;AAEf;AACA,SAASC,YAAYA,CAACC,GAAW,EAAA;AAC/B,EAAA,IAAIN,kBAAkB,EAAE;AACtB,IAAA,OAAOO,KAAK,CAACC,IAAI,CAACR,kBAAkB,CAACS,OAAO,CAACH,GAAG,CAAC,EAAGI,CAAC,IAAKA,CAAC,CAACD,OAAO,CAAC;AACtE,EAAA;AACA;AACA,EAAA,OAAOF,KAAK,CAACC,IAAI,CAACF,GAAG,CAAC;AACxB;AAEM,SAAUK,WAAWA,CAACC,IAAY,EAAA;AACtC,EAAA,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,IAAI,YAAY,CAACd,IAAI,CAACa,IAAI,CAAC,EAAE;AAChD,IAAA,OAAOA,IAAI;AACb,EAAA;AAEA,EAAA,MAAME,WAAW,GAAGF,IAAI,CACrBG,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAElB,IAAI,IAAK,CAACD,qBAAqB,CAACC,IAAI,CAAC,CAAC,CAC9CmB,GAAG,CAAEnB,IAAI,IAAKO,YAAY,CAACP,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CACpCoB,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE;AAEhB;AACA,EAAA,MAAMC,SAAS,GAAGf,YAAY,CAACS,WAAW,CAAC;AAE3C,EAAA,IAAIM,SAAS,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAOO,SAAS,CAAC,CAAC,CAAC;AACrB,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAC,CAAC,CAAC,GAAGA,SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
package/build/main.css CHANGED
@@ -948,7 +948,7 @@
948
948
  }
949
949
  .np-avatar-view .np-avatar-view-content {
950
950
  color: #37517e;
951
- color: var(--color-content-primary);
951
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
952
952
  }
953
953
  .np-avatar-view-interactive {
954
954
  cursor: pointer;
@@ -26,7 +26,7 @@
26
26
  }
27
27
  .np-avatar-view .np-avatar-view-content {
28
28
  color: #37517e;
29
- color: var(--color-content-primary);
29
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
30
30
  }
31
31
  .np-avatar-view-interactive {
32
32
  cursor: pointer;
@@ -948,7 +948,7 @@
948
948
  }
949
949
  .np-avatar-view .np-avatar-view-content {
950
950
  color: #37517e;
951
- color: var(--color-content-primary);
951
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
952
952
  }
953
953
  .np-avatar-view-interactive {
954
954
  cursor: pointer;
@@ -1 +1 @@
1
- {"version":3,"file":"initials.d.ts","sourceRoot":"","sources":["../../../src/common/initials.ts"],"names":[],"mappings":"AAYA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAoBvC"}
1
+ {"version":3,"file":"initials.d.ts","sourceRoot":"","sources":["../../../src/common/initials.ts"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAoBvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "46.123.0",
3
+ "version": "46.124.0",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -4,6 +4,7 @@ import AvatarLayout, { AvatarLayoutProps } from '.';
4
4
  import { Freeze, Graph, Plane, Rewards } from '@transferwise/icons';
5
5
  import { Flag } from '@wise/art';
6
6
  import Body from '../body';
7
+ import SentimentSurface from '../sentimentSurface';
7
8
 
8
9
  export default {
9
10
  title: 'Content/AvatarLayout',
@@ -283,3 +284,55 @@ export const EdgeInstances: Story = {
283
284
  </div>
284
285
  ),
285
286
  };
287
+
288
+ /**
289
+ * Like [AvatarView](?path=/docs/content-avatarview--docs#sentiment-awareness), `AvatarLayout` is sentiment-aware (note: not all features are supported) and will automatically adjust its colours if wrapped inside the
290
+ * [SentimentSurface](?path=/docs/content-sentimentsurface--docs) component.
291
+ *
292
+ * Features like: `interactive` are not supported.
293
+ * Also `AvatarLayout` isn't supported on `"elevated"` state of `SentimentSurface`.
294
+ */
295
+ export const SentimentAwareness: Story = {
296
+ parameters: {
297
+ docs: {
298
+ canvas: {
299
+ sourceState: 'hidden',
300
+ },
301
+ },
302
+ },
303
+ render: (args) => (
304
+ <>
305
+ {(['success', 'warning', 'negative', 'neutral', 'proposition'] as const).map((sentiment) =>
306
+ <SentimentSurface
307
+ key={`${sentiment}-base`}
308
+ sentiment={sentiment}
309
+ emphasis="base"
310
+ className="p-a-1 d-flex"
311
+ style={{ gap: 'var(--size-16)' }}
312
+ >
313
+ <AvatarLayout avatars={[{ asset: <Freeze /> }, { asset: <Freeze /> }]} />
314
+ <AvatarLayout
315
+ orientation="diagonal"
316
+ avatars={[{ asset: <Freeze /> }, { asset: <Freeze /> }]}
317
+ />
318
+ </SentimentSurface>
319
+ )}
320
+ </>
321
+ ),
322
+ decorators: [
323
+ (Story: () => JSX.Element) => (
324
+ <div
325
+ style={{
326
+ width: '100%',
327
+ display: 'grid',
328
+ gridTemplateColumns: 'min-content min-content',
329
+ justifyContent: 'center',
330
+ gap: '1rem',
331
+ maxWidth: '800px',
332
+ }}
333
+ >
334
+ <Story />
335
+ </div>
336
+ ),
337
+ ],
338
+ };
@@ -26,7 +26,7 @@
26
26
  }
27
27
  .np-avatar-view .np-avatar-view-content {
28
28
  color: #37517e;
29
- color: var(--color-content-primary);
29
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
30
30
  }
31
31
  .np-avatar-view-interactive {
32
32
  cursor: pointer;
@@ -2,7 +2,7 @@
2
2
 
3
3
  .np-avatar-view {
4
4
  .np-avatar-view-content {
5
- color: var(--color-content-primary);
5
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
6
6
  }
7
7
 
8
8
  &-interactive {
@@ -17,12 +17,15 @@ import {
17
17
  Transport,
18
18
  Wallet,
19
19
  Water,
20
+ Bank,
21
+ GiftBox,
20
22
  } from '@transferwise/icons';
21
23
  import AvatarView, { AvatarViewProps } from '.';
22
24
  import { Flag } from '@wise/art';
23
25
  import { getBrandColorFromSeed, getInitials, ProfileType } from '../common';
24
26
  import Display from '../display';
25
27
  import Body from '../body';
28
+ import SentimentSurface from '../sentimentSurface';
26
29
 
27
30
  export default {
28
31
  title: 'Content/AvatarView',
@@ -35,6 +38,20 @@ const profileName1 = 'Wolter White';
35
38
  const profileName2 = 'Tyler Durden';
36
39
  const sizes: AvatarViewProps['size'][] = [16, 24, 32, 40, 48, 56, 72];
37
40
 
41
+ const withComponentGrid = (Story: () => JSX.Element) => (
42
+ <div
43
+ style={{
44
+ width: '100%',
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ gap: '1rem',
48
+ maxWidth: '800px',
49
+ }}
50
+ >
51
+ <Story />
52
+ </div>
53
+ );
54
+
38
55
  export const Selected: Story = {
39
56
  render: () => {
40
57
  return (
@@ -420,6 +437,55 @@ export const Profiles: Story = {
420
437
  },
421
438
  };
422
439
 
440
+ /**
441
+ * `AvatarView` is sentiment-aware (note: not all features are supported) and will automatically adjust its colours if wrapped inside the
442
+ * [SentimentSurface](?path=/docs/content-sentimentsurface--docs) component.
443
+ *
444
+ * Features like `online`, `notification`, `selected`, and `interactive` are not supported.
445
+ * For badge (`<AvatarView badge={}>`) only `flagCode` is supported.
446
+ * Also `AvatarView` isn't supported on `"elevated"` state of `SentimentSurface`.
447
+ */
448
+ export const SentimentAwareness: Story = {
449
+ parameters: {
450
+ docs: {
451
+ canvas: {
452
+ sourceState: 'hidden',
453
+ },
454
+ source: { type: 'code' },
455
+ },
456
+ },
457
+ render: () => {
458
+ return (
459
+ <>
460
+ {(['success', 'warning', 'negative', 'neutral', 'proposition'] as const).map((sentiment) => (
461
+ <SentimentSurface
462
+ key={`${sentiment}-base`}
463
+ sentiment={sentiment}
464
+ emphasis="base"
465
+ className="p-a-1 d-flex"
466
+ style={{ gap: 'var(--size-16)' }}
467
+ >
468
+ <AvatarView size={32}>
469
+ <Bank />
470
+ </AvatarView>
471
+ <AvatarView size={32} profileName="John Doe" />
472
+ <AvatarView size={32}>
473
+ <Flag code="JPY" intrinsicSize={32} />
474
+ </AvatarView>
475
+ <AvatarView size={32} badge={sentiment === 'proposition' ? undefined : { status: sentiment }}>
476
+ <Bank />
477
+ </AvatarView>
478
+ <AvatarView size={32} badge={{ flagCode: 'eu' }}>
479
+ <Bank />
480
+ </AvatarView>
481
+ </SentimentSurface>
482
+ ))}
483
+ </>
484
+ );
485
+ },
486
+ decorators: [withComponentGrid],
487
+ };
488
+
423
489
  export const ProfileBrokenImageFallback: Story = {
424
490
  parameters: {
425
491
  chromatic: {
@@ -3,11 +3,18 @@ function startsWithParenthesis(part: string) {
3
3
  }
4
4
 
5
5
  // Reuse a single Intl.Segmenter instance to avoid repeated allocations
6
- const GRAPHEME_SEGMENTER = new Intl.Segmenter('en', { granularity: 'grapheme' });
6
+ const GRAPHEME_SEGMENTER =
7
+ typeof Intl.Segmenter === 'function'
8
+ ? new Intl.Segmenter('en', { granularity: 'grapheme' })
9
+ : undefined;
7
10
 
8
11
  // Helper to split the string into grapheme clusters, which handles complex characters correctly
9
12
  function getGraphemes(str: string): string[] {
10
- return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);
13
+ if (GRAPHEME_SEGMENTER) {
14
+ return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);
15
+ }
16
+ // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
17
+ return Array.from(str);
11
18
  }
12
19
 
13
20
  export function getInitials(name: string) {
package/src/main.css CHANGED
@@ -948,7 +948,7 @@
948
948
  }
949
949
  .np-avatar-view .np-avatar-view-content {
950
950
  color: #37517e;
951
- color: var(--color-content-primary);
951
+ color: var(--color-sentiment-content-primary, var(--color-content-primary));
952
952
  }
953
953
  .np-avatar-view-interactive {
954
954
  cursor: pointer;