@transferwise/components 46.72.0 → 46.72.2
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/build/alert/Alert.js +1 -0
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +1 -0
- package/build/alert/Alert.mjs.map +1 -1
- package/build/avatar/Avatar.js +2 -2
- package/build/avatar/Avatar.js.map +1 -1
- package/build/avatar/Avatar.mjs +2 -2
- package/build/avatar/Avatar.mjs.map +1 -1
- package/build/avatarWrapper/AvatarWrapper.js +2 -8
- package/build/avatarWrapper/AvatarWrapper.js.map +1 -1
- package/build/avatarWrapper/AvatarWrapper.mjs +1 -7
- package/build/avatarWrapper/AvatarWrapper.mjs.map +1 -1
- package/build/common/action/Action.js +11 -2
- package/build/common/action/Action.js.map +1 -1
- package/build/common/action/Action.mjs +11 -2
- package/build/common/action/Action.mjs.map +1 -1
- package/build/{avatar/colors → common}/colors.js +3 -3
- package/build/common/colors.js.map +1 -0
- package/build/{avatar/colors → common}/colors.mjs +3 -3
- package/build/common/colors.mjs.map +1 -0
- package/build/common/initials.js +12 -0
- package/build/common/initials.js.map +1 -0
- package/build/common/initials.mjs +10 -0
- package/build/common/initials.mjs.map +1 -0
- package/build/display/Display.js +1 -1
- package/build/display/Display.js.map +1 -1
- package/build/display/Display.mjs +1 -1
- package/build/display/Display.mjs.map +1 -1
- package/build/types/avatar/Avatar.d.ts.map +1 -1
- package/build/types/avatarWrapper/AvatarWrapper.d.ts.map +1 -1
- package/build/types/common/action/Action.d.ts +2 -1
- package/build/types/common/action/Action.d.ts.map +1 -1
- package/build/types/common/colors.d.ts +4 -0
- package/build/types/common/colors.d.ts.map +1 -0
- package/build/types/common/index.d.ts +2 -0
- package/build/types/common/initials.d.ts +2 -0
- package/build/types/common/initials.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/alert/Alert.tsx +1 -1
- package/src/avatar/Avatar.tsx +2 -3
- package/src/avatarWrapper/AvatarWrapper.tsx +8 -15
- package/src/common/action/Action.tsx +14 -2
- package/src/{avatar/colors → common}/colors.ts +5 -5
- package/src/common/index.js +2 -0
- package/src/common/initials.ts +13 -0
- package/src/display/Display.tsx +1 -1
- package/src/promoCard/__snapshots__/PromoCard.spec.tsx.snap +1 -1
- package/src/promoCard/__snapshots__/PromoCardGroup.spec.tsx.snap +2 -2
- package/src/test-utils/assets/avatar-rectangle-fox.webp +0 -0
- package/src/test-utils/assets/avatar-square-dude.webp +0 -0
- package/src/test-utils/assets/tapestry-01.png +0 -0
- package/build/avatar/colors/colors.js.map +0 -1
- package/build/avatar/colors/colors.mjs.map +0 -1
- package/build/types/avatar/colors/colors.d.ts +0 -4
- package/build/types/avatar/colors/colors.d.ts.map +0 -1
- package/build/types/avatar/colors/index.d.ts +0 -2
- package/build/types/avatar/colors/index.d.ts.map +0 -1
- package/src/avatar/colors/index.ts +0 -1
package/build/alert/Alert.js
CHANGED
package/build/alert/Alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.js","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;;;;AA8BYA,oCAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,0BAAkB,KAAlBA,0BAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AA6BD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AAC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A;AAAC,aACnD,CACR,CAAA;AAAA,WAAK,CACL,EAACN,MAAM,iBAAIoB,cAAA,CAACgC,aAAM,EAAA;AAACpD,YAAAA,MAAM,EAAEA,MAAO;AAACE,YAAAA,SAAS,EAAC,OAAA;AAAO,YAAG,CAAA;AAAA,SACpD,CACP,CAAA;AAAA,OAAK,CACL,EAACG,SAAS,iBACRe,cAAA,CAACiC,uBAAW,EAAA;AAACC,QAAAA,GAAG,EAAEpC,oBAAqB;AAAChB,QAAAA,SAAS,EAAC,OAAO;AAACqD,QAAAA,OAAO,EAAElD,SAAAA;AAAU,OAAG,CACjF,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASqB,oBAAoBA,CAAC3B,KAA8B,EAAA;AAC1D,EAAA,QAAQA,KAAK;AACX,IAAA,KAAK,aAAa;AAChB,MAAA,OAAO,iCAAiC,CAAA;AAC1C,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,+BAA+B,CAAA;AACxC,IAAA,KAAK,YAAY;AACf,MAAA,OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"Alert.js","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;;;;AA8BYA,oCAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,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":3,"file":"Alert.mjs","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mapp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OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"Alert.mjs","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;IA8BYA,mBAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,kBAAkB,KAAlBA,kBAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AA6BD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS,CAAA;AAClB,IAAA,KAAK,OAAO;AACV,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA;AACE,MAAA,OAAOA,IAAI,CAAA;AACf,GAAA;AACF,CAAA;AAEc,SAAUC,KAAKA,CAAC;EAC5BC,KAAK;EACLC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,WAAW;EACXC,IAAI;EACJC,SAAS;EACTC,OAAO;EACPC,IAAI;EACJC,KAAK;AACLX,EAAAA,IAAI,GAAG,SAAS;AAChBY,E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;AAAU,OAAG,CACjF,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASqB,oBAAoBA,CAAC3B,KAA8B,EAAA;AAC1D,EAAA,QAAQA,KAAK;AACX,IAAA,KAAK,aAAa;AAChB,MAAA,OAAO,iCAAiC,CAAA;AAC1C,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,+BAA+B,CAAA;AACxC,IAAA,KAAK,YAAY;AACf,MAAA,OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
package/build/avatar/Avatar.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var colors = require('./colors/colors.js');
|
|
6
5
|
var Circle = require('../common/circle/Circle.js');
|
|
7
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var colors = require('../common/colors.js');
|
|
8
8
|
var theme = require('../common/theme.js');
|
|
9
9
|
|
|
10
10
|
const backwardsCompatibleSize = size => {
|
|
@@ -30,7 +30,7 @@ const Avatar = ({
|
|
|
30
30
|
type = 'thumbnail',
|
|
31
31
|
'aria-label': ariaLabel
|
|
32
32
|
}) => {
|
|
33
|
-
const backgroundColorFromSeed = React.useMemo(() => !backgroundColor && backgroundColorSeed ?
|
|
33
|
+
const backgroundColorFromSeed = React.useMemo(() => !backgroundColor && backgroundColorSeed ? colors.getBrandColorFromSeed(backgroundColorSeed) : undefined, [backgroundColor, backgroundColorSeed]);
|
|
34
34
|
const size = backwardsCompatibleSize(sizeFromProps);
|
|
35
35
|
return /*#__PURE__*/jsxRuntime.jsx(Circle, {
|
|
36
36
|
size: size,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sources":["../../src/avatar/Avatar.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useMemo } from 'react';\n\nimport { Theme } from '../common';\n\nimport
|
|
1
|
+
{"version":3,"file":"Avatar.js","sources":["../../src/avatar/Avatar.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useMemo } from 'react';\n\nimport { getBrandColorFromSeed, Theme } from '../common';\n\nimport Circle from '../common/circle';\n\ntype NumericAvatarSize = 24 | 40 | 48 | 56 | 72;\n\ntype LegacyAvatarSize = 'sm' | 'md' | 'lg';\n\nexport type AvatarSize = NumericAvatarSize | LegacyAvatarSize;\n\nexport type AvatarTheme = 'light' | 'dark';\n\nexport type AvatarType = 'thumbnail' | 'icon' | 'emoji' | 'initials';\n\nexport interface AvatarProps {\n backgroundColor?: string;\n backgroundColorSeed?: string;\n children?: React.ReactNode;\n className?: string;\n outlined?: boolean;\n size?: AvatarSize;\n theme?: AvatarTheme;\n type?: AvatarType;\n 'aria-label'?: string;\n}\n\nconst backwardsCompatibleSize = (size: AvatarSize): NumericAvatarSize => {\n switch (size) {\n case 'sm':\n return 24;\n\n case 'md':\n return 48;\n\n case 'lg':\n return 72;\n\n default:\n return size;\n }\n};\n\nconst Avatar: React.FC<AvatarProps> = ({\n backgroundColor = null,\n backgroundColorSeed = null,\n children = null,\n className,\n outlined = false,\n size: sizeFromProps = 48,\n theme = Theme.LIGHT,\n type = 'thumbnail',\n 'aria-label': ariaLabel,\n}) => {\n const backgroundColorFromSeed = useMemo<string | undefined>(\n () =>\n !backgroundColor && backgroundColorSeed\n ? getBrandColorFromSeed(backgroundColorSeed)\n : undefined,\n [backgroundColor, backgroundColorSeed],\n );\n\n const size = backwardsCompatibleSize(sizeFromProps);\n\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx('tw-avatar', className, `tw-avatar--${size}`, `tw-avatar--${type}`, {\n 'tw-avatar--outlined': outlined,\n 'tw-avatar--branded': Boolean(backgroundColorFromSeed),\n 'np-text-title-body': type === 'initials',\n })}\n aria-label={ariaLabel}\n >\n <Circle\n size={size}\n fixedSize\n className=\"tw-avatar__content\"\n style={{\n backgroundColor: backgroundColor || backgroundColorFromSeed,\n }}\n >\n {children}\n </Circle>\n </Circle>\n );\n};\n\nexport default Avatar;\n"],"names":["backwardsCompatibleSize","size","Avatar","backgroundColor","backgroundColorSeed","children","className","outlined","sizeFromProps","theme","Theme","LIGHT","type","ariaLabel","backgroundColorFromSeed","useMemo","getBrandColorFromSeed","undefined","_jsx","Circle","fixedSize","clsx","Boolean","style"],"mappings":";;;;;;;;;AA6BA,MAAMA,uBAAuB,GAAIC,IAAgB,IAAuB;AACtE,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA;AACE,MAAA,OAAOA,IAAI,CAAA;AACf,GAAA;AACF,CAAC,CAAA;AAEKC,MAAAA,MAAM,GAA0BA,CAAC;AACrCC,EAAAA,eAAe,GAAG,IAAI;AACtBC,EAAAA,mBAAmB,GAAG,IAAI;AAC1BC,EAAAA,QAAQ,GAAG,IAAI;EACfC,SAAS;AACTC,EAAAA,QAAQ,GAAG,KAAK;EAChBN,IAAI,EAAEO,aAAa,GAAG,EAAE;SACxBC,OAAK,GAAGC,WAAK,CAACC,KAAK;AACnBC,EAAAA,IAAI,GAAG,WAAW;AAClB,EAAA,YAAY,EAAEC,SAAAA;AAAS,CACxB,KAAI;EACH,MAAMC,uBAAuB,GAAGC,aAAO,CACrC,MACE,CAACZ,eAAe,IAAIC,mBAAmB,GACnCY,4BAAqB,CAACZ,mBAAmB,CAAC,GAC1Ca,SAAS,EACf,CAACd,eAAe,EAAEC,mBAAmB,CAAC,CACvC,CAAA;AAED,EAAA,MAAMH,IAAI,GAAGD,uBAAuB,CAACQ,aAAa,CAAC,CAAA;EAEnD,oBACEU,cAAA,CAACC,MAAM,EAAA;AACLlB,IAAAA,IAAI,EAAEA,IAAK;IACXmB,SAAS,EAAA,IAAA;AACTd,IAAAA,SAAS,EAAEe,SAAI,CAAC,WAAW,EAAEf,SAAS,EAAE,CAAcL,WAAAA,EAAAA,IAAI,CAAE,CAAA,EAAE,CAAcW,WAAAA,EAAAA,IAAI,EAAE,EAAE;AAClF,MAAA,qBAAqB,EAAEL,QAAQ;AAC/B,MAAA,oBAAoB,EAAEe,OAAO,CAACR,uBAAuB,CAAC;MACtD,oBAAoB,EAAEF,IAAI,KAAK,UAAA;AAChC,KAAA,CAAE;AACH,IAAA,YAAA,EAAYC,SAAU;IAAAR,QAAA,eAEtBa,cAAA,CAACC,MAAM,EAAA;AACLlB,MAAAA,IAAI,EAAEA,IAAK;MACXmB,SAAS,EAAA,IAAA;AACTd,MAAAA,SAAS,EAAC,oBAAoB;AAC9BiB,MAAAA,KAAK,EAAE;QACLpB,eAAe,EAAEA,eAAe,IAAIW,uBAAAA;OACpC;AAAAT,MAAAA,QAAA,EAEDA,QAAAA;KACK,CAAA;AACV,GAAQ,CAAC,CAAA;AAEb;;;;"}
|
package/build/avatar/Avatar.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { getAvatarColorFromSeed } from './colors/colors.mjs';
|
|
4
3
|
import Circle from '../common/circle/Circle.mjs';
|
|
5
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { getBrandColorFromSeed } from '../common/colors.mjs';
|
|
6
6
|
import { Theme } from '../common/theme.mjs';
|
|
7
7
|
|
|
8
8
|
const backwardsCompatibleSize = size => {
|
|
@@ -28,7 +28,7 @@ const Avatar = ({
|
|
|
28
28
|
type = 'thumbnail',
|
|
29
29
|
'aria-label': ariaLabel
|
|
30
30
|
}) => {
|
|
31
|
-
const backgroundColorFromSeed = useMemo(() => !backgroundColor && backgroundColorSeed ?
|
|
31
|
+
const backgroundColorFromSeed = useMemo(() => !backgroundColor && backgroundColorSeed ? getBrandColorFromSeed(backgroundColorSeed) : undefined, [backgroundColor, backgroundColorSeed]);
|
|
32
32
|
const size = backwardsCompatibleSize(sizeFromProps);
|
|
33
33
|
return /*#__PURE__*/jsx(Circle, {
|
|
34
34
|
size: size,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.mjs","sources":["../../src/avatar/Avatar.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useMemo } from 'react';\n\nimport { Theme } from '../common';\n\nimport
|
|
1
|
+
{"version":3,"file":"Avatar.mjs","sources":["../../src/avatar/Avatar.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useMemo } from 'react';\n\nimport { getBrandColorFromSeed, Theme } from '../common';\n\nimport Circle from '../common/circle';\n\ntype NumericAvatarSize = 24 | 40 | 48 | 56 | 72;\n\ntype LegacyAvatarSize = 'sm' | 'md' | 'lg';\n\nexport type AvatarSize = NumericAvatarSize | LegacyAvatarSize;\n\nexport type AvatarTheme = 'light' | 'dark';\n\nexport type AvatarType = 'thumbnail' | 'icon' | 'emoji' | 'initials';\n\nexport interface AvatarProps {\n backgroundColor?: string;\n backgroundColorSeed?: string;\n children?: React.ReactNode;\n className?: string;\n outlined?: boolean;\n size?: AvatarSize;\n theme?: AvatarTheme;\n type?: AvatarType;\n 'aria-label'?: string;\n}\n\nconst backwardsCompatibleSize = (size: AvatarSize): NumericAvatarSize => {\n switch (size) {\n case 'sm':\n return 24;\n\n case 'md':\n return 48;\n\n case 'lg':\n return 72;\n\n default:\n return size;\n }\n};\n\nconst Avatar: React.FC<AvatarProps> = ({\n backgroundColor = null,\n backgroundColorSeed = null,\n children = null,\n className,\n outlined = false,\n size: sizeFromProps = 48,\n theme = Theme.LIGHT,\n type = 'thumbnail',\n 'aria-label': ariaLabel,\n}) => {\n const backgroundColorFromSeed = useMemo<string | undefined>(\n () =>\n !backgroundColor && backgroundColorSeed\n ? getBrandColorFromSeed(backgroundColorSeed)\n : undefined,\n [backgroundColor, backgroundColorSeed],\n );\n\n const size = backwardsCompatibleSize(sizeFromProps);\n\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx('tw-avatar', className, `tw-avatar--${size}`, `tw-avatar--${type}`, {\n 'tw-avatar--outlined': outlined,\n 'tw-avatar--branded': Boolean(backgroundColorFromSeed),\n 'np-text-title-body': type === 'initials',\n })}\n aria-label={ariaLabel}\n >\n <Circle\n size={size}\n fixedSize\n className=\"tw-avatar__content\"\n style={{\n backgroundColor: backgroundColor || backgroundColorFromSeed,\n }}\n >\n {children}\n </Circle>\n </Circle>\n );\n};\n\nexport default Avatar;\n"],"names":["backwardsCompatibleSize","size","Avatar","backgroundColor","backgroundColorSeed","children","className","outlined","sizeFromProps","theme","Theme","LIGHT","type","ariaLabel","backgroundColorFromSeed","useMemo","getBrandColorFromSeed","undefined","_jsx","Circle","fixedSize","clsx","Boolean","style"],"mappings":";;;;;;;AA6BA,MAAMA,uBAAuB,GAAIC,IAAgB,IAAuB;AACtE,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA,KAAK,IAAI;AACP,MAAA,OAAO,EAAE,CAAA;AAEX,IAAA;AACE,MAAA,OAAOA,IAAI,CAAA;AACf,GAAA;AACF,CAAC,CAAA;AAEKC,MAAAA,MAAM,GAA0BA,CAAC;AACrCC,EAAAA,eAAe,GAAG,IAAI;AACtBC,EAAAA,mBAAmB,GAAG,IAAI;AAC1BC,EAAAA,QAAQ,GAAG,IAAI;EACfC,SAAS;AACTC,EAAAA,QAAQ,GAAG,KAAK;EAChBN,IAAI,EAAEO,aAAa,GAAG,EAAE;EACxBC,KAAK,GAAGC,KAAK,CAACC,KAAK;AACnBC,EAAAA,IAAI,GAAG,WAAW;AAClB,EAAA,YAAY,EAAEC,SAAAA;AAAS,CACxB,KAAI;EACH,MAAMC,uBAAuB,GAAGC,OAAO,CACrC,MACE,CAACZ,eAAe,IAAIC,mBAAmB,GACnCY,qBAAqB,CAACZ,mBAAmB,CAAC,GAC1Ca,SAAS,EACf,CAACd,eAAe,EAAEC,mBAAmB,CAAC,CACvC,CAAA;AAED,EAAA,MAAMH,IAAI,GAAGD,uBAAuB,CAACQ,aAAa,CAAC,CAAA;EAEnD,oBACEU,GAAA,CAACC,MAAM,EAAA;AACLlB,IAAAA,IAAI,EAAEA,IAAK;IACXmB,SAAS,EAAA,IAAA;AACTd,IAAAA,SAAS,EAAEe,IAAI,CAAC,WAAW,EAAEf,SAAS,EAAE,CAAcL,WAAAA,EAAAA,IAAI,CAAE,CAAA,EAAE,CAAcW,WAAAA,EAAAA,IAAI,EAAE,EAAE;AAClF,MAAA,qBAAqB,EAAEL,QAAQ;AAC/B,MAAA,oBAAoB,EAAEe,OAAO,CAACR,uBAAuB,CAAC;MACtD,oBAAoB,EAAEF,IAAI,KAAK,UAAA;AAChC,KAAA,CAAE;AACH,IAAA,YAAA,EAAYC,SAAU;IAAAR,QAAA,eAEtBa,GAAA,CAACC,MAAM,EAAA;AACLlB,MAAAA,IAAI,EAAEA,IAAK;MACXmB,SAAS,EAAA,IAAA;AACTd,MAAAA,SAAS,EAAC,oBAAoB;AAC9BiB,MAAAA,KAAK,EAAE;QACLpB,eAAe,EAAEA,eAAe,IAAIW,uBAAAA;OACpC;AAAAT,MAAAA,QAAA,EAEDA,QAAAA;KACK,CAAA;AACV,GAAQ,CAAC,CAAA;AAEb;;;;"}
|
|
@@ -8,6 +8,7 @@ var Badge = require('../badge/Badge.js');
|
|
|
8
8
|
var StatusIcon = require('../statusIcon/StatusIcon.js');
|
|
9
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
10
10
|
var profileType = require('../common/propsValues/profileType.js');
|
|
11
|
+
var initials = require('../common/initials.js');
|
|
11
12
|
var size = require('../common/propsValues/size.js');
|
|
12
13
|
|
|
13
14
|
const OptionalBadge = ({
|
|
@@ -94,7 +95,7 @@ const AvatarWrapper = ({
|
|
|
94
95
|
return {
|
|
95
96
|
type: avatarTypes.AvatarType.INITIALS,
|
|
96
97
|
children: /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
97
|
-
children: getInitials(name)
|
|
98
|
+
children: initials.getInitials(name)
|
|
98
99
|
}),
|
|
99
100
|
backgroundColorSeed: profileId?.toString(),
|
|
100
101
|
...updatedAvatarProps
|
|
@@ -120,13 +121,6 @@ const AvatarWrapper = ({
|
|
|
120
121
|
})
|
|
121
122
|
});
|
|
122
123
|
};
|
|
123
|
-
function getInitials(name) {
|
|
124
|
-
const allInitials = name.split(' ').map(part => part[0]).join('').toUpperCase();
|
|
125
|
-
if (allInitials.length === 1) {
|
|
126
|
-
return allInitials[0];
|
|
127
|
-
}
|
|
128
|
-
return allInitials[0] + allInitials.slice(-1);
|
|
129
|
-
}
|
|
130
124
|
|
|
131
125
|
module.exports = AvatarWrapper;
|
|
132
126
|
//# sourceMappingURL=AvatarWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarWrapper.js","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person as ProfileIcon, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {
|
|
1
|
+
{"version":3,"file":"AvatarWrapper.js","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person as ProfileIcon, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [hasImageLoadError, setImageLoadError] = useState(false);\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n // Reset the errored state when url changes\n useEffect(() => setImageLoadError(false), [url]);\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setImageLoadError(true)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <ProfileIcon size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <ProfileIcon size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","hasImageLoadError","setImageLoadError","useState","isBusinessProfile","ProfileType","BUSINESS","useEffect","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","ProfileIcon","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;;;AAsBA,MAAMA,aAAa,GAAGA,CAAC;EACrBC,GAAG;EACHC,OAAO;EACPC,UAAU;EACVC,QAAQ;EACRC,SAAS;EACT,GAAGC,IAAAA;AAAI,CACY,KAAI;AACvB,EAAA,IAAIL,GAAG,EAAE;IACP,oBACEM,cAAA,CAACC,KAAK,EAAA;AAAC,MAAA,YAAA,EAAYH,SAAU;AAACI,MAAAA,KAAK,eAAEF,cAAA,CAAA,KAAA,EAAA;AAAKG,QAAAA,GAAG,EAAET,GAAI;AAACU,QAAAA,GAA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AAA;GACF,CAAA;EAED,oBACE5B,cAAA,CAACP,aAAa,EAAA;AACZC,IAAAA,GAAG,EAAEoB,QAAS;AACdhB,IAAAA,SAAS,EAAEA,SAAU;AACrBH,IAAAA,OAAO,EAAEoB,YAAa;AACtBnB,IAAAA,UAAU,EAAEoB,eAAgB;AAAA,IAAA,GACxBG,UAAU;IAAAtB,QAAA,eAEdG,cAAA,CAACwC,MAAM,EAAA;MAACjC,IAAI,EAAEC,SAAI,CAACiC,MAAO;AAAA,MAAA,GAAKd,cAAc,EAAA;KAC/C,CAAA;AAAA,GAAe,CAAC,CAAA;AAEpB;;;;"}
|
|
@@ -6,6 +6,7 @@ import Badge from '../badge/Badge.mjs';
|
|
|
6
6
|
import StatusIcon from '../statusIcon/StatusIcon.mjs';
|
|
7
7
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import { ProfileType } from '../common/propsValues/profileType.mjs';
|
|
9
|
+
import { getInitials } from '../common/initials.mjs';
|
|
9
10
|
import { Size } from '../common/propsValues/size.mjs';
|
|
10
11
|
|
|
11
12
|
const OptionalBadge = ({
|
|
@@ -118,13 +119,6 @@ const AvatarWrapper = ({
|
|
|
118
119
|
})
|
|
119
120
|
});
|
|
120
121
|
};
|
|
121
|
-
function getInitials(name) {
|
|
122
|
-
const allInitials = name.split(' ').map(part => part[0]).join('').toUpperCase();
|
|
123
|
-
if (allInitials.length === 1) {
|
|
124
|
-
return allInitials[0];
|
|
125
|
-
}
|
|
126
|
-
return allInitials[0] + allInitials.slice(-1);
|
|
127
|
-
}
|
|
128
122
|
|
|
129
123
|
export { AvatarWrapper as default };
|
|
130
124
|
//# sourceMappingURL=AvatarWrapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarWrapper.mjs","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person as ProfileIcon, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {
|
|
1
|
+
{"version":3,"file":"AvatarWrapper.mjs","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person as ProfileIcon, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [hasImageLoadError, setImageLoadError] = useState(false);\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n // Reset the errored state when url changes\n useEffect(() => setImageLoadError(false), [url]);\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setImageLoadError(true)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <ProfileIcon size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <ProfileIcon size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","hasImageLoadError","setImageLoadError","useState","isBusinessProfile","ProfileType","BUSINESS","useEffect","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","ProfileIcon","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;AAsBA,MAAMA,aA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A;AAAC,SAAI,CAAA;AAClCqB,QAAAA,mBAAmB,EAAEzB,SAAS,EAAE0B,QAAQ,EAAE;QAC1C,GAAGX,kBAAAA;OACJ,CAAA;AACH,KAAA;IACA,OAAO;MACLC,IAAI,EAAEC,UAAU,CAACG,IAAI;MACrBpC,QAAQ,eAAEG,GAAA,CAACmC,MAAW,EAAA;AAAC5B,QAAAA,IAAI,EAAC,IAAA;AAAI,OAAG,CAAA;MACnC,GAAGqB,kBAAAA;KACJ,CAAA;GACF,CAAA;EAED,oBACE5B,GAAA,CAACP,aAAa,EAAA;AACZC,IAAAA,GAAG,EAAEoB,QAAS;AACdhB,IAAAA,SAAS,EAAEA,SAAU;AACrBH,IAAAA,OAAO,EAAEoB,YAAa;AACtBnB,IAAAA,UAAU,EAAEoB,eAAgB;AAAA,IAAA,GACxBG,UAAU;IAAAtB,QAAA,eAEdG,GAAA,CAACwC,MAAM,EAAA;MAACjC,IAAI,EAAEC,IAAI,CAACiC,MAAO;AAAA,MAAA,GAAKd,cAAc,EAAA;KAC/C,CAAA;AAAA,GAAe,CAAC,CAAA;AAEpB;;;;"}
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var Link = require('../../link/Link.js');
|
|
5
5
|
var typography = require('../propsValues/typography.js');
|
|
6
|
+
var ActionButton = require('../../actionButton/ActionButton.js');
|
|
7
|
+
var control = require('../propsValues/control.js');
|
|
6
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
9
|
|
|
8
10
|
function Action({
|
|
9
11
|
action,
|
|
10
|
-
className
|
|
12
|
+
className,
|
|
13
|
+
variant = 'button'
|
|
11
14
|
}) {
|
|
12
15
|
if ('href' in action) {
|
|
13
16
|
return /*#__PURE__*/jsxRuntime.jsx(Link, {
|
|
@@ -20,12 +23,18 @@ function Action({
|
|
|
20
23
|
children: action.text
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
|
-
return /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
26
|
+
return variant === 'button' ? /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
24
27
|
type: "button",
|
|
25
28
|
"aria-label": action['aria-label'],
|
|
26
29
|
className: clsx.clsx('btn-unstyled np-text-link-large', className),
|
|
27
30
|
onClick: action.onClick,
|
|
28
31
|
children: action.text
|
|
32
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(ActionButton, {
|
|
33
|
+
"aria-label": action['aria-label'],
|
|
34
|
+
priority: control.Priority.SECONDARY,
|
|
35
|
+
className: clsx.clsx(className),
|
|
36
|
+
onClick: action.onClick,
|
|
37
|
+
children: action.text
|
|
29
38
|
});
|
|
30
39
|
}
|
|
31
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.js","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n );\n}\n"],"names":["Action","action","className","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Action.js","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\nimport ActionButton from '../../actionButton';\nimport { Priority } from '../propsValues/control';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n variant?: 'button' | 'action-button';\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className, variant = 'button' }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return variant === 'button' ? (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n ) : (\n <ActionButton\n aria-label={action['aria-label']}\n priority={Priority.SECONDARY}\n className={clsx(className)}\n onClick={action.onClick}\n >\n {action.text}\n </ActionButton>\n );\n}\n"],"names":["Action","action","className","variant","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx","ActionButton","priority","Priority","SECONDARY"],"mappings":";;;;;;;;;AAoBM,SAAUA,MAAMA,CAAC;EAAEC,MAAM;EAAEC,SAAS;AAAEC,EAAAA,OAAO,GAAG,QAAA;AAAiB,CAAA,EAAA;EACrE,IAAI,MAAM,IAAIF,MAAM,EAAE;IACpB,oBACEG,cAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEL,MAAM,CAACK,IAAK;AAClBJ,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCM,MAAM,EAAEN,MAAM,CAACM,MAAO;MACtBC,IAAI,EAAEC,qBAAU,CAACC,UAAW;MAC5BC,OAAO,EAAEV,MAAM,CAACU,OAAQ;MAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,OAAOV,OAAO,KAAK,QAAQ,gBACzBC,cAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYP,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEY,SAAI,CAAC,iCAAiC,EAAEZ,SAAS,CAAE;IAC9DS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACN,CAAC,gBAETT,cAAA,CAACW,YAAY,EAAA;IACX,YAAYd,EAAAA,MAAM,CAAC,YAAY,CAAE;IACjCe,QAAQ,EAAEC,gBAAQ,CAACC,SAAU;AAC7BhB,IAAAA,SAAS,EAAEY,SAAI,CAACZ,SAAS,CAAE;IAC3BS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACA,CACf,CAAA;AACH;;;;"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import Link from '../../link/Link.mjs';
|
|
3
3
|
import { Typography } from '../propsValues/typography.mjs';
|
|
4
|
+
import ActionButton from '../../actionButton/ActionButton.mjs';
|
|
5
|
+
import { Priority } from '../propsValues/control.mjs';
|
|
4
6
|
import { jsx } from 'react/jsx-runtime';
|
|
5
7
|
|
|
6
8
|
function Action({
|
|
7
9
|
action,
|
|
8
|
-
className
|
|
10
|
+
className,
|
|
11
|
+
variant = 'button'
|
|
9
12
|
}) {
|
|
10
13
|
if ('href' in action) {
|
|
11
14
|
return /*#__PURE__*/jsx(Link, {
|
|
@@ -18,12 +21,18 @@ function Action({
|
|
|
18
21
|
children: action.text
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
|
-
return /*#__PURE__*/jsx("button", {
|
|
24
|
+
return variant === 'button' ? /*#__PURE__*/jsx("button", {
|
|
22
25
|
type: "button",
|
|
23
26
|
"aria-label": action['aria-label'],
|
|
24
27
|
className: clsx('btn-unstyled np-text-link-large', className),
|
|
25
28
|
onClick: action.onClick,
|
|
26
29
|
children: action.text
|
|
30
|
+
}) : /*#__PURE__*/jsx(ActionButton, {
|
|
31
|
+
"aria-label": action['aria-label'],
|
|
32
|
+
priority: Priority.SECONDARY,
|
|
33
|
+
className: clsx(className),
|
|
34
|
+
onClick: action.onClick,
|
|
35
|
+
children: action.text
|
|
27
36
|
});
|
|
28
37
|
}
|
|
29
38
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.mjs","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n );\n}\n"],"names":["Action","action","className","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Action.mjs","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\nimport ActionButton from '../../actionButton';\nimport { Priority } from '../propsValues/control';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n variant?: 'button' | 'action-button';\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className, variant = 'button' }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return variant === 'button' ? (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n ) : (\n <ActionButton\n aria-label={action['aria-label']}\n priority={Priority.SECONDARY}\n className={clsx(className)}\n onClick={action.onClick}\n >\n {action.text}\n </ActionButton>\n );\n}\n"],"names":["Action","action","className","variant","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx","ActionButton","priority","Priority","SECONDARY"],"mappings":";;;;;;;AAoBM,SAAUA,MAAMA,CAAC;EAAEC,MAAM;EAAEC,SAAS;AAAEC,EAAAA,OAAO,GAAG,QAAA;AAAiB,CAAA,EAAA;EACrE,IAAI,MAAM,IAAIF,MAAM,EAAE;IACpB,oBACEG,GAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEL,MAAM,CAACK,IAAK;AAClBJ,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCM,MAAM,EAAEN,MAAM,CAACM,MAAO;MACtBC,IAAI,EAAEC,UAAU,CAACC,UAAW;MAC5BC,OAAO,EAAEV,MAAM,CAACU,OAAQ;MAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,OAAOV,OAAO,KAAK,QAAQ,gBACzBC,GAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYP,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEY,IAAI,CAAC,iCAAiC,EAAEZ,SAAS,CAAE;IAC9DS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACN,CAAC,gBAETT,GAAA,CAACW,YAAY,EAAA;IACX,YAAYd,EAAAA,MAAM,CAAC,YAAY,CAAE;IACjCe,QAAQ,EAAEC,QAAQ,CAACC,SAAU;AAC7BhB,IAAAA,SAAS,EAAEY,IAAI,CAACZ,SAAS,CAAE;IAC3BS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACA,CACf,CAAA;AACH;;;;"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Changing this array will change the assignment between seeds.
|
|
6
6
|
* Do not change this array.
|
|
7
7
|
*/
|
|
8
|
-
const avatarColors = ['--color-bright-blue', '--color-bright-yellow', '--color-bright-pink', '--color-bright-orange'];
|
|
8
|
+
const avatarColors = ['var(--color-bright-blue)', 'var(--color-bright-yellow)', 'var(--color-bright-pink)', 'var(--color-bright-orange)'];
|
|
9
9
|
/*
|
|
10
10
|
* Takes in a "seed" string and spits out an index for the color we should use.
|
|
11
11
|
* This implementation has been synced across all three clients so that we consistently
|
|
@@ -23,9 +23,9 @@ const hashSeed = seed => {
|
|
|
23
23
|
}
|
|
24
24
|
return hashValue;
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const getBrandColorFromSeed = seed => {
|
|
27
27
|
return avatarColors[hashSeed(seed)];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
exports.
|
|
30
|
+
exports.getBrandColorFromSeed = getBrandColorFromSeed;
|
|
31
31
|
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sources":["../../src/common/colors.ts"],"sourcesContent":["/*\n * The colors we support generating an Avatar background color from a \"seed\" for.\n * Changing this array will change the assignment between seeds.\n * Do not change this array.\n */\nconst avatarColors = [\n 'var(--color-bright-blue)',\n 'var(--color-bright-yellow)',\n 'var(--color-bright-pink)',\n 'var(--color-bright-orange)',\n] as const;\n\n/*\n * Takes in a \"seed\" string and spits out an index for the color we should use.\n * This implementation has been synced across all three clients so that we consistently\n * generate branded avatar colors when rendering a list of Avatars.\n * Do not change this implementation.\n */\nconst hashSeed = (seed: string): number => {\n const base = 31;\n const modulo = avatarColors.length;\n\n let hashValue = 0;\n let basePow = 1;\n\n for (let i = 0; i < seed.length; i += 1) {\n hashValue = (hashValue + seed.charCodeAt(i) * basePow) % modulo;\n basePow = (basePow * base) % modulo;\n }\n\n return hashValue;\n};\n\nexport const getBrandColorFromSeed = (seed: string): (typeof avatarColors)[number] => {\n return avatarColors[hashSeed(seed)];\n};\n"],"names":["avatarColors","hashSeed","seed","base","modulo","length","hashValue","basePow","i","charCodeAt","getBrandColorFromSeed"],"mappings":";;AAAA;;;;AAIG;AACH,MAAMA,YAAY,GAAG,CACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,CACpB,CAAA;AAEV;;;;;AAKG;AACH,MAAMC,QAAQ,GAAIC,IAAY,IAAY;EACxC,MAAMC,IAAI,GAAG,EAAE,CAAA;AACf,EAAA,MAAMC,MAAM,GAAGJ,YAAY,CAACK,MAAM,CAAA;EAElC,IAAIC,SAAS,GAAG,CAAC,CAAA;EACjB,IAAIC,OAAO,GAAG,CAAC,CAAA;AAEf,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,IAAI,CAACG,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;AACvCF,IAAAA,SAAS,GAAG,CAACA,SAAS,GAAGJ,IAAI,CAACO,UAAU,CAACD,CAAC,CAAC,GAAGD,OAAO,IAAIH,MAAM,CAAA;AAC/DG,IAAAA,OAAO,GAAIA,OAAO,GAAGJ,IAAI,GAAIC,MAAM,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOE,SAAS,CAAA;AAClB,CAAC,CAAA;AAEYI,MAAAA,qBAAqB,GAAIR,IAAY,IAAmC;AACnF,EAAA,OAAOF,YAAY,CAACC,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;AACrC;;;;"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Changing this array will change the assignment between seeds.
|
|
4
4
|
* Do not change this array.
|
|
5
5
|
*/
|
|
6
|
-
const avatarColors = ['--color-bright-blue', '--color-bright-yellow', '--color-bright-pink', '--color-bright-orange'];
|
|
6
|
+
const avatarColors = ['var(--color-bright-blue)', 'var(--color-bright-yellow)', 'var(--color-bright-pink)', 'var(--color-bright-orange)'];
|
|
7
7
|
/*
|
|
8
8
|
* Takes in a "seed" string and spits out an index for the color we should use.
|
|
9
9
|
* This implementation has been synced across all three clients so that we consistently
|
|
@@ -21,9 +21,9 @@ const hashSeed = seed => {
|
|
|
21
21
|
}
|
|
22
22
|
return hashValue;
|
|
23
23
|
};
|
|
24
|
-
const
|
|
24
|
+
const getBrandColorFromSeed = seed => {
|
|
25
25
|
return avatarColors[hashSeed(seed)];
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export {
|
|
28
|
+
export { getBrandColorFromSeed };
|
|
29
29
|
//# sourceMappingURL=colors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.mjs","sources":["../../src/common/colors.ts"],"sourcesContent":["/*\n * The colors we support generating an Avatar background color from a \"seed\" for.\n * Changing this array will change the assignment between seeds.\n * Do not change this array.\n */\nconst avatarColors = [\n 'var(--color-bright-blue)',\n 'var(--color-bright-yellow)',\n 'var(--color-bright-pink)',\n 'var(--color-bright-orange)',\n] as const;\n\n/*\n * Takes in a \"seed\" string and spits out an index for the color we should use.\n * This implementation has been synced across all three clients so that we consistently\n * generate branded avatar colors when rendering a list of Avatars.\n * Do not change this implementation.\n */\nconst hashSeed = (seed: string): number => {\n const base = 31;\n const modulo = avatarColors.length;\n\n let hashValue = 0;\n let basePow = 1;\n\n for (let i = 0; i < seed.length; i += 1) {\n hashValue = (hashValue + seed.charCodeAt(i) * basePow) % modulo;\n basePow = (basePow * base) % modulo;\n }\n\n return hashValue;\n};\n\nexport const getBrandColorFromSeed = (seed: string): (typeof avatarColors)[number] => {\n return avatarColors[hashSeed(seed)];\n};\n"],"names":["avatarColors","hashSeed","seed","base","modulo","length","hashValue","basePow","i","charCodeAt","getBrandColorFromSeed"],"mappings":"AAAA;;;;AAIG;AACH,MAAMA,YAAY,GAAG,CACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,4BAA4B,CACpB,CAAA;AAEV;;;;;AAKG;AACH,MAAMC,QAAQ,GAAIC,IAAY,IAAY;EACxC,MAAMC,IAAI,GAAG,EAAE,CAAA;AACf,EAAA,MAAMC,MAAM,GAAGJ,YAAY,CAACK,MAAM,CAAA;EAElC,IAAIC,SAAS,GAAG,CAAC,CAAA;EACjB,IAAIC,OAAO,GAAG,CAAC,CAAA;AAEf,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,IAAI,CAACG,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;AACvCF,IAAAA,SAAS,GAAG,CAACA,SAAS,GAAGJ,IAAI,CAACO,UAAU,CAACD,CAAC,CAAC,GAAGD,OAAO,IAAIH,MAAM,CAAA;AAC/DG,IAAAA,OAAO,GAAIA,OAAO,GAAGJ,IAAI,GAAIC,MAAM,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOE,SAAS,CAAA;AAClB,CAAC,CAAA;AAEYI,MAAAA,qBAAqB,GAAIR,IAAY,IAAmC;AACnF,EAAA,OAAOF,YAAY,CAACC,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;AACrC;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getInitials(name) {
|
|
4
|
+
const allInitials = name.split(' ').map(part => part[0]).join('').toUpperCase();
|
|
5
|
+
if (allInitials.length === 1) {
|
|
6
|
+
return allInitials[0];
|
|
7
|
+
}
|
|
8
|
+
return allInitials[0] + allInitials.slice(-1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.getInitials = getInitials;
|
|
12
|
+
//# sourceMappingURL=initials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initials.js","sources":["../../src/common/initials.ts"],"sourcesContent":["export function getInitials(name: string) {\n const allInitials = name\n .split(' ')\n .map((part) => part[0])\n .join('')\n .toUpperCase();\n\n if (allInitials.length === 1) {\n return allInitials[0];\n }\n\n return allInitials[0] + allInitials.slice(-1);\n}\n"],"names":["getInitials","name","allInitials","split","map","part","join","toUpperCase","length","slice"],"mappings":";;AAAM,SAAUA,WAAWA,CAACC,IAAY,EAAA;EACtC,MAAMC,WAAW,GAAGD,IAAI,CACrBE,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAAC,CAAC,CAAC,CAAC,CACtBC,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE,CAAA;AAEhB,EAAA,IAAIL,WAAW,CAACM,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAON,WAAW,CAAC,CAAC,CAAC,CAAA;AACvB,GAAA;EAEA,OAAOA,WAAW,CAAC,CAAC,CAAC,GAAGA,WAAW,CAACO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/C;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function getInitials(name) {
|
|
2
|
+
const allInitials = name.split(' ').map(part => part[0]).join('').toUpperCase();
|
|
3
|
+
if (allInitials.length === 1) {
|
|
4
|
+
return allInitials[0];
|
|
5
|
+
}
|
|
6
|
+
return allInitials[0] + allInitials.slice(-1);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { getInitials };
|
|
10
|
+
//# sourceMappingURL=initials.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initials.mjs","sources":["../../src/common/initials.ts"],"sourcesContent":["export function getInitials(name: string) {\n const allInitials = name\n .split(' ')\n .map((part) => part[0])\n .join('')\n .toUpperCase();\n\n if (allInitials.length === 1) {\n return allInitials[0];\n }\n\n return allInitials[0] + allInitials.slice(-1);\n}\n"],"names":["getInitials","name","allInitials","split","map","part","join","toUpperCase","length","slice"],"mappings":"AAAM,SAAUA,WAAWA,CAACC,IAAY,EAAA;EACtC,MAAMC,WAAW,GAAGD,IAAI,CACrBE,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAAC,CAAC,CAAC,CAAC,CACtBC,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE,CAAA;AAEhB,EAAA,IAAIL,WAAW,CAACM,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAON,WAAW,CAAC,CAAC,CAAC,CAAA;AACvB,GAAA;EAEA,OAAOA,WAAW,CAAC,CAAC,CAAC,GAAGA,WAAW,CAACO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/C;;;;"}
|
package/build/display/Display.js
CHANGED
|
@@ -13,7 +13,7 @@ function Display({
|
|
|
13
13
|
}) {
|
|
14
14
|
return /*#__PURE__*/jsxRuntime.jsx(Heading, {
|
|
15
15
|
id: id,
|
|
16
|
-
className: clsx.clsx(`np-text-${type}`, 'text-primary', className),
|
|
16
|
+
className: clsx.clsx('np-display', `np-text-${type}`, 'text-primary', className),
|
|
17
17
|
children: children
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Display.js","sources":["../../src/display/Display.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { PropsWithChildren } from 'react';\n\nimport { DisplayTypes, Typography } from '../common';\n\ntype Props = PropsWithChildren<{\n as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n id?: string;\n type?: DisplayTypes;\n className?: string;\n}>;\n\nfunction Display({\n as: Heading = 'h1',\n type = Typography.DISPLAY_LARGE,\n children,\n className,\n id,\n}: Props) {\n return (\n <Heading id={id} className={clsx(`np-text-${type}`, 'text-primary', className)}>\n {children}\n </Heading>\n );\n}\n\nexport default Display;\n"],"names":["Display","as","Heading","type","Typography","DISPLAY_LARGE","children","className","id","_jsx","clsx"],"mappings":";;;;;;AAYA,SAASA,OAAOA,CAAC;EACfC,EAAE,EAAEC,OAAO,GAAG,IAAI;EAClBC,IAAI,GAAGC,qBAAU,CAACC,aAAa;EAC/BC,QAAQ;EACRC,SAAS;AACTC,EAAAA,EAAAA;AACM,CAAA,EAAA;EACN,oBACEC,cAAA,CAACP,OAAO,EAAA;AAACM,IAAAA,EAAE,EAAEA,EAAG;
|
|
1
|
+
{"version":3,"file":"Display.js","sources":["../../src/display/Display.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { PropsWithChildren } from 'react';\n\nimport { DisplayTypes, Typography } from '../common';\n\ntype Props = PropsWithChildren<{\n as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n id?: string;\n type?: DisplayTypes;\n className?: string;\n}>;\n\nfunction Display({\n as: Heading = 'h1',\n type = Typography.DISPLAY_LARGE,\n children,\n className,\n id,\n}: Props) {\n return (\n <Heading id={id} className={clsx('np-display', `np-text-${type}`, 'text-primary', className)}>\n {children}\n </Heading>\n );\n}\n\nexport default Display;\n"],"names":["Display","as","Heading","type","Typography","DISPLAY_LARGE","children","className","id","_jsx","clsx"],"mappings":";;;;;;AAYA,SAASA,OAAOA,CAAC;EACfC,EAAE,EAAEC,OAAO,GAAG,IAAI;EAClBC,IAAI,GAAGC,qBAAU,CAACC,aAAa;EAC/BC,QAAQ;EACRC,SAAS;AACTC,EAAAA,EAAAA;AACM,CAAA,EAAA;EACN,oBACEC,cAAA,CAACP,OAAO,EAAA;AAACM,IAAAA,EAAE,EAAEA,EAAG;AAACD,IAAAA,SAAS,EAAEG,SAAI,CAAC,YAAY,EAAE,CAAA,QAAA,EAAWP,IAAI,CAAA,CAAE,EAAE,cAAc,EAAEI,SAAS,CAAE;AAAAD,IAAAA,QAAA,EAC1FA,QAAAA;AAAQ,GACF,CAAC,CAAA;AAEd;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Display.mjs","sources":["../../src/display/Display.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { PropsWithChildren } from 'react';\n\nimport { DisplayTypes, Typography } from '../common';\n\ntype Props = PropsWithChildren<{\n as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n id?: string;\n type?: DisplayTypes;\n className?: string;\n}>;\n\nfunction Display({\n as: Heading = 'h1',\n type = Typography.DISPLAY_LARGE,\n children,\n className,\n id,\n}: Props) {\n return (\n <Heading id={id} className={clsx(`np-text-${type}`, 'text-primary', className)}>\n {children}\n </Heading>\n );\n}\n\nexport default Display;\n"],"names":["Display","as","Heading","type","Typography","DISPLAY_LARGE","children","className","id","_jsx","clsx"],"mappings":";;;;AAYA,SAASA,OAAOA,CAAC;EACfC,EAAE,EAAEC,OAAO,GAAG,IAAI;EAClBC,IAAI,GAAGC,UAAU,CAACC,aAAa;EAC/BC,QAAQ;EACRC,SAAS;AACTC,EAAAA,EAAAA;AACM,CAAA,EAAA;EACN,oBACEC,GAAA,CAACP,OAAO,EAAA;AAACM,IAAAA,EAAE,EAAEA,EAAG;
|
|
1
|
+
{"version":3,"file":"Display.mjs","sources":["../../src/display/Display.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { PropsWithChildren } from 'react';\n\nimport { DisplayTypes, Typography } from '../common';\n\ntype Props = PropsWithChildren<{\n as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n id?: string;\n type?: DisplayTypes;\n className?: string;\n}>;\n\nfunction Display({\n as: Heading = 'h1',\n type = Typography.DISPLAY_LARGE,\n children,\n className,\n id,\n}: Props) {\n return (\n <Heading id={id} className={clsx('np-display', `np-text-${type}`, 'text-primary', className)}>\n {children}\n </Heading>\n );\n}\n\nexport default Display;\n"],"names":["Display","as","Heading","type","Typography","DISPLAY_LARGE","children","className","id","_jsx","clsx"],"mappings":";;;;AAYA,SAASA,OAAOA,CAAC;EACfC,EAAE,EAAEC,OAAO,GAAG,IAAI;EAClBC,IAAI,GAAGC,UAAU,CAACC,aAAa;EAC/BC,QAAQ;EACRC,SAAS;AACTC,EAAAA,EAAAA;AACM,CAAA,EAAA;EACN,oBACEC,GAAA,CAACP,OAAO,EAAA;AAACM,IAAAA,EAAE,EAAEA,EAAG;AAACD,IAAAA,SAAS,EAAEG,IAAI,CAAC,YAAY,EAAE,CAAA,QAAA,EAAWP,IAAI,CAAA,CAAE,EAAE,cAAc,EAAEI,SAAS,CAAE;AAAAD,IAAAA,QAAA,EAC1FA,QAAAA;AAAQ,GACF,CAAC,CAAA;AAEd;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../../src/avatar/Avatar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../../src/avatar/Avatar.tsx"],"names":[],"mappings":"AAOA,KAAK,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEhD,KAAK,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAkBD,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CA4CjC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarWrapper.d.ts","sourceRoot":"","sources":["../../../src/avatarWrapper/AvatarWrapper.tsx"],"names":[],"mappings":"AAGA,OAAe,EAAE,WAAW,EAAc,MAAM,WAAW,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"AvatarWrapper.d.ts","sourceRoot":"","sources":["../../../src/avatarWrapper/AvatarWrapper.tsx"],"names":[],"mappings":"AAGA,OAAe,EAAE,WAAW,EAAc,MAAM,WAAW,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAEL,mBAAmB,EACnB,mBAAmB,EAEnB,SAAS,EAEV,MAAM,WAAW,CAAC;AAuCnB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,GAAG,CACA;IACE,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,eAAe,EAAE,SAAS,CAAC;CAC5B,GACD;IACE,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB,CACJ,CAAC;AAEF,QAAA,MAAM,aAAa,sIAWhB,kBAAkB,gCAoDpB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -6,9 +6,10 @@ export type ActionOptions = {
|
|
|
6
6
|
onClick?: () => void;
|
|
7
7
|
};
|
|
8
8
|
type Props = {
|
|
9
|
+
variant?: 'button' | 'action-button';
|
|
9
10
|
action: ActionOptions;
|
|
10
11
|
className?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function Action({ action, className }: Props): import("react").JSX.Element;
|
|
13
|
+
export declare function Action({ action, className, variant }: Props): import("react").JSX.Element;
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=Action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../../../src/common/action/Action.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../../../src/common/action/Action.tsx"],"names":[],"mappings":"AAMA,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,OAAO,CAAC,EAAE,QAAQ,GAAG,eAAe,CAAC;IACrC,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAkB,EAAE,EAAE,KAAK,+BAmCtE"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const avatarColors: readonly ["var(--color-bright-blue)", "var(--color-bright-yellow)", "var(--color-bright-pink)", "var(--color-bright-orange)"];
|
|
2
|
+
export declare const getBrandColorFromSeed: (seed: string) => (typeof avatarColors)[number];
|
|
3
|
+
export {};
|
|
4
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/common/colors.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,YAAY,+HAKR,CAAC;AAuBX,eAAO,MAAM,qBAAqB,SAAU,MAAM,KAAG,CAAC,OAAO,YAAY,EAAE,MAAM,CAEhF,CAAC"}
|
|
@@ -12,6 +12,8 @@ export * from "./propsValues/profileType";
|
|
|
12
12
|
export * from "./propsValues/scroll";
|
|
13
13
|
export * from "./locale";
|
|
14
14
|
export * from "./commonProps";
|
|
15
|
+
export * from "./initials";
|
|
16
|
+
export * from "./colors";
|
|
15
17
|
export { Breakpoint } from "./propsValues/breakpoint";
|
|
16
18
|
export { Type } from "./propsValues/type";
|
|
17
19
|
export { DateMode } from "./propsValues/dateMode";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initials.d.ts","sourceRoot":"","sources":["../../../src/common/initials.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAYvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.72.
|
|
3
|
+
"version": "46.72.2",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@types/react": "^18.3.11",
|
|
80
80
|
"@types/react-dom": "^18.3.1",
|
|
81
81
|
"@types/react-transition-group": "4.4.10",
|
|
82
|
-
"@wise/art": "^2.
|
|
82
|
+
"@wise/art": "^2.16.3",
|
|
83
83
|
"babel-plugin-formatjs": "^10.5.16",
|
|
84
84
|
"babel-plugin-inline-react-svg": "^2.0.2",
|
|
85
85
|
"enzyme": "^3.11.0",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@transferwise/icons": "^3.13.1",
|
|
100
100
|
"@transferwise/neptune-css": "^14.9.6",
|
|
101
|
-
"@wise/art": "^2.
|
|
101
|
+
"@wise/art": "^2.16",
|
|
102
102
|
"@wise/components-theming": "^1.0.0",
|
|
103
103
|
"react": ">=18",
|
|
104
104
|
"react-dom": ">=18",
|
package/src/alert/Alert.tsx
CHANGED
|
@@ -186,7 +186,7 @@ export default function Alert({
|
|
|
186
186
|
{children || <InlineMarkdown>{message}</InlineMarkdown>}
|
|
187
187
|
</Body>
|
|
188
188
|
</div>
|
|
189
|
-
{action && <Action action={action} className="m-t-1" />}
|
|
189
|
+
{action && <Action action={action} variant="action-button" className="m-t-1" />}
|
|
190
190
|
</div>
|
|
191
191
|
</div>
|
|
192
192
|
{onDismiss && (
|
package/src/avatar/Avatar.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
|
|
4
|
-
import { Theme } from '../common';
|
|
4
|
+
import { getBrandColorFromSeed, Theme } from '../common';
|
|
5
5
|
|
|
6
|
-
import { getAvatarColorFromSeed } from './colors';
|
|
7
6
|
import Circle from '../common/circle';
|
|
8
7
|
|
|
9
8
|
type NumericAvatarSize = 24 | 40 | 48 | 56 | 72;
|
|
@@ -58,7 +57,7 @@ const Avatar: React.FC<AvatarProps> = ({
|
|
|
58
57
|
const backgroundColorFromSeed = useMemo<string | undefined>(
|
|
59
58
|
() =>
|
|
60
59
|
!backgroundColor && backgroundColorSeed
|
|
61
|
-
?
|
|
60
|
+
? getBrandColorFromSeed(backgroundColorSeed)
|
|
62
61
|
: undefined,
|
|
63
62
|
[backgroundColor, backgroundColorSeed],
|
|
64
63
|
);
|
|
@@ -3,7 +3,14 @@ import { useState, useEffect } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import Avatar, { AvatarProps, AvatarType } from '../avatar';
|
|
5
5
|
import Badge, { BadgeProps } from '../badge';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ProfileType,
|
|
8
|
+
ProfileTypePersonal,
|
|
9
|
+
ProfileTypeBusiness,
|
|
10
|
+
Size,
|
|
11
|
+
Sentiment,
|
|
12
|
+
getInitials,
|
|
13
|
+
} from '../common';
|
|
7
14
|
import StatusIcon from '../statusIcon/StatusIcon';
|
|
8
15
|
|
|
9
16
|
interface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {
|
|
@@ -133,18 +140,4 @@ const AvatarWrapper = ({
|
|
|
133
140
|
);
|
|
134
141
|
};
|
|
135
142
|
|
|
136
|
-
function getInitials(name: string) {
|
|
137
|
-
const allInitials = name
|
|
138
|
-
.split(' ')
|
|
139
|
-
.map((part) => part[0])
|
|
140
|
-
.join('')
|
|
141
|
-
.toUpperCase();
|
|
142
|
-
|
|
143
|
-
if (allInitials.length === 1) {
|
|
144
|
-
return allInitials[0];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return allInitials[0] + allInitials.slice(-1);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
143
|
export default AvatarWrapper;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import Link from '../../link';
|
|
3
3
|
import { Typography } from '../propsValues/typography';
|
|
4
|
+
import ActionButton from '../../actionButton';
|
|
5
|
+
import { Priority } from '../propsValues/control';
|
|
4
6
|
|
|
5
7
|
export type ActionOptions = {
|
|
6
8
|
'aria-label'?: string;
|
|
@@ -11,11 +13,12 @@ export type ActionOptions = {
|
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
type Props = {
|
|
16
|
+
variant?: 'button' | 'action-button';
|
|
14
17
|
action: ActionOptions;
|
|
15
18
|
className?: string;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
export function Action({ action, className }: Props) {
|
|
21
|
+
export function Action({ action, className, variant = 'button' }: Props) {
|
|
19
22
|
if ('href' in action) {
|
|
20
23
|
return (
|
|
21
24
|
<Link
|
|
@@ -31,7 +34,7 @@ export function Action({ action, className }: Props) {
|
|
|
31
34
|
);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
return (
|
|
37
|
+
return variant === 'button' ? (
|
|
35
38
|
<button
|
|
36
39
|
type="button"
|
|
37
40
|
aria-label={action['aria-label']}
|
|
@@ -40,5 +43,14 @@ export function Action({ action, className }: Props) {
|
|
|
40
43
|
>
|
|
41
44
|
{action.text}
|
|
42
45
|
</button>
|
|
46
|
+
) : (
|
|
47
|
+
<ActionButton
|
|
48
|
+
aria-label={action['aria-label']}
|
|
49
|
+
priority={Priority.SECONDARY}
|
|
50
|
+
className={clsx(className)}
|
|
51
|
+
onClick={action.onClick}
|
|
52
|
+
>
|
|
53
|
+
{action.text}
|
|
54
|
+
</ActionButton>
|
|
43
55
|
);
|
|
44
56
|
}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* Do not change this array.
|
|
5
5
|
*/
|
|
6
6
|
const avatarColors = [
|
|
7
|
-
'--color-bright-blue',
|
|
8
|
-
'--color-bright-yellow',
|
|
9
|
-
'--color-bright-pink',
|
|
10
|
-
'--color-bright-orange',
|
|
7
|
+
'var(--color-bright-blue)',
|
|
8
|
+
'var(--color-bright-yellow)',
|
|
9
|
+
'var(--color-bright-pink)',
|
|
10
|
+
'var(--color-bright-orange)',
|
|
11
11
|
] as const;
|
|
12
12
|
|
|
13
13
|
/*
|
|
@@ -31,6 +31,6 @@ const hashSeed = (seed: string): number => {
|
|
|
31
31
|
return hashValue;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const
|
|
34
|
+
export const getBrandColorFromSeed = (seed: string): (typeof avatarColors)[number] => {
|
|
35
35
|
return avatarColors[hashSeed(seed)];
|
|
36
36
|
};
|
package/src/common/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getInitials(name: string) {
|
|
2
|
+
const allInitials = name
|
|
3
|
+
.split(' ')
|
|
4
|
+
.map((part) => part[0])
|
|
5
|
+
.join('')
|
|
6
|
+
.toUpperCase();
|
|
7
|
+
|
|
8
|
+
if (allInitials.length === 1) {
|
|
9
|
+
return allInitials[0];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return allInitials[0] + allInitials.slice(-1);
|
|
13
|
+
}
|
package/src/display/Display.tsx
CHANGED
|
@@ -18,7 +18,7 @@ function Display({
|
|
|
18
18
|
id,
|
|
19
19
|
}: Props) {
|
|
20
20
|
return (
|
|
21
|
-
<Heading id={id} className={clsx(`np-text-${type}`, 'text-primary', className)}>
|
|
21
|
+
<Heading id={id} className={clsx('np-display', `np-text-${type}`, 'text-primary', className)}>
|
|
22
22
|
{children}
|
|
23
23
|
</Heading>
|
|
24
24
|
);
|
|
@@ -17,7 +17,7 @@ exports[`PromoCardGroup matches snapshot 1`] = `
|
|
|
17
17
|
tabindex="0"
|
|
18
18
|
>
|
|
19
19
|
<h3
|
|
20
|
-
class="np-text-display-small text-primary np-Card-title"
|
|
20
|
+
class="np-display np-text-display-small text-primary np-Card-title"
|
|
21
21
|
id="radio-1-title"
|
|
22
22
|
>
|
|
23
23
|
Test Card
|
|
@@ -51,7 +51,7 @@ exports[`PromoCardGroup matches snapshot 1`] = `
|
|
|
51
51
|
tabindex="0"
|
|
52
52
|
>
|
|
53
53
|
<h3
|
|
54
|
-
class="np-text-display-small text-primary np-Card-title"
|
|
54
|
+
class="np-display np-text-display-small text-primary np-Card-title"
|
|
55
55
|
id="radio-2-title"
|
|
56
56
|
>
|
|
57
57
|
Test Card
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.js","sources":["../../../src/avatar/colors/colors.ts"],"sourcesContent":["/*\n * The colors we support generating an Avatar background color from a \"seed\" for.\n * Changing this array will change the assignment between seeds.\n * Do not change this array.\n */\nconst avatarColors = [\n '--color-bright-blue',\n '--color-bright-yellow',\n '--color-bright-pink',\n '--color-bright-orange',\n] as const;\n\n/*\n * Takes in a \"seed\" string and spits out an index for the color we should use.\n * This implementation has been synced across all three clients so that we consistently\n * generate branded avatar colors when rendering a list of Avatars.\n * Do not change this implementation.\n */\nconst hashSeed = (seed: string): number => {\n const base = 31;\n const modulo = avatarColors.length;\n\n let hashValue = 0;\n let basePow = 1;\n\n for (let i = 0; i < seed.length; i += 1) {\n hashValue = (hashValue + seed.charCodeAt(i) * basePow) % modulo;\n basePow = (basePow * base) % modulo;\n }\n\n return hashValue;\n};\n\nexport const getAvatarColorFromSeed = (seed: string): (typeof avatarColors)[number] => {\n return avatarColors[hashSeed(seed)];\n};\n"],"names":["avatarColors","hashSeed","seed","base","modulo","length","hashValue","basePow","i","charCodeAt","getAvatarColorFromSeed"],"mappings":";;AAAA;;;;AAIG;AACH,MAAMA,YAAY,GAAG,CACnB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,CACf,CAAA;AAEV;;;;;AAKG;AACH,MAAMC,QAAQ,GAAIC,IAAY,IAAY;EACxC,MAAMC,IAAI,GAAG,EAAE,CAAA;AACf,EAAA,MAAMC,MAAM,GAAGJ,YAAY,CAACK,MAAM,CAAA;EAElC,IAAIC,SAAS,GAAG,CAAC,CAAA;EACjB,IAAIC,OAAO,GAAG,CAAC,CAAA;AAEf,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,IAAI,CAACG,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;AACvCF,IAAAA,SAAS,GAAG,CAACA,SAAS,GAAGJ,IAAI,CAACO,UAAU,CAACD,CAAC,CAAC,GAAGD,OAAO,IAAIH,MAAM,CAAA;AAC/DG,IAAAA,OAAO,GAAIA,OAAO,GAAGJ,IAAI,GAAIC,MAAM,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOE,SAAS,CAAA;AAClB,CAAC,CAAA;AAEYI,MAAAA,sBAAsB,GAAIR,IAAY,IAAmC;AACpF,EAAA,OAAOF,YAAY,CAACC,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;AACrC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.mjs","sources":["../../../src/avatar/colors/colors.ts"],"sourcesContent":["/*\n * The colors we support generating an Avatar background color from a \"seed\" for.\n * Changing this array will change the assignment between seeds.\n * Do not change this array.\n */\nconst avatarColors = [\n '--color-bright-blue',\n '--color-bright-yellow',\n '--color-bright-pink',\n '--color-bright-orange',\n] as const;\n\n/*\n * Takes in a \"seed\" string and spits out an index for the color we should use.\n * This implementation has been synced across all three clients so that we consistently\n * generate branded avatar colors when rendering a list of Avatars.\n * Do not change this implementation.\n */\nconst hashSeed = (seed: string): number => {\n const base = 31;\n const modulo = avatarColors.length;\n\n let hashValue = 0;\n let basePow = 1;\n\n for (let i = 0; i < seed.length; i += 1) {\n hashValue = (hashValue + seed.charCodeAt(i) * basePow) % modulo;\n basePow = (basePow * base) % modulo;\n }\n\n return hashValue;\n};\n\nexport const getAvatarColorFromSeed = (seed: string): (typeof avatarColors)[number] => {\n return avatarColors[hashSeed(seed)];\n};\n"],"names":["avatarColors","hashSeed","seed","base","modulo","length","hashValue","basePow","i","charCodeAt","getAvatarColorFromSeed"],"mappings":"AAAA;;;;AAIG;AACH,MAAMA,YAAY,GAAG,CACnB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,CACf,CAAA;AAEV;;;;;AAKG;AACH,MAAMC,QAAQ,GAAIC,IAAY,IAAY;EACxC,MAAMC,IAAI,GAAG,EAAE,CAAA;AACf,EAAA,MAAMC,MAAM,GAAGJ,YAAY,CAACK,MAAM,CAAA;EAElC,IAAIC,SAAS,GAAG,CAAC,CAAA;EACjB,IAAIC,OAAO,GAAG,CAAC,CAAA;AAEf,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,IAAI,CAACG,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;AACvCF,IAAAA,SAAS,GAAG,CAACA,SAAS,GAAGJ,IAAI,CAACO,UAAU,CAACD,CAAC,CAAC,GAAGD,OAAO,IAAIH,MAAM,CAAA;AAC/DG,IAAAA,OAAO,GAAIA,OAAO,GAAGJ,IAAI,GAAIC,MAAM,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOE,SAAS,CAAA;AAClB,CAAC,CAAA;AAEYI,MAAAA,sBAAsB,GAAIR,IAAY,IAAmC;AACpF,EAAA,OAAOF,YAAY,CAACC,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;AACrC;;;;"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
declare const avatarColors: readonly ["--color-bright-blue", "--color-bright-yellow", "--color-bright-pink", "--color-bright-orange"];
|
|
2
|
-
export declare const getAvatarColorFromSeed: (seed: string) => (typeof avatarColors)[number];
|
|
3
|
-
export {};
|
|
4
|
-
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../../src/avatar/colors/colors.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,YAAY,2GAKR,CAAC;AAuBX,eAAO,MAAM,sBAAsB,SAAU,MAAM,KAAG,CAAC,OAAO,YAAY,EAAE,MAAM,CAEjF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/avatar/colors/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './colors';
|