@chayns-components/core 5.0.0-beta.574 → 5.0.0-beta.576
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/accordion/Accordion.js +6 -1
- package/lib/components/accordion/Accordion.js.map +1 -1
- package/lib/components/area-provider/AreaContextProvider.d.ts +14 -0
- package/lib/components/area-provider/AreaContextProvider.js +20 -0
- package/lib/components/area-provider/AreaContextProvider.js.map +1 -0
- package/lib/components/content-card/ContentCard.js +9 -3
- package/lib/components/content-card/ContentCard.js.map +1 -1
- package/lib/components/content-card/ContentCard.styles.d.ts +1 -0
- package/lib/components/content-card/ContentCard.styles.js +25 -8
- package/lib/components/content-card/ContentCard.styles.js.map +1 -1
- package/lib/components/file-input/FileInput.d.ts +6 -1
- package/lib/components/file-input/FileInput.js +61 -12
- package/lib/components/file-input/FileInput.js.map +1 -1
- package/lib/components/file-input/FileInput.styles.d.ts +4 -0
- package/lib/components/file-input/FileInput.styles.js +17 -6
- package/lib/components/file-input/FileInput.styles.js.map +1 -1
- package/lib/components/file-input/file-list/FileListItem.js +2 -1
- package/lib/components/file-input/file-list/FileListItem.js.map +1 -1
- package/lib/components/input/Input.js +5 -1
- package/lib/components/input/Input.js.map +1 -1
- package/lib/components/input/Input.styles.d.ts +1 -0
- package/lib/components/input/Input.styles.js +3 -2
- package/lib/components/input/Input.styles.js.map +1 -1
- package/lib/components/list/list-item/ListItem.js +2 -1
- package/lib/components/list/list-item/ListItem.js.map +1 -1
- package/lib/components/list/list-item/list-item-head/ListItemHead.js +54 -6
- 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 +536 -2
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js +78 -14
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js.map +1 -1
- package/lib/components/popup/Popup.js +4 -1
- package/lib/components/popup/Popup.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/types/fileInput.d.ts +5 -0
- package/lib/types/fileInput.js.map +1 -1
- package/lib/utils/file.d.ts +5 -0
- package/lib/utils/file.js +17 -2
- package/lib/utils/file.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnimatePresence, MotionConfig } from 'framer-motion';
|
|
2
2
|
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { useUuid } from '../../hooks/uuid';
|
|
4
|
+
import { AreaContext } from '../area-provider/AreaContextProvider';
|
|
4
5
|
import AccordionBody from './accordion-body/AccordionBody';
|
|
5
6
|
import { AccordionGroupContext } from './accordion-group/AccordionGroup';
|
|
6
7
|
import AccordionHead from './accordion-head/AccordionHead';
|
|
@@ -139,7 +140,11 @@ const Accordion = _ref => {
|
|
|
139
140
|
maxHeight: bodyMaxHeight,
|
|
140
141
|
onScroll: onBodyScroll,
|
|
141
142
|
shouldHideBody: shouldRenderClosed && !isOpen
|
|
142
|
-
},
|
|
143
|
+
}, /*#__PURE__*/React.createElement(AreaContext.Provider, {
|
|
144
|
+
value: {
|
|
145
|
+
shouldChangeColor: true
|
|
146
|
+
}
|
|
147
|
+
}, children))))));
|
|
143
148
|
};
|
|
144
149
|
Accordion.displayName = 'Accordion';
|
|
145
150
|
export default Accordion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.js","names":["AnimatePresence","MotionConfig","React","useCallback","useContext","useEffect","useMemo","useRef","useState","useUuid","AccordionBody","AccordionGroupContext","AccordionHead","StyledAccordion","AccordionContext","createContext","isWrapped","Accordion","_ref","bodyMaxHeight","children","icon","isDefaultOpen","isDisabled","isFixed","isOpened","isTitleGreyed","onBodyScroll","onClose","onOpen","onSearchChange","rightElement","searchIcon","searchPlaceholder","searchValue","shouldForceBackground","shouldHideBackground","shouldRenderClosed","shouldRotateIcon","title","titleElement","openAccordionUuid","updateOpenAccordionUuid","isParentWrapped","isAccordionOpen","setIsAccordionOpen","uuid","isInitialRenderRef","isInGroup","isOpen","isOpenRef","onCloseRef","onOpenRef","current","handleHeadClick","currentIsAccordionOpen","shouldOnlyOpen","accordionContextProviderValue","createElement","className","$isOpen","$isParentWrapped","$isWrapped","$shouldForceBackground","$shouldHideBackground","Provider","value","transition","type","onClick","initial","maxHeight","onScroll","shouldHideBody","displayName"],"sources":["../../../src/components/accordion/Accordion.tsx"],"sourcesContent":["import { AnimatePresence, MotionConfig } from 'framer-motion';\nimport React, {\n ChangeEventHandler,\n FC,\n ReactNode,\n UIEvent,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport AccordionBody from './accordion-body/AccordionBody';\nimport { AccordionGroupContext } from './accordion-group/AccordionGroup';\nimport AccordionHead from './accordion-head/AccordionHead';\nimport { StyledAccordion } from './Accordion.styles';\n\nexport const AccordionContext = React.createContext({ isWrapped: false });\n\nexport type AccordionProps = {\n /**\n * Maximum height of the accordion body element. This automatically makes the content of the\n * body element scrollable.\n */\n bodyMaxHeight?: number;\n /**\n * The content of the accordion body\n */\n children: ReactNode;\n /**\n * The icon that is displayed in front of the title\n */\n icon?: string;\n /**\n * This can be used to automatically expand the Accordion during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This will disable the Accordion so that it cannot be opened and will gray out the title. Does not work with isOpened.\n */\n isDisabled?: boolean;\n /**\n * This can be used so that the Accordion cannot be opened or closed.\n * In addition, in this case the icon is exchanged to mark the Accordions.\n */\n isFixed?: boolean;\n /**\n * This can be used to open the Accordion from the outside.\n */\n isOpened?: boolean;\n /**\n * This will gray out the title of the Accordion to indicate hidden content, for example.\n */\n isTitleGreyed?: boolean;\n /**\n * Function that is executed when the accordion body will be scrolled\n */\n onBodyScroll?: (event: UIEvent<HTMLDivElement>) => void;\n /**\n * Function that is executed when the accordion will be closed.\n */\n onClose?: VoidFunction;\n /**\n * Function that is executed when the accordion will be opened.\n */\n onOpen?: VoidFunction;\n /**\n * Function that is executed when the text of the search in the accordion\n * head changes. When this function is given, the search field is displayed\n * in the Accordion Head.\n */\n onSearchChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Content to be displayed on the right side in the head of the Accordion\n */\n rightElement?: ReactNode;\n /**\n * Icon to be displayed on the right side in the search input\n */\n searchIcon?: string[];\n /**\n * The placeholder to be used for the search\n */\n searchPlaceholder?: string;\n /**\n * The value that is displayed inside the search\n */\n searchValue?: string;\n /**\n * This will force the background color of the accordion to be used even if it is closed and not hovered.\n */\n shouldForceBackground?: boolean;\n /**\n * This will hide the background color of the accordion\n */\n shouldHideBackground?: boolean;\n /**\n * This will render the Accordion closed on the first render.\n */\n shouldRenderClosed?: boolean;\n /**\n * Whether the icon should be rotating.\n */\n shouldRotateIcon?: boolean;\n /**\n * Title of the Accordion displayed in the head\n */\n title: string;\n /**\n * Additional elements to be displayed in the header next to the title.\n */\n titleElement?: ReactNode;\n};\n\nconst Accordion: FC<AccordionProps> = ({\n bodyMaxHeight,\n children,\n icon,\n isDefaultOpen = false,\n isDisabled = false,\n isFixed = false,\n isOpened,\n isTitleGreyed = false,\n onBodyScroll,\n onClose,\n onOpen,\n onSearchChange,\n rightElement,\n searchIcon,\n searchPlaceholder,\n searchValue,\n shouldForceBackground = false,\n shouldHideBackground = false,\n shouldRenderClosed = false,\n shouldRotateIcon = true,\n title,\n titleElement,\n}) => {\n const { isWrapped, openAccordionUuid, updateOpenAccordionUuid } =\n useContext(AccordionGroupContext);\n const { isWrapped: isParentWrapped } = useContext(AccordionContext);\n\n const [isAccordionOpen, setIsAccordionOpen] = useState<boolean>(isDefaultOpen ?? isOpened);\n\n const uuid = useUuid();\n\n const isInitialRenderRef = useRef(true);\n\n const isInGroup = typeof updateOpenAccordionUuid === 'function';\n\n const isOpen = isInGroup ? openAccordionUuid === uuid : isAccordionOpen;\n\n const isOpenRef = useRef(isOpen);\n const onCloseRef = useRef(onClose);\n const onOpenRef = useRef(onOpen);\n\n useEffect(() => {\n isOpenRef.current = isOpen;\n onCloseRef.current = onClose;\n onOpenRef.current = onOpen;\n }, [isOpen, onClose, onOpen]);\n\n const handleHeadClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }, [isDisabled, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isDisabled && isOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }\n }, [isDisabled, isOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (isOpen) {\n if (typeof onOpenRef.current === 'function') {\n onOpenRef.current();\n }\n } else if (typeof onCloseRef.current === 'function') {\n onCloseRef.current();\n }\n }, [isOpen]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid, { shouldOnlyOpen: true });\n } else {\n setIsAccordionOpen(true);\n }\n }\n }, [isDefaultOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (typeof isOpened === 'boolean') {\n if (typeof updateOpenAccordionUuid === 'function' && isOpened !== isOpenRef.current) {\n updateOpenAccordionUuid(uuid);\n } else {\n setIsAccordionOpen(isOpened);\n }\n }\n }, [isOpened, updateOpenAccordionUuid, uuid]);\n\n const accordionContextProviderValue = useMemo(\n () => ({ isWrapped: isWrapped === true }),\n [isWrapped],\n );\n\n return (\n <StyledAccordion\n className=\"beta-chayns-accordion\"\n $isOpen={isOpen}\n $isParentWrapped={isParentWrapped}\n $isWrapped={isWrapped}\n $shouldForceBackground={shouldForceBackground}\n $shouldHideBackground={shouldHideBackground}\n >\n <AccordionContext.Provider value={accordionContextProviderValue}>\n <MotionConfig transition={{ type: 'tween' }}>\n <AccordionHead\n icon={icon}\n isOpen={isOpen}\n isFixed={isFixed}\n isTitleGreyed={isTitleGreyed || isDisabled}\n isWrapped={isWrapped === true}\n onClick={handleHeadClick}\n onSearchChange={onSearchChange}\n rightElement={rightElement}\n searchIcon={searchIcon}\n searchPlaceholder={searchPlaceholder}\n searchValue={searchValue}\n shouldRotateIcon={shouldRotateIcon}\n title={title}\n titleElement={titleElement}\n />\n <AnimatePresence initial={false}>\n {(isOpen || shouldRenderClosed) && (\n <AccordionBody\n maxHeight={bodyMaxHeight}\n onScroll={onBodyScroll}\n shouldHideBody={shouldRenderClosed && !isOpen}\n >\n {children}\n </AccordionBody>\n )}\n </AnimatePresence>\n </MotionConfig>\n </AccordionContext.Provider>\n </StyledAccordion>\n );\n};\n\nAccordion.displayName = 'Accordion';\n\nexport default Accordion;\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,YAAY,QAAQ,eAAe;AAC7D,OAAOC,KAAK,IAKRC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,OAAO,MAAMC,gBAAgB,gBAAGZ,KAAK,CAACa,aAAa,CAAC;EAAEC,SAAS,EAAE;AAAM,CAAC,CAAC;AAiGzE,MAAMC,SAA6B,GAAGC,IAAA,IAuBhC;EAAA,IAvBiC;IACnCC,aAAa;IACbC,QAAQ;IACRC,IAAI;IACJC,aAAa,GAAG,KAAK;IACrBC,UAAU,GAAG,KAAK;IAClBC,OAAO,GAAG,KAAK;IACfC,QAAQ;IACRC,aAAa,GAAG,KAAK;IACrBC,YAAY;IAC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W,EAAEA,WAAY;IACzBI,gBAAgB,EAAEA,gBAAiB;IACnCC,KAAK,EAAEA,KAAM;IACbC,YAAY,EAAEA;EAAa,CAC9B,CAAC,eACFtC,KAAA,CAAAwD,aAAA,CAAC1D,eAAe;IAACsE,OAAO,EAAE;EAAM,GAC3B,CAACrB,MAAM,IAAIZ,kBAAkB,kBAC1BnC,KAAA,CAAAwD,aAAA,CAAChD,aAAa;IACV6D,SAAS,EAAEpD,aAAc;IACzBqD,QAAQ,EAAE7C,YAAa;IACvB8C,cAAc,EAAEpC,kBAAkB,IAAI,CAACY;EAAO,GAE7C7B,QACU,CAEN,CACP,CACS,CACd,CAAC;AAE1B,CAAC;AAEDH,SAAS,CAACyD,WAAW,GAAG,WAAW;AAEnC,eAAezD,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Accordion.js","names":["AnimatePresence","MotionConfig","React","useCallback","useContext","useEffect","useMemo","useRef","useState","useUuid","AreaContext","AccordionBody","AccordionGroupContext","AccordionHead","StyledAccordion","AccordionContext","createContext","isWrapped","Accordion","_ref","bodyMaxHeight","children","icon","isDefaultOpen","isDisabled","isFixed","isOpened","isTitleGreyed","onBodyScroll","onClose","onOpen","onSearchChange","rightElement","searchIcon","searchPlaceholder","searchValue","shouldForceBackground","shouldHideBackground","shouldRenderClosed","shouldRotateIcon","title","titleElement","openAccordionUuid","updateOpenAccordionUuid","isParentWrapped","isAccordionOpen","setIsAccordionOpen","uuid","isInitialRenderRef","isInGroup","isOpen","isOpenRef","onCloseRef","onOpenRef","current","handleHeadClick","currentIsAccordionOpen","shouldOnlyOpen","accordionContextProviderValue","createElement","className","$isOpen","$isParentWrapped","$isWrapped","$shouldForceBackground","$shouldHideBackground","Provider","value","transition","type","onClick","initial","maxHeight","onScroll","shouldHideBody","shouldChangeColor","displayName"],"sources":["../../../src/components/accordion/Accordion.tsx"],"sourcesContent":["import { AnimatePresence, MotionConfig } from 'framer-motion';\nimport React, {\n ChangeEventHandler,\n FC,\n ReactNode,\n UIEvent,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport AccordionBody from './accordion-body/AccordionBody';\nimport { AccordionGroupContext } from './accordion-group/AccordionGroup';\nimport AccordionHead from './accordion-head/AccordionHead';\nimport { StyledAccordion } from './Accordion.styles';\n\nexport const AccordionContext = React.createContext({ isWrapped: false });\n\nexport type AccordionProps = {\n /**\n * Maximum height of the accordion body element. This automatically makes the content of the\n * body element scrollable.\n */\n bodyMaxHeight?: number;\n /**\n * The content of the accordion body\n */\n children: ReactNode;\n /**\n * The icon that is displayed in front of the title\n */\n icon?: string;\n /**\n * This can be used to automatically expand the Accordion during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This will disable the Accordion so that it cannot be opened and will gray out the title. Does not work with isOpened.\n */\n isDisabled?: boolean;\n /**\n * This can be used so that the Accordion cannot be opened or closed.\n * In addition, in this case the icon is exchanged to mark the Accordions.\n */\n isFixed?: boolean;\n /**\n * This can be used to open the Accordion from the outside.\n */\n isOpened?: boolean;\n /**\n * This will gray out the title of the Accordion to indicate hidden content, for example.\n */\n isTitleGreyed?: boolean;\n /**\n * Function that is executed when the accordion body will be scrolled\n */\n onBodyScroll?: (event: UIEvent<HTMLDivElement>) => void;\n /**\n * Function that is executed when the accordion will be closed.\n */\n onClose?: VoidFunction;\n /**\n * Function that is executed when the accordion will be opened.\n */\n onOpen?: VoidFunction;\n /**\n * Function that is executed when the text of the search in the accordion\n * head changes. When this function is given, the search field is displayed\n * in the Accordion Head.\n */\n onSearchChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Content to be displayed on the right side in the head of the Accordion\n */\n rightElement?: ReactNode;\n /**\n * Icon to be displayed on the right side in the search input\n */\n searchIcon?: string[];\n /**\n * The placeholder to be used for the search\n */\n searchPlaceholder?: string;\n /**\n * The value that is displayed inside the search\n */\n searchValue?: string;\n /**\n * This will force the background color of the accordion to be used even if it is closed and not hovered.\n */\n shouldForceBackground?: boolean;\n /**\n * This will hide the background color of the accordion\n */\n shouldHideBackground?: boolean;\n /**\n * This will render the Accordion closed on the first render.\n */\n shouldRenderClosed?: boolean;\n /**\n * Whether the icon should be rotating.\n */\n shouldRotateIcon?: boolean;\n /**\n * Title of the Accordion displayed in the head\n */\n title: string;\n /**\n * Additional elements to be displayed in the header next to the title.\n */\n titleElement?: ReactNode;\n};\n\nconst Accordion: FC<AccordionProps> = ({\n bodyMaxHeight,\n children,\n icon,\n isDefaultOpen = false,\n isDisabled = false,\n isFixed = false,\n isOpened,\n isTitleGreyed = false,\n onBodyScroll,\n onClose,\n onOpen,\n onSearchChange,\n rightElement,\n searchIcon,\n searchPlaceholder,\n searchValue,\n shouldForceBackground = false,\n shouldHideBackground = false,\n shouldRenderClosed = false,\n shouldRotateIcon = true,\n title,\n titleElement,\n}) => {\n const { isWrapped, openAccordionUuid, updateOpenAccordionUuid } =\n useContext(AccordionGroupContext);\n const { isWrapped: isParentWrapped } = useContext(AccordionContext);\n\n const [isAccordionOpen, setIsAccordionOpen] = useState<boolean>(isDefaultOpen ?? isOpened);\n\n const uuid = useUuid();\n\n const isInitialRenderRef = useRef(true);\n\n const isInGroup = typeof updateOpenAccordionUuid === 'function';\n\n const isOpen = isInGroup ? openAccordionUuid === uuid : isAccordionOpen;\n\n const isOpenRef = useRef(isOpen);\n const onCloseRef = useRef(onClose);\n const onOpenRef = useRef(onOpen);\n\n useEffect(() => {\n isOpenRef.current = isOpen;\n onCloseRef.current = onClose;\n onOpenRef.current = onOpen;\n }, [isOpen, onClose, onOpen]);\n\n const handleHeadClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }, [isDisabled, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isDisabled && isOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }\n }, [isDisabled, isOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (isOpen) {\n if (typeof onOpenRef.current === 'function') {\n onOpenRef.current();\n }\n } else if (typeof onCloseRef.current === 'function') {\n onCloseRef.current();\n }\n }, [isOpen]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid, { shouldOnlyOpen: true });\n } else {\n setIsAccordionOpen(true);\n }\n }\n }, [isDefaultOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (typeof isOpened === 'boolean') {\n if (typeof updateOpenAccordionUuid === 'function' && isOpened !== isOpenRef.current) {\n updateOpenAccordionUuid(uuid);\n } else {\n setIsAccordionOpen(isOpened);\n }\n }\n }, [isOpened, updateOpenAccordionUuid, uuid]);\n\n const accordionContextProviderValue = useMemo(\n () => ({ isWrapped: isWrapped === true }),\n [isWrapped],\n );\n\n return (\n <StyledAccordion\n className=\"beta-chayns-accordion\"\n $isOpen={isOpen}\n $isParentWrapped={isParentWrapped}\n $isWrapped={isWrapped}\n $shouldForceBackground={shouldForceBackground}\n $shouldHideBackground={shouldHideBackground}\n >\n <AccordionContext.Provider value={accordionContextProviderValue}>\n <MotionConfig transition={{ type: 'tween' }}>\n <AccordionHead\n icon={icon}\n isOpen={isOpen}\n isFixed={isFixed}\n isTitleGreyed={isTitleGreyed || isDisabled}\n isWrapped={isWrapped === true}\n onClick={handleHeadClick}\n onSearchChange={onSearchChange}\n rightElement={rightElement}\n searchIcon={searchIcon}\n searchPlaceholder={searchPlaceholder}\n searchValue={searchValue}\n shouldRotateIcon={shouldRotateIcon}\n title={title}\n titleElement={titleElement}\n />\n <AnimatePresence initial={false}>\n {(isOpen || shouldRenderClosed) && (\n <AccordionBody\n maxHeight={bodyMaxHeight}\n onScroll={onBodyScroll}\n shouldHideBody={shouldRenderClosed && !isOpen}\n >\n <AreaContext.Provider value={{ shouldChangeColor: true }}>\n {children}\n </AreaContext.Provider>\n </AccordionBody>\n )}\n </AnimatePresence>\n </MotionConfig>\n </AccordionContext.Provider>\n </StyledAccordion>\n );\n};\n\nAccordion.displayName = 'Accordion';\n\nexport default Accordion;\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,YAAY,QAAQ,eAAe;AAC7D,OAAOC,KAAK,IAKRC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,WAAW,QAAQ,sCAAsC;AAClE,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,OAAO,MAAMC,gBAAgB,gBAAGb,KAAK,CAACc,aAAa,CAAC;EAAEC,SAAS,EAAE;AAAM,CAAC,CAAC;AAiGzE,MAAMC,SAA6B,GAAGC,IAAA,IAuBhC;EAAA,IAvBiC;IACnCC,aAAa;IACbC,QAAQ;IACRC,IAAI;IACJC,aAAa,GAAG,KAAK;IACrBC,UAAU,GAAG,KAAK;IAClBC,OAAO,GAAG,KAAK;IACfC,QAAQ;IACRC,aAAa,GAAG,KAAK;IACrBC,YAAY;IACZC,OAAO;IACPC,MAAM;IACNC,cAAc;IACdC,YAAY;IACZC,UAAU;IACVC,iBAAiB;IACjBC,WAAW;IACXC,qBAAqB,GAAG,KAAK;IAC7BC,oBAAoB,GAAG,KAAK;IAC5BC,kBAAkB,GAAG,KAAK;IAC1BC,gBAAgB,GAAG,IAAI;IACvBC,KAAK;IACLC;EACJ,CAAC,GAAAtB,IAAA;EACG,MAAM;IA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,aAAa;IACV6D,SAAS,EAAEpD,aAAc;IACzBqD,QAAQ,EAAE7C,YAAa;IACvB8C,cAAc,EAAEpC,kBAAkB,IAAI,CAACY;EAAO,gBAE9ChD,KAAA,CAAAyD,aAAA,CAACjD,WAAW,CAACwD,QAAQ;IAACC,KAAK,EAAE;MAAEQ,iBAAiB,EAAE;IAAK;EAAE,GACpDtD,QACiB,CACX,CAEN,CACP,CACS,CACd,CAAC;AAE1B,CAAC;AAEDH,SAAS,CAAC0D,WAAW,GAAG,WAAW;AAEnC,eAAe1D,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
interface IAreaProviderContext {
|
|
3
|
+
shouldChangeColor?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const AreaContext: React.Context<IAreaProviderContext>;
|
|
6
|
+
interface AreaContextProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
shouldChangeColor?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const AreaContextProvider: {
|
|
11
|
+
({ children, shouldChangeColor }: AreaContextProviderProps): React.JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
14
|
+
export default AreaContextProvider;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
export const AreaContext = /*#__PURE__*/React.createContext({
|
|
3
|
+
shouldChangeColor: undefined
|
|
4
|
+
});
|
|
5
|
+
AreaContext.displayName = 'AreaContext';
|
|
6
|
+
const AreaContextProvider = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
shouldChangeColor = true
|
|
10
|
+
} = _ref;
|
|
11
|
+
const providerValue = useMemo(() => ({
|
|
12
|
+
shouldChangeColor
|
|
13
|
+
}), [shouldChangeColor]);
|
|
14
|
+
return /*#__PURE__*/React.createElement(AreaContext.Provider, {
|
|
15
|
+
value: providerValue
|
|
16
|
+
}, children);
|
|
17
|
+
};
|
|
18
|
+
AreaContextProvider.displayName = 'AreaContextProvider';
|
|
19
|
+
export default AreaContextProvider;
|
|
20
|
+
//# sourceMappingURL=AreaContextProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AreaContextProvider.js","names":["React","useMemo","AreaContext","createContext","shouldChangeColor","undefined","displayName","AreaContextProvider","_ref","children","providerValue","createElement","Provider","value"],"sources":["../../../src/components/area-provider/AreaContextProvider.tsx"],"sourcesContent":["import React, { useMemo, type ReactNode } from 'react';\n\ninterface IAreaProviderContext {\n shouldChangeColor?: boolean;\n}\n\nexport const AreaContext = React.createContext<IAreaProviderContext>({\n shouldChangeColor: undefined,\n});\n\nAreaContext.displayName = 'AreaContext';\n\ninterface AreaContextProviderProps {\n children: ReactNode;\n shouldChangeColor?: boolean;\n}\n\nconst AreaContextProvider = ({ children, shouldChangeColor = true }: AreaContextProviderProps) => {\n const providerValue = useMemo<IAreaProviderContext>(\n () => ({\n shouldChangeColor,\n }),\n [shouldChangeColor],\n );\n\n return <AreaContext.Provider value={providerValue}>{children}</AreaContext.Provider>;\n};\n\nAreaContextProvider.displayName = 'AreaContextProvider';\n\nexport default AreaContextProvider;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAwB,OAAO;AAMtD,OAAO,MAAMC,WAAW,gBAAGF,KAAK,CAACG,aAAa,CAAuB;EACjEC,iBAAiB,EAAEC;AACvB,CAAC,CAAC;AAEFH,WAAW,CAACI,WAAW,GAAG,aAAa;AAOvC,MAAMC,mBAAmB,GAAGC,IAAA,IAAsE;EAAA,IAArE;IAAEC,QAAQ;IAAEL,iBAAiB,GAAG;EAA+B,CAAC,GAAAI,IAAA;EACzF,MAAME,aAAa,GAAGT,OAAO,CACzB,OAAO;IACHG;EACJ,CAAC,CAAC,EACF,CAACA,iBAAiB,CACtB,CAAC;EAED,oBAAOJ,KAAA,CAAAW,aAAA,CAACT,WAAW,CAACU,QAAQ;IAACC,KAAK,EAAEH;EAAc,GAAED,QAA+B,CAAC;AACxF,CAAC;AAEDF,mBAAmB,CAACD,WAAW,GAAG,qBAAqB;AAEvD,eAAeC,mBAAmB","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext, useMemo } from 'react';
|
|
2
2
|
import { ContentCardType } from '../../types/contentCard';
|
|
3
|
+
import AreaContextProvider, { AreaContext } from '../area-provider/AreaContextProvider';
|
|
3
4
|
import { StyledContentCard } from './ContentCard.styles';
|
|
4
5
|
const ContentCard = _ref => {
|
|
5
6
|
let {
|
|
@@ -7,10 +8,15 @@ const ContentCard = _ref => {
|
|
|
7
8
|
onClick,
|
|
8
9
|
type = ContentCardType.Default
|
|
9
10
|
} = _ref;
|
|
11
|
+
const areaProvider = useContext(AreaContext);
|
|
12
|
+
const shouldChangeColor = useMemo(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
|
|
10
13
|
return /*#__PURE__*/React.createElement(StyledContentCard, {
|
|
11
14
|
onClick: onClick,
|
|
12
|
-
$type: type
|
|
13
|
-
|
|
15
|
+
$type: type,
|
|
16
|
+
$shouldChangeColor: shouldChangeColor
|
|
17
|
+
}, /*#__PURE__*/React.createElement(AreaContextProvider, {
|
|
18
|
+
shouldChangeColor: !shouldChangeColor
|
|
19
|
+
}, children));
|
|
14
20
|
};
|
|
15
21
|
ContentCard.displayName = 'ContentCard';
|
|
16
22
|
export default ContentCard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentCard.js","names":["React","ContentCardType","StyledContentCard","ContentCard","_ref","children","onClick","type","Default","createElement","$type","displayName"],"sources":["../../../src/components/content-card/ContentCard.tsx"],"sourcesContent":["import React, { FC, ReactNode } from 'react';\nimport { ContentCardType } from '../../types/contentCard';\nimport { StyledContentCard } from './ContentCard.styles';\n\nexport type ContentCardProps = {\n /**\n * The content of the content card\n */\n children?: ReactNode;\n /**\n * The onClick event handler\n */\n onClick?: () => void;\n /**\n * The type of the content card\n */\n type?: ContentCardType;\n};\n\nconst ContentCard: FC<ContentCardProps> = ({\n children,\n onClick,\n type = ContentCardType.Default,\n}) => (\n <StyledContentCard onClick={onClick} $type={type}>\n
|
|
1
|
+
{"version":3,"file":"ContentCard.js","names":["React","useContext","useMemo","ContentCardType","AreaContextProvider","AreaContext","StyledContentCard","ContentCard","_ref","children","onClick","type","Default","areaProvider","shouldChangeColor","createElement","$type","$shouldChangeColor","displayName"],"sources":["../../../src/components/content-card/ContentCard.tsx"],"sourcesContent":["import React, { FC, ReactNode, useContext, useMemo } from 'react';\nimport { ContentCardType } from '../../types/contentCard';\nimport AreaContextProvider, { AreaContext } from '../area-provider/AreaContextProvider';\nimport { StyledContentCard } from './ContentCard.styles';\n\nexport type ContentCardProps = {\n /**\n * The content of the content card\n */\n children?: ReactNode;\n /**\n * The onClick event handler\n */\n onClick?: () => void;\n /**\n * The type of the content card\n */\n type?: ContentCardType;\n};\n\nconst ContentCard: FC<ContentCardProps> = ({\n children,\n onClick,\n type = ContentCardType.Default,\n}) => {\n const areaProvider = useContext(AreaContext);\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n return (\n <StyledContentCard onClick={onClick} $type={type} $shouldChangeColor={shouldChangeColor}>\n <AreaContextProvider shouldChangeColor={!shouldChangeColor}>\n {children}\n </AreaContextProvider>\n </StyledContentCard>\n );\n};\n\nContentCard.displayName = 'ContentCard';\n\nexport default ContentCard;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAmBC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AACjE,SAASC,eAAe,QAAQ,yBAAyB;AACzD,OAAOC,mBAAmB,IAAIC,WAAW,QAAQ,sCAAsC;AACvF,SAASC,iBAAiB,QAAQ,sBAAsB;AAiBxD,MAAMC,WAAiC,GAAGC,IAAA,IAIpC;EAAA,IAJqC;IACvCC,QAAQ;IACRC,OAAO;IACPC,IAAI,GAAGR,eAAe,CAACS;EAC3B,CAAC,GAAAJ,IAAA;EACG,MAAMK,YAAY,GAAGZ,UAAU,CAACI,WAAW,CAAC;EAE5C,MAAMS,iBAAiB,GAAGZ,OAAO,CAC7B,MAAMW,YAAY,CAACC,iBAAiB,IAAI,KAAK,EAC7C,CAACD,YAAY,CAACC,iBAAiB,CACnC,CAAC;EAED,oBACId,KAAA,CAAAe,aAAA,CAACT,iBAAiB;IAACI,OAAO,EAAEA,OAAQ;IAACM,KAAK,EAAEL,IAAK;IAACM,kBAAkB,EAAEH;EAAkB,gBACpFd,KAAA,CAAAe,aAAA,CAACX,mBAAmB;IAACU,iBAAiB,EAAE,CAACA;EAAkB,GACtDL,QACgB,CACN,CAAC;AAE5B,CAAC;AAEDF,WAAW,CAACW,WAAW,GAAG,aAAa;AAEvC,eAAeX,WAAW","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@ import { ContentCardType } from '../../types/contentCard';
|
|
|
3
3
|
import type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';
|
|
4
4
|
type StyledContentCardProps = WithTheme<{
|
|
5
5
|
$type: ContentCardType;
|
|
6
|
+
$shouldChangeColor: boolean;
|
|
6
7
|
}>;
|
|
7
8
|
export declare const StyledContentCard: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledContentCardProps>>;
|
|
8
9
|
export {};
|
|
@@ -7,24 +7,41 @@ export const StyledContentCard = styled.div`
|
|
|
7
7
|
} = _ref;
|
|
8
8
|
return theme.cardBorderRadius;
|
|
9
9
|
}}px;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
${_ref2 => {
|
|
12
12
|
let {
|
|
13
|
-
theme
|
|
13
|
+
theme,
|
|
14
|
+
$shouldChangeColor
|
|
14
15
|
} = _ref2;
|
|
15
|
-
return
|
|
16
|
-
}
|
|
16
|
+
return !$shouldChangeColor && css`
|
|
17
|
+
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${theme.cardShadow});
|
|
18
|
+
`;
|
|
19
|
+
}};
|
|
20
|
+
|
|
17
21
|
padding: 8px 12px;
|
|
18
22
|
|
|
23
|
+
color: ${_ref3 => {
|
|
24
|
+
let {
|
|
25
|
+
theme
|
|
26
|
+
} = _ref3;
|
|
27
|
+
return theme.text;
|
|
28
|
+
}};
|
|
29
|
+
|
|
19
30
|
&:not(:last-child) {
|
|
20
31
|
margin-bottom: 8px;
|
|
21
32
|
}
|
|
22
33
|
|
|
23
|
-
${
|
|
34
|
+
${_ref4 => {
|
|
24
35
|
let {
|
|
25
36
|
$type,
|
|
26
|
-
theme
|
|
27
|
-
|
|
37
|
+
theme,
|
|
38
|
+
$shouldChangeColor
|
|
39
|
+
} = _ref4;
|
|
40
|
+
if ($type === ContentCardType.Default && $shouldChangeColor) {
|
|
41
|
+
return css`
|
|
42
|
+
background-color: rgba(${theme['000-rgb']}, ${theme.cardBackgroundOpacity});
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
28
45
|
switch ($type) {
|
|
29
46
|
case ContentCardType.Error:
|
|
30
47
|
return css`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentCard.styles.js","names":["styled","css","ContentCardType","StyledContentCard","div","_ref","theme","cardBorderRadius","_ref2","cardShadow","_ref3","$type","Error","Success","Warning"
|
|
1
|
+
{"version":3,"file":"ContentCard.styles.js","names":["styled","css","ContentCardType","StyledContentCard","div","_ref","theme","cardBorderRadius","_ref2","$shouldChangeColor","cardShadow","_ref3","text","_ref4","$type","Default","cardBackgroundOpacity","Error","Success","Warning"],"sources":["../../../src/components/content-card/ContentCard.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport { ContentCardType } from '../../types/contentCard';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledContentCardProps = WithTheme<{\n $type: ContentCardType;\n $shouldChangeColor: boolean;\n}>;\n\nexport const StyledContentCard = styled.div<StyledContentCardProps>`\n border-radius: ${({ theme }: StyledContentCardProps) => theme.cardBorderRadius}px;\n\n ${({ theme, $shouldChangeColor }: StyledContentCardProps) =>\n !$shouldChangeColor &&\n css`\n box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${theme.cardShadow});\n `};\n\n padding: 8px 12px;\n\n color: ${({ theme }: StyledContentCardProps) => theme.text};\n\n &:not(:last-child) {\n margin-bottom: 8px;\n }\n\n ${({ $type, theme, $shouldChangeColor }: StyledContentCardProps) => {\n if ($type === ContentCardType.Default && $shouldChangeColor) {\n return css`\n background-color: rgba(${theme['000-rgb']}, ${theme.cardBackgroundOpacity});\n `;\n }\n\n switch ($type) {\n case ContentCardType.Error:\n return css`\n background-color: ${theme['red-4']};\n border: 1px solid ${theme['red-1']};\n color: #222;\n `;\n case ContentCardType.Success:\n return css`\n background-color: ${theme['green-4']};\n border: 1px solid ${theme['green-1']};\n color: #222;\n `;\n case ContentCardType.Warning:\n return css`\n background-color: ${theme['yellow-4']};\n border: 1px solid ${theme['yellow-1']};\n color: #222;\n `;\n default:\n return css`\n background-color: rgba(\n ${theme['secondary-100-rgb']},\n ${theme.cardBackgroundOpacity}\n );\n `;\n }\n }}\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAC/C,SAASC,eAAe,QAAQ,yBAAyB;AAQzD,OAAO,MAAMC,iBAAiB,GAAGH,MAAM,CAACI,GAA4B;AACpE,qBAAqBC,IAAA;EAAA,IAAC;IAAEC;EAA8B,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAACC,gBAAgB;AAAA,CAAC;AACnF;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEF,KAAK;IAAEG;EAA2C,CAAC,GAAAD,KAAA;EAAA,OACpD,CAACC,kBAAkB,IACnBR,GAAI;AACZ,oDAAoDK,KAAK,CAACI,UAAW;AACrE,SAAS;AAAA,CAAC;AACV;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEL;EAA8B,CAAC,GAAAK,KAAA;EAAA,OAAKL,KAAK,CAACM,IAAI;AAAA,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA,IAAkE;EAAA,IAAjE;IAAEC,KAAK;IAAER,KAAK;IAAEG;EAA2C,CAAC,GAAAI,KAAA;EAC3D,IAAIC,KAAK,KAAKZ,eAAe,CAACa,OAAO,IAAIN,kBAAkB,EAAE;IACzD,OAAOR,GAAI;AACvB,yCAAyCK,KAAK,CAAC,SAAS,CAAE,KAAIA,KAAK,CAACU,qBAAsB;AAC1F,aAAa;EACL;EAEA,QAAQF,KAAK;IACT,KAAKZ,eAAe,CAACe,KAAK;MACtB,OAAOhB,GAAI;AAC3B,wCAAwCK,KAAK,CAAC,OAAO,CAAE;AACvD,wCAAwCA,KAAK,CAAC,OAAO,CAAE;AACvD;AACA,iBAAiB;IACL,KAAKJ,eAAe,CAACgB,OAAO;MACxB,OAAOjB,GAAI;AAC3B,wCAAwCK,KAAK,CAAC,SAAS,CAAE;AACzD,wCAAwCA,KAAK,CAAC,SAAS,CAAE;AACzD;AACA,iBAAiB;IACL,KAAKJ,eAAe,CAACiB,OAAO;MACxB,OAAOlB,GAAI;AAC3B,wCAAwCK,KAAK,CAAC,UAAU,CAAE;AAC1D,wCAAwCA,KAAK,CAAC,UAAU,CAAE;AAC1D;AACA,iBAAiB;IACL;MACI,OAAOL,GAAI;AAC3B;AACA,0BAA0BK,KAAK,CAAC,mBAAmB,CAAE;AACrD,0BAA0BA,KAAK,CAACU,qBAAsB;AACtD;AACA,iBAAiB;EACT;AACJ,CAAE;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
+
import type { FileInputFileItem } from '../../types/fileInput';
|
|
2
3
|
export type FileInputProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Already uploaded files to display.
|
|
6
|
+
*/
|
|
7
|
+
files?: FileInputFileItem[];
|
|
3
8
|
/**
|
|
4
9
|
* An array of icons that should be displayed inside the FileInput
|
|
5
10
|
*/
|
|
@@ -35,7 +40,7 @@ export type FileInputProps = {
|
|
|
35
40
|
/**
|
|
36
41
|
* A function to be executed when a file is removed.
|
|
37
42
|
*/
|
|
38
|
-
onRemove?: (file: File | string) => void;
|
|
43
|
+
onRemove?: (file: File | FileInputFileItem | string) => void;
|
|
39
44
|
};
|
|
40
45
|
declare const FileInput: FC<FileInputProps>;
|
|
41
46
|
export default FileInput;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createDialog, DialogType } from 'chayns-api';
|
|
2
2
|
import { AnimatePresence } from 'framer-motion';
|
|
3
3
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
4
|
-
import { filterDuplicateFile, filterDuplicateFileUrls } from '../../utils/file';
|
|
4
|
+
import { filterDuplicateFile, filterDuplicateFileUrls, isValidFileType } from '../../utils/file';
|
|
5
5
|
import { selectFiles } from '../../utils/fileDialog';
|
|
6
6
|
import Icon from '../icon/Icon';
|
|
7
7
|
import List from '../list/List';
|
|
8
8
|
import FileListItem from './file-list/FileListItem';
|
|
9
|
-
import { StyledFileInput, StyledFileInputContainer, StyledFileInputText, StyledFileInputWrapper, StyledMotionFileInputList } from './FileInput.styles';
|
|
9
|
+
import { StyledFileInput, StyledFileInputContainer, StyledFileInputText, StyledFileInputWrapper, StyledMotionFileInputList, StyledUploadedFilesList } from './FileInput.styles';
|
|
10
10
|
const FileInput = _ref => {
|
|
11
11
|
let {
|
|
12
12
|
fileSelectionIcons = ['fa fa-upload'],
|
|
@@ -15,6 +15,7 @@ const FileInput = _ref => {
|
|
|
15
15
|
onMaxFilesReached,
|
|
16
16
|
maxFiles,
|
|
17
17
|
onRemove,
|
|
18
|
+
files,
|
|
18
19
|
onAdd,
|
|
19
20
|
fileSelectionPlaceholder = 'Dateien hinzufügen',
|
|
20
21
|
imageSelectPlaceholder
|
|
@@ -33,16 +34,22 @@ const FileInput = _ref => {
|
|
|
33
34
|
});
|
|
34
35
|
let tmp = newImages;
|
|
35
36
|
if (maxFiles) {
|
|
36
|
-
tmp = newImages.slice(0, maxFiles - (internalFiles.length + internalImages.length));
|
|
37
|
+
tmp = newImages.slice(0, maxFiles - (internalFiles.length + internalImages.length + (files?.length ?? 0)));
|
|
37
38
|
}
|
|
38
39
|
if (tmp.length > 0 && typeof onAdd === 'function') {
|
|
39
40
|
onAdd(tmp);
|
|
40
41
|
}
|
|
41
42
|
setInternalImages(prevState => [...prevState, ...tmp]);
|
|
42
|
-
}, [internalFiles.length, internalImages, maxFiles, onAdd]);
|
|
43
|
-
const handleAddFiles = useCallback(
|
|
43
|
+
}, [files?.length, internalFiles.length, internalImages, maxFiles, onAdd]);
|
|
44
|
+
const handleAddFiles = useCallback(newFiles => {
|
|
44
45
|
const newFileItems = [];
|
|
45
|
-
|
|
46
|
+
newFiles.forEach(file => {
|
|
47
|
+
if (fileTypes && !isValidFileType({
|
|
48
|
+
file,
|
|
49
|
+
types: fileTypes
|
|
50
|
+
})) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
46
53
|
if (file && !filterDuplicateFile({
|
|
47
54
|
files: internalFiles,
|
|
48
55
|
newFile: file
|
|
@@ -52,13 +59,13 @@ const FileInput = _ref => {
|
|
|
52
59
|
});
|
|
53
60
|
let tmp = newFileItems;
|
|
54
61
|
if (maxFiles) {
|
|
55
|
-
tmp = newFileItems.slice(0, maxFiles - (internalFiles.length + internalImages.length));
|
|
62
|
+
tmp = newFileItems.slice(0, maxFiles - (internalFiles.length + internalImages.length + (files?.length ?? 0)));
|
|
56
63
|
}
|
|
57
64
|
if (tmp.length > 0 && typeof onAdd === 'function') {
|
|
58
65
|
onAdd(tmp);
|
|
59
66
|
}
|
|
60
67
|
setInternalFiles(prevState => [...prevState, ...tmp]);
|
|
61
|
-
}, [internalFiles, internalImages.length, maxFiles, onAdd]);
|
|
68
|
+
}, [files?.length, internalFiles, internalImages.length, maxFiles, onAdd]);
|
|
62
69
|
const handleDeleteFile = useCallback(fileName => {
|
|
63
70
|
let fileToDelete;
|
|
64
71
|
const filteredFiles = internalFiles.filter(file => {
|
|
@@ -80,11 +87,18 @@ const FileInput = _ref => {
|
|
|
80
87
|
});
|
|
81
88
|
setInternalImages(filteredImages);
|
|
82
89
|
}
|
|
90
|
+
if (!fileToDelete) {
|
|
91
|
+
files?.forEach(file => {
|
|
92
|
+
if (file.url === fileName || file.name === fileName) {
|
|
93
|
+
fileToDelete = file;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
83
97
|
if (!fileToDelete || typeof onRemove !== 'function') {
|
|
84
98
|
return;
|
|
85
99
|
}
|
|
86
100
|
onRemove(fileToDelete);
|
|
87
|
-
}, [internalFiles, internalImages, onRemove]);
|
|
101
|
+
}, [files, internalFiles, internalImages, onRemove]);
|
|
88
102
|
const isDisabled = useMemo(() => {
|
|
89
103
|
if (maxFiles) {
|
|
90
104
|
if (internalFiles.length + internalImages.length >= maxFiles) {
|
|
@@ -131,11 +145,11 @@ const FileInput = _ref => {
|
|
|
131
145
|
if (isDisabled) {
|
|
132
146
|
return;
|
|
133
147
|
}
|
|
134
|
-
const
|
|
148
|
+
const newFiles = await selectFiles({
|
|
135
149
|
multiple: true,
|
|
136
150
|
type: fileTypes
|
|
137
151
|
});
|
|
138
|
-
handleAddFiles(
|
|
152
|
+
handleAddFiles(newFiles);
|
|
139
153
|
}, [fileTypes, handleAddFiles, isDisabled]);
|
|
140
154
|
const handleDrop = useCallback(e => {
|
|
141
155
|
e.preventDefault();
|
|
@@ -167,6 +181,37 @@ const FileInput = _ref => {
|
|
|
167
181
|
})));
|
|
168
182
|
return items;
|
|
169
183
|
}, [handleDeleteFile, internalFiles, internalImages]);
|
|
184
|
+
const uploadedFiles = useMemo(() => {
|
|
185
|
+
const items = [];
|
|
186
|
+
const cutFiles = maxFiles ? files?.splice(0, maxFiles) : files;
|
|
187
|
+
cutFiles?.forEach(_ref2 => {
|
|
188
|
+
let {
|
|
189
|
+
url,
|
|
190
|
+
id,
|
|
191
|
+
name
|
|
192
|
+
} = _ref2;
|
|
193
|
+
items.push( /*#__PURE__*/React.createElement(StyledMotionFileInputList, {
|
|
194
|
+
animate: {
|
|
195
|
+
height: 'auto',
|
|
196
|
+
opacity: 1
|
|
197
|
+
},
|
|
198
|
+
exit: {
|
|
199
|
+
height: 0,
|
|
200
|
+
opacity: 0
|
|
201
|
+
},
|
|
202
|
+
key: id,
|
|
203
|
+
transition: {
|
|
204
|
+
duration: 0.25,
|
|
205
|
+
type: 'tween'
|
|
206
|
+
}
|
|
207
|
+
}, /*#__PURE__*/React.createElement(FileListItem, {
|
|
208
|
+
url: url,
|
|
209
|
+
onRemove: handleDeleteFile,
|
|
210
|
+
fileName: name
|
|
211
|
+
})));
|
|
212
|
+
});
|
|
213
|
+
return items;
|
|
214
|
+
}, [files, handleDeleteFile, maxFiles]);
|
|
170
215
|
return useMemo(() => /*#__PURE__*/React.createElement(StyledFileInput, null, /*#__PURE__*/React.createElement(StyledFileInputWrapper, {
|
|
171
216
|
$isDisabled: isDisabled
|
|
172
217
|
}, /*#__PURE__*/React.createElement(StyledFileInputContainer, {
|
|
@@ -182,7 +227,11 @@ const FileInput = _ref => {
|
|
|
182
227
|
icons: imageSelectIcons
|
|
183
228
|
}), /*#__PURE__*/React.createElement(StyledFileInputText, null, imageSelectPlaceholder))), /*#__PURE__*/React.createElement(List, null, /*#__PURE__*/React.createElement(AnimatePresence, {
|
|
184
229
|
initial: false
|
|
185
|
-
}, content))
|
|
230
|
+
}, content)), uploadedFiles.length > 0 && /*#__PURE__*/React.createElement(StyledUploadedFilesList, {
|
|
231
|
+
$shouldShowBorder: content.length > 0
|
|
232
|
+
}, /*#__PURE__*/React.createElement(List, null, /*#__PURE__*/React.createElement(AnimatePresence, {
|
|
233
|
+
initial: false
|
|
234
|
+
}, uploadedFiles)))), [isDisabled, fileSelectionIcons, fileSelectionPlaceholder, imageSelectPlaceholder, imageSelectIcons, content, uploadedFiles, handleFileSelectionClick, handleDrop, handleImageSelectionClick]);
|
|
186
235
|
};
|
|
187
236
|
FileInput.displayName = 'FileInput';
|
|
188
237
|
export default FileInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.js","names":["createDialog","DialogType","AnimatePresence","React","useCallback","useMemo","useState","filterDuplicateFile","filterDuplicateFileUrls","selectFiles","Icon","List","FileListItem","StyledFileInput","StyledFileInputContainer","StyledFileInputText","StyledFileInputWrapper","StyledMotionFileInputList","FileInput","_ref","fileSelectionIcons","imageSelectIcons","fileTypes","onMaxFilesReached","maxFiles","onRemove","onAdd","fileSelectionPlaceholder","imageSelectPlaceholder","internalFiles","setInternalFiles","internalImages","setInternalImages","handleAddImages","images","newImages","forEach","image","files","newFile","push","tmp","slice","length","prevState","handleAddFiles","newFileItems","file","handleDeleteFile","fileName","fileToDelete","filteredFiles","filter","name","filteredImages","isDisabled","handleImageSelectionClick","buttonType","result","dialogInput","upload","buttons","text","initialView","type","MODULE","system","url","scope","module","open","handleFileSelectionClick","multiple","handleDrop","e","preventDefault","draggedFiles","Array","from","dataTransfer","content","combinedFiles","items","map","createElement","animate","height","opacity","exit","key","transition","duration","fileType","undefined","fileSize","size","$isDisabled","onClick","onDragOver","onDrop","icons","$isImageSelection","initial","displayName"],"sources":["../../../src/components/file-input/FileInput.tsx"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\nimport { AnimatePresence } from 'framer-motion';\nimport React, { DragEvent, FC, ReactElement, useCallback, useMemo, useState } from 'react';\nimport type { ImageDialogResult } from '../../types/fileInput';\nimport { filterDuplicateFile, filterDuplicateFileUrls } from '../../utils/file';\nimport { selectFiles } from '../../utils/fileDialog';\nimport Icon from '../icon/Icon';\nimport List from '../list/List';\nimport FileListItem from './file-list/FileListItem';\nimport {\n StyledFileInput,\n StyledFileInputContainer,\n StyledFileInputText,\n StyledFileInputWrapper,\n StyledMotionFileInputList,\n} from './FileInput.styles';\n\nexport type FileInputProps = {\n /**\n * An array of icons that should be displayed inside the FileInput\n */\n fileSelectionIcons?: string[];\n /**\n * The text that should be displayed inside the FileInput.\n */\n fileSelectionPlaceholder?: string;\n /**\n * The filetypes that could be selected. Example for multiple types: 'image/*, video/*'.\n */\n fileTypes?: string;\n /**\n * The icon of the image selection.\n */\n imageSelectIcons?: string[];\n /**\n * If set, pictures can be select via Pixabay.\n */\n imageSelectPlaceholder?: string;\n /**\n * The maximum amount of Files that can be uploaded.\n */\n maxFiles?: number;\n /**\n * A function to be executed when files are added.\n */\n onAdd?: (files: File[] | string[]) => void;\n /**\n * Function to be executed when the maximum amount of Files are reached.\n */\n onMaxFilesReached?: () => void;\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (file: File | string) => void;\n};\n\nconst FileInput: FC<FileInputProps> = ({\n fileSelectionIcons = ['fa fa-upload'],\n imageSelectIcons = ['ts-image'],\n fileTypes,\n onMaxFilesReached,\n maxFiles,\n onRemove,\n onAdd,\n fileSelectionPlaceholder = 'Dateien hinzufügen',\n imageSelectPlaceholder,\n}) => {\n const [internalFiles, setInternalFiles] = useState<File[]>([]);\n const [internalImages, setInternalImages] = useState<string[]>([]);\n\n const handleAddImages = useCallback(\n (images: string[]) => {\n const newImages: string[] = [];\n\n images.forEach((image) => {\n if (!filterDuplicateFileUrls({ files: internalImages, newFile: image })) {\n newImages.push(image);\n }\n });\n\n let tmp = newImages;\n\n if (maxFiles) {\n tmp = newImages.slice(0, maxFiles - (internalFiles.length + internalImages.length));\n }\n\n if (tmp.length > 0 && typeof onAdd === 'function') {\n onAdd(tmp);\n }\n\n setInternalImages((prevState) => [...prevState, ...tmp]);\n },\n [internalFiles.length, internalImages, maxFiles, onAdd],\n );\n\n const handleAddFiles = useCallback(\n (files: File[]) => {\n const newFileItems: File[] = [];\n\n files.forEach((file) => {\n if (file && !filterDuplicateFile({ files: internalFiles, newFile: file })) {\n newFileItems.push(file);\n }\n });\n\n let tmp = newFileItems;\n\n if (maxFiles) {\n tmp = newFileItems.slice(\n 0,\n maxFiles - (internalFiles.length + internalImages.length),\n );\n }\n\n if (tmp.length > 0 && typeof onAdd === 'function') {\n onAdd(tmp);\n }\n\n setInternalFiles((prevState) => [...prevState, ...tmp]);\n },\n [internalFiles, internalImages.length, maxFiles, onAdd],\n );\n\n const handleDeleteFile = useCallback(\n (fileName?: string) => {\n let fileToDelete: File | string | undefined;\n\n const filteredFiles = internalFiles.filter((file) => {\n const { name } = file;\n\n if (name === fileName) {\n fileToDelete = file;\n }\n\n return name !== fileName;\n });\n\n setInternalFiles(filteredFiles);\n\n if (!fileToDelete) {\n const filteredImages = internalImages.filter((image) => {\n if (image === fileName) {\n fileToDelete = image;\n }\n\n return image !== fileName;\n });\n\n setInternalImages(filteredImages);\n }\n\n if (!fileToDelete || typeof onRemove !== 'function') {\n return;\n }\n\n onRemove(fileToDelete);\n },\n [internalFiles, internalImages, onRemove],\n );\n\n const isDisabled = useMemo(() => {\n if (maxFiles) {\n if (internalFiles.length + internalImages.length >= maxFiles) {\n if (typeof onMaxFilesReached === 'function') {\n onMaxFilesReached();\n }\n\n return true;\n }\n }\n\n return false;\n }, [internalFiles.length, internalImages.length, maxFiles, onMaxFilesReached]);\n\n const handleImageSelectionClick = useCallback(async () => {\n if (isDisabled) {\n return;\n }\n\n const { buttonType, result } = (await createDialog({\n dialogInput: {\n upload: true,\n buttons: [\n { text: 'hello', buttonType: 1 },\n { text: 'can', buttonType: -1 },\n ],\n initialView: 'pixabay',\n },\n type: DialogType.MODULE,\n system: {\n url: 'https://tapp.chayns-static.space/api/dialog-image-editor/v1/remoteEntry.js',\n scope: 'dialog_image_editor',\n module: './ImageEditorEntry',\n },\n buttons: [],\n }).open()) as ImageDialogResult;\n\n if (buttonType === 1 && result?.url) {\n handleAddImages([result.url]);\n }\n }, [handleAddImages, isDisabled]);\n\n const handleFileSelectionClick = useCallback(async () => {\n if (isDisabled) {\n return;\n }\n\n const files = await selectFiles({\n multiple: true,\n type: fileTypes,\n });\n\n handleAddFiles(files);\n }, [fileTypes, handleAddFiles, isDisabled]);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n const draggedFiles = Array.from(e.dataTransfer.files);\n\n handleAddFiles(draggedFiles);\n },\n [handleAddFiles],\n );\n\n const content = useMemo(() => {\n const combinedFiles = [...internalImages, ...internalFiles];\n\n const items: ReactElement[] = combinedFiles.map((file) => (\n <StyledMotionFileInputList\n animate={{ height: 'auto', opacity: 1 }}\n exit={{ height: 0, opacity: 0 }}\n key={typeof file === 'string' ? file : file.name}\n transition={{ duration: 0.25, type: 'tween' }}\n >\n <FileListItem\n fileType={typeof file !== 'string' ? file.type : undefined}\n fileName={typeof file !== 'string' ? file.name : undefined}\n fileSize={typeof file !== 'string' ? file.size : undefined}\n url={typeof file === 'string' ? file : undefined}\n onRemove={handleDeleteFile}\n />\n </StyledMotionFileInputList>\n ));\n\n return items;\n }, [handleDeleteFile, internalFiles, internalImages]);\n\n return useMemo(\n () => (\n <StyledFileInput>\n <StyledFileInputWrapper $isDisabled={isDisabled}>\n <StyledFileInputContainer\n onClick={() => void handleFileSelectionClick()}\n onDragOver={(e: DragEvent<HTMLDivElement>) => e.preventDefault()}\n onDrop={(e: DragEvent<HTMLDivElement>) => void handleDrop(e)}\n >\n <Icon icons={fileSelectionIcons} />\n <StyledFileInputText>{fileSelectionPlaceholder}</StyledFileInputText>\n </StyledFileInputContainer>\n {imageSelectPlaceholder && (\n <StyledFileInputContainer\n $isImageSelection\n onClick={() => void handleImageSelectionClick()}\n >\n <Icon icons={imageSelectIcons} />\n <StyledFileInputText>{imageSelectPlaceholder}</StyledFileInputText>\n </StyledFileInputContainer>\n )}\n </StyledFileInputWrapper>\n\n <List>\n <AnimatePresence initial={false}>{content}</AnimatePresence>\n </List>\n </StyledFileInput>\n ),\n [\n isDisabled,\n fileSelectionIcons,\n fileSelectionPlaceholder,\n imageSelectPlaceholder,\n imageSelectIcons,\n content,\n handleFileSelectionClick,\n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,eAAerF,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FileInput.js","names":["createDialog","DialogType","AnimatePresence","React","useCallback","useMemo","useState","filterDuplicateFile","filterDuplicateFileUrls","isValidFileType","selectFiles","Icon","List","FileListItem","StyledFileInput","StyledFileInputContainer","StyledFileInputText","StyledFileInputWrapper","StyledMotionFileInputList","StyledUploadedFilesList","FileInput","_ref","fileSelectionIcons","imageSelectIcons","fileTypes","onMaxFilesReached","maxFiles","onRemove","files","onAdd","fileSelectionPlaceholder","imageSelectPlaceholder","internalFiles","setInternalFiles","internalImages","setInternalImages","handleAddImages","images","newImages","forEach","image","newFile","push","tmp","slice","length","prevState","handleAddFiles","newFiles","newFileItems","file","types","handleDeleteFile","fileName","fileToDelete","filteredFiles","filter","name","filteredImages","url","isDisabled","handleImageSelectionClick","buttonType","result","dialogInput","upload","buttons","text","initialView","type","MODULE","system","scope","module","open","handleFileSelectionClick","multiple","handleDrop","e","preventDefault","draggedFiles","Array","from","dataTransfer","content","combinedFiles","items","map","createElement","animate","height","opacity","exit","key","transition","duration","fileType","undefined","fileSize","size","uploadedFiles","cutFiles","splice","_ref2","id","$isDisabled","onClick","onDragOver","onDrop","icons","$isImageSelection","initial","$shouldShowBorder","displayName"],"sources":["../../../src/components/file-input/FileInput.tsx"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\nimport { AnimatePresence } from 'framer-motion';\nimport React, { DragEvent, FC, ReactElement, useCallback, useMemo, useState } from 'react';\nimport type { FileInputFileItem, ImageDialogResult } from '../../types/fileInput';\nimport { filterDuplicateFile, filterDuplicateFileUrls, isValidFileType } from '../../utils/file';\nimport { selectFiles } from '../../utils/fileDialog';\nimport Icon from '../icon/Icon';\nimport List from '../list/List';\nimport FileListItem from './file-list/FileListItem';\nimport {\n StyledFileInput,\n StyledFileInputContainer,\n StyledFileInputText,\n StyledFileInputWrapper,\n StyledMotionFileInputList,\n StyledUploadedFilesList,\n} from './FileInput.styles';\n\nexport type FileInputProps = {\n /**\n * Already uploaded files to display.\n */\n files?: FileInputFileItem[];\n /**\n * An array of icons that should be displayed inside the FileInput\n */\n fileSelectionIcons?: string[];\n /**\n * The text that should be displayed inside the FileInput.\n */\n fileSelectionPlaceholder?: string;\n /**\n * The filetypes that could be selected. Example for multiple types: 'image/*, video/*'.\n */\n fileTypes?: string;\n /**\n * The icon of the image selection.\n */\n imageSelectIcons?: string[];\n /**\n * If set, pictures can be select via Pixabay.\n */\n imageSelectPlaceholder?: string;\n /**\n * The maximum amount of Files that can be uploaded.\n */\n maxFiles?: number;\n /**\n * A function to be executed when files are added.\n */\n onAdd?: (files: File[] | string[]) => void;\n /**\n * Function to be executed when the maximum amount of Files are reached.\n */\n onMaxFilesReached?: () => void;\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (file: File | FileInputFileItem | string) => void;\n};\n\nconst FileInput: FC<FileInputProps> = ({\n fileSelectionIcons = ['fa fa-upload'],\n imageSelectIcons = ['ts-image'],\n fileTypes,\n onMaxFilesReached,\n maxFiles,\n onRemove,\n files,\n onAdd,\n fileSelectionPlaceholder = 'Dateien hinzufügen',\n imageSelectPlaceholder,\n}) => {\n const [internalFiles, setInternalFiles] = useState<File[]>([]);\n const [internalImages, setInternalImages] = useState<string[]>([]);\n\n const handleAddImages = useCallback(\n (images: string[]) => {\n const newImages: string[] = [];\n\n images.forEach((image) => {\n if (!filterDuplicateFileUrls({ files: internalImages, newFile: image })) {\n newImages.push(image);\n }\n });\n\n let tmp = newImages;\n\n if (maxFiles) {\n tmp = newImages.slice(\n 0,\n maxFiles -\n (internalFiles.length + internalImages.length + (files?.length ?? 0)),\n );\n }\n\n if (tmp.length > 0 && typeof onAdd === 'function') {\n onAdd(tmp);\n }\n\n setInternalImages((prevState) => [...prevState, ...tmp]);\n },\n [files?.length, internalFiles.length, internalImages, maxFiles, onAdd],\n );\n\n const handleAddFiles = useCallback(\n (newFiles: File[]) => {\n const newFileItems: File[] = [];\n\n newFiles.forEach((file) => {\n if (fileTypes && !isValidFileType({ file, types: fileTypes })) {\n return;\n }\n\n if (file && !filterDuplicateFile({ files: internalFiles, newFile: file })) {\n newFileItems.push(file);\n }\n });\n\n let tmp = newFileItems;\n\n if (maxFiles) {\n tmp = newFileItems.slice(\n 0,\n maxFiles -\n (internalFiles.length + internalImages.length + (files?.length ?? 0)),\n );\n }\n\n if (tmp.length > 0 && typeof onAdd === 'function') {\n onAdd(tmp);\n }\n\n setInternalFiles((prevState) => [...prevState, ...tmp]);\n },\n [files?.length, internalFiles, internalImages.length, maxFiles, onAdd],\n );\n\n const handleDeleteFile = useCallback(\n (fileName?: string) => {\n let fileToDelete: File | FileInputFileItem | string | undefined;\n\n const filteredFiles = internalFiles.filter((file) => {\n const { name } = file;\n\n if (name === fileName) {\n fileToDelete = file;\n }\n\n return name !== fileName;\n });\n\n setInternalFiles(filteredFiles);\n\n if (!fileToDelete) {\n const filteredImages = internalImages.filter((image) => {\n if (image === fileName) {\n fileToDelete = image;\n }\n\n return image !== fileName;\n });\n\n setInternalImages(filteredImages);\n }\n\n if (!fileToDelete) {\n files?.forEach((file) => {\n if (file.url === fileName || file.name === fileName) {\n fileToDelete = file;\n }\n });\n }\n\n if (!fileToDelete || typeof onRemove !== 'function') {\n return;\n }\n\n onRemove(fileToDelete);\n },\n [files, internalFiles, internalImages, onRemove],\n );\n\n const isDisabled = useMemo(() => {\n if (maxFiles) {\n if (internalFiles.length + internalImages.length >= maxFiles) {\n if (typeof onMaxFilesReached === 'function') {\n onMaxFilesReached();\n }\n\n return true;\n }\n }\n\n return false;\n }, [internalFiles.length, internalImages.length, maxFiles, onMaxFilesReached]);\n\n const handleImageSelectionClick = useCallback(async () => {\n if (isDisabled) {\n return;\n }\n\n const { buttonType, result } = (await createDialog({\n dialogInput: {\n upload: true,\n buttons: [\n { text: 'hello', buttonType: 1 },\n { text: 'can', buttonType: -1 },\n ],\n initialView: 'pixabay',\n },\n type: DialogType.MODULE,\n system: {\n url: 'https://tapp.chayns-static.space/api/dialog-image-editor/v1/remoteEntry.js',\n scope: 'dialog_image_editor',\n module: './ImageEditorEntry',\n },\n buttons: [],\n }).open()) as ImageDialogResult;\n\n if (buttonType === 1 && result?.url) {\n handleAddImages([result.url]);\n }\n }, [handleAddImages, isDisabled]);\n\n const handleFileSelectionClick = useCallback(async () => {\n if (isDisabled) {\n return;\n }\n\n const newFiles = await selectFiles({\n multiple: true,\n type: fileTypes,\n });\n\n handleAddFiles(newFiles);\n }, [fileTypes, handleAddFiles, isDisabled]);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n const draggedFiles = Array.from(e.dataTransfer.files);\n\n handleAddFiles(draggedFiles);\n },\n [handleAddFiles],\n );\n\n const content = useMemo(() => {\n const combinedFiles = [...internalImages, ...internalFiles];\n\n const items: ReactElement[] = combinedFiles.map((file) => (\n <StyledMotionFileInputList\n animate={{ height: 'auto', opacity: 1 }}\n exit={{ height: 0, opacity: 0 }}\n key={typeof file === 'string' ? file : file.name}\n transition={{ duration: 0.25, type: 'tween' }}\n >\n <FileListItem\n fileType={typeof file !== 'string' ? file.type : undefined}\n fileName={typeof file !== 'string' ? file.name : undefined}\n fileSize={typeof file !== 'string' ? file.size : undefined}\n url={typeof file === 'string' ? file : undefined}\n onRemove={handleDeleteFile}\n />\n </StyledMotionFileInputList>\n ));\n\n return items;\n }, [handleDeleteFile, internalFiles, internalImages]);\n\n const uploadedFiles = useMemo(() => {\n const items: ReactElement[] = [];\n\n const cutFiles = maxFiles ? files?.splice(0, maxFiles) : files;\n\n cutFiles?.forEach(({ url, id, name }) => {\n items.push(\n <StyledMotionFileInputList\n animate={{ height: 'auto', opacity: 1 }}\n exit={{ height: 0, opacity: 0 }}\n key={id}\n transition={{ duration: 0.25, type: 'tween' }}\n >\n <FileListItem url={url} onRemove={handleDeleteFile} fileName={name} />\n </StyledMotionFileInputList>,\n );\n });\n\n return items;\n }, [files, handleDeleteFile, maxFiles]);\n\n return useMemo(\n () => (\n <StyledFileInput>\n <StyledFileInputWrapper $isDisabled={isDisabled}>\n <StyledFileInputContainer\n onClick={() => void handleFileSelectionClick()}\n onDragOver={(e: DragEvent<HTMLDivElement>) => e.preventDefault()}\n onDrop={(e: DragEvent<HTMLDivElement>) => void handleDrop(e)}\n >\n <Icon icons={fileSelectionIcons} />\n <StyledFileInputText>{fileSelectionPlaceholder}</StyledFileInputText>\n </StyledFileInputContainer>\n {imageSelectPlaceholder && (\n <StyledFileInputContainer\n $isImageSelection\n onClick={() => void handleImageSelectionClick()}\n >\n <Icon icons={imageSelectIcons} />\n <StyledFileInputText>{imageSelectPlaceholder}</StyledFileInputText>\n </StyledFileInputContainer>\n )}\n </StyledFileInputWrapper>\n <List>\n <AnimatePresence initial={false}>{content}</AnimatePresence>\n </List>\n {uploadedFiles.length > 0 && (\n <StyledUploadedFilesList $shouldShowBorder={content.length > 0}>\n <List>\n <AnimatePresence initial={false}>{uploadedFiles}</AnimatePresence>\n </List>\n </StyledUploadedFilesList>\n )}\n </StyledFileInput>\n ),\n [\n isDisabled,\n fileSelectionIcons,\n fileSelectionPlaceholder,\n imageSelectPlaceholder,\n imageSelectIcons,\n content,\n uploadedFiles,\n handleFileSelectionClick,\n handleDrop,\n handleImageSelectionClick,\n ],\n );\n};\n\nFileInput.displayName = 'FileInput';\n\nexport default FileInput;\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,UAAU,QAAQ,YAAY;AACrD,SAASC,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAAiCC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAE1F,SAASC,mBAAmB,EAAEC,uBAAuB,EAAEC,eAAe,QAAQ,kBAAkB;AAChG,SAASC,WAAW,QAAQ,wBAAwB;AACpD,OAAOC,IAAI,MAAM,cAAc;AAC/B,OAAOC,IAAI,MAAM,cAAc;AAC/B,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SACIC,eAAe,EACfC,wBAAwB,EACxBC,mBAAmB,EACnBC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AC;AACL,CAAC;AAEDzC,SAAS,CAAC6F,WAAW,GAAG,WAAW;AAEnC,eAAe7F,SAAS","ignoreList":[]}
|
|
@@ -9,6 +9,10 @@ export declare const StyledFileInputWrapper: import("styled-components").IStyled
|
|
|
9
9
|
type StyledFileInputContainerProps = WithTheme<{
|
|
10
10
|
$isImageSelection?: boolean;
|
|
11
11
|
}>;
|
|
12
|
+
type StyledUploadedFilesListProps = WithTheme<{
|
|
13
|
+
$shouldShowBorder: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const StyledUploadedFilesList: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledUploadedFilesListProps>>;
|
|
12
16
|
export declare const StyledFileInputContainer: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledFileInputContainerProps>>;
|
|
13
17
|
export declare const StyledFileInputText: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, {
|
|
14
18
|
theme: import("../color-scheme-provider/ColorSchemeProvider").Theme;
|
|
@@ -17,11 +17,22 @@ export const StyledFileInputWrapper = styled.div`
|
|
|
17
17
|
return $isDisabled ? 0.5 : 1;
|
|
18
18
|
}};
|
|
19
19
|
`;
|
|
20
|
-
export const
|
|
21
|
-
|
|
20
|
+
export const StyledUploadedFilesList = styled.div`
|
|
21
|
+
${_ref3 => {
|
|
22
22
|
let {
|
|
23
|
+
$shouldShowBorder,
|
|
23
24
|
theme
|
|
24
25
|
} = _ref3;
|
|
26
|
+
return $shouldShowBorder && css`
|
|
27
|
+
border-top: 1px solid ${theme.headline};
|
|
28
|
+
`;
|
|
29
|
+
}}
|
|
30
|
+
`;
|
|
31
|
+
export const StyledFileInputContainer = styled.div`
|
|
32
|
+
border: ${_ref4 => {
|
|
33
|
+
let {
|
|
34
|
+
theme
|
|
35
|
+
} = _ref4;
|
|
25
36
|
return theme.text;
|
|
26
37
|
}} 1px dotted;
|
|
27
38
|
display: flex;
|
|
@@ -31,20 +42,20 @@ export const StyledFileInputContainer = styled.div`
|
|
|
31
42
|
justify-content: center;
|
|
32
43
|
width: 100%;
|
|
33
44
|
|
|
34
|
-
${
|
|
45
|
+
${_ref5 => {
|
|
35
46
|
let {
|
|
36
47
|
$isImageSelection
|
|
37
|
-
} =
|
|
48
|
+
} = _ref5;
|
|
38
49
|
return $isImageSelection && css`
|
|
39
50
|
border-left: none;
|
|
40
51
|
`;
|
|
41
52
|
}}
|
|
42
53
|
`;
|
|
43
54
|
export const StyledFileInputText = styled.p`
|
|
44
|
-
color: ${
|
|
55
|
+
color: ${_ref6 => {
|
|
45
56
|
let {
|
|
46
57
|
theme
|
|
47
|
-
} =
|
|
58
|
+
} = _ref6;
|
|
48
59
|
return theme.text;
|
|
49
60
|
}};
|
|
50
61
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.styles.js","names":["motion","styled","css","StyledFileInput","div","StyledFileInputWrapper","_ref","$isDisabled","_ref2","
|
|
1
|
+
{"version":3,"file":"FileInput.styles.js","names":["motion","styled","css","StyledFileInput","div","StyledFileInputWrapper","_ref","$isDisabled","_ref2","StyledUploadedFilesList","_ref3","$shouldShowBorder","theme","headline","StyledFileInputContainer","_ref4","text","_ref5","$isImageSelection","StyledFileInputText","p","_ref6","StyledMotionFileInputList"],"sources":["../../../src/components/file-input/FileInput.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { FramerMotionBugFix, WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledFileInput = styled.div``;\n\ntype StyledFileInputWrapperProps = WithTheme<{\n $isDisabled: boolean;\n}>;\n\nexport const StyledFileInputWrapper = styled.div<StyledFileInputWrapperProps>`\n display: flex;\n\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'default' : 'pointer')};\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n`;\n\ntype StyledFileInputContainerProps = WithTheme<{\n $isImageSelection?: boolean;\n}>;\n\ntype StyledUploadedFilesListProps = WithTheme<{ $shouldShowBorder: boolean }>;\n\nexport const StyledUploadedFilesList = styled.div<StyledUploadedFilesListProps>`\n ${({ $shouldShowBorder, theme }: StyledUploadedFilesListProps) =>\n $shouldShowBorder &&\n css`\n border-top: 1px solid ${theme.headline};\n `}\n`;\n\nexport const StyledFileInputContainer = styled.div<StyledFileInputContainerProps>`\n border: ${({ theme }: StyledFileInputContainerProps) => theme.text} 1px dotted;\n display: flex;\n gap: 10px;\n align-items: center;\n padding: 15px;\n justify-content: center;\n width: 100%;\n\n ${({ $isImageSelection }) =>\n $isImageSelection &&\n css`\n border-left: none;\n `}\n`;\n\ntype StyledFileInputTextProps = WithTheme<unknown>;\n\nexport const StyledFileInputText = styled.p<StyledFileInputTextProps>`\n color: ${({ theme }: StyledFileInputTextProps) => theme.text};\n`;\n\nexport const StyledMotionFileInputList = styled(motion.div)<FramerMotionBugFix>``;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAG/C,OAAO,MAAMC,eAAe,GAAGF,MAAM,CAACG,GAAI,EAAC;AAM3C,OAAO,MAAMC,sBAAsB,GAAGJ,MAAM,CAACG,GAAiC;AAC9E;AACA;AACA,cAAcE,IAAA;EAAA,IAAC;IAAEC;EAAY,CAAC,GAAAD,IAAA;EAAA,OAAMC,WAAW,GAAG,SAAS,GAAG,SAAS;AAAA,CAAE;AACzE,eAAeC,KAAA;EAAA,IAAC;IAAED;EAAY,CAAC,GAAAC,KAAA;EAAA,OAAMD,WAAW,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AAC5D,CAAC;AAQD,OAAO,MAAME,uBAAuB,GAAGR,MAAM,CAACG,GAAkC;AAChF,MAAMM,KAAA;EAAA,IAAC;IAAEC,iBAAiB;IAAEC;EAAoC,CAAC,GAAAF,KAAA;EAAA,OACzDC,iBAAiB,IACjBT,GAAI;AACZ,oCAAoCU,KAAK,CAACC,QAAS;AACnD,SAAS;AAAA,CAAC;AACV,CAAC;AAED,OAAO,MAAMC,wBAAwB,GAAGb,MAAM,CAACG,GAAmC;AAClF,cAAcW,KAAA;EAAA,IAAC;IAAEH;EAAqC,CAAC,GAAAG,KAAA;EAAA,OAAKH,KAAK,CAACI,IAAI;AAAA,CAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEC;EAAkB,CAAC,GAAAD,KAAA;EAAA,OACpBC,iBAAiB,IACjBhB,GAAI;AACZ;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAID,OAAO,MAAMiB,mBAAmB,GAAGlB,MAAM,CAACmB,CAA4B;AACtE,aAAaC,KAAA;EAAA,IAAC;IAAET;EAAgC,CAAC,GAAAS,KAAA;EAAA,OAAKT,KAAK,CAACI,IAAI;AAAA,CAAC;AACjE,CAAC;AAED,OAAO,MAAMM,yBAAyB,GAAGrB,MAAM,CAACD,MAAM,CAACI,GAAG,CAAsB,EAAC","ignoreList":[]}
|
|
@@ -17,11 +17,12 @@ const FileListItem = _ref => {
|
|
|
17
17
|
title: fileName ?? url,
|
|
18
18
|
subtitle: humanFileSize,
|
|
19
19
|
icons: url ? ['fa fa-file-image'] : [icon],
|
|
20
|
+
shouldShowSingleRightElementCentered: true,
|
|
20
21
|
rightElements: [/*#__PURE__*/React.createElement(Icon, {
|
|
21
22
|
icons: ['ts-wrong'],
|
|
22
23
|
onClick: () => onRemove(fileName ?? url ?? '')
|
|
23
24
|
})]
|
|
24
|
-
})), [fileName, humanFileSize, icon, onRemove]);
|
|
25
|
+
})), [fileName, humanFileSize, icon, onRemove, url]);
|
|
25
26
|
};
|
|
26
27
|
FileListItem.displayName = 'FileList';
|
|
27
28
|
export default FileListItem;
|