@pega/cosmos-react-core 9.0.0-build.9.4 → 9.0.0-build.9.6
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/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +6 -4
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +5 -3
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/WeekInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/WeekInput.js +6 -4
- package/lib/components/DateTime/Input/WeekInput.js.map +1 -1
- package/lib/components/Dialog/InfoDialog.js +1 -1
- package/lib/components/Dialog/InfoDialog.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.d.ts.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.js +4 -2
- package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.utils.d.ts +1 -1
- package/lib/components/FieldGroup/FieldGroupList.utils.js +2 -2
- package/lib/components/FieldGroup/FieldGroupList.utils.js.map +1 -1
- package/lib/components/MetaList/MetaList.js +1 -1
- package/lib/components/MetaList/MetaList.js.map +1 -1
- package/lib/components/Popover/Popover.styles.d.ts.map +1 -1
- package/lib/components/Popover/Popover.styles.js +18 -1
- package/lib/components/Popover/Popover.styles.js.map +1 -1
- package/lib/components/Popover/modifiers.d.ts.map +1 -1
- package/lib/components/Popover/modifiers.js +10 -0
- package/lib/components/Popover/modifiers.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/lib/components/Tooltip/Tooltip.js +3 -1
- package/lib/components/Tooltip/Tooltip.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +25 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useItemIntersection.d.ts +2 -1
- package/lib/hooks/useItemIntersection.d.ts.map +1 -1
- package/lib/hooks/useItemIntersection.js +10 -6
- package/lib/hooks/useItemIntersection.js.map +1 -1
- package/lib/i18n/default.d.ts +25 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +26 -0
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +25 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/styles/animations.d.ts +9 -0
- package/lib/styles/animations.d.ts.map +1 -0
- package/lib/styles/animations.js +78 -0
- package/lib/styles/animations.js.map +1 -0
- package/lib/styles/index.d.ts +1 -0
- package/lib/styles/index.d.ts.map +1 -1
- package/lib/styles/index.js +1 -0
- package/lib/styles/index.js.map +1 -1
- package/lib/utils/getFocusables.d.ts +4 -2
- package/lib/utils/getFocusables.d.ts.map +1 -1
- package/lib/utils/getFocusables.js +9 -7
- package/lib/utils/getFocusables.js.map +1 -1
- package/lib/utils/isInstance.d.ts +4 -4
- package/lib/utils/isInstance.d.ts.map +1 -1
- package/lib/utils/isInstance.js +20 -8
- package/lib/utils/isInstance.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfoDialog.js","sourceRoot":"","sources":["../../../src/components/Dialog/InfoDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,gBAAgB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AAE,OAAO,EAChB,SAAS,EACP,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CACtB,KAAC,IAAI,IAAC,OAAO,EAAC,WAAW,YAAE,WAAW,CAAC,SAAS,GAAQ,CACzD,CAAC,CAAC,CAAC,SAAS,EAEf,MAAM,EAAE,WAAW,CAAC,MAAM,GAC1B,CACH,EACA,aAAa,IACT,CACR,EAEA,CAAC,CAAC,WAAW,IAAI,QAAQ,IAAI,YAAY,CAAC,IAAI,CAC7C,MAAC,IAAI,IACH,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAClC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EACjB,EAAE,EAAE,mBAAmB,EACvB,GAAG,EAAE,gBAAgB,aAEpB,CAAC,WAAW,IAAI,aAAa,EAC7B,QAAQ,IAAI,CACX,KAAC,kBAAkB,IAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YACrD,QAAQ,GACU,CACtB,EACA,QAAQ,IACJ,CACR,IACgB,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport { useConsolidatedRef, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';\nimport Text from '../Text';\nimport Icon from '../Icon';\nimport Progress from '../Progress';\nimport Flex from '../Flex';\nimport SummaryItem from '../SummaryItem';\nimport { getActiveElement, getFocusables } from '../../utils';\nimport type { RefElement } from '../../types';\n\nimport { StyledChildrenWrap, StyledDialogContent, StyledDialogHeader } from './Dialog.styles';\nimport type { InfoDialogProps } from './Dialog.types';\nimport { StyledDismissButton, StyledInfoDialog } from './InfoDialog.styles';\n\nconst InfoDialog = forwardRef<RefElement<InfoDialogProps>, PropsWithoutRef<InfoDialogProps>>(\n function InfoDialog(\n { target, heading: headingProp, children, progress: progressProp, onDismiss, ...restProps },\n ref\n ) {\n const t = useI18n();\n const headingId = useUID();\n const dialogRef = useConsolidatedRef(ref);\n const dialogContentRef = useRef<HTMLDivElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n\n const setFocus = () => {\n if (progressProp) return;\n\n const focusables = getFocusables(dialogRef);\n\n const focusable =\n focusables.find(el => {\n return dialogContentRef.current?.contains(el);\n }) ??\n closeButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n };\n\n useEscape(\n e => {\n onDismiss?.();\n e.stopPropagation();\n },\n dialogRef,\n [onDismiss]\n );\n\n useOuterEvent('mousedown', [target, dialogRef], () => {\n onDismiss?.();\n });\n\n // Using layout effect to capture the focused element prior to dialog elements taking focus.\n useLayoutEffect(() => {\n const initiatorElement = getActiveElement();\n\n return () => {\n if (initiatorElement instanceof HTMLElement && initiatorElement.isConnected) {\n initiatorElement.focus();\n }\n };\n }, []);\n\n useEffect(() => {\n if (!progressProp) {\n setFocus();\n }\n }, [progressProp]);\n\n useEffect(() => {\n const closeDialog = () => {\n setTimeout(() => {\n onDismiss?.();\n // The 0 timeout ensures that the dialog will not re-open immediately after the close event is triggered.\n }, 0);\n };\n\n target.addEventListener('click', closeDialog);\n\n return () => {\n target.removeEventListener('click', closeDialog);\n };\n }, []);\n\n const heading = headingProp ? (\n <Text id={headingId} variant='h2'>\n {typeof headingProp === 'string' ? headingProp : headingProp.primary}\n </Text>\n ) : null;\n\n const progress = (\n <Progress\n visible={!!progressProp}\n focusOnVisible\n placement='local'\n message={typeof progressProp === 'string' ? progressProp : undefined}\n />\n );\n\n const dismissButton = (\n <StyledDismissButton\n icon\n variant='simple'\n onClick={() => {\n onDismiss();\n }}\n label={t('close')}\n ref={closeButtonRef}\n >\n <Icon name='times' />\n </StyledDismissButton>\n );\n\n return (\n <StyledInfoDialog\n {...restProps}\n {...(typeof headingProp === 'string'\n ? { 'aria-labelledby': headingId }\n : { 'aria-label': headingProp?.primary })}\n arrow\n target={target}\n progress={progressProp}\n ref={dialogRef}\n >\n {headingProp && heading && (\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: [1, 2], gap: 1 }}\n item={{ shrink: 0 }}\n as={StyledDialogHeader}\n >\n {typeof headingProp === 'string' ? (\n heading\n ) : (\n <SummaryItem\n primary={heading}\n secondary={\n headingProp.secondary ? (\n <Text variant='secondary'>{headingProp.secondary}</Text>\n ) : undefined\n }\n visual={headingProp.visual}\n />\n )}\n {dismissButton}\n </Flex>\n )}\n\n {(!headingProp || children || progressProp) && (\n <Flex\n container={{ direction: 'column' }}\n item={{ grow: 1 }}\n as={StyledDialogContent}\n ref={dialogContentRef}\n >\n {!headingProp && dismissButton}\n {children && (\n <StyledChildrenWrap inert={progressProp ? '' : undefined}>\n {children}\n </StyledChildrenWrap>\n )}\n {progress}\n </Flex>\n )}\n </StyledInfoDialog>\n );\n }\n);\n\nexport default InfoDialog;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroupList.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAc,MAAM,OAAO,CAAC;AAI9D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAqBnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG;IACtD,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,wCAAwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC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OAAO,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,uBAAuB,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC9C,aAAa,EAAE,CAAC,EAAE,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAUD,eAAO,MAAM,cAAc;WAClB,MAAM;oBACG,MAAM;qBACL,OAAO;SA2EzB,CAAC;AAuJF,QAAA,MAAM,cAAc,EAAE,+BAA+B,CAAC,mBAAmB,CAkJxE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { transparentize } from 'polished';
|
|
|
5
5
|
import Button from '../Button';
|
|
6
6
|
import Icon, { registerIcon } from '../Icon';
|
|
7
7
|
import * as plusIcon from '../Icon/icons/plus.icon';
|
|
8
|
-
import { useDirection, useI18n } from '../../hooks';
|
|
8
|
+
import { useDirection, useI18n, useLiveLog } from '../../hooks';
|
|
9
9
|
import { defaultThemeProp } from '../../theme';
|
|
10
10
|
import { getActiveElement, getFocusables, tryCatch } from '../../utils';
|
|
11
11
|
import Flex from '../Flex';
|
|
@@ -123,6 +123,7 @@ const ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }) =>
|
|
|
123
123
|
const { id, children, name = '', isDynamic, headingTag, ...restItemProps } = item;
|
|
124
124
|
const t = useI18n();
|
|
125
125
|
const { rtl } = useDirection();
|
|
126
|
+
const { announcePolite } = useLiveLog();
|
|
126
127
|
const { depth = 1, ancestorIndices = [], isAncestorHighlighted = false } = useContext(FieldGroupListContext);
|
|
127
128
|
const [isItemFocused, setIsItemFocused] = useState(false);
|
|
128
129
|
const [isDeleteHovered, setIsDeleteHovered] = useState(false);
|
|
@@ -155,6 +156,7 @@ const ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }) =>
|
|
|
155
156
|
iconOnly: true,
|
|
156
157
|
onClick: () => {
|
|
157
158
|
handleDelete(id);
|
|
159
|
+
announcePolite({ message: t('deleted', [contextualLabel]) });
|
|
158
160
|
},
|
|
159
161
|
onMouseEnter: () => setIsDeleteHovered(true),
|
|
160
162
|
onMouseLeave: () => setIsDeleteHovered(false)
|
|
@@ -206,7 +208,7 @@ const FieldGroupList = forwardRef(function FieldGroupList({ label, additionalCon
|
|
|
206
208
|
e.stopPropagation();
|
|
207
209
|
}, onBlur: (e) => {
|
|
208
210
|
e.stopPropagation();
|
|
209
|
-
}, children: [label && (_jsxs(Flex, { container: { gap: 0.5, alignItems: 'center' }, children: [_jsx(Text, { variant: 'h3', children: label }), additionalContext && (_jsx(AdditionalInfo, { contextualLabel: label, children: additionalContext })), _jsx(StyledDivider, { "aria-hidden": 'true' })] })), items.length === 0 ? (_jsx(EmptyState, {})) : (_jsx(Flex, { container: { direction: 'column', gap: 1 }, as: StyledFieldGroupList, ref: ref, ...restProps, children: items.map((item, index) => {
|
|
211
|
+
}, children: [label && (_jsxs(Flex, { container: { gap: 0.5, alignItems: 'center' }, children: [_jsx(Text, { variant: 'h3', children: label }), additionalContext && (_jsx(AdditionalInfo, { contextualLabel: label, children: additionalContext })), _jsx(StyledDivider, { "aria-hidden": 'true' })] })), items.length === 0 ? (_jsx(EmptyState, {})) : (_jsx(Flex, { container: { direction: 'column', gap: 1 }, as: StyledFieldGroupList, ref: ref, "aria-label": label, ...restProps, children: items.map((item, index) => {
|
|
210
212
|
const handleDelete = onDelete || item.onDelete
|
|
211
213
|
? (id) => {
|
|
212
214
|
deletedItemIndexRef.current = index;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroupList.js","sourceRoot":"","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IAAC,IAAI,EAAC,MAAM,GAAG,EACnB,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAC9C,CACnB,IACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { forwardRef, useRef, useLayoutEffect, useContext, useMemo, useState } from 'react';\nimport type { PropsWithoutRef, Ref, FocusEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport { useDirection, useI18n } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport { getActiveElement, getFocusables, tryCatch } from '../../utils';\nimport Flex from '../Flex';\nimport EmptyState from '../EmptyState';\nimport AdditionalInfo from '../AdditionalInfo';\nimport Text from '../Text';\nimport { nlpColors, readableHue } from '../../styles';\n\nimport { getIndexDetails } from './FieldGroupList.utils';\nimport FieldGroup, {\n StyledFieldGroup,\n StyledFieldGroupContent,\n StyledFieldGroupLegend,\n StyledGroupContainer,\n StyledFieldHeader\n} from './FieldGroup';\nimport type { FieldGroupProps } from './FieldGroup';\nimport FieldGroupListContext from './FieldGroupListContext';\n\nregisterIcon(plusIcon);\n\nexport type FieldGroupListItemProps = FieldGroupProps & {\n /** The ID of the field group list item */\n id: string;\n /** Item level onDelete callback. */\n onDelete?: (id: string) => void;\n /** Indicates if the item is dynamic. */\n isDynamic?: boolean;\n};\n\nexport interface FieldGroupListProps {\n items: FieldGroupListItemProps[];\n contextualLabel?: string;\n label?: string;\n additionalContext?: string | JSX.Element;\n onAdd?: () => void;\n onDelete?: (id: string) => void;\n ref?: Ref<HTMLOListElement>;\n}\n\nexport interface ListItemProps {\n item: FieldGroupListItemProps;\n index: number;\n isAddFocused: boolean;\n handleDelete: FieldGroupListProps['onDelete'];\n fieldGroupRef: (el: HTMLFieldSetElement | null) => void;\n}\n\nconst StyledFieldGroupList = styled.ol(\n () => css`\n list-style: none;\n `\n);\n\nStyledFieldGroupList.defaultProps = defaultThemeProp;\n\nexport const StyledListItem = styled.li<{\n depth: number;\n listGroupIndex: number;\n shouldHighlight: boolean;\n}>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n depth,\n listGroupIndex,\n shouldHighlight\n }) => {\n const bgColor = tryCatch(\n () => readableHue(nlpColors[listGroupIndex % nlpColors.length], palette['app-background']),\n () => nlpColors[listGroupIndex % nlpColors.length]\n );\n\n return css`\n display: block;\n\n > ${StyledGroupContainer} {\n position: relative;\n padding-inline-end: ${spacing};\n\n &::before {\n content: '';\n position: absolute;\n inset-block-start: 0;\n bottom: 0;\n inset-inline-start: 0;\n width: calc(0.5 * ${spacing});\n background: ${transparentize(0.75, bgColor)};\n }\n\n ${depth > 1 &&\n css`\n margin-inline-end: -${spacing};\n `}\n\n ${shouldHighlight &&\n css`\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.95, palette['foreground-color'])};\n `}\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} {\n margin-block-start: 0;\n padding: ${spacing} 0;\n\n &:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${palette['border-line']};\n margin-block-end: calc(2 * ${spacing});\n }\n\n legend {\n margin-block-end: 0;\n }\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupContent} {\n padding-inline-start: calc(1.5 * ${spacing});\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupLegend} {\n ${StyledFieldHeader} {\n margin-inline-start: calc(0.5 * ${spacing});\n padding-inline: ${spacing};\n height: calc(4 * ${spacing});\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.75, bgColor)};\n }\n }\n `;\n }\n);\n\nStyledListItem.defaultProps = defaultThemeProp;\n\nconst StyledAddButton = styled(Button)(\n ({\n theme: {\n base: {\n spacing,\n 'hit-area': { 'mouse-min': hitAreaMouse }\n }\n }\n }) => css`\n display: inline-flex;\n align-items: center;\n min-height: ${hitAreaMouse};\n min-width: ${hitAreaMouse};\n width: fit-content;\n margin-inline-start: calc(2 * ${spacing});\n `\n);\n\nStyledAddButton.defaultProps = defaultThemeProp;\n\nconst StyledFieldGroupListContainer = styled.div<{ hasAdd: boolean }>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n hasAdd\n }) => css`\n position: relative;\n margin-block-start: ${spacing};\n\n ${hasAdd &&\n css`\n &::before {\n content: '';\n position: absolute;\n inset-inline-start: 0;\n bottom: calc(1.5 * ${spacing});\n width: calc(1.5 * ${spacing});\n height: calc(2.5 * ${spacing});\n border-end-start-radius: calc(0.5 * ${borderRadius});\n border-inline-start: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n border-bottom: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n }\n `}\n `\n);\n\nStyledFieldGroupListContainer.defaultProps = defaultThemeProp;\n\nconst StyledDivider = styled.div(\n ({\n theme: {\n base: { spacing, palette }\n }\n }) => css`\n flex: 1;\n height: calc(0.5 * ${spacing});\n background-color: ${palette['border-line']};\n `\n);\n\nStyledDivider.defaultProps = defaultThemeProp;\n\nconst ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }: ListItemProps) => {\n const { id, children, name = '', isDynamic, headingTag, ...restItemProps } = item;\n\n const t = useI18n();\n const { rtl } = useDirection();\n const {\n depth = 1,\n ancestorIndices = [],\n isAncestorHighlighted = false\n } = useContext(FieldGroupListContext);\n\n const [isItemFocused, setIsItemFocused] = useState(false);\n const [isDeleteHovered, setIsDeleteHovered] = useState(false);\n\n const listIndices = [...ancestorIndices, index];\n const { rootIndex, currentIndex, compoundIndex } = getIndexDetails(listIndices);\n\n const shouldHighlight =\n !isAncestorHighlighted && (isAddFocused || isDeleteHovered || isItemFocused);\n\n let formattedName: string;\n if (isDynamic) {\n formattedName = name;\n } else {\n formattedName = rtl ? `${currentIndex}\\u200F ${name}` : `${currentIndex} ${name}`;\n }\n const contextualLabel = isDynamic ? name : `${name} ${compoundIndex}`;\n\n const ctxValue = useMemo(\n () => ({\n depth: depth + 1,\n isAncestorHighlighted: shouldHighlight || isAncestorHighlighted,\n ancestorIndices: listIndices\n }),\n [depth, index, shouldHighlight, isAncestorHighlighted, listIndices]\n );\n\n return (\n <StyledListItem\n depth={depth}\n listGroupIndex={rootIndex}\n shouldHighlight={shouldHighlight}\n onFocus={() => {\n setIsItemFocused(true);\n }}\n onBlur={() => {\n setIsItemFocused(false);\n }}\n >\n <FieldGroupListContext.Provider value={ctxValue}>\n <FieldGroup\n name={formattedName}\n contextualLabel={contextualLabel}\n headingTag={headingTag}\n {...restItemProps}\n actions={\n handleDelete\n ? [\n {\n id: 'delete',\n text: t('delete'),\n icon: 'trash',\n iconOnly: true,\n onClick: () => {\n handleDelete(id);\n },\n onMouseEnter: () => setIsDeleteHovered(true),\n onMouseLeave: () => setIsDeleteHovered(false)\n }\n ]\n : undefined\n }\n ref={fieldGroupRef}\n >\n {children}\n </FieldGroup>\n </FieldGroupListContext.Provider>\n </StyledListItem>\n );\n};\n\nconst FieldGroupList: ForwardRefForwardPropsComponent<FieldGroupListProps> = forwardRef(\n function FieldGroupList(\n {\n label,\n additionalContext,\n items,\n onAdd,\n onDelete,\n contextualLabel,\n ...restProps\n }: PropsWithoutRef<FieldGroupListProps>,\n ref: FieldGroupListProps['ref']\n ) {\n const t = useI18n();\n\n const addBtnRef = useRef<HTMLButtonElement>(null);\n const itemRefs = useRef<(HTMLFieldSetElement | null)[]>([]);\n const deletedItemIndexRef = useRef<number | null>(null);\n\n const [isAddFocused, setIsAddFocused] = useState(false);\n\n const focusElement = (\n itemRef: HTMLFieldSetElement | null,\n focusPreference: 'action' | 'content'\n ) => {\n if (!itemRef) return;\n\n const focusables = getFocusables(itemRef);\n const groupItemLegend = itemRef.querySelector(':scope > legend');\n\n const groupActionButtons = focusables.filter(focusable =>\n groupItemLegend?.contains(focusable)\n );\n\n const groupContentFocusables = focusables.filter(\n focusable => !groupItemLegend?.contains(focusable)\n );\n\n if (focusPreference === 'action') {\n (groupActionButtons[0] || groupContentFocusables[0])?.focus();\n } else {\n (groupContentFocusables[0] || groupActionButtons[0])?.focus();\n }\n };\n\n useLayoutEffect(() => {\n const currentActiveEl = getActiveElement();\n\n if (deletedItemIndexRef.current !== null) {\n const deletedIndex = deletedItemIndexRef.current;\n\n if (items.length === 0 && addBtnRef.current) {\n addBtnRef.current.focus();\n } else {\n const nextIndex = Math.min(deletedIndex, items.length - 1);\n const nextItemRef = itemRefs.current[nextIndex];\n focusElement(nextItemRef, 'action');\n }\n\n deletedItemIndexRef.current = null;\n }\n\n if (currentActiveEl === addBtnRef.current) {\n const lastIndex = items.length - 1;\n const lastItemRef = itemRefs.current[lastIndex];\n focusElement(lastItemRef, 'content');\n }\n }, [items.length]);\n\n return (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupListContainer}\n hasAdd={!!onAdd}\n onFocus={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n onBlur={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n >\n {label && (\n <Flex container={{ gap: 0.5, alignItems: 'center' }}>\n <Text variant='h3'>{label}</Text>\n\n {additionalContext && (\n <AdditionalInfo contextualLabel={label}>{additionalContext}</AdditionalInfo>\n )}\n\n <StyledDivider aria-hidden='true' />\n </Flex>\n )}\n\n {items.length === 0 ? (\n <EmptyState />\n ) : (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupList}\n ref={ref}\n {...restProps}\n >\n {items.map((item, index) => {\n const handleDelete =\n onDelete || item.onDelete\n ? (id: string) => {\n deletedItemIndexRef.current = index;\n item.onDelete?.(id);\n onDelete?.(id);\n }\n : undefined;\n\n return (\n <ListItem\n key={item.id}\n item={item}\n index={index}\n isAddFocused={isAddFocused}\n handleDelete={handleDelete}\n fieldGroupRef={(el: HTMLFieldSetElement | null) => {\n itemRefs.current[index] = el;\n }}\n />\n );\n })}\n </Flex>\n )}\n\n {onAdd && (\n <StyledAddButton\n variant='link'\n onClick={onAdd}\n onFocus={() => {\n setIsAddFocused(true);\n }}\n onBlur={() => setIsAddFocused(false)}\n ref={addBtnRef}\n >\n <Icon name='plus' />\n {contextualLabel ? t('add_noun', [contextualLabel]) : t('add')}\n </StyledAddButton>\n )}\n </Flex>\n );\n }\n);\n\nexport default FieldGroupList;\n"]}
|
|
1
|
+
{"version":3,"file":"FieldGroupList.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3F,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,IAAI,MAAM,SAAS,CAAC;A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C,EAAE,CAAC,CAAC;wBACjB,CAAC;wBACH,CAAC,CAAC,SAAS,CAAC;oBAEhB,OAAO,CACL,KAAC,QAAQ,IAEP,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,CAAC,EAA8B,EAAE,EAAE;4BAChD,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;wBAC/B,CAAC,IAPI,IAAI,CAAC,EAAE,CAQZ,CACH,CAAC;gBACJ,CAAC,CAAC,GACG,CACR,EAEA,KAAK,IAAI,CACR,MAAC,eAAe,IACd,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,KAAK,EACd,OAAO,EAAE,GAAG,EAAE;oBACZ,eAAe,CAAC,IAAI,CAAC,CAAC;gBACxB,CAAC,EACD,MAAM,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,EACpC,GAAG,EAAE,SAAS,aAEd,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,EACnB,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAC9C,CACnB,IACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { forwardRef, useRef, useLayoutEffect, useContext, useMemo, useState } from 'react';\nimport type { PropsWithoutRef, Ref, FocusEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport { useDirection, useI18n, useLiveLog } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport { getActiveElement, getFocusables, tryCatch } from '../../utils';\nimport Flex from '../Flex';\nimport EmptyState from '../EmptyState';\nimport AdditionalInfo from '../AdditionalInfo';\nimport Text from '../Text';\nimport { nlpColors, readableHue } from '../../styles';\n\nimport { getIndexDetails } from './FieldGroupList.utils';\nimport FieldGroup, {\n StyledFieldGroup,\n StyledFieldGroupContent,\n StyledFieldGroupLegend,\n StyledGroupContainer,\n StyledFieldHeader\n} from './FieldGroup';\nimport type { FieldGroupProps } from './FieldGroup';\nimport FieldGroupListContext from './FieldGroupListContext';\n\nregisterIcon(plusIcon);\n\nexport type FieldGroupListItemProps = FieldGroupProps & {\n /** The ID of the field group list item */\n id: string;\n /** Item level onDelete callback. */\n onDelete?: (id: string) => void;\n /** Indicates if the item is dynamic. */\n isDynamic?: boolean;\n};\n\nexport interface FieldGroupListProps {\n items: FieldGroupListItemProps[];\n contextualLabel?: string;\n label?: string;\n additionalContext?: string | JSX.Element;\n onAdd?: () => void;\n onDelete?: (id: string) => void;\n ref?: Ref<HTMLOListElement>;\n}\n\nexport interface ListItemProps {\n item: FieldGroupListItemProps;\n index: number;\n isAddFocused: boolean;\n handleDelete: FieldGroupListProps['onDelete'];\n fieldGroupRef: (el: HTMLFieldSetElement | null) => void;\n}\n\nconst StyledFieldGroupList = styled.ol(\n () => css`\n list-style: none;\n `\n);\n\nStyledFieldGroupList.defaultProps = defaultThemeProp;\n\nexport const StyledListItem = styled.li<{\n depth: number;\n listGroupIndex: number;\n shouldHighlight: boolean;\n}>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n depth,\n listGroupIndex,\n shouldHighlight\n }) => {\n const bgColor = tryCatch(\n () => readableHue(nlpColors[listGroupIndex % nlpColors.length], palette['app-background']),\n () => nlpColors[listGroupIndex % nlpColors.length]\n );\n\n return css`\n display: block;\n\n > ${StyledGroupContainer} {\n position: relative;\n padding-inline-end: ${spacing};\n\n &::before {\n content: '';\n position: absolute;\n inset-block-start: 0;\n bottom: 0;\n inset-inline-start: 0;\n width: calc(0.5 * ${spacing});\n background: ${transparentize(0.75, bgColor)};\n }\n\n ${depth > 1 &&\n css`\n margin-inline-end: -${spacing};\n `}\n\n ${shouldHighlight &&\n css`\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.95, palette['foreground-color'])};\n `}\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} {\n margin-block-start: 0;\n padding: ${spacing} 0;\n\n &:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${palette['border-line']};\n margin-block-end: calc(2 * ${spacing});\n }\n\n legend {\n margin-block-end: 0;\n }\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupContent} {\n padding-inline-start: calc(1.5 * ${spacing});\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupLegend} {\n ${StyledFieldHeader} {\n margin-inline-start: calc(0.5 * ${spacing});\n padding-inline: ${spacing};\n height: calc(4 * ${spacing});\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.75, bgColor)};\n }\n }\n `;\n }\n);\n\nStyledListItem.defaultProps = defaultThemeProp;\n\nconst StyledAddButton = styled(Button)(\n ({\n theme: {\n base: {\n spacing,\n 'hit-area': { 'mouse-min': hitAreaMouse }\n }\n }\n }) => css`\n display: inline-flex;\n align-items: center;\n min-height: ${hitAreaMouse};\n min-width: ${hitAreaMouse};\n width: fit-content;\n margin-inline-start: calc(2 * ${spacing});\n `\n);\n\nStyledAddButton.defaultProps = defaultThemeProp;\n\nconst StyledFieldGroupListContainer = styled.div<{ hasAdd: boolean }>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n hasAdd\n }) => css`\n position: relative;\n margin-block-start: ${spacing};\n\n ${hasAdd &&\n css`\n &::before {\n content: '';\n position: absolute;\n inset-inline-start: 0;\n bottom: calc(1.5 * ${spacing});\n width: calc(1.5 * ${spacing});\n height: calc(2.5 * ${spacing});\n border-end-start-radius: calc(0.5 * ${borderRadius});\n border-inline-start: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n border-bottom: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n }\n `}\n `\n);\n\nStyledFieldGroupListContainer.defaultProps = defaultThemeProp;\n\nconst StyledDivider = styled.div(\n ({\n theme: {\n base: { spacing, palette }\n }\n }) => css`\n flex: 1;\n height: calc(0.5 * ${spacing});\n background-color: ${palette['border-line']};\n `\n);\n\nStyledDivider.defaultProps = defaultThemeProp;\n\nconst ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }: ListItemProps) => {\n const { id, children, name = '', isDynamic, headingTag, ...restItemProps } = item;\n\n const t = useI18n();\n const { rtl } = useDirection();\n const { announcePolite } = useLiveLog();\n\n const {\n depth = 1,\n ancestorIndices = [],\n isAncestorHighlighted = false\n } = useContext(FieldGroupListContext);\n\n const [isItemFocused, setIsItemFocused] = useState(false);\n const [isDeleteHovered, setIsDeleteHovered] = useState(false);\n\n const listIndices = [...ancestorIndices, index];\n const { rootIndex, currentIndex, compoundIndex } = getIndexDetails(listIndices);\n\n const shouldHighlight =\n !isAncestorHighlighted && (isAddFocused || isDeleteHovered || isItemFocused);\n\n let formattedName: string;\n if (isDynamic) {\n formattedName = name;\n } else {\n formattedName = rtl ? `${currentIndex}\\u200F ${name}` : `${currentIndex} ${name}`;\n }\n const contextualLabel = isDynamic ? name : `${name} ${compoundIndex}`;\n\n const ctxValue = useMemo(\n () => ({\n depth: depth + 1,\n isAncestorHighlighted: shouldHighlight || isAncestorHighlighted,\n ancestorIndices: listIndices\n }),\n [depth, index, shouldHighlight, isAncestorHighlighted, listIndices]\n );\n\n return (\n <StyledListItem\n depth={depth}\n listGroupIndex={rootIndex}\n shouldHighlight={shouldHighlight}\n onFocus={() => {\n setIsItemFocused(true);\n }}\n onBlur={() => {\n setIsItemFocused(false);\n }}\n >\n <FieldGroupListContext.Provider value={ctxValue}>\n <FieldGroup\n name={formattedName}\n contextualLabel={contextualLabel}\n headingTag={headingTag}\n {...restItemProps}\n actions={\n handleDelete\n ? [\n {\n id: 'delete',\n text: t('delete'),\n icon: 'trash',\n iconOnly: true,\n onClick: () => {\n handleDelete(id);\n announcePolite({ message: t('deleted', [contextualLabel]) });\n },\n onMouseEnter: () => setIsDeleteHovered(true),\n onMouseLeave: () => setIsDeleteHovered(false)\n }\n ]\n : undefined\n }\n ref={fieldGroupRef}\n >\n {children}\n </FieldGroup>\n </FieldGroupListContext.Provider>\n </StyledListItem>\n );\n};\n\nconst FieldGroupList: ForwardRefForwardPropsComponent<FieldGroupListProps> = forwardRef(\n function FieldGroupList(\n {\n label,\n additionalContext,\n items,\n onAdd,\n onDelete,\n contextualLabel,\n ...restProps\n }: PropsWithoutRef<FieldGroupListProps>,\n ref: FieldGroupListProps['ref']\n ) {\n const t = useI18n();\n\n const addBtnRef = useRef<HTMLButtonElement>(null);\n const itemRefs = useRef<(HTMLFieldSetElement | null)[]>([]);\n const deletedItemIndexRef = useRef<number | null>(null);\n\n const [isAddFocused, setIsAddFocused] = useState(false);\n\n const focusElement = (\n itemRef: HTMLFieldSetElement | null,\n focusPreference: 'action' | 'content'\n ) => {\n if (!itemRef) return;\n\n const focusables = getFocusables(itemRef);\n const groupItemLegend = itemRef.querySelector(':scope > legend');\n\n const groupActionButtons = focusables.filter(focusable =>\n groupItemLegend?.contains(focusable)\n );\n\n const groupContentFocusables = focusables.filter(\n focusable => !groupItemLegend?.contains(focusable)\n );\n\n if (focusPreference === 'action') {\n (groupActionButtons[0] || groupContentFocusables[0])?.focus();\n } else {\n (groupContentFocusables[0] || groupActionButtons[0])?.focus();\n }\n };\n\n useLayoutEffect(() => {\n const currentActiveEl = getActiveElement();\n\n if (deletedItemIndexRef.current !== null) {\n const deletedIndex = deletedItemIndexRef.current;\n\n if (items.length === 0 && addBtnRef.current) {\n addBtnRef.current.focus();\n } else {\n const nextIndex = Math.min(deletedIndex, items.length - 1);\n const nextItemRef = itemRefs.current[nextIndex];\n focusElement(nextItemRef, 'action');\n }\n\n deletedItemIndexRef.current = null;\n }\n\n if (currentActiveEl === addBtnRef.current) {\n const lastIndex = items.length - 1;\n const lastItemRef = itemRefs.current[lastIndex];\n focusElement(lastItemRef, 'content');\n }\n }, [items.length]);\n\n return (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupListContainer}\n hasAdd={!!onAdd}\n onFocus={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n onBlur={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n >\n {label && (\n <Flex container={{ gap: 0.5, alignItems: 'center' }}>\n <Text variant='h3'>{label}</Text>\n\n {additionalContext && (\n <AdditionalInfo contextualLabel={label}>{additionalContext}</AdditionalInfo>\n )}\n\n <StyledDivider aria-hidden='true' />\n </Flex>\n )}\n\n {items.length === 0 ? (\n <EmptyState />\n ) : (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupList}\n ref={ref}\n aria-label={label}\n {...restProps}\n >\n {items.map((item, index) => {\n const handleDelete =\n onDelete || item.onDelete\n ? (id: string) => {\n deletedItemIndexRef.current = index;\n item.onDelete?.(id);\n onDelete?.(id);\n }\n : undefined;\n\n return (\n <ListItem\n key={item.id}\n item={item}\n index={index}\n isAddFocused={isAddFocused}\n handleDelete={handleDelete}\n fieldGroupRef={(el: HTMLFieldSetElement | null) => {\n itemRefs.current[index] = el;\n }}\n />\n );\n })}\n </Flex>\n )}\n\n {onAdd && (\n <StyledAddButton\n variant='link'\n onClick={onAdd}\n onFocus={() => {\n setIsAddFocused(true);\n }}\n onBlur={() => setIsAddFocused(false)}\n ref={addBtnRef}\n >\n <Icon name='plus' />\n {contextualLabel ? t('add_noun', [contextualLabel]) : t('add')}\n </StyledAddButton>\n )}\n </Flex>\n );\n }\n);\n\nexport default FieldGroupList;\n"]}
|
|
@@ -23,7 +23,7 @@ export declare const getFormattedListNumber: (levelIndex: number, depth: number)
|
|
|
23
23
|
* @returns An object containing:
|
|
24
24
|
* - `rootIndex`: The zero-based index at the root level (e.g., 0 for "1.", 1 for "2.").
|
|
25
25
|
* - `currentIndex`: The index at the latest depth (e.g., "a." or "i.").
|
|
26
|
-
* - `compoundIndex`: The full compound index (e.g., "1
|
|
26
|
+
* - `compoundIndex`: The full compound index (e.g., "1 A II").
|
|
27
27
|
*/
|
|
28
28
|
export declare const getIndexDetails: (indices: number[]) => {
|
|
29
29
|
rootIndex: number;
|
|
@@ -62,13 +62,13 @@ export const getFormattedListNumber = (levelIndex, depth) => {
|
|
|
62
62
|
* @returns An object containing:
|
|
63
63
|
* - `rootIndex`: The zero-based index at the root level (e.g., 0 for "1.", 1 for "2.").
|
|
64
64
|
* - `currentIndex`: The index at the latest depth (e.g., "a." or "i.").
|
|
65
|
-
* - `compoundIndex`: The full compound index (e.g., "1
|
|
65
|
+
* - `compoundIndex`: The full compound index (e.g., "1 A II").
|
|
66
66
|
*/
|
|
67
67
|
export const getIndexDetails = (indices) => {
|
|
68
68
|
const indexSegments = indices.map((levelIndex, index) => getFormattedListNumber(levelIndex, index));
|
|
69
69
|
const rootIndex = indices[0];
|
|
70
70
|
const currentIndex = `${indexSegments[indexSegments.length - 1]}.`;
|
|
71
|
-
const compoundIndex = indexSegments.join('
|
|
71
|
+
const compoundIndex = indexSegments.join(' ').toUpperCase();
|
|
72
72
|
return { rootIndex, currentIndex, compoundIndex };
|
|
73
73
|
};
|
|
74
74
|
//# sourceMappingURL=FieldGroupList.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroupList.utils.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5C,MAAM,QAAQ,GAAuB;QACnC,CAAC,GAAG,EAAE,IAAI,CAAC;QACX,CAAC,IAAI,EAAE,GAAG,CAAC;QACX,CAAC,GAAG,EAAE,G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C,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,cAAc,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAiB,EACmD,EAAE;IACtE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CACtD,sBAAsB,CAAC,UAAU,EAAE,KAAK,CAAC,CAC1C,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,YAAY,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC;IACnE,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"FieldGroupList.utils.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5C,MAAM,QAAQ,GAAuB;QACnC,CAAC,GAAG,EAAE,IAAI,CAAC;QACX,CAAC,IAAI,EAAE,GAAG,CAAC;QACX,CAAC,GAAG,EAAE,GAAG,CAAC;QACV,CAAC,IAAI,EAAE,GAAG,CAAC;QACX,CAAC,GAAG,EAAE,GAAG,CAAC;QACV,CAAC,IAAI,EAAE,EAAE,CAAC;QACV,CAAC,GAAG,EAAE,EAAE,CAAC;QACT,CAAC,IAAI,EAAE,EAAE,CAAC;QACV,CAAC,GAAG,EAAE,EAAE,CAAC;QACT,CAAC,IAAI,EAAE,CAAC,CAAC;QACT,CAAC,GAAG,EAA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AC7B,OAAiB,EACmD,EAAE;IACtE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CACtD,sBAAsB,CAAC,UAAU,EAAE,KAAK,CAAC,CAC1C,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,YAAY,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC;IACnE,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAE5D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACpD,CAAC,CAAC","sourcesContent":["/**\n * Converts a number to a Roman numeral.\n * @param num - The number to convert.\n * @returns The Roman numeral representation.\n */\nexport const convertToRoman = (num: number) => {\n const romanMap: [string, number][] = [\n ['m', 1000],\n ['cm', 900],\n ['d', 500],\n ['cd', 400],\n ['c', 100],\n ['xc', 90],\n ['l', 50],\n ['xl', 40],\n ['x', 10],\n ['ix', 9],\n ['v', 5],\n ['iv', 4],\n ['i', 1]\n ];\n\n let result = '';\n for (const [roman, value] of romanMap) {\n while (num >= value) {\n result += roman;\n num -= value;\n }\n }\n\n return result;\n};\n\n/**\n * Converts a number to a base-26 alphabetic string (a, b, c... aa, ab, ac...).\n * @param num - The 0-based index to convert.\n * @returns The alphabetic representation.\n */\nexport const convertToAlphabetic = (num: number) => {\n let result = '';\n while (num >= 0) {\n result = String.fromCharCode((num % 26) + 97) + result;\n num = Math.floor(num / 26) - 1;\n }\n\n return result;\n};\n\n/**\n * Generates a list number based on depth and index.\n * @param levelIndex - The index of the item in the list (0-based).\n * @param depth - The depth of the list (0-based).\n * @returns The formatted list number.\n */\nexport const getFormattedListNumber = (levelIndex: number, depth: number) => {\n if (depth % 3 === 0) {\n return (levelIndex + 1).toString();\n }\n\n if (depth % 3 === 1) {\n return convertToAlphabetic(levelIndex);\n }\n\n return convertToRoman(levelIndex + 1);\n};\n\n/**\n * Generates a compound index and the current list index based on the depth and index of the current item and its ancestors.\n * @param indices - An array of indices representing the position at each depth (e.g., [0, 1, 2]).\n * @returns An object containing:\n * - `rootIndex`: The zero-based index at the root level (e.g., 0 for \"1.\", 1 for \"2.\").\n * - `currentIndex`: The index at the latest depth (e.g., \"a.\" or \"i.\").\n * - `compoundIndex`: The full compound index (e.g., \"1 A II\").\n */\nexport const getIndexDetails = (\n indices: number[]\n): { rootIndex: number; currentIndex: string; compoundIndex: string } => {\n const indexSegments = indices.map((levelIndex, index) =>\n getFormattedListNumber(levelIndex, index)\n );\n\n const rootIndex = indices[0];\n const currentIndex = `${indexSegments[indexSegments.length - 1]}.`;\n const compoundIndex = indexSegments.join(' ').toUpperCase();\n\n return { rootIndex, currentIndex, compoundIndex };\n};\n"]}
|
|
@@ -44,7 +44,7 @@ export const StyledMetaListItem = styled.li(({ wrapItems }) => {
|
|
|
44
44
|
});
|
|
45
45
|
const MetaList = forwardRef(function MetaList({ testId, items, wrapItems = true, ...restProps }, ref) {
|
|
46
46
|
const testIds = useTestIds(testId, getMetaListTestIds);
|
|
47
|
-
const roleAttrValue = items.length <= 1 ? '
|
|
47
|
+
const roleAttrValue = items.length <= 1 ? 'none' : undefined;
|
|
48
48
|
return (_jsx(Flex, { "data-testid": testIds.root, ...restProps, as: StyledMetaList, role: roleAttrValue, container: { colGap: 0.5, alignItems: 'center', wrap: wrapItems ? 'wrap' : 'nowrap' }, wrapItems: wrapItems, ref: ref, children: items.flatMap((item, i, arr) => item
|
|
49
49
|
? [
|
|
50
50
|
_jsx(Text, { as: StyledMetaListItem, variant: 'secondary', role: roleAttrValue, wrapItems: wrapItems, children: item }, `${i + 0}`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaList.js","sourceRoot":"","sources":["../../../src/components/MetaList/MetaList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,U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,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,EACrF,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,GAAG,YAEP,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAC9B,IAAI;YACF,CAAC,CAAC;gBACE,KAAC,IAAI,IACH,EAAE,EAAE,kBAAkB,EAEtB,OAAO,EAAC,WAAW,EACnB,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,SAAS,YAEnB,IAAI,IALA,GAAG,CAAC,GAAG,CAAC,EAAE,CAMV;aACR,CAAC,MAAM,CACN,CAAC,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC;gBAClB,CAAC,CAAC;oBACE,KAAC,IAAI,IACH,EAAE,EAAE,kBAAkB,uBAGtB,OAAO,EAAC,WAAW,wBADd,GAAG,CAAC,GAAG,CAAC,MAAM,CAId;iBACR;gBACH,CAAC,CAAC,EAAE,CACP;YACH,CAAC,CAAC,EAAE,CACP,GACI,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { ReactNode, Ref, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text from '../Text';\nimport Flex from '../Flex';\nimport type {\n BaseProps,\n ForwardRefForwardPropsComponent,\n NoChildrenProp,\n TestIdProp\n} from '../../types';\nimport { useTestIds } from '../../hooks';\nimport { withTestIds } from '../../utils';\n\nimport { getMetaListTestIds } from './MetaList.test-ids';\n\nexport interface MetaListProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** Array of nodes or text to be rendered in the list. */\n items: ReactNode[];\n /**\n * If true, MetaList items that extend past the MetaList's container will wrap to a new line.\n * @default true\n */\n wrapItems?: boolean;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLUListElement>;\n}\n\nexport const StyledMetaList = styled.ul<{ wrapItems: boolean }>(({ wrapItems }) => {\n return css`\n list-style: none;\n overflow: hidden;\n\n /* Negative margin to account for overflow clipping of focus indicator */\n padding: 0.3rem;\n margin: -0.3rem;\n\n ${!wrapItems &&\n css`\n white-space: nowrap;\n `}\n `;\n});\n\nexport const StyledMetaListItem = styled.li<{ wrapItems: boolean }>(({ wrapItems }) => {\n return css`\n min-width: 0;\n display: inline-block;\n\n ${wrapItems\n ? css`\n overflow-wrap: break-word;\n `\n : css`\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n `}\n\n &[role='separator'] {\n -webkit-user-select: none;\n user-select: none;\n }\n `;\n});\n\nconst MetaList: ForwardRefForwardPropsComponent<MetaListProps> = forwardRef(function MetaList(\n { testId, items, wrapItems = true, ...restProps }: PropsWithoutRef<MetaListProps>,\n ref: MetaListProps['ref']\n) {\n const testIds = useTestIds(testId, getMetaListTestIds);\n const roleAttrValue = items.length <= 1 ? 'none' : undefined;\n\n return (\n <Flex\n data-testid={testIds.root}\n {...restProps}\n as={StyledMetaList}\n role={roleAttrValue}\n container={{ colGap: 0.5, alignItems: 'center', wrap: wrapItems ? 'wrap' : 'nowrap' }}\n wrapItems={wrapItems}\n ref={ref}\n >\n {items.flatMap((item, i, arr) =>\n item\n ? [\n <Text\n as={StyledMetaListItem}\n key={`${i + 0}`}\n variant='secondary'\n role={roleAttrValue}\n wrapItems={wrapItems}\n >\n {item}\n </Text>\n ].concat(\n i !== arr.length - 1\n ? [\n <Text\n as={StyledMetaListItem}\n aria-hidden\n key={`${i + 0}-sep`}\n variant='secondary'\n >\n •\n </Text>\n ]\n : []\n )\n : []\n )}\n </Flex>\n );\n});\n\nexport default withTestIds(MetaList, getMetaListTestIds);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Popover/Popover.styles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Popover.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Popover/Popover.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,yGAW9B,CAAC;AAIF,eAAO,MAAM,aAAa;aAAyB,MAAM;aAAW,OAAO;SA+H1E,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
2
|
import { defaultThemeProp } from '../../theme';
|
|
3
|
+
import { animations } from '../../styles';
|
|
3
4
|
export const StyledPopoverArrow = styled.div `
|
|
4
5
|
background-color: inherit;
|
|
5
6
|
|
|
@@ -13,7 +14,7 @@ export const StyledPopoverArrow = styled.div `
|
|
|
13
14
|
}
|
|
14
15
|
`;
|
|
15
16
|
StyledPopoverArrow.defaultProps = defaultThemeProp;
|
|
16
|
-
export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': borderRadius, 'z-index': { popover: popoverZIndex, backdrop: backdropZIndex }, shadow: { high }, palette }, components: { 'form-control': { 'border-radius': formControlBorderRadius }, popover: { background: popoverBackground } } }, portal, offset }) => {
|
|
17
|
+
export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': borderRadius, 'z-index': { popover: popoverZIndex, backdrop: backdropZIndex }, shadow: { high }, palette, animation }, components: { 'form-control': { 'border-radius': formControlBorderRadius }, popover: { background: popoverBackground } } }, portal, offset }) => {
|
|
17
18
|
return css `
|
|
18
19
|
/*
|
|
19
20
|
Margin should never be used with Popper.
|
|
@@ -25,12 +26,19 @@ export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': bor
|
|
|
25
26
|
border-radius: calc(${formControlBorderRadius} * ${borderRadius});
|
|
26
27
|
box-shadow: ${high};
|
|
27
28
|
color: ${palette['foreground-color']};
|
|
29
|
+
${animations.subProperties}
|
|
30
|
+
--scale-in-size: 1;
|
|
31
|
+
--animation-duration: calc(2 * ${animation.speed});
|
|
32
|
+
|
|
28
33
|
&[data-popper-reference-hidden='true'] {
|
|
29
34
|
visibility: hidden;
|
|
30
35
|
pointer-events: none;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
&[data-popper-placement^='top'] {
|
|
39
|
+
transform-origin: center bottom;
|
|
40
|
+
animation-name: ${animations.reveal}, ${animations.slideInYEnd}, ${animations.scaleIn};
|
|
41
|
+
|
|
34
42
|
> ${StyledPopoverArrow} {
|
|
35
43
|
top: calc(100%);
|
|
36
44
|
|
|
@@ -50,6 +58,9 @@ export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': bor
|
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
&[data-popper-placement^='bottom'] {
|
|
61
|
+
transform-origin: center top;
|
|
62
|
+
animation-name: ${animations.reveal}, ${animations.slideInYStart}, ${animations.scaleIn};
|
|
63
|
+
|
|
53
64
|
> ${StyledPopoverArrow} {
|
|
54
65
|
bottom: calc(100%);
|
|
55
66
|
|
|
@@ -69,6 +80,9 @@ export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': bor
|
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
&[data-popper-placement^='right'] {
|
|
83
|
+
transform-origin: left center;
|
|
84
|
+
animation-name: ${animations.reveal}, ${animations.slideInXStart}, ${animations.scaleIn};
|
|
85
|
+
|
|
72
86
|
> ${StyledPopoverArrow} {
|
|
73
87
|
right: calc(100%);
|
|
74
88
|
|
|
@@ -88,6 +102,9 @@ export const StyledPopover = styled.div(({ theme: { base: { 'border-radius': bor
|
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
&[data-popper-placement^='left'] {
|
|
105
|
+
transform-origin: right center;
|
|
106
|
+
animation-name: ${animations.reveal}, ${animations.slideInXEnd}, ${animations.scaleIn};
|
|
107
|
+
|
|
91
108
|
> ${StyledPopoverArrow} {
|
|
92
109
|
left: calc(100%);
|
|
93
110
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.styles.js","sourceRoot":"","sources":["../../../src/components/Popover/Popover.styles.ts"],"names":[],"mappings":"AAAA,O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AAK,UAAU,CAAC,OAAO;;YAEjF,kBAAkB;;;;+CAIiB,YAAY;;;;;;;oBAOvC,MAAM;qBACL,MAAM;;;;;;;;0BAQD,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,aAAa,KAAK,UAAU,CAAC,OAAO;;YAEnF,kBAAkB;;;;2CAIa,YAAY;;;;;;;oBAOnC,MAAM;kBACR,MAAM;;;;;;;;0BAQE,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,aAAa,KAAK,UAAU,CAAC,OAAO;;YAEnF,kBAAkB;;;;8CAIgB,YAAY;;;;;;;mBAOvC,MAAM;mBACN,MAAM;;;;;;;;0BAQC,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,WAAW,KAAK,UAAU,CAAC,OAAO;;YAEjF,kBAAkB;;;;4CAIc,YAAY;;;;;;;mBAOrC,MAAM;oBACL,MAAM;;;;;KAKrB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,aAAa,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\nimport { animations } from '../../styles';\n\nexport const StyledPopoverArrow = styled.div`\n background-color: inherit;\n\n ::before {\n content: '';\n display: block;\n position: absolute;\n inset: -0.25rem;\n background-color: inherit;\n transform: rotate(45deg);\n }\n`;\n\nStyledPopoverArrow.defaultProps = defaultThemeProp;\n\nexport const StyledPopover = styled.div<{ offset?: number; portal?: boolean }>(\n ({\n theme: {\n base: {\n 'border-radius': borderRadius,\n 'z-index': { popover: popoverZIndex, backdrop: backdropZIndex },\n shadow: { high },\n palette,\n animation\n },\n components: {\n 'form-control': { 'border-radius': formControlBorderRadius },\n popover: { background: popoverBackground }\n }\n },\n portal,\n offset\n }) => {\n return css`\n /*\n Margin should never be used with Popper.\n https://popper.js.org/docs/v2/migration-guide/#4-remove-all-css-margins\n */\n margin: 0 !important;\n z-index: ${portal ? backdropZIndex - 1 : popoverZIndex};\n background: ${popoverBackground};\n border-radius: calc(${formControlBorderRadius} * ${borderRadius});\n box-shadow: ${high};\n color: ${palette['foreground-color']};\n ${animations.subProperties}\n --scale-in-size: 1;\n --animation-duration: calc(2 * ${animation.speed});\n\n &[data-popper-reference-hidden='true'] {\n visibility: hidden;\n pointer-events: none;\n }\n\n &[data-popper-placement^='top'] {\n transform-origin: center bottom;\n animation-name: ${animations.reveal}, ${animations.slideInYEnd}, ${animations.scaleIn};\n\n > ${StyledPopoverArrow} {\n top: calc(100%);\n\n ::before {\n border-bottom-right-radius: calc(${borderRadius} / 4);\n }\n }\n\n ::before {\n content: '';\n position: absolute;\n height: ${offset}px;\n bottom: -${offset}px;\n left: 0;\n right: 0;\n }\n }\n\n &[data-popper-placement^='bottom'] {\n transform-origin: center top;\n animation-name: ${animations.reveal}, ${animations.slideInYStart}, ${animations.scaleIn};\n\n > ${StyledPopoverArrow} {\n bottom: calc(100%);\n\n ::before {\n border-top-left-radius: calc(${borderRadius} / 4);\n }\n }\n\n ::before {\n content: '';\n position: absolute;\n height: ${offset}px;\n top: -${offset}px;\n left: 0;\n right: 0;\n }\n }\n\n &[data-popper-placement^='right'] {\n transform-origin: left center;\n animation-name: ${animations.reveal}, ${animations.slideInXStart}, ${animations.scaleIn};\n\n > ${StyledPopoverArrow} {\n right: calc(100%);\n\n ::before {\n border-bottom-left-radius: calc(${borderRadius} / 4);\n }\n }\n\n ::before {\n content: '';\n position: absolute;\n width: ${offset}px;\n left: -${offset}px;\n top: 0;\n bottom: 0;\n }\n }\n\n &[data-popper-placement^='left'] {\n transform-origin: right center;\n animation-name: ${animations.reveal}, ${animations.slideInXEnd}, ${animations.scaleIn};\n\n > ${StyledPopoverArrow} {\n left: calc(100%);\n\n ::before {\n border-top-right-radius: calc(${borderRadius} / 4);\n }\n }\n\n ::before {\n content: '';\n position: absolute;\n width: ${offset}px;\n right: -${offset}px;\n top: 0;\n bottom: 0;\n }\n }\n `;\n }\n);\n\nStyledPopover.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../../src/components/Popover/modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAQlD,CAAC;AAIH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../../src/components/Popover/modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAQlD,CAAC;AAIH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAsBxD,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAkK9D,CAAC"}
|
|
@@ -15,10 +15,20 @@ export const fitToContent = Object.freeze({
|
|
|
15
15
|
phase: 'beforeWrite',
|
|
16
16
|
requires: ['computeStyles', 'offset'],
|
|
17
17
|
fn({ state }) {
|
|
18
|
+
if (state.elements.popper.dataset.initialized !== 'true') {
|
|
19
|
+
state.elements.popper.style.visibility = 'hidden';
|
|
20
|
+
}
|
|
18
21
|
state.styles.popper.width = 'fit-content';
|
|
19
22
|
// Ideally, we would use `content-width.md` from the theme, but we can't access it outside of a React function component
|
|
20
23
|
state.elements.popper.style.maxWidth = '60ch';
|
|
21
24
|
state.elements.popper.style.minWidth = `${state.rects.reference.width}px`;
|
|
25
|
+
state.elements.popper.style.visibility = 'visible';
|
|
26
|
+
state.elements.popper.dataset.initialized = 'true';
|
|
27
|
+
},
|
|
28
|
+
effect({ instance }) {
|
|
29
|
+
requestAnimationFrame(() => {
|
|
30
|
+
instance.update();
|
|
31
|
+
});
|
|
22
32
|
}
|
|
23
33
|
});
|
|
24
34
|
export const placeAndContain = Object.freeze({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../../../src/components/Popover/modifiers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,CAAC,MAAM,SAAS,GAAkC,MAAM,CAAC,MAAM,CAAC;IACpE,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,aAAa;IACpB,EAAE,CAAC,EAAE,KAAK,EAAE;QACV,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IACjE,CAAC;IACD,QAAQ,EAAE,CAAC,eAAe,CAAC;CAC5B,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,mBAAmB,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,YAAY,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC1E,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,aAAa;IACpB,QAAQ,EAAE,CAAC,eAAe,EAAE,QAAQ,CAAC;IACrC,EAAE,CAAC,EAAE,KAAK,EAAE;QACV,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC;QAC1C,wHAAwH;QACxH,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC9C,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IAC5E,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OAAO,CAAC,KAAK,CAAC;YAE1E;YACE,kDAAkD;YAClD,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,OAAO,CAAC,KAAK;gBACxE,EAAE,EACF,CAAC;gBACD,sCAAsC;gBACtC,iBAAiB,GAAG,4BAA4B,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YACtE,CAAC;QACH,CAAC;QAED,IAAI,iBAAiB,KAAK,MAAM,IAAI,iBAAiB,KAAK,OAAO,EAAE,CAAC;YAClE,gBAAgB,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,gBAAgB,IAAI,CAAC;QAEhE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,eAAe,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAE9F,iBAAiB,GAAG,GAAG,iBAAiB,GACtC,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,2BAA2B,EAAE,CAAC,CAAC,CAAC,EAAE,CAIvE,EAAE,CAAC;QAEH,IAAI,KAAK,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;YAC1C,KAAK,CAAC,SAAS,GAAG,iBAAiB,CAAC;YACpC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { Modifier } from '@popperjs/core';\n\nimport { documentIsAvailable, getScrollbarWidth, testElForOverflow } from '../../utils';\n\nexport const sameWidth: Modifier<'sameWidth', object> = Object.freeze({\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n fn({ state }) {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n requires: ['computeStyles']\n});\n\nconst scrollbarSize = documentIsAvailable ? getScrollbarWidth() : 0;\n\nexport const fitToContent: Modifier<'fitToContent', object> = Object.freeze({\n name: 'fitToContent',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles', 'offset'],\n fn({ state }) {\n state.styles.popper.width = 'fit-content';\n // Ideally, we would use `content-width.md` from the theme, but we can't access it outside of a React function component\n state.elements.popper.style.maxWidth = '60ch';\n state.elements.popper.style.minWidth = `${state.rects.reference.width}px`;\n }\n});\n\nexport const placeAndContain: Modifier<'placeAndContain', object> = Object.freeze({\n name: 'placeAndContain',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles', 'offset'],\n fn: ({ state }) => {\n const [requestedPrimaryPlacement, requestedSecondaryPlacement] = state.placement.split('-') as [\n primaryPlacement: 'top' | 'bottom' | 'left' | 'right' | 'auto',\n secondaryPlacement?: 'start' | 'end' | undefined\n ];\n\n const padding = {\n top: 0,\n bottom: 0,\n right: 0,\n left: 0\n };\n\n const preventOverflowPad = state.orderedModifiers.find(({ name }) => name === 'preventOverflow')\n ?.options?.padding;\n\n if (typeof preventOverflowPad === 'number') {\n padding.top = preventOverflowPad;\n padding.bottom = preventOverflowPad;\n padding.right = preventOverflowPad;\n padding.left = preventOverflowPad;\n } else if (preventOverflowPad) {\n padding.top = preventOverflowPad.top ?? padding.top;\n padding.bottom = preventOverflowPad.bottom ?? padding.bottom;\n padding.right = preventOverflowPad.right ?? padding.right;\n padding.left = preventOverflowPad.left ?? padding.left;\n }\n\n const vw = document.documentElement.clientWidth;\n const vh = document.documentElement.clientHeight;\n\n const targetRect = state.rects.reference;\n const targetRectXStart = targetRect.x;\n const targetRectXEnd = targetRectXStart + targetRect.width;\n const targetRectYStart = targetRect.y;\n const targetRectYEnd = targetRectYStart + targetRect.height;\n const targetXMid = (targetRectXStart + targetRectXEnd) / 2;\n const targetYMid = (targetRectYStart + targetRectYEnd) / 2;\n const targetIsInLeftHalfOfViewport = targetXMid < vw / 2;\n const targetIsInTopHalfOfViewport = targetYMid < vh / 2;\n\n const offsetFromTargetX = state.modifiersData.offset?.[state.placement]?.x ?? 0;\n const offsetFromTargetY = state.modifiersData.offset?.[state.placement]?.y ?? 0;\n\n let popoverMaxWidth: null | number = null;\n let popoverMaxHeight: null | number = null;\n\n // The elements whose natural content size should be measured to determine resolved placement\n const scrollableEls = [...state.elements.popper.children].flatMap(popoverChildEl => {\n // Default to measuring direct popover children unless they have measureable items declared within\n const elsToMeasure = popoverChildEl.querySelectorAll('[data-popover-scroll-el]');\n return elsToMeasure.length > 0 ? [...elsToMeasure] : popoverChildEl;\n });\n\n const totalScrollableChildHeight = scrollableEls.reduce((sum, el) => {\n if (el === state.elements.arrow) {\n return sum;\n }\n\n if (testElForOverflow(el)[0]) {\n return sum + el.scrollHeight + scrollbarSize;\n }\n\n return sum + el.scrollHeight;\n }, 0);\n\n const naturalPopoverHeight = Math.max(\n state.elements.popper.scrollHeight,\n totalScrollableChildHeight\n );\n\n const naturalPopoverWidth = Math.max(\n state.elements.popper.scrollWidth,\n ...Array.from(state.elements.popper.children).map(el => {\n if (el === state.elements.arrow) {\n return -Infinity;\n }\n\n if (testElForOverflow(el)[1]) {\n return el.scrollWidth + scrollbarSize;\n }\n\n return el.scrollWidth;\n })\n );\n\n let resolvedPlacement: `${'top' | 'bottom' | 'left' | 'right' | 'auto'}${\n | ''\n | '-start'\n | '-end'}` = requestedPrimaryPlacement;\n\n if (requestedPrimaryPlacement === 'bottom') {\n popoverMaxHeight = vh - targetRectYEnd - offsetFromTargetY - padding.bottom;\n\n if (\n // If the popover will overflow the viewport bottom\n targetRectYEnd + offsetFromTargetY + naturalPopoverHeight + padding.bottom >\n vh\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInTopHalfOfViewport ? 'bottom' : 'top';\n }\n } else if (requestedPrimaryPlacement === 'top') {\n popoverMaxHeight = targetRectYStart + offsetFromTargetY - padding.top;\n\n if (\n // If the popover will overflow the viewport top\n targetRectYStart + offsetFromTargetY - naturalPopoverHeight + padding.top <\n 0\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInTopHalfOfViewport ? 'bottom' : 'top';\n }\n } else if (requestedPrimaryPlacement === 'left') {\n popoverMaxWidth = targetRectXStart + offsetFromTargetX - padding.left;\n\n if (\n // If the popover will overflow the viewport left\n targetRectXStart + offsetFromTargetX - naturalPopoverWidth + padding.left <\n 0\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInLeftHalfOfViewport ? 'right' : 'left';\n }\n } else if (requestedPrimaryPlacement === 'right') {\n popoverMaxWidth = vw - targetRectXEnd - offsetFromTargetX - padding.right;\n\n if (\n // If the popover will overflow the viewport right\n targetRectXEnd + offsetFromTargetX + naturalPopoverWidth + padding.right >\n vw\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInLeftHalfOfViewport ? 'right' : 'left';\n }\n }\n\n if (resolvedPlacement === 'left' || resolvedPlacement === 'right') {\n popoverMaxHeight = vh - padding.top - padding.bottom;\n }\n\n state.elements.popper.style.maxHeight = `${popoverMaxHeight}px`;\n\n state.elements.popper.style.maxWidth = popoverMaxWidth !== null ? `${popoverMaxWidth}px` : '';\n\n resolvedPlacement = `${resolvedPlacement}${\n (requestedSecondaryPlacement ? `-${requestedSecondaryPlacement}` : '') as\n | ''\n | '-start'\n | '-end'\n }`;\n\n if (state.placement !== resolvedPlacement) {\n state.placement = resolvedPlacement;\n state.reset = true;\n }\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../../../src/components/Popover/modifiers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,CAAC,MAAM,SAAS,GAAkC,MAAM,CAAC,MAAM,CAAC;IACpE,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,aAAa;IACpB,EAAE,CAAC,EAAE,KAAK,EAAE;QACV,KAAK,CAA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AAG,cAAc,GAAG,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;YAE1E;YACE,kDAAkD;YAClD,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,OAAO,CAAC,KAAK;gBACxE,EAAE,EACF,CAAC;gBACD,sCAAsC;gBACtC,iBAAiB,GAAG,4BAA4B,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YACtE,CAAC;QACH,CAAC;QAED,IAAI,iBAAiB,KAAK,MAAM,IAAI,iBAAiB,KAAK,OAAO,EAAE,CAAC;YAClE,gBAAgB,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,gBAAgB,IAAI,CAAC;QAEhE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,eAAe,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAE9F,iBAAiB,GAAG,GAAG,iBAAiB,GACtC,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,2BAA2B,EAAE,CAAC,CAAC,CAAC,EAAE,CAIvE,EAAE,CAAC;QAEH,IAAI,KAAK,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;YAC1C,KAAK,CAAC,SAAS,GAAG,iBAAiB,CAAC;YACpC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { Modifier } from '@popperjs/core';\n\nimport { documentIsAvailable, getScrollbarWidth, testElForOverflow } from '../../utils';\n\nexport const sameWidth: Modifier<'sameWidth', object> = Object.freeze({\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n fn({ state }) {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n requires: ['computeStyles']\n});\n\nconst scrollbarSize = documentIsAvailable ? getScrollbarWidth() : 0;\n\nexport const fitToContent: Modifier<'fitToContent', object> = Object.freeze({\n name: 'fitToContent',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles', 'offset'],\n fn({ state }) {\n if (state.elements.popper.dataset.initialized !== 'true') {\n state.elements.popper.style.visibility = 'hidden';\n }\n state.styles.popper.width = 'fit-content';\n // Ideally, we would use `content-width.md` from the theme, but we can't access it outside of a React function component\n state.elements.popper.style.maxWidth = '60ch';\n state.elements.popper.style.minWidth = `${state.rects.reference.width}px`;\n\n state.elements.popper.style.visibility = 'visible';\n state.elements.popper.dataset.initialized = 'true';\n },\n effect({ instance }) {\n requestAnimationFrame(() => {\n instance.update();\n });\n }\n});\n\nexport const placeAndContain: Modifier<'placeAndContain', object> = Object.freeze({\n name: 'placeAndContain',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles', 'offset'],\n fn: ({ state }) => {\n const [requestedPrimaryPlacement, requestedSecondaryPlacement] = state.placement.split('-') as [\n primaryPlacement: 'top' | 'bottom' | 'left' | 'right' | 'auto',\n secondaryPlacement?: 'start' | 'end' | undefined\n ];\n\n const padding = {\n top: 0,\n bottom: 0,\n right: 0,\n left: 0\n };\n\n const preventOverflowPad = state.orderedModifiers.find(({ name }) => name === 'preventOverflow')\n ?.options?.padding;\n\n if (typeof preventOverflowPad === 'number') {\n padding.top = preventOverflowPad;\n padding.bottom = preventOverflowPad;\n padding.right = preventOverflowPad;\n padding.left = preventOverflowPad;\n } else if (preventOverflowPad) {\n padding.top = preventOverflowPad.top ?? padding.top;\n padding.bottom = preventOverflowPad.bottom ?? padding.bottom;\n padding.right = preventOverflowPad.right ?? padding.right;\n padding.left = preventOverflowPad.left ?? padding.left;\n }\n\n const vw = document.documentElement.clientWidth;\n const vh = document.documentElement.clientHeight;\n\n const targetRect = state.rects.reference;\n const targetRectXStart = targetRect.x;\n const targetRectXEnd = targetRectXStart + targetRect.width;\n const targetRectYStart = targetRect.y;\n const targetRectYEnd = targetRectYStart + targetRect.height;\n const targetXMid = (targetRectXStart + targetRectXEnd) / 2;\n const targetYMid = (targetRectYStart + targetRectYEnd) / 2;\n const targetIsInLeftHalfOfViewport = targetXMid < vw / 2;\n const targetIsInTopHalfOfViewport = targetYMid < vh / 2;\n\n const offsetFromTargetX = state.modifiersData.offset?.[state.placement]?.x ?? 0;\n const offsetFromTargetY = state.modifiersData.offset?.[state.placement]?.y ?? 0;\n\n let popoverMaxWidth: null | number = null;\n let popoverMaxHeight: null | number = null;\n\n // The elements whose natural content size should be measured to determine resolved placement\n const scrollableEls = [...state.elements.popper.children].flatMap(popoverChildEl => {\n // Default to measuring direct popover children unless they have measureable items declared within\n const elsToMeasure = popoverChildEl.querySelectorAll('[data-popover-scroll-el]');\n return elsToMeasure.length > 0 ? [...elsToMeasure] : popoverChildEl;\n });\n\n const totalScrollableChildHeight = scrollableEls.reduce((sum, el) => {\n if (el === state.elements.arrow) {\n return sum;\n }\n\n if (testElForOverflow(el)[0]) {\n return sum + el.scrollHeight + scrollbarSize;\n }\n\n return sum + el.scrollHeight;\n }, 0);\n\n const naturalPopoverHeight = Math.max(\n state.elements.popper.scrollHeight,\n totalScrollableChildHeight\n );\n\n const naturalPopoverWidth = Math.max(\n state.elements.popper.scrollWidth,\n ...Array.from(state.elements.popper.children).map(el => {\n if (el === state.elements.arrow) {\n return -Infinity;\n }\n\n if (testElForOverflow(el)[1]) {\n return el.scrollWidth + scrollbarSize;\n }\n\n return el.scrollWidth;\n })\n );\n\n let resolvedPlacement: `${'top' | 'bottom' | 'left' | 'right' | 'auto'}${\n | ''\n | '-start'\n | '-end'}` = requestedPrimaryPlacement;\n\n if (requestedPrimaryPlacement === 'bottom') {\n popoverMaxHeight = vh - targetRectYEnd - offsetFromTargetY - padding.bottom;\n\n if (\n // If the popover will overflow the viewport bottom\n targetRectYEnd + offsetFromTargetY + naturalPopoverHeight + padding.bottom >\n vh\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInTopHalfOfViewport ? 'bottom' : 'top';\n }\n } else if (requestedPrimaryPlacement === 'top') {\n popoverMaxHeight = targetRectYStart + offsetFromTargetY - padding.top;\n\n if (\n // If the popover will overflow the viewport top\n targetRectYStart + offsetFromTargetY - naturalPopoverHeight + padding.top <\n 0\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInTopHalfOfViewport ? 'bottom' : 'top';\n }\n } else if (requestedPrimaryPlacement === 'left') {\n popoverMaxWidth = targetRectXStart + offsetFromTargetX - padding.left;\n\n if (\n // If the popover will overflow the viewport left\n targetRectXStart + offsetFromTargetX - naturalPopoverWidth + padding.left <\n 0\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInLeftHalfOfViewport ? 'right' : 'left';\n }\n } else if (requestedPrimaryPlacement === 'right') {\n popoverMaxWidth = vw - targetRectXEnd - offsetFromTargetX - padding.right;\n\n if (\n // If the popover will overflow the viewport right\n targetRectXEnd + offsetFromTargetX + naturalPopoverWidth + padding.right >\n vw\n ) {\n // Choose the side with most allowance\n resolvedPlacement = targetIsInLeftHalfOfViewport ? 'right' : 'left';\n }\n }\n\n if (resolvedPlacement === 'left' || resolvedPlacement === 'right') {\n popoverMaxHeight = vh - padding.top - padding.bottom;\n }\n\n state.elements.popper.style.maxHeight = `${popoverMaxHeight}px`;\n\n state.elements.popper.style.maxWidth = popoverMaxWidth !== null ? `${popoverMaxWidth}px` : '';\n\n resolvedPlacement = `${resolvedPlacement}${\n (requestedSecondaryPlacement ? `-${requestedSecondaryPlacement}` : '') as\n | ''\n | '-start'\n | '-end'\n }`;\n\n if (state.placement !== resolvedPlacement) {\n state.placement = resolvedPlacement;\n state.reset = true;\n }\n }\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqC,SAAS,EAAE,G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SAAQ,SAAS,EAAE,UAAU;IACzD,oCAAoC;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,gDAAgD;IAChD,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC3C;;;OAGG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IACtC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IAClC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,aAAa,yGAcxB,CAAC;;;;AA4LH,wBAAuD"}
|
|
@@ -15,9 +15,11 @@ export const StyledTooltip = styled.div(({ theme }) => {
|
|
|
15
15
|
color: ${theme.components.tooltip['foreground-color']};
|
|
16
16
|
font-size: ${fontSize.xxs};
|
|
17
17
|
max-width: 40ch;
|
|
18
|
-
padding: ${theme.base.spacing};
|
|
18
|
+
padding: calc(${theme.base.spacing} / 2);
|
|
19
19
|
white-space: pre-line;
|
|
20
20
|
word-break: break-word;
|
|
21
|
+
--scale-in-size: 0;
|
|
22
|
+
--animation-duration: ${theme.base.animation.speed};
|
|
21
23
|
`;
|
|
22
24
|
});
|
|
23
25
|
StyledTooltip.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],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B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAC9B,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAC7C;aACF;SACF;KACF,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,IAAC,KAAK,EAAE,YAAY,YAChC,KAAC,OAAO,mBACO,OAAO,CAAC,IAAI,EACzB,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,OAAO,KACZ,SAAS,EACb,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAC3C,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAC3C,WAAW,EAAE,GAAG,EAAE;gBAChB,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,EACD,UAAU,EAAE,GAAG,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,EACD,QAAQ,EAAC,OAAO,EAChB,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAC9C,MAAM,EAAE,MAAM,EACd,KAAK,QACL,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,kBAAkB,QAClB,GAAG,EAAE,UAAU,YAEd,QAAQ,GACD,GACI,CACjB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport type { MutableRefObject, PropsWithoutRef, ReactNode, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover from '../Popover';\nimport type { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useTestIds, useTheme, useUID } from '../../hooks';\nimport { calculateFontSize, readableHue } from '../../styles';\nimport { getActiveElement, mouseState, testElForOverflow, withTestIds } from '../../utils';\nimport { ThemeOverride } from '../Configuration';\n\nimport { getTooltipTestIds } from './Tooltip.test-ids';\n\nexport interface TooltipProps extends BaseProps, TestIdProp {\n /** Text content for the tooltip. */\n children: ReactNode;\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /** Elements to ignore from within the tooltip's target. */\n ignoredElements?: TooltipProps['target'][];\n /**\n * Delay showing the tooltip on mouseenter.\n * @default 'short'\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default 'long'\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default true\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n /**\n * Sets the placement of the tooltip relative to the target.\n * @default 'bottom'\n */\n placement?: PopoverProps['placement'];\n /**\n * Conditionally renders a tooltip only if the associated element's (or its descendants) text content is truncated.\n * To work, the associated element must be be displayed as a CSS \"block box\" i.e. block, inline-block, etc...\n * @default false\n */\n smart?: boolean;\n /**\n * The group that the Popover belongs to. Popovers in the same group will be closed when others open.\n * @default 'tooltip'\n */\n groupId?: PopoverProps['groupId'];\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: ${theme.base.spacing};\n white-space: pre-line;\n word-break: break-word;\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: ForwardRefForwardPropsComponent<TooltipProps> = forwardRef(function Tooltip(\n {\n testId,\n children,\n target,\n ignoredElements = [],\n showDelay = 'short',\n hideDelay = 'long',\n placement = 'top',\n describeTarget = true,\n smart,\n groupId = 'tooltip',\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: TooltipProps['ref']\n) {\n const id = useUID();\n const [show, setShow] = useState(false);\n const [ignoreDelay, setIgnoreDelay] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n const testIds = useTestIds(testId, getTooltipTestIds);\n\n const stringContentOnly =\n typeof children === 'string' ||\n (Array.isArray(children) && children.every(child => typeof child === 'string'));\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n const showTooltip = () => {\n // This approach may result in a tooltip NOT appearing 1px before it should due to browser specifics. Enhance as needed.\n // https://stackoverflow.com/a/64747288\n\n const checkTruncation = (element: Element): boolean => {\n if (\n testElForOverflow(element).some(Boolean) &&\n !['absolute', 'fixed'].includes(window.getComputedStyle(element).position)\n )\n return true;\n\n for (const child of element.children) {\n if (checkTruncation(child)) return true;\n }\n\n return false;\n };\n\n setShow(smart ? checkTruncation(target) : true);\n };\n\n const onFocusIn = () => {\n showTooltip();\n };\n\n const onFocusOut = () => {\n if (!lastClickedRef.current || lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n };\n\n const onMouseEnter = () => {\n if (ignoredElements.some(exclusion => exclusion?.matches(':hover')) || mouseState.primary) {\n return;\n }\n\n showTooltip();\n };\n\n const onMouseLeave = () => {\n if (getActiveElement() !== target) {\n setShow(false);\n }\n };\n\n const onKeyDown = ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && show) {\n setIgnoreDelay(true);\n setShow(false);\n }\n };\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', onFocusIn);\n target.addEventListener('focusout', onFocusOut);\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', onFocusIn);\n target.removeEventListener('focusout', onFocusOut);\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, onMouseDown, smart, show]);\n\n useEffect(() => {\n if (target && describeTarget && show) {\n const describedBy = target.getAttribute('aria-describedby');\n // Set the attribute to the old attribute plus the id\n target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);\n } else if (target) {\n // Get the old attribute\n const describedBy = target.getAttribute('aria-describedby');\n if (describedBy) {\n // If the old attribute matches the id just remove it entirely\n if (describedBy === id) {\n target.removeAttribute('aria-describedby');\n } else {\n // Otherwise we want to just remove the id that was added and reset the attribute to what it was before\n const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\\\s+)${id}`), '');\n target.setAttribute('aria-describedby', oldDescribedBy);\n }\n }\n }\n }, [describeTarget, target, show]);\n\n useEffect(() => {\n if (!show && ignoreDelay) {\n setIgnoreDelay(false);\n }\n }, [show, ignoreDelay]);\n\n const theme = useTheme();\n const tooltipTheme = {\n base: {\n palette: {\n 'primary-background': theme.components.tooltip['background-color'],\n 'foreground-color': theme.components.tooltip['foreground-color'],\n interactive: readableHue(\n theme.base.palette.interactive,\n theme.components.tooltip['background-color']\n )\n }\n }\n };\n\n return (\n <ThemeOverride theme={tooltipTheme}>\n <Popover\n data-testid={testIds.root}\n id={id}\n groupId={groupId}\n {...restProps}\n show={show}\n showDelay={ignoreDelay ? 'none' : showDelay}\n hideDelay={ignoreDelay ? 'none' : hideDelay}\n onMouseOver={() => {\n setShow(true);\n }}\n onMouseOut={() => {\n setShow(false);\n }}\n strategy='fixed'\n as={StyledTooltip}\n role={stringContentOnly ? 'tooltip' : 'dialog'}\n target={target}\n arrow\n placement={placement}\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n </ThemeOverride>\n );\n});\n\nexport default withTestIds(Tooltip, getTooltipTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAgDvD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEtF,OAAO,GAAG,CAAA;wBACY,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC;aACvD,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC;iBACxC,QAAQ,CAAC,GA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E,iBAAiB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport type { MutableRefObject, PropsWithoutRef, ReactNode, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover from '../Popover';\nimport type { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useTestIds, useTheme, useUID } from '../../hooks';\nimport { calculateFontSize, readableHue } from '../../styles';\nimport { getActiveElement, mouseState, testElForOverflow, withTestIds } from '../../utils';\nimport { ThemeOverride } from '../Configuration';\n\nimport { getTooltipTestIds } from './Tooltip.test-ids';\n\nexport interface TooltipProps extends BaseProps, TestIdProp {\n /** Text content for the tooltip. */\n children: ReactNode;\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /** Elements to ignore from within the tooltip's target. */\n ignoredElements?: TooltipProps['target'][];\n /**\n * Delay showing the tooltip on mouseenter.\n * @default 'short'\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default 'long'\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default true\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n /**\n * Sets the placement of the tooltip relative to the target.\n * @default 'bottom'\n */\n placement?: PopoverProps['placement'];\n /**\n * Conditionally renders a tooltip only if the associated element's (or its descendants) text content is truncated.\n * To work, the associated element must be be displayed as a CSS \"block box\" i.e. block, inline-block, etc...\n * @default false\n */\n smart?: boolean;\n /**\n * The group that the Popover belongs to. Popovers in the same group will be closed when others open.\n * @default 'tooltip'\n */\n groupId?: PopoverProps['groupId'];\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: calc(${theme.base.spacing} / 2);\n white-space: pre-line;\n word-break: break-word;\n --scale-in-size: 0;\n --animation-duration: ${theme.base.animation.speed};\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: ForwardRefForwardPropsComponent<TooltipProps> = forwardRef(function Tooltip(\n {\n testId,\n children,\n target,\n ignoredElements = [],\n showDelay = 'short',\n hideDelay = 'long',\n placement = 'top',\n describeTarget = true,\n smart,\n groupId = 'tooltip',\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: TooltipProps['ref']\n) {\n const id = useUID();\n const [show, setShow] = useState(false);\n const [ignoreDelay, setIgnoreDelay] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n const testIds = useTestIds(testId, getTooltipTestIds);\n\n const stringContentOnly =\n typeof children === 'string' ||\n (Array.isArray(children) && children.every(child => typeof child === 'string'));\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n const showTooltip = () => {\n // This approach may result in a tooltip NOT appearing 1px before it should due to browser specifics. Enhance as needed.\n // https://stackoverflow.com/a/64747288\n\n const checkTruncation = (element: Element): boolean => {\n if (\n testElForOverflow(element).some(Boolean) &&\n !['absolute', 'fixed'].includes(window.getComputedStyle(element).position)\n )\n return true;\n\n for (const child of element.children) {\n if (checkTruncation(child)) return true;\n }\n\n return false;\n };\n\n setShow(smart ? checkTruncation(target) : true);\n };\n\n const onFocusIn = () => {\n showTooltip();\n };\n\n const onFocusOut = () => {\n if (!lastClickedRef.current || lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n };\n\n const onMouseEnter = () => {\n if (ignoredElements.some(exclusion => exclusion?.matches(':hover')) || mouseState.primary) {\n return;\n }\n\n showTooltip();\n };\n\n const onMouseLeave = () => {\n if (getActiveElement() !== target) {\n setShow(false);\n }\n };\n\n const onKeyDown = ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && show) {\n setIgnoreDelay(true);\n setShow(false);\n }\n };\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', onFocusIn);\n target.addEventListener('focusout', onFocusOut);\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', onFocusIn);\n target.removeEventListener('focusout', onFocusOut);\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, onMouseDown, smart, show]);\n\n useEffect(() => {\n if (target && describeTarget && show) {\n const describedBy = target.getAttribute('aria-describedby');\n // Set the attribute to the old attribute plus the id\n target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);\n } else if (target) {\n // Get the old attribute\n const describedBy = target.getAttribute('aria-describedby');\n if (describedBy) {\n // If the old attribute matches the id just remove it entirely\n if (describedBy === id) {\n target.removeAttribute('aria-describedby');\n } else {\n // Otherwise we want to just remove the id that was added and reset the attribute to what it was before\n const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\\\s+)${id}`), '');\n target.setAttribute('aria-describedby', oldDescribedBy);\n }\n }\n }\n }, [describeTarget, target, show]);\n\n useEffect(() => {\n if (!show && ignoreDelay) {\n setIgnoreDelay(false);\n }\n }, [show, ignoreDelay]);\n\n const theme = useTheme();\n const tooltipTheme = {\n base: {\n palette: {\n 'primary-background': theme.components.tooltip['background-color'],\n 'foreground-color': theme.components.tooltip['foreground-color'],\n interactive: readableHue(\n theme.base.palette.interactive,\n theme.components.tooltip['background-color']\n )\n }\n }\n };\n\n return (\n <ThemeOverride theme={tooltipTheme}>\n <Popover\n data-testid={testIds.root}\n id={id}\n groupId={groupId}\n {...restProps}\n show={show}\n showDelay={ignoreDelay ? 'none' : showDelay}\n hideDelay={ignoreDelay ? 'none' : hideDelay}\n onMouseOver={() => {\n setShow(true);\n }}\n onMouseOut={() => {\n setShow(false);\n }}\n strategy='fixed'\n as={StyledTooltip}\n role={stringContentOnly ? 'tooltip' : 'dialog'}\n target={target}\n arrow\n placement={placement}\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n </ThemeOverride>\n );\n});\n\nexport default withTestIds(Tooltip, getTooltipTestIds);\n"]}
|