@chayns-components/core 5.0.0-beta.573 → 5.0.0-beta.575
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/api/image/post.d.ts +2 -1
- package/lib/api/image/post.js +13 -3
- package/lib/api/image/post.js.map +1 -1
- package/lib/components/accordion/Accordion.js +2 -1
- package/lib/components/accordion/Accordion.js.map +1 -1
- package/lib/components/amount-control/AmountControl.js +2 -0
- package/lib/components/amount-control/AmountControl.js.map +1 -1
- package/lib/components/amount-control/AmountControl.styles.d.ts +1 -0
- package/lib/components/amount-control/AmountControl.styles.js +14 -8
- package/lib/components/amount-control/AmountControl.styles.js.map +1 -1
- package/lib/components/area-provider/AreaProvider.d.ts +14 -0
- package/lib/components/area-provider/AreaProvider.js +20 -0
- package/lib/components/area-provider/AreaProvider.js.map +1 -0
- package/lib/components/button/Button.js +2 -2
- package/lib/components/button/Button.js.map +1 -1
- 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 +54 -11
- 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/filter-buttons/filter-button/FilterButton.d.ts +1 -1
- package/lib/components/filter-buttons/filter-button/FilterButton.js +1 -2
- package/lib/components/filter-buttons/filter-button/FilterButton.js.map +1 -1
- package/lib/components/filter-buttons/filter-button/FilterButton.styles.js +10 -6
- package/lib/components/filter-buttons/filter-button/FilterButton.styles.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/popup/Popup.js +4 -1
- package/lib/components/popup/Popup.js.map +1 -1
- package/lib/components/small-wait-cursor/SmallWaitCursor.d.ts +1 -1
- package/lib/components/small-wait-cursor/SmallWaitCursor.js.map +1 -1
- package/lib/components/small-wait-cursor/SmallWaitCursor.styles.d.ts +2 -2
- package/lib/components/small-wait-cursor/SmallWaitCursor.styles.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/uploadFile.d.ts +2 -1
- package/lib/utils/uploadFile.js +4 -2
- package/lib/utils/uploadFile.js.map +1 -1
- package/package.json +2 -2
package/lib/api/image/post.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export interface PostImageResult {
|
|
|
6
6
|
}
|
|
7
7
|
interface PostImageOptions {
|
|
8
8
|
file: File;
|
|
9
|
+
shouldUploadImageToSite?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Uploads an image to the tsimg cloud service
|
|
12
13
|
*/
|
|
13
|
-
export declare const postImage: ({ file, }: PostImageOptions) => Promise<PostImageResult | undefined>;
|
|
14
|
+
export declare const postImage: ({ file, shouldUploadImageToSite, }: PostImageOptions) => Promise<PostImageResult | undefined>;
|
|
14
15
|
export {};
|
package/lib/api/image/post.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import { getAccessToken, getUser } from 'chayns-api';
|
|
1
|
+
import { getAccessToken, getSite, getUser } from 'chayns-api';
|
|
2
2
|
import { getFileAsArrayBuffer } from '../../utils/fileDialog';
|
|
3
3
|
/**
|
|
4
4
|
* Uploads an image to the tsimg cloud service
|
|
5
5
|
*/
|
|
6
6
|
export const postImage = async _ref => {
|
|
7
7
|
let {
|
|
8
|
-
file
|
|
8
|
+
file,
|
|
9
|
+
shouldUploadImageToSite
|
|
9
10
|
} = _ref;
|
|
10
11
|
const {
|
|
11
12
|
accessToken
|
|
12
13
|
} = await getAccessToken();
|
|
13
14
|
const user = getUser();
|
|
15
|
+
const site = getSite();
|
|
14
16
|
if (!accessToken || !user?.personId) {
|
|
15
17
|
return undefined;
|
|
16
18
|
}
|
|
19
|
+
let head = {
|
|
20
|
+
'X-Person-Id': user.personId
|
|
21
|
+
};
|
|
22
|
+
if (shouldUploadImageToSite && site.id) {
|
|
23
|
+
head = {
|
|
24
|
+
'X-Site-Id': site.id
|
|
25
|
+
};
|
|
26
|
+
}
|
|
17
27
|
const body = await getFileAsArrayBuffer(file);
|
|
18
28
|
const response = await fetch('https://api.tsimg.cloud/image', {
|
|
19
29
|
body,
|
|
@@ -21,7 +31,7 @@ export const postImage = async _ref => {
|
|
|
21
31
|
Accept: 'application/json',
|
|
22
32
|
Authorization: `bearer ${accessToken}`,
|
|
23
33
|
'Content-Type': 'image/*',
|
|
24
|
-
|
|
34
|
+
...head
|
|
25
35
|
},
|
|
26
36
|
method: 'POST'
|
|
27
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post.js","names":["getAccessToken","getUser","getFileAsArrayBuffer","postImage","_ref","file","accessToken","user","personId","undefined","body","response","fetch","headers","Accept","Authorization","method","ok","json","Error","status"],"sources":["../../../src/api/image/post.ts"],"sourcesContent":["import { getAccessToken, getUser } from 'chayns-api';\nimport type { Meta } from '../../types/file';\nimport { getFileAsArrayBuffer } from '../../utils/fileDialog';\n\nexport interface PostImageResult {\n key: string;\n base: string;\n meta?: Meta;\n}\n\ninterface PostImageOptions {\n file: File;\n}\n\n/**\n * Uploads an image to the tsimg cloud service\n */\nexport const postImage = async ({\n file,\n}: PostImageOptions): Promise<PostImageResult | undefined> => {\n const { accessToken } = await getAccessToken();\n const user = getUser();\n\n if (!accessToken || !user?.personId) {\n return undefined;\n }\n\n const body = await getFileAsArrayBuffer(file);\n\n const response = await fetch('https://api.tsimg.cloud/image', {\n body,\n headers: {\n Accept: 'application/json',\n Authorization: `bearer ${accessToken}`,\n 'Content-Type': 'image/*',\n
|
|
1
|
+
{"version":3,"file":"post.js","names":["getAccessToken","getSite","getUser","getFileAsArrayBuffer","postImage","_ref","file","shouldUploadImageToSite","accessToken","user","site","personId","undefined","head","id","body","response","fetch","headers","Accept","Authorization","method","ok","json","Error","status"],"sources":["../../../src/api/image/post.ts"],"sourcesContent":["import { getAccessToken, getSite, getUser } from 'chayns-api';\nimport type { Meta } from '../../types/file';\nimport { getFileAsArrayBuffer } from '../../utils/fileDialog';\n\nexport interface PostImageResult {\n key: string;\n base: string;\n meta?: Meta;\n}\n\ninterface PostImageOptions {\n file: File;\n shouldUploadImageToSite?: boolean;\n}\n\n/**\n * Uploads an image to the tsimg cloud service\n */\nexport const postImage = async ({\n file,\n shouldUploadImageToSite,\n}: PostImageOptions): Promise<PostImageResult | undefined> => {\n const { accessToken } = await getAccessToken();\n const user = getUser();\n const site = getSite();\n\n if (!accessToken || !user?.personId) {\n return undefined;\n }\n\n let head: { [key: string]: string } = { 'X-Person-Id': user.personId };\n\n if (shouldUploadImageToSite && site.id) {\n head = { 'X-Site-Id': site.id };\n }\n\n const body = await getFileAsArrayBuffer(file);\n\n const response = await fetch('https://api.tsimg.cloud/image', {\n body,\n headers: {\n Accept: 'application/json',\n Authorization: `bearer ${accessToken}`,\n 'Content-Type': 'image/*',\n ...head,\n },\n method: 'POST',\n });\n\n if (response.ok) {\n return (await response.json()) as PostImageResult;\n }\n\n throw Error(`Failed to POST image (status code: ${response.status}).`);\n};\n"],"mappings":"AAAA,SAASA,cAAc,EAAEC,OAAO,EAAEC,OAAO,QAAQ,YAAY;AAE7D,SAASC,oBAAoB,QAAQ,wBAAwB;AAa7D;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAG,MAAAC,IAAA,IAGqC;EAAA,IAH9B;IAC5BC,IAAI;IACJC;EACc,CAAC,GAAAF,IAAA;EACf,MAAM;IAAEG;EAAY,CAAC,GAAG,MAAMR,cAAc,CAAC,CAAC;EAC9C,MAAMS,IAAI,GAAGP,OAAO,CAAC,CAAC;EACtB,MAAMQ,IAAI,GAAGT,OAAO,CAAC,CAAC;EAEtB,IAAI,CAACO,WAAW,IAAI,CAACC,IAAI,EAAEE,QAAQ,EAAE;IACjC,OAAOC,SAAS;EACpB;EAEA,IAAIC,IAA+B,GAAG;IAAE,aAAa,EAAEJ,IAAI,CAACE;EAAS,CAAC;EAEtE,IAAIJ,uBAAuB,IAAIG,IAAI,CAACI,EAAE,EAAE;IACpCD,IAAI,GAAG;MAAE,WAAW,EAAEH,IAAI,CAACI;IAAG,CAAC;EACnC;EAEA,MAAMC,IAAI,GAAG,MAAMZ,oBAAoB,CAACG,IAAI,CAAC;EAE7C,MAAMU,QAAQ,GAAG,MAAMC,KAAK,CAAC,+BAA+B,EAAE;IAC1DF,IAAI;IACJG,OAAO,EAAE;MACLC,MAAM,EAAE,kBAAkB;MAC1BC,aAAa,EAAG,UAASZ,WAAY,EAAC;MACtC,cAAc,EAAE,SAAS;MACzB,GAAGK;IACP,CAAC;IACDQ,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,IAAIL,QAAQ,CAACM,EAAE,EAAE;IACb,OAAQ,MAAMN,QAAQ,CAACO,IAAI,CAAC,CAAC;EACjC;EAEA,MAAMC,KAAK,CAAE,sCAAqCR,QAAQ,CAACS,MAAO,IAAG,CAAC;AAC1E,CAAC","ignoreList":[]}
|
|
@@ -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 AreaProvider from '../area-provider/AreaProvider';
|
|
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,7 @@ const Accordion = _ref => {
|
|
|
139
140
|
maxHeight: bodyMaxHeight,
|
|
140
141
|
onScroll: onBodyScroll,
|
|
141
142
|
shouldHideBody: shouldRenderClosed && !isOpen
|
|
142
|
-
}, children)))));
|
|
143
|
+
}, /*#__PURE__*/React.createElement(AreaProvider, null, children))))));
|
|
143
144
|
};
|
|
144
145
|
Accordion.displayName = 'Accordion';
|
|
145
146
|
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;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;IAAEF,SAAS;IAAEyB,iBAAiB;IAAEC;EAAwB,CAAC,GAC3DtC,UAAU,CAACO,qBAAqB,CAAC;EACrC,MAAM;IAAEK,SAAS,EAAE2B;EAAgB,CAAC,GAAGvC,UAAU,CAACU,gBAAgB,CAAC;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AEDH,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","AreaProvider","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 AreaProvider from '../area-provider/AreaProvider';\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 <AreaProvider>{children}</AreaProvider>\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,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AC5C,gBAAgB,CAACmD,QAAQ;IAACC,KAAK,EAAET;EAA8B,gBAC5DxD,KAAA,CAAAyD,aAAA,CAAC1D,YAAY;IAACmE,UAAU,EAAE;MAAEC,IAAI,EAAE;IAAQ;EAAE,gBACxCnE,KAAA,CAAAyD,aAAA,CAAC9C,aAAa;IACVS,IAAI,EAAEA,IAAK;IACX4B,MAAM,EAAEA,MAAO;IACfzB,OAAO,EAAEA,OAAQ;IACjBE,aAAa,EAAEA,aAAa,IAAIH,UAAW;IAC3CP,SAAS,EAAEA,SAAS,KAAK,IAAK;IAC9BqD,OAAO,EAAEf,eAAgB;IACzBxB,cAAc,EAAEA,cAAe;IAC/BC,YAAY,EAAEA,YAAa;IAC3BC,UAAU,EAAEA,UAAW;IACvBC,iBAAiB,EAAEA,iBAAkB;IACrCC,WAAW,EAAEA,WAAY;IACzBI,gBAAgB,EAAEA,gBAAiB;IACnCC,KAAK,EAAEA,KAAM;IACbC,YAAY,EAAEA;EAAa,CAC9B,CAAC,eACFvC,KAAA,CAAAyD,aAAA,CAAC3D,eAAe;IAACuE,OAAO,EAAE;EAAM,GAC3B,CAACrB,MAAM,IAAIZ,kBAAkB,kBAC1BpC,KAAA,CAAAyD,aAAA,CAAChD,aAAa;IACV6D,SAAS,EAAEpD,aAAc;IACzBqD,QAAQ,EAAE7C,YAAa;IACvB8C,cAAc,EAAEpC,kBAAkB,IAAI,CAACY;EAAO,gBAE9ChD,KAAA,CAAAyD,aAAA,CAACjD,YAAY,QAAEW,QAAuB,CAC3B,CAEN,CACP,CACS,CACd,CAAC;AAE1B,CAAC;AAEDH,SAAS,CAACyD,WAAW,GAAG,WAAW;AAEnC,eAAezD,SAAS","ignoreList":[]}
|
|
@@ -35,6 +35,7 @@ const AmountControl = _ref => {
|
|
|
35
35
|
setDisplayState('default');
|
|
36
36
|
}
|
|
37
37
|
}, [amountValue, maxAmount]);
|
|
38
|
+
const hasFocus = useMemo(() => displayState !== 'default', [displayState]);
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Function that sets the amountValue to the amount
|
|
@@ -168,6 +169,7 @@ const AmountControl = _ref => {
|
|
|
168
169
|
}, leftIcon)), /*#__PURE__*/React.createElement(StyledAmountControlInput, {
|
|
169
170
|
$displayState: displayState,
|
|
170
171
|
$shouldShowIcon: shouldShowIcon,
|
|
172
|
+
$hasFocus: hasFocus,
|
|
171
173
|
onBlur: handleInputBlur,
|
|
172
174
|
onChange: handleInputChange,
|
|
173
175
|
value: displayState === 'default' && label ? label : inputValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmountControl.js","names":["AnimatePresence","React","useCallback","useEffect","useMemo","useState","checkForValidAmount","Icon","StyledAmountControl","StyledAmountControlInput","StyledMotionAmountControlButton","AmountControl","_ref","amount","icon","shouldShowIcon","label","maxAmount","onChange","amountValue","setAmountValue","inputValue","setInputValue","displayState","setDisplayState","minAmount","toString","handleAmountAdd","prevState","Number","handleAmountRemove","handleFirstAmount","handleInputBlur","handleInputChange","event","valueBeforeCheck","target","value","checkedValue","leftIcon","item","createElement","icons","size","color","shouldShowLeftIcon","onClick","initial","key","width","opacity","padding","animate","exit","transition","duration","type","disabled","$isDisabled","$displayState","$shouldShowIcon","onBlur","displayName"],"sources":["../../../src/components/amount-control/AmountControl.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { checkForValidAmount } from '../../utils/amountControl';\nimport Icon from '../icon/Icon';\nimport {\n StyledAmountControl,\n StyledAmountControlInput,\n StyledMotionAmountControlButton,\n} from './AmountControl.styles';\n\nexport type DisplayState = 'default' | 'delete' | 'normal' | 'maxAmount';\n\nexport type AmountControlProps = {\n /**\n * The amount that should be displayed.\n */\n amount?: number;\n /**\n * The icon that should be displayed if no amount is selected.\n */\n icon?: string;\n /**\n * A Text that should be displayed, if no amount is selected;\n */\n label?: string;\n /**\n * The maximum allowed amount. If the maxAmount is set to one, a delete button is displayed on the left side.\n */\n maxAmount?: number;\n /**\n * A Function that is executed when the amount is changed\n */\n onChange?: (amount: number) => void;\n /**\n * Whether the icon should be displayed if no amount is selected\n */\n shouldShowIcon?: boolean;\n};\n\nconst AmountControl: FC<AmountControlProps> = ({\n amount,\n icon,\n shouldShowIcon = true,\n label,\n maxAmount,\n onChange,\n}) => {\n const [amountValue, setAmountValue] = useState(0);\n const [inputValue, setInputValue] = useState('0');\n const [displayState, setDisplayState] = useState<DisplayState>('default');\n\n const minAmount = 0;\n\n /**\n * This function controls the displayState\n */\n useEffect(() => {\n switch (true) {\n case maxAmount === 1 && amountValue === 1:\n setDisplayState('delete');\n return;\n case maxAmount && amountValue >= maxAmount:\n setDisplayState('maxAmount');\n return;\n case amountValue > 0:\n setDisplayState('normal');\n return;\n default:\n setDisplayState('default');\n }\n }, [amountValue, maxAmount]);\n\n /**\n * Function that sets the amountValue to the amount\n */\n useEffect(() => {\n if (!amount) {\n return;\n }\n\n setAmountValue(checkForValidAmount({ amount, maxAmount, minAmount }));\n setInputValue(checkForValidAmount({ amount, maxAmount, minAmount }).toString());\n }, [amount, maxAmount, minAmount]);\n\n /**\n * Function that updates the onChange event\n */\n useEffect(() => {\n if (onChange) {\n onChange(amountValue);\n }\n }, [amountValue, onChange]);\n\n const handleAmountAdd = () => {\n setAmountValue((prevState) => prevState + 1);\n setInputValue((prevState) => (Number(prevState) + 1).toString());\n };\n\n const handleAmountRemove = () => {\n setAmountValue((prevState) => prevState - 1);\n setInputValue((prevState) => (Number(prevState) - 1).toString());\n };\n\n const handleFirstAmount = useCallback(() => {\n if (amountValue !== 0) {\n return;\n }\n\n setAmountValue(1);\n setInputValue('1');\n }, [amountValue]);\n\n const handleInputBlur = useCallback(() => {\n setAmountValue(inputValue === '' ? 0 : Number(inputValue));\n\n if (inputValue === '') {\n setInputValue('0');\n }\n }, [inputValue]);\n\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const valueBeforeCheck = Number(event.target.value);\n\n const checkedValue = checkForValidAmount({\n minAmount,\n maxAmount,\n amount: Number(event.target.value),\n });\n\n if (valueBeforeCheck < minAmount && minAmount === 0) {\n setInputValue('0');\n\n return;\n }\n\n setInputValue(checkedValue === 0 ? '' : checkedValue.toString());\n },\n [maxAmount, minAmount],\n );\n\n const leftIcon = useMemo(() => {\n let item: ReactElement | null = null;\n\n switch (displayState) {\n case 'default':\n item = <Icon icons={[icon ?? 'fa fa-cart-shopping']} size={15} />;\n break;\n case 'delete':\n item = <Icon icons={['fa ts-trash']} size={25} />;\n break;\n case 'normal':\n item = <Icon icons={['fa fa-minus']} size={15} color=\"red\" />;\n break;\n case 'maxAmount':\n item = <Icon icons={['fa fa-minus']} size={15} color=\"red\" />;\n break;\n default:\n break;\n }\n\n return item;\n }, [displayState, icon]);\n\n const shouldShowLeftIcon = useMemo(() => {\n if (shouldShowIcon) {\n return true;\n }\n\n return !(displayState === 'default' && !shouldShowIcon);\n }, [displayState, shouldShowIcon]);\n\n return useMemo(\n () => (\n <StyledAmountControl onClick={handleFirstAmount}>\n <AnimatePresence initial={false}>\n {shouldShowLeftIcon && (\n <StyledMotionAmountControlButton\n key=\"right_button\"\n initial={{ width: 0, opacity: 0, padding: 0 }}\n animate={{ width: 40, opacity: 1, padding: 0 }}\n exit={{ width: 0, opacity: 0, padding: 0 }}\n transition={{ duration: 0.2, type: 'tween' }}\n onClick={handleAmountRemove}\n disabled={amountValue !== 0 && amountValue <= minAmount}\n $isDisabled={amountValue !== 0 && amountValue <= minAmount}\n >\n {leftIcon}\n </StyledMotionAmountControlButton>\n )}\n </AnimatePresence>\n <StyledAmountControlInput\n $displayState={displayState}\n $shouldShowIcon={shouldShowIcon}\n onBlur={handleInputBlur}\n onChange={handleInputChange}\n value={displayState === 'default' && label ? label : inputValue}\n type={amountValue === 0 ? 'text' : 'number'}\n />\n <AnimatePresence initial={false}>\n {displayState === 'normal' && (\n <StyledMotionAmountControlButton\n key=\"right_button\"\n initial={{ width: 0, opacity: 0, padding: 0 }}\n animate={{ width: 40, opacity: 1, padding: 0 }}\n exit={{ width: 0, opacity: 0, padding: 0 }}\n transition={{ duration: 0.2, type: 'tween' }}\n onClick={handleAmountAdd}\n disabled={maxAmount ? amountValue >= maxAmount : false}\n $isDisabled={maxAmount ? amountValue >= maxAmount : false}\n >\n <Icon icons={['fa fa-plus']} size={15} color=\"green\" />\n </StyledMotionAmountControlButton>\n )}\n </AnimatePresence>\n </StyledAmountControl>\n ),\n [\n amountValue,\n displayState,\n handleFirstAmount,\n handleInputBlur,\n handleInputChange,\n inputValue,\n label,\n leftIcon,\n maxAmount,\n shouldShowIcon,\n shouldShowLeftIcon,\n ],\n );\n};\n\nAmountControl.displayName = 'AmountControl';\n\nexport default AmountControl;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAIRC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACL,OAAO;AACd,SAASC,mBAAmB,QAAQ,2BAA2B;AAC/D,OAAOC,IAAI,MAAM,cAAc;AAC/B,SACIC,mBAAmB,EACnBC,wBAAwB,EACxBC,+BAA+B,QAC5B,wBAAwB;AA+B/B,MAAMC,aAAqC,GAAGC,IAAA,IAOxC;EAAA,IAPyC;IAC3CC,MAAM;IACNC,IAAI;IACJC,cAAc,GAAG,IAAI;IACrBC,KAAK;IACLC,SAAS;IACTC;EACJ,CAAC,GAAAN,IAAA;EACG,MAAM,CAACO,WAAW,EAAEC,cAAc,CAAC,GAAGf,QAAQ,CAAC,CAAC,CAAC;EACjD,MAAM,CAACgB,UAAU,EAAEC,aAAa,CAAC,GAAGjB,QAAQ,CAAC,GAAG,CAAC;EACjD,MAAM,CAACkB,YAAY,EAAEC,eAAe,CAAC,GAAGnB,QAAQ,CAAe,SAAS,CAAC;EAEzE,MAAMoB,SAAS,GAAG,CAAC;;EAEnB;AACJ;AACA;EACItB,SAAS,CAAC,MAAM;IACZ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MAAEC,OAAO,EAAE;IAAE,CAAE;IAC/CE,IAAI,EAAE;MAAEJ,KAAK,EAAE,CAAC;MAAEC,OAAO,EAAE,CAAC;MAAEC,OAAO,EAAE;IAAE,CAAE;IAC3CG,UAAU,EAAE;MAAEC,QAAQ,EAAE,GAAG;MAAEC,IAAI,EAAE;IAAQ,CAAE;IAC7CV,OAAO,EAAEnB,eAAgB;IACzB8B,QAAQ,EAAExC,SAAS,GAAGE,WAAW,IAAIF,SAAS,GAAG,KAAM;IACvDyC,WAAW,EAAEzC,SAAS,GAAGE,WAAW,IAAIF,SAAS,GAAG;EAAM,gBAE1DhB,KAAA,CAAAwC,aAAA,CAAClC,IAAI;IAACmC,KAAK,EAAE,CAAC,YAAY,CAAE;IAACC,IAAI,EAAE,EAAG;IAACC,KAAK,EAAC;EAAO,CAAE,CACzB,CAExB,CACA,CACxB,EACD,CACIzB,WAAW,EACXI,YAAY,EACZQ,iBAAiB,EACjBC,eAAe,EACfC,iBAAiB,EACjBZ,UAAU,EACVL,KAAK,EACLuB,QAAQ,EACRtB,SAAS,EACTF,cAAc,EACd8B,kBAAkB,CAE1B,CAAC;AACL,CAAC;AAEDlC,aAAa,CAACmD,WAAW,GAAG,eAAe;AAE3C,eAAenD,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"AmountControl.js","names":["AnimatePresence","React","useCallback","useEffect","useMemo","useState","checkForValidAmount","Icon","StyledAmountControl","StyledAmountControlInput","StyledMotionAmountControlButton","AmountControl","_ref","amount","icon","shouldShowIcon","label","maxAmount","onChange","amountValue","setAmountValue","inputValue","setInputValue","displayState","setDisplayState","minAmount","hasFocus","toString","handleAmountAdd","prevState","Number","handleAmountRemove","handleFirstAmount","handleInputBlur","handleInputChange","event","valueBeforeCheck","target","value","checkedValue","leftIcon","item","createElement","icons","size","color","shouldShowLeftIcon","onClick","initial","key","width","opacity","padding","animate","exit","transition","duration","type","disabled","$isDisabled","$displayState","$shouldShowIcon","$hasFocus","onBlur","displayName"],"sources":["../../../src/components/amount-control/AmountControl.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { checkForValidAmount } from '../../utils/amountControl';\nimport Icon from '../icon/Icon';\nimport {\n StyledAmountControl,\n StyledAmountControlInput,\n StyledMotionAmountControlButton,\n} from './AmountControl.styles';\n\nexport type DisplayState = 'default' | 'delete' | 'normal' | 'maxAmount';\n\nexport type AmountControlProps = {\n /**\n * The amount that should be displayed.\n */\n amount?: number;\n /**\n * The icon that should be displayed if no amount is selected.\n */\n icon?: string;\n /**\n * A Text that should be displayed, if no amount is selected;\n */\n label?: string;\n /**\n * The maximum allowed amount. If the maxAmount is set to one, a delete button is displayed on the left side.\n */\n maxAmount?: number;\n /**\n * A Function that is executed when the amount is changed\n */\n onChange?: (amount: number) => void;\n /**\n * Whether the icon should be displayed if no amount is selected\n */\n shouldShowIcon?: boolean;\n};\n\nconst AmountControl: FC<AmountControlProps> = ({\n amount,\n icon,\n shouldShowIcon = true,\n label,\n maxAmount,\n onChange,\n}) => {\n const [amountValue, setAmountValue] = useState(0);\n const [inputValue, setInputValue] = useState('0');\n const [displayState, setDisplayState] = useState<DisplayState>('default');\n\n const minAmount = 0;\n\n /**\n * This function controls the displayState\n */\n useEffect(() => {\n switch (true) {\n case maxAmount === 1 && amountValue === 1:\n setDisplayState('delete');\n return;\n case maxAmount && amountValue >= maxAmount:\n setDisplayState('maxAmount');\n return;\n case amountValue > 0:\n setDisplayState('normal');\n return;\n default:\n setDisplayState('default');\n }\n }, [amountValue, maxAmount]);\n\n const hasFocus = useMemo(() => displayState !== 'default', [displayState]);\n\n /**\n * Function that sets the amountValue to the amount\n */\n useEffect(() => {\n if (!amount) {\n return;\n }\n\n setAmountValue(checkForValidAmount({ amount, maxAmount, minAmount }));\n setInputValue(checkForValidAmount({ amount, maxAmount, minAmount }).toString());\n }, [amount, maxAmount, minAmount]);\n\n /**\n * Function that updates the onChange event\n */\n useEffect(() => {\n if (onChange) {\n onChange(amountValue);\n }\n }, [amountValue, onChange]);\n\n const handleAmountAdd = () => {\n setAmountValue((prevState) => prevState + 1);\n setInputValue((prevState) => (Number(prevState) + 1).toString());\n };\n\n const handleAmountRemove = () => {\n setAmountValue((prevState) => prevState - 1);\n setInputValue((prevState) => (Number(prevState) - 1).toString());\n };\n\n const handleFirstAmount = useCallback(() => {\n if (amountValue !== 0) {\n return;\n }\n\n setAmountValue(1);\n setInputValue('1');\n }, [amountValue]);\n\n const handleInputBlur = useCallback(() => {\n setAmountValue(inputValue === '' ? 0 : Number(inputValue));\n\n if (inputValue === '') {\n setInputValue('0');\n }\n }, [inputValue]);\n\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const valueBeforeCheck = Number(event.target.value);\n\n const checkedValue = checkForValidAmount({\n minAmount,\n maxAmount,\n amount: Number(event.target.value),\n });\n\n if (valueBeforeCheck < minAmount && minAmount === 0) {\n setInputValue('0');\n\n return;\n }\n\n setInputValue(checkedValue === 0 ? '' : checkedValue.toString());\n },\n [maxAmount, minAmount],\n );\n\n const leftIcon = useMemo(() => {\n let item: ReactElement | null = null;\n\n switch (displayState) {\n case 'default':\n item = <Icon icons={[icon ?? 'fa fa-cart-shopping']} size={15} />;\n break;\n case 'delete':\n item = <Icon icons={['fa ts-trash']} size={25} />;\n break;\n case 'normal':\n item = <Icon icons={['fa fa-minus']} size={15} color=\"red\" />;\n break;\n case 'maxAmount':\n item = <Icon icons={['fa fa-minus']} size={15} color=\"red\" />;\n break;\n default:\n break;\n }\n\n return item;\n }, [displayState, icon]);\n\n const shouldShowLeftIcon = useMemo(() => {\n if (shouldShowIcon) {\n return true;\n }\n\n return !(displayState === 'default' && !shouldShowIcon);\n }, [displayState, shouldShowIcon]);\n\n return useMemo(\n () => (\n <StyledAmountControl onClick={handleFirstAmount}>\n <AnimatePresence initial={false}>\n {shouldShowLeftIcon && (\n <StyledMotionAmountControlButton\n key=\"right_button\"\n initial={{ width: 0, opacity: 0, padding: 0 }}\n animate={{ width: 40, opacity: 1, padding: 0 }}\n exit={{ width: 0, opacity: 0, padding: 0 }}\n transition={{ duration: 0.2, type: 'tween' }}\n onClick={handleAmountRemove}\n disabled={amountValue !== 0 && amountValue <= minAmount}\n $isDisabled={amountValue !== 0 && amountValue <= minAmount}\n >\n {leftIcon}\n </StyledMotionAmountControlButton>\n )}\n </AnimatePresence>\n <StyledAmountControlInput\n $displayState={displayState}\n $shouldShowIcon={shouldShowIcon}\n $hasFocus={hasFocus}\n onBlur={handleInputBlur}\n onChange={handleInputChange}\n value={displayState === 'default' && label ? label : inputValue}\n type={amountValue === 0 ? 'text' : 'number'}\n />\n <AnimatePresence initial={false}>\n {displayState === 'normal' && (\n <StyledMotionAmountControlButton\n key=\"right_button\"\n initial={{ width: 0, opacity: 0, padding: 0 }}\n animate={{ width: 40, opacity: 1, padding: 0 }}\n exit={{ width: 0, opacity: 0, padding: 0 }}\n transition={{ duration: 0.2, type: 'tween' }}\n onClick={handleAmountAdd}\n disabled={maxAmount ? amountValue >= maxAmount : false}\n $isDisabled={maxAmount ? amountValue >= maxAmount : false}\n >\n <Icon icons={['fa fa-plus']} size={15} color=\"green\" />\n </StyledMotionAmountControlButton>\n )}\n </AnimatePresence>\n </StyledAmountControl>\n ),\n [\n amountValue,\n displayState,\n handleFirstAmount,\n handleInputBlur,\n handleInputChange,\n inputValue,\n label,\n leftIcon,\n maxAmount,\n shouldShowIcon,\n shouldShowLeftIcon,\n ],\n );\n};\n\nAmountControl.displayName = 'AmountControl';\n\nexport default AmountControl;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAIRC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACL,OAAO;AACd,SAASC,mBAAmB,QAAQ,2BAA2B;AAC/D,OAAOC,IAAI,MAAM,cAAc;AAC/B,SACIC,mBAAmB,EACnBC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,EACfC,iBAAiB,EACjBb,UAAU,EACVL,KAAK,EACLwB,QAAQ,EACRvB,SAAS,EACTF,cAAc,EACd+B,kBAAkB,CAE1B,CAAC;AACL,CAAC;AAEDnC,aAAa,CAACqD,WAAW,GAAG,eAAe;AAE3C,eAAerD,aAAa","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ export declare const StyledAmountControl: import("styled-components").IStyledCom
|
|
|
8
8
|
type StyledAmountControlInputProps = WithTheme<{
|
|
9
9
|
$displayState: DisplayState;
|
|
10
10
|
$shouldShowIcon: boolean;
|
|
11
|
+
$hasFocus: boolean;
|
|
11
12
|
}>;
|
|
12
13
|
export declare const StyledAmountControlInput: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, StyledAmountControlInputProps>>;
|
|
13
14
|
type StyledAmountControlButtonProps = WithTheme<{
|
|
@@ -22,26 +22,32 @@ export const StyledAmountControlInput = styled.input`
|
|
|
22
22
|
height: 28px;
|
|
23
23
|
width: 95px;
|
|
24
24
|
text-align: center;
|
|
25
|
-
${_ref3 => {
|
|
25
|
+
cursor: ${_ref3 => {
|
|
26
26
|
let {
|
|
27
|
-
$
|
|
27
|
+
$hasFocus
|
|
28
28
|
} = _ref3;
|
|
29
|
+
return $hasFocus ? 'text' : 'pointer';
|
|
30
|
+
}};
|
|
31
|
+
|
|
32
|
+
${_ref4 => {
|
|
33
|
+
let {
|
|
34
|
+
$displayState
|
|
35
|
+
} = _ref4;
|
|
29
36
|
return $displayState !== 'normal' && css`
|
|
30
37
|
border-bottom-right-radius: 3px;
|
|
31
38
|
border-top-right-radius: 3px;
|
|
32
39
|
`;
|
|
33
40
|
}}
|
|
34
|
-
|
|
35
|
-
${_ref4 => {
|
|
41
|
+
${_ref5 => {
|
|
36
42
|
let {
|
|
37
43
|
$displayState,
|
|
38
44
|
$shouldShowIcon
|
|
39
|
-
} =
|
|
45
|
+
} = _ref5;
|
|
40
46
|
return $displayState === 'default' && !$shouldShowIcon && css`
|
|
41
47
|
border-bottom-left-radius: 3px;
|
|
42
48
|
border-top-left-radius: 3px;
|
|
43
49
|
`;
|
|
44
|
-
}}
|
|
50
|
+
}};
|
|
45
51
|
`;
|
|
46
52
|
export const StyledMotionAmountControlButton = styled(motion.button)`
|
|
47
53
|
overflow: hidden;
|
|
@@ -49,10 +55,10 @@ export const StyledMotionAmountControlButton = styled(motion.button)`
|
|
|
49
55
|
height: 28px;
|
|
50
56
|
width: 40px;
|
|
51
57
|
|
|
52
|
-
${
|
|
58
|
+
${_ref6 => {
|
|
53
59
|
let {
|
|
54
60
|
$isDisabled
|
|
55
|
-
} =
|
|
61
|
+
} = _ref6;
|
|
56
62
|
return $isDisabled && css`
|
|
57
63
|
opacity: 0.5;
|
|
58
64
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmountControl.styles.js","names":["motion","styled","css","StyledAmountControl","div","_ref","theme","StyledAmountControlInput","input","_ref2","_ref3","$
|
|
1
|
+
{"version":3,"file":"AmountControl.styles.js","names":["motion","styled","css","StyledAmountControl","div","_ref","theme","StyledAmountControlInput","input","_ref2","_ref3","$hasFocus","_ref4","$displayState","_ref5","$shouldShowIcon","StyledMotionAmountControlButton","button","_ref6","$isDisabled"],"sources":["../../../src/components/amount-control/AmountControl.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport type { DisplayState } from './AmountControl';\n\ntype StyledAmountControlProps = WithTheme<unknown>;\n\nexport const StyledAmountControl = styled.div<StyledAmountControlProps>`\n background-color: ${({ theme }: StyledAmountControlProps) => theme['202']};\n display: flex;\n width: fit-content;\n border-radius: 3px;\n`;\n\ntype StyledAmountControlInputProps = WithTheme<{\n $displayState: DisplayState;\n $shouldShowIcon: boolean;\n $hasFocus: boolean;\n}>;\n\nexport const StyledAmountControlInput = styled.input<StyledAmountControlInputProps>`\n background-color: ${({ theme }: StyledAmountControlInputProps) => theme['202']};\n border: none;\n height: 28px;\n width: 95px;\n text-align: center;\n cursor: ${({ $hasFocus }) => ($hasFocus ? 'text' : 'pointer')};\n\n ${({ $displayState }) =>\n $displayState !== 'normal' &&\n css`\n border-bottom-right-radius: 3px;\n border-top-right-radius: 3px;\n `}\n ${({ $displayState, $shouldShowIcon }) =>\n $displayState === 'default' &&\n !$shouldShowIcon &&\n css`\n border-bottom-left-radius: 3px;\n border-top-left-radius: 3px;\n `};\n`;\n\ntype StyledAmountControlButtonProps = WithTheme<{\n $isDisabled: boolean;\n}>;\n\nexport const StyledMotionAmountControlButton = styled(\n motion.button,\n)<StyledAmountControlButtonProps>`\n overflow: hidden;\n background-color: rgba(255, 255, 255, 0.2);\n height: 28px;\n width: 40px;\n\n ${({ $isDisabled }) =>\n $isDisabled &&\n css`\n opacity: 0.5;\n `}\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAM/C,OAAO,MAAMC,mBAAmB,GAAGF,MAAM,CAACG,GAA8B;AACxE,wBAAwBC,IAAA;EAAA,IAAC;IAAEC;EAAgC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC9E;AACA;AACA;AACA,CAAC;AAQD,OAAO,MAAMC,wBAAwB,GAAGN,MAAM,CAACO,KAAqC;AACpF,wBAAwBC,KAAA;EAAA,IAAC;IAAEH;EAAqC,CAAC,GAAAG,KAAA;EAAA,OAAKH,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AACnF;AACA;AACA;AACA;AACA,cAAcI,KAAA;EAAA,IAAC;IAAEC;EAAU,CAAC,GAAAD,KAAA;EAAA,OAAMC,SAAS,GAAG,MAAM,GAAG,SAAS;AAAA,CAAE;AAClE;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEC;EAAc,CAAC,GAAAD,KAAA;EAAA,OAChBC,aAAa,KAAK,QAAQ,IAC1BX,GAAI;AACZ;AACA;AACA,SAAS;AAAA,CAAC;AACV,MAAMY,KAAA;EAAA,IAAC;IAAED,aAAa;IAAEE;EAAgB,CAAC,GAAAD,KAAA;EAAA,OACjCD,aAAa,KAAK,SAAS,IAC3B,CAACE,eAAe,IAChBb,GAAI;AACZ;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAMD,OAAO,MAAMc,+BAA+B,GAAGf,MAAM,CACjDD,MAAM,CAACiB,MACX,CAAkC;AAClC;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEC;EAAY,CAAC,GAAAD,KAAA;EAAA,OACdC,WAAW,IACXjB,GAAI;AACZ;AACA,SAAS;AAAA,CAAC;AACV,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
interface IAreaProviderContext {
|
|
3
|
+
shouldChangeColor?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const AreaProviderContext: React.Context<IAreaProviderContext>;
|
|
6
|
+
interface AreaProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
shouldChangeColor?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const AreaProvider: {
|
|
11
|
+
({ children, shouldChangeColor }: AreaProviderProps): React.JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
14
|
+
export default AreaProvider;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
export const AreaProviderContext = /*#__PURE__*/React.createContext({
|
|
3
|
+
shouldChangeColor: undefined
|
|
4
|
+
});
|
|
5
|
+
AreaProviderContext.displayName = 'AreaProviderContext';
|
|
6
|
+
const AreaProvider = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
shouldChangeColor = true
|
|
10
|
+
} = _ref;
|
|
11
|
+
const providerValue = useMemo(() => ({
|
|
12
|
+
shouldChangeColor
|
|
13
|
+
}), [shouldChangeColor]);
|
|
14
|
+
return /*#__PURE__*/React.createElement(AreaProviderContext.Provider, {
|
|
15
|
+
value: providerValue
|
|
16
|
+
}, children);
|
|
17
|
+
};
|
|
18
|
+
AreaProvider.displayName = 'AreaProvider';
|
|
19
|
+
export default AreaProvider;
|
|
20
|
+
//# sourceMappingURL=AreaProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AreaProvider.js","names":["React","useMemo","AreaProviderContext","createContext","shouldChangeColor","undefined","displayName","AreaProvider","_ref","children","providerValue","createElement","Provider","value"],"sources":["../../../src/components/area-provider/AreaProvider.tsx"],"sourcesContent":["import React, { useMemo, type ReactNode } from 'react';\n\ninterface IAreaProviderContext {\n shouldChangeColor?: boolean;\n}\n\nexport const AreaProviderContext = React.createContext<IAreaProviderContext>({\n shouldChangeColor: undefined,\n});\n\nAreaProviderContext.displayName = 'AreaProviderContext';\n\ninterface AreaProviderProps {\n children: ReactNode;\n shouldChangeColor?: boolean;\n}\n\nconst AreaProvider = ({ children, shouldChangeColor = true }: AreaProviderProps) => {\n const providerValue = useMemo<IAreaProviderContext>(\n () => ({\n shouldChangeColor,\n }),\n [shouldChangeColor],\n );\n\n return (\n <AreaProviderContext.Provider value={providerValue}>\n {children}\n </AreaProviderContext.Provider>\n );\n};\n\nAreaProvider.displayName = 'AreaProvider';\n\nexport default AreaProvider;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAwB,OAAO;AAMtD,OAAO,MAAMC,mBAAmB,gBAAGF,KAAK,CAACG,aAAa,CAAuB;EACzEC,iBAAiB,EAAEC;AACvB,CAAC,CAAC;AAEFH,mBAAmB,CAACI,WAAW,GAAG,qBAAqB;AAOvD,MAAMC,YAAY,GAAGC,IAAA,IAA+D;EAAA,IAA9D;IAAEC,QAAQ;IAAEL,iBAAiB,GAAG;EAAwB,CAAC,GAAAI,IAAA;EAC3E,MAAME,aAAa,GAAGT,OAAO,CACzB,OAAO;IACHG;EACJ,CAAC,CAAC,EACF,CAACA,iBAAiB,CACtB,CAAC;EAED,oBACIJ,KAAA,CAAAW,aAAA,CAACT,mBAAmB,CAACU,QAAQ;IAACC,KAAK,EAAEH;EAAc,GAC9CD,QACyB,CAAC;AAEvC,CAAC;AAEDF,YAAY,CAACD,WAAW,GAAG,cAAc;AAEzC,eAAeC,YAAY","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import { AnimatePresence } from 'framer-motion';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { useTheme } from 'styled-components';
|
|
5
5
|
import Icon from '../icon/Icon';
|
|
6
|
-
import SmallWaitCursor
|
|
6
|
+
import SmallWaitCursor from '../small-wait-cursor/SmallWaitCursor';
|
|
7
7
|
import { StyledIconWrapper, StyledMotionButton, StyledMotionChildrenWrapper, StyledMotionWaitCursorWrapper } from './Button.styles';
|
|
8
8
|
const Button = _ref => {
|
|
9
9
|
let {
|
|
@@ -66,7 +66,7 @@ const Button = _ref => {
|
|
|
66
66
|
}, /*#__PURE__*/React.createElement(SmallWaitCursor, {
|
|
67
67
|
color: "white",
|
|
68
68
|
shouldHideBackground: true,
|
|
69
|
-
size:
|
|
69
|
+
size: 26
|
|
70
70
|
})), !shouldShowWaitCursor && children && /*#__PURE__*/React.createElement(StyledMotionChildrenWrapper, {
|
|
71
71
|
animate: {
|
|
72
72
|
opacity: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","names":["clsx","AnimatePresence","React","useTheme","Icon","SmallWaitCursor","
|
|
1
|
+
{"version":3,"file":"Button.js","names":["clsx","AnimatePresence","React","useTheme","Icon","SmallWaitCursor","StyledIconWrapper","StyledMotionButton","StyledMotionChildrenWrapper","StyledMotionWaitCursorWrapper","Button","_ref","children","className","icon","isDisabled","isSecondary","onClick","shouldShowWaitCursor","shouldStopPropagation","handleClick","event","stopPropagation","buttonClasses","theme","createElement","disabled","$isDisabled","$hasChildren","$hasIcon","$isSecondary","whileTap","backgroundColor","whileHover","initial","color","icons","animate","opacity","width","exit","key","style","overflow","transition","duration","shouldHideBackground","size","displayName"],"sources":["../../../src/components/button/Button.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { AnimatePresence } from 'framer-motion';\nimport React, { FC, MouseEventHandler, ReactNode } from 'react';\nimport { useTheme } from 'styled-components';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\nimport Icon from '../icon/Icon';\nimport SmallWaitCursor from '../small-wait-cursor/SmallWaitCursor';\nimport {\n StyledIconWrapper,\n StyledMotionButton,\n StyledMotionChildrenWrapper,\n StyledMotionWaitCursorWrapper,\n} from './Button.styles';\n\nexport type ButtonProps = {\n /**\n * The label of the button\n */\n children?: ReactNode;\n /**\n * Additional class names for the button element\n */\n className?: string;\n /**\n * An icon that is displayed on the left-hand side of the button text\n */\n icon?: string;\n /**\n * Disables the button so that it cannot be clicked anymore\n */\n isDisabled?: boolean;\n /**\n * Displays the button in the secondary style\n */\n isSecondary?: boolean;\n /**\n * Function to be executed when the button is clicked\n */\n onClick: MouseEventHandler<HTMLButtonElement>;\n /**\n * Shows a wait cursor instead of button text\n */\n shouldShowWaitCursor?: boolean;\n /**\n * Stops event propagation on click\n */\n shouldStopPropagation?: boolean;\n};\n\nconst Button: FC<ButtonProps> = ({\n children,\n className,\n icon,\n isDisabled,\n isSecondary,\n onClick,\n shouldShowWaitCursor,\n shouldStopPropagation,\n}) => {\n const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {\n if (shouldStopPropagation) {\n event.stopPropagation();\n }\n\n onClick(event);\n };\n\n const buttonClasses = clsx('beta-chayns-button ellipsis', className);\n\n const theme: Theme = useTheme();\n\n return (\n <StyledMotionButton\n className={buttonClasses}\n disabled={isDisabled}\n $isDisabled={isDisabled}\n $hasChildren={!!children}\n $hasIcon={typeof icon === 'string' && icon !== ''}\n $isSecondary={isSecondary}\n onClick={handleClick}\n whileTap={\n isDisabled ? {} : { backgroundColor: isSecondary ? theme['201'] : theme['407'] }\n }\n whileHover={\n isDisabled ? {} : { backgroundColor: isSecondary ? theme['203'] : theme['409'] }\n }\n >\n <AnimatePresence initial={false}>\n {icon && (\n <StyledIconWrapper>\n <Icon color=\"white\" icons={[icon]} />\n </StyledIconWrapper>\n )}\n {shouldShowWaitCursor && (\n <StyledMotionWaitCursorWrapper\n animate={{ opacity: 1, width: 40 }}\n exit={{ opacity: 0, width: 0 }}\n initial={{ opacity: 0, width: 0 }}\n key=\"wait-cursor\"\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.2 }}\n >\n <SmallWaitCursor color=\"white\" shouldHideBackground size={26} />\n </StyledMotionWaitCursorWrapper>\n )}\n {!shouldShowWaitCursor && children && (\n <StyledMotionChildrenWrapper\n animate={{ opacity: 1, width: 'auto' }}\n exit={{ opacity: 0, width: 0 }}\n initial={{ opacity: 0, width: 0 }}\n key=\"children\"\n // style={{ overflow: 'hidden' }}\n transition={{ duration: 0.2 }}\n >\n {children}\n </StyledMotionChildrenWrapper>\n )}\n </AnimatePresence>\n </StyledMotionButton>\n );\n};\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,MAA4C,OAAO;AAC/D,SAASC,QAAQ,QAAQ,mBAAmB;AAE5C,OAAOC,IAAI,MAAM,cAAc;AAC/B,OAAOC,eAAe,MAAM,sCAAsC;AAClE,SACIC,iBAAiB,EACjBC,kBAAkB,EAClBC,2BAA2B,EAC3BC,6BAA6B,QAC1B,iBAAiB;AAqCxB,MAAMC,MAAuB,GAAGC,IAAA,IAS1B;EAAA,IAT2B;IAC7BC,QAAQ;IACRC,SAAS;IACTC,IAAI;IACJC,UAAU;IACVC,WAAW;IACXC,OAAO;IACPC,oBAAoB;IACpBC;EACJ,CAAC,GAAAR,IAAA;EACG,MAAMS,WAAi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AAE;IACnCC,IAAI,EAAE;MAAEF,OAAO,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAE,CAAE;IAC/BL,OAAO,EAAE;MAAEI,OAAO,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAE,CAAE;IAClCE,GAAG,EAAC,aAAa;IACjBC,KAAK,EAAE;MAAEC,QAAQ,EAAE;IAAS,CAAE;IAC9BC,UAAU,EAAE;MAAEC,QAAQ,EAAE;IAAI;EAAE,gBAE9B3C,KAAA,CAAAuB,aAAA,CAACpB,eAAe;IAAC8B,KAAK,EAAC,OAAO;IAACW,oBAAoB;IAACC,IAAI,EAAE;EAAG,CAAE,CACpC,CAClC,EACA,CAAC7B,oBAAoB,IAAIN,QAAQ,iBAC9BV,KAAA,CAAAuB,aAAA,CAACjB,2BAA2B;IACxB6B,OAAO,EAAE;MAAEC,OAAO,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAO,CAAE;IACvCC,IAAI,EAAE;MAAEF,OAAO,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAE,CAAE;IAC/BL,OAAO,EAAE;MAAEI,OAAO,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAE,CAAE;IAClCE,GAAG,EAAC;IACJ;IAAA;IACAG,UAAU,EAAE;MAAEC,QAAQ,EAAE;IAAI;EAAE,GAE7BjC,QACwB,CAEpB,CACD,CAAC;AAE7B,CAAC;AAEDF,MAAM,CAACsC,WAAW,GAAG,QAAQ;AAE7B,eAAetC,MAAM","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 AreaProvider, { AreaProviderContext } from '../area-provider/AreaProvider';
|
|
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(AreaProviderContext);
|
|
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(AreaProvider, {
|
|
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","AreaProvider","AreaProviderContext","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 AreaProvider, { AreaProviderContext } from '../area-provider/AreaProvider';\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(AreaProviderContext);\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 <AreaProvider shouldChangeColor={!shouldChangeColor}>{children}</AreaProvider>\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,YAAY,IAAIC,mBAAmB,QAAQ,+BAA+B;AACjF,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,mBAAmB,CAAC;EAEpD,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,YAAY;IAACU,iBAAiB,EAAE,CAACA;EAAkB,GAAEL,QAAuB,CAC9D,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;
|