@chayns-components/core 5.0.0-beta.516 → 5.0.0-beta.519
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/list/list-item/ListItem.js +3 -2
- package/lib/components/list/list-item/ListItem.js.map +1 -1
- package/lib/components/list/list-item/list-item-head/ListItemHead.js +1 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.js.map +1 -1
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.d.ts +1 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js +14 -5
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js.map +1 -1
- package/lib/components/slider-button/SliderButton.js +20 -11
- package/lib/components/slider-button/SliderButton.js.map +1 -1
- package/package.json +2 -2
|
@@ -54,6 +54,7 @@ const ListItem = _ref => {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
}, [isDefaultOpen, updateOpenItemUuid, uuid]);
|
|
57
|
+
const isClickable = typeof onClick === 'function' || isExpandable;
|
|
57
58
|
return /*#__PURE__*/React.createElement(StyledMotionListItem, {
|
|
58
59
|
animate: {
|
|
59
60
|
height: 'auto',
|
|
@@ -69,7 +70,7 @@ const ListItem = _ref => {
|
|
|
69
70
|
opacity: 0
|
|
70
71
|
},
|
|
71
72
|
key: `list-item-${uuid}`,
|
|
72
|
-
$isClickable:
|
|
73
|
+
$isClickable: isClickable,
|
|
73
74
|
$isOpen: isItemOpen,
|
|
74
75
|
$isWrapped: isWrapped
|
|
75
76
|
}, /*#__PURE__*/React.createElement(ListItemHead, {
|
|
@@ -79,7 +80,7 @@ const ListItem = _ref => {
|
|
|
79
80
|
isAnyItemExpandable: isAnyItemExpandable,
|
|
80
81
|
isExpandable: isExpandable,
|
|
81
82
|
isOpen: isItemOpen,
|
|
82
|
-
onClick: handleHeadClick,
|
|
83
|
+
onClick: isClickable ? handleHeadClick : undefined,
|
|
83
84
|
onLongPress: onLongPress,
|
|
84
85
|
leftElements: leftElements,
|
|
85
86
|
rightElements: rightElements,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItem.js","names":["AnimatePresence","React","useCallback","useContext","useEffect","useUuid","ListContext","ListItemBody","ListItemHead","StyledMotionListItem","ListItem","_ref","children","hoverItem","icons","images","isDefaultOpen","isOpen","onClick","onLongPress","leftElements","rightElements","subtitle","shouldShowRoundImage","title","incrementExpandableItemCount","isAnyItemExpandable","isWrapped","openItemUuid","updateOpenItemUuid","uuid","isExpandable","undefined","isItemOpen","handleHeadClick","event","shouldOnlyOpen","createElement","animate","height","opacity","className","exit","initial","key","$isClickable","$isOpen","$isWrapped","id","displayName"],"sources":["../../../../src/components/list/list-item/ListItem.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n FC,\n MouseEventHandler,\n ReactNode,\n TouchEventHandler,\n useCallback,\n useContext,\n useEffect,\n} from 'react';\nimport { useUuid } from '../../../hooks/uuid';\nimport { ListContext } from '../List';\nimport ListItemBody from './list-item-body/ListItemBody';\nimport ListItemHead from './list-item-head/ListItemHead';\nimport { StyledMotionListItem } from './ListItem.styles';\n\nexport type ListItemProps = {\n /**\n * The content of the `ListItem` body. When the `ListItem` has children,\n * it can be opened and also gets an icon as an indicator automatically.\n */\n children?: ReactNode;\n /**\n * Element that is displayed when hovering over the `ListItem` on the right\n * side. On mobile devices, this element is not displayed.\n */\n hoverItem?: ReactNode;\n /**\n * The FontAwesome or tobit icons to render like an image on the left side\n * of the header. Multiple icons are stacked. See the `Icon` component\n * documentation for more information.\n */\n icons?: string[];\n /**\n * A list of image URLs that are displayed on the left side of the header.\n * If multiple URLs are passed, the image is assembled from the first three\n * image URLs as a puzzle.\n */\n images?: string[];\n /**\n * This can be used to automatically expand the `ListItem` during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This overrides the internal opening state of the item and makes it controlled.\n */\n isOpen?: boolean;\n /**\n * Function to be executed when the header of the `ListItem` was clicked\n */\n onClick?: MouseEventHandler<HTMLDivElement>;\n /**\n * Function to be executed when the header of the `ListItem` is pressed for\n * 400 milliseconds.\n */\n onLongPress?: TouchEventHandler<HTMLDivElement>;\n /**\n * Elements that are displayed on the left side of the header. If multiple\n * elements are specified, they are displayed one aside the other.\n */\n leftElements?: [ReactNode, ...ReactNode[]];\n /**\n * Elements that are displayed on the right side of the header. If multiple\n * elements are specified, they are displayed one below the other.\n */\n rightElements?: [ReactNode, ...ReactNode[]];\n /**\n * Images of users should always be displayed in a round shape. Therefore,\n * this property can be set to true.\n */\n shouldShowRoundImage?: boolean;\n /**\n * Subtitle of the `ListItem` displayed in the head below the title\n */\n subtitle?: ReactNode;\n /**\n * Title of the `ListItem` displayed in the head\n */\n title: ReactNode;\n};\n\nconst ListItem: FC<ListItemProps> = ({\n children,\n hoverItem,\n icons,\n images,\n isDefaultOpen,\n isOpen,\n onClick,\n onLongPress,\n leftElements,\n rightElements,\n subtitle,\n shouldShowRoundImage,\n title,\n}) => {\n const {\n incrementExpandableItemCount,\n isAnyItemExpandable,\n isWrapped,\n openItemUuid,\n updateOpenItemUuid,\n } = useContext(ListContext);\n\n const uuid = useUuid();\n\n const isExpandable = children !== undefined;\n const isItemOpen = isOpen ?? openItemUuid === uuid;\n\n const handleHeadClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n if (isExpandable) {\n updateOpenItemUuid(uuid);\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n },\n [isExpandable, onClick, updateOpenItemUuid, uuid],\n );\n\n useEffect(() => {\n if (isExpandable) {\n // The incrementExpandableItemCount function returns an cleanup\n // function to decrement expandableItemCount if component unmounts\n return incrementExpandableItemCount();\n }\n\n return undefined;\n }, [incrementExpandableItemCount, isExpandable]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n updateOpenItemUuid(uuid, { shouldOnlyOpen: true });\n }\n }, [isDefaultOpen, updateOpenItemUuid, uuid]);\n\n return (\n <StyledMotionListItem\n animate={{ height: 'auto', opacity: 1 }}\n className=\"beta-chayns-list-item\"\n exit={{ height: 0, opacity: 0 }}\n initial={{ height: 0, opacity: 0 }}\n key={`list-item-${uuid}`}\n $isClickable={
|
|
1
|
+
{"version":3,"file":"ListItem.js","names":["AnimatePresence","React","useCallback","useContext","useEffect","useUuid","ListContext","ListItemBody","ListItemHead","StyledMotionListItem","ListItem","_ref","children","hoverItem","icons","images","isDefaultOpen","isOpen","onClick","onLongPress","leftElements","rightElements","subtitle","shouldShowRoundImage","title","incrementExpandableItemCount","isAnyItemExpandable","isWrapped","openItemUuid","updateOpenItemUuid","uuid","isExpandable","undefined","isItemOpen","handleHeadClick","event","shouldOnlyOpen","isClickable","createElement","animate","height","opacity","className","exit","initial","key","$isClickable","$isOpen","$isWrapped","id","displayName"],"sources":["../../../../src/components/list/list-item/ListItem.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n FC,\n MouseEventHandler,\n ReactNode,\n TouchEventHandler,\n useCallback,\n useContext,\n useEffect,\n} from 'react';\nimport { useUuid } from '../../../hooks/uuid';\nimport { ListContext } from '../List';\nimport ListItemBody from './list-item-body/ListItemBody';\nimport ListItemHead from './list-item-head/ListItemHead';\nimport { StyledMotionListItem } from './ListItem.styles';\n\nexport type ListItemProps = {\n /**\n * The content of the `ListItem` body. When the `ListItem` has children,\n * it can be opened and also gets an icon as an indicator automatically.\n */\n children?: ReactNode;\n /**\n * Element that is displayed when hovering over the `ListItem` on the right\n * side. On mobile devices, this element is not displayed.\n */\n hoverItem?: ReactNode;\n /**\n * The FontAwesome or tobit icons to render like an image on the left side\n * of the header. Multiple icons are stacked. See the `Icon` component\n * documentation for more information.\n */\n icons?: string[];\n /**\n * A list of image URLs that are displayed on the left side of the header.\n * If multiple URLs are passed, the image is assembled from the first three\n * image URLs as a puzzle.\n */\n images?: string[];\n /**\n * This can be used to automatically expand the `ListItem` during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This overrides the internal opening state of the item and makes it controlled.\n */\n isOpen?: boolean;\n /**\n * Function to be executed when the header of the `ListItem` was clicked\n */\n onClick?: MouseEventHandler<HTMLDivElement>;\n /**\n * Function to be executed when the header of the `ListItem` is pressed for\n * 400 milliseconds.\n */\n onLongPress?: TouchEventHandler<HTMLDivElement>;\n /**\n * Elements that are displayed on the left side of the header. If multiple\n * elements are specified, they are displayed one aside the other.\n */\n leftElements?: [ReactNode, ...ReactNode[]];\n /**\n * Elements that are displayed on the right side of the header. If multiple\n * elements are specified, they are displayed one below the other.\n */\n rightElements?: [ReactNode, ...ReactNode[]];\n /**\n * Images of users should always be displayed in a round shape. Therefore,\n * this property can be set to true.\n */\n shouldShowRoundImage?: boolean;\n /**\n * Subtitle of the `ListItem` displayed in the head below the title\n */\n subtitle?: ReactNode;\n /**\n * Title of the `ListItem` displayed in the head\n */\n title: ReactNode;\n};\n\nconst ListItem: FC<ListItemProps> = ({\n children,\n hoverItem,\n icons,\n images,\n isDefaultOpen,\n isOpen,\n onClick,\n onLongPress,\n leftElements,\n rightElements,\n subtitle,\n shouldShowRoundImage,\n title,\n}) => {\n const {\n incrementExpandableItemCount,\n isAnyItemExpandable,\n isWrapped,\n openItemUuid,\n updateOpenItemUuid,\n } = useContext(ListContext);\n\n const uuid = useUuid();\n\n const isExpandable = children !== undefined;\n const isItemOpen = isOpen ?? openItemUuid === uuid;\n\n const handleHeadClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n if (isExpandable) {\n updateOpenItemUuid(uuid);\n }\n\n if (typeof onClick === 'function') {\n onClick(event);\n }\n },\n [isExpandable, onClick, updateOpenItemUuid, uuid],\n );\n\n useEffect(() => {\n if (isExpandable) {\n // The incrementExpandableItemCount function returns an cleanup\n // function to decrement expandableItemCount if component unmounts\n return incrementExpandableItemCount();\n }\n\n return undefined;\n }, [incrementExpandableItemCount, isExpandable]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n updateOpenItemUuid(uuid, { shouldOnlyOpen: true });\n }\n }, [isDefaultOpen, updateOpenItemUuid, uuid]);\n\n const isClickable = typeof onClick === 'function' || isExpandable;\n\n return (\n <StyledMotionListItem\n animate={{ height: 'auto', opacity: 1 }}\n className=\"beta-chayns-list-item\"\n exit={{ height: 0, opacity: 0 }}\n initial={{ height: 0, opacity: 0 }}\n key={`list-item-${uuid}`}\n $isClickable={isClickable}\n $isOpen={isItemOpen}\n $isWrapped={isWrapped}\n >\n <ListItemHead\n hoverItem={hoverItem}\n icons={icons}\n images={images}\n isAnyItemExpandable={isAnyItemExpandable}\n isExpandable={isExpandable}\n isOpen={isItemOpen}\n onClick={isClickable ? handleHeadClick : undefined}\n onLongPress={onLongPress}\n leftElements={leftElements}\n rightElements={rightElements}\n subtitle={subtitle}\n shouldShowRoundImage={shouldShowRoundImage}\n title={title}\n />\n <AnimatePresence initial={false}>\n {isExpandable && isItemOpen && <ListItemBody id={uuid}>{children}</ListItemBody>}\n </AnimatePresence>\n </StyledMotionListItem>\n );\n};\n\nListItem.displayName = 'ListItem';\n\nexport default ListItem;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAKRC,WAAW,EACXC,UAAU,EACVC,SAAS,QACN,OAAO;AACd,SAASC,OAAO,QAAQ,qBAAqB;AAC7C,SAASC,WAAW,QAAQ,SAAS;AACrC,OAAOC,YAAY,MAAM,+BAA+B;AACxD,OAAOC,YAAY,MAAM,+BAA+B;AACxD,SAASC,oBAAoB,QAAQ,mBAAmB;AAmExD,MAAMC,QAA2B,GAAGC,IAAA,IAc9B;EAAA,IAd+B;IACjCC,QAAQ;IACRC,SAAS;IACTC,KAAK;IACLC,MAAM;IACNC,aAAa;IACbC,MAAM;IACNC,OAAO;IACPC,WAAW;IACXC,YAAY;IACZC,aAAa;IACbC,QAAQ;IACRC,oBAAoB;IACpBC;EACJ,CAAC,GAAAb,IAAA;EACG,MAAM;IACFc,4BAA4B;IAC5BC,mBAAmB;IACnBC,SAAS;IACTC,YAAY;IACZC;EACJ,CAAC,GAAG1B,UAAU,CA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EAAG,aAAYf,IAAK,EAAE;IACzBgB,YAAY,EAAET,WAAY;IAC1BU,OAAO,EAAEd,UAAW;IACpBe,UAAU,EAAErB;EAAU,gBAEtB1B,KAAA,CAAAqC,aAAA,CAAC9B,YAAY;IACTK,SAAS,EAAEA,SAAU;IACrBC,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfW,mBAAmB,EAAEA,mBAAoB;IACzCK,YAAY,EAAEA,YAAa;IAC3Bd,MAAM,EAAEgB,UAAW;IACnBf,OAAO,EAAEmB,WAAW,GAAGH,eAAe,GAAGF,SAAU;IACnDb,WAAW,EAAEA,WAAY;IACzBC,YAAY,EAAEA,YAAa;IAC3BC,aAAa,EAAEA,aAAc;IAC7BC,QAAQ,EAAEA,QAAS;IACnBC,oBAAoB,EAAEA,oBAAqB;IAC3CC,KAAK,EAAEA;EAAM,CAChB,CAAC,eACFvB,KAAA,CAAAqC,aAAA,CAACtC,eAAe;IAAC4C,OAAO,EAAE;EAAM,GAC3Bb,YAAY,IAAIE,UAAU,iBAAIhC,KAAA,CAAAqC,aAAA,CAAC/B,YAAY;IAAC0C,EAAE,EAAEnB;EAAK,GAAElB,QAAuB,CAClE,CACC,CAAC;AAE/B,CAAC;AAEDF,QAAQ,CAACwC,WAAW,GAAG,UAAU;AAEjC,eAAexC,QAAQ"}
|
|
@@ -50,6 +50,7 @@ const ListItemHead = _ref => {
|
|
|
50
50
|
return /*#__PURE__*/React.createElement(StyledListItemHead, {
|
|
51
51
|
className: "beta-chayns-list-item-head",
|
|
52
52
|
$isClickable: typeof onClick === 'function' || isExpandable,
|
|
53
|
+
$isAnyItemExpandable: isAnyItemExpandable,
|
|
53
54
|
onClick: onClick,
|
|
54
55
|
onMouseEnter: handleMouseEnter,
|
|
55
56
|
onMouseLeave: handleMouseLeave,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItemHead.js","names":["React","useCallback","useMemo","useRef","useState","Icon","ListItemIcon","ListItemImage","StyledListItemHead","StyledListItemHeadBottomRightElement","StyledListItemHeadContent","StyledListItemHeadRightElement","StyledListItemHeadSubtitle","StyledListItemHeadSubtitleText","StyledListItemHeadTitle","StyledListItemHeadTitleText","StyledListItemHeadTopRightElement","StyledMotionListItemHeadHoverItem","StyledMotionListItemHeadIndicator","ListItemHead","_ref","hoverItem","icons","images","isAnyItemExpandable","isExpandable","isOpen","onClick","onLongPress","rightElements","subtitle","shouldShowRoundImage","title","leftElements","shouldShowHoverItem","setShouldShowHoverItem","longPressTimeoutRef","handleMouseEnter","handleMouseLeave","handleTouchStart","event","current","window","setTimeout","handleTouchEnd","clearTimeout","iconOrImageElement","createElement","undefined","className","$isClickable","onMouseEnter","onMouseLeave","onTouchStart","onTouchEnd","animate","rotate","initial","transition","type","$isIconOrImageGiven","$isOpen","length","marginLeft","opacity","width","duration","displayName"],"sources":["../../../../../src/components/list/list-item/list-item-head/ListItemHead.tsx"],"sourcesContent":["import React, {\n FC,\n MouseEventHandler,\n ReactNode,\n TouchEventHandler,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport Icon from '../../../icon/Icon';\nimport ListItemIcon from './list-item-icon/ListItemIcon';\nimport ListItemImage from './list-item-image/ListItemImage';\nimport {\n StyledListItemHead,\n StyledListItemHeadBottomRightElement,\n StyledListItemHeadContent,\n StyledListItemHeadRightElement,\n StyledListItemHeadSubtitle,\n StyledListItemHeadSubtitleText,\n StyledListItemHeadTitle,\n StyledListItemHeadTitleText,\n StyledListItemHeadTopRightElement,\n StyledMotionListItemHeadHoverItem,\n StyledMotionListItemHeadIndicator,\n} from './ListItemHead.styles';\n\ntype ListItemHeadProps = {\n hoverItem?: ReactNode;\n icons?: string[];\n images?: string[];\n isAnyItemExpandable: boolean;\n isExpandable: boolean;\n isOpen: boolean;\n onClick?: MouseEventHandler<HTMLDivElement>;\n onLongPress?: TouchEventHandler<HTMLDivElement>;\n rightElements?: [ReactNode, ...ReactNode[]];\n subtitle?: ReactNode;\n leftElements?: ReactNode;\n shouldShowRoundImage?: boolean;\n title: ReactNode;\n};\n\nconst ListItemHead: FC<ListItemHeadProps> = ({\n hoverItem,\n icons,\n images,\n isAnyItemExpandable,\n isExpandable,\n isOpen,\n onClick,\n onLongPress,\n rightElements,\n subtitle,\n shouldShowRoundImage,\n title,\n leftElements,\n}) => {\n const [shouldShowHoverItem, setShouldShowHoverItem] = useState(false);\n\n const longPressTimeoutRef = useRef<number>();\n\n const handleMouseEnter = useCallback(() => setShouldShowHoverItem(true), []);\n\n const handleMouseLeave = useCallback(() => setShouldShowHoverItem(false), []);\n\n const handleTouchStart = useCallback<TouchEventHandler<HTMLDivElement>>(\n (event) => {\n longPressTimeoutRef.current = window.setTimeout(() => {\n if (typeof onLongPress === 'function') {\n onLongPress(event);\n }\n }, 400);\n },\n [onLongPress],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(longPressTimeoutRef.current);\n }, []);\n\n const iconOrImageElement = useMemo(() => {\n if (icons) {\n return <ListItemIcon icons={icons} />;\n }\n\n if (images) {\n return <ListItemImage images={images} shouldShowRoundImage={!!shouldShowRoundImage} />;\n }\n\n return undefined;\n }, [icons, images, shouldShowRoundImage]);\n\n return (\n <StyledListItemHead\n className=\"beta-chayns-list-item-head\"\n $isClickable={typeof onClick === 'function' || isExpandable}\n onClick={onClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onTouchStart={typeof onLongPress === 'function' ? handleTouchStart : undefined}\n onTouchEnd={typeof onLongPress === 'function' ? handleTouchEnd : undefined}\n >\n {isAnyItemExpandable && (\n <StyledMotionListItemHeadIndicator\n animate={{ rotate: isOpen ? 90 : 0 }}\n initial={false}\n transition={{ type: 'tween' }}\n >\n {isExpandable && <Icon icons={['fa fa-chevron-right']} />}\n </StyledMotionListItemHeadIndicator>\n )}\n {leftElements}\n {iconOrImageElement}\n <StyledListItemHeadContent\n $isIconOrImageGiven={iconOrImageElement !== undefined}\n $isOpen={isOpen}\n >\n <StyledListItemHeadTitle>\n <StyledListItemHeadTitleText className=\"ellipsis\">\n {title}\n </StyledListItemHeadTitleText>\n {rightElements && rightElements.length > 1 && rightElements[0] && (\n <StyledListItemHeadTopRightElement>\n {rightElements[0]}\n </StyledListItemHeadTopRightElement>\n )}\n </StyledListItemHeadTitle>\n {subtitle && (\n <StyledListItemHeadSubtitle>\n <StyledListItemHeadSubtitleText className=\"ellipsis\">\n {subtitle}\n </StyledListItemHeadSubtitleText>\n {rightElements && rightElements.length > 1 && rightElements[1] && (\n <StyledListItemHeadBottomRightElement>\n {rightElements[1]}\n </StyledListItemHeadBottomRightElement>\n )}\n </StyledListItemHeadSubtitle>\n )}\n </StyledListItemHeadContent>\n {rightElements?.length === 1 && (\n <StyledListItemHeadRightElement>{rightElements[0]}</StyledListItemHeadRightElement>\n )}\n {hoverItem && (\n <StyledMotionListItemHeadHoverItem\n animate={{\n marginLeft: shouldShowHoverItem ? 8 : 0,\n opacity: shouldShowHoverItem ? 1 : 0,\n width: shouldShowHoverItem ? 'auto' : 0,\n }}\n initial={false}\n transition={{ duration: 0.15, type: 'tween' }}\n >\n {hoverItem}\n </StyledMotionListItemHeadHoverItem>\n )}\n </StyledListItemHead>\n );\n};\n\nListItemHead.displayName = 'ListItemHead';\n\nexport default ListItemHead;\n"],"mappings":"AAAA,OAAOA,KAAK,IAKRC,WAAW,EACXC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,OAAOC,IAAI,MAAM,oBAAoB;AACrC,OAAOC,YAAY,MAAM,+BAA+B;AACxD,OAAOC,aAAa,MAAM,iCAAiC;AAC3D,SACIC,kBAAkB,EAClBC,oCAAoC,EACpCC,yBAAyB,EACzBC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,8BAA8B,EAC9BC,uBAAuB,EACvBC,2BAA2B,EAC3BC,iCAAiC,EACjCC,iCAAiC,EACjCC,iCAAiC,QAC9B,uBAAuB;AAkB9B,MAAMC,YAAmC,GAAGC,IAAA,IActC;EAAA,IAduC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,QAC7Ba,aAAa,CAAC,CAAC,CACe,CAElB,CAAC,EACzBC,QAAQ,iBACL9B,KAAA,CAAA+C,aAAA,CAACnC,0BAA0B,qBACvBZ,KAAA,CAAA+C,aAAA,CAAClC,8BAA8B;IAACoC,SAAS,EAAC;EAAU,GAC/CnB,QAC2B,CAAC,EAChCD,aAAa,IAAIA,aAAa,CAACiC,MAAM,GAAG,CAAC,IAAIjC,aAAa,CAAC,CAAC,CAAC,iBAC1D7B,KAAA,CAAA+C,aAAA,CAACtC,oCAAoC,QAChCoB,aAAa,CAAC,CAAC,CACkB,CAElB,CAET,CAAC,EAC3BA,aAAa,EAAEiC,MAAM,KAAK,CAAC,iBACxB9D,KAAA,CAAA+C,aAAA,CAACpC,8BAA8B,QAAEkB,aAAa,CAAC,CAAC,CAAkC,CACrF,EACAR,SAAS,iBACNrB,KAAA,CAAA+C,aAAA,CAAC9B,iCAAiC;IAC9BsC,OAAO,EAAE;MACLQ,UAAU,EAAE7B,mBAAmB,GAAG,CAAC,GAAG,CAAC;MACvC8B,OAAO,EAAE9B,mBAAmB,GAAG,CAAC,GAAG,CAAC;MACpC+B,KAAK,EAAE/B,mBAAmB,GAAG,MAAM,GAAG;IAC1C,CAAE;IACFuB,OAAO,EAAE,KAAM;IACfC,UAAU,EAAE;MAAEQ,QAAQ,EAAE,IAAI;MAAEP,IAAI,EAAE;IAAQ;EAAE,GAE7CtC,SAC8B,CAEvB,CAAC;AAE7B,CAAC;AAEDF,YAAY,CAACgD,WAAW,GAAG,cAAc;AAEzC,eAAehD,YAAY"}
|
|
1
|
+
{"version":3,"file":"ListItemHead.js","names":["React","useCallback","useMemo","useRef","useState","Icon","ListItemIcon","ListItemImage","StyledListItemHead","StyledListItemHeadBottomRightElement","StyledListItemHeadContent","StyledListItemHeadRightElement","StyledListItemHeadSubtitle","StyledListItemHeadSubtitleText","StyledListItemHeadTitle","StyledListItemHeadTitleText","StyledListItemHeadTopRightElement","StyledMotionListItemHeadHoverItem","StyledMotionListItemHeadIndicator","ListItemHead","_ref","hoverItem","icons","images","isAnyItemExpandable","isExpandable","isOpen","onClick","onLongPress","rightElements","subtitle","shouldShowRoundImage","title","leftElements","shouldShowHoverItem","setShouldShowHoverItem","longPressTimeoutRef","handleMouseEnter","handleMouseLeave","handleTouchStart","event","current","window","setTimeout","handleTouchEnd","clearTimeout","iconOrImageElement","createElement","undefined","className","$isClickable","$isAnyItemExpandable","onMouseEnter","onMouseLeave","onTouchStart","onTouchEnd","animate","rotate","initial","transition","type","$isIconOrImageGiven","$isOpen","length","marginLeft","opacity","width","duration","displayName"],"sources":["../../../../../src/components/list/list-item/list-item-head/ListItemHead.tsx"],"sourcesContent":["import React, {\n FC,\n MouseEventHandler,\n ReactNode,\n TouchEventHandler,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport Icon from '../../../icon/Icon';\nimport ListItemIcon from './list-item-icon/ListItemIcon';\nimport ListItemImage from './list-item-image/ListItemImage';\nimport {\n StyledListItemHead,\n StyledListItemHeadBottomRightElement,\n StyledListItemHeadContent,\n StyledListItemHeadRightElement,\n StyledListItemHeadSubtitle,\n StyledListItemHeadSubtitleText,\n StyledListItemHeadTitle,\n StyledListItemHeadTitleText,\n StyledListItemHeadTopRightElement,\n StyledMotionListItemHeadHoverItem,\n StyledMotionListItemHeadIndicator,\n} from './ListItemHead.styles';\n\ntype ListItemHeadProps = {\n hoverItem?: ReactNode;\n icons?: string[];\n images?: string[];\n isAnyItemExpandable: boolean;\n isExpandable: boolean;\n isOpen: boolean;\n onClick?: MouseEventHandler<HTMLDivElement>;\n onLongPress?: TouchEventHandler<HTMLDivElement>;\n rightElements?: [ReactNode, ...ReactNode[]];\n subtitle?: ReactNode;\n leftElements?: ReactNode;\n shouldShowRoundImage?: boolean;\n title: ReactNode;\n};\n\nconst ListItemHead: FC<ListItemHeadProps> = ({\n hoverItem,\n icons,\n images,\n isAnyItemExpandable,\n isExpandable,\n isOpen,\n onClick,\n onLongPress,\n rightElements,\n subtitle,\n shouldShowRoundImage,\n title,\n leftElements,\n}) => {\n const [shouldShowHoverItem, setShouldShowHoverItem] = useState(false);\n\n const longPressTimeoutRef = useRef<number>();\n\n const handleMouseEnter = useCallback(() => setShouldShowHoverItem(true), []);\n\n const handleMouseLeave = useCallback(() => setShouldShowHoverItem(false), []);\n\n const handleTouchStart = useCallback<TouchEventHandler<HTMLDivElement>>(\n (event) => {\n longPressTimeoutRef.current = window.setTimeout(() => {\n if (typeof onLongPress === 'function') {\n onLongPress(event);\n }\n }, 400);\n },\n [onLongPress],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(longPressTimeoutRef.current);\n }, []);\n\n const iconOrImageElement = useMemo(() => {\n if (icons) {\n return <ListItemIcon icons={icons} />;\n }\n\n if (images) {\n return <ListItemImage images={images} shouldShowRoundImage={!!shouldShowRoundImage} />;\n }\n\n return undefined;\n }, [icons, images, shouldShowRoundImage]);\n\n return (\n <StyledListItemHead\n className=\"beta-chayns-list-item-head\"\n $isClickable={typeof onClick === 'function' || isExpandable}\n $isAnyItemExpandable={isAnyItemExpandable}\n onClick={onClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onTouchStart={typeof onLongPress === 'function' ? handleTouchStart : undefined}\n onTouchEnd={typeof onLongPress === 'function' ? handleTouchEnd : undefined}\n >\n {isAnyItemExpandable && (\n <StyledMotionListItemHeadIndicator\n animate={{ rotate: isOpen ? 90 : 0 }}\n initial={false}\n transition={{ type: 'tween' }}\n >\n {isExpandable && <Icon icons={['fa fa-chevron-right']} />}\n </StyledMotionListItemHeadIndicator>\n )}\n {leftElements}\n {iconOrImageElement}\n <StyledListItemHeadContent\n $isIconOrImageGiven={iconOrImageElement !== undefined}\n $isOpen={isOpen}\n >\n <StyledListItemHeadTitle>\n <StyledListItemHeadTitleText className=\"ellipsis\">\n {title}\n </StyledListItemHeadTitleText>\n {rightElements && rightElements.length > 1 && rightElements[0] && (\n <StyledListItemHeadTopRightElement>\n {rightElements[0]}\n </StyledListItemHeadTopRightElement>\n )}\n </StyledListItemHeadTitle>\n {subtitle && (\n <StyledListItemHeadSubtitle>\n <StyledListItemHeadSubtitleText className=\"ellipsis\">\n {subtitle}\n </StyledListItemHeadSubtitleText>\n {rightElements && rightElements.length > 1 && rightElements[1] && (\n <StyledListItemHeadBottomRightElement>\n {rightElements[1]}\n </StyledListItemHeadBottomRightElement>\n )}\n </StyledListItemHeadSubtitle>\n )}\n </StyledListItemHeadContent>\n {rightElements?.length === 1 && (\n <StyledListItemHeadRightElement>{rightElements[0]}</StyledListItemHeadRightElement>\n )}\n {hoverItem && (\n <StyledMotionListItemHeadHoverItem\n animate={{\n marginLeft: shouldShowHoverItem ? 8 : 0,\n opacity: shouldShowHoverItem ? 1 : 0,\n width: shouldShowHoverItem ? 'auto' : 0,\n }}\n initial={false}\n transition={{ duration: 0.15, type: 'tween' }}\n >\n {hoverItem}\n </StyledMotionListItemHeadHoverItem>\n )}\n </StyledListItemHead>\n );\n};\n\nListItemHead.displayName = 'ListItemHead';\n\nexport default ListItemHead;\n"],"mappings":"AAAA,OAAOA,KAAK,IAKRC,WAAW,EACXC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,OAAOC,IAAI,MAAM,oBAAoB;AACrC,OAAOC,YAAY,MAAM,+BAA+B;AACxD,OAAOC,aAAa,MAAM,iCAAiC;AAC3D,SACIC,kBAAkB,EAClBC,oCAAoC,EACpCC,yBAAyB,EACzBC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,8BAA8B,EAC9BC,uBAAuB,EACvBC,2BAA2B,EAC3BC,iCAAiC,EACjCC,iCAAiC,EACjCC,iCAAiC,QAC9B,uBAAuB;AAkB9B,MAAMC,YAAmC,GAAGC,IAAA,IActC;EAAA,IAduC;IACzCC,SAAS;IACTC,KAAK;IACLC,MAAM;IACNC,mBAAmB;IACnBC,YAAY;IACZC,MAAM;IACNC,OAAO;IACPC,WAAW;IACXC,aAAa;IACbC,QAAQ;IACRC,o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AA0B,qBACvBZ,KAAA,CAAA+C,aAAA,CAAClC,8BAA8B;IAACoC,SAAS,EAAC;EAAU,GAC/CnB,QAC2B,CAAC,EAChCD,aAAa,IAAIA,aAAa,CAACkC,MAAM,GAAG,CAAC,IAAIlC,aAAa,CAAC,CAAC,CAAC,iBAC1D7B,KAAA,CAAA+C,aAAA,CAACtC,oCAAoC,QAChCoB,aAAa,CAAC,CAAC,CACkB,CAElB,CAET,CAAC,EAC3BA,aAAa,EAAEkC,MAAM,KAAK,CAAC,iBACxB/D,KAAA,CAAA+C,aAAA,CAACpC,8BAA8B,QAAEkB,aAAa,CAAC,CAAC,CAAkC,CACrF,EACAR,SAAS,iBACNrB,KAAA,CAAA+C,aAAA,CAAC9B,iCAAiC;IAC9BuC,OAAO,EAAE;MACLQ,UAAU,EAAE9B,mBAAmB,GAAG,CAAC,GAAG,CAAC;MACvC+B,OAAO,EAAE/B,mBAAmB,GAAG,CAAC,GAAG,CAAC;MACpCgC,KAAK,EAAEhC,mBAAmB,GAAG,MAAM,GAAG;IAC1C,CAAE;IACFwB,OAAO,EAAE,KAAM;IACfC,UAAU,EAAE;MAAEQ,QAAQ,EAAE,IAAI;MAAEP,IAAI,EAAE;IAAQ;EAAE,GAE7CvC,SAC8B,CAEvB,CAAC;AAE7B,CAAC;AAEDF,YAAY,CAACiD,WAAW,GAAG,cAAc;AAEzC,eAAejD,YAAY"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { WithTheme } from '../../../color-scheme-provider/ColorSchemeProvider';
|
|
4
4
|
type StyledListItemHeadProps = WithTheme<{
|
|
5
5
|
$isClickable: boolean;
|
|
6
|
+
$isAnyItemExpandable: boolean;
|
|
6
7
|
}>;
|
|
7
8
|
export declare const StyledListItemHead: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledListItemHeadProps>>;
|
|
8
9
|
export declare const StyledMotionListItemHeadIndicator: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<{
|
|
@@ -14,8 +14,17 @@ export const StyledListItemHead = styled.div`
|
|
|
14
14
|
|
|
15
15
|
${_ref2 => {
|
|
16
16
|
let {
|
|
17
|
-
$
|
|
17
|
+
$isAnyItemExpandable
|
|
18
18
|
} = _ref2;
|
|
19
|
+
return !$isAnyItemExpandable && css`
|
|
20
|
+
padding-left: 12px;
|
|
21
|
+
`;
|
|
22
|
+
}}
|
|
23
|
+
|
|
24
|
+
${_ref3 => {
|
|
25
|
+
let {
|
|
26
|
+
$isClickable
|
|
27
|
+
} = _ref3;
|
|
19
28
|
return $isClickable && css`
|
|
20
29
|
cursor: pointer;
|
|
21
30
|
`;
|
|
@@ -33,18 +42,18 @@ export const StyledListItemHeadContent = styled.div`
|
|
|
33
42
|
display: flex;
|
|
34
43
|
flex: 1 1 auto;
|
|
35
44
|
flex-direction: column;
|
|
36
|
-
font-weight: ${
|
|
45
|
+
font-weight: ${_ref4 => {
|
|
37
46
|
let {
|
|
38
47
|
$isOpen
|
|
39
|
-
} =
|
|
48
|
+
} = _ref4;
|
|
40
49
|
return $isOpen ? 'bold' : 'normal';
|
|
41
50
|
}};
|
|
42
51
|
justify-content: center;
|
|
43
52
|
line-height: normal;
|
|
44
|
-
margin-left: ${
|
|
53
|
+
margin-left: ${_ref5 => {
|
|
45
54
|
let {
|
|
46
55
|
$isIconOrImageGiven
|
|
47
|
-
} =
|
|
56
|
+
} = _ref5;
|
|
48
57
|
return $isIconOrImageGiven ? '10px' : undefined;
|
|
49
58
|
}};
|
|
50
59
|
min-width: 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItemHead.styles.js","names":["motion","styled","css","StyledListItemHead","div","_ref","theme","text","_ref2","$isClickable","StyledMotionListItemHeadIndicator","StyledListItemHeadContent","
|
|
1
|
+
{"version":3,"file":"ListItemHead.styles.js","names":["motion","styled","css","StyledListItemHead","div","_ref","theme","text","_ref2","$isAnyItemExpandable","_ref3","$isClickable","StyledMotionListItemHeadIndicator","StyledListItemHeadContent","_ref4","$isOpen","_ref5","$isIconOrImageGiven","undefined","StyledListItemHeadTitle","StyledListItemHeadTitleText","span","StyledListItemHeadSubtitle","StyledListItemHeadSubtitleText","StyledListItemHeadTopRightElement","StyledListItemHeadBottomRightElement","StyledListItemHeadRightElement","StyledMotionListItemHeadHoverItem"],"sources":["../../../../../src/components/list/list-item/list-item-head/ListItemHead.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type {\n FramerMotionBugFix,\n WithTheme,\n} from '../../../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledListItemHeadProps = WithTheme<{\n $isClickable: boolean;\n $isAnyItemExpandable: boolean;\n}>;\n\nexport const StyledListItemHead = styled.div<StyledListItemHeadProps>`\n align-items: center;\n color: ${({ theme }: StyledListItemHeadProps) => theme.text};\n display: flex;\n height: 64px;\n padding: 12px 9px;\n\n ${({ $isAnyItemExpandable }) =>\n !$isAnyItemExpandable &&\n css`\n padding-left: 12px;\n `}\n\n ${({ $isClickable }) =>\n $isClickable &&\n css`\n cursor: pointer;\n `}\n`;\n\nexport const StyledMotionListItemHeadIndicator = styled(motion.div)<FramerMotionBugFix>`\n align-items: center;\n display: flex;\n flex: 0 0 auto;\n height: 26px;\n justify-content: center;\n width: 26px;\n`;\n\ntype StyledListItemHeadContentProps = {\n $isIconOrImageGiven: boolean;\n $isOpen: boolean;\n};\n\nexport const StyledListItemHeadContent = styled.div<StyledListItemHeadContentProps>`\n display: flex;\n flex: 1 1 auto;\n flex-direction: column;\n font-weight: ${({ $isOpen }) => ($isOpen ? 'bold' : 'normal')};\n justify-content: center;\n line-height: normal;\n margin-left: ${({ $isIconOrImageGiven }) => ($isIconOrImageGiven ? '10px' : undefined)};\n min-width: 0;\n`;\n\nexport const StyledListItemHeadTitle = styled.div`\n align-items: center;\n display: flex;\n justify-content: space-between;\n`;\n\nexport const StyledListItemHeadTitleText = styled.span`\n flex: 1 1 auto;\n min-width: 0;\n`;\n\nexport const StyledListItemHeadSubtitle = styled.div`\n align-items: center;\n display: flex;\n justify-content: space-between;\n margin-top: 2px;\n opacity: 0.75;\n`;\n\nexport const StyledListItemHeadSubtitleText = styled.span`\n flex: 1 1 auto;\n font-size: 85%;\n min-width: 0;\n`;\n\nexport const StyledListItemHeadTopRightElement = styled.div`\n flex: 0 0 auto;\n font-size: 85%;\n margin-left: 8px;\n opacity: 0.75;\n`;\n\nexport const StyledListItemHeadBottomRightElement = styled.div`\n flex: 0 0 auto;\n margin-left: 8px;\n font-size: 85%;\n`;\n\nexport const StyledListItemHeadRightElement = styled.div`\n flex: 0 0 auto;\n margin-left: 8px;\n`;\n\nexport const StyledMotionListItemHeadHoverItem = styled(motion.div)<FramerMotionBugFix>`\n overflow: hidden;\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAW/C,OAAO,MAAMC,kBAAkB,GAAGF,MAAM,CAACG,GAA6B;AACtE;AACA,aAAaC,IAAA;EAAA,IAAC;IAAEC;EAA+B,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAACC,IAAI;AAAA,CAAC;AAChE;AACA;AACA;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEC;EAAqB,CAAC,GAAAD,KAAA;EAAA,OACvB,CAACC,oBAAoB,IACrBP,GAAI;AACZ;AACA,SAAS;AAAA,CAAC;AACV;AACA,MAAMQ,KAAA;EAAA,IAAC;IAAEC;EAAa,CAAC,GAAAD,KAAA;EAAA,OACfC,YAAY,IACZT,GAAI;AACZ;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAED,OAAO,MAAMU,iCAAiC,GAAGX,MAAM,CAACD,MAAM,CAACI,GAAG,CAAsB;AACxF;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAOD,OAAO,MAAMS,yBAAyB,GAAGZ,MAAM,CAACG,GAAoC;AACpF;AACA;AACA;AACA,mBAAmBU,KAAA;EAAA,IAAC;IAAEC;EAAQ,CAAC,GAAAD,KAAA;EAAA,OAAMC,OAAO,GAAG,MAAM,GAAG,QAAQ;AAAA,CAAE;AAClE;AACA;AACA,mBAAmBC,KAAA;EAAA,IAAC;IAAEC;EAAoB,CAAC,GAAAD,KAAA;EAAA,OAAMC,mBAAmB,GAAG,MAAM,GAAGC,SAAS;AAAA,CAAE;AAC3F;AACA,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAAGlB,MAAM,CAACG,GAAI;AAClD;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMgB,2BAA2B,GAAGnB,MAAM,CAACoB,IAAK;AACvD;AACA;AACA,CAAC;AAED,OAAO,MAAMC,0BAA0B,GAAGrB,MAAM,CAACG,GAAI;AACrD;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMmB,8BAA8B,GAAGtB,MAAM,CAACoB,IAAK;AAC1D;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMG,iCAAiC,GAAGvB,MAAM,CAACG,GAAI;AAC5D;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMqB,oCAAoC,GAAGxB,MAAM,CAACG,GAAI;AAC/D;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMsB,8BAA8B,GAAGzB,MAAM,CAACG,GAAI;AACzD;AACA;AACA,CAAC;AAED,OAAO,MAAMuB,iCAAiC,GAAG1B,MAAM,CAACD,MAAM,CAACI,GAAG,CAAsB;AACxF;AACA,CAAC"}
|
|
@@ -17,13 +17,6 @@ const SliderButton = _ref => {
|
|
|
17
17
|
});
|
|
18
18
|
const sliderButtonRef = useRef(null);
|
|
19
19
|
const [scope, animate] = useAnimate();
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (selectedButtonId) {
|
|
22
|
-
setSelectedButton(selectedButtonId);
|
|
23
|
-
} else {
|
|
24
|
-
setSelectedButton(items[0]?.id);
|
|
25
|
-
}
|
|
26
|
-
}, [items, selectedButtonId]);
|
|
27
20
|
const itemWidth = useMemo(() => calculateBiggestWidth(items), [items]);
|
|
28
21
|
useEffect(() => {
|
|
29
22
|
if (sliderButtonRef.current) {
|
|
@@ -41,6 +34,22 @@ const SliderButton = _ref => {
|
|
|
41
34
|
duration: 0.2
|
|
42
35
|
});
|
|
43
36
|
}, [animate, scope]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (selectedButtonId) {
|
|
39
|
+
setSelectedButton(selectedButtonId);
|
|
40
|
+
const index = items.findIndex(_ref2 => {
|
|
41
|
+
let {
|
|
42
|
+
id
|
|
43
|
+
} = _ref2;
|
|
44
|
+
return id === selectedButtonId;
|
|
45
|
+
});
|
|
46
|
+
if (index >= 0) {
|
|
47
|
+
void animation(itemWidth * index);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
setSelectedButton(items[0]?.id);
|
|
51
|
+
}
|
|
52
|
+
}, [animation, itemWidth, items, selectedButtonId]);
|
|
44
53
|
const handleClick = useCallback((id, index) => {
|
|
45
54
|
if (isDisabled) {
|
|
46
55
|
return;
|
|
@@ -53,11 +62,11 @@ const SliderButton = _ref => {
|
|
|
53
62
|
}, [animation, isDisabled, itemWidth, onChange]);
|
|
54
63
|
const buttons = useMemo(() => {
|
|
55
64
|
const list = [];
|
|
56
|
-
items.forEach((
|
|
65
|
+
items.forEach((_ref3, index) => {
|
|
57
66
|
let {
|
|
58
67
|
id,
|
|
59
68
|
text
|
|
60
|
-
} =
|
|
69
|
+
} = _ref3;
|
|
61
70
|
list.push( /*#__PURE__*/React.createElement(StyledSliderButtonItem, {
|
|
62
71
|
$width: itemWidth,
|
|
63
72
|
key: `slider-button-${id}`,
|
|
@@ -68,10 +77,10 @@ const SliderButton = _ref => {
|
|
|
68
77
|
return list;
|
|
69
78
|
}, [handleClick, itemWidth, items, selectedButton]);
|
|
70
79
|
const thumbText = useMemo(() => {
|
|
71
|
-
const selectedItem = items.find(
|
|
80
|
+
const selectedItem = items.find(_ref4 => {
|
|
72
81
|
let {
|
|
73
82
|
id
|
|
74
|
-
} =
|
|
83
|
+
} = _ref4;
|
|
75
84
|
return id === selectedButton;
|
|
76
85
|
});
|
|
77
86
|
return selectedItem ? selectedItem.text : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliderButton.js","names":["AnimatePresence","useAnimate","React","useCallback","useEffect","useMemo","useRef","useState","calculateBiggestWidth","getNearestPoint","getThumbPosition","StyledMotionSliderButtonThumb","StyledSliderButton","StyledSliderButtonItem","SliderButton","_ref","selectedButtonId","isDisabled","items","onChange","selectedButton","setSelectedButton","undefined","dragRange","setDragRange","left","right","sliderButtonRef","scope","animate","id","itemWidth","current","offsetWidth","animation","x","type","duration","handleClick","index","buttons","list","forEach","_ref2","text","push","createElement","$width","key","onClick","$isSelected","thumbText","selectedItem","find","_ref3","snapPoints","points","i","length","handleDragEnd","position","nearestPoint","nearestIndex","handleWhileDrag","$isDisabled","ref","drag","dragElastic","dragConstraints","onDrag","onDragEnd","displayName"],"sources":["../../../src/components/slider-button/SliderButton.tsx"],"sourcesContent":["import { AnimatePresence, useAnimate } from 'framer-motion';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport type { SliderButtonItem } from '../../types/slider-button';\nimport { calculateBiggestWidth } from '../../utils/calculate';\nimport { getNearestPoint, getThumbPosition } from '../../utils/sliderButton';\nimport {\n StyledMotionSliderButtonThumb,\n StyledSliderButton,\n StyledSliderButtonItem,\n} from './SliderButton.styles';\n\nexport type SliderButtonProps = {\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when a button is selected.\n * @param id\n */\n onChange?: (id: string) => void;\n /**\n * The buttons that are slidable.\n */\n items: SliderButtonItem[];\n /**\n * The id of a button that should be selected.\n */\n selectedButtonId?: string;\n};\n\nconst SliderButton: FC<SliderButtonProps> = ({ selectedButtonId, isDisabled, items, onChange }) => {\n const [selectedButton, setSelectedButton] = useState<string | undefined>(undefined);\n const [dragRange, setDragRange] = useState({ left: 0, right: 0 });\n\n const sliderButtonRef = useRef<HTMLDivElement>(null);\n\n const [scope, animate] = useAnimate();\n\n useEffect(() => {\n if (selectedButtonId) {\n setSelectedButton(selectedButtonId);\n } else {\n setSelectedButton(items[0]?.id);\n }\n }, [items, selectedButtonId]);\n\n const itemWidth = useMemo(() => calculateBiggestWidth(items), [items]);\n\n useEffect(() => {\n if (sliderButtonRef.current) {\n setDragRange({ left: 0, right: sliderButtonRef.current.offsetWidth - itemWidth });\n }\n }, [itemWidth]);\n\n const animation = useCallback(\n async (x: number) => {\n await animate(\n scope.current,\n { x },\n {\n type: 'tween',\n duration: 0.2,\n },\n );\n },\n [animate, scope],\n );\n\n const handleClick = useCallback(\n (id: string, index: number) => {\n if (isDisabled) {\n return;\n }\n\n setSelectedButton(id);\n\n if (typeof onChange === 'function') {\n onChange(id);\n }\n\n void animation(itemWidth * index);\n },\n [animation, isDisabled, itemWidth, onChange],\n );\n\n const buttons = useMemo(() => {\n const list: ReactElement[] = [];\n\n items.forEach(({ id, text }, index) => {\n list.push(\n <StyledSliderButtonItem\n $width={itemWidth}\n key={`slider-button-${id}`}\n onClick={() => handleClick(id, index)}\n $isSelected={id === selectedButton}\n >\n {text}\n </StyledSliderButtonItem>,\n );\n });\n\n return list;\n }, [handleClick, itemWidth, items, selectedButton]);\n\n const thumbText = useMemo(() => {\n const selectedItem = items.find(({ id }) => id === selectedButton);\n\n return selectedItem ? selectedItem.text : '';\n }, [items, selectedButton]);\n\n /**\n * Creates an array with the snap points relative to the width of the items\n */\n const snapPoints = useMemo(() => {\n const points = [0];\n\n for (let i = 1; i < items.length; i++) {\n points.push(itemWidth * i);\n }\n\n return points;\n }, [itemWidth, items.length]);\n\n const handleDragEnd = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestPoint, nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestPoint >= 0 && nearestIndex >= 0) {\n void animation(nearestPoint);\n\n const id = items[nearestIndex]?.id;\n\n if (typeof onChange === 'function' && id) {\n onChange(id);\n }\n }\n }, [animation, itemWidth, items, onChange, scope, snapPoints]);\n\n const handleWhileDrag = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestIndex >= 0) {\n setSelectedButton(items[nearestIndex]?.id);\n }\n }, [itemWidth, items, scope, snapPoints]);\n\n return useMemo(\n () => (\n <StyledSliderButton $isDisabled={isDisabled} ref={sliderButtonRef}>\n <AnimatePresence>\n {buttons}\n <StyledMotionSliderButtonThumb\n ref={scope}\n drag={isDisabled ? false : 'x'}\n dragElastic={0}\n dragConstraints={{ ...dragRange }}\n $width={itemWidth}\n onDrag={handleWhileDrag}\n onDragEnd={handleDragEnd}\n >\n {thumbText}\n </StyledMotionSliderButtonThumb>\n </AnimatePresence>\n </StyledSliderButton>\n ),\n [\n buttons,\n dragRange,\n handleDragEnd,\n handleWhileDrag,\n isDisabled,\n itemWidth,\n scope,\n thumbText,\n ],\n );\n};\n\nSliderButton.displayName = 'SliderButton';\n\nexport default SliderButton;\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,UAAU,QAAQ,eAAe;AAC3D,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAEL,OAAO;AAEd,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,eAAe,EAAEC,gBAAgB,QAAQ,0BAA0B;AAC5E,SACIC,6BAA6B,EAC7BC,kBAAkB,EAClBC,sBAAsB,QACnB,uBAAuB;AAsB9B,MAAMC,YAAmC,GAAGC,IAAA,IAAuD;EAAA,IAAtD;IAAEC,gBAAgB;IAAEC,UAAU;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAAJ,IAAA;EAC1F,M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C;MAAE8C,UAAU;MAAEK;IAAS,CAAC,CAAC;IAElE,IAAIE,YAAY,IAAI,CAAC,EAAE;MACnBzC,iBAAiB,CAACH,KAAK,CAAC4C,YAAY,CAAC,EAAEhC,EAAE,CAAC;IAC9C;EACJ,CAAC,EAAE,CAACC,SAAS,EAAEb,KAAK,EAAEU,KAAK,EAAE2B,UAAU,CAAC,CAAC;EAEzC,OAAOlD,OAAO,CACV,mBACIH,KAAA,CAAA4C,aAAA,CAAClC,kBAAkB;IAACoD,WAAW,EAAE/C,UAAW;IAACgD,GAAG,EAAEtC;EAAgB,gBAC9DzB,KAAA,CAAA4C,aAAA,CAAC9C,eAAe,QACXwC,OAAO,eACRtC,KAAA,CAAA4C,aAAA,CAACnC,6BAA6B;IAC1BsD,GAAG,EAAErC,KAAM;IACXsC,IAAI,EAAEjD,UAAU,GAAG,KAAK,GAAG,GAAI;IAC/BkD,WAAW,EAAE,CAAE;IACfC,eAAe,EAAE;MAAE,GAAG7C;IAAU,CAAE;IAClCwB,MAAM,EAAEhB,SAAU;IAClBsC,MAAM,EAAEN,eAAgB;IACxBO,SAAS,EAAEX;EAAc,GAExBR,SAC0B,CAClB,CACD,CACvB,EACD,CACIX,OAAO,EACPjB,SAAS,EACToC,aAAa,EACbI,eAAe,EACf9C,UAAU,EACVc,SAAS,EACTH,KAAK,EACLuB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDrC,YAAY,CAACyD,WAAW,GAAG,cAAc;AAEzC,eAAezD,YAAY"}
|
|
1
|
+
{"version":3,"file":"SliderButton.js","names":["AnimatePresence","useAnimate","React","useCallback","useEffect","useMemo","useRef","useState","calculateBiggestWidth","getNearestPoint","getThumbPosition","StyledMotionSliderButtonThumb","StyledSliderButton","StyledSliderButtonItem","SliderButton","_ref","selectedButtonId","isDisabled","items","onChange","selectedButton","setSelectedButton","undefined","dragRange","setDragRange","left","right","sliderButtonRef","scope","animate","itemWidth","current","offsetWidth","animation","x","type","duration","index","findIndex","_ref2","id","handleClick","buttons","list","forEach","_ref3","text","push","createElement","$width","key","onClick","$isSelected","thumbText","selectedItem","find","_ref4","snapPoints","points","i","length","handleDragEnd","position","nearestPoint","nearestIndex","handleWhileDrag","$isDisabled","ref","drag","dragElastic","dragConstraints","onDrag","onDragEnd","displayName"],"sources":["../../../src/components/slider-button/SliderButton.tsx"],"sourcesContent":["import { AnimatePresence, useAnimate } from 'framer-motion';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport type { SliderButtonItem } from '../../types/slider-button';\nimport { calculateBiggestWidth } from '../../utils/calculate';\nimport { getNearestPoint, getThumbPosition } from '../../utils/sliderButton';\nimport {\n StyledMotionSliderButtonThumb,\n StyledSliderButton,\n StyledSliderButtonItem,\n} from './SliderButton.styles';\n\nexport type SliderButtonProps = {\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when a button is selected.\n * @param id\n */\n onChange?: (id: string) => void;\n /**\n * The buttons that are slidable.\n */\n items: SliderButtonItem[];\n /**\n * The id of a button that should be selected.\n */\n selectedButtonId?: string;\n};\n\nconst SliderButton: FC<SliderButtonProps> = ({ selectedButtonId, isDisabled, items, onChange }) => {\n const [selectedButton, setSelectedButton] = useState<string | undefined>(undefined);\n const [dragRange, setDragRange] = useState({ left: 0, right: 0 });\n\n const sliderButtonRef = useRef<HTMLDivElement>(null);\n\n const [scope, animate] = useAnimate();\n\n const itemWidth = useMemo(() => calculateBiggestWidth(items), [items]);\n\n useEffect(() => {\n if (sliderButtonRef.current) {\n setDragRange({ left: 0, right: sliderButtonRef.current.offsetWidth - itemWidth });\n }\n }, [itemWidth]);\n\n const animation = useCallback(\n async (x: number) => {\n await animate(\n scope.current,\n { x },\n {\n type: 'tween',\n duration: 0.2,\n },\n );\n },\n [animate, scope],\n );\n\n useEffect(() => {\n if (selectedButtonId) {\n setSelectedButton(selectedButtonId);\n\n const index = items.findIndex(({ id }) => id === selectedButtonId);\n\n if (index >= 0) {\n void animation(itemWidth * index);\n }\n } else {\n setSelectedButton(items[0]?.id);\n }\n }, [animation, itemWidth, items, selectedButtonId]);\n\n const handleClick = useCallback(\n (id: string, index: number) => {\n if (isDisabled) {\n return;\n }\n\n setSelectedButton(id);\n\n if (typeof onChange === 'function') {\n onChange(id);\n }\n\n void animation(itemWidth * index);\n },\n [animation, isDisabled, itemWidth, onChange],\n );\n\n const buttons = useMemo(() => {\n const list: ReactElement[] = [];\n\n items.forEach(({ id, text }, index) => {\n list.push(\n <StyledSliderButtonItem\n $width={itemWidth}\n key={`slider-button-${id}`}\n onClick={() => handleClick(id, index)}\n $isSelected={id === selectedButton}\n >\n {text}\n </StyledSliderButtonItem>,\n );\n });\n\n return list;\n }, [handleClick, itemWidth, items, selectedButton]);\n\n const thumbText = useMemo(() => {\n const selectedItem = items.find(({ id }) => id === selectedButton);\n\n return selectedItem ? selectedItem.text : '';\n }, [items, selectedButton]);\n\n /**\n * Creates an array with the snap points relative to the width of the items\n */\n const snapPoints = useMemo(() => {\n const points = [0];\n\n for (let i = 1; i < items.length; i++) {\n points.push(itemWidth * i);\n }\n\n return points;\n }, [itemWidth, items.length]);\n\n const handleDragEnd = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestPoint, nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestPoint >= 0 && nearestIndex >= 0) {\n void animation(nearestPoint);\n\n const id = items[nearestIndex]?.id;\n\n if (typeof onChange === 'function' && id) {\n onChange(id);\n }\n }\n }, [animation, itemWidth, items, onChange, scope, snapPoints]);\n\n const handleWhileDrag = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestIndex >= 0) {\n setSelectedButton(items[nearestIndex]?.id);\n }\n }, [itemWidth, items, scope, snapPoints]);\n\n return useMemo(\n () => (\n <StyledSliderButton $isDisabled={isDisabled} ref={sliderButtonRef}>\n <AnimatePresence>\n {buttons}\n <StyledMotionSliderButtonThumb\n ref={scope}\n drag={isDisabled ? false : 'x'}\n dragElastic={0}\n dragConstraints={{ ...dragRange }}\n $width={itemWidth}\n onDrag={handleWhileDrag}\n onDragEnd={handleDragEnd}\n >\n {thumbText}\n </StyledMotionSliderButtonThumb>\n </AnimatePresence>\n </StyledSliderButton>\n ),\n [\n buttons,\n dragRange,\n handleDragEnd,\n handleWhileDrag,\n isDisabled,\n itemWidth,\n scope,\n thumbText,\n ],\n );\n};\n\nSliderButton.displayName = 'SliderButton';\n\nexport default SliderButton;\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,UAAU,QAAQ,eAAe;AAC3D,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAEL,OAAO;AAEd,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,eAAe,EAAEC,gBAAgB,QAAQ,0BAA0B;AAC5E,SACIC,6BAA6B,EAC7BC,kBAAkB,EAClBC,sBAAsB,QACnB,uBAAuB;AAsB9B,MAAMC,YAAmC,GAAGC,IAAA,IAAuD;EAAA,IAAtD;IAAEC,gBAAgB;IAAEC,UAAU;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAAJ,IAAA;EAC1F,MAAM,CAACK,cAAc,EAAEC,iBAAiB,CAAC,GAAGd,QAAQ,CAAqBe,SAAS,CAAC;EACnF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGjB,QAAQ,CAAC;IAAEkB,IAAI,EAAE,CAAC;IAAEC,KAAK,EAAE;EAAE,CAAC,CAAC;EAEjE,MAAMC,eAAe,GAAGrB,MAAM,CAAiB,IAAI,CAAC;EAEpD,MAAM,CAACsB,KAAK,EAAEC,OAAO,CAAC,GAAG5B,UAAU,CAAC,CAAC;EAErC,MAAM6B,SAAS,GAAGzB,OAAO,CAAC,MAAMG,qBAAqB,CAACU,KAAK,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AACH,KAAK,CAAC8C,YAAY,CAAC,EAAExB,EAAE,CAAC;IAC9C;EACJ,CAAC,EAAE,CAACV,SAAS,EAAEZ,KAAK,EAAEU,KAAK,EAAE6B,UAAU,CAAC,CAAC;EAEzC,OAAOpD,OAAO,CACV,mBACIH,KAAA,CAAA8C,aAAA,CAACpC,kBAAkB;IAACsD,WAAW,EAAEjD,UAAW;IAACkD,GAAG,EAAExC;EAAgB,gBAC9DzB,KAAA,CAAA8C,aAAA,CAAChD,eAAe,QACX0C,OAAO,eACRxC,KAAA,CAAA8C,aAAA,CAACrC,6BAA6B;IAC1BwD,GAAG,EAAEvC,KAAM;IACXwC,IAAI,EAAEnD,UAAU,GAAG,KAAK,GAAG,GAAI;IAC/BoD,WAAW,EAAE,CAAE;IACfC,eAAe,EAAE;MAAE,GAAG/C;IAAU,CAAE;IAClC0B,MAAM,EAAEnB,SAAU;IAClByC,MAAM,EAAEN,eAAgB;IACxBO,SAAS,EAAEX;EAAc,GAExBR,SAC0B,CAClB,CACD,CACvB,EACD,CACIX,OAAO,EACPnB,SAAS,EACTsC,aAAa,EACbI,eAAe,EACfhD,UAAU,EACVa,SAAS,EACTF,KAAK,EACLyB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDvC,YAAY,CAAC2D,WAAW,GAAG,cAAc;AAEzC,eAAe3D,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.519",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "bac868dc6109d2afe6951c66dbc1a33457de959d"
|
|
77
77
|
}
|