@cloudscape-design/components-themeable 3.0.1315 → 3.0.1316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/internal/generated/custom-css-properties/index.scss +1 -1
- package/lib/internal/scss/link/styles.scss +16 -0
- package/lib/internal/scss/side-navigation/styles.scss +221 -48
- package/lib/internal/scss/side-navigation/test-classes/styles.scss +4 -0
- package/lib/internal/scss/top-navigation/test-classes/styles.scss +8 -0
- package/lib/internal/template/file-token-group/file-token.d.ts.map +1 -1
- package/lib/internal/template/file-token-group/file-token.js +33 -27
- package/lib/internal/template/file-token-group/file-token.js.map +1 -1
- package/lib/internal/template/internal/base-component/styles.scoped.css +13 -1
- package/lib/internal/template/internal/breakpoints.d.ts +1 -1
- package/lib/internal/template/internal/breakpoints.d.ts.map +1 -1
- package/lib/internal/template/internal/breakpoints.js +25 -3
- package/lib/internal/template/internal/breakpoints.js.map +1 -1
- package/lib/internal/template/internal/environment.js +2 -2
- package/lib/internal/template/internal/environment.json +2 -2
- package/lib/internal/template/internal/generated/styles/tokens.d.ts +5 -0
- package/lib/internal/template/internal/generated/styles/tokens.js +5 -0
- package/lib/internal/template/internal/generated/theming/index.cjs +99 -0
- package/lib/internal/template/internal/generated/theming/index.cjs.d.ts +36 -0
- package/lib/internal/template/internal/generated/theming/index.d.ts +36 -0
- package/lib/internal/template/internal/generated/theming/index.js +99 -0
- package/lib/internal/template/internal/hooks/container-queries/use-container-breakpoints.d.ts.map +1 -1
- package/lib/internal/template/internal/hooks/container-queries/use-container-breakpoints.js +2 -1
- package/lib/internal/template/internal/hooks/container-queries/use-container-breakpoints.js.map +1 -1
- package/lib/internal/template/link/internal.js +1 -1
- package/lib/internal/template/link/internal.js.map +1 -1
- package/lib/internal/template/link/styles.css.js +21 -21
- package/lib/internal/template/link/styles.scoped.css +118 -72
- package/lib/internal/template/link/styles.selectors.js +21 -21
- package/lib/internal/template/prompt-input/index.d.ts.map +1 -1
- package/lib/internal/template/prompt-input/index.js +3 -1
- package/lib/internal/template/prompt-input/index.js.map +1 -1
- package/lib/internal/template/side-navigation/implementation.d.ts +1 -1
- package/lib/internal/template/side-navigation/implementation.d.ts.map +1 -1
- package/lib/internal/template/side-navigation/implementation.js +4 -4
- package/lib/internal/template/side-navigation/implementation.js.map +1 -1
- package/lib/internal/template/side-navigation/index.d.ts +1 -1
- package/lib/internal/template/side-navigation/index.d.ts.map +1 -1
- package/lib/internal/template/side-navigation/index.js +5 -3
- package/lib/internal/template/side-navigation/index.js.map +1 -1
- package/lib/internal/template/side-navigation/interfaces.d.ts +20 -1
- package/lib/internal/template/side-navigation/interfaces.d.ts.map +1 -1
- package/lib/internal/template/side-navigation/interfaces.js.map +1 -1
- package/lib/internal/template/side-navigation/parts.d.ts +3 -2
- package/lib/internal/template/side-navigation/parts.d.ts.map +1 -1
- package/lib/internal/template/side-navigation/parts.js +147 -37
- package/lib/internal/template/side-navigation/parts.js.map +1 -1
- package/lib/internal/template/side-navigation/styles.css.js +46 -30
- package/lib/internal/template/side-navigation/styles.scoped.css +223 -74
- package/lib/internal/template/side-navigation/styles.selectors.js +46 -30
- package/lib/internal/template/side-navigation/test-classes/styles.css.js +2 -1
- package/lib/internal/template/side-navigation/test-classes/styles.scoped.css +5 -1
- package/lib/internal/template/side-navigation/test-classes/styles.selectors.js +2 -1
- package/lib/internal/template/test-utils/dom/top-navigation/index.d.ts +2 -1
- package/lib/internal/template/test-utils/dom/top-navigation/index.js +4 -0
- package/lib/internal/template/test-utils/dom/top-navigation/index.js.map +1 -1
- package/lib/internal/template/test-utils/selectors/top-navigation/index.d.ts +1 -0
- package/lib/internal/template/test-utils/selectors/top-navigation/index.js +4 -0
- package/lib/internal/template/test-utils/selectors/top-navigation/index.js.map +1 -1
- package/lib/internal/template/token/internal.d.ts +18 -2
- package/lib/internal/template/token/internal.d.ts.map +1 -1
- package/lib/internal/template/token/internal.js +20 -9
- package/lib/internal/template/token/internal.js.map +1 -1
- package/lib/internal/template/top-navigation/index.d.ts +1 -1
- package/lib/internal/template/top-navigation/index.d.ts.map +1 -1
- package/lib/internal/template/top-navigation/index.js +2 -2
- package/lib/internal/template/top-navigation/index.js.map +1 -1
- package/lib/internal/template/top-navigation/interfaces.d.ts +14 -1
- package/lib/internal/template/top-navigation/interfaces.d.ts.map +1 -1
- package/lib/internal/template/top-navigation/interfaces.js.map +1 -1
- package/lib/internal/template/top-navigation/internal.d.ts +2 -2
- package/lib/internal/template/top-navigation/internal.d.ts.map +1 -1
- package/lib/internal/template/top-navigation/internal.js +42 -21
- package/lib/internal/template/top-navigation/internal.js.map +1 -1
- package/lib/internal/template/top-navigation/test-classes/styles.css.js +6 -0
- package/lib/internal/template/top-navigation/test-classes/styles.scoped.css +7 -0
- package/lib/internal/template/top-navigation/test-classes/styles.selectors.js +7 -0
- package/lib/internal/template/top-navigation/use-top-navigation.d.ts +5 -0
- package/lib/internal/template/top-navigation/use-top-navigation.d.ts.map +1 -1
- package/lib/internal/template/top-navigation/use-top-navigation.js +12 -5
- package/lib/internal/template/top-navigation/use-top-navigation.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
|
|
2
3
|
import { TokenProps } from './interfaces';
|
|
3
|
-
type InternalTokenProps = TokenProps & InternalBaseComponentProps & {
|
|
4
|
+
type InternalTokenProps = Omit<TokenProps, 'label'> & InternalBaseComponentProps & {
|
|
5
|
+
/** Token label. Required unless `__customContent` replaces the option layout entirely. */
|
|
6
|
+
label?: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* Overrides the default `role="group"` on the token root. Set to `"presentation"` when a
|
|
9
|
+
* parent element provides grouping semantics; this also strips ARIA attributes
|
|
10
|
+
* (aria-label, aria-labelledby, aria-disabled), focus/mouse handlers, and the tab stop so the
|
|
11
|
+
* token doesn't expose a redundant nested group to assistive tech.
|
|
12
|
+
*/
|
|
4
13
|
role?: string;
|
|
5
14
|
disableInnerPadding?: boolean;
|
|
15
|
+
/** Extra class on the token-box element */
|
|
16
|
+
__tokenBoxClassName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Renders content inside the token-box, replacing the standard option layout
|
|
19
|
+
* (label, labelTag, description, tags). The dismiss button is still rendered as a sibling.
|
|
20
|
+
*/
|
|
21
|
+
__customContent?: React.ReactNode;
|
|
6
22
|
};
|
|
7
|
-
declare function InternalToken({ label, ariaLabel, labelTag, description, variant, disabled, readOnly, icon, tags, dismissLabel, onDismiss, tooltipContent, role, disableInnerPadding, __internalRootRef, ...restProps }: InternalTokenProps): JSX.Element;
|
|
23
|
+
declare function InternalToken({ label, ariaLabel, labelTag, description, variant, disabled, readOnly, icon, tags, dismissLabel, onDismiss, tooltipContent, role, disableInnerPadding, __tokenBoxClassName, __customContent, __internalRootRef, ...restProps }: InternalTokenProps): JSX.Element;
|
|
8
24
|
export default InternalToken;
|
|
9
25
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/token/internal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/token/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAehD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAIlF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ1C,KAAK,kBAAkB,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GACjD,0BAA0B,GAAG;IAC3B,0FAA0F;IAC1F,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,2CAA2C;IAC3C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACnC,CAAC;AAEJ,iBAAS,aAAa,CAAC,EAErB,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,OAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,cAAc,EAGd,IAAI,EACJ,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EAGf,iBAAiB,EACjB,GAAG,SAAS,EACb,EAAE,kBAAkB,eAwJpB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -19,7 +19,7 @@ function InternalToken({
|
|
|
19
19
|
// External
|
|
20
20
|
label, ariaLabel, labelTag, description, variant = 'normal', disabled, readOnly, icon, tags, dismissLabel, onDismiss, tooltipContent,
|
|
21
21
|
// Internal
|
|
22
|
-
role, disableInnerPadding,
|
|
22
|
+
role, disableInnerPadding, __tokenBoxClassName, __customContent,
|
|
23
23
|
// Base
|
|
24
24
|
__internalRootRef, ...restProps }) {
|
|
25
25
|
const baseProps = getBaseProps(restProps);
|
|
@@ -30,6 +30,9 @@ __internalRootRef, ...restProps }) {
|
|
|
30
30
|
const [isEllipsisActive, setIsEllipsisActive] = useState(false);
|
|
31
31
|
const isInline = variant === 'inline';
|
|
32
32
|
const isOneTheme = isThemeActive(Theme.OneTheme);
|
|
33
|
+
// Consumers with their own grouping semantics can pass role="presentation" to treat the root
|
|
34
|
+
// as a pure styling wrapper (strips ARIA and focus/mouse handlers).
|
|
35
|
+
const isPresentation = role === 'presentation';
|
|
33
36
|
const ariaLabelledbyId = useUniqueId();
|
|
34
37
|
const isLabelOverflowing = () => {
|
|
35
38
|
const labelContent = labelRef.current;
|
|
@@ -77,17 +80,25 @@ __internalRootRef, ...restProps }) {
|
|
|
77
80
|
// Use span for inline tokens (e.g. inside contentEditable) to avoid block-level elements breaking text flow.
|
|
78
81
|
const SpanOrDivTag = isInline ? 'span' : 'div';
|
|
79
82
|
return (React.createElement(TokenInlineContext.Provider, { value: { isInlineToken: isInline } },
|
|
80
|
-
React.createElement(SpanOrDivTag, { ...baseProps, ref: __internalRootRef, className: clsx(styles.root, legacyTestingStyles.token, testUtilStyles.root, !isInline ? styles['token-normal'] : styles['token-inline'], analyticsSelectors.token, baseProps.className), "aria-label": ariaLabel, "aria-labelledby":
|
|
81
|
-
|
|
83
|
+
React.createElement(SpanOrDivTag, { ...baseProps, ref: __internalRootRef, className: clsx(styles.root, legacyTestingStyles.token, testUtilStyles.root, !isInline ? styles['token-normal'] : styles['token-inline'], analyticsSelectors.token, baseProps.className), "aria-label": isPresentation ? undefined : ariaLabel, "aria-labelledby": isPresentation || ariaLabel ? undefined : ariaLabelledbyId, "aria-disabled": isPresentation ? undefined : !!disabled, role: role !== null && role !== void 0 ? role : 'group', onFocus: () => {
|
|
84
|
+
if (!isPresentation) {
|
|
85
|
+
setShowTooltip(true);
|
|
86
|
+
}
|
|
82
87
|
}, onBlur: () => {
|
|
83
|
-
|
|
88
|
+
if (!isPresentation) {
|
|
89
|
+
setShowTooltip(false);
|
|
90
|
+
}
|
|
84
91
|
}, onMouseEnter: () => {
|
|
85
|
-
|
|
92
|
+
if (!isPresentation) {
|
|
93
|
+
setShowTooltip(true);
|
|
94
|
+
}
|
|
86
95
|
}, onMouseLeave: () => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
if (!isPresentation) {
|
|
97
|
+
setShowTooltip(false);
|
|
98
|
+
}
|
|
99
|
+
}, tabIndex: !isPresentation && !!tooltipContent && isInline && isEllipsisActive ? 0 : undefined },
|
|
100
|
+
React.createElement(SpanOrDivTag, { className: clsx(!isInline ? styles['token-box'] : styles['token-box-inline'], disabled && styles['token-box-disabled'], readOnly && styles['token-box-readonly'], !isInline && !onDismiss && !__customContent && styles['token-box-without-dismiss'], disableInnerPadding && styles['disable-padding'], __tokenBoxClassName), style: tokenRootStyleProps },
|
|
101
|
+
React.createElement(Option, { className: clsx(isInline && styles['token-option-inline']), triggerVariant: isInline, option: buildOptionDefinition(), disableTitleTooltip: !!tooltipContent, labelContainerRef: labelContainerRef, labelRef: labelRef, labelId: ariaLabelledbyId, customContent: __customContent }),
|
|
91
102
|
onDismiss && (React.createElement(DismissButton, { disabled: disabled, dismissLabel: dismissLabel, onDismiss: onDismiss, readOnly: readOnly, inline: isInline }))),
|
|
92
103
|
!!tooltipContent && isInline && isEllipsisActive && showTooltip && (React.createElement(Tooltip, { "data-testid": "token-tooltip", getTrack: () => labelContainerRef.current, content: React.createElement(LiveRegion, null,
|
|
93
104
|
React.createElement("span", { "data-testid": "tooltip-live-region-content" }, tooltipContent)), onEscape: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/token/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,QAAQ,GACT,MAAM,+CAA+C,CAAC;AAEvD,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,mBAAmB,MAAM,8BAA8B,CAAC;AAC/D,OAAO,kBAAkB,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,aAAa,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport {\n isThemeActive,\n Theme,\n useResizeObserver,\n useUniqueId,\n warnOnce,\n} from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalIcon from '../icon/internal';\nimport { getBaseProps } from '../internal/base-component';\nimport Option from '../internal/components/option';\nimport { TokenInlineContext } from '../internal/context/token-inline-context';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport LiveRegion from '../live-region/internal';\nimport Tooltip from '../tooltip/internal.js';\nimport DismissButton from './dismiss-button';\nimport { TokenProps } from './interfaces';\nimport { getTokenRootStyles } from './styles';\n\nimport legacyTestingStyles from '../token-group/styles.css.js';\nimport analyticsSelectors from './analytics-metadata/styles.css.js';\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\ntype InternalTokenProps = TokenProps &\n InternalBaseComponentProps & {\n role?: string;\n disableInnerPadding?: boolean;\n };\n\nfunction InternalToken({\n // External\n label,\n ariaLabel,\n labelTag,\n description,\n variant = 'normal',\n disabled,\n readOnly,\n icon,\n tags,\n dismissLabel,\n onDismiss,\n tooltipContent,\n\n // Internal\n role,\n disableInnerPadding,\n\n // Base\n __internalRootRef,\n ...restProps\n}: InternalTokenProps) {\n const baseProps = getBaseProps(restProps);\n const tokenRootStyleProps = getTokenRootStyles(restProps.style);\n const labelContainerRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n const [isEllipsisActive, setIsEllipsisActive] = useState(false);\n const isInline = variant === 'inline';\n const isOneTheme = isThemeActive(Theme.OneTheme);\n const ariaLabelledbyId = useUniqueId();\n\n const isLabelOverflowing = () => {\n const labelContent = labelRef.current;\n const labelContainer = labelContainerRef.current;\n\n if (labelContent && labelContainer) {\n return labelContent.offsetWidth > labelContainer.offsetWidth;\n }\n };\n\n useResizeObserver(labelContainerRef, () => {\n if (isInline) {\n setIsEllipsisActive(isLabelOverflowing() ?? false);\n }\n });\n\n const sizedIcon = (iconNode: React.ReactNode) => {\n if (isInline && isOneTheme && React.isValidElement(iconNode) && iconNode.type === InternalIcon) {\n return React.cloneElement(iconNode, { size: 'x-small' });\n }\n return iconNode;\n };\n\n const buildOptionDefinition = () => {\n const isLabelStringOrNumber = typeof label === 'string' || typeof label === 'number';\n const labelObject = isLabelStringOrNumber ? { label: String(label) } : { labelContent: label };\n\n if (isInline) {\n if (!isLabelStringOrNumber) {\n warnOnce('Label', `Only plain text (strings or numbers) are supported when variant=\"inline\".`);\n }\n\n return {\n ...labelObject,\n disabled,\n __customIcon: icon && <span className={clsx(styles.icon, styles['icon-inline'])}>{sizedIcon(icon)}</span>,\n };\n } else {\n return {\n ...labelObject,\n disabled,\n labelTag,\n description,\n tags,\n __customIcon: icon && <span className={styles.icon}>{sizedIcon(icon)}</span>,\n };\n }\n };\n\n // Use span for inline tokens (e.g. inside contentEditable) to avoid block-level elements breaking text flow.\n const SpanOrDivTag = isInline ? 'span' : 'div';\n\n return (\n <TokenInlineContext.Provider value={{ isInlineToken: isInline }}>\n <SpanOrDivTag\n {...baseProps}\n ref={__internalRootRef}\n className={clsx(\n styles.root,\n legacyTestingStyles.token,\n testUtilStyles.root,\n !isInline ? styles['token-normal'] : styles['token-inline'],\n analyticsSelectors.token,\n baseProps.className\n )}\n aria-label={ariaLabel}\n aria-labelledby={!ariaLabel ? ariaLabelledbyId : undefined}\n aria-disabled={!!disabled}\n role={role ?? 'group'}\n onFocus={() => {\n setShowTooltip(true);\n }}\n onBlur={() => {\n setShowTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n }}\n tabIndex={!!tooltipContent && isInline && isEllipsisActive ? 0 : undefined}\n >\n <SpanOrDivTag\n className={clsx(\n !isInline ? styles['token-box'] : styles['token-box-inline'],\n disabled && styles['token-box-disabled'],\n readOnly && styles['token-box-readonly'],\n !isInline && !onDismiss && styles['token-box-without-dismiss'],\n disableInnerPadding && styles['disable-padding']\n )}\n style={tokenRootStyleProps}\n >\n <Option\n className={clsx(isInline && styles['token-option-inline'])}\n triggerVariant={isInline}\n option={buildOptionDefinition()}\n disableTitleTooltip={!!tooltipContent}\n labelContainerRef={labelContainerRef}\n labelRef={labelRef}\n labelId={ariaLabelledbyId}\n />\n {onDismiss && (\n <DismissButton\n disabled={disabled}\n dismissLabel={dismissLabel}\n onDismiss={onDismiss}\n readOnly={readOnly}\n inline={isInline}\n />\n )}\n </SpanOrDivTag>\n {!!tooltipContent && isInline && isEllipsisActive && showTooltip && (\n <Tooltip\n data-testid=\"token-tooltip\"\n getTrack={() => labelContainerRef.current}\n content={\n <LiveRegion>\n <span data-testid=\"tooltip-live-region-content\">{tooltipContent}</span>\n </LiveRegion>\n }\n onEscape={() => {\n setShowTooltip(false);\n }}\n />\n )}\n </SpanOrDivTag>\n </TokenInlineContext.Provider>\n );\n}\n\nexport default InternalToken;\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/token/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,QAAQ,GACT,MAAM,+CAA+C,CAAC;AAEvD,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAA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C,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,eAAe,GAC9B;gBACD,SAAS,IAAI,CACZ,oBAAC,aAAa,IACZ,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,QAAQ,GAChB,CACH,CACY;YACd,CAAC,CAAC,cAAc,IAAI,QAAQ,IAAI,gBAAgB,IAAI,WAAW,IAAI,CAClE,oBAAC,OAAO,mBACM,eAAe,EAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,EACzC,OAAO,EACL,oBAAC,UAAU;oBACT,6CAAkB,6BAA6B,IAAE,cAAc,CAAQ,CAC5D,EAEf,QAAQ,EAAE,GAAG,EAAE;oBACb,cAAc,CAAC,KAAK,CAAC,CAAC;gBACxB,CAAC,GACD,CACH,CACY,CACa,CAC/B,CAAC;AACJ,CAAC;AAED,eAAe,aAAa,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport {\n isThemeActive,\n Theme,\n useResizeObserver,\n useUniqueId,\n warnOnce,\n} from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalIcon from '../icon/internal';\nimport { getBaseProps } from '../internal/base-component';\nimport Option from '../internal/components/option';\nimport { TokenInlineContext } from '../internal/context/token-inline-context';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport LiveRegion from '../live-region/internal';\nimport Tooltip from '../tooltip/internal.js';\nimport DismissButton from './dismiss-button';\nimport { TokenProps } from './interfaces';\nimport { getTokenRootStyles } from './styles';\n\nimport legacyTestingStyles from '../token-group/styles.css.js';\nimport analyticsSelectors from './analytics-metadata/styles.css.js';\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\ntype InternalTokenProps = Omit<TokenProps, 'label'> &\n InternalBaseComponentProps & {\n /** Token label. Required unless `__customContent` replaces the option layout entirely. */\n label?: React.ReactNode;\n /**\n * Overrides the default `role=\"group\"` on the token root. Set to `\"presentation\"` when a\n * parent element provides grouping semantics; this also strips ARIA attributes\n * (aria-label, aria-labelledby, aria-disabled), focus/mouse handlers, and the tab stop so the\n * token doesn't expose a redundant nested group to assistive tech.\n */\n role?: string;\n disableInnerPadding?: boolean;\n /** Extra class on the token-box element */\n __tokenBoxClassName?: string;\n /**\n * Renders content inside the token-box, replacing the standard option layout\n * (label, labelTag, description, tags). The dismiss button is still rendered as a sibling.\n */\n __customContent?: React.ReactNode;\n };\n\nfunction InternalToken({\n // External\n label,\n ariaLabel,\n labelTag,\n description,\n variant = 'normal',\n disabled,\n readOnly,\n icon,\n tags,\n dismissLabel,\n onDismiss,\n tooltipContent,\n\n // Internal\n role,\n disableInnerPadding,\n __tokenBoxClassName,\n __customContent,\n\n // Base\n __internalRootRef,\n ...restProps\n}: InternalTokenProps) {\n const baseProps = getBaseProps(restProps);\n const tokenRootStyleProps = getTokenRootStyles(restProps.style);\n const labelContainerRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n const [isEllipsisActive, setIsEllipsisActive] = useState(false);\n const isInline = variant === 'inline';\n const isOneTheme = isThemeActive(Theme.OneTheme);\n // Consumers with their own grouping semantics can pass role=\"presentation\" to treat the root\n // as a pure styling wrapper (strips ARIA and focus/mouse handlers).\n const isPresentation = role === 'presentation';\n const ariaLabelledbyId = useUniqueId();\n\n const isLabelOverflowing = () => {\n const labelContent = labelRef.current;\n const labelContainer = labelContainerRef.current;\n\n if (labelContent && labelContainer) {\n return labelContent.offsetWidth > labelContainer.offsetWidth;\n }\n };\n\n useResizeObserver(labelContainerRef, () => {\n if (isInline) {\n setIsEllipsisActive(isLabelOverflowing() ?? false);\n }\n });\n\n const sizedIcon = (iconNode: React.ReactNode) => {\n if (isInline && isOneTheme && React.isValidElement(iconNode) && iconNode.type === InternalIcon) {\n return React.cloneElement(iconNode, { size: 'x-small' });\n }\n return iconNode;\n };\n\n const buildOptionDefinition = () => {\n const isLabelStringOrNumber = typeof label === 'string' || typeof label === 'number';\n const labelObject = isLabelStringOrNumber ? { label: String(label) } : { labelContent: label };\n\n if (isInline) {\n if (!isLabelStringOrNumber) {\n warnOnce('Label', `Only plain text (strings or numbers) are supported when variant=\"inline\".`);\n }\n\n return {\n ...labelObject,\n disabled,\n __customIcon: icon && <span className={clsx(styles.icon, styles['icon-inline'])}>{sizedIcon(icon)}</span>,\n };\n } else {\n return {\n ...labelObject,\n disabled,\n labelTag,\n description,\n tags,\n __customIcon: icon && <span className={styles.icon}>{sizedIcon(icon)}</span>,\n };\n }\n };\n\n // Use span for inline tokens (e.g. inside contentEditable) to avoid block-level elements breaking text flow.\n const SpanOrDivTag = isInline ? 'span' : 'div';\n\n return (\n <TokenInlineContext.Provider value={{ isInlineToken: isInline }}>\n <SpanOrDivTag\n {...baseProps}\n ref={__internalRootRef}\n className={clsx(\n styles.root,\n legacyTestingStyles.token,\n testUtilStyles.root,\n !isInline ? styles['token-normal'] : styles['token-inline'],\n analyticsSelectors.token,\n baseProps.className\n )}\n aria-label={isPresentation ? undefined : ariaLabel}\n aria-labelledby={isPresentation || ariaLabel ? undefined : ariaLabelledbyId}\n aria-disabled={isPresentation ? undefined : !!disabled}\n role={role ?? 'group'}\n onFocus={() => {\n if (!isPresentation) {\n setShowTooltip(true);\n }\n }}\n onBlur={() => {\n if (!isPresentation) {\n setShowTooltip(false);\n }\n }}\n onMouseEnter={() => {\n if (!isPresentation) {\n setShowTooltip(true);\n }\n }}\n onMouseLeave={() => {\n if (!isPresentation) {\n setShowTooltip(false);\n }\n }}\n tabIndex={!isPresentation && !!tooltipContent && isInline && isEllipsisActive ? 0 : undefined}\n >\n <SpanOrDivTag\n className={clsx(\n !isInline ? styles['token-box'] : styles['token-box-inline'],\n disabled && styles['token-box-disabled'],\n readOnly && styles['token-box-readonly'],\n !isInline && !onDismiss && !__customContent && styles['token-box-without-dismiss'],\n disableInnerPadding && styles['disable-padding'],\n __tokenBoxClassName\n )}\n style={tokenRootStyleProps}\n >\n <Option\n className={clsx(isInline && styles['token-option-inline'])}\n triggerVariant={isInline}\n option={buildOptionDefinition()}\n disableTitleTooltip={!!tooltipContent}\n labelContainerRef={labelContainerRef}\n labelRef={labelRef}\n labelId={ariaLabelledbyId}\n customContent={__customContent}\n />\n {onDismiss && (\n <DismissButton\n disabled={disabled}\n dismissLabel={dismissLabel}\n onDismiss={onDismiss}\n readOnly={readOnly}\n inline={isInline}\n />\n )}\n </SpanOrDivTag>\n {!!tooltipContent && isInline && isEllipsisActive && showTooltip && (\n <Tooltip\n data-testid=\"token-tooltip\"\n getTrack={() => labelContainerRef.current}\n content={\n <LiveRegion>\n <span data-testid=\"tooltip-live-region-content\">{tooltipContent}</span>\n </LiveRegion>\n }\n onEscape={() => {\n setShowTooltip(false);\n }}\n />\n )}\n </SpanOrDivTag>\n </TokenInlineContext.Provider>\n );\n}\n\nexport default InternalToken;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TopNavigationProps } from './interfaces';
|
|
2
2
|
export { TopNavigationProps };
|
|
3
|
-
export default function TopNavigation({ utilities, ...restProps }: TopNavigationProps): JSX.Element;
|
|
3
|
+
export default function TopNavigation({ utilities, visualContext, ...restProps }: TopNavigationProps): JSX.Element;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,SAAc,EACd,aAAgC,EAChC,GAAG,SAAS,EACb,EAAE,kBAAkB,eAKpB"}
|
|
@@ -5,9 +5,9 @@ import React from 'react';
|
|
|
5
5
|
import useBaseComponent from '../internal/hooks/use-base-component';
|
|
6
6
|
import { applyDisplayName } from '../internal/utils/apply-display-name';
|
|
7
7
|
import InternalTopNavigation from './internal';
|
|
8
|
-
export default function TopNavigation({ utilities = [], ...restProps }) {
|
|
8
|
+
export default function TopNavigation({ utilities = [], visualContext = 'top-navigation', ...restProps }) {
|
|
9
9
|
const baseComponentProps = useBaseComponent('TopNavigation');
|
|
10
|
-
return React.createElement(InternalTopNavigation, { ...baseComponentProps, utilities: utilities, ...restProps });
|
|
10
|
+
return (React.createElement(InternalTopNavigation, { ...baseComponentProps, utilities: utilities, visualContext: visualContext, ...restProps }));
|
|
11
11
|
}
|
|
12
12
|
applyDisplayName(TopNavigation, 'TopNavigation');
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/top-navigation/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,YAAY,CAAC;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,qBAAqB,MAAM,YAAY,CAAC;AAI/C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/top-navigation/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,YAAY,CAAC;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,qBAAqB,MAAM,YAAY,CAAC;AAI/C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,SAAS,GAAG,EAAE,EACd,aAAa,GAAG,gBAAgB,EAChC,GAAG,SAAS,EACO;IACnB,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC7D,OAAO,CACL,oBAAC,qBAAqB,OAAK,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,KAAM,SAAS,GAAI,CACrH,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n'use client';\nimport React from 'react';\n\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { TopNavigationProps } from './interfaces';\nimport InternalTopNavigation from './internal';\n\nexport { TopNavigationProps };\n\nexport default function TopNavigation({\n utilities = [],\n visualContext = 'top-navigation',\n ...restProps\n}: TopNavigationProps) {\n const baseComponentProps = useBaseComponent('TopNavigation');\n return (\n <InternalTopNavigation {...baseComponentProps} utilities={utilities} visualContext={visualContext} {...restProps} />\n );\n}\n\napplyDisplayName(TopNavigation, 'TopNavigation');\n"]}
|
|
@@ -12,7 +12,19 @@ export interface TopNavigationProps extends BaseComponentProps {
|
|
|
12
12
|
* * `href` (string) - Specifies the `href` that the header links to.
|
|
13
13
|
* * `onFollow` (() => void) - Specifies the event handler called when the identity is clicked without any modifier keys.
|
|
14
14
|
*/
|
|
15
|
-
identity
|
|
15
|
+
identity?: TopNavigationProps.Identity;
|
|
16
|
+
/**
|
|
17
|
+
* Specifies custom navigation content.
|
|
18
|
+
* When provided, replaces all structured content (identity, search, utilities are ignored).
|
|
19
|
+
* @displayname customContent
|
|
20
|
+
*/
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Visual context applied to the navigation bar.
|
|
24
|
+
* - "top-navigation": Applies the top-navigation visual context. The component maintains a dark appearance regardless of the page's light/dark mode setting. Child components automatically adapt their colors to work on this dark background.
|
|
25
|
+
* - "none": No visual context applied. The component and its children use the same colors as the rest of the page and respond to the global light/dark mode normally.
|
|
26
|
+
*/
|
|
27
|
+
visualContext?: TopNavigationProps.VisualContext;
|
|
16
28
|
/**
|
|
17
29
|
* Use with an input or autosuggest control for a global search query.
|
|
18
30
|
*/
|
|
@@ -112,6 +124,7 @@ export declare namespace TopNavigationProps {
|
|
|
112
124
|
overflowMenuTriggerText?: string;
|
|
113
125
|
overflowMenuTitleText?: string;
|
|
114
126
|
}
|
|
127
|
+
export type VisualContext = 'top-navigation' | 'none';
|
|
115
128
|
export {};
|
|
116
129
|
}
|
|
117
130
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D;;;;;;;OAOG;IACH,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;
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AAE,MAAM,CAAC;QACpC,gCAAgC,CAAC,EAAE,MAAM,CAAC;QAC1C,6BAA6B,CAAC,EAAE,MAAM,CAAC;QACvC,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC;IAED,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,MAAM,CAAC;;CACvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/top-navigation/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonProps } from '../button/interfaces';\nimport { ButtonDropdownProps } from '../button-dropdown/interfaces';\nimport { IconProps } from '../icon/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { CancelableEventHandler } from '../internal/events';\n\nexport interface TopNavigationProps extends BaseComponentProps {\n /**\n * Properties describing the product identity. They are as follows:\n *\n * * `title` (string) - Specifies the title text.\n * * `logo` ({ src: string, alt: string }) - Specifies the logo for the product. Use fixed width and height for SVG images to ensure proper rendering.\n * * `href` (string) - Specifies the `href` that the header links to.\n * * `onFollow` (() => void) - Specifies the event handler called when the identity is clicked without any modifier keys.\n */\n identity
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/top-navigation/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonProps } from '../button/interfaces';\nimport { ButtonDropdownProps } from '../button-dropdown/interfaces';\nimport { IconProps } from '../icon/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { CancelableEventHandler } from '../internal/events';\n\nexport interface TopNavigationProps extends BaseComponentProps {\n /**\n * Properties describing the product identity. They are as follows:\n *\n * * `title` (string) - Specifies the title text.\n * * `logo` ({ src: string, alt: string }) - Specifies the logo for the product. Use fixed width and height for SVG images to ensure proper rendering.\n * * `href` (string) - Specifies the `href` that the header links to.\n * * `onFollow` (() => void) - Specifies the event handler called when the identity is clicked without any modifier keys.\n */\n identity?: TopNavigationProps.Identity;\n\n /**\n * Specifies custom navigation content.\n * When provided, replaces all structured content (identity, search, utilities are ignored).\n * @displayname customContent\n */\n children?: React.ReactNode;\n\n /**\n * Visual context applied to the navigation bar.\n * - \"top-navigation\": Applies the top-navigation visual context. The component maintains a dark appearance regardless of the page's light/dark mode setting. Child components automatically adapt their colors to work on this dark background.\n * - \"none\": No visual context applied. The component and its children use the same colors as the rest of the page and respond to the global light/dark mode normally.\n */\n visualContext?: TopNavigationProps.VisualContext;\n\n /**\n * Use with an input or autosuggest control for a global search query.\n */\n search?: React.ReactNode;\n\n /**\n * A list of utility navigation elements.\n * The supported utility types are: `button` and `menu-dropdown`.\n *\n * The following properties are supported across all utility types:\n *\n * * `type` (string) - The type of the utility. Can be `button` or `menu-dropdown`.\n * * `text` (string) - Specifies the text shown in the top navigation or the title inside the dropdown if no explicit `title` property is set.\n * * `title` (string) - The title displayed inside the dropdown.\n * * `iconName` (string) - The name of an existing icon to display next to the utility.\n * * `iconUrl` (string) - Specifies the URL of a custom icon. Use this property if the icon you want isn't available.\n * * `iconAlt` (string) - Specifies alternate text for a custom icon provided using `iconUrl`. We recommend that you provide this for accessibility.\n * * `iconSvg` (string) - Specifies the SVG of a custom icon.\n * * `ariaLabel` (string) - Adds `aria-label` to the button or dropdown trigger. This is recommended for accessibility if a text is not provided.\n * * `badge` (boolean) - Adds a badge to the corner of the icon to indicate a state change. For example: Unread notifications.\n * * `disableTextCollapse` (boolean) - Prevents the utility text from being hidden on smaller screens.\n * * `disableUtilityCollapse` (boolean) - Prevents the utility from being moved to an overflow menu on smaller screens.\n *\n * ### button\n *\n * * `variant` ('primary-button' | 'link') - The visual appearance of the button. The default value is 'link'.\n * * `href` (string) - Specifies the `href` for a link styled as a button.\n * * `target` (string) - Specifies where to open the linked URL (for example, to open in a new browser window or tab use `_blank`). This property only applies when an `href` is provided.\n * * `rel` (string) - Adds a `rel` attribute to the link. By default, the component sets the `rel` attribute to \"noopener noreferrer\" when `target` is `\"_blank\"`. If the `rel` property is provided, it overrides the default behavior.\n * * `external` (boolean) - Marks the link as external by adding an icon after the text. When clicked, the link opens in a new tab.\n * * `externalIconAriaLabel` (string) - Adds an `aria-label` for the external icon.\n * * `onClick` (() => void) - Specifies the event handler called when the utility is clicked.\n * * `onFollow` (() => void) - Specifies the event handler called when the utility is clicked without pressing modifier keys, and the utility has an `href` set.\n *\n * ### menu-dropdown\n *\n * * `description` (string) - The description displayed inside the dropdown.\n * * `items` (ButtonDropdownProps.Items) - An array of dropdown items. This follows the same structure as the `items` property of the [button dropdown component](/components/button-dropdown).\n * * `onItemClick` (NonCancelableEventHandler<ButtonDropdownProps.ItemClickDetails>) - Specifies the event handler called when a dropdown item is selected.\n * * `onItemFollow` (NonCancelableEventHandler<ButtonDropdownProps.ItemClickDetails>) - Specifies the event handler called when a dropdown item is selected without pressing modifier keys, and the item has an `href` set.\n * * `expandableGroups` (boolean) - Controls expandability of the item groups.\n */\n utilities?: ReadonlyArray<TopNavigationProps.Utility>;\n\n /**\n * An object containing all the localized strings required by the component.\n * @i18n\n */\n i18nStrings?: TopNavigationProps.I18nStrings;\n}\n\nexport namespace TopNavigationProps {\n export interface Identity {\n title?: string;\n logo?: Logo;\n href: string;\n onFollow?: CancelableEventHandler;\n }\n\n export interface Logo {\n src: string;\n alt?: string;\n }\n\n interface BaseUtility {\n text?: string;\n title?: string;\n iconName?: IconProps.Name;\n iconUrl?: string;\n iconAlt?: string;\n iconSvg?: React.ReactNode;\n ariaLabel?: string;\n\n badge?: boolean;\n disableUtilityCollapse?: boolean;\n disableTextCollapse?: boolean;\n }\n\n export interface MenuDropdownUtility extends BaseUtility {\n type: 'menu-dropdown';\n description?: string;\n items: ButtonDropdownProps.Items;\n expandableGroups?: boolean;\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n }\n\n export interface ButtonUtility extends BaseUtility {\n type: 'button';\n variant?: 'primary-button' | 'link';\n onClick?: CancelableEventHandler;\n onFollow?: CancelableEventHandler<ButtonProps.FollowDetail>;\n href?: string;\n target?: string;\n rel?: string;\n external?: boolean;\n externalIconAriaLabel?: string;\n }\n\n export type Utility = MenuDropdownUtility | ButtonUtility;\n\n export interface I18nStrings {\n searchIconAriaLabel?: string;\n searchDismissIconAriaLabel?: string;\n overflowMenuDismissIconAriaLabel?: string;\n overflowMenuBackIconAriaLabel?: string;\n overflowMenuTriggerText?: string;\n overflowMenuTitleText?: string;\n }\n\n export type VisualContext = 'top-navigation' | 'none';\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
|
|
2
2
|
import { SomeRequired } from '../internal/types';
|
|
3
3
|
import { TopNavigationProps } from './interfaces';
|
|
4
|
-
type InternalTopNavigationProps = SomeRequired<TopNavigationProps, 'utilities'> & InternalBaseComponentProps;
|
|
5
|
-
export default function InternalTopNavigation({ __internalRootRef,
|
|
4
|
+
type InternalTopNavigationProps = SomeRequired<TopNavigationProps, 'utilities' | 'visualContext'> & InternalBaseComponentProps;
|
|
5
|
+
export default function InternalTopNavigation({ __internalRootRef, children, visualContext, ...restProps }: InternalTopNavigationProps): JSX.Element;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/internal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/internal.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAElF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAQlD,KAAK,0BAA0B,GAAG,YAAY,CAAC,kBAAkB,EAAE,WAAW,GAAG,eAAe,CAAC,GAC/F,0BAA0B,CAAC;AAM7B,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAC5C,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,GAAG,SAAS,EACb,EAAE,0BAA0B,eAU5B"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import React, { useEffect, useRef, useState } from 'react';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
+
import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
|
|
5
6
|
import { useInternalI18n } from '../i18n/context';
|
|
6
7
|
import { getBaseProps } from '../internal/base-component';
|
|
7
8
|
import { ButtonTrigger } from '../internal/components/menu-dropdown';
|
|
@@ -13,8 +14,29 @@ import OverflowMenu from './parts/overflow-menu';
|
|
|
13
14
|
import Utility from './parts/utility';
|
|
14
15
|
import { useTopNavigation } from './use-top-navigation.js';
|
|
15
16
|
import styles from './styles.css.js';
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
import testUtilStyles from './test-classes/styles.css.js';
|
|
18
|
+
function wrapWithVisualContext(content, visualContext) {
|
|
19
|
+
return visualContext === 'none' ? content : React.createElement(VisualContext, { contextName: visualContext }, content);
|
|
20
|
+
}
|
|
21
|
+
export default function InternalTopNavigation({ __internalRootRef, children, visualContext, ...restProps }) {
|
|
22
|
+
if (children !== undefined) {
|
|
23
|
+
return (React.createElement(CustomContentTopNavigation, { __internalRootRef: __internalRootRef, visualContext: visualContext, ...restProps }, children));
|
|
24
|
+
}
|
|
25
|
+
return React.createElement(StructuredTopNavigation, { __internalRootRef: __internalRootRef, visualContext: visualContext, ...restProps });
|
|
26
|
+
}
|
|
27
|
+
function CustomContentTopNavigation({ __internalRootRef, children, visualContext, ...restProps }) {
|
|
28
|
+
const baseProps = getBaseProps(restProps);
|
|
29
|
+
const { identity, search, utilities } = restProps;
|
|
30
|
+
if (identity || search || (utilities && utilities.length > 0)) {
|
|
31
|
+
warnOnce('TopNavigation', 'When children is set, the structured props (identity, search, and utilities) are ignored');
|
|
32
|
+
}
|
|
33
|
+
return (React.createElement("div", { ...baseProps, ref: __internalRootRef }, wrapWithVisualContext(React.createElement("header", { className: styles['top-navigation'] },
|
|
34
|
+
React.createElement("div", { className: testUtilStyles['custom-content'] }, children)), visualContext)));
|
|
35
|
+
}
|
|
36
|
+
function StructuredTopNavigation({ __internalRootRef, identity, i18nStrings, utilities, search, visualContext, ...restProps }) {
|
|
37
|
+
if (identity) {
|
|
38
|
+
checkSafeUrl('TopNavigation', identity.href);
|
|
39
|
+
}
|
|
18
40
|
const baseProps = getBaseProps(restProps);
|
|
19
41
|
const { mainRef, virtualRef, breakpoint, responsiveState, isSearchExpanded, onSearchUtilityClick } = useTopNavigation({ identity, search, utilities });
|
|
20
42
|
const [overflowMenuOpen, setOverflowMenuOpen] = useState(false);
|
|
@@ -23,14 +45,6 @@ export default function InternalTopNavigation({ __internalRootRef, identity, i18
|
|
|
23
45
|
const isMediumViewport = breakpoint === 'xxs';
|
|
24
46
|
const isLargeViewport = breakpoint === 's';
|
|
25
47
|
const i18n = useInternalI18n('top-navigation');
|
|
26
|
-
const onIdentityClick = (event) => {
|
|
27
|
-
if (isPlainLeftClick(event)) {
|
|
28
|
-
fireCancelableEvent(identity.onFollow, {}, event);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const toggleOverflowMenu = () => {
|
|
32
|
-
setOverflowMenuOpen(overflowMenuOpen => !overflowMenuOpen);
|
|
33
|
-
};
|
|
34
48
|
const menuTriggerVisible = !isSearchExpanded && responsiveState.hideUtilities;
|
|
35
49
|
useEffect(() => {
|
|
36
50
|
setOverflowMenuOpen(false);
|
|
@@ -41,13 +55,20 @@ export default function InternalTopNavigation({ __internalRootRef, identity, i18
|
|
|
41
55
|
(_a = overflowMenuTriggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
42
56
|
}
|
|
43
57
|
}, [overflowMenuOpen]);
|
|
58
|
+
const onIdentityClick = (event) => {
|
|
59
|
+
if (isPlainLeftClick(event)) {
|
|
60
|
+
fireCancelableEvent(identity === null || identity === void 0 ? void 0 : identity.onFollow, {}, event);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const toggleOverflowMenu = () => {
|
|
64
|
+
setOverflowMenuOpen(overflowMenuOpen => !overflowMenuOpen);
|
|
65
|
+
};
|
|
44
66
|
// Render the top nav twice; once as the top nav that users can see, and another
|
|
45
67
|
// "virtual" top nav used just for calculations. The virtual top nav doesn't react to
|
|
46
68
|
// layout changes and renders two sets of utilities: one with labels and one without.
|
|
47
69
|
const content = (isVirtual) => {
|
|
48
|
-
var _a, _b;
|
|
49
70
|
const Wrapper = isVirtual ? 'div' : 'header';
|
|
50
|
-
const showIdentity = isVirtual || !isSearchExpanded;
|
|
71
|
+
const showIdentity = !!identity && (isVirtual || !isSearchExpanded);
|
|
51
72
|
const showTitle = isVirtual || !responsiveState.hideTitle;
|
|
52
73
|
const showSearchSlot = search && (isVirtual || !responsiveState.hideSearch || isSearchExpanded);
|
|
53
74
|
const showSearchUtility = isVirtual || (search && responsiveState.hideSearch);
|
|
@@ -60,9 +81,9 @@ export default function InternalTopNavigation({ __internalRootRef, identity, i18
|
|
|
60
81
|
[styles.medium]: isMediumViewport,
|
|
61
82
|
}) },
|
|
62
83
|
React.createElement("div", { className: styles['padding-box'] },
|
|
63
|
-
showIdentity && (React.createElement("div", { className: clsx(styles.identity, !identity.logo && styles['no-logo']) },
|
|
84
|
+
showIdentity && identity && (React.createElement("div", { className: clsx(styles.identity, !identity.logo && styles['no-logo']) },
|
|
64
85
|
React.createElement("a", { className: styles['identity-link'], href: identity.href, onClick: onIdentityClick },
|
|
65
|
-
identity.logo && (React.createElement("img", { role: "img", src:
|
|
86
|
+
identity.logo && (React.createElement("img", { role: "img", src: identity.logo.src, alt: identity.logo.alt, className: clsx(styles.logo, {
|
|
66
87
|
[styles.narrow]: isNarrowViewport,
|
|
67
88
|
}) })),
|
|
68
89
|
showTitle && React.createElement("span", { className: styles.title }, identity.title)))),
|
|
@@ -113,12 +134,12 @@ export default function InternalTopNavigation({ __internalRootRef, identity, i18
|
|
|
113
134
|
}), "data-utility-special": "menu-trigger" },
|
|
114
135
|
React.createElement(ButtonTrigger, { expanded: overflowMenuOpen, onClick: toggleOverflowMenu, offsetRight: "l", ref: !isVirtual ? overflowMenuTriggerRef : undefined }, i18n('i18nStrings.overflowMenuTriggerText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.overflowMenuTriggerText))))))));
|
|
115
136
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
137
|
+
const structuredContent = (React.createElement(React.Fragment, null,
|
|
138
|
+
content(true),
|
|
139
|
+
content(false),
|
|
140
|
+
menuTriggerVisible && overflowMenuOpen && (React.createElement("div", { className: styles['overflow-menu-drawer'] },
|
|
141
|
+
React.createElement(OverflowMenu, { headerText: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.overflowMenuTitleText, dismissIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.overflowMenuDismissIconAriaLabel, backIconAriaLabel: i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.overflowMenuBackIconAriaLabel, items: utilities.filter((utility, i) => (!responsiveState.hideUtilities || responsiveState.hideUtilities.indexOf(i) !== -1) &&
|
|
142
|
+
!utility.disableUtilityCollapse), onClose: toggleOverflowMenu })))));
|
|
143
|
+
return (React.createElement("div", { ...baseProps, ref: __internalRootRef }, wrapWithVisualContext(structuredContent, visualContext)));
|
|
123
144
|
}
|
|
124
145
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @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,gBAAgB,EAC1B,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAC,GAAG,EACf,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,SAAS,IAEnD,IAAI,CAAC,qCAAqC,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,uBAAuB,CAAC,CACpE,CACZ,CACP,CACG,CACF,CACE,CACX,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,gCAAS,SAAS,EAAE,GAAG,EAAE,iBAAiB;QACxC,oBAAC,aAAa,IAAC,WAAW,EAAC,gBAAgB;YAExC,OAAO,CAAC,IAAI,CAAC;YAEb,OAAO,CAAC,KAAK,CAAC;YAEd,kBAAkB,IAAI,gBAAgB,IAAI,CACzC,6BAAK,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC;gBAC5C,oBAAC,YAAY,IACX,UAAU,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,qBAAqB,EAC9C,oBAAoB,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gCAAgC,EACnE,iBAAiB,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,6BAA6B,EAC7D,KAAK,EAAE,SAAS,CAAC,MAAM,CACrB,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CACb,CAAC,CAAC,eAAe,CAAC,aAAa,IAAI,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;wBACnF,CAAC,OAAO,CAAC,sBAAsB,CAClC,EACD,OAAO,EAAE,kBAAkB,GAC3B,CACE,CACP,CACa,CACZ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { getBaseProps } from '../internal/base-component';\nimport { ButtonTrigger } from '../internal/components/menu-dropdown';\nimport VisualContext from '../internal/components/visual-context';\nimport { fireCancelableEvent, isPlainLeftClick } from '../internal/events';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useEffectOnUpdate } from '../internal/hooks/use-effect-on-update';\nimport { SomeRequired } from '../internal/types';\nimport { checkSafeUrl } from '../internal/utils/check-safe-url';\nimport { TopNavigationProps } from './interfaces';\nimport OverflowMenu from './parts/overflow-menu';\nimport Utility from './parts/utility';\nimport { useTopNavigation } from './use-top-navigation.js';\n\nimport styles from './styles.css.js';\n\ntype InternalTopNavigationProps = SomeRequired<TopNavigationProps, 'utilities'> & InternalBaseComponentProps;\n\nexport default function InternalTopNavigation({\n __internalRootRef,\n identity,\n i18nStrings,\n utilities,\n search,\n ...restProps\n}: InternalTopNavigationProps) {\n checkSafeUrl('TopNavigation', identity.href);\n const baseProps = getBaseProps(restProps);\n const { mainRef, virtualRef, breakpoint, responsiveState, isSearchExpanded, onSearchUtilityClick } = useTopNavigation(\n { identity, search, utilities }\n );\n const [overflowMenuOpen, setOverflowMenuOpen] = useState(false);\n const overflowMenuTriggerRef = useRef<HTMLButtonElement>(null);\n const isNarrowViewport = breakpoint === 'default';\n const isMediumViewport = breakpoint === 'xxs';\n const isLargeViewport = breakpoint === 's';\n const i18n = useInternalI18n('top-navigation');\n\n const onIdentityClick = (event: React.MouseEvent) => {\n if (isPlainLeftClick(event)) {\n fireCancelableEvent(identity.onFollow, {}, event);\n }\n };\n\n const toggleOverflowMenu = () => {\n setOverflowMenuOpen(overflowMenuOpen => !overflowMenuOpen);\n };\n\n const menuTriggerVisible = !isSearchExpanded && responsiveState.hideUtilities;\n\n useEffect(() => {\n setOverflowMenuOpen(false);\n }, [menuTriggerVisible]);\n\n useEffectOnUpdate(() => {\n if (!overflowMenuOpen) {\n overflowMenuTriggerRef.current?.focus();\n }\n }, [overflowMenuOpen]);\n\n // Render the top nav twice; once as the top nav that users can see, and another\n // \"virtual\" top nav used just for calculations. The virtual top nav doesn't react to\n // layout changes and renders two sets of utilities: one with labels and one without.\n const content = (isVirtual: boolean) => {\n const Wrapper = isVirtual ? 'div' : 'header';\n const showIdentity = isVirtual || !isSearchExpanded;\n const showTitle = isVirtual || !responsiveState.hideTitle;\n const showSearchSlot = search && (isVirtual || !responsiveState.hideSearch || isSearchExpanded);\n const showSearchUtility = isVirtual || (search && responsiveState.hideSearch);\n const showUtilities = isVirtual || !isSearchExpanded;\n const showMenuTrigger = isVirtual || menuTriggerVisible;\n\n return (\n <Wrapper\n ref={isVirtual ? virtualRef : mainRef}\n aria-hidden={isVirtual ? true : undefined}\n className={clsx(styles['top-navigation'], {\n [styles.virtual]: isVirtual,\n [styles.hidden]: isVirtual,\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n })}\n >\n <div className={styles['padding-box']}>\n {showIdentity && (\n <div className={clsx(styles.identity, !identity.logo && styles['no-logo'])}>\n <a className={styles['identity-link']} href={identity.href} onClick={onIdentityClick}>\n {identity.logo && (\n <img\n role=\"img\"\n src={identity.logo?.src}\n alt={identity.logo?.alt}\n className={clsx(styles.logo, {\n [styles.narrow]: isNarrowViewport,\n })}\n />\n )}\n {showTitle && <span className={styles.title}>{identity.title}</span>}\n </a>\n </div>\n )}\n\n {showSearchSlot && (\n <div className={styles.inputs}>\n <div className={clsx(styles.search, !isVirtual && isSearchExpanded && styles['search-expanded'])}>\n {search}\n </div>\n </div>\n )}\n\n <div className={styles.utilities}>\n {showSearchUtility && (\n <div\n className={clsx(\n styles['utility-wrapper'],\n styles['utility-type-button'],\n styles['utility-type-button-link'],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-special=\"search\"\n >\n <Utility\n hideText={true}\n definition={{\n type: 'button',\n iconName: isSearchExpanded ? 'close' : 'search',\n ariaLabel: isSearchExpanded\n ? i18n('i18nStrings.searchDismissIconAriaLabel', i18nStrings?.searchDismissIconAriaLabel)\n : i18n('i18nStrings.searchIconAriaLabel', i18nStrings?.searchIconAriaLabel),\n onClick: onSearchUtilityClick,\n }}\n />\n </div>\n )}\n\n {showUtilities &&\n utilities\n .filter(\n (_utility, i) =>\n isVirtual || !responsiveState.hideUtilities || responsiveState.hideUtilities.indexOf(i) === -1\n )\n .map((utility, i) => {\n const hideText = !!responsiveState.hideUtilityText;\n const isLast = (isVirtual || !showMenuTrigger) && i === utilities.length - 1;\n const offsetRight = isLast && isLargeViewport ? 'xxl' : isLast ? 'l' : undefined;\n\n return (\n <div\n key={i}\n className={clsx(\n styles['utility-wrapper'],\n styles[`utility-type-${utility.type}`],\n utility.type === 'button' && styles[`utility-type-button-${utility.variant ?? 'link'}`],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-index={i}\n data-utility-hide={`${hideText}`}\n >\n <Utility hideText={hideText} definition={utility} offsetRight={offsetRight} />\n </div>\n );\n })}\n\n {isVirtual &&\n utilities.map((utility, i) => {\n const hideText = !responsiveState.hideUtilityText;\n const isLast = !showMenuTrigger && i === utilities.length - 1;\n const offsetRight = isLast && isLargeViewport ? 'xxl' : isLast ? 'l' : undefined;\n\n return (\n <div\n key={i}\n className={clsx(\n styles['utility-wrapper'],\n styles[`utility-type-${utility.type}`],\n utility.type === 'button' && styles[`utility-type-button-${utility.variant ?? 'link'}`],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-index={i}\n data-utility-hide={`${hideText}`}\n >\n <Utility hideText={hideText} definition={utility} offsetRight={offsetRight} />\n </div>\n );\n })}\n\n {showMenuTrigger && (\n <div\n className={clsx(styles['utility-wrapper'], styles['utility-type-menu-dropdown'], {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n })}\n data-utility-special=\"menu-trigger\"\n >\n <ButtonTrigger\n expanded={overflowMenuOpen}\n onClick={toggleOverflowMenu}\n offsetRight=\"l\"\n ref={!isVirtual ? overflowMenuTriggerRef : undefined}\n >\n {i18n('i18nStrings.overflowMenuTriggerText', i18nStrings?.overflowMenuTriggerText)}\n </ButtonTrigger>\n </div>\n )}\n </div>\n </div>\n </Wrapper>\n );\n };\n\n return (\n <div {...baseProps} ref={__internalRootRef}>\n <VisualContext contextName=\"top-navigation\">\n {/* Render virtual content first to ensure React refs for content will be assigned on the actual nodes. */}\n {content(true)}\n\n {content(false)}\n\n {menuTriggerVisible && overflowMenuOpen && (\n <div className={styles['overflow-menu-drawer']}>\n <OverflowMenu\n headerText={i18nStrings?.overflowMenuTitleText}\n dismissIconAriaLabel={i18nStrings?.overflowMenuDismissIconAriaLabel}\n backIconAriaLabel={i18nStrings?.overflowMenuBackIconAriaLabel}\n items={utilities.filter(\n (utility, i) =>\n (!responsiveState.hideUtilities || responsiveState.hideUtilities.indexOf(i) !== -1) &&\n !utility.disableUtilityCollapse\n )}\n onClose={toggleOverflowMenu}\n />\n </div>\n )}\n </VisualContext>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/top-navigation/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,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AAK,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC;YAC5C,oBAAC,YAAY,IACX,UAAU,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,qBAAqB,EAC9C,oBAAoB,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gCAAgC,EACnE,iBAAiB,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,6BAA6B,EAC7D,KAAK,EAAE,SAAS,CAAC,MAAM,CACrB,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CACb,CAAC,CAAC,eAAe,CAAC,aAAa,IAAI,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;oBACnF,CAAC,OAAO,CAAC,sBAAsB,CAClC,EACD,OAAO,EAAE,kBAAkB,GAC3B,CACE,CACP,CACA,CACJ,CAAC;IAEF,OAAO,CACL,gCAAS,SAAS,EAAE,GAAG,EAAE,iBAAiB,IACvC,qBAAqB,CAAC,iBAAiB,EAAE,aAAa,CAAC,CACpD,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { getBaseProps } from '../internal/base-component';\nimport { ButtonTrigger } from '../internal/components/menu-dropdown';\nimport VisualContext from '../internal/components/visual-context';\nimport { fireCancelableEvent, isPlainLeftClick } from '../internal/events';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useEffectOnUpdate } from '../internal/hooks/use-effect-on-update';\nimport { SomeRequired } from '../internal/types';\nimport { checkSafeUrl } from '../internal/utils/check-safe-url';\nimport { TopNavigationProps } from './interfaces';\nimport OverflowMenu from './parts/overflow-menu';\nimport Utility from './parts/utility';\nimport { useTopNavigation } from './use-top-navigation.js';\n\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\ntype InternalTopNavigationProps = SomeRequired<TopNavigationProps, 'utilities' | 'visualContext'> &\n InternalBaseComponentProps;\n\nfunction wrapWithVisualContext(content: React.ReactNode, visualContext: TopNavigationProps.VisualContext) {\n return visualContext === 'none' ? content : <VisualContext contextName={visualContext}>{content}</VisualContext>;\n}\n\nexport default function InternalTopNavigation({\n __internalRootRef,\n children,\n visualContext,\n ...restProps\n}: InternalTopNavigationProps) {\n if (children !== undefined) {\n return (\n <CustomContentTopNavigation __internalRootRef={__internalRootRef} visualContext={visualContext} {...restProps}>\n {children}\n </CustomContentTopNavigation>\n );\n }\n\n return <StructuredTopNavigation __internalRootRef={__internalRootRef} visualContext={visualContext} {...restProps} />;\n}\n\nfunction CustomContentTopNavigation({\n __internalRootRef,\n children,\n visualContext,\n ...restProps\n}: InternalTopNavigationProps) {\n const baseProps = getBaseProps(restProps);\n\n const { identity, search, utilities } = restProps;\n if (identity || search || (utilities && utilities.length > 0)) {\n warnOnce(\n 'TopNavigation',\n 'When children is set, the structured props (identity, search, and utilities) are ignored'\n );\n }\n\n return (\n <div {...baseProps} ref={__internalRootRef}>\n {wrapWithVisualContext(\n <header className={styles['top-navigation']}>\n <div className={testUtilStyles['custom-content']}>{children}</div>\n </header>,\n visualContext\n )}\n </div>\n );\n}\n\ntype StructuredTopNavigationProps = Omit<InternalTopNavigationProps, 'children'>;\n\nfunction StructuredTopNavigation({\n __internalRootRef,\n identity,\n i18nStrings,\n utilities,\n search,\n visualContext,\n ...restProps\n}: StructuredTopNavigationProps) {\n if (identity) {\n checkSafeUrl('TopNavigation', identity.href);\n }\n const baseProps = getBaseProps(restProps);\n\n const { mainRef, virtualRef, breakpoint, responsiveState, isSearchExpanded, onSearchUtilityClick } = useTopNavigation(\n { identity, search, utilities }\n );\n const [overflowMenuOpen, setOverflowMenuOpen] = useState(false);\n const overflowMenuTriggerRef = useRef<HTMLButtonElement>(null);\n const isNarrowViewport = breakpoint === 'default';\n const isMediumViewport = breakpoint === 'xxs';\n const isLargeViewport = breakpoint === 's';\n const i18n = useInternalI18n('top-navigation');\n\n const menuTriggerVisible = !isSearchExpanded && responsiveState.hideUtilities;\n\n useEffect(() => {\n setOverflowMenuOpen(false);\n }, [menuTriggerVisible]);\n\n useEffectOnUpdate(() => {\n if (!overflowMenuOpen) {\n overflowMenuTriggerRef.current?.focus();\n }\n }, [overflowMenuOpen]);\n\n const onIdentityClick = (event: React.MouseEvent) => {\n if (isPlainLeftClick(event)) {\n fireCancelableEvent(identity?.onFollow, {}, event);\n }\n };\n\n const toggleOverflowMenu = () => {\n setOverflowMenuOpen(overflowMenuOpen => !overflowMenuOpen);\n };\n\n // Render the top nav twice; once as the top nav that users can see, and another\n // \"virtual\" top nav used just for calculations. The virtual top nav doesn't react to\n // layout changes and renders two sets of utilities: one with labels and one without.\n const content = (isVirtual: boolean) => {\n const Wrapper = isVirtual ? 'div' : 'header';\n const showIdentity = !!identity && (isVirtual || !isSearchExpanded);\n const showTitle = isVirtual || !responsiveState.hideTitle;\n const showSearchSlot = search && (isVirtual || !responsiveState.hideSearch || isSearchExpanded);\n const showSearchUtility = isVirtual || (search && responsiveState.hideSearch);\n const showUtilities = isVirtual || !isSearchExpanded;\n const showMenuTrigger = isVirtual || menuTriggerVisible;\n\n return (\n <Wrapper\n ref={isVirtual ? virtualRef : mainRef}\n aria-hidden={isVirtual ? true : undefined}\n className={clsx(styles['top-navigation'], {\n [styles.virtual]: isVirtual,\n [styles.hidden]: isVirtual,\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n })}\n >\n <div className={styles['padding-box']}>\n {showIdentity && identity && (\n <div className={clsx(styles.identity, !identity.logo && styles['no-logo'])}>\n <a className={styles['identity-link']} href={identity.href} onClick={onIdentityClick}>\n {identity.logo && (\n <img\n role=\"img\"\n src={identity.logo.src}\n alt={identity.logo.alt}\n className={clsx(styles.logo, {\n [styles.narrow]: isNarrowViewport,\n })}\n />\n )}\n {showTitle && <span className={styles.title}>{identity.title}</span>}\n </a>\n </div>\n )}\n\n {showSearchSlot && (\n <div className={styles.inputs}>\n <div className={clsx(styles.search, !isVirtual && isSearchExpanded && styles['search-expanded'])}>\n {search}\n </div>\n </div>\n )}\n\n <div className={styles.utilities}>\n {showSearchUtility && (\n <div\n className={clsx(\n styles['utility-wrapper'],\n styles['utility-type-button'],\n styles['utility-type-button-link'],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-special=\"search\"\n >\n <Utility\n hideText={true}\n definition={{\n type: 'button',\n iconName: isSearchExpanded ? 'close' : 'search',\n ariaLabel: isSearchExpanded\n ? i18n('i18nStrings.searchDismissIconAriaLabel', i18nStrings?.searchDismissIconAriaLabel)\n : i18n('i18nStrings.searchIconAriaLabel', i18nStrings?.searchIconAriaLabel),\n onClick: onSearchUtilityClick,\n }}\n />\n </div>\n )}\n\n {showUtilities &&\n utilities\n .filter(\n (_utility, i) =>\n isVirtual || !responsiveState.hideUtilities || responsiveState.hideUtilities.indexOf(i) === -1\n )\n .map((utility, i) => {\n const hideText = !!responsiveState.hideUtilityText;\n const isLast = (isVirtual || !showMenuTrigger) && i === utilities.length - 1;\n const offsetRight = isLast && isLargeViewport ? 'xxl' : isLast ? 'l' : undefined;\n\n return (\n <div\n key={i}\n className={clsx(\n styles['utility-wrapper'],\n styles[`utility-type-${utility.type}`],\n utility.type === 'button' && styles[`utility-type-button-${utility.variant ?? 'link'}`],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-index={i}\n data-utility-hide={`${hideText}`}\n >\n <Utility hideText={hideText} definition={utility} offsetRight={offsetRight} />\n </div>\n );\n })}\n\n {isVirtual &&\n utilities.map((utility, i) => {\n const hideText = !responsiveState.hideUtilityText;\n const isLast = !showMenuTrigger && i === utilities.length - 1;\n const offsetRight = isLast && isLargeViewport ? 'xxl' : isLast ? 'l' : undefined;\n\n return (\n <div\n key={i}\n className={clsx(\n styles['utility-wrapper'],\n styles[`utility-type-${utility.type}`],\n utility.type === 'button' && styles[`utility-type-button-${utility.variant ?? 'link'}`],\n {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n }\n )}\n data-utility-index={i}\n data-utility-hide={`${hideText}`}\n >\n <Utility hideText={hideText} definition={utility} offsetRight={offsetRight} />\n </div>\n );\n })}\n\n {showMenuTrigger && (\n <div\n className={clsx(styles['utility-wrapper'], styles['utility-type-menu-dropdown'], {\n [styles.narrow]: isNarrowViewport,\n [styles.medium]: isMediumViewport,\n })}\n data-utility-special=\"menu-trigger\"\n >\n <ButtonTrigger\n expanded={overflowMenuOpen}\n onClick={toggleOverflowMenu}\n offsetRight=\"l\"\n ref={!isVirtual ? overflowMenuTriggerRef : undefined}\n >\n {i18n('i18nStrings.overflowMenuTriggerText', i18nStrings?.overflowMenuTriggerText)}\n </ButtonTrigger>\n </div>\n )}\n </div>\n </div>\n </Wrapper>\n );\n };\n\n const structuredContent = (\n <>\n {/* Render virtual content first to ensure React refs for content will be assigned on the actual nodes. */}\n {content(true)}\n\n {content(false)}\n\n {menuTriggerVisible && overflowMenuOpen && (\n <div className={styles['overflow-menu-drawer']}>\n <OverflowMenu\n headerText={i18nStrings?.overflowMenuTitleText}\n dismissIconAriaLabel={i18nStrings?.overflowMenuDismissIconAriaLabel}\n backIconAriaLabel={i18nStrings?.overflowMenuBackIconAriaLabel}\n items={utilities.filter(\n (utility, i) =>\n (!responsiveState.hideUtilities || responsiveState.hideUtilities.indexOf(i) !== -1) &&\n !utility.disableUtilityCollapse\n )}\n onClose={toggleOverflowMenu}\n />\n </div>\n )}\n </>\n );\n\n return (\n <div {...baseProps} ref={__internalRootRef}>\n {wrapWithVisualContext(structuredContent, visualContext)}\n </div>\n );\n}\n"]}
|
|
@@ -32,6 +32,11 @@ interface UseTopNavigation {
|
|
|
32
32
|
onSearchUtilityClick: () => void;
|
|
33
33
|
}
|
|
34
34
|
export declare function useTopNavigation({ identity, search, utilities }: UseTopNavigationParams): UseTopNavigation;
|
|
35
|
+
/**
|
|
36
|
+
* Measures the width of an optional element, returning 0 when it is not rendered
|
|
37
|
+
* (e.g. there is no `identity`, `title` or `search`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function getOptionalElementWidth(parent: Element, selector: string): number;
|
|
35
40
|
/**
|
|
36
41
|
* Generates the series of responsive steps that can be performed on the header in order.
|
|
37
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-top-navigation.d.ts","sourceRoot":"","sources":["../../../src/top-navigation/use-top-navigation.ts"],"names":[],"mappings":"AAEA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAMjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIlD,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACrC,SAAS,EAAE,WAAW,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;CACzD;AAED,UAAU,eAAe;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,yBAAyB,EAAE,MAAM,EAAE,CAAC;IACpC,uBAAuB,EAAE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ACpC,eAAe,CA6BjB"}
|
|
@@ -16,7 +16,7 @@ export function useTopNavigation({ identity, search, utilities }) {
|
|
|
16
16
|
// The component works by calculating the possible resize states that it can
|
|
17
17
|
// be in, and having a state variable to track which state we're currently in.
|
|
18
18
|
const hasSearch = !!search;
|
|
19
|
-
const hasTitleWithLogo = identity && !!identity.logo && !!identity.title;
|
|
19
|
+
const hasTitleWithLogo = !!identity && !!identity.logo && !!identity.title;
|
|
20
20
|
const responsiveStates = useMemo(() => {
|
|
21
21
|
return generateResponsiveStateKeys(utilities, hasSearch, hasTitleWithLogo);
|
|
22
22
|
}, [utilities, hasSearch, hasTitleWithLogo]);
|
|
@@ -31,7 +31,6 @@ export function useTopNavigation({ identity, search, utilities }) {
|
|
|
31
31
|
// spacing token values, icon sizes, text widths, etc.
|
|
32
32
|
const [responsiveState, setResponsiveState] = useState();
|
|
33
33
|
const recalculateFit = useCallback(() => {
|
|
34
|
-
var _a, _b, _c, _d;
|
|
35
34
|
if (!(mainRef === null || mainRef === void 0 ? void 0 : mainRef.current) || !virtualRef.current) {
|
|
36
35
|
setResponsiveState(responsiveStates[0]);
|
|
37
36
|
return;
|
|
@@ -47,9 +46,9 @@ export function useTopNavigation({ identity, search, utilities }) {
|
|
|
47
46
|
hasSearch,
|
|
48
47
|
availableWidth,
|
|
49
48
|
// Get widths from the hidden top navigation
|
|
50
|
-
fullIdentityWidth: virtualRef.current
|
|
51
|
-
titleWidth: (
|
|
52
|
-
searchSlotWidth: (
|
|
49
|
+
fullIdentityWidth: getOptionalElementWidth(virtualRef.current, `.${styles.identity}`),
|
|
50
|
+
titleWidth: getOptionalElementWidth(virtualRef.current, `.${styles.title}`),
|
|
51
|
+
searchSlotWidth: getOptionalElementWidth(virtualRef.current, `.${styles.search}`),
|
|
53
52
|
searchUtilityWidth: virtualRef.current.querySelector('[data-utility-special="search"]').getBoundingClientRect()
|
|
54
53
|
.width,
|
|
55
54
|
utilitiesLeftPadding: parseFloat(getComputedStyle(virtualRef.current.querySelector(`.${styles.utilities}`)).paddingLeft || '0px'),
|
|
@@ -110,6 +109,14 @@ function getContentBoxWidth(element) {
|
|
|
110
109
|
const style = getComputedStyle(element);
|
|
111
110
|
return (parseFloat(style.width || '0px') - parseFloat(style.paddingLeft || '0px') - parseFloat(style.paddingRight || '0px'));
|
|
112
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Measures the width of an optional element, returning 0 when it is not rendered
|
|
114
|
+
* (e.g. there is no `identity`, `title` or `search`).
|
|
115
|
+
*/
|
|
116
|
+
export function getOptionalElementWidth(parent, selector) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
return (_b = (_a = parent.querySelector(selector)) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) !== null && _b !== void 0 ? _b : 0;
|
|
119
|
+
}
|
|
113
120
|
/**
|
|
114
121
|
* Generates the series of responsive steps that can be performed on the header in order.
|
|
115
122
|
*/
|