@pega/cosmos-react-core 2.1.1 → 3.0.0-dev.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppShell/Operator.d.ts.map +1 -1
- package/lib/components/AppShell/Operator.js +1 -1
- package/lib/components/AppShell/Operator.js.map +1 -1
- package/lib/components/Avatar/Avatar.d.ts +5 -1
- package/lib/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/components/Avatar/Avatar.js +13 -8
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/Configuration/Configuration.js +1 -1
- package/lib/components/Configuration/Configuration.js.map +1 -1
- package/lib/components/EmojiPicker/EmojiDisplay.d.ts.map +1 -1
- package/lib/components/EmojiPicker/EmojiDisplay.js +1 -1
- package/lib/components/EmojiPicker/EmojiDisplay.js.map +1 -1
- package/lib/components/FormField/FormField.d.ts +10 -0
- package/lib/components/FormField/FormField.d.ts.map +1 -1
- package/lib/components/FormField/FormField.js +2 -2
- package/lib/components/FormField/FormField.js.map +1 -1
- package/lib/components/Label/Label.d.ts +6 -1
- package/lib/components/Label/Label.d.ts.map +1 -1
- package/lib/components/Label/Label.js +2 -2
- package/lib/components/Label/Label.js.map +1 -1
- package/lib/components/Modal/MinimizedModal.js +5 -5
- package/lib/components/Modal/MinimizedModal.js.map +1 -1
- package/lib/components/Number/NumberDisplay.js +1 -1
- package/lib/components/Number/NumberDisplay.js.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.js +1 -1
- package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js.map +1 -1
- package/lib/hooks/useArrows.d.ts +2 -2
- package/lib/hooks/useArrows.d.ts.map +1 -1
- package/lib/hooks/useArrows.js +19 -12
- package/lib/hooks/useArrows.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +6 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/i18n/default.d.ts +6 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +8 -1
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +12 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/utils/utils.d.ts.map +1 -1
- package/lib/utils/utils.js +3 -1
- package/lib/utils/utils.js.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operator.d.ts","sourceRoot":"","sources":["../../../src/components/AppShell/Operator.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,SAAS,EAAuB,MAAM,OAAO,CAAC;AAIjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,QAAA,MAAM,QAAQ;cAQE,SAAS;aACV,aAAa,CAAC,SAAS,CAAC;;
|
|
1
|
+
{"version":3,"file":"Operator.d.ts","sourceRoot":"","sources":["../../../src/components/AppShell/Operator.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAO,SAAS,EAAuB,MAAM,OAAO,CAAC;AAIjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,QAAA,MAAM,QAAQ;cAQE,SAAS;aACV,aAAa,CAAC,SAAS,CAAC;;8DA+DtC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -21,7 +21,7 @@ const Operator = forwardRef(({ children, actions, popover, as }, ref) => {
|
|
|
21
21
|
if (!navOpen)
|
|
22
22
|
setShowMenu(false);
|
|
23
23
|
}, [navOpen]);
|
|
24
|
-
return (_jsxs(_Fragment, { children: [_jsx(BareButton, { as: as, ref: buttonRef, onClick: () => {
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx(BareButton, { as: as, ref: buttonRef, "aria-expanded": showMenu ? 'true' : 'false', "aria-haspopup": 'menu', onClick: () => {
|
|
25
25
|
setShowMenu(cur => !cur);
|
|
26
26
|
}, onKeyDown: (e) => {
|
|
27
27
|
if (e.key === 'Escape')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operator.js","sourceRoot":"","sources":["../../../src/components/AppShell/Operator.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG7E,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAGhD,MAAM,QAAQ,GAAG,UAAU,CACzB,CACE,EACE,QAAQ,EACR,OAAO,EACP,OAAO,EACP,EAAE,EAKM,EACV,GAAuC,EACvC,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAE1C,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,EAAE;QACrC,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACpE,EAAE;YACF,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,KAAK;YACd,GAAG,IAAI;SACR,CAAC,CAAC,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AC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useState, useEffect, useContext, useMemo } from 'react';\nimport type { Ref, ReactNode, MouseEvent, UIEvent } from 'react';\n\nimport BareButton from '../Button/BareButton';\nimport Popover from '../Popover';\nimport type { PopoverProps } from '../Popover';\nimport Menu from '../Menu';\nimport type { AcceptedMouseEventElement } from '../Menu/Menu.types';\nimport { useConsolidatedRef } from '../../hooks';\nimport type { AsProp, OmitStrict } from '../../types';\n\nimport AppShellContext from './AppShellContext';\nimport { OperatorProps } from './AppShell.types';\n\nconst Operator = forwardRef(\n (\n {\n children,\n actions,\n popover,\n as\n }: {\n children: ReactNode;\n actions: OperatorProps['actions'];\n popover?: OmitStrict<PopoverProps, 'show' | 'target' | 'children'>;\n } & AsProp,\n ref: Ref<HTMLButtonElement> | undefined\n ) => {\n const { navOpen } = useContext(AppShellContext);\n const buttonRef = useConsolidatedRef(ref);\n\n const operatorMenuItems = useMemo(() => {\n return actions.flat().map(({ id, text, onClick: click, ...rest }) => ({\n id,\n primary: text,\n onClick: click,\n ...rest\n }));\n }, [actions]);\n\n const [showMenu, setShowMenu] = useState(false);\n\n useEffect(() => {\n if (!navOpen) setShowMenu(false);\n }, [navOpen]);\n\n return (\n <>\n <BareButton\n as={as}\n ref={buttonRef}\n aria-expanded={showMenu ? 'true' : 'false'}\n aria-haspopup='menu'\n onClick={() => {\n setShowMenu(cur => !cur);\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Escape') setShowMenu(false);\n }}\n onBlur={() => {\n setShowMenu(false);\n }}\n >\n {children}\n </BareButton>\n <Popover {...popover} show={showMenu} target={buttonRef.current}>\n <Menu\n focusControlEl={buttonRef.current ?? undefined}\n mode='action'\n items={operatorMenuItems}\n /**\n * @see {@link MenuButton} implementation for explanation of conditions. This is in essence duplicated.\n */\n onItemClick={(_, e) => {\n if (\n (e as MouseEvent<AcceptedMouseEventElement> & UIEvent<AcceptedMouseEventElement>)\n .detail > 0\n ) {\n setShowMenu(false);\n }\n }}\n />\n </Popover>\n </>\n );\n }\n);\n\nexport default Operator;\n"]}
|
|
@@ -7,6 +7,10 @@ export interface AvatarProps extends BaseProps, NoChildrenProp {
|
|
|
7
7
|
imageSrc?: string;
|
|
8
8
|
/** An icon to render as the content of the avatar. imageSrc will take precedence if passed. */
|
|
9
9
|
icon?: string;
|
|
10
|
+
/** Optional color for the icon to be rendered */
|
|
11
|
+
color?: string;
|
|
12
|
+
/** Optional background color for the avatar. Will be auto computed if not passed */
|
|
13
|
+
backgroundColor?: string;
|
|
10
14
|
/**
|
|
11
15
|
* Shape of the Avatar.
|
|
12
16
|
* @default "circle"
|
|
@@ -16,7 +20,7 @@ export interface AvatarProps extends BaseProps, NoChildrenProp {
|
|
|
16
20
|
* Avatar size.
|
|
17
21
|
* @default "m"
|
|
18
22
|
*/
|
|
19
|
-
size?: 's' | 'm' | 'l';
|
|
23
|
+
size?: 's' | 'm' | 'l' | 'xl';
|
|
20
24
|
/** If defined, will render status icon on the avatar. */
|
|
21
25
|
status?: 'active';
|
|
22
26
|
/** Optional error handler in the event an image fails to load. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../../src/components/Avatar/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,GAAG,EAEH,cAAc,EAIf,MAAM,OAAO,CAAC;AAKf,OAAO,EACL,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,UAAU,EACX,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,WAAY,SAAQ,SAAS,EAAE,cAAc;IAC5D,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ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AY,4IA0BvB,CAAC;AAmBH;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,iBAAiB,CAAC,WAAW,GAAG,YAAY,CAyDzD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -11,17 +11,20 @@ import { tryCatch } from '../../utils';
|
|
|
11
11
|
const sizeToRem = {
|
|
12
12
|
s: 1,
|
|
13
13
|
m: 2,
|
|
14
|
-
l: 2.5
|
|
14
|
+
l: 2.5,
|
|
15
|
+
xl: 4
|
|
15
16
|
};
|
|
16
17
|
const fontSizeToRem = {
|
|
17
18
|
s: 0.5625,
|
|
18
19
|
m: 0.8125,
|
|
19
|
-
l: 1
|
|
20
|
+
l: 1,
|
|
21
|
+
xl: 1.5
|
|
20
22
|
};
|
|
21
23
|
const sizeToBorderRadius = {
|
|
22
24
|
s: 0.25,
|
|
23
25
|
m: 0.5,
|
|
24
|
-
l: 1
|
|
26
|
+
l: 1,
|
|
27
|
+
xl: 1
|
|
25
28
|
};
|
|
26
29
|
export const StyledAvatarImage = styled(Image) `
|
|
27
30
|
min-height: 100%;
|
|
@@ -30,16 +33,18 @@ export const StyledAvatarImage = styled(Image) `
|
|
|
30
33
|
object-fit: cover;
|
|
31
34
|
border-radius: inherit;
|
|
32
35
|
`;
|
|
33
|
-
export const StyledAvatar = styled.div(({ hasBrokenImage, hasSrc, size, shape, theme: { base: { palette: { 'foreground-color': foregroundColor, 'primary-background': primaryBackground } }, components: { avatar } } }) => {
|
|
36
|
+
export const StyledAvatar = styled.div(({ hasBrokenImage, hasSrc, size, shape, color, backgroundColor, theme: { base: { palette: { 'foreground-color': foregroundColor, 'primary-background': primaryBackground } }, components: { avatar } } }) => {
|
|
34
37
|
const sizeRem = sizeToRem[size];
|
|
35
38
|
const fontSize = fontSizeToRem[size];
|
|
36
|
-
|
|
39
|
+
let bgColor = hasSrc && !hasBrokenImage ? primaryBackground : backgroundColor || avatar['background-color'];
|
|
40
|
+
if (color && !backgroundColor && !(hasSrc && !hasBrokenImage))
|
|
41
|
+
bgColor = tryCatch(() => readableColor(color), () => avatar['background-color']);
|
|
37
42
|
const shadowColor = tryCatch(() => rgba(foregroundColor, 0.1));
|
|
38
|
-
const
|
|
43
|
+
const iconColor = color || tryCatch(() => readableColor(bgColor));
|
|
39
44
|
return css `
|
|
40
45
|
position: relative;
|
|
41
|
-
background-color: ${
|
|
42
|
-
color: ${
|
|
46
|
+
background-color: ${bgColor};
|
|
47
|
+
color: ${iconColor};
|
|
43
48
|
width: ${sizeRem}rem;
|
|
44
49
|
height: ${sizeRem}rem;
|
|
45
50
|
min-width: ${sizeRem}rem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../../../src/components/Avatar/Avatar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,MAAM,UAAU,CAAC;AAQ7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA6BvC,MAAM,SAAS,GAAG;IAChB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;CACP,CAAC;AAEF,MAAM,aAAa,GAAG;IACpB,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,kBAAkB,GAAG;IAC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C,KAAK,IAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAC,SAAS,WAAG,YACpE,CAChB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n FunctionComponent,\n forwardRef,\n Ref,\n PropsWithoutRef,\n SyntheticEvent,\n useState,\n useEffect,\n useMemo\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { readableColor, rgba } from 'polished';\n\nimport Image from '../Image';\nimport {\n BaseProps,\n ForwardProps,\n PropsWithDefaults,\n NoChildrenProp,\n OmitStrict\n} from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Icon, { StyledIcon } from '../Icon';\nimport { Alert } from '../Badges';\nimport { useI18n } from '../../hooks';\nimport { tryCatch } from '../../utils';\n\nexport interface AvatarProps extends BaseProps, NoChildrenProp {\n /** The name of the identity the Avatar represents. */\n name: string;\n /** Content of the Avatar as an image source url. */\n imageSrc?: string;\n /** An icon to render as the content of the avatar. imageSrc will take precedence if passed. */\n icon?: string;\n /**\n * Shape of the Avatar.\n * @default \"circle\"\n */\n shape?: 'circle' | 'squircle';\n /**\n * Avatar size.\n * @default \"m\"\n */\n size?: 's' | 'm' | 'l';\n /** If defined, will render status icon on the avatar. */\n status?: 'active';\n /** Optional error handler in the event an image fails to load. */\n onImageError?: (err: SyntheticEvent<HTMLImageElement>) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement | HTMLImageElement>;\n}\n\ntype AvatarPropsWithDefaults = PropsWithDefaults<AvatarProps, 'shape' | 'size'>;\n\nconst sizeToRem = {\n s: 1,\n m: 2,\n l: 2.5\n};\n\nconst fontSizeToRem = {\n s: 0.5625,\n m: 0.8125,\n l: 1\n};\n\nconst sizeToBorderRadius = {\n s: 0.25,\n m: 0.5,\n l: 1\n};\n\nexport const StyledAvatarImage = styled(Image)`\n min-height: 100%;\n min-width: 100%;\n aspect-ratio: 1 / 1;\n object-fit: cover;\n border-radius: inherit;\n`;\n\nexport const StyledAvatar = styled.div<\n OmitStrict<AvatarPropsWithDefaults, 'name' | 'children'> & {\n hasSrc?: boolean;\n hasBrokenImage?: boolean;\n }\n>(\n ({\n hasBrokenImage,\n hasSrc,\n size,\n shape,\n theme: {\n base: {\n palette: { 'foreground-color': foregroundColor, 'primary-background': primaryBackground }\n },\n components: { avatar }\n }\n }) => {\n const sizeRem = sizeToRem[size];\n const fontSize = fontSizeToRem[size];\n const backgroundColor =\n hasSrc && !hasBrokenImage ? primaryBackground : avatar['background-color'];\n const shadowColor = tryCatch(() => rgba(foregroundColor, 0.1));\n const color = tryCatch(() => readableColor(avatar['background-color']));\n\n return css`\n position: relative;\n background-color: ${backgroundColor};\n color: ${color};\n width: ${sizeRem}rem;\n height: ${sizeRem}rem;\n min-width: ${sizeRem}rem;\n min-height: ${sizeRem}rem;\n font-size: ${fontSize}rem;\n text-transform: uppercase;\n line-height: ${sizeRem}rem;\n text-align: center;\n vertical-align: top;\n display: inline-block;\n border-radius: 100%;\n user-select: none;\n -webkit-user-select: none;\n\n ${shape === 'squircle' &&\n css`\n border-radius: calc(${sizeToBorderRadius[size]} * ${avatar['border-radius']});\n `}\n\n ${StyledIcon} {\n width: 50%;\n height: 100%;\n vertical-align: initial;\n }\n\n ::after {\n content: '';\n position: absolute;\n inset: 0;\n border-radius: inherit;\n pointer-events: none;\n box-shadow: inset 0 0 0 0.0625rem ${shadowColor};\n }\n `;\n }\n);\n\nStyledAvatar.defaultProps = defaultThemeProp;\n\nexport const StyledStatus = styled.div<Pick<AvatarPropsWithDefaults, 'size'>>(({ size, theme }) => {\n /** Scales alert badge dimensions based on size of avatar */\n const sizeDimensions = (0.625 * sizeToRem[size]) / sizeToRem.m;\n\n return css`\n position: absolute;\n height: ${sizeDimensions}rem;\n width: ${sizeDimensions}rem;\n inset-block-end: 0;\n inset-inline-end: 0;\n z-index: 1;\n animation: pop calc(${theme.base.animation.speed} * 2) cubic-bezier(1, 1.65, 0.3, 1.24);\n\n @keyframes pop {\n 0% {\n opacity: 0;\n transform: scale(0);\n }\n 50% {\n opacity: 1;\n }\n 100% {\n transform: scale(1);\n }\n }\n `;\n});\n\nStyledStatus.defaultProps = defaultThemeProp;\n\n/**\n * Helper function to construct a two or one letter initial from the title prop.\n * This text will be displayed if no valid image source is provided.\n * @param name\n * @param size\n */\nconst getInitials = (name: AvatarProps['name'], size: AvatarProps['size']) => {\n const words = name.split(' ');\n const firstInitial = words[0].slice(0, 1);\n\n return words.length === 1 || size === 's'\n ? firstInitial\n : `${firstInitial}${words[1].slice(0, 1)}`;\n};\n\n/**\n * Generally, avatars are used to distinguish between different operators and\n * objects when they are shown in a list or in a small space. Users of applications\n * can upload a custom avatar of their choice.\n */\nconst Avatar: FunctionComponent<AvatarProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<AvatarProps>, ref: Ref<HTMLDivElement | HTMLImageElement>) => {\n const {\n shape = 'circle',\n size = 'm',\n imageSrc,\n icon,\n name,\n status,\n onImageError,\n ...restProps\n } = props;\n const [hasBrokenImage, setHasBrokenImage] = useState<undefined | boolean>();\n const t = useI18n();\n\n useEffect(() => {\n setHasBrokenImage(undefined);\n }, [imageSrc]);\n\n const content = useMemo(() => {\n if (icon) {\n return <Icon name={icon} />;\n }\n if (imageSrc && !hasBrokenImage) {\n return (\n <StyledAvatarImage\n src={imageSrc}\n alt={name}\n onError={(e: SyntheticEvent<HTMLImageElement>) => {\n setHasBrokenImage(true);\n onImageError?.(e);\n }}\n onLoad={() => {\n setHasBrokenImage(false);\n }}\n />\n );\n }\n return getInitials(name, size);\n }, [imageSrc, name, size, icon, hasBrokenImage, onImageError]);\n\n return (\n <StyledAvatar\n role='img'\n hasSrc={!!imageSrc}\n hasBrokenImage={hasBrokenImage}\n shape={shape}\n size={size}\n ref={ref}\n aria-label={`${name}${status ? ` ${t('status')} ${status}` : ''}`}\n {...restProps}\n >\n {content}\n {status === 'active' && <Alert as={StyledStatus} size={size} variant='success' />}\n </StyledAvatar>\n );\n }\n);\n\nexport default Avatar;\n"]}
|
|
1
|
+
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../../../src/components/Avatar/Avatar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,MAAM,UAAU,CAAC;AAQ7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAiCvC,MAAM,SAAS,GAAG;IAChB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,CAAC;CACN,CAAC;AAEF,MAAM,aAAa,GAAG;IACpB,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,CAAC;IACJ,EAAE,EAAE,GAAG;CACR,CAAC;AAEF,MAAM,kBAAkB,GAAG;IACzB,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,CAAC;IACJ,EAAE,EAAE,CAAC;CACN,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;;;;;;CAM7C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAMpC,CAAC,EACC,cAAc,EACd,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,EACL,eA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AAI,EAAE,OAAO,EAAC,SAAS,WAAG,YACpE,CAChB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n FunctionComponent,\n forwardRef,\n Ref,\n PropsWithoutRef,\n SyntheticEvent,\n useState,\n useEffect,\n useMemo\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { readableColor, rgba } from 'polished';\n\nimport Image from '../Image';\nimport {\n BaseProps,\n ForwardProps,\n PropsWithDefaults,\n NoChildrenProp,\n OmitStrict\n} from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Icon, { StyledIcon } from '../Icon';\nimport { Alert } from '../Badges';\nimport { useI18n } from '../../hooks';\nimport { tryCatch } from '../../utils';\n\nexport interface AvatarProps extends BaseProps, NoChildrenProp {\n /** The name of the identity the Avatar represents. */\n name: string;\n /** Content of the Avatar as an image source url. */\n imageSrc?: string;\n /** An icon to render as the content of the avatar. imageSrc will take precedence if passed. */\n icon?: string;\n /** Optional color for the icon to be rendered */\n color?: string;\n /** Optional background color for the avatar. Will be auto computed if not passed */\n backgroundColor?: string;\n /**\n * Shape of the Avatar.\n * @default \"circle\"\n */\n shape?: 'circle' | 'squircle';\n /**\n * Avatar size.\n * @default \"m\"\n */\n size?: 's' | 'm' | 'l' | 'xl';\n /** If defined, will render status icon on the avatar. */\n status?: 'active';\n /** Optional error handler in the event an image fails to load. */\n onImageError?: (err: SyntheticEvent<HTMLImageElement>) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement | HTMLImageElement>;\n}\n\ntype AvatarPropsWithDefaults = PropsWithDefaults<AvatarProps, 'shape' | 'size'>;\n\nconst sizeToRem = {\n s: 1,\n m: 2,\n l: 2.5,\n xl: 4\n};\n\nconst fontSizeToRem = {\n s: 0.5625,\n m: 0.8125,\n l: 1,\n xl: 1.5\n};\n\nconst sizeToBorderRadius = {\n s: 0.25,\n m: 0.5,\n l: 1,\n xl: 1\n};\n\nexport const StyledAvatarImage = styled(Image)`\n min-height: 100%;\n min-width: 100%;\n aspect-ratio: 1 / 1;\n object-fit: cover;\n border-radius: inherit;\n`;\n\nexport const StyledAvatar = styled.div<\n OmitStrict<AvatarPropsWithDefaults, 'name' | 'children'> & {\n hasSrc?: boolean;\n hasBrokenImage?: boolean;\n }\n>(\n ({\n hasBrokenImage,\n hasSrc,\n size,\n shape,\n color,\n backgroundColor,\n theme: {\n base: {\n palette: { 'foreground-color': foregroundColor, 'primary-background': primaryBackground }\n },\n components: { avatar }\n }\n }) => {\n const sizeRem = sizeToRem[size];\n const fontSize = fontSizeToRem[size];\n let bgColor =\n hasSrc && !hasBrokenImage ? primaryBackground : backgroundColor || avatar['background-color'];\n if (color && !backgroundColor && !(hasSrc && !hasBrokenImage))\n bgColor = tryCatch(\n () => readableColor(color),\n () => avatar['background-color']\n );\n const shadowColor = tryCatch(() => rgba(foregroundColor, 0.1));\n const iconColor = color || tryCatch(() => readableColor(bgColor));\n\n return css`\n position: relative;\n background-color: ${bgColor};\n color: ${iconColor};\n width: ${sizeRem}rem;\n height: ${sizeRem}rem;\n min-width: ${sizeRem}rem;\n min-height: ${sizeRem}rem;\n font-size: ${fontSize}rem;\n text-transform: uppercase;\n line-height: ${sizeRem}rem;\n text-align: center;\n vertical-align: top;\n display: inline-block;\n border-radius: 100%;\n user-select: none;\n -webkit-user-select: none;\n\n ${shape === 'squircle' &&\n css`\n border-radius: calc(${sizeToBorderRadius[size]} * ${avatar['border-radius']});\n `}\n\n ${StyledIcon} {\n width: 50%;\n height: 100%;\n vertical-align: initial;\n }\n\n ::after {\n content: '';\n position: absolute;\n inset: 0;\n border-radius: inherit;\n pointer-events: none;\n box-shadow: inset 0 0 0 0.0625rem ${shadowColor};\n }\n `;\n }\n);\n\nStyledAvatar.defaultProps = defaultThemeProp;\n\nexport const StyledStatus = styled.div<Pick<AvatarPropsWithDefaults, 'size'>>(({ size, theme }) => {\n /** Scales alert badge dimensions based on size of avatar */\n const sizeDimensions = (0.625 * sizeToRem[size]) / sizeToRem.m;\n\n return css`\n position: absolute;\n height: ${sizeDimensions}rem;\n width: ${sizeDimensions}rem;\n inset-block-end: 0;\n inset-inline-end: 0;\n z-index: 1;\n animation: pop calc(${theme.base.animation.speed} * 2) cubic-bezier(1, 1.65, 0.3, 1.24);\n\n @keyframes pop {\n 0% {\n opacity: 0;\n transform: scale(0);\n }\n 50% {\n opacity: 1;\n }\n 100% {\n transform: scale(1);\n }\n }\n `;\n});\n\nStyledStatus.defaultProps = defaultThemeProp;\n\n/**\n * Helper function to construct a two or one letter initial from the title prop.\n * This text will be displayed if no valid image source is provided.\n * @param name\n * @param size\n */\nconst getInitials = (name: AvatarProps['name'], size: AvatarProps['size']) => {\n const words = name.split(' ');\n const firstInitial = words[0].slice(0, 1);\n\n return words.length === 1 || size === 's'\n ? firstInitial\n : `${firstInitial}${words[1].slice(0, 1)}`;\n};\n\n/**\n * Generally, avatars are used to distinguish between different operators and\n * objects when they are shown in a list or in a small space. Users of applications\n * can upload a custom avatar of their choice.\n */\nconst Avatar: FunctionComponent<AvatarProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<AvatarProps>, ref: Ref<HTMLDivElement | HTMLImageElement>) => {\n const {\n shape = 'circle',\n size = 'm',\n imageSrc,\n icon,\n name,\n status,\n onImageError,\n ...restProps\n } = props;\n const [hasBrokenImage, setHasBrokenImage] = useState<undefined | boolean>();\n const t = useI18n();\n\n useEffect(() => {\n setHasBrokenImage(undefined);\n }, [imageSrc]);\n\n const content = useMemo(() => {\n if (icon) {\n return <Icon name={icon} />;\n }\n if (imageSrc && !hasBrokenImage) {\n return (\n <StyledAvatarImage\n src={imageSrc}\n alt={name}\n onError={(e: SyntheticEvent<HTMLImageElement>) => {\n setHasBrokenImage(true);\n onImageError?.(e);\n }}\n onLoad={() => {\n setHasBrokenImage(false);\n }}\n />\n );\n }\n return getInitials(name, size);\n }, [imageSrc, name, size, icon, hasBrokenImage, onImageError]);\n\n return (\n <StyledAvatar\n role='img'\n hasSrc={!!imageSrc}\n hasBrokenImage={hasBrokenImage}\n shape={shape}\n size={size}\n ref={ref}\n aria-label={`${name}${status ? ` ${t('status')} ${status}` : ''}`}\n {...restProps}\n >\n {content}\n {status === 'active' && <Alert as={StyledStatus} size={size} variant='success' />}\n </StyledAvatar>\n );\n }\n);\n\nexport default Avatar;\n"]}
|
|
@@ -25,7 +25,7 @@ if (windowIsAvailable) {
|
|
|
25
25
|
if (!window[metaKey]) {
|
|
26
26
|
window[metaKey] = [];
|
|
27
27
|
}
|
|
28
|
-
window[metaKey].push({ version: '
|
|
28
|
+
window[metaKey].push({ version: '3.0.0-dev.1.0' });
|
|
29
29
|
}
|
|
30
30
|
const Configuration = ({ context = ConfigurationContext, children, locale, direction, translations: customTranslations, theme, disableDefaultFontLoading, styleSheetTarget, portalTarget, overrideMap, renderNativeControls }) => {
|
|
31
31
|
const ctx = useContext(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/components/Configuration/Configuration.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EAIV,OAAO,EACP,QAAQ,EACR,SAAS,EAEV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EAGrB,kBAAkB,EAClB,SAAS,IAAI,iBAAiB,EAC/B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAoD3F,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;AAcvF,MAAM,YAA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AAI,GAAG,CAAC,MAAM;YAC5B,SAAS,EAAE,SAAS,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;YAC1F,YAAY;YACZ,YAAY;YACZ,CAAC,cAAc,CAAC,EAAE,IAAI;YACtB,gBAAgB,EAAE,gBAAgB,IAAI,GAAG,CAAC,gBAAgB;YAC1D,YAAY,EAAE,YAAY,IAAI,GAAG,CAAC,YAAY;YAC9C,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW;YACnF,oBAAoB,EAAE,oBAAoB,IAAI,GAAG,CAAC,oBAAoB;SACvE,YAED,KAAC,aAAa,IAAC,KAAK,EAAE,YAAY,CAAC,KAAK,YAAG,eAAe,WAAiB,WAC7C,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF,aAAa,CAAC,YAAY,GAAG,YAAY,CAAC;AAE1C,eAAe,aAAa,CAAC","sourcesContent":["import {\n createContext,\n useContext,\n FunctionComponent,\n ComponentType,\n ReactNode,\n useMemo,\n useState,\n useEffect,\n Context\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { ThemeProvider, StyleSheetManager } from 'styled-components';\n\nimport { GlobalStyle } from '../../styles';\nimport {\n ThemeMachine,\n BaseThemeMachine,\n DefaultSettableTheme,\n DefaultThemeDefinition\n} from '../../theme';\nimport {\n createTranslationPack,\n Translation,\n TranslationPack,\n DefaultTranslation,\n direction as directionOfLocale\n} from '../../i18n';\nimport { FileInputProps } from '../File';\nimport { windowIsAvailable, navigatorIsAvailable, documentIsAvailable } from '../../utils';\n\nexport interface ConfigurationProps {\n /**\n * Any components or nodes that should be impacted by the settings applied by this Configuration component.\n */\n children: ReactNode;\n /**\n * Context to read previous configuration values from.\n */\n context?: Context<ConfigurationContextValue>;\n /**\n * User locale as defined in [BCP-47](https://www.techonthenet.com/js/language_tags.php).\n */\n locale?: string;\n /**\n * Override rendering direction of the document. Direction will be based on the locale if now provided.\n */\n direction?: 'ltr' | 'rtl';\n /**\n * Object with (partial) translations.\n */\n translations?: Translation;\n /**\n * Theme object used to override any or all Cosmos theme properties.\n */\n theme?: DefaultSettableTheme;\n /**\n * Disables loading Open Sans from Google Fonts. Only takes effect on the root configuration.\n */\n disableDefaultFontLoading?: boolean;\n /**\n * Target element for loading styles related to `styled-components`.\n */\n styleSheetTarget?: HTMLElement;\n /**\n * Target element for rendering a `ReactDOM` portal.\n */\n portalTarget?: Element;\n /**\n * Override map to replace Cosmos components.\n */\n overrideMap?: {\n FileInput?: ComponentType<FileInputProps>;\n };\n /**\n * Use native HTML5 controls for inputs instead of rich ones.\n * @default false\n */\n renderNativeControls?: boolean;\n}\n\nconst initializedKey = Symbol.for('@pega/cosmos-react-core.configuration.initialized');\n\nexport interface ConfigurationContextValue {\n [initializedKey]: boolean;\n locale: string;\n direction: ConfigurationProps['direction'];\n translations: TranslationPack;\n themeMachine: ThemeMachine<DefaultThemeDefinition>;\n styleSheetTarget?: HTMLElement;\n portalTarget?: Element;\n overrideMap: NonNullable<ConfigurationProps['overrideMap']>;\n renderNativeControls: boolean;\n}\n\nconst defaultProps: Partial<ConfigurationProps> = {};\nconst defaultLocale = navigatorIsAvailable ? navigator.language : 'en';\n\nexport const ConfigurationContext = createContext<ConfigurationContextValue>({\n [initializedKey]: false,\n locale: defaultLocale,\n direction: directionOfLocale(defaultLocale),\n translations: DefaultTranslation,\n themeMachine: BaseThemeMachine,\n styleSheetTarget: documentIsAvailable ? document.head : undefined,\n portalTarget: documentIsAvailable ? document.body : undefined,\n overrideMap: {},\n renderNativeControls: false\n});\n\nconst metaKey = Symbol.for('@pega/cosmos-react-core.metadata');\n\ninterface CosmosMetadata {\n version: string;\n}\n\ndeclare global {\n interface Window {\n [metaKey]: CosmosMetadata[];\n }\n}\n\nif (windowIsAvailable) {\n if (!window[metaKey]) {\n window[metaKey] = [];\n }\n\n window[metaKey].push({ version: '3.0.0-dev.1.0' });\n}\n\nconst Configuration: FunctionComponent<ConfigurationProps> = ({\n context = ConfigurationContext,\n children,\n locale,\n direction,\n translations: customTranslations,\n theme,\n disableDefaultFontLoading,\n styleSheetTarget,\n portalTarget,\n overrideMap,\n renderNativeControls\n}: ConfigurationProps) => {\n const ctx = useContext(context);\n const themeMachine = theme\n ? new ThemeMachine<DefaultThemeDefinition>({ theme, parent: ctx.themeMachine })\n : ctx.themeMachine;\n const translations = useMemo(\n () => createTranslationPack({ ...ctx.translations, ...customTranslations }),\n [ctx.translations, customTranslations]\n );\n\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n const wrappedChildren = ctx[initializedKey] ? (\n children\n ) : (\n <StyleSheetManager disableVendorPrefixes target={styleSheetTarget ?? ctx.styleSheetTarget}>\n <>\n {!disableDefaultFontLoading &&\n mounted &&\n documentIsAvailable &&\n createPortal(\n <link\n rel='stylesheet'\n href='https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap'\n />,\n document.head\n )}\n <GlobalStyle />\n {children}\n </>\n </StyleSheetManager>\n );\n return (\n <ConfigurationContext.Provider\n value={{\n locale: locale ?? ctx.locale,\n direction: direction ?? (locale !== undefined ? directionOfLocale(locale) : ctx.direction),\n translations,\n themeMachine,\n [initializedKey]: true,\n styleSheetTarget: styleSheetTarget ?? ctx.styleSheetTarget,\n portalTarget: portalTarget ?? ctx.portalTarget,\n overrideMap: overrideMap ? { ...ctx.overrideMap, ...overrideMap } : ctx.overrideMap,\n renderNativeControls: renderNativeControls ?? ctx.renderNativeControls\n }}\n >\n <ThemeProvider theme={themeMachine.theme}>{wrappedChildren}</ThemeProvider>\n </ConfigurationContext.Provider>\n );\n};\n\nConfiguration.defaultProps = defaultProps;\n\nexport default Configuration;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmojiDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/EmojiPicker/EmojiDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMjE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKxD,MAAM,WAAW,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAClE,8BAA8B;IAC9B,OAAO,EAAE,SAAS,CAAC;IACnB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"EmojiDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/EmojiPicker/EmojiDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMjE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKxD,MAAM,WAAW,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAClE,8BAA8B;IAC9B,OAAO,EAAE,SAAS,CAAC;IACnB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAmBtD,CAAC;AACF,eAAe,YAAY,CAAC"}
|
|
@@ -26,7 +26,7 @@ const EmojiDisplay = props => {
|
|
|
26
26
|
msgArr = replaceMatchWithElement(content, regex, renderEmoji);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
return emojiSet && msgArr.length
|
|
29
|
+
return emojiSet && msgArr.length >= 1 ? (_jsx(StyledEmojiDisplay, { ...restProps, children: msgArr }, void 0)) : (_jsx(_Fragment, { children: content }, void 0));
|
|
30
30
|
};
|
|
31
31
|
export default EmojiDisplay;
|
|
32
32
|
//# source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IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACnC,MAAM,GAAG,uBAAuB,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;SAC/D;KACF;IACD,OAAO,QAAQ,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CACtC,KAAC,kBAAkB,OAAK,SAAS,YAAG,MAAM,WAAsB,CACjE,CAAC,CAAC,CAAC,CACF,4BAAG,OAAO,WAAI,CACf,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,YAAY,CAAC","sourcesContent":["import { useContext, FunctionComponent, ReactNode } from 'react';\nimport styled from 'styled-components';\nimport emojiRegex from 'emoji-regex';\nimport { getEmojiDataFromNative, Emoji, Data as NativeData } from 'emoji-mart';\nimport data from 'emoji-mart/data/all.json';\n\nimport { BaseProps, NoChildrenProp } from '../../types';\nimport { replaceMatchWithElement } from '../../utils';\n\nimport { EmojiContext } from './EmojiPicker';\n\nexport interface EmojiDisplayProps extends BaseProps, NoChildrenProp {\n /** Content to be displayed */\n content: ReactNode;\n /** Size of emoji */\n size?: number;\n}\nconst StyledEmojiDisplay = styled.span`\n .emoji-mart-emoji {\n line-height: 1;\n vertical-align: middle;\n }\n`;\nconst EmojiDisplay: FunctionComponent<EmojiDisplayProps> = props => {\n const { content, size = 20, ...restProps } = props;\n const regex = emojiRegex();\n let msgArr: JSX.Element[] = [];\n const { set: emojiSet } = useContext(EmojiContext);\n if (typeof content === 'string' && emojiSet) {\n const renderEmoji = (eMatch: string) => {\n const emojiData = getEmojiDataFromNative(eMatch, emojiSet, data as unknown as NativeData);\n return emojiData && <Emoji set={emojiSet} emoji={emojiData} size={size} />;\n };\n if (content.split(regex).length > 1) {\n msgArr = replaceMatchWithElement(content, regex, renderEmoji);\n }\n }\n return emojiSet && msgArr.length >= 1 ? (\n <StyledEmojiDisplay {...restProps}>{msgArr}</StyledEmojiDisplay>\n ) : (\n <>{content}</>\n );\n};\nexport default EmojiDisplay;\n"]}
|
|
@@ -21,6 +21,16 @@ export interface FormFieldProps extends OmitStrict<FormControlProps, 'placeholde
|
|
|
21
21
|
* @default "label"
|
|
22
22
|
*/
|
|
23
23
|
labelAs?: LabelProps['as'];
|
|
24
|
+
/**
|
|
25
|
+
* Overrides the for attribute on the label. If this is not set it will default to the forms id.
|
|
26
|
+
* @default undefined
|
|
27
|
+
*/
|
|
28
|
+
labelFor?: LabelProps['htmlFor'];
|
|
29
|
+
/**
|
|
30
|
+
* Sets the id of the label.
|
|
31
|
+
* @default undefined
|
|
32
|
+
*/
|
|
33
|
+
labelId?: LabelProps['id'];
|
|
24
34
|
/**
|
|
25
35
|
* Visually hides the label region.
|
|
26
36
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../src/components/FormField/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,SAAS,EACT,aAAa,EAEb,YAAY,EAMb,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAc,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AAI1D,MAAM,WAAW,cACf,SAAQ,UAAU,CAAC,gBAAgB,EAAE,aAAa,GAAG,OAAO,GAAG,cAAc,CAAC;IAC9E,kFAAkF;IAClF,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;IACxC;;;;;;;;OAQG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH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Q,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,EAAE,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gDAAgD;IAChD,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,SAAS,CAAC;CAC9B;AAgBD,eAAO,MAAM,mBAAmB,uIAsB/B,CAAC;AAIF,eAAO,MAAM,eAAe,qHAsC1B,CAAC;AAMH,QAAA,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,GAAG,YAAY,CA4HhD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -65,9 +65,9 @@ StyledFormField.defaultProps = defaultThemeProp;
|
|
|
65
65
|
const statusIconMap = { error: 'warn-solid', warning: 'warn', success: 'check' };
|
|
66
66
|
const FormField = forwardRef((props, ref) => {
|
|
67
67
|
const uid = useUID();
|
|
68
|
-
const { children: controlElement, id = uid, as = 'div', label, labelAs = 'label', labelHidden = false, labelAfter = false, info, status, charLimitDisplay, required = false, disabled = false, readOnly = false, inline = false, actions, container, ...restProps } = props;
|
|
68
|
+
const { children: controlElement, id = uid, as = 'div', label, labelAs = 'label', labelFor = id, labelId, labelHidden = false, labelAfter = false, info, status, charLimitDisplay, required = false, disabled = false, readOnly = false, inline = false, actions, container, ...restProps } = props;
|
|
69
69
|
const labelAsLegend = labelAs === 'legend';
|
|
70
|
-
const styledLabel = (_jsxs(Label, { as: labelAs, htmlFor: labelAs === 'label' ?
|
|
70
|
+
const styledLabel = (_jsxs(Label, { id: labelId, as: labelAs, htmlFor: labelAs === 'label' ? labelFor : undefined, labelHidden: labelHidden, onClick: (e) => {
|
|
71
71
|
if (readOnly)
|
|
72
72
|
e.preventDefault();
|
|
73
73
|
}, inline: inline, children: [status && !labelHidden && (_jsx(StyledStatusIcon, { status: status, name: statusIconMap[status] }, void 0)), label] }, void 0));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.js","sourceRoot":"","sources":["../../../src/components/FormField/FormField.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,YAAY,EAEZ,SAAS,EACT,QAAQ,EAER,UAAU,EAEX,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,IAAmB,MAAM,SAAS,CAAC;AAC1C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,EAAc,WAAW,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,IAAI,MAAM,SAAS,CAAC;AAiD3B,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CACnC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;IACpB,OAAO,GAAG,CAAA;;;eAGC,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC;;;KAGhE,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,G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EACD,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,GAAG,EAAE,QAAQ,EACjB,WAAW,EAAE,EAAE,EACf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,sBACA,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,EAClE,GAAG,EAAE,GAAG,aAEP,CAAC,aAAa,IAAI,CAAC,UAAU,CAAC,IAAI,WAAW,EAC7C,OAAO,EACP,CAAC,aAAa,IAAI,UAAU,IAAI,WAAW,EAC3C,WAAW,YACP,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import {\n FC,\n ReactNode,\n ComponentType,\n cloneElement,\n ReactElement,\n useEffect,\n useState,\n PropsWithoutRef,\n forwardRef,\n Ref\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\nimport { Action, ForwardProps, OmitStrict } from '../../types';\nimport Flex, { FlexProps } from '../Flex';\nimport Actions from '../Actions';\nimport { FormControlProps } from '../FormControl';\nimport { useUID } from '../../hooks';\nimport Label, { LabelProps, StyledLabel } from '../Label';\nimport { calculateFontSize } from '../../styles';\nimport Icon from '../Icon';\n\nexport interface FormFieldProps\n extends OmitStrict<FormControlProps, 'placeholder' | 'value' | 'defaultValue'> {\n /** Pass a single form control component i.e. Input | TextArea | Select | etc.. */\n children: ReactElement | ReactElement[];\n /**\n * An id is required to connect a FormField's wrapping element, control element and info(aria-describedby) live region.\n * A random id will be generated if none is provided.\n * Since MOST FormControls should possess an id(excl. i.e RadioCheckGroup and others) this can be used.\n * The id prop will be used to generate the following:\n * - FormControl <-> Label association via a Label's htmlFor prop.\n * - FormField's wrapping element id {id}-field.\n * - FormField info element id ${id}-info.\n */\n id?: string;\n /**\n * Determines how the wrapping label should be rendered.\n * @default \"label\"\n */\n labelAs?: LabelProps['as'];\n /**\n * Visually hides the label region.\n * @default false\n */\n labelHidden?: boolean;\n /**\n * Visually places the label after the input.\n * @default false\n */\n labelAfter?: boolean;\n /**\n * Wrapping HTML element tag. Renders as a fieldset for grouped elements i.e. RadioButtons/CheckboxGroup\n * @default \"div\"\n */\n as?: 'div' | 'fieldset' | ComponentType<any>;\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: boolean;\n /** Optionally utilized by Input or Select. */\n actions?: Action[];\n /** Enables Flex container prop pass through. */\n container?: Exclude<FlexProps['container'], boolean>;\n /** Character remaining count. Typically used on Textareas only */\n charLimitDisplay?: ReactNode;\n}\n\nconst StyledStatusIcon = styled(Icon)<{ status: NonNullable<FormFieldProps['status']> }>(\n ({ theme, status }) => {\n return css`\n height: 1em;\n width: 1em;\n color: ${theme.components['form-field'][status]['status-color']};\n vertical-align: baseline;\n margin-inline-end: 0.5ch;\n `;\n }\n);\n\nStyledStatusIcon.defaultProps = defaultThemeProp;\n\nexport const StyledFormFieldInfo = styled.div<Pick<FormControlProps, 'status'>>(\n ({\n status,\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { 'form-field': formField }\n }\n }) => {\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n max-width: max-content;\n margin-top: calc(0.25 * ${spacing});\n font-size: ${infoFontSize};\n word-break: break-word;\n ${status &&\n formField[status] &&\n css`\n color: ${formField[status]['status-color']};\n `}\n `;\n }\n);\n\nStyledFormFieldInfo.defaultProps = defaultThemeProp;\n\nexport const StyledFormField = styled.div<FormFieldProps>(props => {\n const {\n disabled,\n required,\n theme: {\n base: {\n palette: { urgent },\n 'disabled-opacity': disabledOpacity,\n spacing\n }\n }\n } = props;\n\n return css`\n ${disabled &&\n css`\n opacity: ${disabledOpacity};\n -webkit-user-select: none;\n user-select: none;\n `}\n position: relative;\n border: 0;\n\n > ${StyledLabel} {\n margin-bottom: calc(0.25 * ${spacing});\n ${disabled &&\n css`\n cursor: not-allowed;\n `}\n\n &::after {\n display: ${required ? 'inline' : 'none'};\n content: '\\\\00a0*';\n vertical-align: top;\n color: ${urgent};\n }\n }\n `;\n});\n\nStyledFormField.defaultProps = defaultThemeProp;\n\nconst statusIconMap = { error: 'warn-solid', warning: 'warn', success: 'check' };\n\nconst FormField: FC<FormFieldProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<FormFieldProps>, ref: Ref<HTMLElement>) => {\n const uid = useUID();\n const {\n children: controlElement,\n id = uid,\n as = 'div',\n label,\n labelAs = 'label',\n labelHidden = false,\n labelAfter = false,\n info,\n status,\n charLimitDisplay,\n required = false,\n disabled = false,\n readOnly = false,\n inline = false,\n actions,\n container,\n ...restProps\n } = props;\n\n const labelAsLegend: boolean = labelAs === 'legend';\n\n const styledLabel = (\n <Label\n as={labelAs}\n htmlFor={labelAs === 'label' ? id : undefined}\n labelHidden={labelHidden}\n onClick={(e: MouseEvent) => {\n if (readOnly) e.preventDefault();\n }}\n inline={inline}\n >\n {status && !labelHidden && (\n <StyledStatusIcon status={status} name={statusIconMap[status]} />\n )}\n {label}\n </Label>\n );\n\n /*\n We have to use an internal state and an effect to set the text value of info after the DOM element is rendered.\n This is to ensure screen readers will announce info on errors when role is set to alert.\n Needs testing to confirm. Currently the expected sequence would be:\n - FormField renders with no error and no info\n - user input triggers an error status\n - props passed set error status and provide info text\n - effect runs and sets live region state which renders and is announced\n */\n const [liveRegionInfo, setLiveRegionInfo] = useState<ReactNode>(null);\n\n useEffect(() => {\n setLiveRegionInfo(info);\n }, [info]);\n\n // fieldset or single form control element\n let content: FormFieldProps['children'] = labelAsLegend\n ? controlElement\n : cloneElement(controlElement as ReactElement, {\n 'aria-describedby': info && `${id}-info`\n });\n\n if (actions) {\n content = (\n <Flex container={{ alignItems: 'center', gap: 0.5 }}>\n {content}\n <Actions items={actions} menuAt={3} />\n </Flex>\n );\n }\n\n let infoContent = info ? (\n /*\n Region for additional info, help or error message.\n Withholding aria-live=\"assertive\" to avoid iOS issue. See below.\n https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions#Preferring_specialized_live_region_roles\n */\n <StyledFormFieldInfo\n status={status}\n role={status === 'error' || status === 'warning' ? 'alert' : undefined}\n id={`${id}-info`}\n >\n {liveRegionInfo}\n </StyledFormFieldInfo>\n ) : undefined;\n\n if (charLimitDisplay) {\n infoContent = (\n <Flex container={{ justify: infoContent ? 'between' : 'end', gap: 1 }}>\n {infoContent}\n <Flex item={{ shrink: 0 }}>{charLimitDisplay}</Flex>\n </Flex>\n );\n }\n\n return (\n <Flex\n {...restProps}\n container={{\n direction: inline ? 'row' : 'column',\n alignItems: inline ? 'center' : undefined,\n ...container\n }}\n as={StyledFormField}\n id={`${id}-field`}\n forwardedAs={as}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n aria-describedby={labelAsLegend && info ? `${id}-info` : undefined}\n ref={ref}\n >\n {(labelAsLegend || !labelAfter) && styledLabel}\n {content}\n {!labelAsLegend && labelAfter && styledLabel}\n {infoContent}\n </Flex>\n );\n }\n);\n\nexport default FormField;\n"]}
|
|
1
|
+
{"version":3,"file":"FormField.js","sourceRoot":"","sources":["../../../src/components/FormField/FormField.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,YAAY,EAEZ,SAAS,EACT,QAAQ,EAER,UAAU,EAEX,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,IAAmB,MAAM,SAAS,CAAC;AAC1C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,EAAc,WAAW,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,IAAI,MAAM,SAAS,CAAC;AA2D3B,MAA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,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,aAClE,WAAW,EACZ,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,YAAG,gBAAgB,WAAQ,YAC/C,CACR,CAAC;KACH;IAED,OAAO,CACL,MAAC,IAAI,OACC,SAAS,EACb,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;YACpC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACzC,GAAG,SAAS;SACb,EACD,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,GAAG,EAAE,QAAQ,EACjB,WAAW,EAAE,EAAE,EACf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,sBACA,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,EAClE,GAAG,EAAE,GAAG,aAEP,CAAC,aAAa,IAAI,CAAC,UAAU,CAAC,IAAI,WAAW,EAC7C,OAAO,EACP,CAAC,aAAa,IAAI,UAAU,IAAI,WAAW,EAC3C,WAAW,YACP,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import {\n FC,\n ReactNode,\n ComponentType,\n cloneElement,\n ReactElement,\n useEffect,\n useState,\n PropsWithoutRef,\n forwardRef,\n Ref\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\nimport { Action, ForwardProps, OmitStrict } from '../../types';\nimport Flex, { FlexProps } from '../Flex';\nimport Actions from '../Actions';\nimport { FormControlProps } from '../FormControl';\nimport { useUID } from '../../hooks';\nimport Label, { LabelProps, StyledLabel } from '../Label';\nimport { calculateFontSize } from '../../styles';\nimport Icon from '../Icon';\n\nexport interface FormFieldProps\n extends OmitStrict<FormControlProps, 'placeholder' | 'value' | 'defaultValue'> {\n /** Pass a single form control component i.e. Input | TextArea | Select | etc.. */\n children: ReactElement | ReactElement[];\n /**\n * An id is required to connect a FormField's wrapping element, control element and info(aria-describedby) live region.\n * A random id will be generated if none is provided.\n * Since MOST FormControls should possess an id(excl. i.e RadioCheckGroup and others) this can be used.\n * The id prop will be used to generate the following:\n * - FormControl <-> Label association via a Label's htmlFor prop.\n * - FormField's wrapping element id {id}-field.\n * - FormField info element id ${id}-info.\n */\n id?: string;\n /**\n * Determines how the wrapping label should be rendered.\n * @default \"label\"\n */\n labelAs?: LabelProps['as'];\n /**\n * Overrides the for attribute on the label. If this is not set it will default to the forms id.\n * @default undefined\n */\n labelFor?: LabelProps['htmlFor'];\n /**\n * Sets the id of the label.\n * @default undefined\n */\n labelId?: LabelProps['id'];\n /**\n * Visually hides the label region.\n * @default false\n */\n labelHidden?: boolean;\n /**\n * Visually places the label after the input.\n * @default false\n */\n labelAfter?: boolean;\n /**\n * Wrapping HTML element tag. Renders as a fieldset for grouped elements i.e. RadioButtons/CheckboxGroup\n * @default \"div\"\n */\n as?: 'div' | 'fieldset' | ComponentType<any>;\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: boolean;\n /** Optionally utilized by Input or Select. */\n actions?: Action[];\n /** Enables Flex container prop pass through. */\n container?: Exclude<FlexProps['container'], boolean>;\n /** Character remaining count. Typically used on Textareas only */\n charLimitDisplay?: ReactNode;\n}\n\nconst StyledStatusIcon = styled(Icon)<{ status: NonNullable<FormFieldProps['status']> }>(\n ({ theme, status }) => {\n return css`\n height: 1em;\n width: 1em;\n color: ${theme.components['form-field'][status]['status-color']};\n vertical-align: baseline;\n margin-inline-end: 0.5ch;\n `;\n }\n);\n\nStyledStatusIcon.defaultProps = defaultThemeProp;\n\nexport const StyledFormFieldInfo = styled.div<Pick<FormControlProps, 'status'>>(\n ({\n status,\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { 'form-field': formField }\n }\n }) => {\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n max-width: max-content;\n margin-top: calc(0.25 * ${spacing});\n font-size: ${infoFontSize};\n word-break: break-word;\n ${status &&\n formField[status] &&\n css`\n color: ${formField[status]['status-color']};\n `}\n `;\n }\n);\n\nStyledFormFieldInfo.defaultProps = defaultThemeProp;\n\nexport const StyledFormField = styled.div<FormFieldProps>(props => {\n const {\n disabled,\n required,\n theme: {\n base: {\n palette: { urgent },\n 'disabled-opacity': disabledOpacity,\n spacing\n }\n }\n } = props;\n\n return css`\n ${disabled &&\n css`\n opacity: ${disabledOpacity};\n -webkit-user-select: none;\n user-select: none;\n `}\n position: relative;\n border: 0;\n\n > ${StyledLabel} {\n margin-bottom: calc(0.25 * ${spacing});\n ${disabled &&\n css`\n cursor: not-allowed;\n `}\n\n &::after {\n display: ${required ? 'inline' : 'none'};\n content: '\\\\00a0*';\n vertical-align: top;\n color: ${urgent};\n }\n }\n `;\n});\n\nStyledFormField.defaultProps = defaultThemeProp;\n\nconst statusIconMap = { error: 'warn-solid', warning: 'warn', success: 'check' };\n\nconst FormField: FC<FormFieldProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<FormFieldProps>, ref: Ref<HTMLElement>) => {\n const uid = useUID();\n const {\n children: controlElement,\n id = uid,\n as = 'div',\n label,\n labelAs = 'label',\n labelFor = id,\n labelId,\n labelHidden = false,\n labelAfter = false,\n info,\n status,\n charLimitDisplay,\n required = false,\n disabled = false,\n readOnly = false,\n inline = false,\n actions,\n container,\n ...restProps\n } = props;\n\n const labelAsLegend: boolean = labelAs === 'legend';\n\n const styledLabel = (\n <Label\n id={labelId}\n as={labelAs}\n htmlFor={labelAs === 'label' ? labelFor : undefined}\n labelHidden={labelHidden}\n onClick={(e: MouseEvent) => {\n if (readOnly) e.preventDefault();\n }}\n inline={inline}\n >\n {status && !labelHidden && (\n <StyledStatusIcon status={status} name={statusIconMap[status]} />\n )}\n {label}\n </Label>\n );\n\n /*\n We have to use an internal state and an effect to set the text value of info after the DOM element is rendered.\n This is to ensure screen readers will announce info on errors when role is set to alert.\n Needs testing to confirm. Currently the expected sequence would be:\n - FormField renders with no error and no info\n - user input triggers an error status\n - props passed set error status and provide info text\n - effect runs and sets live region state which renders and is announced\n */\n const [liveRegionInfo, setLiveRegionInfo] = useState<ReactNode>(null);\n\n useEffect(() => {\n setLiveRegionInfo(info);\n }, [info]);\n\n // fieldset or single form control element\n let content: FormFieldProps['children'] = labelAsLegend\n ? controlElement\n : cloneElement(controlElement as ReactElement, {\n 'aria-describedby': info && `${id}-info`\n });\n\n if (actions) {\n content = (\n <Flex container={{ alignItems: 'center', gap: 0.5 }}>\n {content}\n <Actions items={actions} menuAt={3} />\n </Flex>\n );\n }\n\n let infoContent = info ? (\n /*\n Region for additional info, help or error message.\n Withholding aria-live=\"assertive\" to avoid iOS issue. See below.\n https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions#Preferring_specialized_live_region_roles\n */\n <StyledFormFieldInfo\n status={status}\n role={status === 'error' || status === 'warning' ? 'alert' : undefined}\n id={`${id}-info`}\n >\n {liveRegionInfo}\n </StyledFormFieldInfo>\n ) : undefined;\n\n if (charLimitDisplay) {\n infoContent = (\n <Flex container={{ justify: infoContent ? 'between' : 'end', gap: 1 }}>\n {infoContent}\n <Flex item={{ shrink: 0 }}>{charLimitDisplay}</Flex>\n </Flex>\n );\n }\n\n return (\n <Flex\n {...restProps}\n container={{\n direction: inline ? 'row' : 'column',\n alignItems: inline ? 'center' : undefined,\n ...container\n }}\n as={StyledFormField}\n id={`${id}-field`}\n forwardedAs={as}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n aria-describedby={labelAsLegend && info ? `${id}-info` : undefined}\n ref={ref}\n >\n {(labelAsLegend || !labelAfter) && styledLabel}\n {content}\n {!labelAsLegend && labelAfter && styledLabel}\n {infoContent}\n </Flex>\n );\n }\n);\n\nexport default FormField;\n"]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { FunctionComponent, ReactNode, Ref } from 'react';
|
|
2
2
|
import { BaseProps, ForwardProps } from '../../types';
|
|
3
3
|
export interface LabelProps extends BaseProps {
|
|
4
|
+
/**
|
|
5
|
+
* Id for the label.
|
|
6
|
+
* @default undefined
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
4
9
|
/**
|
|
5
10
|
* HTML tag to render the label as.
|
|
6
11
|
* @default "label"
|
|
@@ -18,7 +23,7 @@ export interface LabelProps extends BaseProps {
|
|
|
18
23
|
/** Ref for the wrapping element. */
|
|
19
24
|
ref?: Ref<HTMLLabelElement | HTMLLegendElement | HTMLDivElement | HTMLSpanElement>;
|
|
20
25
|
}
|
|
21
|
-
export declare const StyledLabel: import("styled-components").StyledComponent<"label", import("styled-components").DefaultTheme, Pick<LabelProps, "labelHidden">, never>;
|
|
26
|
+
export declare const StyledLabel: import("styled-components").StyledComponent<"label", import("styled-components").DefaultTheme, Pick<LabelProps, "htmlFor" | "labelHidden">, never>;
|
|
22
27
|
declare const Label: FunctionComponent<LabelProps & ForwardProps>;
|
|
23
28
|
export default Label;
|
|
24
29
|
//# sourceMappingURL=Label.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/components/Label/Label.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAIvF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKtD,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C;;;OAGG;IACH,EAAE,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACzC,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,QAAQ,EAAE,SAAS,CAAC;IACpB,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,iBAAiB,GAAG,cAAc,GAAG,eAAe,CAAC,CAAC;CACpF;AAED,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/components/Label/Label.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAIvF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKtD,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,EAAE,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACzC,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,QAAQ,EAAE,SAAS,CAAC;IACpB,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,iBAAiB,GAAG,cAAc,GAAG,eAAe,CAAC,CAAC;CACpF;AAED,eAAO,MAAM,WAAW,oJAoBvB,CAAC;AAIF,QAAA,MAAM,KAAK,EAAE,iBAAiB,CAAC,UAAU,GAAG,YAAY,CAgBvD,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -20,8 +20,8 @@ export const StyledLabel = styled.label(({ theme, labelHidden }) => {
|
|
|
20
20
|
`;
|
|
21
21
|
});
|
|
22
22
|
StyledLabel.defaultProps = defaultThemeProp;
|
|
23
|
-
const Label = forwardRef(({ children, labelHidden = false, ...restProps }, ref) => {
|
|
24
|
-
return (_jsx(StyledLabel, { ref: ref, labelHidden: labelHidden, ...restProps, children: children }, void 0));
|
|
23
|
+
const Label = forwardRef(({ children, labelHidden = false, htmlFor, ...restProps }, ref) => {
|
|
24
|
+
return (_jsx(StyledLabel, { ref: ref, labelHidden: labelHidden, htmlFor: htmlFor === '' ? undefined : htmlFor, ...restProps, children: children }, void 0));
|
|
25
25
|
});
|
|
26
26
|
export default Label;
|
|
27
27
|
//# sourceMappingURL=Label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sourceRoot":"","sources":["../../../src/components/Label/Label.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsD,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAY,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Label.js","sourceRoot":"","sources":["../../../src/components/Label/Label.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsD,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAY,MAAM,cAAc,CAAC;AA0B3D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CACrC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE;IACzB,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC1B,OAAO,IAAI,CACT,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,EACvD,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CACzC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEtF,OAAO,WAAW;QAChB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,GAAG,CAAA;;uBAEY,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAa,CAAC;yBACvD,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC;mBAC5C,KAAK;SACf,CAAC;AACR,CAAC,CACF,CAAC;AAEF,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,KAAK,GAAiD,UAAU,CACpE,CACE,EAAE,QAAQ,EAAE,WAAW,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,EAA+B,EACrF,GAAsB,EACtB,EAAE;IACF,OAAO,CACL,KAAC,WAAW,IACV,GAAG,EAAE,GAA4B,EACjC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,KACzC,SAAS,YAEZ,QAAQ,WACG,CACf,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, ReactNode, Ref } from 'react';\nimport styled, { css } from 'styled-components';\nimport { hideVisually, readableColor, rgba } from 'polished';\n\nimport { BaseProps, ForwardProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { calculateFontSize, FontSize } from '../../styles';\n\nexport interface LabelProps extends BaseProps {\n /**\n * Id for the label.\n * @default undefined\n */\n id?: string;\n /**\n * HTML tag to render the label as.\n * @default \"label\"\n */\n as?: 'label' | 'legend' | 'div' | 'span';\n /** Use to associate with a form-element's id. */\n htmlFor?: string;\n /**\n * Visually hides the label.\n * @default false\n */\n labelHidden?: boolean;\n /** Content/text for the label. */\n children: ReactNode;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLLabelElement | HTMLLegendElement | HTMLDivElement | HTMLSpanElement>;\n}\n\nexport const StyledLabel = styled.label<Pick<LabelProps, 'labelHidden' | 'htmlFor'>>(\n ({ theme, labelHidden }) => {\n const color = tryCatch(() => {\n return rgba(\n readableColor(theme.base.palette['primary-background']),\n theme.base.transparency['transparent-3']\n );\n });\n\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return labelHidden\n ? hideVisually\n : css`\n max-width: max-content;\n font-size: ${fontSize[theme.components.label['font-size'] as FontSize]};\n font-weight: ${theme.base['font-weight']['semi-bold']};\n color: ${color};\n `;\n }\n);\n\nStyledLabel.defaultProps = defaultThemeProp;\n\nconst Label: FunctionComponent<LabelProps & ForwardProps> = forwardRef(\n (\n { children, labelHidden = false, htmlFor, ...restProps }: PropsWithoutRef<LabelProps>,\n ref: LabelProps['ref']\n ) => {\n return (\n <StyledLabel\n ref={ref as Ref<HTMLLabelElement>}\n labelHidden={labelHidden}\n htmlFor={htmlFor === '' ? undefined : htmlFor}\n {...restProps}\n >\n {children}\n </StyledLabel>\n );\n }\n);\n\nexport default Label;\n"]}
|
|
@@ -5,13 +5,13 @@ import Button from '../Button';
|
|
|
5
5
|
import BareRoleButton from '../Button/BareRoleButton';
|
|
6
6
|
import Icon, { registerIcon } from '../Icon';
|
|
7
7
|
import * as timesIcon from '../Icon/icons/times.icon';
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
8
|
+
import * as minusIcon from '../Icon/icons/minus.icon';
|
|
9
|
+
import * as undockIcon from '../Icon/icons/undock.icon';
|
|
10
10
|
import { defaultThemeProp } from '../../theme';
|
|
11
11
|
import Flex from '../Flex';
|
|
12
12
|
import { useI18n } from '../../hooks';
|
|
13
13
|
import { ModalManagerContext } from './Contexts';
|
|
14
|
-
registerIcon(timesIcon,
|
|
14
|
+
registerIcon(timesIcon, minusIcon, undockIcon);
|
|
15
15
|
const StyledMinimizedModal = styled(BareRoleButton)(({ theme: { base } }) => {
|
|
16
16
|
return css `
|
|
17
17
|
height: 3rem;
|
|
@@ -59,11 +59,11 @@ const MinimizedModal = ({ heading, onBeforeClose, onAfterClose, onRequestDismiss
|
|
|
59
59
|
if (onRequestMaximize?.() !== false) {
|
|
60
60
|
maximize();
|
|
61
61
|
}
|
|
62
|
-
}, children: _jsx(Icon, { name: '
|
|
62
|
+
}, children: _jsx(Icon, { name: 'undock' }, void 0) }, void 0)), dockable && (_jsx(Button, { "aria-label": t('modal_dock'), variant: 'simple', onClick: () => {
|
|
63
63
|
if (onRequestDock?.() !== false) {
|
|
64
64
|
dock();
|
|
65
65
|
}
|
|
66
|
-
}, icon: true, children: _jsx(Icon, { name: '
|
|
66
|
+
}, icon: true, children: _jsx(Icon, { name: 'minus' }, void 0) }, void 0)), dismissible && (_jsx(Button, { "aria-label": `${t('close')} ${heading}`, variant: 'simple', onClick: () => {
|
|
67
67
|
if (onRequestDismiss?.() !== false) {
|
|
68
68
|
onBeforeClose?.();
|
|
69
69
|
unmount();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MinimizedModal.js","sourceRoot":"","sources":["../../../src/components/Modal/MinimizedModal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,UAAU,EAAiB,MAAM,OAAO,CAAC;AACrE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,cAAc,MAAM,0BAA0B,CAAC;AACtD,OAAO,IAAI,EAAE,EAAE,YAAY,EA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ACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { FunctionComponent, useContext, KeyboardEvent } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Button from '../Button';\nimport BareRoleButton from '../Button/BareRoleButton';\nimport Icon, { registerIcon } from '../Icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport * as minusIcon from '../Icon/icons/minus.icon';\nimport * as undockIcon from '../Icon/icons/undock.icon';\nimport { defaultThemeProp } from '../../theme';\nimport { ForwardProps } from '../../types';\nimport Flex from '../Flex';\nimport { useI18n } from '../../hooks';\n\nimport { ModalProps } from './Modal.types';\nimport { ModalManagerContext } from './Contexts';\n\nregisterIcon(timesIcon, minusIcon, undockIcon);\n\nconst StyledMinimizedModal = styled(BareRoleButton)(({ theme: { base } }) => {\n return css`\n height: 3rem;\n width: 30ch;\n border-radius: calc(0.5 * ${base['border-radius']}) calc(0.5 * ${base['border-radius']}) 0 0;\n color: ${base.palette['foreground-color']};\n background-color: ${base.palette['primary-background']};\n box-shadow: ${base.shadow.low};\n cursor: pointer;\n user-select: none;\n transition: box-shadow ${base.animation.speed} ${base.animation.timing.ease};\n\n &:hover {\n box-shadow: ${base.shadow.high};\n }\n\n &:focus {\n outline: none;\n box-shadow: ${base.shadow.focus};\n }\n\n > div:first-child {\n margin-inline-end: auto;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n `;\n});\n\nStyledMinimizedModal.defaultProps = defaultThemeProp;\n\nconst MinimizedModal: FunctionComponent<ModalProps & ForwardProps> = ({\n heading,\n onBeforeClose,\n onAfterClose,\n onRequestDismiss,\n onRequestActivate,\n onRequestMinimize,\n onRequestMaximize,\n onRequestDock,\n ...restProps\n}) => {\n const { ModalContext } = useContext(ModalManagerContext);\n const { dismissible, dockable, maximizable, dock, maximize, activate, unmount } =\n useContext(ModalContext);\n\n const t = useI18n();\n\n return (\n <Flex\n {...restProps}\n container={{ alignItems: 'center', justify: 'between', pad: [0, 2], gap: 2 }}\n item={{ shrink: 0 }}\n as={StyledMinimizedModal}\n aria-label={`${t('activate')} ${heading}`}\n onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {\n // Prevent issues when auto focusing on close button.\n if ((e.key === 'Space' || e.key === 'Enter') && e.target === e.currentTarget)\n e.preventDefault();\n }}\n onClick={() => {\n if (onRequestActivate?.() !== false && !dockable) activate();\n if (onRequestDock?.() !== false && dockable) dock();\n }}\n >\n <div>{heading}</div>\n\n {(maximizable || dockable || dismissible) && (\n <Flex container>\n {maximizable && (\n <Button\n icon\n variant='simple'\n aria-label={t('modal_maximize')}\n onClick={() => {\n if (onRequestMaximize?.() !== false) {\n maximize();\n }\n }}\n >\n <Icon name='undock' />\n </Button>\n )}\n\n {dockable && (\n <Button\n aria-label={t('modal_dock')}\n variant='simple'\n onClick={() => {\n if (onRequestDock?.() !== false) {\n dock();\n }\n }}\n icon\n >\n <Icon name='minus' />\n </Button>\n )}\n\n {dismissible && (\n <Button\n aria-label={`${t('close')} ${heading}`}\n variant='simple'\n onClick={() => {\n if (onRequestDismiss?.() !== false) {\n onBeforeClose?.();\n unmount();\n onAfterClose?.();\n }\n }}\n icon\n >\n <Icon name='times' />\n </Button>\n )}\n </Flex>\n )}\n </Flex>\n );\n};\n\nexport default MinimizedModal;\n"]}
|
|
@@ -6,7 +6,7 @@ import { NUMBER_MAX_DECIMAL_PLACES } from './NumberInput.types';
|
|
|
6
6
|
const NumberDisplay = forwardRef(({ value = '', unit = '', unitPlacement = 'after', formattingOptions = {}, ...restProps }, ref) => {
|
|
7
7
|
const { locale } = useConfiguration();
|
|
8
8
|
const { showDecimal = true, numberOfDecimals = NUMBER_MAX_DECIMAL_PLACES, showGroupSeparators = true } = formattingOptions;
|
|
9
|
-
return (_jsx("span", { ref: ref, ...restProps, children: value ? (`${unit && unitPlacement === 'before' ?
|
|
9
|
+
return (_jsx("span", { ref: ref, ...restProps, children: value ? (`${unit && unitPlacement === 'before' ? unit : ''}${getFormattedValue(!showDecimal ? getInteger(value) : value, locale, showGroupSeparators, numberOfDecimals)}${unit && unitPlacement === 'after' ? unit : ''}`) : (_jsx("span", { "aria-hidden": 'true', children: "\u2013\u2013" }, void 0)) }, void 0));
|
|
10
10
|
});
|
|
11
11
|
export default NumberDisplay;
|
|
12
12
|
//# sourceMappingURL=NumberDisplay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberDisplay.js","sourceRoot":"","sources":["../../../src/components/Number/NumberDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AA8BhE,MAAM,aAAa,GAAyD,UAAU,CACpF,CACE,EACE,KAAK,GAAG,EAAE,EACV,IAAI,GAAG,EAAE,EACT,aAAa,GAAG,OAAO,EACvB,iBAAiB,GAAG,EAAE,EACtB,GAAG,SAAS,EACwB,EACtC,GAA8B,EAC9B,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,EACJ,WAAW,GAAG,IAAI,EAClB,gBAAgB,GAAG,yBAAyB,EAC5C,mBAAmB,GAAG,IAAI,EAC3B,GAAG,iBAAiB,CAAC;IAEtB,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,CAAC,CAAC,CAAC,CACP,GAAG,IAAI,IAAI,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"NumberDisplay.js","sourceRoot":"","sources":["../../../src/components/Number/NumberDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AA8BhE,MAAM,aAAa,GAAyD,UAAU,CACpF,CACE,EACE,KAAK,GAAG,EAAE,EACV,IAAI,GAAG,EAAE,EACT,aAAa,GAAG,OAAO,EACvB,iBAAiB,GAAG,EAAE,EACtB,GAAG,SAAS,EACwB,EACtC,GAA8B,EAC9B,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,EACJ,WAAW,GAAG,IAAI,EAClB,gBAAgB,GAAG,yBAAyB,EAC5C,mBAAmB,GAAG,IAAI,EAC3B,GAAG,iBAAiB,CAAC;IAEtB,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,CAAC,CAAC,CAAC,CACP,GAAG,IAAI,IAAI,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,iBAAiB,CACnE,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EACxC,MAAM,EACN,mBAAmB,EACnB,gBAAgB,CACjB,GAAG,IAAI,IAAI,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACpD,CAAC,CAAC,CAAC,CACF,8BAAkB,MAAM,qCAAsB,CAC/C,WACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, Ref } from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\n\nimport { getFormattedValue, getInteger } from './utils';\nimport { NUMBER_MAX_DECIMAL_PLACES } from './NumberInput.types';\n\nexport interface NumberDisplayProps extends BaseProps, NoChildrenProp {\n /** Number value */\n value?: string;\n /** Unit to be included in the text, for example '%' */\n unit?: string;\n /**\n * Determines the placement of the unit.\n * @default \"after\"\n */\n unitPlacement?: 'before' | 'after';\n formattingOptions?: {\n /** Determines whether decimal places should be shown. The value is simply truncated if true.\n * @default true\n */\n showDecimal?: boolean;\n /** Determines the maximum number of decimal places. The value is simply truncated to the number of places.\n * @default variable NUMBER_MAX_DECIMAL_PLACES. Recommended minimum: 1.\n */\n numberOfDecimals?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n showGroupSeparators?: boolean;\n };\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst NumberDisplay: FunctionComponent<NumberDisplayProps & ForwardProps> = forwardRef(\n (\n {\n value = '',\n unit = '',\n unitPlacement = 'after',\n formattingOptions = {},\n ...restProps\n }: PropsWithoutRef<NumberDisplayProps>,\n ref: NumberDisplayProps['ref']\n ) => {\n const { locale } = useConfiguration();\n const {\n showDecimal = true,\n numberOfDecimals = NUMBER_MAX_DECIMAL_PLACES,\n showGroupSeparators = true\n } = formattingOptions;\n\n return (\n <span ref={ref} {...restProps}>\n {value ? (\n `${unit && unitPlacement === 'before' ? unit : ''}${getFormattedValue(\n !showDecimal ? getInteger(value) : value,\n locale,\n showGroupSeparators,\n numberOfDecimals\n )}${unit && unitPlacement === 'after' ? unit : ''}`\n ) : (\n <span aria-hidden='true'>––</span>\n )}\n </span>\n );\n }\n);\n\nexport default NumberDisplay;\n"]}
|
|
@@ -21,7 +21,7 @@ export const StyledPseudoRadioCheck = styled.div(props => {
|
|
|
21
21
|
position: relative;
|
|
22
22
|
width: ${size};
|
|
23
23
|
height: ${size};
|
|
24
|
-
margin-inline-end: ${spacing};
|
|
24
|
+
margin-inline-end: calc(${spacing} / 2);
|
|
25
25
|
border: ${borderWidth} solid ${useBorderColor};
|
|
26
26
|
background-color: ${useBackgroundColor};
|
|
27
27
|
|