@muraldevkit/ui-toolkit 4.84.0 → 4.84.1
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/dist/cjs/components/avatar/MrlAvatar/MrlAvatar.js.map +1 -1
- package/dist/cjs/components/callout/MrlCallout/MrlCallout.js.map +1 -1
- package/dist/cjs/components/form/textarea/MrlTextarea/MrlTextarea.js.map +1 -1
- package/dist/cjs/components/grid/constants.js.map +1 -1
- package/dist/cjs/components/live-region/MrlLiveRegion/MrlLiveRegion.js.map +1 -1
- package/dist/cjs/components/popover/MrlPopover/MrlPopover.js.map +1 -1
- package/dist/cjs/components/portal/MrlPortal.js.map +1 -1
- package/dist/cjs/components/rovingTabindex/MrlRovingTabindex/MrlRovingTabindex.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/components/avatar/MrlAvatar/MrlAvatar.js.map +1 -1
- package/dist/esm/components/callout/MrlCallout/MrlCallout.js.map +1 -1
- package/dist/esm/components/form/textarea/MrlTextarea/MrlTextarea.js.map +1 -1
- package/dist/esm/components/grid/constants.js.map +1 -1
- package/dist/esm/components/live-region/MrlLiveRegion/MrlLiveRegion.js.map +1 -1
- package/dist/esm/components/popover/MrlPopover/MrlPopover.js.map +1 -1
- package/dist/esm/components/portal/MrlPortal.js.map +1 -1
- package/dist/esm/components/rovingTabindex/MrlRovingTabindex/MrlRovingTabindex.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/components/avatar/MrlAvatar/MrlAvatar.d.ts +2 -2
- package/dist/types/components/callout/MrlCallout/MrlCallout.d.ts +1 -2
- package/dist/types/components/form/textarea/MrlTextarea/MrlTextarea.d.ts +1 -1
- package/dist/types/components/grid/constants.d.ts +2 -3
- package/dist/types/components/grid/index.d.ts +1 -1
- package/dist/types/components/live-region/MrlLiveRegion/MrlLiveRegion.d.ts +1 -2
- package/dist/types/components/live-region/MrlLiveRegion/index.d.ts +1 -1
- package/dist/types/components/popover/MrlPopover/MrlPopover.d.ts +1 -2
- package/dist/types/components/portal/MrlPortal.d.ts +1 -2
- package/dist/types/components/rovingTabindex/MrlRovingTabindex/MrlRovingTabindex.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MrlRovingTabindex.js","sources":["../../../../../src/components/rovingTabindex/MrlRovingTabindex/MrlRovingTabindex.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype RefType = HTMLElement | HTMLDivElement | null;\n\n/**\n * Gets tabbable elements in a given bit of the DOM, excluding disabled elements\n * @param {RefType} ref - the ref of the container\n * @param {string} selector - the selector to query (should already exclude disabled elements)\n * @returns {HTMLElement[]} - an array of tabbable HTML elements\n */\nexport const getTabbableElements = (ref: RefType, selector: string): HTMLElement[] => {\n\tconst elements = ref?.querySelectorAll(selector);\n\tif (!elements) return [];\n\treturn Array.prototype.slice.call(elements);\n};\n\nconst arraysEqual = (a: (Element | null)[], b: (Element | null)[]): boolean =>\n\ta.length === b.length && a.every((el, i) => el === b[i]);\n\nexport type FocusOnInitPosition = 'first' | 'last';\nexport interface RovingPropTypes {\n\t/** CSS selector of the element that starts as the tab stop, for example a checked custom radio. Falls back to `[data-roving-active]`, then to the first `[data-roving]` element. */\n\tactiveSelector?: string;\n\t/**\n\t * If true, disabled elements (with disabled attribute or aria-disabled=\"true\")\n\t * will be included in the roving tabindex. Defaults to true (disabled elements are included).\n\t */\n\tallowDisabled?: boolean;\n\tchildren: React.ReactNode;\n\t/**\n\t * delayMount is used to apply a delay to the mounting\n\t * of the RovingTabindex component. This can be helpful in\n\t * the event that a component's children have not been fully\n\t * rendered by the time the componentDidMount function is triggered\n\t */\n\tdelayMount?: number;\n\t/** Moves focus to the first or last element when the component mounts (after `delayMount`, if set). */\n\tfocusOnInit?: FocusOnInitPosition;\n\t/** Keeps every element out of the tab order until `isFocused` becomes true. For groups reached through a keyboard shortcut instead of Tab. */\n\tfocusWithShortcut?: boolean;\n\t/** Has no effect. Kept for backwards compatibility. */\n\tforceUpdate?: boolean;\n\t/** Set when another roving tabindex is nested inside this one, so its elements are left to the inner instance. */\n\thasChildRoving?: boolean;\n\t/** CSS selector. Keyboard navigation is ignored while focus is inside a matching element, for example a text input. */\n\tignoreElements?: string;\n\t/** With `focusWithShortcut`, whether the group holds focus. Turning it on focuses the active element; turning it off removes the group from the tab order. */\n\tisFocused?: boolean;\n\t/** Called when focus moves from the group to another element outside it. With `focusWithShortcut`, also called when `isFocused` turns off while focus is outside the group. */\n\tonBlur?: () => void;\n\t/** Pass it after moving focus into the group programmatically. On the next update the focused element becomes the tab stop and the callback receives `false`, so the consumer can drop it. */\n\tonRefocus?: (shouldRefocus: boolean) => void;\n\t/** Axis of the group, read once at mount. Every arrow key moves focus, but the keys across the axis are left to a focused element with `aria-haspopup=\"true\"` or role combobox, listbox or option. Defaults to horizontal. */\n\torientation?: RovingOrientation;\n\tqa?: string;\n}\n\ntype RovingOrientation = 'horizontal' | 'vertical';\ntype NavigationDirection = 'forward' | 'back';\n\n/**\n * Default value for allowDisabled prop.\n * When true, disabled elements are included in the roving tabindex navigation.\n */\nconst DEFAULT_ALLOW_DISABLED = true;\n\n/**\n * CSS selector to exclude disabled elements.\n * Excludes both native disabled attribute and ARIA-compliant disabled elements.\n */\nconst DISABLED_EXCLUSION = ':not([disabled]):not([aria-disabled=\"true\"])';\n\n/**\n * CSS selector suffix to exclude nested roving tabindex elements.\n * Prevents deeply nested elements from being included in parent roving tabindex.\n */\nconst NESTED_ROVING_EXCLUSION =\n\t':not(.helpers-roving-tabindex-container .helpers-roving-tabindex-container [data-roving])';\n\n/**\n * Builds the appropriate CSS selector based on configuration.\n * @param allowDisabled - Whether to include disabled elements in the roving tabindex\n * @param hasChildRoving - Whether nested roving tabindex containers should be excluded\n * @returns CSS selector string for querying roving elements\n */\nconst buildSelector = (allowDisabled: boolean, hasChildRoving: boolean): string => {\n\tconst disabledPart = allowDisabled ? '' : DISABLED_EXCLUSION;\n\tconst nestedPart = hasChildRoving ? NESTED_ROVING_EXCLUSION : '';\n\treturn `[data-roving]${disabledPart}${nestedPart}`;\n};\n\n/**\n * Component to create a Roving Tabindex in the DOM\n * @returns {HTMLDivElement}\n */\nclass MrlRovingTabindex extends React.Component<RovingPropTypes> {\n\telements: Array<Element | null>;\n\torientation: RovingOrientation;\n\tref!: HTMLDivElement | null;\n\tselector: string;\n\n\t/**\n\t * MrlRovingTabindex class constructor\n\t * @param props - the MrlRovingTabindex props\n\t * @returns new instance\n\t */\n\tconstructor(props: RovingPropTypes) {\n\t\tsuper(props);\n\n\t\tconst { allowDisabled = DEFAULT_ALLOW_DISABLED, hasChildRoving = false, orientation } = props;\n\n\t\tthis.elements = [];\n\t\tthis.orientation = orientation || 'horizontal';\n\t\tthis.selector = buildSelector(allowDisabled, hasChildRoving);\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component mounts\n\t */\n\tcomponentDidMount(): void {\n\t\tconst { delayMount } = this.props;\n\t\tif (delayMount) {\n\t\t\tsetTimeout(() => this.mount(), delayMount);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.mount();\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component unmounts\n\t */\n\tcomponentWillUnmount(): void {\n\t\t// Remove focus event listener\n\t\tif (this.ref) {\n\t\t\tthis.ref.removeEventListener('focusout', this.handleFocusOut);\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component updates\n\t * @param {RovingPropTypes} prevProps - the props before the component updated\n\t */\n\tcomponentDidUpdate(prevProps: RovingPropTypes): void {\n\t\tconst {\n\t\t\tallowDisabled = DEFAULT_ALLOW_DISABLED,\n\t\t\tchildren,\n\t\t\tfocusWithShortcut,\n\t\t\thasChildRoving = false,\n\t\t\tisFocused,\n\t\t\tonBlur,\n\t\t\tonRefocus\n\t\t} = this.props;\n\n\t\t/**\n\t\t * If allowDisabled or hasChildRoving prop changes, rebuild the selector\n\t\t * and re-scan for elements to reflect the new configuration.\n\t\t */\n\t\tif (prevProps.allowDisabled !== allowDisabled || prevProps.hasChildRoving !== hasChildRoving) {\n\t\t\tthis.selector = buildSelector(allowDisabled, hasChildRoving);\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\t/**\n\t\t * If focus is programatically moved to the MrlRovingTabindex\n\t\t * component from outside of the MrlRovingTabindex, passing\n\t\t * the prop of `onRefocus` will cause the component to go\n\t\t * through and make sure that only the active element\n\t\t * has a tabindex set to 0.\n\t\t */\n\t\tif (onRefocus) {\n\t\t\tthis.handleRefocus();\n\t\t}\n\n\t\t/**\n\t\t * When children change, re-scan for elements and update tabindex values.\n\t\t * This ensures that dynamically added/removed buttons are properly managed.\n\t\t */\n\t\tif (prevProps.children !== children && !focusWithShortcut) {\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\tif (focusWithShortcut) {\n\t\t\t/**\n\t\t\t * If the component within MrlRovingTabindex shows on the page before it should\n\t\t\t * be reached with a keyboard the prop `focusWithiShortcut` can be used to\n\t\t\t * achieve that. The conditions below handle the various states that a\n\t\t\t * component can experience under this scenario.\n\t\t\t */\n\t\t\tif (!isFocused && !prevProps.isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was not focus before and is not ready to be focused on\n\t\t\t\t */\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t}\n\n\t\t\tif (prevProps.isFocused && !isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was focused but is not focused anymore\n\t\t\t\t */\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t\t// Only call onBlur if focus has truly left the container\n\t\t\t\tif (this.ref && !this.ref.contains(document.activeElement)) {\n\t\t\t\t\tonBlur?.();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!prevProps.isFocused && isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was not focused before and is ready to be focused\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.setElementFocus(this.getActiveElement());\n\t\t\t}\n\n\t\t\tif (prevProps.children !== children && !isFocused && !prevProps.isFocused) {\n\t\t\t\t/**\n\t\t\t\t * Children changed but component is not focused\n\t\t\t\t * Ensure all new elements have tabindex=-1 to prevent Tab key access\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tprevProps.children !== children &&\n\t\t\t\tprevProps.isFocused &&\n\t\t\t\tisFocused &&\n\t\t\t\t!this.ref?.contains(document.activeElement)\n\t\t\t) {\n\t\t\t\t/**\n\t\t\t\t * While the component was focused an action was performed that\n\t\t\t\t * changed the elements of the component and focus was moved to\n\t\t\t\t * a different element on the page\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.setActiveElement(this.getActiveElement());\n\n\t\t\t\tif (this.getActiveElement()) {\n\t\t\t\t\t/**\n\t\t\t\t\t * The active element is still within the roving tabindex so focus\n\t\t\t\t\t * on the element that should receive focus\n\t\t\t\t\t */\n\t\t\t\t\tthis.setElementFocus(this.getActiveElement());\n\t\t\t\t} else {\n\t\t\t\t\t/**\n\t\t\t\t\t * The active element has been moved outside of the MrlRovingTabindex\n\t\t\t\t\t * component so reset the component\n\t\t\t\t\t */\n\t\t\t\t\t// Only call onBlur if focus has truly left the container\n\t\t\t\t\tif (this.ref && !this.ref.contains(document.activeElement)) {\n\t\t\t\t\t\tonBlur?.();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\thandleRef = (ref: HTMLDivElement): HTMLDivElement => {\n\t\tthis.ref = ref;\n\t\t// Set up focus listener when ref becomes available\n\t\tif (ref) {\n\t\t\tref.addEventListener('focusout', this.handleFocusOut);\n\t\t}\n\t\treturn ref;\n\t};\n\n\t/**\n\t * Handles focus out events to detect when focus leaves the roving tabindex container\n\t * @param {FocusEvent} event - the focus out event\n\t * @returns {void}\n\t */\n\thandleFocusOut = (event: FocusEvent): void => {\n\t\tconst { onBlur } = this.props;\n\t\tconst relatedTarget = (event as FocusEvent & { relatedTarget?: HTMLElement }).relatedTarget;\n\n\t\t// Check if focus is moving to an element outside the container\n\t\tif (relatedTarget && !this.ref?.contains(relatedTarget)) {\n\t\t\t// Focus has moved from inside the container to outside\n\t\t\tonBlur?.();\n\t\t}\n\t};\n\n\t/**\n\t * Sets component array of elements\n\t * @returns {void}\n\t */\n\tsetElements = (): void => {\n\t\tif (!this.ref) return;\n\t\tthis.elements = getTabbableElements(this.ref, this.selector);\n\t};\n\n\t/**\n\t * Queries for a single element matching the selector within the container.\n\t * @param selector - CSS selector to query\n\t * @returns The matching element or null\n\t */\n\tqueryElement = (selector: string): HTMLElement | null => {\n\t\treturn this.ref?.querySelector(selector) as HTMLElement | null;\n\t};\n\n\t/**\n\t * Gets the active element based on priority order:\n\t * 1. Element matching the custom `activeSelector` prop (e.g., custom radio elements)\n\t * 2. Element with `data-roving-active` attribute (programmatically set active)\n\t * 3. First element with `data-roving` attribute (default fallback)\n\t *\n\t * Disabled elements are excluded unless `allowDisabled` is true.\n\t * @returns The active HTML element, or undefined if none found\n\t */\n\tgetActiveElement = (): HTMLElement | undefined => {\n\t\tconst { activeSelector, allowDisabled = DEFAULT_ALLOW_DISABLED } = this.props;\n\t\tconst disabledFilter = allowDisabled ? '' : DISABLED_EXCLUSION;\n\n\t\t// Priority 1: Custom active selector (e.g., for radio button groups)\n\t\t// An element with the matching activeSelector prop (example usage: custom radio elements)\n\t\tif (activeSelector) {\n\t\t\tconst customActiveElement = this.queryElement(\n\t\t\t\t`${activeSelector}[data-roving]${disabledFilter}`\n\t\t\t);\n\t\t\tif (customActiveElement) return customActiveElement;\n\t\t}\n\n\t\t// Priority 2: Programmatically marked active element\n\t\t// An element with a `data-roving-active` attribute, indicating the current active element\n\t\tconst markedActiveElement = this.queryElement(\n\t\t\t`[data-roving][data-roving-active]${disabledFilter}`\n\t\t);\n\t\tif (markedActiveElement) return markedActiveElement;\n\n\t\t// Priority 3: First roving element (uses pre-built selector with disabled handling)\n\t\t// If no active element is found, the first instance of an element with `data-roving=\"true\"`\n\t\tconst firstRovingElement = this.ref?.querySelectorAll(this.selector)[0];\n\t\treturn firstRovingElement as HTMLElement | undefined;\n\t};\n\n\t/**\n\t * Sets an element to `tabindex=0` and sets all other elements to `tabindex=-1`\n\t * @param {HTMLElement | undefined} el - the element to set as active\n\t * @returns {void}\n\t */\n\tsetActiveElement = (el: HTMLElement | undefined): void => {\n\t\tif (!el) return;\n\n\t\tthis.unsetTabbableElements();\n\t\tel.setAttribute('tabindex', '0');\n\t};\n\n\t/**\n\t * Sets focus to a specific element\n\t * @param {HTMLElement | undefined} el - the element to set in focus\n\t * @returns {void}\n\t */\n\tsetElementFocus = (el: HTMLElement | undefined): void => {\n\t\tif (!el) return;\n\n\t\t/**\n\t\t * Why data-roving-active?\n\t\t *\n\t\t * We only want to set data-roving-active when 'setElementFocus' is triggered because we don't want [tabindex=0] to be mutally exclusive with\n\t\t * [data-roving-active]. An item with [data-roving-active] can exist without having [tabindex=0] and vice versa. We only want to set [data-roving-active]\n\t\t * intentionally when a user action has occured to change it. Such as a keyboard event or moving focus manually with Javascript.\n\t\t */\n\t\tconst current = this.getActiveElement();\n\t\tif (current) current.removeAttribute('data-roving-active');\n\t\tel.setAttribute('data-roving-active', 'true');\n\n\t\tthis.setActiveElement(el);\n\t\tel.focus();\n\t};\n\n\t/**\n\t * Sets focus to an element based on a direction (`forward` or `back`)\n\t * Disabled elements are already excluded from this.elements via CSS selector\n\t * @param {NavigationDirection} direction 'forward' | 'back'\n\t * @returns {void}\n\t */\n\tsetFocusByDirection = (direction: NavigationDirection): void => {\n\t\tconst itemsLen = this.elements.length;\n\n\t\tif (itemsLen > 0) {\n\t\t\tconst currentIndex = this.elements.indexOf(document.activeElement);\n\n\t\t\tconst directionSum = direction === 'back' ? -1 : 1;\n\t\t\tlet nextIndex = currentIndex + directionSum;\n\n\t\t\tif (direction === 'back') {\n\t\t\t\tnextIndex = nextIndex < 0 ? itemsLen - 1 : nextIndex;\n\t\t\t}\n\n\t\t\tif (direction === 'forward') {\n\t\t\t\tnextIndex = nextIndex >= itemsLen ? 0 : nextIndex;\n\t\t\t}\n\n\t\t\tthis.setElementFocus(this.elements[nextIndex] as HTMLElement);\n\t\t}\n\t};\n\n\t/**\n\t * Sets all tabindex for elements of this component to -1\n\t * Also ensures disabled elements (excluded from roving tabindex) have tabindex=-1\n\t * @returns {void}\n\t */\n\tunsetTabbableElements = (): void => {\n\t\tif (!this.elements) return;\n\n\t\t// Set tabindex=-1 for all roving tabindex elements\n\t\tthis.elements.forEach((el: Element | null) => {\n\t\t\tel && el.setAttribute('tabindex', '-1');\n\t\t});\n\n\t\t// Also set tabindex=-1 for disabled elements that are excluded from roving tabindex\n\t\t// This ensures disabled elements are not tabbable even though they're not in the navigation order\n\t\tif (!this.ref || this.props.allowDisabled) return;\n\n\t\tconst disabledElements = this.ref.querySelectorAll(\n\t\t\t`[data-roving][disabled], [data-roving][aria-disabled=\"true\"]`\n\t\t);\n\t\tdisabledElements.forEach((el) => {\n\t\t\tel.setAttribute('tabindex', '-1');\n\t\t});\n\t};\n\n\t/**\n\t * Will return `false` if the orientation param matches the\n\t * orientation of the component and the actively focused element has a menu or select\n\t * @param orientation : 'horizontal' | 'vertical'\n\t * @returns boolean\n\t */\n\tcanUseArrows = (orientation: RovingOrientation): boolean => {\n\t\tconst { activeElement } = document;\n\t\tconst role = activeElement?.getAttribute('role');\n\t\tconst hasMenuOrSelect =\n\t\t\tactiveElement?.getAttribute('aria-haspopup') === 'true' ||\n\t\t\trole === 'combobox' ||\n\t\t\trole === 'option' ||\n\t\t\trole === 'listbox';\n\n\t\treturn !(this.orientation === orientation && hasMenuOrSelect);\n\t};\n\n\thandleKeyUp = (e: React.KeyboardEvent): void => {\n\t\tconst { ignoreElements } = this.props;\n\t\tconst allowKeyPress = !ignoreElements ? true : !document.activeElement?.closest(ignoreElements);\n\n\t\tconst modifierPressed = e.ctrlKey || e.metaKey || e.shiftKey;\n\n\t\tif (modifierPressed) return;\n\n\t\t/**\n\t\t * If elements within MrlRovingTabindex are added after the component mounts\n\t\t * they will not automatically be a `part of this.elements`. This checks if\n\t\t * `this.elements` contains all elements that MrlRovingTabindex should be aware\n\t\t * of and will update `this.elements` if neccessary.\n\t\t */\n\t\tconst knownTabbableElements = this.elements;\n\t\tconst allTabbableElements = getTabbableElements(this.ref, this.selector);\n\n\t\tif (\n\t\t\tknownTabbableElements.length !== allTabbableElements.length ||\n\t\t\t!arraysEqual(knownTabbableElements, allTabbableElements)\n\t\t) {\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\tconst isActiveRoving = this.getActiveElement() === document.activeElement;\n\n\t\tif (allowKeyPress && isActiveRoving) {\n\t\t\te.stopPropagation();\n\t\t\tswitch (e.key) {\n\t\t\t\tcase 'ArrowDown':\n\t\t\t\t\tif (this.canUseArrows('horizontal')) this.setFocusByDirection('forward');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowUp':\n\t\t\t\t\tif (this.canUseArrows('horizontal')) this.setFocusByDirection('back');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowRight':\n\t\t\t\t\tif (this.canUseArrows('vertical')) this.setFocusByDirection('forward');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowLeft':\n\t\t\t\t\tif (this.canUseArrows('vertical')) this.setFocusByDirection('back');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'End':\n\t\t\t\t\tthis.handleFocusedLast();\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'Home':\n\t\t\t\t\tthis.handleFocusedFirst();\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t};\n\n\thandleFocusedFirst = (): void => this.setElementFocus(this.elements[0] as HTMLElement);\n\n\thandleFocusedLast = (): void =>\n\t\tthis.setElementFocus(this.elements[this.elements.length - 1] as HTMLElement);\n\n\thandleRefocus = (): void => {\n\t\tthis.setActiveElement(document.activeElement as HTMLElement);\n\t\tthis.props.onRefocus?.(false);\n\t};\n\n\t/**\n\t * Mounts the MrlRovingTabindex component\n\t * @returns {void}\n\t */\n\tmount(): void {\n\t\tconst { focusOnInit, focusWithShortcut, isFocused } = this.props;\n\n\t\tif (!focusWithShortcut) {\n\t\t\t// get initial set of elements for the component\n\t\t\tthis.setElements();\n\n\t\t\t// sets the first element of the component to tabindex=0 but does not move focus\n\t\t\t// this allows users to tab to the component naturally based on tab order\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t} else {\n\t\t\t// When focusWithShortcut is true, we need to set up elements\n\t\t\t// but only set tabindex values based on isFocused state\n\t\t\tthis.setElements();\n\n\t\t\tif (!isFocused) {\n\t\t\t\t// If not focused initially, set all elements to tabindex=-1\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t} else {\n\t\t\t\t// If focused initially, set the active element properly\n\t\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t\t}\n\t\t}\n\n\t\tif (focusOnInit && this.elements.length > 0) {\n\t\t\tif (focusOnInit === 'first') {\n\t\t\t\tthis.handleFocusedFirst();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.handleFocusedLast();\n\t\t}\n\t}\n\n\t/**\n\t * Renders the MrlRovingTabindex component\n\t * @returns {HTMLDivElement} - the rendered MrlRovingTabindex component\n\t */\n\trender(): JSX.Element {\n\t\t/* eslint-disable @typescript-eslint/no-unused-vars */\n\t\t// Destructure component-specific props to prevent them from being spread to the DOM\n\t\tconst {\n\t\t\tactiveSelector,\n\t\t\tallowDisabled,\n\t\t\tchildren,\n\t\t\tdelayMount,\n\t\t\tfocusOnInit,\n\t\t\tfocusWithShortcut,\n\t\t\tforceUpdate,\n\t\t\thasChildRoving,\n\t\t\tignoreElements,\n\t\t\tisFocused,\n\t\t\tonBlur,\n\t\t\tonRefocus,\n\t\t\torientation,\n\t\t\tqa,\n\t\t\t...rest\n\t\t} = this.props;\n\t\t/* eslint-enable @typescript-eslint/no-unused-vars */\n\n\t\tconst dataQa = `${qa || 'generic'}-roving`;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tclassName=\"helpers-roving-tabindex-container\"\n\t\t\t\tdata-qa={dataQa}\n\t\t\t\tonKeyUp={this.handleKeyUp}\n\t\t\t\tref={this.handleRef}\n\t\t\t\trole=\"presentation\"\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n\t\t\t\ttabIndex={-1}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nexport { MrlRovingTabindex };\n"],"names":["getTabbableElements","ref","selector","elements","querySelectorAll","Array","prototype","slice","call","arraysEqual","a","b","length","every","el","i","DEFAULT_ALLOW_DISABLED","DISABLED_EXCLUSION","NESTED_ROVING_EXCLUSION","buildSelector","allowDisabled","hasChildRoving","disabledPart","nestedPart","concat","MrlRovingTabindex","React","Component","constructor","props","_defineProperty","addEventListener","handleFocusOut","event","_this$ref","onBlur","relatedTarget","contains","_this$ref2","querySelector","_this$ref3","_this$props","activeSelector","_this$props$allowDisa","disabledFilter","customActiveElement","queryElement","markedActiveElement","firstRovingElement","unsetTabbableElements","setAttribute","current","getActiveElement","removeAttribute","setActiveElement","focus","direction","itemsLen","currentIndex","indexOf","document","activeElement","directionSum","nextIndex","setElementFocus","forEach","disabledElements","orientation","_document","role","getAttribute","hasMenuOrSelect","e","_document$activeEleme","ignoreElements","allowKeyPress","closest","modifierPressed","ctrlKey","metaKey","shiftKey","knownTabbableElements","allTabbableElements","setElements","isActiveRoving","stopPropagation","key","canUseArrows","setFocusByDirection","handleFocusedLast","handleFocusedFirst","_this$props$onRefocus","_this$props2","onRefocus","_props$allowDisabled","_props$hasChildRoving","componentDidMount","delayMount","setTimeout","mount","componentWillUnmount","removeEventListener","componentDidUpdate","prevProps","_this$props3","_this$props3$allowDis","children","focusWithShortcut","_this$props3$hasChild","isFocused","handleRefocus","_this$ref4","_this$props4","focusOnInit","render","_this$props5","forceUpdate","qa","rest","_objectWithoutProperties","_excluded","dataQa","createElement","_extends","className","onKeyUp","handleKeyUp","handleRef","tabIndex"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;IACaA,mBAAmB,GAAGA,CAACC,GAAY,EAAEC,QAAgB,KAAoB;EACrF,IAAMC,QAAQ,GAAGF,GAAG,KAAA,IAAA,IAAHA,GAAG,KAAA,MAAA,GAAA,MAAA,GAAHA,GAAG,CAAEG,gBAAgB,CAACF,QAAQ,CAAC;AAChD,EAAA,IAAI,CAACC,QAAQ,EAAE,OAAO,EAAE;EACxB,OAAOE,KAAK,CAACC,SAAS,CAACC,KAAK,CAACC,IAAI,CAACL,QAAQ,CAAC;AAC5C;AAEA,IAAMM,WAAW,GAAGA,CAACC,CAAqB,EAAEC,CAAqB,KAChED,CAAC,CAACE,MAAM,KAAKD,CAAC,CAACC,MAAM,IAAIF,CAAC,CAACG,KAAK,CAAC,CAACC,EAAE,EAAEC,CAAC,KAAKD,EAAE,KAAKH,CAAC,CAACI,CAAC,CAAC,CAAC;AA2CzD;AACA;AACA;AACA;AACA,IAAMC,sBAAsB,GAAG,IAAI;;AAEnC;AACA;AACA;AACA;AACA,IAAMC,kBAAkB,GAAG,8CAA8C;;AAEzE;AACA;AACA;AACA;AACA,IAAMC,uBAAuB,GAC5B,2FAA2F;;AAE5F;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,aAAa,GAAGA,CAACC,aAAsB,EAAEC,cAAuB,KAAa;AAClF,EAAA,IAAMC,YAAY,GAAGF,aAAa,GAAG,EAAE,GAAGH,kBAAkB;AAC5D,EAAA,IAAMM,UAAU,GAAGF,cAAc,GAAGH,uBAAuB,GAAG,EAAE;AAChE,EAAA,OAAA,eAAA,CAAAM,MAAA,CAAuBF,YAAY,CAAA,CAAAE,MAAA,CAAGD,UAAU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A,CAAA,EAEZtB,QACG,CAAC;AAER,EAAA;AACD;;;;;"}
|
|
1
|
+
{"version":3,"file":"MrlRovingTabindex.js","sources":["../../../../../src/components/rovingTabindex/MrlRovingTabindex/MrlRovingTabindex.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype RefType = HTMLElement | HTMLDivElement | null;\n\n/**\n * Gets tabbable elements in a given bit of the DOM, excluding disabled elements\n * @param {RefType} ref - the ref of the container\n * @param {string} selector - the selector to query (should already exclude disabled elements)\n * @returns {HTMLElement[]} - an array of tabbable HTML elements\n */\nexport const getTabbableElements = (ref: RefType, selector: string): HTMLElement[] => {\n\tconst elements = ref?.querySelectorAll(selector);\n\tif (!elements) return [];\n\treturn Array.prototype.slice.call(elements);\n};\n\nconst arraysEqual = (a: (Element | null)[], b: (Element | null)[]): boolean =>\n\ta.length === b.length && a.every((el, i) => el === b[i]);\n\nexport type FocusOnInitPosition = 'first' | 'last';\nexport interface RovingPropTypes {\n\t/** CSS selector of the element that starts as the tab stop, for example a checked custom radio. Falls back to `[data-roving-active]`, then to the first `[data-roving]` element. */\n\tactiveSelector?: string;\n\t/**\n\t * If true, disabled elements (with disabled attribute or aria-disabled=\"true\")\n\t * will be included in the roving tabindex. Defaults to true (disabled elements are included).\n\t */\n\tallowDisabled?: boolean;\n\tchildren: React.ReactNode;\n\t/**\n\t * delayMount is used to apply a delay to the mounting\n\t * of the RovingTabindex component. This can be helpful in\n\t * the event that a component's children have not been fully\n\t * rendered by the time the componentDidMount function is triggered\n\t */\n\tdelayMount?: number;\n\t/** Moves focus to the first or last element when the component mounts (after `delayMount`, if set). */\n\tfocusOnInit?: FocusOnInitPosition;\n\t/** Keeps every element out of the tab order until `isFocused` becomes true. For groups reached through a keyboard shortcut instead of Tab. */\n\tfocusWithShortcut?: boolean;\n\t/** Has no effect. Kept for backwards compatibility. */\n\tforceUpdate?: boolean;\n\t/** Set when another roving tabindex is nested inside this one, so its elements are left to the inner instance. */\n\thasChildRoving?: boolean;\n\t/** CSS selector. Keyboard navigation is ignored while focus is inside a matching element, for example a text input. */\n\tignoreElements?: string;\n\t/** With `focusWithShortcut`, whether the group holds focus. Turning it on focuses the active element; turning it off removes the group from the tab order. */\n\tisFocused?: boolean;\n\t/** Called when focus moves from the group to another element outside it. With `focusWithShortcut`, also called when `isFocused` turns off while focus is outside the group. */\n\tonBlur?: () => void;\n\t/** Pass it after moving focus into the group programmatically. On the next update the focused element becomes the tab stop and the callback receives `false`, so the consumer can drop it. */\n\tonRefocus?: (shouldRefocus: boolean) => void;\n\t/** Axis of the group, read once at mount. Every arrow key moves focus, but the keys across the axis are left to a focused element with `aria-haspopup=\"true\"` or role combobox, listbox or option. Defaults to horizontal. */\n\torientation?: RovingOrientation;\n\tqa?: string;\n}\n\nexport type RovingOrientation = 'horizontal' | 'vertical';\ntype NavigationDirection = 'forward' | 'back';\n\n/**\n * Default value for allowDisabled prop.\n * When true, disabled elements are included in the roving tabindex navigation.\n */\nconst DEFAULT_ALLOW_DISABLED = true;\n\n/**\n * CSS selector to exclude disabled elements.\n * Excludes both native disabled attribute and ARIA-compliant disabled elements.\n */\nconst DISABLED_EXCLUSION = ':not([disabled]):not([aria-disabled=\"true\"])';\n\n/**\n * CSS selector suffix to exclude nested roving tabindex elements.\n * Prevents deeply nested elements from being included in parent roving tabindex.\n */\nconst NESTED_ROVING_EXCLUSION =\n\t':not(.helpers-roving-tabindex-container .helpers-roving-tabindex-container [data-roving])';\n\n/**\n * Builds the appropriate CSS selector based on configuration.\n * @param allowDisabled - Whether to include disabled elements in the roving tabindex\n * @param hasChildRoving - Whether nested roving tabindex containers should be excluded\n * @returns CSS selector string for querying roving elements\n */\nconst buildSelector = (allowDisabled: boolean, hasChildRoving: boolean): string => {\n\tconst disabledPart = allowDisabled ? '' : DISABLED_EXCLUSION;\n\tconst nestedPart = hasChildRoving ? NESTED_ROVING_EXCLUSION : '';\n\treturn `[data-roving]${disabledPart}${nestedPart}`;\n};\n\n/**\n * Component to create a Roving Tabindex in the DOM\n * @returns {HTMLDivElement}\n */\nclass MrlRovingTabindex extends React.Component<RovingPropTypes> {\n\telements: Array<Element | null>;\n\torientation: RovingOrientation;\n\tref!: HTMLDivElement | null;\n\tselector: string;\n\n\t/**\n\t * MrlRovingTabindex class constructor\n\t * @param props - the MrlRovingTabindex props\n\t * @returns new instance\n\t */\n\tconstructor(props: RovingPropTypes) {\n\t\tsuper(props);\n\n\t\tconst { allowDisabled = DEFAULT_ALLOW_DISABLED, hasChildRoving = false, orientation } = props;\n\n\t\tthis.elements = [];\n\t\tthis.orientation = orientation || 'horizontal';\n\t\tthis.selector = buildSelector(allowDisabled, hasChildRoving);\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component mounts\n\t */\n\tcomponentDidMount(): void {\n\t\tconst { delayMount } = this.props;\n\t\tif (delayMount) {\n\t\t\tsetTimeout(() => this.mount(), delayMount);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.mount();\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component unmounts\n\t */\n\tcomponentWillUnmount(): void {\n\t\t// Remove focus event listener\n\t\tif (this.ref) {\n\t\t\tthis.ref.removeEventListener('focusout', this.handleFocusOut);\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the MrlRovingTabindex component updates\n\t * @param {RovingPropTypes} prevProps - the props before the component updated\n\t */\n\tcomponentDidUpdate(prevProps: RovingPropTypes): void {\n\t\tconst {\n\t\t\tallowDisabled = DEFAULT_ALLOW_DISABLED,\n\t\t\tchildren,\n\t\t\tfocusWithShortcut,\n\t\t\thasChildRoving = false,\n\t\t\tisFocused,\n\t\t\tonBlur,\n\t\t\tonRefocus\n\t\t} = this.props;\n\n\t\t/**\n\t\t * If allowDisabled or hasChildRoving prop changes, rebuild the selector\n\t\t * and re-scan for elements to reflect the new configuration.\n\t\t */\n\t\tif (prevProps.allowDisabled !== allowDisabled || prevProps.hasChildRoving !== hasChildRoving) {\n\t\t\tthis.selector = buildSelector(allowDisabled, hasChildRoving);\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\t/**\n\t\t * If focus is programatically moved to the MrlRovingTabindex\n\t\t * component from outside of the MrlRovingTabindex, passing\n\t\t * the prop of `onRefocus` will cause the component to go\n\t\t * through and make sure that only the active element\n\t\t * has a tabindex set to 0.\n\t\t */\n\t\tif (onRefocus) {\n\t\t\tthis.handleRefocus();\n\t\t}\n\n\t\t/**\n\t\t * When children change, re-scan for elements and update tabindex values.\n\t\t * This ensures that dynamically added/removed buttons are properly managed.\n\t\t */\n\t\tif (prevProps.children !== children && !focusWithShortcut) {\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\tif (focusWithShortcut) {\n\t\t\t/**\n\t\t\t * If the component within MrlRovingTabindex shows on the page before it should\n\t\t\t * be reached with a keyboard the prop `focusWithiShortcut` can be used to\n\t\t\t * achieve that. The conditions below handle the various states that a\n\t\t\t * component can experience under this scenario.\n\t\t\t */\n\t\t\tif (!isFocused && !prevProps.isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was not focus before and is not ready to be focused on\n\t\t\t\t */\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t}\n\n\t\t\tif (prevProps.isFocused && !isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was focused but is not focused anymore\n\t\t\t\t */\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t\t// Only call onBlur if focus has truly left the container\n\t\t\t\tif (this.ref && !this.ref.contains(document.activeElement)) {\n\t\t\t\t\tonBlur?.();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!prevProps.isFocused && isFocused) {\n\t\t\t\t/**\n\t\t\t\t * The component was not focused before and is ready to be focused\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.setElementFocus(this.getActiveElement());\n\t\t\t}\n\n\t\t\tif (prevProps.children !== children && !isFocused && !prevProps.isFocused) {\n\t\t\t\t/**\n\t\t\t\t * Children changed but component is not focused\n\t\t\t\t * Ensure all new elements have tabindex=-1 to prevent Tab key access\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tprevProps.children !== children &&\n\t\t\t\tprevProps.isFocused &&\n\t\t\t\tisFocused &&\n\t\t\t\t!this.ref?.contains(document.activeElement)\n\t\t\t) {\n\t\t\t\t/**\n\t\t\t\t * While the component was focused an action was performed that\n\t\t\t\t * changed the elements of the component and focus was moved to\n\t\t\t\t * a different element on the page\n\t\t\t\t */\n\t\t\t\tthis.setElements();\n\t\t\t\tthis.setActiveElement(this.getActiveElement());\n\n\t\t\t\tif (this.getActiveElement()) {\n\t\t\t\t\t/**\n\t\t\t\t\t * The active element is still within the roving tabindex so focus\n\t\t\t\t\t * on the element that should receive focus\n\t\t\t\t\t */\n\t\t\t\t\tthis.setElementFocus(this.getActiveElement());\n\t\t\t\t} else {\n\t\t\t\t\t/**\n\t\t\t\t\t * The active element has been moved outside of the MrlRovingTabindex\n\t\t\t\t\t * component so reset the component\n\t\t\t\t\t */\n\t\t\t\t\t// Only call onBlur if focus has truly left the container\n\t\t\t\t\tif (this.ref && !this.ref.contains(document.activeElement)) {\n\t\t\t\t\t\tonBlur?.();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\thandleRef = (ref: HTMLDivElement): HTMLDivElement => {\n\t\tthis.ref = ref;\n\t\t// Set up focus listener when ref becomes available\n\t\tif (ref) {\n\t\t\tref.addEventListener('focusout', this.handleFocusOut);\n\t\t}\n\t\treturn ref;\n\t};\n\n\t/**\n\t * Handles focus out events to detect when focus leaves the roving tabindex container\n\t * @param {FocusEvent} event - the focus out event\n\t * @returns {void}\n\t */\n\thandleFocusOut = (event: FocusEvent): void => {\n\t\tconst { onBlur } = this.props;\n\t\tconst relatedTarget = (event as FocusEvent & { relatedTarget?: HTMLElement }).relatedTarget;\n\n\t\t// Check if focus is moving to an element outside the container\n\t\tif (relatedTarget && !this.ref?.contains(relatedTarget)) {\n\t\t\t// Focus has moved from inside the container to outside\n\t\t\tonBlur?.();\n\t\t}\n\t};\n\n\t/**\n\t * Sets component array of elements\n\t * @returns {void}\n\t */\n\tsetElements = (): void => {\n\t\tif (!this.ref) return;\n\t\tthis.elements = getTabbableElements(this.ref, this.selector);\n\t};\n\n\t/**\n\t * Queries for a single element matching the selector within the container.\n\t * @param selector - CSS selector to query\n\t * @returns The matching element or null\n\t */\n\tqueryElement = (selector: string): HTMLElement | null => {\n\t\treturn this.ref?.querySelector(selector) as HTMLElement | null;\n\t};\n\n\t/**\n\t * Gets the active element based on priority order:\n\t * 1. Element matching the custom `activeSelector` prop (e.g., custom radio elements)\n\t * 2. Element with `data-roving-active` attribute (programmatically set active)\n\t * 3. First element with `data-roving` attribute (default fallback)\n\t *\n\t * Disabled elements are excluded unless `allowDisabled` is true.\n\t * @returns The active HTML element, or undefined if none found\n\t */\n\tgetActiveElement = (): HTMLElement | undefined => {\n\t\tconst { activeSelector, allowDisabled = DEFAULT_ALLOW_DISABLED } = this.props;\n\t\tconst disabledFilter = allowDisabled ? '' : DISABLED_EXCLUSION;\n\n\t\t// Priority 1: Custom active selector (e.g., for radio button groups)\n\t\t// An element with the matching activeSelector prop (example usage: custom radio elements)\n\t\tif (activeSelector) {\n\t\t\tconst customActiveElement = this.queryElement(\n\t\t\t\t`${activeSelector}[data-roving]${disabledFilter}`\n\t\t\t);\n\t\t\tif (customActiveElement) return customActiveElement;\n\t\t}\n\n\t\t// Priority 2: Programmatically marked active element\n\t\t// An element with a `data-roving-active` attribute, indicating the current active element\n\t\tconst markedActiveElement = this.queryElement(\n\t\t\t`[data-roving][data-roving-active]${disabledFilter}`\n\t\t);\n\t\tif (markedActiveElement) return markedActiveElement;\n\n\t\t// Priority 3: First roving element (uses pre-built selector with disabled handling)\n\t\t// If no active element is found, the first instance of an element with `data-roving=\"true\"`\n\t\tconst firstRovingElement = this.ref?.querySelectorAll(this.selector)[0];\n\t\treturn firstRovingElement as HTMLElement | undefined;\n\t};\n\n\t/**\n\t * Sets an element to `tabindex=0` and sets all other elements to `tabindex=-1`\n\t * @param {HTMLElement | undefined} el - the element to set as active\n\t * @returns {void}\n\t */\n\tsetActiveElement = (el: HTMLElement | undefined): void => {\n\t\tif (!el) return;\n\n\t\tthis.unsetTabbableElements();\n\t\tel.setAttribute('tabindex', '0');\n\t};\n\n\t/**\n\t * Sets focus to a specific element\n\t * @param {HTMLElement | undefined} el - the element to set in focus\n\t * @returns {void}\n\t */\n\tsetElementFocus = (el: HTMLElement | undefined): void => {\n\t\tif (!el) return;\n\n\t\t/**\n\t\t * Why data-roving-active?\n\t\t *\n\t\t * We only want to set data-roving-active when 'setElementFocus' is triggered because we don't want [tabindex=0] to be mutally exclusive with\n\t\t * [data-roving-active]. An item with [data-roving-active] can exist without having [tabindex=0] and vice versa. We only want to set [data-roving-active]\n\t\t * intentionally when a user action has occured to change it. Such as a keyboard event or moving focus manually with Javascript.\n\t\t */\n\t\tconst current = this.getActiveElement();\n\t\tif (current) current.removeAttribute('data-roving-active');\n\t\tel.setAttribute('data-roving-active', 'true');\n\n\t\tthis.setActiveElement(el);\n\t\tel.focus();\n\t};\n\n\t/**\n\t * Sets focus to an element based on a direction (`forward` or `back`)\n\t * Disabled elements are already excluded from this.elements via CSS selector\n\t * @param {NavigationDirection} direction 'forward' | 'back'\n\t * @returns {void}\n\t */\n\tsetFocusByDirection = (direction: NavigationDirection): void => {\n\t\tconst itemsLen = this.elements.length;\n\n\t\tif (itemsLen > 0) {\n\t\t\tconst currentIndex = this.elements.indexOf(document.activeElement);\n\n\t\t\tconst directionSum = direction === 'back' ? -1 : 1;\n\t\t\tlet nextIndex = currentIndex + directionSum;\n\n\t\t\tif (direction === 'back') {\n\t\t\t\tnextIndex = nextIndex < 0 ? itemsLen - 1 : nextIndex;\n\t\t\t}\n\n\t\t\tif (direction === 'forward') {\n\t\t\t\tnextIndex = nextIndex >= itemsLen ? 0 : nextIndex;\n\t\t\t}\n\n\t\t\tthis.setElementFocus(this.elements[nextIndex] as HTMLElement);\n\t\t}\n\t};\n\n\t/**\n\t * Sets all tabindex for elements of this component to -1\n\t * Also ensures disabled elements (excluded from roving tabindex) have tabindex=-1\n\t * @returns {void}\n\t */\n\tunsetTabbableElements = (): void => {\n\t\tif (!this.elements) return;\n\n\t\t// Set tabindex=-1 for all roving tabindex elements\n\t\tthis.elements.forEach((el: Element | null) => {\n\t\t\tel && el.setAttribute('tabindex', '-1');\n\t\t});\n\n\t\t// Also set tabindex=-1 for disabled elements that are excluded from roving tabindex\n\t\t// This ensures disabled elements are not tabbable even though they're not in the navigation order\n\t\tif (!this.ref || this.props.allowDisabled) return;\n\n\t\tconst disabledElements = this.ref.querySelectorAll(\n\t\t\t`[data-roving][disabled], [data-roving][aria-disabled=\"true\"]`\n\t\t);\n\t\tdisabledElements.forEach((el) => {\n\t\t\tel.setAttribute('tabindex', '-1');\n\t\t});\n\t};\n\n\t/**\n\t * Will return `false` if the orientation param matches the\n\t * orientation of the component and the actively focused element has a menu or select\n\t * @param orientation : 'horizontal' | 'vertical'\n\t * @returns boolean\n\t */\n\tcanUseArrows = (orientation: RovingOrientation): boolean => {\n\t\tconst { activeElement } = document;\n\t\tconst role = activeElement?.getAttribute('role');\n\t\tconst hasMenuOrSelect =\n\t\t\tactiveElement?.getAttribute('aria-haspopup') === 'true' ||\n\t\t\trole === 'combobox' ||\n\t\t\trole === 'option' ||\n\t\t\trole === 'listbox';\n\n\t\treturn !(this.orientation === orientation && hasMenuOrSelect);\n\t};\n\n\thandleKeyUp = (e: React.KeyboardEvent): void => {\n\t\tconst { ignoreElements } = this.props;\n\t\tconst allowKeyPress = !ignoreElements ? true : !document.activeElement?.closest(ignoreElements);\n\n\t\tconst modifierPressed = e.ctrlKey || e.metaKey || e.shiftKey;\n\n\t\tif (modifierPressed) return;\n\n\t\t/**\n\t\t * If elements within MrlRovingTabindex are added after the component mounts\n\t\t * they will not automatically be a `part of this.elements`. This checks if\n\t\t * `this.elements` contains all elements that MrlRovingTabindex should be aware\n\t\t * of and will update `this.elements` if neccessary.\n\t\t */\n\t\tconst knownTabbableElements = this.elements;\n\t\tconst allTabbableElements = getTabbableElements(this.ref, this.selector);\n\n\t\tif (\n\t\t\tknownTabbableElements.length !== allTabbableElements.length ||\n\t\t\t!arraysEqual(knownTabbableElements, allTabbableElements)\n\t\t) {\n\t\t\tthis.setElements();\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t}\n\n\t\tconst isActiveRoving = this.getActiveElement() === document.activeElement;\n\n\t\tif (allowKeyPress && isActiveRoving) {\n\t\t\te.stopPropagation();\n\t\t\tswitch (e.key) {\n\t\t\t\tcase 'ArrowDown':\n\t\t\t\t\tif (this.canUseArrows('horizontal')) this.setFocusByDirection('forward');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowUp':\n\t\t\t\t\tif (this.canUseArrows('horizontal')) this.setFocusByDirection('back');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowRight':\n\t\t\t\t\tif (this.canUseArrows('vertical')) this.setFocusByDirection('forward');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'ArrowLeft':\n\t\t\t\t\tif (this.canUseArrows('vertical')) this.setFocusByDirection('back');\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'End':\n\t\t\t\t\tthis.handleFocusedLast();\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'Home':\n\t\t\t\t\tthis.handleFocusedFirst();\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t};\n\n\thandleFocusedFirst = (): void => this.setElementFocus(this.elements[0] as HTMLElement);\n\n\thandleFocusedLast = (): void =>\n\t\tthis.setElementFocus(this.elements[this.elements.length - 1] as HTMLElement);\n\n\thandleRefocus = (): void => {\n\t\tthis.setActiveElement(document.activeElement as HTMLElement);\n\t\tthis.props.onRefocus?.(false);\n\t};\n\n\t/**\n\t * Mounts the MrlRovingTabindex component\n\t * @returns {void}\n\t */\n\tmount(): void {\n\t\tconst { focusOnInit, focusWithShortcut, isFocused } = this.props;\n\n\t\tif (!focusWithShortcut) {\n\t\t\t// get initial set of elements for the component\n\t\t\tthis.setElements();\n\n\t\t\t// sets the first element of the component to tabindex=0 but does not move focus\n\t\t\t// this allows users to tab to the component naturally based on tab order\n\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t} else {\n\t\t\t// When focusWithShortcut is true, we need to set up elements\n\t\t\t// but only set tabindex values based on isFocused state\n\t\t\tthis.setElements();\n\n\t\t\tif (!isFocused) {\n\t\t\t\t// If not focused initially, set all elements to tabindex=-1\n\t\t\t\tthis.unsetTabbableElements();\n\t\t\t} else {\n\t\t\t\t// If focused initially, set the active element properly\n\t\t\t\tthis.setActiveElement(this.getActiveElement());\n\t\t\t}\n\t\t}\n\n\t\tif (focusOnInit && this.elements.length > 0) {\n\t\t\tif (focusOnInit === 'first') {\n\t\t\t\tthis.handleFocusedFirst();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.handleFocusedLast();\n\t\t}\n\t}\n\n\t/**\n\t * Renders the MrlRovingTabindex component\n\t * @returns {HTMLDivElement} - the rendered MrlRovingTabindex component\n\t */\n\trender(): JSX.Element {\n\t\t/* eslint-disable @typescript-eslint/no-unused-vars */\n\t\t// Destructure component-specific props to prevent them from being spread to the DOM\n\t\tconst {\n\t\t\tactiveSelector,\n\t\t\tallowDisabled,\n\t\t\tchildren,\n\t\t\tdelayMount,\n\t\t\tfocusOnInit,\n\t\t\tfocusWithShortcut,\n\t\t\tforceUpdate,\n\t\t\thasChildRoving,\n\t\t\tignoreElements,\n\t\t\tisFocused,\n\t\t\tonBlur,\n\t\t\tonRefocus,\n\t\t\torientation,\n\t\t\tqa,\n\t\t\t...rest\n\t\t} = this.props;\n\t\t/* eslint-enable @typescript-eslint/no-unused-vars */\n\n\t\tconst dataQa = `${qa || 'generic'}-roving`;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tclassName=\"helpers-roving-tabindex-container\"\n\t\t\t\tdata-qa={dataQa}\n\t\t\t\tonKeyUp={this.handleKeyUp}\n\t\t\t\tref={this.handleRef}\n\t\t\t\trole=\"presentation\"\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n\t\t\t\ttabIndex={-1}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nexport { MrlRovingTabindex };\n"],"names":["getTabbableElements","ref","selector","elements","querySelectorAll","Array","prototype","slice","call","arraysEqual","a","b","length","every","el","i","DEFAULT_ALLOW_DISABLED","DISABLED_EXCLUSION","NESTED_ROVING_EXCLUSION","buildSelector","allowDisabled","hasChildRoving","disabledPart","nestedPart","concat","MrlRovingTabindex","React","Component","constructor","props","_defineProperty","addEventListener","handleFocusOut","event","_this$ref","onBlur","relatedTarget","contains","_this$ref2","querySelector","_this$ref3","_this$props","activeSelector","_this$props$allowDisa","disabledFilter","customActiveElement","queryElement","markedActiveElement","firstRovingElement","unsetTabbableElements","setAttribute","current","getActiveElement","removeAttribute","setActiveElement","focus","direction","itemsLen","currentIndex","indexOf","document","activeElement","directionSum","nextIndex","setElementFocus","forEach","disabledElements","orientation","_document","role","getAttribute","hasMenuOrSelect","e","_document$activeEleme","ignoreElements","allowKeyPress","closest","modifierPressed","ctrlKey","metaKey","shiftKey","knownTabbableElements","allTabbableElements","setElements","isActiveRoving","stopPropagation","key","canUseArrows","setFocusByDirection","handleFocusedLast","handleFocusedFirst","_this$props$onRefocus","_this$props2","onRefocus","_props$allowDisabled","_props$hasChildRoving","componentDidMount","delayMount","setTimeout","mount","componentWillUnmount","removeEventListener","componentDidUpdate","prevProps","_this$props3","_this$props3$allowDis","children","focusWithShortcut","_this$props3$hasChild","isFocused","handleRefocus","_this$ref4","_this$props4","focusOnInit","render","_this$props5","forceUpdate","qa","rest","_objectWithoutProperties","_excluded","dataQa","createElement","_extends","className","onKeyUp","handleKeyUp","handleRef","t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","sources":["../../src/version.ts"],"sourcesContent":["export const TOOLKIT_VERSION = \"4.84.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["export const TOOLKIT_VERSION = \"4.84.1\";"],"names":["TOOLKIT_VERSION"],"mappings":";;AAAO,IAAMA,eAAe,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MrlAvatar.js","sources":["../../../../../src/components/avatar/MrlAvatar/MrlAvatar.tsx"],"sourcesContent":["import { lock, facilitatorBadge } from '@muraldevkit/ds-icons';\nimport {\n\thexToRgb,\n\tisValidHexColor,\n\tisValidRgbString,\n\tisValidRgbaString,\n\tstickyTextColor\n} from '@tactivos/mural-shared/lib/colors';\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport { MrlSvg } from '../../svg/MrlSvg/MrlSvg';\n\nimport styles from './MrlAvatar.module.scss';\n\ntype AvatarKind = (typeof avatarValues.kind)[number];\ntype AvatarSize = (typeof avatarValues.size)[number];\n\ninterface avatarDefaults {\n\tkind: AvatarKind;\n\tsize: AvatarSize;\n\tavatarColor: string;\n}\n\nexport interface MrlAvatarPropTypes {\n\t/** Alt text when `image` is a URL. Defaults to \"<name>'s avatar\", or \"Participant avatar\" without a name. */\n\talt?: string;\n\tdataQa?: string;\n\t/** Image shown instead of the initials: a URL rendered as an `img`, or a custom element. */\n\timage?: React.ReactNode | string;\n\t/** Badge shown on the corner of small and xsmall avatars: a facilitator badge or a lock icon. Also draws the border in `avatarColor`. */\n\tkind?: AvatarKind;\n\t/** Name of the person. Used for the initials when there is no image, and set as `aria-label` on the avatar content. */\n\tname?: string;\n\t/** Called when the `image` URL fails to load. */\n\tonImageError?: React.ReactEventHandler<HTMLImageElement>;\n\t/** Draws a border in `avatarColor` around the avatar. */\n\tshowBorder?: boolean;\n\t/** Size of the avatar. xsmall shows one initial, the other sizes up to two. */\n\tsize?: AvatarSize;\n\t/** Color of the person as hex, rgb or rgba, used to tint the avatar. */\n\tavatarColor?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst avatarValues = {\n\tkind: ['default', 'facilitator', 'lock'] as const,\n\tsize: ['xsmall', 'small', 'medium', 'large'] as const\n};\n\nexport const defaultAvatarValues: avatarDefaults = {\n\tavatarColor: '#2f2f2f',\n\tkind: 'default',\n\tsize: 'medium'\n};\n\n/**\n * Renders an avatar component\n * @param {MrlAvatarPropTypes} props the props for your MrlAvatar\n * @returns {React.ReactElement} an avatar containing the props you pass\n */\nexport const MrlAvatar = ({\n\talt,\n\tavatarColor = defaultAvatarValues.avatarColor,\n\tdataQa,\n\tkind = defaultAvatarValues.kind,\n\timage,\n\tname,\n\tonImageError,\n\tshowBorder = false,\n\tsize = defaultAvatarValues.size,\n\t...rest\n}: MrlAvatarPropTypes): React.ReactElement => {\n\tconst containerClasses = classNames(styles['MrlAvatar'], 'MrlAvatar', {\n\t\t[styles[`MrlAvatar--${size}`]]: size && size !== 'medium'\n\t});\n\n\tconst isFacilitatorSize = size === 'small' || size === 'xsmall';\n\tconst showIcon = kind !== 'default' && isFacilitatorSize;\n\tconst iconContainerClasses = classNames(styles['MrlAvatar-icon-container'], {\n\t\t[styles[`MrlAvatar-icon-container--${size}`]]: size && size !== 'medium'\n\t});\n\n\tconst getAvatarRgb = () => {\n\t\tif (isValidHexColor(avatarColor)) {\n\t\t\treturn hexToRgb(avatarColor).toString();\n\t\t}\n\n\t\tif (isValidRgbString(avatarColor)) {\n\t\t\treturn avatarColor.substring(4, avatarColor.length - 1);\n\t\t}\n\n\t\tif (isValidRgbaString(avatarColor)) {\n\t\t\tconst lastComma = avatarColor.lastIndexOf(',');\n\n\t\t\treturn avatarColor.substring(5, lastComma);\n\t\t}\n\t};\n\n\tconst renderImage = () => {\n\t\tif (typeof image === 'string') {\n\t\t\tconst imgAltText = alt ? alt : name ? `${name}'s avatar` : 'Participant avatar';\n\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\talt={imgAltText}\n\t\t\t\t\tclassName={styles['MrlAvatar-image']}\n\t\t\t\t\tdata-qa={`${dataQa || 'avatar'}-image`}\n\t\t\t\t\tonError={onImageError}\n\t\t\t\t\tsrc={image}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn image;\n\t};\n\n\tconst getInitials = (str: string | undefined): string => {\n\t\tif (!str) {\n\t\t\treturn '';\n\t\t}\n\n\t\tconst textLength = size === 'xsmall' ? 1 : 2;\n\n\t\t// Take the name passed in.\n\t\treturn (\n\t\t\tstr\n\t\t\t\t// Split it at each space to create an array of words\n\t\t\t\t.split(' ')\n\t\t\t\t// Take the first character from each word.\n\t\t\t\t.map((item: string) => item.charAt(0).toUpperCase())\n\t\t\t\t// Bring the characters back into one word\n\t\t\t\t.join('')\n\t\t\t\t// Make sure we remove spaces\n\t\t\t\t.replace(/ /g, '')\n\t\t\t\t// Return the correct number of characters\n\t\t\t\t.substring(0, textLength)\n\t\t);\n\t};\n\n\tconst isDarkText = stickyTextColor(avatarColor, '#000000', '#ffffff') === '#ffffff';\n\tconst safeColor = getAvatarRgb();\n\n\tconst backgroundColor =\n\t\timage && typeof image === 'string'\n\t\t\t? 'rgba(var(--mrl-color-white), 1)'\n\t\t\t: `rgba(${safeColor}, 0.08)`;\n\tconst borderColor = showIcon || showBorder ? `rgba(${safeColor}, 1` : 'transparent';\n\tconst textColor = isDarkText ? `rgba(${safeColor}, 1` : 'rgba(--mrl-gray-90, 1)';\n\n\treturn (\n\t\t<div className={containerClasses} data-qa={dataQa} {...rest}>\n\t\t\t<span\n\t\t\t\taria-label={name}\n\t\t\t\tclassName={`${styles['MrlAvatar-content']} MrlAvatar-content`}\n\t\t\t\tdata-qa={dataQa && `avatar-${image ? 'image-container' : 'initials'}`}\n\t\t\t\tstyle={{\n\t\t\t\t\tbackgroundColor: backgroundColor,\n\t\t\t\t\tborderColor: borderColor,\n\t\t\t\t\tcolor: textColor\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{image ? renderImage() : <span aria-hidden=\"true\">{getInitials(name)}</span>}\n\t\t\t</span>\n\t\t\t{showIcon && (\n\t\t\t\t<span\n\t\t\t\t\tclassName={iconContainerClasses}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundColor: borderColor\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<MrlSvg\n\t\t\t\t\t\tclassName={styles['MrlAvatar-icon']}\n\t\t\t\t\t\tsize=\"auto\"\n\t\t\t\t\t\tsvg={kind === 'facilitator' ? facilitatorBadge : lock}\n\t\t\t\t\t/>\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"names":["defaultAvatarValues","avatarColor","kind","size","MrlAvatar","_ref","alt","_ref$avatarColor","dataQa","_ref$kind","image","name","onImageError","_ref$showBorder","showBorder","_ref$size","rest","_objectWithoutProperties","_excluded","containerClasses","classNames","styles","concat","isFacilitatorSize","showIcon","iconContainerClasses","getAvatarRgb","isValidHexColor","hexToRgb","toString","isValidRgbString","substring","length","isValidRgbaString","lastComma","lastIndexOf","renderImage","imgAltText","React","createElement","className","onError","src","getInitials","str","textLength","split","map","item","charAt","toUpperCase","join","replace","isDarkText","stickyTextColor","safeColor","backgroundColor","borderColor","textColor","_extends","style","color","MrlSvg","svg","facilitatorBadge","lock"],"mappings":";;;;;;;;;AAiDO,IAAMA,mBAAmC,GAAG;AAClDC,EAAAA,WAAW,EAAE,SAAS;AACtBC,EAAAA,IAAI,EAAE,SAAS;AACfC,EAAAA,IAAI,EAAE;AACP;;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMC,SAAS,GAAGC,IAAA,IAWqB;AAAA,EAAA,IAV7CC,GAAG,GAAAD,IAAA,CAAHC,GAAG;IAAAC,gBAAA,GAAAF,IAAA,CACHJ,WAAW;AAAXA,IAAAA,WAAW,GAAAM,gBAAA,KAAA,MAAA,GAAGP,mBAAmB,CAACC,WAAW,GAAAM,gBAAA;IAC7CC,MAAM,GAAAH,IAAA,CAANG,MAAM;IAAAC,S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ACR;GAAE,EAEDhD,KAAK,GAAG0B,WAAW,EAAE,gBAAGE,KAAA,CAAAC,aAAA,CAAA,MAAA,EAAA;IAAM,aAAA,EAAY;GAAM,EAAEI,WAAW,CAAChC,IAAI,CAAQ,CACtE,CAAC,EACNa,QAAQ,iBACRc,KAAA,CAAAC,aAAA,CAAA,MAAA,EAAA;AACCC,IAAAA,SAAS,EAAEf,oBAAqB;AAChCmC,IAAAA,KAAK,EAAE;AACNJ,MAAAA,eAAe,EAAEC;AAClB;AAAE,GAAA,eAEFnB,KAAA,CAAAC,aAAA,CAACuB,MAAM,EAAA;AACNtB,IAAAA,SAAS,EAAEnB,MAAM,CAAC,gBAAgB,CAAE;AACpClB,IAAAA,IAAI,EAAC,MAAM;AACX4D,IAAAA,GAAG,EAAE7D,IAAI,KAAK,aAAa,GAAG8D,gBAAgB,GAAGC;GACjD,CACI,CAEH,CAAC;AAER;;;;"}
|
|
1
|
+
{"version":3,"file":"MrlAvatar.js","sources":["../../../../../src/components/avatar/MrlAvatar/MrlAvatar.tsx"],"sourcesContent":["import { lock, facilitatorBadge } from '@muraldevkit/ds-icons';\nimport {\n\thexToRgb,\n\tisValidHexColor,\n\tisValidRgbString,\n\tisValidRgbaString,\n\tstickyTextColor\n} from '@tactivos/mural-shared/lib/colors';\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport { MrlSvg } from '../../svg/MrlSvg/MrlSvg';\n\nimport styles from './MrlAvatar.module.scss';\n\nexport type AvatarKind = (typeof avatarValues.kind)[number];\nexport type AvatarSize = (typeof avatarValues.size)[number];\n\ninterface avatarDefaults {\n\tkind: AvatarKind;\n\tsize: AvatarSize;\n\tavatarColor: string;\n}\n\nexport interface MrlAvatarPropTypes {\n\t/** Alt text when `image` is a URL. Defaults to \"<name>'s avatar\", or \"Participant avatar\" without a name. */\n\talt?: string;\n\tdataQa?: string;\n\t/** Image shown instead of the initials: a URL rendered as an `img`, or a custom element. */\n\timage?: React.ReactNode | string;\n\t/** Badge shown on the corner of small and xsmall avatars: a facilitator badge or a lock icon. Also draws the border in `avatarColor`. */\n\tkind?: AvatarKind;\n\t/** Name of the person. Used for the initials when there is no image, and set as `aria-label` on the avatar content. */\n\tname?: string;\n\t/** Called when the `image` URL fails to load. */\n\tonImageError?: React.ReactEventHandler<HTMLImageElement>;\n\t/** Draws a border in `avatarColor` around the avatar. */\n\tshowBorder?: boolean;\n\t/** Size of the avatar. xsmall shows one initial, the other sizes up to two. */\n\tsize?: AvatarSize;\n\t/** Color of the person as hex, rgb or rgba, used to tint the avatar. */\n\tavatarColor?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst avatarValues = {\n\tkind: ['default', 'facilitator', 'lock'] as const,\n\tsize: ['xsmall', 'small', 'medium', 'large'] as const\n};\n\nexport const defaultAvatarValues: avatarDefaults = {\n\tavatarColor: '#2f2f2f',\n\tkind: 'default',\n\tsize: 'medium'\n};\n\n/**\n * Renders an avatar component\n * @param {MrlAvatarPropTypes} props the props for your MrlAvatar\n * @returns {React.ReactElement} an avatar containing the props you pass\n */\nexport const MrlAvatar = ({\n\talt,\n\tavatarColor = defaultAvatarValues.avatarColor,\n\tdataQa,\n\tkind = defaultAvatarValues.kind,\n\timage,\n\tname,\n\tonImageError,\n\tshowBorder = false,\n\tsize = defaultAvatarValues.size,\n\t...rest\n}: MrlAvatarPropTypes): React.ReactElement => {\n\tconst containerClasses = classNames(styles['MrlAvatar'], 'MrlAvatar', {\n\t\t[styles[`MrlAvatar--${size}`]]: size && size !== 'medium'\n\t});\n\n\tconst isFacilitatorSize = size === 'small' || size === 'xsmall';\n\tconst showIcon = kind !== 'default' && isFacilitatorSize;\n\tconst iconContainerClasses = classNames(styles['MrlAvatar-icon-container'], {\n\t\t[styles[`MrlAvatar-icon-container--${size}`]]: size && size !== 'medium'\n\t});\n\n\tconst getAvatarRgb = () => {\n\t\tif (isValidHexColor(avatarColor)) {\n\t\t\treturn hexToRgb(avatarColor).toString();\n\t\t}\n\n\t\tif (isValidRgbString(avatarColor)) {\n\t\t\treturn avatarColor.substring(4, avatarColor.length - 1);\n\t\t}\n\n\t\tif (isValidRgbaString(avatarColor)) {\n\t\t\tconst lastComma = avatarColor.lastIndexOf(',');\n\n\t\t\treturn avatarColor.substring(5, lastComma);\n\t\t}\n\t};\n\n\tconst renderImage = () => {\n\t\tif (typeof image === 'string') {\n\t\t\tconst imgAltText = alt ? alt : name ? `${name}'s avatar` : 'Participant avatar';\n\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\talt={imgAltText}\n\t\t\t\t\tclassName={styles['MrlAvatar-image']}\n\t\t\t\t\tdata-qa={`${dataQa || 'avatar'}-image`}\n\t\t\t\t\tonError={onImageError}\n\t\t\t\t\tsrc={image}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn image;\n\t};\n\n\tconst getInitials = (str: string | undefined): string => {\n\t\tif (!str) {\n\t\t\treturn '';\n\t\t}\n\n\t\tconst textLength = size === 'xsmall' ? 1 : 2;\n\n\t\t// Take the name passed in.\n\t\treturn (\n\t\t\tstr\n\t\t\t\t// Split it at each space to create an array of words\n\t\t\t\t.split(' ')\n\t\t\t\t// Take the first character from each word.\n\t\t\t\t.map((item: string) => item.charAt(0).toUpperCase())\n\t\t\t\t// Bring the characters back into one word\n\t\t\t\t.join('')\n\t\t\t\t// Make sure we remove spaces\n\t\t\t\t.replace(/ /g, '')\n\t\t\t\t// Return the correct number of characters\n\t\t\t\t.substring(0, textLength)\n\t\t);\n\t};\n\n\tconst isDarkText = stickyTextColor(avatarColor, '#000000', '#ffffff') === '#ffffff';\n\tconst safeColor = getAvatarRgb();\n\n\tconst backgroundColor =\n\t\timage && typeof image === 'string'\n\t\t\t? 'rgba(var(--mrl-color-white), 1)'\n\t\t\t: `rgba(${safeColor}, 0.08)`;\n\tconst borderColor = showIcon || showBorder ? `rgba(${safeColor}, 1` : 'transparent';\n\tconst textColor = isDarkText ? `rgba(${safeColor}, 1` : 'rgba(--mrl-gray-90, 1)';\n\n\treturn (\n\t\t<div className={containerClasses} data-qa={dataQa} {...rest}>\n\t\t\t<span\n\t\t\t\taria-label={name}\n\t\t\t\tclassName={`${styles['MrlAvatar-content']} MrlAvatar-content`}\n\t\t\t\tdata-qa={dataQa && `avatar-${image ? 'image-container' : 'initials'}`}\n\t\t\t\tstyle={{\n\t\t\t\t\tbackgroundColor: backgroundColor,\n\t\t\t\t\tborderColor: borderColor,\n\t\t\t\t\tcolor: textColor\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{image ? renderImage() : <span aria-hidden=\"true\">{getInitials(name)}</span>}\n\t\t\t</span>\n\t\t\t{showIcon && (\n\t\t\t\t<span\n\t\t\t\t\tclassName={iconContainerClasses}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundColor: borderColor\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<MrlSvg\n\t\t\t\t\t\tclassName={styles['MrlAvatar-icon']}\n\t\t\t\t\t\tsize=\"auto\"\n\t\t\t\t\t\tsvg={kind === 'facilitator' ? facilitatorBadge : lock}\n\t\t\t\t\t/>\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"names":["defaultAvatarValues","avatarColor","kind","size","MrlAvatar","_ref","alt","_ref$avatarColor","dataQa","_ref$kind","image","name","onImageError","_ref$showBorder","showBorder","_ref$size","rest","_objectWithoutProperties","_excluded","containerClasses","classNames","styles","concat","isFacilitatorSize","showIcon","iconContainerClasses","getAvatarRgb","isValidHexColor","hexToRgb","toString","isValidRgbString","substring","length","isValidRgbaString","lastComma","lastIndexOf","renderImage","imgAltText","React","createElement","className","onError","src","getInitials","str","textLength","split","map","item","charAt","toUpperCase","join","replace","isDarkText","stickyTextColor","safeColor","backgroundColor","borderColor","textColor","_extends","style","color","MrlSvg","svg","facilitatorBadge","lock"],"mappings":";;;;;;;;;AAiDO,IAAMA,mBAAmC,GAAG;AAClDC,EAAAA,WAAW,EAAE,SAAS;AACtBC,EAAAA,IA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AAA,EAAA;AACC,IAAA,YAAA,EAAY5B,IAAK;AACjB6B,IAAAA,SAAS,KAAAlB,MAAA,CAAKD,MAAM,CAAC,mBAAmB,CAAC,EAAA,oBAAA,CAAqB;IAC9D,SAAA,EAASb,MAAM,cAAAc,MAAA,CAAcZ,KAAK,GAAG,iBAAiB,GAAG,UAAU,CAAG;AACtEkD,IAAAA,KAAK,EAAE;AACNJ,MAAAA,eAAe,EAAEA,eAAe;AAChCC,MAAAA,WAAW,EAAEA,WAAW;AACxBI,MAAAA,KAAK,EAAEH;AACR;GAAE,EAEDhD,KAAK,GAAG0B,WAAW,EAAE,gBAAGE,KAAA,CAAAC,aAAA,CAAA,MAAA,EAAA;IAAM,aAAA,EAAY;GAAM,EAAEI,WAAW,CAAChC,IAAI,CAAQ,CACtE,CAAC,EACNa,QAAQ,iBACRc,KAAA,CAAAC,aAAA,CAAA,MAAA,EAAA;AACCC,IAAAA,SAAS,EAAEf,oBAAqB;AAChCmC,IAAAA,KAAK,EAAE;AACNJ,MAAAA,eAAe,EAAEC;AAClB;AAAE,GAAA,eAEFnB,KAAA,CAAAC,aAAA,CAACuB,MAAM,EAAA;AACNtB,IAAAA,SAAS,EAAEnB,MAAM,CAAC,gBAAgB,CAAE;AACpClB,IAAAA,IAAI,EAAC,MAAM;AACX4D,IAAAA,GAAG,EAAE7D,IAAI,KAAK,aAAa,GAAG8D,gBAAgB,GAAGC;GACjD,CACI,CAEH,CAAC;AAER;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MrlCallout.js","sources":["../../../../../src/components/callout/MrlCallout/MrlCallout.tsx"],"sourcesContent":["import * as React from 'react';\nimport { MrlPopover, MrlPopoverProps } from '../../popover';\nimport { MrlText, MrlTextHeading } from '../../text';\nimport styles from './MrlCallout.module.scss';\nimport { MrlButton } from '../../button';\nimport { getUniqueId } from '../../../utils';\nimport { PORTAL_LAYERS } from '../../../utils/layers';\nimport { useRef } from 'react';\nimport { useMrlTrackInteraction } from '../../../hooks/useMrlAnalytics';\n\nexport type MrlCalloutPopoverProps = Omit<\n\tMrlPopoverProps,\n\t'children' | 'actionState' | 'isSubMenu' | 'triggerRef' | 'kind'\n>;\n\ninterface MrlCalloutCTA {\n\tonClick: () => void;\n\tdataQa?: string;\n\ttext: string;\n}\n\nexport interface MrlCalloutProps extends MrlCalloutPopoverProps {\n\t/** a unique id that binds the callout content and the trigger for assistive technologies */\n\tariaControls?: string;\n\t/** Has no effect (passed to the popover container, which ignores it). Focus on open is handled by the popover; see `disableFocusTrap`. Kept for backwards compatibility. */\n\tautoFocus?: boolean;\n\tchildren: React.ReactElement;\n\tdisableClickOutside?: boolean;\n\t/** Body text of the callout. A string renders as MrlText; pass an element for rich content. */\n\tdescription?: string | JSX.Element;\n\t/** Short label rendered above the title. */\n\teyebrow?: string;\n\tid?: string;\n\t/** Illustration rendered between the description and the actions. */\n\timage?: JSX.Element;\n\t/** Has no effect. Kept for backwards compatibility. The callout renders in the callout portal layer unless `portalProps` is overridden. */\n\trenderWithPortal?: boolean;\n\t/** Whether the callout is open. The consumer controls visibility; the trigger child gets `aria-expanded` from it. */\n\tshow: boolean;\n\t/** Heading of the callout, rendered as a level 2 heading. */\n\ttitle?: string;\n\t/** Primary action button rendered at the bottom of the callout. */\n\tprimaryCta?: MrlCalloutCTA;\n\t/** Secondary action button rendered before the primary one. */\n\tsecondaryCta?: MrlCalloutCTA;\n\t/**\n\t * Enables interaction tracking for this callout. Provide a stable, non-PII id\n\t * (e.g. 'ai-onboarding-callout'). When omitted, the callout emits no analytics.\n\t *\n\t * Note: title, eyebrow and description text are never emitted.\n\t */\n\teventId?: string;\n}\n\ntype MrlCalloutContent = Pick<\n\tMrlCalloutProps,\n\t'alignment' | 'description' | 'eyebrow' | 'image' | 'title'\n>;\n\n/**\n * MrlCallout component.\n *\n * @param props - The props.\n * @returns {React.ReactElement} The MrlCallout component.\n */\nexport const MrlCallout = (props: MrlCalloutProps): React.ReactElement => {\n\t// In some cases when `show` is false, the content is also null or empty.\n\t// At the same time callout shows fade-out animation and do not disappear immediately.\n\t// Saving last visible content to show it while animating on close.\n\tconst savedContent = useRef<MrlCalloutContent>();\n\tif (props.show) {\n\t\tsavedContent.current = {\n\t\t\talignment: props.alignment,\n\t\t\tdescription: props.description,\n\t\t\teyebrow: props.eyebrow,\n\t\t\timage: props.image,\n\t\t\ttitle: props.title\n\t\t};\n\t}\n\n\tconst {\n\t\tariaControls,\n\t\talignment = 'center',\n\t\tchildren,\n\t\tdescription,\n\t\tdisableClickOutside = true,\n\t\tdisableFocusTrap = true,\n\t\teyebrow,\n\t\thasCloseButton = true,\n\t\timage,\n\t\tonOpen,\n\t\tonClose,\n\t\tpoint = true,\n\t\tposition = 'bottom',\n\t\tprimaryCta,\n\t\tsecondaryCta,\n\t\tshow = true,\n\t\tspacing,\n\t\ttitle,\n\t\t// pulled out of `rest` so the nested MrlPopover doesn't emit a second, less\n\t\t// specific event for the same callout.\n\t\teventId,\n\t\t...rest\n\t} = props.show ? props : { ...props, ...savedContent.current };\n\n\tconst trackInteraction = useMrlTrackInteraction('MrlCallout', eventId);\n\n\t// the callout's visibility is consumer-controlled through `show`, so open/close\n\t// is emitted from that rather than from the popover's internal state.\n\tconst wasShownRef = React.useRef(false);\n\n\tReact.useEffect(() => {\n\t\tif (wasShownRef.current === show) return;\n\n\t\twasShownRef.current = show;\n\n\t\ttrackInteraction({ action: show ? 'open' : 'close' });\n\t}, [show, trackInteraction]);\n\n\tif (React.isValidElement(children) && children.type === React.Fragment) {\n\t\tthrow new Error(\n\t\t\t'MrlCallout accepts a single child and does not accept a React.Fragment as a child.'\n\t\t);\n\t}\n\n\tconst calloutId = React.useMemo(() => getUniqueId('callout-append'), []);\n\tconst triggerRef = React.useRef<HTMLElement | null>(null);\n\n\tconst childElement = React.useMemo(() => {\n\t\treturn React.Children.map(children, (child) => {\n\t\t\treturn React.cloneElement(child, {\n\t\t\t\t...child.props,\n\t\t\t\t/** if the callout is tied to an interactive element we need to ensure that it has role=\"button\" */\n\t\t\t\t...(child.type !== 'button' && { role: 'button' }),\n\t\t\t\t'aria-controls': ariaControls,\n\t\t\t\t'aria-expanded': show,\n\t\t\t\tid: calloutId\n\t\t\t});\n\t\t});\n\t}, [calloutId, children, show, ariaControls]);\n\n\t// Setting trigger ref to the element with the calloutId (set above in the childElement useMemo)\n\t//\n\t// We are using querySelector to set the triggerRef instead of assigning a ref directly in childElement because\n\t// a child element may already have a ref assigned to it and we don't want to override it.\n\tReact.useEffect(() => {\n\t\ttriggerRef.current = document.querySelector(`#${calloutId}`) as HTMLElement;\n\t}, [calloutId]);\n\n\treturn (\n\t\t<>\n\t\t\t{childElement}\n\t\t\t{triggerRef && (\n\t\t\t\t<MrlPopover\n\t\t\t\t\tactionState={{ actionType: 'click', isOpen: show }}\n\t\t\t\t\talignment={alignment}\n\t\t\t\t\tclassName={styles['MrlCallout']}\n\t\t\t\t\tdisableClickToOpen\n\t\t\t\t\tdisableClickOutside={disableClickOutside}\n\t\t\t\t\tdisableFocusTrap={disableFocusTrap}\n\t\t\t\t\thasCloseButton={hasCloseButton}\n\t\t\t\t\tkind=\"inverse\"\n\t\t\t\t\tonClose={onClose}\n\t\t\t\t\tonOpen={onOpen}\n\t\t\t\t\tpoint={point}\n\t\t\t\t\tportalProps={{\n\t\t\t\t\t\tid: PORTAL_LAYERS.CALLOUT.name,\n\t\t\t\t\t\tlayer: PORTAL_LAYERS.CALLOUT\n\t\t\t\t\t}}\n\t\t\t\t\tposition={position}\n\t\t\t\t\tspacing={spacing}\n\t\t\t\t\ttriggerRef={triggerRef}\n\t\t\t\t\t{...rest}\n\t\t\t\t>\n\t\t\t\t\t<div className={styles['MrlCallout--content']}>\n\t\t\t\t\t\t{eyebrow && (\n\t\t\t\t\t\t\t<MrlText attrs={{ className: styles['MrlCallout--eyebrow'] }} text={eyebrow} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{title && (\n\t\t\t\t\t\t\t<MrlTextHeading className={styles['MrlCallout--title']} level=\"2\" text={title} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{description && (\n\t\t\t\t\t\t\t<div className={styles['MrlCallout--description']}>\n\t\t\t\t\t\t\t\t{typeof description === 'string' ? <MrlText text={description} /> : description}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{image && <div className={styles['MrlCallout--image']}>{image}</div>}\n\t\t\t\t\t\t{(primaryCta || secondaryCta) && (\n\t\t\t\t\t\t\t<div className={styles['MrlCallout--footer']}>\n\t\t\t\t\t\t\t\t{secondaryCta && (\n\t\t\t\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\t\t\t\tdata-qa={secondaryCta.dataQa}\n\t\t\t\t\t\t\t\t\t\tkind=\"ghost-inverse\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\ttrackInteraction({\n\t\t\t\t\t\t\t\t\t\t\t\taction: 'click',\n\t\t\t\t\t\t\t\t\t\t\t\tmetadata: { cta: 'secondary' }\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tsecondaryCta.onClick();\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\ttext={secondaryCta.text}\n\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t{primaryCta && (\n\t\t\t\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\t\t\t\tdata-qa={primaryCta.dataQa}\n\t\t\t\t\t\t\t\t\t\tkind=\"inverse\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\ttrackInteraction({\n\t\t\t\t\t\t\t\t\t\t\t\taction: 'click',\n\t\t\t\t\t\t\t\t\t\t\t\tmetadata: { cta: 'primary' }\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tprimaryCta.onClick();\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\ttext={primaryCta.text}\n\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</MrlPopover>\n\t\t\t)}\n\t\t</>\n\t);\n};\n"],"names":["MrlCallout","props","savedContent","useRef","show","current","alignment","description","eyebrow","image","title","_ref","_objectSpread","ariaControls","_ref$alignment","children","_ref$disableClickOuts","disableClickOutside","_ref$disableFocusTrap","disableFocusTrap","_ref$hasCloseButton","hasCloseButton","onOpen","onClose","_ref$point","point","_ref$position","position","primaryCta","secondaryCta","_ref$show","spacing","eventId","rest","_objectWithoutProperties","_excluded","trackInteraction","useMrlTrackInteraction","wasShownRef","React","useEffect","action","isValidElement","type","Fragment","Error","calloutId","useMemo","getUniqueId","triggerRef","childElement","Children","map","child","cloneElement","role","id","document","querySelector","concat","createElement","MrlPopover","_extends","actionState","actionType","isOpen","className","styles","disableClickToOpen","kind","portalProps","PORTAL_LAYERS","CALLOUT","name","layer","MrlText","attrs","text","MrlTextHeading","level","MrlButton","dataQa","onClick","metadata","cta","size"],"mappings":";;;;;;;;;;;;;AA2DA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,UAAU,GAAIC,KAAsB,IAAyB;AACzE;AACA;AACA;AACA,EAAA,IAAMC,YAAY,GAAGC,MAAM,EAAqB;EAChD,IAAIF,KAAK,CAACG,IAAI,EAAE;IACfF,YAAY,CAACG,OAAO,GAAG;MACtBC,SAAS,EAAEL,KAAK,CAACK,SAAS;MAC1BC,WAAW,EAAEN,KAAK,CAACM,WAAW;MAC9BC,OAAO,EAAEP,KAAK,CAACO,OAAO;MACtBC,KAAK,EAAER,KAAK,CAACQ,KAAK;MAClBC,KAAK,EAAET,KAAK,CAACS;KACb;AACF,EAA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A;IAAKM,SAAS,EAAEC,MAAM,CAAC,oBAAoB;AAAE,GAAA,EAC3CtC,YAAY,iBACZU,KAAA,CAAAqB,aAAA,CAACoB,SAAS,EAAA;IACT,SAAA,EAASnD,YAAY,CAACoD,MAAO;AAC7BZ,IAAAA,IAAI,EAAC,eAAe;IACpBa,OAAO,EAAEA,MAAM;AACd9C,MAAAA,gBAAgB,CAAC;AAChBK,QAAAA,MAAM,EAAE,OAAO;AACf0C,QAAAA,QAAQ,EAAE;AAAEC,UAAAA,GAAG,EAAE;AAAY;AAC9B,OAAC,CAAC;MAEFvD,YAAY,CAACqD,OAAO,EAAE;IACvB,CAAE;IACFL,IAAI,EAAEhD,YAAY,CAACgD,IAAK;AACxBQ,IAAAA,IAAI,EAAC;GACL,CACD,EACAzD,UAAU,iBACVW,KAAA,CAAAqB,aAAA,CAACoB,SAAS,EAAA;IACT,SAAA,EAASpD,UAAU,CAACqD,MAAO;AAC3BZ,IAAAA,IAAI,EAAC,SAAS;IACda,OAAO,EAAEA,MAAM;AACd9C,MAAAA,gBAAgB,CAAC;AAChBK,QAAAA,MAAM,EAAE,OAAO;AACf0C,QAAAA,QAAQ,EAAE;AAAEC,UAAAA,GAAG,EAAE;AAAU;AAC5B,OAAC,CAAC;MAEFxD,UAAU,CAACsD,OAAO,EAAE;IACrB,CAAE;IACFL,IAAI,EAAEjD,UAAU,CAACiD,IAAK;AACtBQ,IAAAA,IAAI,EAAC;AAAO,GACZ,CAEE,CAEF,CACM,CAEZ,CAAC;AAEL;;;;"}
|
|
1
|
+
{"version":3,"file":"MrlCallout.js","sources":["../../../../../src/components/callout/MrlCallout/MrlCallout.tsx"],"sourcesContent":["import * as React from 'react';\nimport { MrlPopover, MrlPopoverProps } from '../../popover';\nimport { MrlText, MrlTextHeading } from '../../text';\nimport styles from './MrlCallout.module.scss';\nimport { MrlButton } from '../../button';\nimport { getUniqueId } from '../../../utils';\nimport { PORTAL_LAYERS } from '../../../utils/layers';\nimport { useRef } from 'react';\nimport { useMrlTrackInteraction } from '../../../hooks/useMrlAnalytics';\n\nexport type MrlCalloutPopoverProps = Omit<\n\tMrlPopoverProps,\n\t'children' | 'actionState' | 'isSubMenu' | 'triggerRef' | 'kind'\n>;\n\nexport interface MrlCalloutCTA {\n\tonClick: () => void;\n\tdataQa?: string;\n\ttext: string;\n}\n\nexport interface MrlCalloutProps extends MrlCalloutPopoverProps {\n\t/** a unique id that binds the callout content and the trigger for assistive technologies */\n\tariaControls?: string;\n\t/** Has no effect (passed to the popover container, which ignores it). Focus on open is handled by the popover; see `disableFocusTrap`. Kept for backwards compatibility. */\n\tautoFocus?: boolean;\n\tchildren: React.ReactElement;\n\tdisableClickOutside?: boolean;\n\t/** Body text of the callout. A string renders as MrlText; pass an element for rich content. */\n\tdescription?: string | JSX.Element;\n\t/** Short label rendered above the title. */\n\teyebrow?: string;\n\tid?: string;\n\t/** Illustration rendered between the description and the actions. */\n\timage?: JSX.Element;\n\t/** Has no effect. Kept for backwards compatibility. The callout renders in the callout portal layer unless `portalProps` is overridden. */\n\trenderWithPortal?: boolean;\n\t/** Whether the callout is open. The consumer controls visibility; the trigger child gets `aria-expanded` from it. */\n\tshow: boolean;\n\t/** Heading of the callout, rendered as a level 2 heading. */\n\ttitle?: string;\n\t/** Primary action button rendered at the bottom of the callout. */\n\tprimaryCta?: MrlCalloutCTA;\n\t/** Secondary action button rendered before the primary one. */\n\tsecondaryCta?: MrlCalloutCTA;\n\t/**\n\t * Enables interaction tracking for this callout. Provide a stable, non-PII id\n\t * (e.g. 'ai-onboarding-callout'). When omitted, the callout emits no analytics.\n\t *\n\t * Note: title, eyebrow and description text are never emitted.\n\t */\n\teventId?: string;\n}\n\ntype MrlCalloutContent = Pick<\n\tMrlCalloutProps,\n\t'alignment' | 'description' | 'eyebrow' | 'image' | 'title'\n>;\n\n/**\n * MrlCallout component.\n *\n * @param props - The props.\n * @returns {React.ReactElement} The MrlCallout component.\n */\nexport const MrlCallout = (props: MrlCalloutProps): React.ReactElement => {\n\t// In some cases when `show` is false, the content is also null or empty.\n\t// At the same time callout shows fade-out animation and do not disappear immediately.\n\t// Saving last visible content to show it while animating on close.\n\tconst savedContent = useRef<MrlCalloutContent>();\n\tif (props.show) {\n\t\tsavedContent.current = {\n\t\t\talignment: props.alignment,\n\t\t\tdescription: props.description,\n\t\t\teyebrow: props.eyebrow,\n\t\t\timage: props.image,\n\t\t\ttitle: props.title\n\t\t};\n\t}\n\n\tconst {\n\t\tariaControls,\n\t\talignment = 'center',\n\t\tchildren,\n\t\tdescription,\n\t\tdisableClickOutside = true,\n\t\tdisableFocusTrap = true,\n\t\teyebrow,\n\t\thasCloseButton = true,\n\t\timage,\n\t\tonOpen,\n\t\tonClose,\n\t\tpoint = true,\n\t\tposition = 'bottom',\n\t\tprimaryCta,\n\t\tsecondaryCta,\n\t\tshow = true,\n\t\tspacing,\n\t\ttitle,\n\t\t// pulled out of `rest` so the nested MrlPopover doesn't emit a second, less\n\t\t// specific event for the same callout.\n\t\teventId,\n\t\t...rest\n\t} = props.show ? props : { ...props, ...savedContent.current };\n\n\tconst trackInteraction = useMrlTrackInteraction('MrlCallout', eventId);\n\n\t// the callout's visibility is consumer-controlled through `show`, so open/close\n\t// is emitted from that rather than from the popover's internal state.\n\tconst wasShownRef = React.useRef(false);\n\n\tReact.useEffect(() => {\n\t\tif (wasShownRef.current === show) return;\n\n\t\twasShownRef.current = show;\n\n\t\ttrackInteraction({ action: show ? 'open' : 'close' });\n\t}, [show, trackInteraction]);\n\n\tif (React.isValidElement(children) && children.type === React.Fragment) {\n\t\tthrow new Error(\n\t\t\t'MrlCallout accepts a single child and does not accept a React.Fragment as a child.'\n\t\t);\n\t}\n\n\tconst calloutId = React.useMemo(() => getUniqueId('callout-append'), []);\n\tconst triggerRef = React.useRef<HTMLElement | null>(null);\n\n\tconst childElement = React.useMemo(() => {\n\t\treturn React.Children.map(children, (child) => {\n\t\t\treturn React.cloneElement(child, {\n\t\t\t\t...child.props,\n\t\t\t\t/** if the callout is tied to an interactive element we need to ensure that it has role=\"button\" */\n\t\t\t\t...(child.type !== 'button' && { role: 'button' }),\n\t\t\t\t'aria-controls': ariaControls,\n\t\t\t\t'aria-expanded': show,\n\t\t\t\tid: calloutId\n\t\t\t});\n\t\t});\n\t}, [calloutId, children, show, ariaControls]);\n\n\t// Setting trigger ref to the element with the calloutId (set above in the childElement useMemo)\n\t//\n\t// We are using querySelector to set the triggerRef instead of assigning a ref directly in childElement because\n\t// a child element may already have a ref assigned to it and we don't want to override it.\n\tReact.useEffect(() => {\n\t\ttriggerRef.current = document.querySelector(`#${calloutId}`) as HTMLElement;\n\t}, [calloutId]);\n\n\treturn (\n\t\t<>\n\t\t\t{childElement}\n\t\t\t{triggerRef && (\n\t\t\t\t<MrlPopover\n\t\t\t\t\tactionState={{ actionType: 'click', isOpen: show }}\n\t\t\t\t\talignment={alignment}\n\t\t\t\t\tclassName={styles['MrlCallout']}\n\t\t\t\t\tdisableClickToOpen\n\t\t\t\t\tdisableClickOutside={disableClickOutside}\n\t\t\t\t\tdisableFocusTrap={disableFocusTrap}\n\t\t\t\t\thasCloseButton={hasCloseButton}\n\t\t\t\t\tkind=\"inverse\"\n\t\t\t\t\tonClose={onClose}\n\t\t\t\t\tonOpen={onOpen}\n\t\t\t\t\tpoint={point}\n\t\t\t\t\tportalProps={{\n\t\t\t\t\t\tid: PORTAL_LAYERS.CALLOUT.name,\n\t\t\t\t\t\tlayer: PORTAL_LAYERS.CALLOUT\n\t\t\t\t\t}}\n\t\t\t\t\tposition={position}\n\t\t\t\t\tspacing={spacing}\n\t\t\t\t\ttriggerRef={triggerRef}\n\t\t\t\t\t{...rest}\n\t\t\t\t>\n\t\t\t\t\t<div className={styles['MrlCallout--content']}>\n\t\t\t\t\t\t{eyebrow && (\n\t\t\t\t\t\t\t<MrlText attrs={{ className: styles['MrlCallout--eyebrow'] }} text={eyebrow} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{title && (\n\t\t\t\t\t\t\t<MrlTextHeading className={styles['MrlCallout--title']} level=\"2\" text={title} />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{description && (\n\t\t\t\t\t\t\t<div className={styles['MrlCallout--description']}>\n\t\t\t\t\t\t\t\t{typeof description === 'string' ? <MrlText text={description} /> : description}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{image && <div className={styles['MrlCallout--image']}>{image}</div>}\n\t\t\t\t\t\t{(primaryCta || secondaryCta) && (\n\t\t\t\t\t\t\t<div className={styles['MrlCallout--footer']}>\n\t\t\t\t\t\t\t\t{secondaryCta && (\n\t\t\t\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\t\t\t\tdata-qa={secondaryCta.dataQa}\n\t\t\t\t\t\t\t\t\t\tkind=\"ghost-inverse\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\ttrackInteraction({\n\t\t\t\t\t\t\t\t\t\t\t\taction: 'click',\n\t\t\t\t\t\t\t\t\t\t\t\tmetadata: { cta: 'secondary' }\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tsecondaryCta.onClick();\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\ttext={secondaryCta.text}\n\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t{primaryCta && (\n\t\t\t\t\t\t\t\t\t<MrlButton\n\t\t\t\t\t\t\t\t\t\tdata-qa={primaryCta.dataQa}\n\t\t\t\t\t\t\t\t\t\tkind=\"inverse\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\ttrackInteraction({\n\t\t\t\t\t\t\t\t\t\t\t\taction: 'click',\n\t\t\t\t\t\t\t\t\t\t\t\tmetadata: { cta: 'primary' }\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tprimaryCta.onClick();\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\ttext={primaryCta.text}\n\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</MrlPopover>\n\t\t\t)}\n\t\t</>\n\t);\n};\n"],"names":["MrlCallout","props","savedContent","useRef","show","current","alignment","description","eyebrow","image","title","_ref","_objectSpread","ariaControls","_ref$alignment","children","_ref$disableClickOuts","disableClickOutside","_ref$disableFocusTrap","disableFocusTrap","_ref$hasCloseButton","hasCloseButton","onOpen","onClose","_ref$point","point","_ref$position","position","primaryCta","secondaryCta","_ref$show","spacing","eventId","rest","_objectWithoutProperties","_excluded","trackInteraction","useMrlTrackInteraction","wasShownRef","React","useEffect","action","isValidElement","type","Fragment","Error","calloutId","useMemo","getUniqueId","triggerRef","childElement","Children","map","child","cloneElement","role","id","document","querySelector","concat","createElement","MrlPopover","_extends","actionState","actionType","isOpen","className","styles","disableClickToOpen","kind","portalProps","PORTAL_LAYERS","CALLOUT","name","layer","MrlText","attrs","text","MrlTextHeading","level","MrlButton","dataQa","onClick","metadata","cta","size"],"mappings":";;;;;;;;;;;;;AA2DA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,UAAU,GAAIC,KAAsB,IAAyB;AACzE;AACA;AACA;AACA,EAAA,IAAMC,YAAY,GAAGC,MAAM,EAAqB;EAChD,IAAIF,KAAK,CAACG,IAAI,EAAE;IACfF,YAAY,CAACG,OAAO,GAAG;MACtBC,SAAS,EAAEL,KAAK,CAACK,SAAS;MAC1BC,WAAW,EAAEN,KAAK,CAACM,WAAW;MAC9BC,OAAO,EAAEP,KAAK,CAACO,OAAO;MACtBC,KAAK,EAAER,KAAK,CAACQ,KAAK;MAClBC,KAAK,EAAET,KAAK,CA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,CAAA,KAAA,EAAA;IAAKM,SAAS,EAAEC,MAAM,CAAC,oBAAoB;AAAE,GAAA,EAC3CtC,YAAY,iBACZU,KAAA,CAAAqB,aAAA,CAACoB,SAAS,EAAA;IACT,SAAA,EAASnD,YAAY,CAACoD,MAAO;AAC7BZ,IAAAA,IAAI,EAAC,eAAe;IACpBa,OAAO,EAAEA,MAAM;AACd9C,MAAAA,gBAAgB,CAAC;AAChBK,QAAAA,MAAM,EAAE,OAAO;AACf0C,QAAAA,QAAQ,EAAE;AAAEC,UAAAA,GAAG,EAAE;AAAY;AAC9B,OAAC,CAAC;MAEFvD,YAAY,CAACqD,OAAO,EAAE;IACvB,CAAE;IACFL,IAAI,EAAEhD,YAAY,CAACgD,IAAK;AACxBQ,IAAAA,IAAI,EAAC;GACL,CACD,EACAzD,UAAU,iBACVW,KAAA,CAAAqB,aAAA,CAACoB,SAAS,EAAA;IACT,SAAA,EAASpD,UAAU,CAACqD,MAAO;AAC3BZ,IAAAA,IAAI,EAAC,SAAS;IACda,OAAO,EAAEA,MAAM;AACd9C,MAAAA,gBAAgB,CAAC;AAChBK,QAAAA,MAAM,EAAE,OAAO;AACf0C,QAAAA,QAAQ,EAAE;AAAEC,UAAAA,GAAG,EAAE;AAAU;AAC5B,OAAC,CAAC;MAEFxD,UAAU,CAACsD,OAAO,EAAE;IACrB,CAAE;IACFL,IAAI,EAAEjD,UAAU,CAACiD,IAAK;AACtBQ,IAAAA,IAAI,EAAC;AAAO,GACZ,CAEE,CAEF,CACM,CAEZ,CAAC;AAEL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MrlTextarea.js","sources":["../../../../../../src/components/form/textarea/MrlTextarea/MrlTextarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport classnames from 'classnames';\nimport { AttrsObject, setAttributes } from '../../../../utils';\nimport { useMrlTrackInteraction } from '../../../../hooks/useMrlAnalytics';\n\nimport styles from './MrlTextarea.module.scss';\nimport './MrlTextarea.global.scss';\n\ntype MrlTextareaState = 'default' | 'disabled' | 'error' | 'read-only';\n\ninterface MrlTextareaProps {\n\t/** Applies additional HTML attributes to the textarea element */\n\tattrs?: AttrsObject;\n\t/** The value of the textarea used to make it a controlled input */\n\tvalue?: string;\n\t/**\n\t * The maximum number of characters that the user can enter.\n\t * If undefined or set to \"0\", removes the character counter from the textarea\n\t */\n\tmaxLength?: number;\n\t/**\n\t * Id of the text input.\n\t */\n\tinputId: string;\n\t/**\n\t * Text placeholder for the text input.\n\t */\n\tplaceholder?: string;\n\t/**\n\t * Changes the state of the input based on user permissions or actions.\n\t */\n\tstate?: MrlTextareaState;\n\n\t/** Additional class to add to the textarea */\n\tclassName?: string;\n\n\t/** Autoexpand will automatically adjust the height of the textarea based on the amount of text within it */\n\tautoExpand?: boolean;\n\n\t/**\n\t * Enables interaction tracking for this textarea. Provide a stable, non-PII id\n\t * (e.g. 'template-description'). When omitted, the textarea emits no analytics.\n\t *\n\t * Note: the textarea's value is never emitted, and `change` is emitted once per\n\t * editing session (on blur, when the value actually changed) rather than per keystroke.\n\t */\n\teventId?: string;\n}\n\n/**\n * Allows the user to input plain text in a multi-line format\n * @param {MrlTextareaProps} props - the component props\n * @returns a textarea element\n */\nexport function MrlTextarea({\n\tattrs = {},\n\tclassName,\n\tinputId,\n\tstate = 'default',\n\tmaxLength,\n\tplaceholder,\n\teventId,\n\tvalue,\n\tautoExpand = false,\n\t...rest\n}: MrlTextareaProps): JSX.Element {\n\tconst textareaRef = React.useRef<HTMLTextAreaElement>(null);\n\t// the value when the field gained focus, so `change` can be emitted once per\n\t// editing session instead of once per keystroke.\n\tconst valueOnFocusRef = React.useRef<string>('');\n\n\tconst trackInteraction = useMrlTrackInteraction('MrlTextarea', eventId);\n\n\tReact.useEffect(() => {\n\t\tif (textareaRef.current && attrs.autofocus) {\n\t\t\ttextareaRef.current.focus();\n\t\t}\n\t}, [attrs, textareaRef]);\n\n\tconst dataMaxLength = attrs['data-maxlength'];\n\n\t// Special use-case for AI Chat Input (AI-658)\n\tReact.useEffect(() => {\n\t\tif (autoExpand && textareaRef.current) {\n\t\t\ttextareaRef.current.style.height = '0px';\n\t\t\tconst scrollHeight = textareaRef.current.scrollHeight + 4;\n\t\t\ttextareaRef.current.style.height = scrollHeight + 'px';\n\t\t}\n\t}, [value, autoExpand]);\n\n\tconst hasMaxLength = typeof maxLength !== 'undefined' && Number(maxLength) > 0;\n\tconst hasDataMaxLength = typeof dataMaxLength !== 'undefined' && Number(dataMaxLength) > 0;\n\n\tconst displayCounter = hasMaxLength || hasDataMaxLength;\n\n\tif (hasMaxLength && isNaN(Number(maxLength))) {\n\t\tthrow new Error('maxLength should have type number');\n\t}\n\n\tif (hasDataMaxLength && isNaN(Number(hasDataMaxLength))) {\n\t\tthrow new Error('data-maxlength should have type number');\n\t}\n\n\tif (hasMaxLength && hasDataMaxLength) {\n\t\tthrow new Error('maxLength and data-maxlength should not be used at the same time');\n\t}\n\n\tconst inputClasses = classnames(\n\t\tattrs.class || attrs.className,\n\t\tclassName,\n\t\tstyles['MrlTextarea'],\n\t\t'MrlTextarea',\n\t\t'mrl-textarea',\n\t\t{\n\t\t\t[styles['MrlTextarea--auto-expand']]: autoExpand,\n\t\t\t[styles['MrlTextarea--read-only']]: state === 'read-only'\n\t\t}\n\t);\n\n\tdelete attrs.class;\n\tdelete attrs.className;\n\n\tconst attributes = setAttributes(attrs);\n\n\t/**\n\t * Handle focus events\n\t *\n\t * @param {React.FocusEvent<HTMLTextAreaElement>} e - focus event\n\t */\n\tconst handleOnFocus = (e: React.FocusEvent<HTMLTextAreaElement>) => {\n\t\tvalueOnFocusRef.current = e.target.value;\n\n\t\tif (typeof attributes.onFocus === 'function') {\n\t\t\tattributes.onFocus(e);\n\t\t}\n\t};\n\n\t/**\n\t * Handle blur events\n\t *\n\t * @param {React.FocusEvent<HTMLTextAreaElement>} e - blur event\n\t */\n\tconst handleOnBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {\n\t\t// the value itself is never emitted — only the fact that it changed.\n\t\tif (e.target.value !== valueOnFocusRef.current) {\n\t\t\ttrackInteraction({ action: 'change' });\n\t\t}\n\n\t\tif (typeof attributes.onBlur === 'function') {\n\t\t\tattributes.onBlur(e);\n\t\t}\n\t};\n\n\tconst renderCounter = () => {\n\t\tconst displayedValue = dataMaxLength ? dataMaxLength : maxLength;\n\t\tconst valueExceedsDataMaxLength = dataMaxLength && value ? value.length > dataMaxLength : false;\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tclassName={classnames('MrlCounter', {\n\t\t\t\t\t\t'MrlCounter-overMaxLength': valueExceedsDataMaxLength\n\t\t\t\t\t})}\n\t\t\t\t\tid={`${inputId}-visible-counter`}\n\t\t\t\t>\n\t\t\t\t\t{value?.length || 0}/{displayedValue}\n\t\t\t\t</span>\n\t\t\t\t<p style={{ display: 'none' }} id={`${inputId}-counter`}>\n\t\t\t\t\t{`${displayedValue - (value?.length || 0)} of ${displayedValue} characters remaining`}\n\t\t\t\t</p>\n\t\t\t</>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"MrlTextarea--wrapper\">\n\t\t\t\t<textarea\n\t\t\t\t\t{...rest}\n\t\t\t\t\t{...attributes}\n\t\t\t\t\tid={inputId}\n\t\t\t\t\tonBlur={handleOnBlur}\n\t\t\t\t\tonFocus={handleOnFocus}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tclassName={inputClasses}\n\t\t\t\t\t// Force value if defined (controlled component) or pass\n\t\t\t\t\t// undefined and fallback to the default (uncontrolled)\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdisabled={state === 'disabled'}\n\t\t\t\t\taria-invalid={state === 'error'}\n\t\t\t\t\taria-describedby={`${inputId}-counter`}\n\t\t\t\t\tmaxLength={hasMaxLength ? maxLength : undefined}\n\t\t\t\t\tref={textareaRef}\n\t\t\t\t\treadOnly={state === 'read-only'}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{displayCounter && state !== 'read-only' && (\n\t\t\t\t<span className={classnames(styles['MrlForm-counter'], 'MrlForm-counter')}>\n\t\t\t\t\t{renderCounter()}\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</>\n\t);\n}\n"],"names":["MrlTextarea","_ref","_ref$attrs","attrs","className","inputId","_ref$state","state","maxLength","placeholder","eventId","value","_ref$autoExpand","autoExpand","rest","_objectWithoutProperties","_excluded","textareaRef","React","useRef","valueOnFocusRef","trackInteraction","useMrlTrackInteraction","useEffect","current","autofocus","focus","dataMaxLength","style","height","scrollHeight","hasMaxLength","Number","hasDataMaxLength","displayCounter","isNaN","Error","inputClasses","classnames","class","styles","attributes","setAttributes","handleOnFocus","e","target","onFocus","handleOnBlur","action","onBlur","renderCounter","displayedValue","valueExceedsDataMaxLength","length","createElement","Fragment","id","concat","display","_extends","disabled","undefined","ref","readOnly"],"mappings":";;;;;;;;AAiDA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAWA,CAAAC,IAAA,EAWO;AAAA,EAAA,IAAAC,UAAA,GAAAD,IAAA,CAVjCE,KAAK;AAALA,IAAAA,KAAK,GAAAD,UAAA,KAAA,MAAA,GAAG,EAAE,GAAAA,UAAA;IACVE,SAAS,GAAAH,IAAA,CAATG,SAAS;IACTC,OAAO,GAAAJ,IAAA,CAAPI,OAAO;IAAAC,UAAA,GAAAL,IAAA,CACPM,KAAK;AAALA,IAAAA,KAAK,GAAAD,UAAA,KAAA,MAAA,GAAG,SAAS,GAAAA,UAAA;IACjBE,SAAS,GAAAP,IAAA,CAATO,SAAS;IACTC,WAAW,GAAAR,IAAA,CAAXQ,WAAW;IACXC,OAAO,GAAAT,IAAA,CAAPS,OAAO;IACPC,KAAK,GAAAV,IAAA,CAALU,KAAK;IAAAC,eAAA,GAAAX,IAAA,CACLY,UAAU;AAAVA,IAAAA,UAAU,GAAAD,eAAA,KAAA,MAAA,GAAG,KAAK,GAAAA,eAAA;AACfE,IAAAA,IAAI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AA,MAAA,CAAA,CAAAI,MAAA,CAAON,cAAc,EAAA,uBAAA,CAC5D,CACF,CAAC;EAEL,CAAC;EAED,oBACCjC,KAAA,CAAAoC,aAAA,CAAApC,KAAA,CAAAqC,QAAA,EAAA,IAAA,eACCrC,KAAA,CAAAoC,aAAA,CAAA,KAAA,EAAA;AAAKlD,IAAAA,SAAS,EAAC;GAAsB,eACpCc,KAAA,CAAAoC,aAAA,CAAA,UAAA,EAAAK,QAAA,CAAA,EAAA,EACK7C,IAAI,EACJ2B,UAAU,EAAA;AACde,IAAAA,EAAE,EAAEnD,OAAQ;AACZ4C,IAAAA,MAAM,EAAEF,YAAa;AACrBD,IAAAA,OAAO,EAAEH,aAAc;AACvBlC,IAAAA,WAAW,EAAEA,WAAY;AACzBL,IAAAA,SAAS,EAAEiC;AACX;AACA;AAAA;AACA1B,IAAAA,KAAK,EAAEA,KAAM;IACbiD,QAAQ,EAAErD,KAAK,KAAK,UAAW;IAC/B,cAAA,EAAcA,KAAK,KAAK,OAAQ;IAChC,kBAAA,EAAA,EAAA,CAAAkD,MAAA,CAAqBpD,OAAO,EAAA,UAAA,CAAW;AACvCG,IAAAA,SAAS,EAAEuB,YAAY,GAAGvB,SAAS,GAAGqD,SAAU;AAChDC,IAAAA,GAAG,EAAE7C,WAAY;IACjB8C,QAAQ,EAAExD,KAAK,KAAK;GAAY,CAChC,CACG,CAAC,EACL2B,cAAc,IAAI3B,KAAK,KAAK,WAAW,iBACvCW,KAAA,CAAAoC,aAAA,CAAA,MAAA,EAAA;IAAMlD,SAAS,EAAEkC,UAAU,CAACE,MAAM,CAAC,iBAAiB,CAAC,EAAE,iBAAiB;AAAE,GAAA,EACxEU,aAAa,EACT,CAEN,CAAC;AAEL;;;;"}
|
|
1
|
+
{"version":3,"file":"MrlTextarea.js","sources":["../../../../../../src/components/form/textarea/MrlTextarea/MrlTextarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport classnames from 'classnames';\nimport { AttrsObject, setAttributes } from '../../../../utils';\nimport { useMrlTrackInteraction } from '../../../../hooks/useMrlAnalytics';\n\nimport styles from './MrlTextarea.module.scss';\nimport './MrlTextarea.global.scss';\n\nexport type MrlTextareaState = 'default' | 'disabled' | 'error' | 'read-only';\n\ninterface MrlTextareaProps {\n\t/** Applies additional HTML attributes to the textarea element */\n\tattrs?: AttrsObject;\n\t/** The value of the textarea used to make it a controlled input */\n\tvalue?: string;\n\t/**\n\t * The maximum number of characters that the user can enter.\n\t * If undefined or set to \"0\", removes the character counter from the textarea\n\t */\n\tmaxLength?: number;\n\t/**\n\t * Id of the text input.\n\t */\n\tinputId: string;\n\t/**\n\t * Text placeholder for the text input.\n\t */\n\tplaceholder?: string;\n\t/**\n\t * Changes the state of the input based on user permissions or actions.\n\t */\n\tstate?: MrlTextareaState;\n\n\t/** Additional class to add to the textarea */\n\tclassName?: string;\n\n\t/** Autoexpand will automatically adjust the height of the textarea based on the amount of text within it */\n\tautoExpand?: boolean;\n\n\t/**\n\t * Enables interaction tracking for this textarea. Provide a stable, non-PII id\n\t * (e.g. 'template-description'). When omitted, the textarea emits no analytics.\n\t *\n\t * Note: the textarea's value is never emitted, and `change` is emitted once per\n\t * editing session (on blur, when the value actually changed) rather than per keystroke.\n\t */\n\teventId?: string;\n}\n\n/**\n * Allows the user to input plain text in a multi-line format\n * @param {MrlTextareaProps} props - the component props\n * @returns a textarea element\n */\nexport function MrlTextarea({\n\tattrs = {},\n\tclassName,\n\tinputId,\n\tstate = 'default',\n\tmaxLength,\n\tplaceholder,\n\teventId,\n\tvalue,\n\tautoExpand = false,\n\t...rest\n}: MrlTextareaProps): JSX.Element {\n\tconst textareaRef = React.useRef<HTMLTextAreaElement>(null);\n\t// the value when the field gained focus, so `change` can be emitted once per\n\t// editing session instead of once per keystroke.\n\tconst valueOnFocusRef = React.useRef<string>('');\n\n\tconst trackInteraction = useMrlTrackInteraction('MrlTextarea', eventId);\n\n\tReact.useEffect(() => {\n\t\tif (textareaRef.current && attrs.autofocus) {\n\t\t\ttextareaRef.current.focus();\n\t\t}\n\t}, [attrs, textareaRef]);\n\n\tconst dataMaxLength = attrs['data-maxlength'];\n\n\t// Special use-case for AI Chat Input (AI-658)\n\tReact.useEffect(() => {\n\t\tif (autoExpand && textareaRef.current) {\n\t\t\ttextareaRef.current.style.height = '0px';\n\t\t\tconst scrollHeight = textareaRef.current.scrollHeight + 4;\n\t\t\ttextareaRef.current.style.height = scrollHeight + 'px';\n\t\t}\n\t}, [value, autoExpand]);\n\n\tconst hasMaxLength = typeof maxLength !== 'undefined' && Number(maxLength) > 0;\n\tconst hasDataMaxLength = typeof dataMaxLength !== 'undefined' && Number(dataMaxLength) > 0;\n\n\tconst displayCounter = hasMaxLength || hasDataMaxLength;\n\n\tif (hasMaxLength && isNaN(Number(maxLength))) {\n\t\tthrow new Error('maxLength should have type number');\n\t}\n\n\tif (hasDataMaxLength && isNaN(Number(hasDataMaxLength))) {\n\t\tthrow new Error('data-maxlength should have type number');\n\t}\n\n\tif (hasMaxLength && hasDataMaxLength) {\n\t\tthrow new Error('maxLength and data-maxlength should not be used at the same time');\n\t}\n\n\tconst inputClasses = classnames(\n\t\tattrs.class || attrs.className,\n\t\tclassName,\n\t\tstyles['MrlTextarea'],\n\t\t'MrlTextarea',\n\t\t'mrl-textarea',\n\t\t{\n\t\t\t[styles['MrlTextarea--auto-expand']]: autoExpand,\n\t\t\t[styles['MrlTextarea--read-only']]: state === 'read-only'\n\t\t}\n\t);\n\n\tdelete attrs.class;\n\tdelete attrs.className;\n\n\tconst attributes = setAttributes(attrs);\n\n\t/**\n\t * Handle focus events\n\t *\n\t * @param {React.FocusEvent<HTMLTextAreaElement>} e - focus event\n\t */\n\tconst handleOnFocus = (e: React.FocusEvent<HTMLTextAreaElement>) => {\n\t\tvalueOnFocusRef.current = e.target.value;\n\n\t\tif (typeof attributes.onFocus === 'function') {\n\t\t\tattributes.onFocus(e);\n\t\t}\n\t};\n\n\t/**\n\t * Handle blur events\n\t *\n\t * @param {React.FocusEvent<HTMLTextAreaElement>} e - blur event\n\t */\n\tconst handleOnBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {\n\t\t// the value itself is never emitted — only the fact that it changed.\n\t\tif (e.target.value !== valueOnFocusRef.current) {\n\t\t\ttrackInteraction({ action: 'change' });\n\t\t}\n\n\t\tif (typeof attributes.onBlur === 'function') {\n\t\t\tattributes.onBlur(e);\n\t\t}\n\t};\n\n\tconst renderCounter = () => {\n\t\tconst displayedValue = dataMaxLength ? dataMaxLength : maxLength;\n\t\tconst valueExceedsDataMaxLength = dataMaxLength && value ? value.length > dataMaxLength : false;\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tclassName={classnames('MrlCounter', {\n\t\t\t\t\t\t'MrlCounter-overMaxLength': valueExceedsDataMaxLength\n\t\t\t\t\t})}\n\t\t\t\t\tid={`${inputId}-visible-counter`}\n\t\t\t\t>\n\t\t\t\t\t{value?.length || 0}/{displayedValue}\n\t\t\t\t</span>\n\t\t\t\t<p style={{ display: 'none' }} id={`${inputId}-counter`}>\n\t\t\t\t\t{`${displayedValue - (value?.length || 0)} of ${displayedValue} characters remaining`}\n\t\t\t\t</p>\n\t\t\t</>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"MrlTextarea--wrapper\">\n\t\t\t\t<textarea\n\t\t\t\t\t{...rest}\n\t\t\t\t\t{...attributes}\n\t\t\t\t\tid={inputId}\n\t\t\t\t\tonBlur={handleOnBlur}\n\t\t\t\t\tonFocus={handleOnFocus}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tclassName={inputClasses}\n\t\t\t\t\t// Force value if defined (controlled component) or pass\n\t\t\t\t\t// undefined and fallback to the default (uncontrolled)\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdisabled={state === 'disabled'}\n\t\t\t\t\taria-invalid={state === 'error'}\n\t\t\t\t\taria-describedby={`${inputId}-counter`}\n\t\t\t\t\tmaxLength={hasMaxLength ? maxLength : undefined}\n\t\t\t\t\tref={textareaRef}\n\t\t\t\t\treadOnly={state === 'read-only'}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{displayCounter && state !== 'read-only' && (\n\t\t\t\t<span className={classnames(styles['MrlForm-counter'], 'MrlForm-counter')}>\n\t\t\t\t\t{renderCounter()}\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</>\n\t);\n}\n"],"names":["MrlTextarea","_ref","_ref$attrs","attrs","className","inputId","_ref$state","state","maxLength","placeholder","eventId","value","_ref$autoExpand","autoExpand","rest","_objectWithoutProperties","_excluded","textareaRef","React","useRef","valueOnFocusRef","trackInteraction","useMrlTrackInteraction","useEffect","current","autofocus","focus","dataMaxLength","style","height","scrollHeight","hasMaxLength","Number","hasDataMaxLength","displayCounter","isNaN","Error","inputClasses","classnames","class","styles","attributes","setAttributes","handleOnFocus","e","target","onFocus","handleOnBlur","action","onBlur","renderCounter","displayedValue","valueExceedsDataMaxLength","length","createElement","Fragment","id","concat","display","_extends","disabled","undefined","ref","readOnly"],"mappings":";;;;;;;;AAiDA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAWA,CAAAC,IAAA,EAWO;AAAA,EAAA,IAAAC,UAAA,GAAAD,IAAA,CAVjCE,KAAK;AAALA,IAAAA,KAAK,GAAAD,UAAA,KAAA,MAAA,GAAG,EAAE,GAAAA,UAAA;IACVE,SAAS,GAAAH,IAAA,CAATG,SAAS;IACTC,OAAO,GAAAJ,IAAA,CAAPI,OAAO;IAAAC,UAAA,GAAAL,IAAA,CACPM,KAAK;AAALA,IAAAA,KAAK,GAAAD,UAAA,KAAA,MAAA,GAAG,SAAS,GAAAA,UAAA;IACjBE,SAAS,GAAAP,IAAA,CAATO,SAAS;IACTC,WAAW,GAAAR,IAAA,CAAXQ,WAAW;IACXC,OAAO,GAAAT,IAAA,CAAPS,OAAO;IACPC,KAAK,GAAAV,IAAA,CAALU,KAAK;IAAAC,eAAA,GAAAX,IAAA,CACLY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../../../../src/components/grid/constants.ts"],"sourcesContent":["import { DataQa } from '../../utils/dataQa';\n\n/**\n * Alignment & justification options for grid containers\n */\nexport type AlignOptions = 'start' | 'center' | 'end';\nexport type JustifyOptions = 'start' | 'center' | 'end' | 'between' | 'around';\n\n/**\n * Number of columns a `col` can span. There is no `col-0` class — a column\n * always occupies at least one of the twelve tracks.\n */\nexport type ColSpan = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n\n/**\n * Number of columns an `offset` can skip. `0` is meaningful here: it is how a\n * larger breakpoint cancels an offset inherited from a smaller one.\n */\nexport type OffsetSpan = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;\n\n/**\n * @deprecated Use `ColSpan` for spans or `OffsetSpan` for offsets. This union\n * allowed `col={0}`, which never produced a class.\n */\nexport type NumCols = 0 | ColSpan;\n\n/**\n * Interface of available class selectors per breakpoint.\n *\n * Example interface:\n * {\n * col?: number,\n * offset?: number\n * }\n */\
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/components/grid/constants.ts"],"sourcesContent":["import { DataQa } from '../../utils/dataQa';\n\n/**\n * Alignment & justification options for grid containers\n */\nexport type AlignOptions = 'start' | 'center' | 'end';\nexport type JustifyOptions = 'start' | 'center' | 'end' | 'between' | 'around';\n\n/**\n * Number of columns a `col` can span. There is no `col-0` class — a column\n * always occupies at least one of the twelve tracks.\n */\nexport type ColSpan = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;\n\n/**\n * Number of columns an `offset` can skip. `0` is meaningful here: it is how a\n * larger breakpoint cancels an offset inherited from a smaller one.\n */\nexport type OffsetSpan = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;\n\n/**\n * @deprecated Use `ColSpan` for spans or `OffsetSpan` for offsets. This union\n * allowed `col={0}`, which never produced a class.\n */\nexport type NumCols = 0 | ColSpan;\n\n/**\n * Interface of available class selectors per breakpoint.\n *\n * Example interface:\n * {\n * col?: number,\n * offset?: number\n * }\n */\nexport type GridClassConfig = {\n\tcol?: ColSpan;\n\toffset?: OffsetSpan;\n};\n\n/**\n * Options to configure the number of columns to span on different screen sizes.\n */\nexport type ColumnConfig = ColSpan | 'auto' | GridClassConfig | undefined;\n\nexport interface GridColumns {\n\t/**\n\t * Columns that are the same from the smallest of devices to the largest.\n\t */\n\tcol?: ColumnConfig;\n\n\t/**\n\t * @deprecated Alias of `col`, kept for backwards compatibility. It resolves\n\t * to the same un-prefixed tier, so passing both `col` and `xs` emits two\n\t * competing classes and the larger span wins on CSS source order rather\n\t * than the one you wrote last. Pass only one.\n\t */\n\txs?: ColumnConfig;\n\n\t/**\n\t * The number of columns to span from the sm breakpoint up.\n\t */\n\tsm?: ColumnConfig;\n\n\t/**\n\t * The number of columns to span from the md breakpoint up.\n\t */\n\tmd?: ColumnConfig;\n\n\t/**\n\t * The number of columns to span from the lg breakpoint up.\n\t */\n\tlg?: ColumnConfig;\n\n\t/**\n\t * The number of columns to span from the xl breakpoint up.\n\t */\n\txl?: ColumnConfig;\n\n\t/**\n\t * The number of columns to span from the xxl breakpoint up.\n\t */\n\txxl?: ColumnConfig;\n}\n\n/**\n * Breakpoint keys in ascending order. Drives both class generation and the\n * filtering that keeps grid props from reaching the DOM.\n */\nexport const GRID_SIZE_KEYS = ['col', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'] as const;\n\n/**\n * Available gutter sizes for customizing the grid\n */\nexport type GutterSizes = 0 | 1 | 2;\n\n/**\n * Gutter size to modifier class. `1` is the default declared on `.row`, so it\n * needs no class.\n */\nexport const GUTTER_CLASS: Record<GutterSizes, string | undefined> = {\n\t0: 'MrlRow-gutter--none',\n\t1: undefined,\n\t2: 'MrlRow-gutter--double'\n};\n\n/**\n * Roles a generic layout wrapper may safely carry.\n *\n * Composite widget roles (`grid`, `row`, `gridcell`, `listbox`, `tablist`, …)\n * are deliberately excluded: they promise an APG keyboard contract — roving\n * tabindex or `aria-activedescendant`, arrow-key navigation, selection state —\n * that these divs do not implement. The roles below are structural only and\n * carry no interaction contract, so they are safe to forward.\n *\n * `list`/`listitem` in particular is how a row of columns is announced as\n * \"list, N items\", and is the standard workaround for Safari/VoiceOver\n * dropping implicit list semantics. `region` needs an accessible name to be\n * exposed as a landmark; the type cannot enforce that.\n *\n * Page landmarks belong to the layout components (MrlMain, MrlPage).\n */\nexport type SafeLayoutRole = 'group' | 'list' | 'listitem' | 'none' | 'presentation' | 'region';\n\n/**\n * Shared props for the grid components: every `div` attribute, with `role`\n * narrowed to {@link SafeLayoutRole}.\n */\nexport type GridBaseProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'role'> &\n\tDataQa & {\n\t\t/**\n\t\t * Structural role for the wrapper. Composite widget roles are not\n\t\t * accepted — see {@link SafeLayoutRole}.\n\t\t */\n\t\trole?: SafeLayoutRole;\n\t};\n"],"names":["GRID_SIZE_KEYS","GUTTER_CLASS","undefined"],"mappings":"AAEA;AACA;AACA;;AAIA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;;AA2CA;AACA;AACA;AACA;IACaA,cAAc,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK;;AAEzE;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,IAAMC,YAAqD,GAAG;AACpE,EAAA,CAAC,EAAE,qBAAqB;AACxB,EAAA,CAAC,EAAEC,SAAS;AACZ,EAAA,CAAC,EAAE;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MrlLiveRegion.js","sources":["../../../../../src/components/live-region/MrlLiveRegion/MrlLiveRegion.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport uniqueId from 'lodash.uniqueid';\nimport * as React from 'react';\nimport { useMemo, useState } from 'react';\n\
|
|
1
|
+
{"version":3,"file":"MrlLiveRegion.js","sources":["../../../../../src/components/live-region/MrlLiveRegion/MrlLiveRegion.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport uniqueId from 'lodash.uniqueid';\nimport * as React from 'react';\nimport { useMemo, useState } from 'react';\n\nexport type AriaRelevant = 'additions' | 'all' | 'removals' | 'text' | 'additions text' | undefined;\n\nexport interface MrlLiveRegionProps extends React.HTMLAttributes<HTMLParagraphElement> {\n\t/** Sets `aria-atomic`: announce the whole region on every change instead of only the changed part. */\n\tariaAtomic?: boolean;\n\t/** Sets `aria-live`: how urgently screen readers announce changes. */\n\tariaLive: 'polite' | 'assertive' | 'off';\n\t/** Sets `aria-relevant`: which kinds of change are announced. */\n\tariaRelevant?: AriaRelevant;\n\tid?: string;\n\t/** Empties the region one second after `srContent` changes. */\n\tshouldClearContent?: boolean;\n\t/** Text announced by the live region. */\n\tsrContent: string;\n\t/** Shows the text on screen. By default the region is visually hidden. */\n\tvisible?: boolean;\n}\n\n/**\n * Live region component to render an HTML live region with the provided content.\n *\n * @param props - The live region component props.\n * @returns The live region component.\n */\nexport const MrlLiveRegion = ({\n\tariaAtomic,\n\tariaLive,\n\tariaRelevant,\n\tid,\n\tsrContent,\n\tvisible = false,\n\tshouldClearContent = false,\n\t...props\n}: MrlLiveRegionProps): React.ReactElement => {\n\tconst [content, setContent] = useState('');\n\n\tReact.useEffect(() => {\n\t\tsetContent(srContent);\n\n\t\tif (shouldClearContent) {\n\t\t\tconst contentTimeout = setTimeout(() => {\n\t\t\t\tsetContent('');\n\t\t\t\tclearTimeout(contentTimeout);\n\t\t\t}, 1000);\n\n\t\t\treturn () => clearTimeout(contentTimeout);\n\t\t}\n\t}, [shouldClearContent, srContent]);\n\n\tconst nodeId = useMemo(() => id || uniqueId('live-region-'), [id]);\n\n\tconst dataQaProp = (props as { 'data-qa'?: string })['data-qa'];\n\tconst dataQa = dataQaProp || `${nodeId}-live-region`;\n\n\tconst classes = classNames('MrlLiveRegion', {\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\t'mrl-visually-hidden': !visible\n\t});\n\n\treturn (\n\t\t<p\n\t\t\t{...(ariaAtomic ? { 'aria-atomic': ariaAtomic } : {})}\n\t\t\taria-live={ariaLive}\n\t\t\t{...(ariaRelevant ? { 'aria-relevant': ariaRelevant } : {})}\n\t\t\tclassName={classes}\n\t\t\tdata-qa={dataQa}\n\t\t\tid={nodeId}\n\t\t\t{...props}\n\t\t>\n\t\t\t{content}\n\t\t</p>\n\t);\n};\n"],"names":["MrlLiveRegion","_ref","ariaAtomic","ariaLive","ariaRelevant","id","srContent","_ref$visible","visible","_ref$shouldClearConte","shouldClearContent","props","_objectWithoutProperties","_excluded","_useState","useState","_useState2","_slicedToArray","content","setContent","React","useEffect","contentTimeout","setTimeout","clearTimeout","nodeId","useMemo","uniqueId","dataQaProp","dataQa","concat","classes","classNames","createElement","_extends","className"],"mappings":";;;;;;;AAuBA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,aAAa,GAAGC,IAAA,IASiB;AAAA,EAAA,IAR7CC,UAAU,GAAAD,IAAA,CAAVC,UAAU;IACVC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IACRC,YAAY,GAAAH,IAAA,CAAZG,YAAY;IACZC,EAAE,GAAAJ,IAAA,CAAFI,EAAE;IACFC,SAAS,GAAAL,IAAA,CAATK,SAAS;IAAAC,YAAA,GAAAN,IAAA,CACTO,OAAO;AAAPA,IAAAA,OAAO,GAAAD,YAAA,KAAA,MAAA,GAAG,KAAK,GAAAA,YAAA;IAAAE,qBAAA,GAAAR,IAAA,CACfS,kBAAkB;AAAlBA,IAAAA,kBAAkB,GAAAD,qBAAA,KAAA,MAAA,GAAG,KAAK,GAAAA,qBAAA;AACvBE,IAAAA,KAA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