@mrshmllw/smores-react 15.1.14 → 15.1.16

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.
@@ -22,7 +22,7 @@ export const Modal = ({ title = '', children, rightPanel, showModal = false, han
22
22
  const titleProps = isTitleString ? getDefaultTitleProps(title) : title;
23
23
  if (!showModal)
24
24
  return null;
25
- return createPortal(_jsxs(Wrapper, { ref: modalRef, children: [_jsx(Overlay, { onClick: () => closeOnOverlayClick && handleClick(), "$closeOnOverlayClick": closeOnOverlayClick }), _jsxs(Container, { "$drawer": drawer, "$width": width || '460px', className: containerClass, children: [_jsxs(Box, { flex: true, alignItems: "flex-start", justifyContent: "space-between", mb: "8px", children: [_jsx(TitleElements, { flex: true, direction: "column", children: _jsx(Text, { ...titleProps }) }), _jsxs(Box, { flex: true, alignItems: "center", gap: '8px', children: [rightPanel, cross && (_jsx(IconContainer, { as: "button", onClick: handleClick, role: "button", title: "Close modal", "$size": 32, style: {
25
+ return createPortal(_jsxs(Wrapper, { ref: modalRef, children: [_jsx(Overlay, { onClick: () => closeOnOverlayClick && handleClick(), "$closeOnOverlayClick": closeOnOverlayClick }), _jsxs(Container, { "$drawer": drawer, "$width": width || '460px', className: containerClass, children: [_jsxs(Box, { flex: true, alignItems: "flex-start", justifyContent: "space-between", mb: "space.100", children: [_jsx(TitleElements, { flex: true, direction: "column", children: _jsx(Text, { ...titleProps }) }), _jsxs(Box, { flex: true, alignItems: "center", gap: 'space.100', children: [rightPanel, cross && (_jsx(IconContainer, { as: "button", onClick: handleClick, role: "button", title: "Close modal", "$size": 32, style: {
26
26
  background: theme.color.illustration.neutral[300],
27
27
  borderRadius: '100%',
28
28
  padding: '6px',
@@ -55,7 +55,7 @@ const Container = styled.div(({ $drawer, $width }) => css `
55
55
  background: ${({ theme }) => theme.color.background[100]};
56
56
  box-sizing: border-box;
57
57
  border-radius: 16px;
58
- padding: 24px;
58
+ padding: ${({ theme }) => theme.space[300]};
59
59
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F,EACN,KAAC,GAAG,IAAC,IAAI,QAAC,SAAS,EAAC,QAAQ,YACzB,QAAQ,GACL,IACI,IACJ,EACV,eAAe,CAChB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;;;;;;;CAU1B,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAmC;;gBAE7C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YAChD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;;;;;;CAM1E,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAC1B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;kBACZ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;;;;;iBAK3C,MAAM;;;;;;MAMjB,OAAO,KAAK,IAAI;IAClB,GAAG,CAAA;;;;;;;;;;;;KAYF;GACF,CACF,CAAA;AAED,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAEhC,CAAA","sourcesContent":["import { FC, ReactNode, useRef } from 'react'\nimport { createPortal } from 'react-dom'\nimport styled, { css, useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Text, type TextProps } from '../Text'\nimport { useBodyScrollLock } from '../hooks/useBodyScrollLock'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faXmark } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\ninterface IModalContainer {\n // drawer state\n $drawer: boolean\n // modal width\n $width: string\n}\n\nexport type ModalProps = {\n /**\n * Title of the modal\n * @default \"\" (empty string)\n *\n * @example\n * ```tsx\n * <Modal title=\"MultiCar Account\" />\n * ```\n *\n * @example\n * ```tsx\n * <Modal title={{ typo: 'hero', children: 'MultiCar Account' }} />\n * ```\n */\n title?: string | TitleProps\n icon?: string\n children?: ReactNode\n rightPanel?: ReactNode\n showModal?: boolean\n handleClick: () => void\n drawer?: boolean\n cross?: boolean\n width?: string\n containerClass?: string\n portalContainer?: Element | DocumentFragment\n closeOnOverlayClick?: boolean\n}\n\nexport type TitleProps = TextProps\n\nconst getDefaultTitleProps = (title: string): TitleProps => ({\n children: title,\n tag: 'h2',\n typo: 'heading-small',\n align: 'left',\n})\n\nexport const Modal: FC<ModalProps> = ({\n title = '',\n children,\n rightPanel,\n showModal = false,\n handleClick,\n drawer = true,\n cross = true,\n width,\n containerClass,\n portalContainer = document.body,\n closeOnOverlayClick = true,\n}) => {\n const modalRef = useRef<HTMLDivElement>(null)\n const theme = useTheme()\n\n useBodyScrollLock({ node: modalRef.current, showModal })\n\n const isTitleString = typeof title === 'string'\n const titleProps = isTitleString ? getDefaultTitleProps(title) : title\n\n if (!showModal) return null\n\n return createPortal(\n <Wrapper ref={modalRef}>\n <Overlay\n onClick={() => closeOnOverlayClick && handleClick()}\n $closeOnOverlayClick={closeOnOverlayClick}\n />\n <Container\n $drawer={drawer}\n $width={width || '460px'}\n className={containerClass}\n >\n <Box\n flex\n alignItems=\"flex-start\"\n justifyContent=\"space-between\"\n mb=\"8px\"\n >\n <TitleElements flex direction=\"column\">\n <Text {...titleProps} />\n </TitleElements>\n <Box flex alignItems=\"center\" gap={'8px'}>\n {rightPanel}\n {cross && (\n <IconContainer\n as=\"button\"\n onClick={handleClick}\n role=\"button\"\n title=\"Close modal\"\n $size={32}\n style={{\n background: theme.color.illustration.neutral[300],\n borderRadius: '100%',\n padding: '6px',\n border: 'none',\n cursor: 'pointer',\n }}\n >\n <FontAwesomeIcon icon={faXmark} color={theme.color.icon.base} />\n </IconContainer>\n )}\n </Box>\n </Box>\n <Box flex direction=\"column\">\n {children}\n </Box>\n </Container>\n </Wrapper>,\n portalContainer,\n )\n}\n\nconst Wrapper = styled(Box)`\n display: flex;\n position: absolute;\n z-index: 999;\n top: 0;\n left: 0;\n height: 100vh;\n width: 100%;\n justify-content: center;\n align-items: center;\n`\n\nconst Overlay = styled.div<{ $closeOnOverlayClick: boolean }>`\n position: fixed;\n background: ${({ theme }) => theme.color.surface.base[900]};\n cursor: ${(props) => (props.$closeOnOverlayClick ? 'pointer' : 'default')};\n opacity: 0.4;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n`\n\nconst Container = styled.div<IModalContainer>(\n ({ $drawer, $width }) => css`\n background: ${({ theme }) => theme.color.background[100]};\n box-sizing: border-box;\n border-radius: 16px;\n padding: 24px;\n width: 100%;\n max-width: ${$width};\n position: fixed;\n max-height: calc(100vh - 64px);\n overflow: auto;\n transition: all 0.3s ease-in-out;\n\n ${$drawer === true &&\n css`\n @media (max-width: 768px) {\n max-width: none;\n border-radius: 16px 16px 0px 0px;\n padding: 10% 24px;\n max-height: 90vh;\n\n position: fixed;\n right: 0;\n left: 0;\n bottom: 0;\n }\n `}\n `,\n)\n\nconst TitleElements = styled(Box)`\n align-self: center;\n`\n"]}
1
+ {"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/Modal/Modal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+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AED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAC1B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;kBACZ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;;;eAG7C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;;iBAE7B,MAAM;;;;;;MAMjB,OAAO,KAAK,IAAI;IAClB,GAAG,CAAA;;;;;;;;;;;;KAYF;GACF,CACF,CAAA;AAED,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAEhC,CAAA","sourcesContent":["import { FC, ReactNode, useRef } from 'react'\nimport { createPortal } from 'react-dom'\nimport styled, { css, useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Text, type TextProps } from '../Text'\nimport { useBodyScrollLock } from '../hooks/useBodyScrollLock'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faXmark } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\ninterface IModalContainer {\n // drawer state\n $drawer: boolean\n // modal width\n $width: string\n}\n\nexport type ModalProps = {\n /**\n * Title of the modal\n * @default \"\" (empty string)\n *\n * @example\n * ```tsx\n * <Modal title=\"MultiCar Account\" />\n * ```\n *\n * @example\n * ```tsx\n * <Modal title={{ typo: 'hero', children: 'MultiCar Account' }} />\n * ```\n */\n title?: string | TitleProps\n icon?: string\n children?: ReactNode\n rightPanel?: ReactNode\n showModal?: boolean\n handleClick: () => void\n drawer?: boolean\n cross?: boolean\n width?: string\n containerClass?: string\n portalContainer?: Element | DocumentFragment\n closeOnOverlayClick?: boolean\n}\n\nexport type TitleProps = TextProps\n\nconst getDefaultTitleProps = (title: string): TitleProps => ({\n children: title,\n tag: 'h2',\n typo: 'heading-small',\n align: 'left',\n})\n\nexport const Modal: FC<ModalProps> = ({\n title = '',\n children,\n rightPanel,\n showModal = false,\n handleClick,\n drawer = true,\n cross = true,\n width,\n containerClass,\n portalContainer = document.body,\n closeOnOverlayClick = true,\n}) => {\n const modalRef = useRef<HTMLDivElement>(null)\n const theme = useTheme()\n\n useBodyScrollLock({ node: modalRef.current, showModal })\n\n const isTitleString = typeof title === 'string'\n const titleProps = isTitleString ? getDefaultTitleProps(title) : title\n\n if (!showModal) return null\n\n return createPortal(\n <Wrapper ref={modalRef}>\n <Overlay\n onClick={() => closeOnOverlayClick && handleClick()}\n $closeOnOverlayClick={closeOnOverlayClick}\n />\n <Container\n $drawer={drawer}\n $width={width || '460px'}\n className={containerClass}\n >\n <Box\n flex\n alignItems=\"flex-start\"\n justifyContent=\"space-between\"\n mb=\"space.100\"\n >\n <TitleElements flex direction=\"column\">\n <Text {...titleProps} />\n </TitleElements>\n <Box flex alignItems=\"center\" gap={'space.100'}>\n {rightPanel}\n {cross && (\n <IconContainer\n as=\"button\"\n onClick={handleClick}\n role=\"button\"\n title=\"Close modal\"\n $size={32}\n style={{\n background: theme.color.illustration.neutral[300],\n borderRadius: '100%',\n padding: '6px',\n border: 'none',\n cursor: 'pointer',\n }}\n >\n <FontAwesomeIcon icon={faXmark} color={theme.color.icon.base} />\n </IconContainer>\n )}\n </Box>\n </Box>\n <Box flex direction=\"column\">\n {children}\n </Box>\n </Container>\n </Wrapper>,\n portalContainer,\n )\n}\n\nconst Wrapper = styled(Box)`\n display: flex;\n position: absolute;\n z-index: 999;\n top: 0;\n left: 0;\n height: 100vh;\n width: 100%;\n justify-content: center;\n align-items: center;\n`\n\nconst Overlay = styled.div<{ $closeOnOverlayClick: boolean }>`\n position: fixed;\n background: ${({ theme }) => theme.color.surface.base[900]};\n cursor: ${(props) => (props.$closeOnOverlayClick ? 'pointer' : 'default')};\n opacity: 0.4;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n`\n\nconst Container = styled.div<IModalContainer>(\n ({ $drawer, $width }) => css`\n background: ${({ theme }) => theme.color.background[100]};\n box-sizing: border-box;\n border-radius: 16px;\n padding: ${({ theme }) => theme.space[300]};\n width: 100%;\n max-width: ${$width};\n position: fixed;\n max-height: calc(100vh - 64px);\n overflow: auto;\n transition: all 0.3s ease-in-out;\n\n ${$drawer === true &&\n css`\n @media (max-width: 768px) {\n max-width: none;\n border-radius: 16px 16px 0px 0px;\n padding: 10% 24px;\n max-height: 90vh;\n\n position: fixed;\n right: 0;\n left: 0;\n bottom: 0;\n }\n `}\n `,\n)\n\nconst TitleElements = styled(Box)`\n align-self: center;\n`\n"]}
@@ -92,7 +92,7 @@ export const Pagination = ({ total, partition, handlePageChange, currentPage, ..
92
92
  const Container = styled(Box) `
93
93
  align-items: center;
94
94
  > button {
95
- margin-right: 4px;
95
+ margin-right: ${({ theme }) => theme.space['050']};
96
96
 
97
97
  &:last-child {
98
98
  margin-right: 0;
@@ -1 +1 @@
1
- {"version":3,"file":"Pagination.js","sourceRoot":"","sources":["../../src/Pagination/Pagination.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EACL,WAAW,EACX,YAAY,GACb,MAAM,kDAAkD,CAAA;AAEzD,MAAM,SAAS,GAAG,CAAC,CAAA;AACnB,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAA;AAarD,MAAM,CAAC,MAAM,UAAU,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EAAE,CAAC;wBACtB,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;oBAC1B,CAAC;gBACH,CAAC,YAED,KAAC,aAAa,aAAQ,EAAE,YACtB,KAAC,eAAe,IAAC,IAAI,EAAE,YAAY,GAAI,GACzB,GACR,CACX,IACS,CACb,CAAA;AACH,CAAC,CAAA;AAMD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;;;;;;CAS5B,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAU;gBACvB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACnC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;;wBAWrD,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;wBAG5C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;IAGhE,iBAAiB;CACpB,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAU;;;IAGnC,iBAAiB;CACpB,CAAA","sourcesContent":["import { FC, useEffect, useState } from 'react'\nimport styled from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Text } from '../Text'\n\nimport { focusOutlineStyle } from '../utils/focusOutline'\nimport { MarginProps } from '../utils/space'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport {\n faArrowLeft,\n faArrowRight,\n} from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\nconst MAX_PAGES = 7\nconst MAX_ADDITIONAL_PAGES = Math.ceil(MAX_PAGES / 2)\n\nexport type PaginationProps = {\n /** Total number of records */\n total: number\n /** Number of records per page */\n partition: number\n /** Handle page change */\n handlePageChange: (page: number) => void\n /** Sets current page number */\n currentPage?: number\n} & MarginProps\n\nexport const Pagination: FC<PaginationProps> = ({\n total,\n partition,\n handlePageChange,\n currentPage,\n ...marginProps\n}) => {\n const [lastPage, setLastPage] = useState(0)\n const [activePage, setActivePage] = useState(1)\n const [pages, setPages] = useState<number[]>([])\n const [shownPages, setShownPages] = useState<number[]>([])\n const [showFirstDots, setShowFirstDots] = useState(false)\n const [showLastDots, setShowLastDots] = useState(false)\n\n useEffect(() => {\n // This is a rather hacky fix, in theory it should be listening to total, but because the total comes from the same endpoint as the data, it forces a reset to 1 every time\n // Using lastPage seems to bypass that\n if (currentPage) {\n setActivePage(currentPage)\n } else {\n setActivePage(1)\n }\n }, [lastPage, currentPage])\n\n useEffect(() => {\n const numberOfPages = Math.ceil(total / partition)\n if (numberOfPages > 1) {\n setLastPage(numberOfPages)\n } else if (numberOfPages === 1) {\n // Sets last page to be null to avoid the last page being kept from previous state.\n setLastPage(0)\n }\n if (numberOfPages > 2) {\n const allPages = Array.from({ length: numberOfPages }, (_, i) => i + 1)\n setPages(allPages.slice(1, numberOfPages - 1))\n } else {\n // Sets pages to empty to avoid using the previous state if pages set before.\n setPages([])\n }\n }, [total, partition])\n\n useEffect(() => {\n if (lastPage <= MAX_PAGES) {\n setShownPages(pages)\n } else if (activePage <= MAX_ADDITIONAL_PAGES) {\n setShownPages(pages.slice(0, MAX_ADDITIONAL_PAGES))\n } else if (activePage > lastPage - MAX_ADDITIONAL_PAGES) {\n setShownPages(pages.slice(pages.length - MAX_ADDITIONAL_PAGES))\n } else {\n const activePageIndex = pages.indexOf(activePage)\n setShownPages(pages.slice(activePageIndex - 1, activePageIndex + 2))\n }\n }, [lastPage, activePage, pages])\n\n useEffect(() => {\n setShowFirstDots(shownPages[0] !== pages[0])\n setShowLastDots(\n shownPages[shownPages.length - 1] !== pages[pages.length - 1],\n )\n }, [shownPages, pages])\n\n const movePage = (page: number) => {\n if (page > 0 && page <= lastPage) {\n setActivePage(page)\n handlePageChange(page)\n }\n }\n\n return (\n <Container flex direction=\"row\" {...marginProps}>\n {activePage - 1 > 0 && (\n <IconBox\n aria-label=\"previous-page\"\n onClick={() => movePage(activePage - 1)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(activePage - 1)\n }\n }}\n >\n <IconContainer $size={16}>\n <FontAwesomeIcon icon={faArrowLeft} />\n </IconContainer>\n </IconBox>\n )}\n <PageBox $active={activePage === 1} onClick={() => movePage(1)}>\n <Text\n typo={activePage === 1 ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n 1\n </Text>\n </PageBox>\n {showFirstDots && (\n <PageBox>\n <Text tag=\"p\">...</Text>\n </PageBox>\n )}\n {shownPages.map((i) => {\n return (\n <PageBox\n $active={activePage === i}\n key={i}\n onClick={() => movePage(i)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(i)\n }\n }}\n >\n <Text\n typo={activePage === i ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n {i}\n </Text>\n </PageBox>\n )\n })}\n {showLastDots && (\n <PageBox>\n <Text tag=\"p\">...</Text>\n </PageBox>\n )}\n {Boolean(lastPage) && (\n <PageBox\n $active={activePage === lastPage}\n onClick={() => movePage(lastPage)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(lastPage)\n }\n }}\n >\n <Text\n typo={activePage === lastPage ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n {lastPage}\n </Text>\n </PageBox>\n )}\n {activePage + 1 <= lastPage && (\n <IconBox\n aria-label=\"next-page\"\n onClick={() => movePage(activePage + 1)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(activePage + 1)\n }\n }}\n >\n <IconContainer $size={16}>\n <FontAwesomeIcon icon={faArrowRight} />\n </IconContainer>\n </IconBox>\n )}\n </Container>\n )\n}\n\ninterface IPageBox {\n $active?: boolean\n}\n\nconst Container = styled(Box)`\n align-items: center;\n > button {\n margin-right: 4px;\n\n &:last-child {\n margin-right: 0;\n }\n }\n`\n\nconst PageBox = styled.button<IPageBox>`\n background: ${({ $active, theme }) =>\n $active ? theme.color.surface.base[300] : theme.color.surface.base['000']};\n cursor: pointer;\n display: flex;\n justify-content: center;\n border-radius: 24px;\n width: fit-content;\n padding: 0px 4px;\n height: 24px;\n min-width: 24px;\n\n &:hover {\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n }\n &:active {\n background-color: ${({ theme }) => theme.color.surface.base[200]};\n }\n\n ${focusOutlineStyle}\n`\n\nconst IconBox = styled.button<IPageBox>`\n cursor: pointer;\n\n ${focusOutlineStyle}\n`\n"]}
1
+ {"version":3,"file":"Pagination.js","sourceRoot":"","sources":["../../src/Pagination/Pagination.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EACL,WAAW,EACX,YAAY,GACb,MAAM,kDAAkD,CAAA;AAEzD,MAAM,SAAS,GAAG,CAAC,CAAA;AACnB,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAA;AAarD,MAAM,CAAC,MAAM,UAAU,GAAwB,CAAC,EAC9C,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,GAAG,WAAW,EACf,EAAE,EAAE;IACH,MAAM,CAA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,EAAE,YACtB,KAAC,eAAe,IAAC,IAAI,EAAE,YAAY,GAAI,GACzB,GACR,CACX,IACS,CACb,CAAA;AACH,CAAC,CAAA;AAMD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;oBAGT,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;CAMpD,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAU;gBACvB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACnC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;;wBAWrD,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;wBAG5C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;IAGhE,iBAAiB;CACpB,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAU;;;IAGnC,iBAAiB;CACpB,CAAA","sourcesContent":["import { FC, useEffect, useState } from 'react'\nimport styled from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Text } from '../Text'\n\nimport { focusOutlineStyle } from '../utils/focusOutline'\nimport { MarginProps } from '../utils/space'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport {\n faArrowLeft,\n faArrowRight,\n} from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\nconst MAX_PAGES = 7\nconst MAX_ADDITIONAL_PAGES = Math.ceil(MAX_PAGES / 2)\n\nexport type PaginationProps = {\n /** Total number of records */\n total: number\n /** Number of records per page */\n partition: number\n /** Handle page change */\n handlePageChange: (page: number) => void\n /** Sets current page number */\n currentPage?: number\n} & MarginProps\n\nexport const Pagination: FC<PaginationProps> = ({\n total,\n partition,\n handlePageChange,\n currentPage,\n ...marginProps\n}) => {\n const [lastPage, setLastPage] = useState(0)\n const [activePage, setActivePage] = useState(1)\n const [pages, setPages] = useState<number[]>([])\n const [shownPages, setShownPages] = useState<number[]>([])\n const [showFirstDots, setShowFirstDots] = useState(false)\n const [showLastDots, setShowLastDots] = useState(false)\n\n useEffect(() => {\n // This is a rather hacky fix, in theory it should be listening to total, but because the total comes from the same endpoint as the data, it forces a reset to 1 every time\n // Using lastPage seems to bypass that\n if (currentPage) {\n setActivePage(currentPage)\n } else {\n setActivePage(1)\n }\n }, [lastPage, currentPage])\n\n useEffect(() => {\n const numberOfPages = Math.ceil(total / partition)\n if (numberOfPages > 1) {\n setLastPage(numberOfPages)\n } else if (numberOfPages === 1) {\n // Sets last page to be null to avoid the last page being kept from previous state.\n setLastPage(0)\n }\n if (numberOfPages > 2) {\n const allPages = Array.from({ length: numberOfPages }, (_, i) => i + 1)\n setPages(allPages.slice(1, numberOfPages - 1))\n } else {\n // Sets pages to empty to avoid using the previous state if pages set before.\n setPages([])\n }\n }, [total, partition])\n\n useEffect(() => {\n if (lastPage <= MAX_PAGES) {\n setShownPages(pages)\n } else if (activePage <= MAX_ADDITIONAL_PAGES) {\n setShownPages(pages.slice(0, MAX_ADDITIONAL_PAGES))\n } else if (activePage > lastPage - MAX_ADDITIONAL_PAGES) {\n setShownPages(pages.slice(pages.length - MAX_ADDITIONAL_PAGES))\n } else {\n const activePageIndex = pages.indexOf(activePage)\n setShownPages(pages.slice(activePageIndex - 1, activePageIndex + 2))\n }\n }, [lastPage, activePage, pages])\n\n useEffect(() => {\n setShowFirstDots(shownPages[0] !== pages[0])\n setShowLastDots(\n shownPages[shownPages.length - 1] !== pages[pages.length - 1],\n )\n }, [shownPages, pages])\n\n const movePage = (page: number) => {\n if (page > 0 && page <= lastPage) {\n setActivePage(page)\n handlePageChange(page)\n }\n }\n\n return (\n <Container flex direction=\"row\" {...marginProps}>\n {activePage - 1 > 0 && (\n <IconBox\n aria-label=\"previous-page\"\n onClick={() => movePage(activePage - 1)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(activePage - 1)\n }\n }}\n >\n <IconContainer $size={16}>\n <FontAwesomeIcon icon={faArrowLeft} />\n </IconContainer>\n </IconBox>\n )}\n <PageBox $active={activePage === 1} onClick={() => movePage(1)}>\n <Text\n typo={activePage === 1 ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n 1\n </Text>\n </PageBox>\n {showFirstDots && (\n <PageBox>\n <Text tag=\"p\">...</Text>\n </PageBox>\n )}\n {shownPages.map((i) => {\n return (\n <PageBox\n $active={activePage === i}\n key={i}\n onClick={() => movePage(i)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(i)\n }\n }}\n >\n <Text\n typo={activePage === i ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n {i}\n </Text>\n </PageBox>\n )\n })}\n {showLastDots && (\n <PageBox>\n <Text tag=\"p\">...</Text>\n </PageBox>\n )}\n {Boolean(lastPage) && (\n <PageBox\n $active={activePage === lastPage}\n onClick={() => movePage(lastPage)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(lastPage)\n }\n }}\n >\n <Text\n typo={activePage === lastPage ? 'headline-small' : 'body-regular'}\n tag=\"p\"\n >\n {lastPage}\n </Text>\n </PageBox>\n )}\n {activePage + 1 <= lastPage && (\n <IconBox\n aria-label=\"next-page\"\n onClick={() => movePage(activePage + 1)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n movePage(activePage + 1)\n }\n }}\n >\n <IconContainer $size={16}>\n <FontAwesomeIcon icon={faArrowRight} />\n </IconContainer>\n </IconBox>\n )}\n </Container>\n )\n}\n\ninterface IPageBox {\n $active?: boolean\n}\n\nconst Container = styled(Box)`\n align-items: center;\n > button {\n margin-right: ${({ theme }) => theme.space['050']};\n\n &:last-child {\n margin-right: 0;\n }\n }\n`\n\nconst PageBox = styled.button<IPageBox>`\n background: ${({ $active, theme }) =>\n $active ? theme.color.surface.base[300] : theme.color.surface.base['000']};\n cursor: pointer;\n display: flex;\n justify-content: center;\n border-radius: 24px;\n width: fit-content;\n padding: 0px 4px;\n height: 24px;\n min-width: 24px;\n\n &:hover {\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n }\n &:active {\n background-color: ${({ theme }) => theme.color.surface.base[200]};\n }\n\n ${focusOutlineStyle}\n`\n\nconst IconBox = styled.button<IPageBox>`\n cursor: pointer;\n\n ${focusOutlineStyle}\n`\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrshmllw/smores-react",
3
- "version": "15.1.14",
3
+ "version": "15.1.16",
4
4
  "description": "Collection of React components used by Marshmallow Technology",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",