@chayns-components/core 5.5.65 → 5.5.67
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/AGENTS.md +32 -0
- package/lib/cjs/components/context-menu/ContextMenu.js +13 -5
- package/lib/cjs/components/context-menu/ContextMenu.js.map +1 -1
- package/lib/cjs/components/context-menu/ContextMenu.test.js +234 -0
- package/lib/cjs/components/context-menu/ContextMenu.test.js.map +1 -0
- package/lib/cjs/components/context-menu/ContextMenu.types.js.map +1 -1
- package/lib/cjs/components/context-menu/ContextMenu.utils.js +4 -1
- package/lib/cjs/components/context-menu/ContextMenu.utils.js.map +1 -1
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.js +11 -33
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -1
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js +11 -3
- package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -1
- package/lib/cjs/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.js +74 -0
- package/lib/cjs/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.js.map +1 -0
- package/lib/cjs/components/slider/Slider.js +77 -36
- package/lib/cjs/components/slider/Slider.js.map +1 -1
- package/lib/cjs/components/slider/Slider.styles.js +2 -2
- package/lib/cjs/components/slider/Slider.styles.js.map +1 -1
- package/lib/esm/components/context-menu/ContextMenu.js +13 -4
- package/lib/esm/components/context-menu/ContextMenu.js.map +1 -1
- package/lib/esm/components/context-menu/ContextMenu.test.js +223 -0
- package/lib/esm/components/context-menu/ContextMenu.test.js.map +1 -0
- package/lib/esm/components/context-menu/ContextMenu.types.js.map +1 -1
- package/lib/esm/components/context-menu/ContextMenu.utils.js +4 -1
- package/lib/esm/components/context-menu/ContextMenu.utils.js.map +1 -1
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.js +13 -35
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -1
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.styles.js +11 -3
- package/lib/esm/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -1
- package/lib/esm/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.js +66 -0
- package/lib/esm/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.js.map +1 -0
- package/lib/esm/components/slider/Slider.js +74 -31
- package/lib/esm/components/slider/Slider.js.map +1 -1
- package/lib/esm/components/slider/Slider.styles.js +2 -2
- package/lib/esm/components/slider/Slider.styles.js.map +1 -1
- package/lib/types/components/context-menu/ContextMenu.types.d.ts +9 -0
- package/lib/types/components/context-menu/context-menu-content/ContextMenuContent.styles.d.ts +4 -2
- package/lib/types/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.d.ts +11 -0
- package/lib/types/components/slider/Slider.styles.d.ts +6 -6
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _ContextMenuContentItem = _interopRequireDefault(require("./context-menu-content-item/ContextMenuContentItem"));
|
|
9
9
|
var _ContextMenuContent = require("./ContextMenuContent.styles");
|
|
10
10
|
var _ContextMenu = require("../ContextMenu.types");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -48,39 +48,17 @@ const ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
48
48
|
const percentageOffsetY = isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -100 : 0;
|
|
49
49
|
const anchorOffsetY = isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -21 : 21;
|
|
50
50
|
const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;
|
|
51
|
-
const content = (0, _react.useMemo)(() => items.map(({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let iconElement = null;
|
|
60
|
-
if (/*#__PURE__*/(0, _react.isValidElement)(icons)) {
|
|
61
|
-
iconElement = icons;
|
|
62
|
-
} else if (Array.isArray(icons) && icons.length > 0) {
|
|
63
|
-
iconElement = /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemIconWrapper, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
64
|
-
icons: icons
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItem, {
|
|
68
|
-
key: `context-menu-item-${key}`,
|
|
69
|
-
"data-index": index
|
|
70
|
-
}, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemWrapper, {
|
|
71
|
-
key: key,
|
|
72
|
-
onClick: event => {
|
|
73
|
-
event.preventDefault();
|
|
74
|
-
event.stopPropagation();
|
|
75
|
-
void onClick(event);
|
|
76
|
-
},
|
|
77
|
-
tabIndex: 0,
|
|
78
|
-
$shouldHidePopupArrow: shouldHidePopupArrow,
|
|
79
|
-
$isFocused: isFocused,
|
|
80
|
-
onFocus: () => onItemFocus(index)
|
|
81
|
-
}, iconElement, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemText, null, text)), shouldShowSpacer && /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemSpacer, null));
|
|
82
|
-
}), [items, focusedIndex, shouldHidePopupArrow, onItemFocus]);
|
|
51
|
+
const content = (0, _react.useMemo)(() => items.map((item, index) => /*#__PURE__*/_react.default.createElement(_ContextMenuContentItem.default, {
|
|
52
|
+
key: item.key,
|
|
53
|
+
item: item,
|
|
54
|
+
index: index,
|
|
55
|
+
isFocused: index === focusedIndex,
|
|
56
|
+
shouldHidePopupArrow: shouldHidePopupArrow,
|
|
57
|
+
onItemFocus: onItemFocus
|
|
58
|
+
})), [items, focusedIndex, shouldHidePopupArrow, onItemFocus]);
|
|
83
59
|
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledMotionContextMenuContent, {
|
|
60
|
+
role: "menu",
|
|
61
|
+
"aria-label": headline,
|
|
84
62
|
animate: {
|
|
85
63
|
opacity: 1,
|
|
86
64
|
y: 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuContent.js","names":["_react","_interopRequireWildcard","require","_Icon","_interopRequireDefault","_ContextMenuContent","_ContextMenu","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenuContent","React","forwardRef","alignment","coordinates","items","zIndex","shouldHidePopupArrow","headline","onItemFocus","focusedIndex","onMouseEnter","onMouseLeave","ref","isBottomLeftAlignment","ContextMenuAlignment","BottomLeft","isTopLeftAlignment","TopLeft","isTopRightAlignment","TopRight","isTopCenterAlignment","TopCenter","isBottomCenterAlignment","BottomCenter","percentageOffsetX","useMemo","anchorOffsetX","percentageOffsetY","anchorOffsetY","exitAndInitialY","content","map","onClick","key","text","icons","shouldShowSpacer","index","isFocused","iconElement","isValidElement","Array","isArray","length","createElement","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentItem","StyledContextMenuContentItemWrapper","event","preventDefault","stopPropagation","tabIndex","$shouldHidePopupArrow","$isFocused","onFocus","StyledContextMenuContentItemText","StyledContextMenuContentItemSpacer","StyledMotionContextMenuContent","animate","opacity","y","exit","initial","$position","$zIndex","style","left","x","top","transition","ease","transformTemplate","StyledContextMenuContentHeadline","displayName","_default","exports"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.tsx"],"sourcesContent":["import React, { isValidElement, useMemo } from 'react';\nimport Icon from '../../icon/Icon';\nimport {\n StyledContextMenuContentHeadline,\n StyledContextMenuContentItem,\n StyledContextMenuContentItemIconWrapper,\n StyledContextMenuContentItemSpacer,\n StyledContextMenuContentItemText,\n StyledContextMenuContentItemWrapper,\n StyledMotionContextMenuContent,\n} from './ContextMenuContent.styles';\nimport {\n ContextMenuAlignment,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n} from '../ContextMenu.types';\n\ntype ContextMenuContentProps = {\n alignment: ContextMenuAlignment;\n coordinates: ContextMenuCoordinates;\n items: ContextMenuItem[];\n shouldHidePopupArrow: boolean;\n headline?: string;\n zIndex: number;\n focusedIndex: number;\n onItemFocus: (index: number) => void;\n onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;\n onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;\n};\n\nconst ContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(\n (\n {\n alignment,\n coordinates,\n items,\n zIndex,\n shouldHidePopupArrow,\n headline,\n onItemFocus,\n focusedIndex,\n onMouseEnter,\n onMouseLeave,\n },\n ref,\n ) => {\n const isBottomLeftAlignment = alignment === ContextMenuAlignment.BottomLeft;\n const isTopLeftAlignment = alignment === ContextMenuAlignment.TopLeft;\n const isTopRightAlignment = alignment === ContextMenuAlignment.TopRight;\n const isTopCenterAlignment = alignment === ContextMenuAlignment.TopCenter;\n const isBottomCenterAlignment = alignment === ContextMenuAlignment.BottomCenter;\n\n const percentageOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return -100;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return -50;\n }\n\n return 0;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const anchorOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return 15;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return 0;\n }\n\n return -15;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const percentageOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -100 : 0;\n\n const anchorOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -21 : 21;\n\n const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;\n\n const content = useMemo(\n () =>\n items.map(({ onClick, key, text, icons, shouldShowSpacer }, index) => {\n const isFocused = index === focusedIndex;\n\n let iconElement = null;\n\n if (isValidElement(icons)) {\n iconElement = icons;\n } else if (Array.isArray(icons) && icons.length > 0) {\n iconElement = (\n <StyledContextMenuContentItemIconWrapper>\n <Icon icons={icons} />\n </StyledContextMenuContentItemIconWrapper>\n );\n }\n\n return (\n <StyledContextMenuContentItem\n key={`context-menu-item-${key}`}\n data-index={index}\n >\n <StyledContextMenuContentItemWrapper\n key={key}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n void onClick(event);\n }}\n tabIndex={0}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $isFocused={isFocused}\n onFocus={() => onItemFocus(index)}\n >\n {iconElement}\n <StyledContextMenuContentItemText>\n {text}\n </StyledContextMenuContentItemText>\n </StyledContextMenuContentItemWrapper>\n {shouldShowSpacer && <StyledContextMenuContentItemSpacer />}\n </StyledContextMenuContentItem>\n );\n }),\n [items, focusedIndex, shouldHidePopupArrow, onItemFocus],\n );\n\n return (\n <StyledMotionContextMenuContent\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: exitAndInitialY }}\n initial={{ opacity: 0, y: exitAndInitialY }}\n $position={alignment}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $zIndex={zIndex}\n ref={ref}\n style={{ left: coordinates.x, top: coordinates.y }}\n transition={{ ease: 'anticipate' }}\n transformTemplate={({ y = '0px' }) => `\n translateX(${percentageOffsetX}%)\n translateY(${percentageOffsetY}%)\n translateX(${anchorOffsetX}px)\n translateY(${anchorOffsetY}px)\n translateY(${y})\n `}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n >\n {headline && (\n <StyledContextMenuContentHeadline>{headline}</StyledContextMenuContentHeadline>\n )}\n {content}\n </StyledMotionContextMenuContent>\n );\n },\n);\n\nContextMenuContent.displayName = 'ContextMenuContent';\n\nexport default ContextMenuContent;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AASA,IAAAI,YAAA,GAAAJ,OAAA;AAI8B,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAM,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAAA,GAAAS,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAG,CAAA,OAAAK,CAAA,CAAAI,GAAA,I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IACnCC,iBAAiB,EAAEA,CAAC;MAAEX,CAAC,GAAG;IAAM,CAAC,KAAK;AACtD,iCAAiCpC,iBAAiB;AAClD,iCAAiCG,iBAAiB;AAClD,iCAAiCD,aAAa;AAC9C,iCAAiCE,aAAa;AAC9C,iCAAiCgC,CAAC;AAClC,iBAAkB;IACFlD,YAAY,EAAEA,YAAa;IAC3BC,YAAY,EAAEA;EAAa,GAE1BJ,QAAQ,iBACLlC,MAAA,CAAAS,OAAA,CAAA8D,aAAA,CAAClE,mBAAA,CAAA8F,gCAAgC,QAAEjE,QAA2C,CACjF,EACAuB,OAC2B,CAAC;AAEzC,CACJ,CAAC;AAED/B,kBAAkB,CAAC0E,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7F,OAAA,GAEvCiB,kBAAkB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ContextMenuContent.js","names":["_react","_interopRequireWildcard","require","_ContextMenuContentItem","_interopRequireDefault","_ContextMenuContent","_ContextMenu","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenuContent","React","forwardRef","alignment","coordinates","items","zIndex","shouldHidePopupArrow","headline","onItemFocus","focusedIndex","onMouseEnter","onMouseLeave","ref","isBottomLeftAlignment","ContextMenuAlignment","BottomLeft","isTopLeftAlignment","TopLeft","isTopRightAlignment","TopRight","isTopCenterAlignment","TopCenter","isBottomCenterAlignment","BottomCenter","percentageOffsetX","useMemo","anchorOffsetX","percentageOffsetY","anchorOffsetY","exitAndInitialY","content","map","item","index","createElement","key","isFocused","StyledMotionContextMenuContent","role","animate","opacity","y","exit","initial","$position","$shouldHidePopupArrow","$zIndex","style","left","x","top","transition","ease","transformTemplate","StyledContextMenuContentHeadline","displayName","_default","exports"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport ContextMenuContentItem from './context-menu-content-item/ContextMenuContentItem';\nimport {\n StyledContextMenuContentHeadline,\n StyledMotionContextMenuContent,\n} from './ContextMenuContent.styles';\nimport {\n ContextMenuAlignment,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n} from '../ContextMenu.types';\n\ntype ContextMenuContentProps = {\n alignment: ContextMenuAlignment;\n coordinates: ContextMenuCoordinates;\n items: ContextMenuItem[];\n shouldHidePopupArrow: boolean;\n headline?: string;\n zIndex: number;\n focusedIndex: number;\n onItemFocus: (index: number) => void;\n onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;\n onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;\n};\n\nconst ContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(\n (\n {\n alignment,\n coordinates,\n items,\n zIndex,\n shouldHidePopupArrow,\n headline,\n onItemFocus,\n focusedIndex,\n onMouseEnter,\n onMouseLeave,\n },\n ref,\n ) => {\n const isBottomLeftAlignment = alignment === ContextMenuAlignment.BottomLeft;\n const isTopLeftAlignment = alignment === ContextMenuAlignment.TopLeft;\n const isTopRightAlignment = alignment === ContextMenuAlignment.TopRight;\n const isTopCenterAlignment = alignment === ContextMenuAlignment.TopCenter;\n const isBottomCenterAlignment = alignment === ContextMenuAlignment.BottomCenter;\n\n const percentageOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return -100;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return -50;\n }\n\n return 0;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const anchorOffsetX = useMemo(() => {\n if (isBottomLeftAlignment || isTopLeftAlignment) {\n return 15;\n }\n\n if (isBottomCenterAlignment || isTopCenterAlignment) {\n return 0;\n }\n\n return -15;\n }, [\n isBottomCenterAlignment,\n isBottomLeftAlignment,\n isTopCenterAlignment,\n isTopLeftAlignment,\n ]);\n\n const percentageOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -100 : 0;\n\n const anchorOffsetY =\n isTopRightAlignment || isTopLeftAlignment || isTopCenterAlignment ? -21 : 21;\n\n const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;\n\n const content = useMemo(\n () =>\n items.map((item, index) => (\n <ContextMenuContentItem\n key={item.key}\n item={item}\n index={index}\n isFocused={index === focusedIndex}\n shouldHidePopupArrow={shouldHidePopupArrow}\n onItemFocus={onItemFocus}\n />\n )),\n [items, focusedIndex, shouldHidePopupArrow, onItemFocus],\n );\n\n return (\n <StyledMotionContextMenuContent\n role=\"menu\"\n aria-label={headline}\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: exitAndInitialY }}\n initial={{ opacity: 0, y: exitAndInitialY }}\n $position={alignment}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $zIndex={zIndex}\n ref={ref}\n style={{ left: coordinates.x, top: coordinates.y }}\n transition={{ ease: 'anticipate' }}\n transformTemplate={({ y = '0px' }) => `\n translateX(${percentageOffsetX}%)\n translateY(${percentageOffsetY}%)\n translateX(${anchorOffsetX}px)\n translateY(${anchorOffsetY}px)\n translateY(${y})\n `}\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n >\n {headline && (\n <StyledContextMenuContentHeadline>{headline}</StyledContextMenuContentHeadline>\n )}\n {content}\n </StyledMotionContextMenuContent>\n );\n },\n);\n\nContextMenuContent.displayName = 'ContextMenuContent';\n\nexport default ContextMenuContent;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAIA,IAAAI,YAAA,GAAAJ,OAAA;AAI8B,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wB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AAa,GAE1BJ,QAAQ,iBACLlC,MAAA,CAAAS,OAAA,CAAAoD,aAAA,CAACxD,mBAAA,CAAA4E,gCAAgC,QAAE/C,QAA2C,CACjF,EACAuB,OAC2B,CAAC;AAEzC,CACJ,CAAC;AAED/B,kBAAkB,CAACwD,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA3E,OAAA,GAEvCiB,kBAAkB","ignoreList":[]}
|
|
@@ -104,7 +104,9 @@ const StyledMotionContextMenuContent = exports.StyledMotionContextMenuContent =
|
|
|
104
104
|
z-index: -1;
|
|
105
105
|
}
|
|
106
106
|
`;
|
|
107
|
-
const StyledContextMenuContentItem = exports.StyledContextMenuContentItem = _styledComponents.default.div
|
|
107
|
+
const StyledContextMenuContentItem = exports.StyledContextMenuContentItem = _styledComponents.default.div`
|
|
108
|
+
position: relative;
|
|
109
|
+
`;
|
|
108
110
|
const StyledContextMenuContentItemSpacer = exports.StyledContextMenuContentItemSpacer = _styledComponents.default.div`
|
|
109
111
|
background-color: ${({
|
|
110
112
|
theme
|
|
@@ -117,7 +119,12 @@ const StyledContextMenuContentItemWrapper = exports.StyledContextMenuContentItem
|
|
|
117
119
|
border-radius: ${({
|
|
118
120
|
$shouldHidePopupArrow
|
|
119
121
|
}) => $shouldHidePopupArrow ? '3px' : 0};
|
|
120
|
-
cursor:
|
|
122
|
+
cursor: ${({
|
|
123
|
+
$isDisabled
|
|
124
|
+
}) => $isDisabled ? 'default' : 'pointer'};
|
|
125
|
+
opacity: ${({
|
|
126
|
+
$isDisabled
|
|
127
|
+
}) => $isDisabled ? 0.5 : 1};
|
|
121
128
|
display: flex;
|
|
122
129
|
gap: 6px;
|
|
123
130
|
margin: ${({
|
|
@@ -136,8 +143,9 @@ const StyledContextMenuContentItemWrapper = exports.StyledContextMenuContentItem
|
|
|
136
143
|
|
|
137
144
|
&:hover {
|
|
138
145
|
background-color: ${({
|
|
146
|
+
$isDisabled,
|
|
139
147
|
theme
|
|
140
|
-
}) => theme['secondary-103']};
|
|
148
|
+
}) => $isDisabled ? 'transparent' : theme['secondary-103']};
|
|
141
149
|
}
|
|
142
150
|
`;
|
|
143
151
|
const StyledContextMenuContentItemIconWrapper = exports.StyledContextMenuContentItemIconWrapper = _styledComponents.default.div`
|
package/lib/cjs/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuContent.styles.js","names":["_react","require","_styledComponents","_interopRequireWildcard","_ContextMenu","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledMotionContextMenuContent","exports","styled","motion","div","theme","$shouldHidePopupArrow","text","$zIndex","css","$position","ContextMenuAlignment","TopLeft","BottomLeft","TopRight","BottomRight","TopCenter","BottomCenter","undefined","StyledContextMenuContentItem","StyledContextMenuContentItemSpacer","StyledContextMenuContentItemWrapper","$isFocused","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentHeadline","StyledContextMenuContentItemText"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.styles.ts"],"sourcesContent":["import { motion } from 'motion/react';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport { ContextMenuAlignment } from '../ContextMenu.types';\n\ntype StyledMotionContextMenuContentProps = WithTheme<{\n $position: ContextMenuAlignment;\n $zIndex: number;\n $shouldHidePopupArrow: boolean;\n}>;\n\nexport const StyledMotionContextMenuContent = styled(\n motion.div,\n)<StyledMotionContextMenuContentProps>`\n background-color: ${({ theme }: StyledMotionContextMenuContentProps) => theme['001']};\n border: 1px solid rgba(0, 0, 0, 0.1);\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n box-shadow: 1px 3px 8px rgb(0 0 0 / 30%);\n color: ${({ theme }: StyledMotionContextMenuContentProps) => theme.text};\n max-width: 500px;\n pointer-events: all;\n position: absolute;\n z-index: ${({ $zIndex }) => $zIndex};\n\n &::after {\n background-color: inherit;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n border-right: 1px solid rgba(0, 0, 0, 0.1);\n box-shadow: 2px 2px 8px rgb(4 3 4 / 10%);\n content: '';\n height: 14px;\n position: absolute;\n width: 14px;\n z-index: -2;\n\n ${({ $shouldHidePopupArrow }) =>\n $shouldHidePopupArrow &&\n css`\n display: none;\n `}\n\n ${({ $position }) => {\n switch ($position) {\n case ContextMenuAlignment.TopLeft:\n return css`\n bottom: -7px;\n right: 7px;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomLeft:\n return css`\n top: -7px;\n right: 7px;\n transform: rotate(225deg);\n `;\n case ContextMenuAlignment.TopRight:\n return css`\n transform: rotate(45deg);\n bottom: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.BottomRight:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.TopCenter:\n return css`\n bottom: -7px;\n right: 45%;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomCenter:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 45%;\n `;\n\n default:\n return undefined;\n }\n }}\n }\n\n &::before {\n background-color: inherit;\n bottom: 0;\n content: '';\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n z-index: -1;\n }\n`;\n\nexport const StyledContextMenuContentItem = styled.div
|
|
1
|
+
{"version":3,"file":"ContextMenuContent.styles.js","names":["_react","require","_styledComponents","_interopRequireWildcard","_ContextMenu","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledMotionContextMenuContent","exports","styled","motion","div","theme","$shouldHidePopupArrow","text","$zIndex","css","$position","ContextMenuAlignment","TopLeft","BottomLeft","TopRight","BottomRight","TopCenter","BottomCenter","undefined","StyledContextMenuContentItem","StyledContextMenuContentItemSpacer","StyledContextMenuContentItemWrapper","$isDisabled","$isFocused","StyledContextMenuContentItemIconWrapper","StyledContextMenuContentHeadline","StyledContextMenuContentItemText"],"sources":["../../../../../src/components/context-menu/context-menu-content/ContextMenuContent.styles.ts"],"sourcesContent":["import { motion } from 'motion/react';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport { ContextMenuAlignment } from '../ContextMenu.types';\n\ntype StyledMotionContextMenuContentProps = WithTheme<{\n $position: ContextMenuAlignment;\n $zIndex: number;\n $shouldHidePopupArrow: boolean;\n}>;\n\nexport const StyledMotionContextMenuContent = styled(\n motion.div,\n)<StyledMotionContextMenuContentProps>`\n background-color: ${({ theme }: StyledMotionContextMenuContentProps) => theme['001']};\n border: 1px solid rgba(0, 0, 0, 0.1);\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n box-shadow: 1px 3px 8px rgb(0 0 0 / 30%);\n color: ${({ theme }: StyledMotionContextMenuContentProps) => theme.text};\n max-width: 500px;\n pointer-events: all;\n position: absolute;\n z-index: ${({ $zIndex }) => $zIndex};\n\n &::after {\n background-color: inherit;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n border-right: 1px solid rgba(0, 0, 0, 0.1);\n box-shadow: 2px 2px 8px rgb(4 3 4 / 10%);\n content: '';\n height: 14px;\n position: absolute;\n width: 14px;\n z-index: -2;\n\n ${({ $shouldHidePopupArrow }) =>\n $shouldHidePopupArrow &&\n css`\n display: none;\n `}\n\n ${({ $position }) => {\n switch ($position) {\n case ContextMenuAlignment.TopLeft:\n return css`\n bottom: -7px;\n right: 7px;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomLeft:\n return css`\n top: -7px;\n right: 7px;\n transform: rotate(225deg);\n `;\n case ContextMenuAlignment.TopRight:\n return css`\n transform: rotate(45deg);\n bottom: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.BottomRight:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 7px;\n `;\n case ContextMenuAlignment.TopCenter:\n return css`\n bottom: -7px;\n right: 45%;\n transform: rotate(45deg);\n `;\n case ContextMenuAlignment.BottomCenter:\n return css`\n transform: rotate(225deg);\n top: -7px;\n left: 45%;\n `;\n\n default:\n return undefined;\n }\n }}\n }\n\n &::before {\n background-color: inherit;\n bottom: 0;\n content: '';\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '6px' : '3px')};\n z-index: -1;\n }\n`;\n\nexport const StyledContextMenuContentItem = styled.div`\n position: relative;\n`;\n\ntype StyledContextMenuContentItemSpacerProps = WithTheme<unknown>;\n\nexport const StyledContextMenuContentItemSpacer = styled.div<StyledContextMenuContentItemSpacerProps>`\n background-color: ${({ theme }) => theme['003']};\n height: 1px;\n width: 100%;\n`;\n\ntype StyledContextMenuContentItemWrapperProps = WithTheme<{\n $shouldHidePopupArrow: boolean;\n $isFocused: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledContextMenuContentItemWrapper = styled.div<StyledContextMenuContentItemWrapperProps>`\n align-items: center;\n border-radius: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '3px' : 0)};\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'default' : 'pointer')};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n display: flex;\n gap: 6px;\n margin: ${({ $shouldHidePopupArrow }) => ($shouldHidePopupArrow ? '3px' : 0)};\n overflow: hidden;\n padding: 5px 8px;\n transition: background-color 0.3s ease;\n\n ${({ $isFocused, theme }) =>\n $isFocused &&\n css`\n background-color: ${theme['secondary-103']};\n `}\n\n &:hover {\n background-color: ${({ $isDisabled, theme }) =>\n $isDisabled ? 'transparent' : theme['secondary-103']};\n }\n`;\n\nexport const StyledContextMenuContentItemIconWrapper = styled.div`\n display: flex;\n flex: 0 0 auto;\n justify-content: center;\n width: 20px;\n`;\n\nexport const StyledContextMenuContentHeadline = styled.div`\n width: 100%;\n margin: 3px 6px;\n opacity: 50%;\n font-weight: bold;\n`;\n\nexport const StyledContextMenuContentItemText = styled.div`\n flex: 0 1 auto;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAA4D,SAAAE,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA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AM,CAACE,GAAG;AACjE;AACA;AACA;AACA;AACA,CAAC;AAEM,MAAMqB,gCAAgC,GAAAxB,OAAA,CAAAwB,gCAAA,GAAGvB,yBAAM,CAACE,GAAG;AAC1D;AACA;AACA;AACA;AACA,CAAC;AAEM,MAAMsB,gCAAgC,GAAAzB,OAAA,CAAAyB,gCAAA,GAAGxB,yBAAM,CAACE,GAAG;AAC1D;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _Icon = _interopRequireDefault(require("../../../icon/Icon"));
|
|
9
|
+
var _Tooltip = _interopRequireDefault(require("../../../tooltip/Tooltip"));
|
|
10
|
+
var _ContextMenuContent = require("../ContextMenuContent.styles");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
const ContextMenuContentItem = ({
|
|
14
|
+
item,
|
|
15
|
+
index,
|
|
16
|
+
isFocused,
|
|
17
|
+
shouldHidePopupArrow,
|
|
18
|
+
onItemFocus
|
|
19
|
+
}) => {
|
|
20
|
+
const disabledReasonId = (0, _react.useId)();
|
|
21
|
+
const [tooltipContainer, setTooltipContainer] = (0, _react.useState)(null);
|
|
22
|
+
const {
|
|
23
|
+
icons,
|
|
24
|
+
text,
|
|
25
|
+
onClick,
|
|
26
|
+
isDisabled = false,
|
|
27
|
+
disabledReason,
|
|
28
|
+
shouldShowSpacer
|
|
29
|
+
} = item;
|
|
30
|
+
let iconElement = null;
|
|
31
|
+
if (/*#__PURE__*/(0, _react.isValidElement)(icons)) {
|
|
32
|
+
iconElement = icons;
|
|
33
|
+
} else if (Array.isArray(icons) && icons.length > 0) {
|
|
34
|
+
iconElement = /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemIconWrapper, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
35
|
+
icons: icons
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
const content = /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemWrapper, {
|
|
39
|
+
onClick: event => {
|
|
40
|
+
if (isDisabled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
event.stopPropagation();
|
|
45
|
+
void onClick(event);
|
|
46
|
+
},
|
|
47
|
+
tabIndex: 0,
|
|
48
|
+
role: "menuitem",
|
|
49
|
+
"aria-disabled": isDisabled,
|
|
50
|
+
"aria-describedby": isDisabled && disabledReason ? disabledReasonId : undefined,
|
|
51
|
+
$shouldHidePopupArrow: shouldHidePopupArrow,
|
|
52
|
+
$isFocused: isFocused,
|
|
53
|
+
$isDisabled: isDisabled,
|
|
54
|
+
onFocus: () => onItemFocus(index)
|
|
55
|
+
}, iconElement, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemText, null, text));
|
|
56
|
+
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItem, {
|
|
57
|
+
ref: setTooltipContainer,
|
|
58
|
+
className: "context-menu-content-item",
|
|
59
|
+
"data-index": index,
|
|
60
|
+
"aria-disabled": isDisabled,
|
|
61
|
+
onClick: isDisabled ? event => event.stopPropagation() : undefined
|
|
62
|
+
}, isDisabled && disabledReason ? /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
|
|
63
|
+
item: {
|
|
64
|
+
text: disabledReason
|
|
65
|
+
},
|
|
66
|
+
container: tooltipContainer ?? undefined,
|
|
67
|
+
shouldUseFullWidth: true
|
|
68
|
+
}, content) : content, isDisabled && disabledReason && /*#__PURE__*/_react.default.createElement("span", {
|
|
69
|
+
id: disabledReasonId,
|
|
70
|
+
hidden: true
|
|
71
|
+
}, disabledReason), shouldShowSpacer && /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemSpacer, null));
|
|
72
|
+
};
|
|
73
|
+
var _default = exports.default = ContextMenuContentItem;
|
|
74
|
+
//# sourceMappingURL=ContextMenuContentItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenuContentItem.js","names":["_react","_interopRequireWildcard","require","_Icon","_interopRequireDefault","_Tooltip","_ContextMenuContent","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ContextMenuContentItem","item","index","isFocused","shouldHidePopupArrow","onItemFocus","disabledReasonId","useId","tooltipContainer","setTooltipContainer","useState","icons","text","onClick","isDisabled","disabledReason","shouldShowSpacer","iconElement","isValidElement","Array","isArray","length","createElement","StyledContextMenuContentItemIconWrapper","content","StyledContextMenuContentItemWrapper","event","preventDefault","stopPropagation","tabIndex","role","undefined","$shouldHidePopupArrow","$isFocused","$isDisabled","onFocus","StyledContextMenuContentItemText","StyledContextMenuContentItem","ref","className","container","shouldUseFullWidth","id","hidden","StyledContextMenuContentItemSpacer","_default","exports"],"sources":["../../../../../../src/components/context-menu/context-menu-content/context-menu-content-item/ContextMenuContentItem.tsx"],"sourcesContent":["import React, { isValidElement, useId, useState } from 'react';\nimport Icon from '../../../icon/Icon';\nimport Tooltip from '../../../tooltip/Tooltip';\nimport type { ContextMenuItem } from '../../ContextMenu.types';\nimport {\n StyledContextMenuContentItem,\n StyledContextMenuContentItemIconWrapper,\n StyledContextMenuContentItemSpacer,\n StyledContextMenuContentItemText,\n StyledContextMenuContentItemWrapper,\n} from '../ContextMenuContent.styles';\n\ntype ContextMenuContentItemProps = {\n item: ContextMenuItem;\n index: number;\n isFocused: boolean;\n shouldHidePopupArrow: boolean;\n onItemFocus: (index: number) => void;\n};\n\nconst ContextMenuContentItem = ({\n item,\n index,\n isFocused,\n shouldHidePopupArrow,\n onItemFocus,\n}: ContextMenuContentItemProps) => {\n const disabledReasonId = useId();\n\n const [tooltipContainer, setTooltipContainer] = useState<HTMLDivElement | null>(null);\n\n const { icons, text, onClick, isDisabled = false, disabledReason, shouldShowSpacer } = item;\n\n let iconElement = null;\n\n if (isValidElement(icons)) {\n iconElement = icons;\n } else if (Array.isArray(icons) && icons.length > 0) {\n iconElement = (\n <StyledContextMenuContentItemIconWrapper>\n <Icon icons={icons} />\n </StyledContextMenuContentItemIconWrapper>\n );\n }\n\n const content = (\n <StyledContextMenuContentItemWrapper\n onClick={(event) => {\n if (isDisabled) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n void onClick(event);\n }}\n tabIndex={0}\n role=\"menuitem\"\n aria-disabled={isDisabled}\n aria-describedby={isDisabled && disabledReason ? disabledReasonId : undefined}\n $shouldHidePopupArrow={shouldHidePopupArrow}\n $isFocused={isFocused}\n $isDisabled={isDisabled}\n onFocus={() => onItemFocus(index)}\n >\n {iconElement}\n <StyledContextMenuContentItemText>{text}</StyledContextMenuContentItemText>\n </StyledContextMenuContentItemWrapper>\n );\n\n return (\n <StyledContextMenuContentItem\n ref={setTooltipContainer}\n className=\"context-menu-content-item\"\n data-index={index}\n aria-disabled={isDisabled}\n onClick={isDisabled ? (event) => event.stopPropagation() : undefined}\n >\n {isDisabled && disabledReason ? (\n <Tooltip\n item={{ text: disabledReason }}\n container={tooltipContainer ?? undefined}\n shouldUseFullWidth\n >\n {content}\n </Tooltip>\n ) : (\n content\n )}\n {isDisabled && disabledReason && (\n <span id={disabledReasonId} hidden>\n {disabledReason}\n </span>\n )}\n {shouldShowSpacer && <StyledContextMenuContentItemSpacer />}\n </StyledContextMenuContentItem>\n );\n};\n\nexport default ContextMenuContentItem;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,mBAAA,GAAAJ,OAAA;AAMsC,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAM,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAAA,GAAAS,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAG,CA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E,CAChC,CAAC;AAEvC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA/D,OAAA,GAEaiB,sBAAsB","ignoreList":[]}
|
|
@@ -13,6 +13,7 @@ var _useKeyboardFocusHighlighting = require("../../hooks/useKeyboardFocusHighlig
|
|
|
13
13
|
var _slider = require("../../utils/slider");
|
|
14
14
|
var _Slider = require("./Slider.styles");
|
|
15
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
16
|
+
const SLIDER_TRACK_INSET = 40;
|
|
16
17
|
const Slider = ({
|
|
17
18
|
interval,
|
|
18
19
|
isDisabled,
|
|
@@ -44,7 +45,9 @@ const Slider = ({
|
|
|
44
45
|
const fromSliderThumbContentRef = (0, _react.useRef)(null);
|
|
45
46
|
const toSliderThumbContentRef = (0, _react.useRef)(null);
|
|
46
47
|
const sliderWrapperRef = (0, _react.useRef)(null);
|
|
48
|
+
const activePointerIdRef = (0, _react.useRef)(null);
|
|
47
49
|
const sliderWrapperSize = (0, _element.useElementSize)(sliderWrapperRef);
|
|
50
|
+
const sliderTrackWidth = Math.max(((sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width) ?? 0) - SLIDER_TRACK_INSET, 0);
|
|
48
51
|
const theme = (0, _styledComponents.useTheme)();
|
|
49
52
|
const shouldShowKeyboardHighlighting = (0, _useKeyboardFocusHighlighting.useKeyboardFocusHighlighting)(shouldEnableKeyboardHighlighting && !isDisabled);
|
|
50
53
|
(0, _useFocusRingPortal.useFocusRingPortal)(fromSliderRef, {
|
|
@@ -177,6 +180,16 @@ const Slider = ({
|
|
|
177
180
|
// Note: An interval can't be in the deps because of rerender
|
|
178
181
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
179
182
|
}, [theme]);
|
|
183
|
+
const normalizeSingleValue = (0, _react.useCallback)(rawValue => {
|
|
184
|
+
const effectiveMin = typeof minEnabledValue === 'number' ? Math.max(minValue, minEnabledValue) : minValue;
|
|
185
|
+
const effectiveMax = typeof maxEnabledValue === 'number' ? Math.min(maxValue, maxEnabledValue) : maxValue;
|
|
186
|
+
let newValue = rawValue;
|
|
187
|
+
if (Number.isNaN(newValue)) {
|
|
188
|
+
newValue = effectiveMin;
|
|
189
|
+
}
|
|
190
|
+
if (newValue < effectiveMin) newValue = effectiveMin;else if (newValue > effectiveMax - effectiveMax % step) newValue = effectiveMax;else newValue = Math.round(newValue / step) * step;
|
|
191
|
+
return newValue;
|
|
192
|
+
}, [maxEnabledValue, maxValue, minEnabledValue, minValue, step]);
|
|
180
193
|
|
|
181
194
|
/**
|
|
182
195
|
* This function updates the value
|
|
@@ -191,50 +204,78 @@ const Slider = ({
|
|
|
191
204
|
handleControlFromSlider(event);
|
|
192
205
|
return;
|
|
193
206
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const effectiveMax = typeof maxEnabledValue === 'number' ? Math.min(maxValue, maxEnabledValue) : maxValue;
|
|
198
|
-
let newValue = Number(event.target.value);
|
|
199
|
-
|
|
200
|
-
// Clamp to effective range first
|
|
201
|
-
if (Number.isNaN(newValue)) {
|
|
202
|
-
newValue = effectiveMin;
|
|
207
|
+
const newValue = normalizeSingleValue(Number(event.target.value));
|
|
208
|
+
if (typeof onChange === 'function' && newValue !== previousFromValueRef.current) {
|
|
209
|
+
onChange(newValue);
|
|
203
210
|
}
|
|
204
|
-
|
|
211
|
+
updateFromValue(newValue);
|
|
212
|
+
}, [handleControlFromSlider, interval, isDisabled, maxEnabledValue, normalizeSingleValue, onChange, updateFromValue]);
|
|
213
|
+
const updateValueFromPointer = (0, _react.useCallback)(event => {
|
|
214
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
215
|
+
const relativePosition = (event.clientX - bounds.left - SLIDER_TRACK_INSET / 2) / sliderTrackWidth;
|
|
216
|
+
const rawValue = minValue + Math.min(Math.max(relativePosition, 0), 1) * (maxValue - minValue);
|
|
217
|
+
const newValue = normalizeSingleValue(rawValue);
|
|
205
218
|
if (typeof onChange === 'function' && newValue !== previousFromValueRef.current) {
|
|
206
219
|
onChange(newValue);
|
|
207
220
|
}
|
|
208
221
|
updateFromValue(newValue);
|
|
209
|
-
|
|
210
|
-
|
|
222
|
+
return newValue;
|
|
223
|
+
}, [maxValue, minValue, normalizeSingleValue, onChange, sliderTrackWidth, updateFromValue]);
|
|
224
|
+
const handlePointerDown = (0, _react.useCallback)(event => {
|
|
211
225
|
var _fromSliderRef$curren2;
|
|
212
|
-
if (
|
|
226
|
+
if (isDisabled || interval || event.button !== 0) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
activePointerIdRef.current = event.pointerId;
|
|
231
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
232
|
+
(_fromSliderRef$curren2 = fromSliderRef.current) === null || _fromSliderRef$curren2 === void 0 || _fromSliderRef$curren2.focus();
|
|
233
|
+
updateValueFromPointer(event);
|
|
234
|
+
}, [interval, isDisabled, updateValueFromPointer]);
|
|
235
|
+
const handlePointerMove = (0, _react.useCallback)(event => {
|
|
236
|
+
if (activePointerIdRef.current !== event.pointerId) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
updateValueFromPointer(event);
|
|
241
|
+
}, [updateValueFromPointer]);
|
|
242
|
+
const handlePointerUp = (0, _react.useCallback)(event => {
|
|
243
|
+
if (activePointerIdRef.current !== event.pointerId) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
activePointerIdRef.current = null;
|
|
248
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
249
|
+
if (typeof onSelect === 'function') {
|
|
250
|
+
onSelect(updateValueFromPointer(event));
|
|
251
|
+
}
|
|
252
|
+
}, [onSelect, updateValueFromPointer]);
|
|
253
|
+
const fromSliderThumbPosition = (0, _react.useMemo)(() => {
|
|
254
|
+
if (typeof (sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width) === 'number') {
|
|
213
255
|
return (0, _slider.calculateGradientOffset)({
|
|
214
256
|
maxValue,
|
|
215
257
|
minValue,
|
|
216
|
-
sliderWidth:
|
|
258
|
+
sliderWidth: sliderTrackWidth,
|
|
217
259
|
thumbWidth: 20,
|
|
218
260
|
value: fromValue,
|
|
219
261
|
wrapperWidth: sliderWrapperSize.width
|
|
220
262
|
});
|
|
221
263
|
}
|
|
222
264
|
return 0;
|
|
223
|
-
}, [fromValue, maxValue, minValue, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width]);
|
|
265
|
+
}, [fromValue, maxValue, minValue, sliderTrackWidth, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width]);
|
|
224
266
|
const toSliderThumbPosition = (0, _react.useMemo)(() => {
|
|
225
|
-
|
|
226
|
-
if (typeof ((_toSliderRef$current2 = toSliderRef.current) === null || _toSliderRef$current2 === void 0 ? void 0 : _toSliderRef$current2.offsetWidth) === 'number' && typeof (sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width) === 'number') {
|
|
267
|
+
if (typeof (sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width) === 'number') {
|
|
227
268
|
return (0, _slider.calculateGradientOffset)({
|
|
228
269
|
maxValue,
|
|
229
270
|
minValue,
|
|
230
|
-
sliderWidth:
|
|
271
|
+
sliderWidth: sliderTrackWidth,
|
|
231
272
|
thumbWidth: 20,
|
|
232
273
|
value: toValue,
|
|
233
274
|
wrapperWidth: sliderWrapperSize.width
|
|
234
275
|
});
|
|
235
276
|
}
|
|
236
277
|
return 0;
|
|
237
|
-
}, [maxValue, minValue, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width, toValue]);
|
|
278
|
+
}, [maxValue, minValue, sliderTrackWidth, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width, toValue]);
|
|
238
279
|
const toSliderThumbContentPosition = (0, _react.useMemo)(() => (0, _slider.calculatePopupPosition)({
|
|
239
280
|
min: minValue,
|
|
240
281
|
max: maxValue,
|
|
@@ -257,44 +298,41 @@ const Slider = ({
|
|
|
257
298
|
}
|
|
258
299
|
}, [isDisabled, shouldShowThumbLabel]);
|
|
259
300
|
const handleTouchEnd = (0, _react.useCallback)(() => {
|
|
260
|
-
var _fromSliderRef$curren3, _toSliderRef$
|
|
301
|
+
var _fromSliderRef$curren3, _toSliderRef$current2;
|
|
261
302
|
if (isDisabled) {
|
|
262
303
|
return;
|
|
263
304
|
}
|
|
264
305
|
void (0, _chaynsApi.setRefreshScrollEnabled)(true);
|
|
265
306
|
const from = Number((_fromSliderRef$curren3 = fromSliderRef.current) === null || _fromSliderRef$curren3 === void 0 ? void 0 : _fromSliderRef$curren3.value);
|
|
266
|
-
const to = Number((_toSliderRef$
|
|
267
|
-
if (typeof onSelect === 'function') {
|
|
268
|
-
onSelect(
|
|
307
|
+
const to = Number((_toSliderRef$current2 = toSliderRef.current) === null || _toSliderRef$current2 === void 0 ? void 0 : _toSliderRef$current2.value);
|
|
308
|
+
if (interval && typeof onSelect === 'function') {
|
|
309
|
+
onSelect(undefined, {
|
|
269
310
|
maxValue: to,
|
|
270
311
|
minValue: from
|
|
271
|
-
}
|
|
312
|
+
});
|
|
272
313
|
}
|
|
273
314
|
if (shouldShowThumbLabel) {
|
|
274
315
|
setIsBigSlider(false);
|
|
275
316
|
}
|
|
276
317
|
}, [interval, isDisabled, onSelect, shouldShowThumbLabel]);
|
|
277
318
|
const highlightedStepElements = (0, _react.useMemo)(() => {
|
|
278
|
-
var _fromSliderRef$curren4;
|
|
279
|
-
const sliderWidth = ((_fromSliderRef$curren4 = fromSliderRef.current) === null || _fromSliderRef$curren4 === void 0 ? void 0 : _fromSliderRef$curren4.offsetWidth) ?? 0;
|
|
280
319
|
const wrapperWidth = (sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width) ?? 0;
|
|
281
|
-
if (!shouldHighlightSteps || interval ||
|
|
320
|
+
if (!shouldHighlightSteps || interval || sliderTrackWidth === 0 || wrapperWidth === 0) {
|
|
282
321
|
return null;
|
|
283
322
|
}
|
|
284
323
|
const elements = [];
|
|
285
324
|
for (let i = minValue; i <= maxValue; i += step) {
|
|
286
325
|
const isStepDisabled = typeof minEnabledValue === 'number' && i < minEnabledValue || typeof maxEnabledValue === 'number' && i > maxEnabledValue;
|
|
287
|
-
const offset = (wrapperWidth -
|
|
288
|
-
const stepWidth = sliderWidth / (maxValue - minValue) * step;
|
|
326
|
+
const offset = (wrapperWidth - sliderTrackWidth) / 2;
|
|
289
327
|
elements.push(/*#__PURE__*/_react.default.createElement(_Slider.StyledHighlightedStep, {
|
|
290
328
|
key: `step--${i}`,
|
|
291
329
|
$isDisabled: isStepDisabled,
|
|
292
330
|
$isFilled: i < fromValue,
|
|
293
|
-
$leftPosition: offset +
|
|
331
|
+
$leftPosition: offset + (i - minValue) / (maxValue - minValue) * sliderTrackWidth
|
|
294
332
|
}));
|
|
295
333
|
}
|
|
296
334
|
return elements;
|
|
297
|
-
}, [fromValue, interval, maxEnabledValue, maxValue, minEnabledValue, minValue, shouldHighlightSteps, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width, step]);
|
|
335
|
+
}, [fromValue, interval, maxEnabledValue, maxValue, minEnabledValue, minValue, shouldHighlightSteps, sliderTrackWidth, sliderWrapperSize === null || sliderWrapperSize === void 0 ? void 0 : sliderWrapperSize.width, step]);
|
|
298
336
|
const fromInputBackground = (0, _react.useMemo)(() => {
|
|
299
337
|
if (interval) return undefined;
|
|
300
338
|
const gradientPoints = [];
|
|
@@ -319,7 +357,10 @@ const Slider = ({
|
|
|
319
357
|
}, [fromValue, interval, maxEnabledValue, maxValue, minEnabledValue, minValue, theme]);
|
|
320
358
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Slider.StyledSlider, {
|
|
321
359
|
ref: sliderWrapperRef,
|
|
322
|
-
$isDisabled: isDisabled
|
|
360
|
+
$isDisabled: isDisabled,
|
|
361
|
+
onPointerDown: handlePointerDown,
|
|
362
|
+
onPointerMove: handlePointerMove,
|
|
363
|
+
onPointerUp: handlePointerUp
|
|
323
364
|
}, highlightedStepElements, /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderInput, {
|
|
324
365
|
animate: {
|
|
325
366
|
height: isBigSlider ? 30 : 10
|
|
@@ -330,7 +371,7 @@ const Slider = ({
|
|
|
330
371
|
exit: {
|
|
331
372
|
height: 10
|
|
332
373
|
},
|
|
333
|
-
$
|
|
374
|
+
$trackInset: SLIDER_TRACK_INSET,
|
|
334
375
|
ref: fromSliderRef,
|
|
335
376
|
$isInterval: !!interval,
|
|
336
377
|
type: "range",
|
|
@@ -341,7 +382,7 @@ const Slider = ({
|
|
|
341
382
|
onTouchStart: handleTouchStart,
|
|
342
383
|
onTouchEnd: handleTouchEnd,
|
|
343
384
|
onChange: handleInputChange,
|
|
344
|
-
onMouseUp: handleMouseUp,
|
|
385
|
+
onMouseUp: interval ? handleMouseUp : undefined,
|
|
345
386
|
$background: fromInputBackground,
|
|
346
387
|
onFocus: () => {
|
|
347
388
|
setIsFromThumbFocused(true);
|
|
@@ -378,7 +419,7 @@ const Slider = ({
|
|
|
378
419
|
exit: {
|
|
379
420
|
height: 10
|
|
380
421
|
},
|
|
381
|
-
$
|
|
422
|
+
$trackInset: SLIDER_TRACK_INSET,
|
|
382
423
|
ref: toSliderRef,
|
|
383
424
|
$isInterval: !!interval,
|
|
384
425
|
type: "range",
|
|
@@ -397,7 +438,7 @@ const Slider = ({
|
|
|
397
438
|
onBlur: () => {
|
|
398
439
|
setIsToThumbFocused(false);
|
|
399
440
|
}
|
|
400
|
-
})), [fromInputBackground, fromSliderThumbContentPosition, fromSliderThumbPosition, fromValue, handleControlToSlider, handleInputChange, handleMouseUp, handleTouchEnd, handleTouchStart, highlightedStepElements, interval, isBigSlider, isDisabled, isFromThumbFocused, isToThumbFocused, maxValue, minValue, shouldShowThumbLabel, shouldShowKeyboardHighlighting, thumbLabelFormatter, thumbWidth, toSliderThumbContentPosition, toSliderThumbPosition, toValue]);
|
|
441
|
+
})), [fromInputBackground, fromSliderThumbContentPosition, fromSliderThumbPosition, fromValue, handleControlToSlider, handleInputChange, handleMouseUp, handlePointerDown, handlePointerMove, handlePointerUp, handleTouchEnd, handleTouchStart, highlightedStepElements, interval, isBigSlider, isDisabled, isFromThumbFocused, isToThumbFocused, maxValue, minValue, shouldShowThumbLabel, shouldShowKeyboardHighlighting, thumbLabelFormatter, thumbWidth, toSliderThumbContentPosition, toSliderThumbPosition, toValue]);
|
|
401
442
|
};
|
|
402
443
|
Slider.displayName = 'Slider';
|
|
403
444
|
var _default = exports.default = Slider;
|