@mrshmllw/smores-react 14.1.1 → 14.3.0

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.
Files changed (105) hide show
  1. package/dist/Accordion/Accordion.js +5 -3
  2. package/dist/Accordion/Accordion.js.map +1 -1
  3. package/dist/ActionDropdown/ActionDropdown.js +6 -2
  4. package/dist/ActionDropdown/ActionDropdown.js.map +1 -1
  5. package/dist/Alert/Alert.js +9 -8
  6. package/dist/Alert/Alert.js.map +1 -1
  7. package/dist/Banner/BannerItem.js +8 -2
  8. package/dist/Banner/BannerItem.js.map +1 -1
  9. package/dist/Banner/types.d.ts +3 -1
  10. package/dist/Banner/types.js.map +1 -1
  11. package/dist/Box/index.d.ts +1 -0
  12. package/dist/Box/index.js.map +1 -1
  13. package/dist/Button/Button.d.ts +2 -1
  14. package/dist/Button/Button.js +5 -3
  15. package/dist/Button/Button.js.map +1 -1
  16. package/dist/Card/Card.d.ts +2 -16
  17. package/dist/Card/Card.js +7 -4
  18. package/dist/Card/Card.js.map +1 -1
  19. package/dist/Chip/Chip.d.ts +2 -1
  20. package/dist/Chip/Chip.js +11 -3
  21. package/dist/Chip/Chip.js.map +1 -1
  22. package/dist/CurrencyInput/CurrencyInput.js +6 -3
  23. package/dist/CurrencyInput/CurrencyInput.js.map +1 -1
  24. package/dist/Datepicker/Datepicker.js +7 -4
  25. package/dist/Datepicker/Datepicker.js.map +1 -1
  26. package/dist/Dropdown/Dropdown.d.ts +3 -2
  27. package/dist/Dropdown/Dropdown.js +11 -7
  28. package/dist/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/Dropdown/index.d.ts +1 -1
  30. package/dist/Dropdown/index.js.map +1 -1
  31. package/dist/Icon/Icon.js +5 -0
  32. package/dist/Icon/Icon.js.map +1 -1
  33. package/dist/Icon/index.d.ts +1 -0
  34. package/dist/Icon/index.js.map +1 -1
  35. package/dist/IconStrict/IconStrict.d.ts +1 -1
  36. package/dist/IconStrict/IconStrict.js +5 -0
  37. package/dist/IconStrict/IconStrict.js.map +1 -1
  38. package/dist/IconWrapper/IconWrapper.d.ts +1 -1
  39. package/dist/IconWrapper/IconWrapper.js.map +1 -1
  40. package/dist/Link/Link.d.ts +2 -1
  41. package/dist/Link/Link.js +7 -2
  42. package/dist/Link/Link.js.map +1 -1
  43. package/dist/Modal/Modal.js +12 -3
  44. package/dist/Modal/Modal.js.map +1 -1
  45. package/dist/NumberInput/NumberInput.js +11 -6
  46. package/dist/NumberInput/NumberInput.js.map +1 -1
  47. package/dist/Pagination/Pagination.js +5 -3
  48. package/dist/Pagination/Pagination.js.map +1 -1
  49. package/dist/ProgressIndicator/components/StepItem.js +6 -3
  50. package/dist/ProgressIndicator/components/StepItem.js.map +1 -1
  51. package/dist/RadioGroup/RadioGroup.d.ts +3 -2
  52. package/dist/RadioGroup/RadioGroup.js +1 -1
  53. package/dist/RadioGroup/RadioGroup.js.map +1 -1
  54. package/dist/RadioGroup/RadioItem.d.ts +3 -2
  55. package/dist/RadioGroup/RadioItem.js +7 -2
  56. package/dist/RadioGroup/RadioItem.js.map +1 -1
  57. package/dist/RichText/RichText.js +4 -2
  58. package/dist/RichText/RichText.js.map +1 -1
  59. package/dist/RichTextEditor/plugins/ToolbarPlugin.js +7 -5
  60. package/dist/RichTextEditor/plugins/ToolbarPlugin.js.map +1 -1
  61. package/dist/Row/Row.d.ts +4 -2
  62. package/dist/Row/Row.js +8 -3
  63. package/dist/Row/Row.js.map +1 -1
  64. package/dist/SearchInput/SearchInput.d.ts +0 -9
  65. package/dist/SearchInput/SearchInput.js +11 -6
  66. package/dist/SearchInput/SearchInput.js.map +1 -1
  67. package/dist/Snackbar/SnackbarItem.js +8 -3
  68. package/dist/Snackbar/SnackbarItem.js.map +1 -1
  69. package/dist/Snackbar/types.d.ts +2 -1
  70. package/dist/Snackbar/types.js.map +1 -1
  71. package/dist/SupportMessage/SupportMessage.js +11 -10
  72. package/dist/SupportMessage/SupportMessage.js.map +1 -1
  73. package/dist/Table/index.d.ts +1 -0
  74. package/dist/Table/index.js.map +1 -1
  75. package/dist/Tag/Tag.d.ts +3 -2
  76. package/dist/Tag/Tag.js +4 -2
  77. package/dist/Tag/Tag.js.map +1 -1
  78. package/dist/Tag/Tag.spec.js +10 -0
  79. package/dist/Tag/Tag.spec.js.map +1 -1
  80. package/dist/TextInput/TextInput.js +8 -4
  81. package/dist/TextInput/TextInput.js.map +1 -1
  82. package/dist/ThemeProvider/utils/colourMap.d.ts +2 -8
  83. package/dist/ThemeProvider/utils/colourMap.js.map +1 -1
  84. package/dist/fields/commonFieldTypes.d.ts +3 -1
  85. package/dist/fields/commonFieldTypes.js.map +1 -1
  86. package/dist/fields/components/CommonInput.d.ts +10 -2
  87. package/dist/fields/components/CommonInput.js +16 -0
  88. package/dist/fields/components/CommonInput.js.map +1 -1
  89. package/dist/index.d.ts +2 -0
  90. package/dist/index.js +2 -0
  91. package/dist/index.js.map +1 -1
  92. package/dist/sharedStyles/shared.styles.d.ts +5 -0
  93. package/dist/sharedStyles/shared.styles.js +22 -0
  94. package/dist/sharedStyles/shared.styles.js.map +1 -0
  95. package/dist/types.d.ts +7 -0
  96. package/dist/types.js.map +1 -1
  97. package/dist/utils/deprecated.js +8 -2
  98. package/dist/utils/deprecated.js.map +1 -1
  99. package/dist/utils/flex.d.ts +4 -1
  100. package/dist/utils/flex.js +4 -4
  101. package/dist/utils/flex.js.map +1 -1
  102. package/dist/utils/space.d.ts +12 -5
  103. package/dist/utils/space.js +31 -21
  104. package/dist/utils/space.js.map +1 -1
  105. package/package.json +30 -27
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useRef } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
- import styled, { css } from 'styled-components';
4
+ import styled, { css, useTheme } from 'styled-components';
5
5
  import { Box } from '../Box';
6
- import { IconStrict } from '../IconStrict';
7
6
  import { Text } from '../Text';
8
7
  import { useBodyScrollLock } from '../hooks/useBodyScrollLock';
8
+ import { IconContainer } from '../sharedStyles/shared.styles';
9
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
+ import { faXmark } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
9
11
  const getDefaultTitleProps = (title) => ({
10
12
  children: title,
11
13
  tag: 'h2',
@@ -14,12 +16,19 @@ const getDefaultTitleProps = (title) => ({
14
16
  });
15
17
  export const Modal = ({ title = '', children, rightPanel, showModal = false, handleClick, drawer = true, cross = true, width, containerClass, portalContainer = document.body, closeOnOverlayClick = true, }) => {
16
18
  const modalRef = useRef(null);
19
+ const theme = useTheme();
17
20
  useBodyScrollLock({ node: modalRef.current, showModal });
18
21
  const isTitleString = typeof title === 'string';
19
22
  const titleProps = isTitleString ? getDefaultTitleProps(title) : title;
20
23
  if (!showModal)
21
24
  return null;
22
- 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(IconStrict, { render: "cross", title: "Close modal", backgroundColor: "color.illustration.neutral.300", handleClick: handleClick, size: 36 }))] })] }), _jsx(Box, { flex: true, direction: "column", children: children })] })] }), portalContainer);
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: {
26
+ background: theme.color.illustration.neutral[300],
27
+ borderRadius: '100%',
28
+ padding: '6px',
29
+ border: 'none',
30
+ cursor: 'pointer',
31
+ }, children: _jsx(FontAwesomeIcon, { icon: faXmark, color: theme.color.icon.base }) }))] })] }), _jsx(Box, { flex: true, direction: "column", children: children })] })] }), portalContainer);
23
32
  };
24
33
  const Wrapper = styled(Box) `
25
34
  display: flex;
@@ -1 +1 @@
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,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAwC9D,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,CAAC;IAC3D,QAAQ,EAAE,KAAK;IACf,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,MAAM;CACd,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,KAAK,GAAmB,CAAC,EACpC,KAAK,GAAG,EAAE,EACV,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,KAAK,EACjB,WAAW,EACX,MAAM,GAAG,IAAI,EACb,KAAK,GAAG,IAAI,EACZ,KAAK,EACL,cAAc,EACd,eAAe,GAAG,QAAQ,CAAC,IAAI,EAC/B,mBAAmB,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G,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 } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { IconStrict } from '../IconStrict'\nimport { Text, type TextProps } from '../Text'\nimport { useBodyScrollLock } from '../hooks/useBodyScrollLock'\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\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 <IconStrict\n render=\"cross\"\n title=\"Close modal\"\n backgroundColor=\"color.illustration.neutral.300\"\n handleClick={handleClick}\n size={36}\n />\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+B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAA;AAwC1E,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,CAAC;IAC3D,QAAQ,EAAE,KAAK;IACf,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,MAAM;CACd,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,KAAK,GAAmB,CAAC,EACpC,KAAK,GAAG,EAAE,EACV,QAAQ,EACR,U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AAA","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,13 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, } from 'react';
3
- import styled from 'styled-components';
3
+ import styled, { useTheme } from 'styled-components';
4
4
  import { Box } from '../Box';
5
- import { Icon } from '../Icon';
6
5
  import { Field } from '../fields/Field';
7
- import { Input, StyledFrontIcon, StyledTrailingIcon, } from '../fields/components/CommonInput';
6
+ import { Input, InputLeadingIconContainer, InputTrailingIconContainer, StyledFrontIcon, StyledTrailingIcon, } from '../fields/components/CommonInput';
8
7
  import { useUniqueId } from '../utils/id';
9
- export const NumberInput = forwardRef(function NumberInput({ id: idProp, type = 'number', placeholder, name, value, onChange, onInputChange, onBlur, min = -999999, max = 999999, step = 0, disabled = false, error = false, frontIcon, trailingIcon, fallbackStyle, ...fieldProps }, ref) {
8
+ import { faChevronDown, faChevronUp, } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
9
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
+ import { IconContainer } from '../sharedStyles/shared.styles';
11
+ export const NumberInput = forwardRef(function NumberInput({ id: idProp, type = 'number', placeholder, name, value, onChange, onInputChange, onBlur, min = -999999, max = 999999, step = 0, disabled = false, error = false, frontIcon, frontIconComponent, trailingIconComponent, trailingIcon, fallbackStyle, ...fieldProps }, ref) {
10
12
  const id = useUniqueId(idProp);
13
+ const theme = useTheme();
11
14
  // Check whether the min/max value exists is within the specified range
12
15
  const isInRange = (value) => {
13
16
  if (min && value < min) {
@@ -61,10 +64,12 @@ export const NumberInput = forwardRef(function NumberInput({ id: idProp, type =
61
64
  onChange(roundNumber(currentValue));
62
65
  }
63
66
  };
64
- return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [frontIcon && (_jsx(StyledFrontIcon, { "$disabled": disabled, render: frontIcon, color: "sesame" })), _jsx(Input, { ref: ref, "$error": error, disabled: disabled, type: type, id: id, name: name, placeholder: placeholder, value: value, "$frontIcon": frontIcon, step: step, "$fallbackStyle": fallbackStyle, onWheel: (e) => e.currentTarget.blur(), onChange: (e) => {
67
+ const frontIconToRender = frontIconComponent ? (_jsx(InputLeadingIconContainer, { "$size": 20, "$iconColor": theme.color.text.subtle, children: frontIconComponent })) : frontIcon ? (_jsx(StyledFrontIcon, { "$disabled": disabled, render: frontIcon, color: "sesame" })) : null;
68
+ const trailingIconToRender = trailingIconComponent ? (_jsx(InputTrailingIconContainer, { "$size": 20, "$iconColor": theme.color.text.subtle, children: trailingIconComponent })) : trailingIcon ? (_jsx(StyledTrailingIcon, { "$disabled": disabled, render: trailingIcon, color: "sesame" })) : null;
69
+ return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [frontIconToRender && frontIconToRender, _jsx(Input, { ref: ref, "$error": error, disabled: disabled, type: type, id: id, name: name, placeholder: placeholder, value: value, "$frontIcon": Boolean(frontIconToRender), step: step, "$fallbackStyle": fallbackStyle, onWheel: (e) => e.currentTarget.blur(), onChange: (e) => {
65
70
  onChange && handleChange(e.currentTarget.value);
66
71
  onInputChange?.(e);
67
- }, onBlur: onBlur }), onChange && step > 0 && (_jsxs(Spinner, { children: [_jsx(SpinnerButton, { "aria-label": "step-up", onClick: incrementValue, disabled: disabled, children: _jsx(Icon, { render: "caret", rotate: 180, color: "sesame", size: 24 }) }), _jsx(SpinnerButton, { "aria-label": "step-down", onClick: decrementValue, disabled: disabled, children: _jsx(Icon, { render: "caret", color: "sesame", size: 24 }) })] })), trailingIcon && !step && (_jsx(StyledTrailingIcon, { "$disabled": disabled, render: trailingIcon, color: "sesame" }))] }) }));
72
+ }, onBlur: onBlur }), onChange && step > 0 && (_jsxs(Spinner, { children: [_jsx(SpinnerButton, { "aria-label": "step-up", onClick: incrementValue, disabled: disabled, children: _jsx(IconContainer, { "$size": 20, children: _jsx(FontAwesomeIcon, { icon: faChevronDown, color: theme.color.text.subtle }) }) }), _jsx(SpinnerButton, { "aria-label": "step-down", onClick: decrementValue, disabled: disabled, children: _jsx(IconContainer, { "$size": 20, children: _jsx(FontAwesomeIcon, { icon: faChevronUp, color: theme.color.text.subtle }) }) })] })), trailingIconToRender && !step && trailingIconToRender] }) }));
68
73
  });
69
74
  const Spinner = styled.div `
70
75
  position: relative;
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../src/NumberInput/NumberInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GACX,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC,OAAO,EACL,KAAK,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AA4BzC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,SAAS,WAAW,CACxD,EACE,EAAE,EAAE,MAAM,EACV,IAAI,GAAG,QAAQ,EACf,WAAW,EACX,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,aAAa,EACb,MAAM,EACN,GAAG,GAAG,CAAC,MAAM,EACb,GAAG,GAAG,MAAM,EACZ,IAAI,GAAG,CAAC,EACR,QAAQ,GAAG,KAAK,EAChB,KAAK,GAAG,KAAK,EACb,SAAS,EACT,YAAY,EACZ,aAAa,EACb,GAAG,UAAU,EACI,EACnB,GAAmC;IAEnC,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAE9B,uEAAuE;IACvE,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE;QAClC,IAAI,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YACvB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YACvB,OAAO,KA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AAQ,YAElB,KAAC,IAAI,IAAC,MAAM,EAAC,OAAO,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAC,QAAQ,EAAC,IAAI,EAAE,EAAE,GAAI,GAC/C,EAEhB,KAAC,aAAa,kBACD,WAAW,EACtB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,QAAQ,YAElB,KAAC,IAAI,IAAC,MAAM,EAAC,OAAO,EAAC,KAAK,EAAC,QAAQ,EAAC,IAAI,EAAE,EAAE,GAAI,GAClC,IACR,CACX,EACA,YAAY,IAAI,CAAC,IAAI,IAAI,CACxB,KAAC,kBAAkB,iBACN,QAAQ,EACnB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAC,QAAQ,GACd,CACH,IACG,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;CAKzB,CAAA;AAMD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAS;;;;;;YAMhC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;CACnE,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n MouseEvent,\n forwardRef,\n} from 'react'\nimport styled from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Icon } from '../Icon'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\n\nexport interface Props extends CommonFieldProps {\n type?: 'number'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n step?: number\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string | number) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string | number) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type NumberInputProps = Props & InputProps\n\nexport const NumberInput = forwardRef(function NumberInput(\n {\n id: idProp,\n type = 'number',\n placeholder,\n name,\n value,\n onChange,\n onInputChange,\n onBlur,\n min = -999999,\n max = 999999,\n step = 0,\n disabled = false,\n error = false,\n frontIcon,\n trailingIcon,\n fallbackStyle,\n ...fieldProps\n }: NumberInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n\n // Check whether the min/max value exists is within the specified range\n const isInRange = (value: number) => {\n if (min && value < min) {\n return false\n }\n\n if (max && value > max) {\n return false\n }\n\n return true\n }\n\n // Round the number to two decimal places\n const roundNumber = (event: number) => {\n return Math.round(event * 100) / 100\n }\n\n const applyMinMax = (value: number) => {\n if (min && value < min) return min\n if (max && value > max) return max\n return value\n }\n\n const handleChange = (event: string) => {\n if (onChange === undefined) return\n const EMPTY_INPUT = ''\n\n if (event === EMPTY_INPUT) {\n onChange(event)\n } else {\n const amount = Number(event)\n const normalisedValue = applyMinMax(amount)\n\n onChange(normalisedValue)\n }\n }\n // Increment or decrement the value when clicking the Spinner controls\n const incrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) + step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const decrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) - step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n return (\n <Field {...fieldProps} htmlFor={id} error={error}>\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIcon && (\n <StyledFrontIcon\n $disabled={disabled}\n render={frontIcon}\n color=\"sesame\"\n />\n )}\n <Input\n ref={ref}\n $error={error}\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n placeholder={placeholder}\n value={value}\n $frontIcon={frontIcon}\n step={step}\n $fallbackStyle={fallbackStyle}\n onWheel={(e) => e.currentTarget.blur()}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n onChange && handleChange(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n />\n\n {onChange && step > 0 && (\n <Spinner>\n <SpinnerButton\n aria-label=\"step-up\"\n onClick={incrementValue}\n disabled={disabled}\n >\n <Icon render=\"caret\" rotate={180} color=\"sesame\" size={24} />\n </SpinnerButton>\n\n <SpinnerButton\n aria-label=\"step-down\"\n onClick={decrementValue}\n disabled={disabled}\n >\n <Icon render=\"caret\" color=\"sesame\" size={24} />\n </SpinnerButton>\n </Spinner>\n )}\n {trailingIcon && !step && (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color=\"sesame\"\n />\n )}\n </Box>\n </Field>\n )\n})\n\nconst Spinner = styled.div`\n position: relative;\n display: flex;\n right: 58px;\n margin-right: -58px;\n`\n\ninterface IButton {\n disabled: boolean\n}\n\nconst SpinnerButton = styled.button<IButton>`\n width: 24px;\n height: 24px;\n background-color: transparent;\n border: 0;\n padding: 0;\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};\n`\n"]}
1
+ {"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../src/NumberInput/NumberInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GACX,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC,OAAO,EACL,KAAK,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW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,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;wBAC/C,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC,EACD,MAAM,EAAE,MAAM,GACd,EAED,QAAQ,IAAI,IAAI,GAAG,CAAC,IAAI,CACvB,MAAC,OAAO,eACN,KAAC,aAAa,kBACD,SAAS,EACpB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,QAAQ,YAElB,KAAC,aAAa,aAAQ,EAAE,YACtB,KAAC,eAAe,IACd,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAC9B,GACY,GACF,EAEhB,KAAC,aAAa,kBACD,WAAW,EACtB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,QAAQ,YAElB,KAAC,aAAa,aAAQ,EAAE,YACtB,KAAC,eAAe,IACd,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAC9B,GACY,GACF,IACR,CACX,EACA,oBAAoB,IAAI,CAAC,IAAI,IAAI,oBAAoB,IAClD,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;CAKzB,CAAA;AAMD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAS;;;;;;YAMhC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;CACnE,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n MouseEvent,\n forwardRef,\n} from 'react'\nimport styled, { useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n InputLeadingIconContainer,\n InputTrailingIconContainer,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport {\n faChevronDown,\n faChevronUp,\n} from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\nexport interface Props extends CommonFieldProps {\n type?: 'number'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n step?: number\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string | number) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string | number) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type NumberInputProps = Props & InputProps\n\nexport const NumberInput = forwardRef(function NumberInput(\n {\n id: idProp,\n type = 'number',\n placeholder,\n name,\n value,\n onChange,\n onInputChange,\n onBlur,\n min = -999999,\n max = 999999,\n step = 0,\n disabled = false,\n error = false,\n frontIcon,\n frontIconComponent,\n trailingIconComponent,\n trailingIcon,\n fallbackStyle,\n ...fieldProps\n }: NumberInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n const theme = useTheme()\n // Check whether the min/max value exists is within the specified range\n const isInRange = (value: number) => {\n if (min && value < min) {\n return false\n }\n\n if (max && value > max) {\n return false\n }\n\n return true\n }\n\n // Round the number to two decimal places\n const roundNumber = (event: number) => {\n return Math.round(event * 100) / 100\n }\n\n const applyMinMax = (value: number) => {\n if (min && value < min) return min\n if (max && value > max) return max\n return value\n }\n\n const handleChange = (event: string) => {\n if (onChange === undefined) return\n const EMPTY_INPUT = ''\n\n if (event === EMPTY_INPUT) {\n onChange(event)\n } else {\n const amount = Number(event)\n const normalisedValue = applyMinMax(amount)\n\n onChange(normalisedValue)\n }\n }\n // Increment or decrement the value when clicking the Spinner controls\n const incrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) + step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const decrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) - step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const frontIconToRender = frontIconComponent ? (\n <InputLeadingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {frontIconComponent}\n </InputLeadingIconContainer>\n ) : frontIcon ? (\n <StyledFrontIcon $disabled={disabled} render={frontIcon} color=\"sesame\" />\n ) : null\n\n const trailingIconToRender = trailingIconComponent ? (\n <InputTrailingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {trailingIconComponent}\n </InputTrailingIconContainer>\n ) : trailingIcon ? (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color=\"sesame\"\n />\n ) : null\n\n return (\n <Field {...fieldProps} htmlFor={id} error={error}>\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIconToRender && frontIconToRender}\n <Input\n ref={ref}\n $error={error}\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n placeholder={placeholder}\n value={value}\n $frontIcon={Boolean(frontIconToRender)}\n step={step}\n $fallbackStyle={fallbackStyle}\n onWheel={(e) => e.currentTarget.blur()}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n onChange && handleChange(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n />\n\n {onChange && step > 0 && (\n <Spinner>\n <SpinnerButton\n aria-label=\"step-up\"\n onClick={incrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronDown}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n\n <SpinnerButton\n aria-label=\"step-down\"\n onClick={decrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronUp}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n </Spinner>\n )}\n {trailingIconToRender && !step && trailingIconToRender}\n </Box>\n </Field>\n )\n})\n\nconst Spinner = styled.div`\n position: relative;\n display: flex;\n right: 58px;\n margin-right: -58px;\n`\n\ninterface IButton {\n disabled: boolean\n}\n\nconst SpinnerButton = styled.button<IButton>`\n width: 24px;\n height: 24px;\n background-color: transparent;\n border: 0;\n padding: 0;\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};\n`\n"]}
@@ -2,9 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { Box } from '../Box';
5
- import { Icon } from '../Icon';
6
5
  import { Text } from '../Text';
7
6
  import { focusOutlineStyle } from '../utils/focusOutline';
7
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
+ import { IconContainer } from '../sharedStyles/shared.styles';
9
+ import { faArrowLeft, faArrowRight, } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
8
10
  const MAX_PAGES = 7;
9
11
  const MAX_ADDITIONAL_PAGES = Math.ceil(MAX_PAGES / 2);
10
12
  export const Pagination = ({ total, partition, handlePageChange, currentPage, ...marginProps }) => {
@@ -71,7 +73,7 @@ export const Pagination = ({ total, partition, handlePageChange, currentPage, ..
71
73
  if (e.key === 'Enter') {
72
74
  movePage(activePage - 1);
73
75
  }
74
- }, children: _jsx(Icon, { size: 18, render: "arrow" }) })), _jsx(PageBox, { "$active": activePage === 1, onClick: () => movePage(1), children: _jsx(Text, { typo: activePage === 1 ? 'headline-small' : 'body-regular', tag: "p", children: "1" }) }), showFirstDots && (_jsx(PageBox, { children: _jsx(Text, { tag: "p", children: "..." }) })), shownPages.map((i) => {
76
+ }, children: _jsx(IconContainer, { "$size": 16, children: _jsx(FontAwesomeIcon, { icon: faArrowLeft }) }) })), _jsx(PageBox, { "$active": activePage === 1, onClick: () => movePage(1), children: _jsx(Text, { typo: activePage === 1 ? 'headline-small' : 'body-regular', tag: "p", children: "1" }) }), showFirstDots && (_jsx(PageBox, { children: _jsx(Text, { tag: "p", children: "..." }) })), shownPages.map((i) => {
75
77
  return (_jsx(PageBox, { "$active": activePage === i, onClick: () => movePage(i), onKeyDown: (e) => {
76
78
  if (e.key === 'Enter') {
77
79
  movePage(i);
@@ -85,7 +87,7 @@ export const Pagination = ({ total, partition, handlePageChange, currentPage, ..
85
87
  if (e.key === 'Enter') {
86
88
  movePage(activePage + 1);
87
89
  }
88
- }, children: _jsx(Icon, { size: 18, render: "arrow", rotate: 180 }) }))] }));
90
+ }, children: _jsx(IconContainer, { "$size": 16, children: _jsx(FontAwesomeIcon, { icon: faArrowRight }) }) }))] }));
89
91
  };
90
92
  const Container = styled(Box) `
91
93
  align-items: center;
@@ -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;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAGzD,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,CA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E,EAAE,EAAE,MAAM,EAAC,OAAO,EAAC,MAAM,EAAE,GAAG,GAAI,GACtC,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 { Icon } from '../Icon'\nimport { Text } from '../Text'\n\nimport { focusOutlineStyle } from '../utils/focusOutline'\nimport { MarginProps } from '../utils/space'\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 <Icon size={18} render=\"arrow\" />\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 <Icon size={18} render=\"arrow\" rotate={180} />\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,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC3C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAA;IAChD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAW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C,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,14 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box } from '../../Box';
3
- import styled, { css } from 'styled-components';
3
+ import styled, { css, useTheme } from 'styled-components';
4
4
  import { theme as oldTheme } from '../../theme';
5
5
  import { Text } from '../../Text';
6
- import { Icon } from '../../Icon';
6
+ import { IconContainer } from '../../sharedStyles/shared.styles';
7
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
+ import { faCheck } from '@awesome.me/kit-46ca99185c/icons/classic/solid';
7
9
  export const StepItem = ({ label, isSimple = false, isCurrentStep, stepWidth, onClick, isCompleted = false, isLastCompleted = false, isLastItem = false, isDisabled, }) => {
10
+ const theme = useTheme();
8
11
  if (isSimple) {
9
12
  return (_jsx(SimpleItem, { "$completed": isCompleted, "$lastCompleted": isLastCompleted, width: stepWidth, height: "12px" }));
10
13
  }
11
- return (_jsxs(ProgressItem, { flex: true, alignItems: "flex-start", "$completed": isCompleted, "$lastCompleted": isLastCompleted, width: stepWidth, children: [_jsxs(ClickableArea, { flex: true, "data-testid": `step-item-${label}`, direction: "column", alignItems: "center", onClick: onClick, "$isDisabled": isDisabled, children: [_jsx(ProgressIndicator, { "$completed": isCompleted, "$currentStep": isCurrentStep, flex: true, alignItems: "center", justifyContent: "center", children: isCompleted && (_jsx(Icon, { render: "tick", size: 16, color: "color.surface.base.000" })) }), _jsx(StyledText, { typo: "caption", children: label })] }), isCompleted && !isLastItem && _jsx(CompletedBar, {})] }));
14
+ return (_jsxs(ProgressItem, { flex: true, alignItems: "flex-start", "$completed": isCompleted, "$lastCompleted": isLastCompleted, width: stepWidth, children: [_jsxs(ClickableArea, { flex: true, "data-testid": `step-item-${label}`, direction: "column", alignItems: "center", onClick: onClick, "$isDisabled": isDisabled, children: [_jsx(ProgressIndicator, { "$completed": isCompleted, "$currentStep": isCurrentStep, flex: true, alignItems: "center", justifyContent: "center", children: isCompleted && (_jsx(IconContainer, { "$size": 12, children: _jsx(FontAwesomeIcon, { icon: faCheck, color: theme.color.surface.base['000'] }) })) }), _jsx(StyledText, { typo: "caption", children: label })] }), isCompleted && !isLastItem && _jsx(CompletedBar, {})] }));
12
15
  };
13
16
  const lastCompleted = css `
14
17
  border-radius: 0 100px 100px 0;
@@ -1 +1 @@
1
- {"version":3,"file":"StepItem.js","sourceRoot":"","sources":["../../../src/ProgressIndicator/components/StepItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAajC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EACvB,KAAK,EACL,QAAQ,GAAG,KAAK,EAChB,aAAa,EACb,SAAS,EACT,OAAO,EACP,WAAW,GAAG,KAAK,EACnB,eAAe,GAAG,KAAK,EACvB,UAAU,GAAG,KAAK,EAClB,UAAU,GACI,EAAE,EAAE;IAClB,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CACL,KAAC,UAAU,kBACG,WAAW,oBACP,eAAe,EAC/B,KAAK,EAAE,SAAS,EAChB,MAAM,EAAC,MAAM,GACb,CACH,CAAA;IACH,CAAC;IAED,OAAO,CACL,MAAC,YAAY,IACX,IAAI,QACJ,UAAU,EAAC,YAAY,gBACX,WAAW,oBACP,eAAe,EAC/B,KAAK,EAAE,SAAS,aAEhB,MAAC,aAAa,IACZ,IAAI,uBACS,aAAa,KAAK,EAAE,EACjC,SAAS,EAAC,QAAQ,EAClB,UAAU,EAAC,QAAQ,EACnB,OAAO,EAAE,OAAO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pD,UAAU,IAAI,YAAY;IACxB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;CACzC,CAAA;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;iBAEd,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;;CAE3C,CAAA;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;;;gBAMhB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;;CAEhE,CAAA","sourcesContent":["import { Box } from '../../Box'\nimport { StepData } from 'ProgressIndicator/types'\nimport styled, { css } from 'styled-components'\nimport { theme as oldTheme } from '../../theme'\nimport { Text } from '../../Text'\nimport { Icon } from '../../Icon'\n\nexport interface StepItemProps extends Pick<StepData, 'label'> {\n isCompleted?: boolean\n isLastCompleted?: boolean\n isDisabled: boolean\n isCurrentStep: boolean\n isSimple?: boolean\n onClick: () => void\n stepWidth: string\n isLastItem: boolean\n}\n\nexport const StepItem = ({\n label,\n isSimple = false,\n isCurrentStep,\n stepWidth,\n onClick,\n isCompleted = false,\n isLastCompleted = false,\n isLastItem = false,\n isDisabled,\n}: StepItemProps) => {\n if (isSimple) {\n return (\n <SimpleItem\n $completed={isCompleted}\n $lastCompleted={isLastCompleted}\n width={stepWidth}\n height=\"12px\"\n />\n )\n }\n\n return (\n <ProgressItem\n flex\n alignItems=\"flex-start\"\n $completed={isCompleted}\n $lastCompleted={isLastCompleted}\n width={stepWidth}\n >\n <ClickableArea\n flex\n data-testid={`step-item-${label}`}\n direction=\"column\"\n alignItems=\"center\"\n onClick={onClick}\n $isDisabled={isDisabled}\n >\n <ProgressIndicator\n $completed={isCompleted}\n $currentStep={isCurrentStep}\n flex\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n {isCompleted && (\n <Icon render=\"tick\" size={16} color=\"color.surface.base.000\" />\n )}\n </ProgressIndicator>\n <StyledText typo=\"caption\">{label}</StyledText>\n </ClickableArea>\n {isCompleted && !isLastItem && <CompletedBar />}\n </ProgressItem>\n )\n}\n\ninterface StyledComponentProps {\n $completed?: boolean\n $lastCompleted?: boolean\n $currentStep?: boolean\n $isDisabled?: boolean\n $completedStep?: boolean\n}\n\nconst lastCompleted = css`\n border-radius: 0 100px 100px 0;\n\n &:first-child {\n border-radius: 100px;\n }\n`\n\nconst borderRadiusCss = css<StyledComponentProps>`\n &:first-child {\n border-radius: 100px 0 0 100px;\n }\n\n ${({ $lastCompleted }) => $lastCompleted && lastCompleted}\n`\n\nconst SimpleItem = styled(Box)<StyledComponentProps>`\n position: relative;\n z-index: 1;\n ${borderRadiusCss}\n\n background: ${({ $completed, theme }) =>\n $completed ? theme.color.feedback.positive[200] : 'none'};\n`\n\nconst ProgressItem = styled(Box)<StyledComponentProps>`\n position: relative;\n z-index: 1;\n top: 9px;\n left: -10px;\n\n &:last-child {\n width: auto;\n }\n`\nconst ClickableArea = styled(Box)<StyledComponentProps>`\n position: relative;\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'auto' : 'pointer')};\n`\n\nconst ProgressIndicator = styled(Box)<StyledComponentProps>`\n border-radius: 50%;\n height: 24px;\n width: 24px;\n position: relative;\n z-index: 1;\n background: ${({ $completed, $currentStep, theme }) =>\n $completed || $currentStep\n ? theme.color.feedback.positive[200]\n : theme.color.feedback.positive[100]};\n`\n\nconst StyledText = styled(Text)`\n margin-top: 2px;\n font-weight: ${oldTheme.font.weight.medium};\n white-space: nowrap;\n`\n\nconst CompletedBar = styled(Box)`\n position: absolute;\n height: 12px;\n width: 100%;\n top: 7px;\n left: 13px;\n background: ${({ theme }) => theme.color.feedback.positive[200]};\n z-index: 0;\n`\n"]}
1
+ {"version":3,"file":"StepItem.js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AAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;CACzC,CAAA;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;iBAEd,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;;CAE3C,CAAA;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;;;gBAMhB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;;CAEhE,CAAA","sourcesContent":["import { Box } from '../../Box'\nimport { StepData } from 'ProgressIndicator/types'\nimport styled, { css, useTheme } from 'styled-components'\nimport { theme as oldTheme } from '../../theme'\nimport { Text } from '../../Text'\nimport { IconContainer } from '../../sharedStyles/shared.styles'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faCheck } from '@awesome.me/kit-46ca99185c/icons/classic/solid'\n\nexport interface StepItemProps extends Pick<StepData, 'label'> {\n isCompleted?: boolean\n isLastCompleted?: boolean\n isDisabled: boolean\n isCurrentStep: boolean\n isSimple?: boolean\n onClick: () => void\n stepWidth: string\n isLastItem: boolean\n}\n\nexport const StepItem = ({\n label,\n isSimple = false,\n isCurrentStep,\n stepWidth,\n onClick,\n isCompleted = false,\n isLastCompleted = false,\n isLastItem = false,\n isDisabled,\n}: StepItemProps) => {\n const theme = useTheme()\n if (isSimple) {\n return (\n <SimpleItem\n $completed={isCompleted}\n $lastCompleted={isLastCompleted}\n width={stepWidth}\n height=\"12px\"\n />\n )\n }\n\n return (\n <ProgressItem\n flex\n alignItems=\"flex-start\"\n $completed={isCompleted}\n $lastCompleted={isLastCompleted}\n width={stepWidth}\n >\n <ClickableArea\n flex\n data-testid={`step-item-${label}`}\n direction=\"column\"\n alignItems=\"center\"\n onClick={onClick}\n $isDisabled={isDisabled}\n >\n <ProgressIndicator\n $completed={isCompleted}\n $currentStep={isCurrentStep}\n flex\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n {isCompleted && (\n <IconContainer $size={12}>\n <FontAwesomeIcon\n icon={faCheck}\n color={theme.color.surface.base['000']}\n />\n </IconContainer>\n )}\n </ProgressIndicator>\n <StyledText typo=\"caption\">{label}</StyledText>\n </ClickableArea>\n {isCompleted && !isLastItem && <CompletedBar />}\n </ProgressItem>\n )\n}\n\ninterface StyledComponentProps {\n $completed?: boolean\n $lastCompleted?: boolean\n $currentStep?: boolean\n $isDisabled?: boolean\n $completedStep?: boolean\n}\n\nconst lastCompleted = css`\n border-radius: 0 100px 100px 0;\n\n &:first-child {\n border-radius: 100px;\n }\n`\n\nconst borderRadiusCss = css<StyledComponentProps>`\n &:first-child {\n border-radius: 100px 0 0 100px;\n }\n\n ${({ $lastCompleted }) => $lastCompleted && lastCompleted}\n`\n\nconst SimpleItem = styled(Box)<StyledComponentProps>`\n position: relative;\n z-index: 1;\n ${borderRadiusCss}\n\n background: ${({ $completed, theme }) =>\n $completed ? theme.color.feedback.positive[200] : 'none'};\n`\n\nconst ProgressItem = styled(Box)<StyledComponentProps>`\n position: relative;\n z-index: 1;\n top: 9px;\n left: -10px;\n\n &:last-child {\n width: auto;\n }\n`\nconst ClickableArea = styled(Box)<StyledComponentProps>`\n position: relative;\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'auto' : 'pointer')};\n`\n\nconst ProgressIndicator = styled(Box)<StyledComponentProps>`\n border-radius: 50%;\n height: 24px;\n width: 24px;\n position: relative;\n z-index: 1;\n background: ${({ $completed, $currentStep, theme }) =>\n $completed || $currentStep\n ? theme.color.feedback.positive[200]\n : theme.color.feedback.positive[100]};\n`\n\nconst StyledText = styled(Text)`\n margin-top: 2px;\n font-weight: ${oldTheme.font.weight.medium};\n white-space: nowrap;\n`\n\nconst CompletedBar = styled(Box)`\n position: absolute;\n height: 12px;\n width: 100%;\n top: 7px;\n left: 13px;\n background: ${({ theme }) => theme.color.feedback.positive[200]};\n z-index: 0;\n`\n"]}
@@ -1,12 +1,13 @@
1
- import { FocusEvent, ReactElement, RefAttributes } from 'react';
1
+ import { FocusEvent, ReactElement, ReactNode, RefAttributes } from 'react';
2
2
  import { CommonFieldProps } from '../fields/commonFieldTypes';
3
- import { Icons } from '../Icon/iconsList';
4
3
  import { BaseValueType, DisplayType, IconPosition, ItemWidth, JustifyContent } from './types';
4
+ import { Icons } from '../Icon';
5
5
  export type RadioGroupProps<Value extends BaseValueType = BaseValueType> = {
6
6
  options: Array<{
7
7
  visual?: string;
8
8
  icon?: Icons;
9
9
  iconPosition?: IconPosition;
10
+ iconComponent?: ReactNode;
10
11
  label: string;
11
12
  value: Value;
12
13
  bodyCopy?: string;
@@ -23,7 +23,7 @@ const RadioGroupComponent = ({ options, onChange, onBlur, value, displayType = '
23
23
  optionRefs.current[index] = {
24
24
  current: radioOptionRef,
25
25
  };
26
- }, name: name, visual: option.visual, icon: option.icon, iconPosition: option.iconPosition, label: option.label, value: option.value, checked: isSelected,
26
+ }, name: name, visual: option.visual, icon: option.icon, iconComponent: option.iconComponent, iconPosition: option.iconPosition, label: option.label, value: option.value, checked: isSelected,
27
27
  // @ts-expect-error TODO: address this type inconsistency in another PR
28
28
  onChange: onChange, onBlur: onBlur, displayType: displayType, isError: error, fallbackStyle: fallbackStyle, bodyCopy: option.bodyCopy, disabled: option.disabled, itemWidth: itemWidth }, `${option.value}`));
29
29
  }) }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../src/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAIV,mBAAmB,EACnB,MAAM,GACP,MAAM,OAAO,CAAA;AAEd,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,o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B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG;4BAC1B,OAAO,EAAE,cAAc;yBACxB,CAAA;oBACH,CAAC,EAED,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,YAAY,EAAE,MAAM,CAAC,YAAY,EACjC,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,UAAU;oBACnB,uEAAuE;oBACvE,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,KAAK,EACd,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,SAAS,IAhBf,GAAG,MAAM,CAAC,KAAK,EAAE,CAiBtB,CACH,CAAA;YACH,CAAC,CAAC,GACY,GACP,CACZ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC,mBAAmB,CAIhC,CAAA;AAExB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAE/B;;SAEQ,QAAQ;qBACI,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,eAAe,IAAI,YAAY;;IAEzE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE;IACrB,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,mBAAmB;YACtB,OAAO;;;SAGN,CAAA;QACH,KAAK,iBAAiB;YACpB,OAAO;;;SAGN,CAAA;QACH;YACE,OAAO,yBAAyB,CAAA;IACpC,CAAC;AACH,CAAC;CACF,CAAA","sourcesContent":["import {\n FocusEvent,\n ForwardedRef,\n forwardRef,\n ReactElement,\n RefAttributes,\n RefObject,\n useImperativeHandle,\n useRef,\n} from 'react'\n\nimport styled from 'styled-components'\n\nimport { useUniqueId } from '../utils/id'\n\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { Fieldset } from '../fields/Fieldset'\nimport { Icons } from '../Icon/iconsList'\n\nimport { ITEM_GAP } from './constants'\nimport { RadioItem } from './RadioItem'\nimport {\n BaseValueType,\n DisplayType,\n IconPosition,\n ItemWidth,\n JustifyContent,\n} from './types'\nimport { TransientProps } from 'utils/utilTypes'\n\nexport type RadioGroupProps<Value extends BaseValueType = BaseValueType> = {\n options: Array<{\n visual?: string\n icon?: Icons\n iconPosition?: IconPosition\n label: string\n value: Value\n bodyCopy?: string\n disabled?: boolean\n }>\n justifyContent?: JustifyContent\n itemWidth?: ItemWidth\n onChange: (value: Value) => void\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n value: Value\n displayType?: DisplayType\n fallbackStyle?: boolean\n} & CommonFieldProps\n\nexport type RadioGroupElement = {\n focus: VoidFunction\n}\n\nconst RadioGroupComponent = <Value extends BaseValueType>(\n {\n options,\n onChange,\n onBlur,\n value,\n displayType = 'normal',\n renderAsTitle = false,\n error = false,\n fallbackStyle = false,\n justifyContent,\n itemWidth,\n ...fieldProps\n }: RadioGroupProps<Value>,\n ref: ForwardedRef<RadioGroupElement>,\n) => {\n const name = useUniqueId()\n\n const optionRefs = useRef<RefObject<HTMLInputElement | null>[]>([])\n useImperativeHandle(ref, () => {\n return {\n focus: () => {\n const selectedIndex = options.findIndex((item) => item.value === value)\n\n const elementToFocus = selectedIndex === -1 ? 0 : selectedIndex\n optionRefs.current[elementToFocus].current?.focus()\n },\n }\n })\n\n return (\n <Fieldset renderAsTitle={renderAsTitle} error={error} {...fieldProps}>\n <RadioItemList\n $displayType={displayType}\n $justifyContent={justifyContent}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value\n\n return (\n <RadioItem\n ref={(radioOptionRef) => {\n optionRefs.current[index] = {\n current: radioOptionRef,\n }\n }}\n key={`${option.value}`}\n name={name}\n visual={option.visual}\n icon={option.icon}\n iconPosition={option.iconPosition}\n label={option.label}\n value={option.value}\n checked={isSelected}\n // @ts-expect-error TODO: address this type inconsistency in another PR\n onChange={onChange}\n onBlur={onBlur}\n displayType={displayType}\n isError={error}\n fallbackStyle={fallbackStyle}\n bodyCopy={option.bodyCopy}\n disabled={option.disabled}\n itemWidth={itemWidth}\n />\n )\n })}\n </RadioItemList>\n </Fieldset>\n )\n}\n\nexport const RadioGroup = forwardRef(RadioGroupComponent) as <\n Value extends BaseValueType = BaseValueType,\n>(\n p: RadioGroupProps<Value> & RefAttributes<HTMLInputElement>,\n) => ReactElement | null\n\nconst RadioItemList = styled.div<\n TransientProps<Pick<RadioGroupProps, 'displayType' | 'justifyContent'>>\n>`\n display: flex;\n gap: ${ITEM_GAP}px;\n justify-content: ${({ $justifyContent }) => $justifyContent ?? 'flex-start'};\n\n ${({ $displayType }) => {\n switch ($displayType) {\n case 'horizontal-normal':\n return `\n flex-direction: row;\n align-items: center;\n `\n case 'horizontal-card':\n return `\n flex-direction: row;\n flex-wrap: wrap;\n `\n default:\n return 'flex-direction: column;'\n }\n }}\n`\n"]}
1
+ {"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../src/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAKV,mBAAmB,EACnB,MAAM,GACP,MAAM,OAAO,CAAA;AAEd,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAmCvC,MAAM,mBAAmB,GAAG,CAC1B,EACE,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,EACL,WAAW,GAAG,QAAQ,EACtB,aAAa,GAAG,KAAK,EACrB,KAAK,GAAG,KAAK,EACb,aAAa,G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AE,MAAM,CAAC,KAAK,EACnB,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,UAAU;oBACnB,uEAAuE;oBACvE,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,KAAK,EACd,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,SAAS,IAjBf,GAAG,MAAM,CAAC,KAAK,EAAE,CAkBtB,CACH,CAAA;YACH,CAAC,CAAC,GACY,GACP,CACZ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC,mBAAmB,CAIhC,CAAA;AAExB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAE/B;;SAEQ,QAAQ;qBACI,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,eAAe,IAAI,YAAY;;IAEzE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE;IACrB,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,mBAAmB;YACtB,OAAO;;;SAGN,CAAA;QACH,KAAK,iBAAiB;YACpB,OAAO;;;SAGN,CAAA;QACH;YACE,OAAO,yBAAyB,CAAA;IACpC,CAAC;AACH,CAAC;CACF,CAAA","sourcesContent":["import {\n FocusEvent,\n ForwardedRef,\n forwardRef,\n ReactElement,\n ReactNode,\n RefAttributes,\n RefObject,\n useImperativeHandle,\n useRef,\n} from 'react'\n\nimport styled from 'styled-components'\n\nimport { useUniqueId } from '../utils/id'\n\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { Fieldset } from '../fields/Fieldset'\n\nimport { ITEM_GAP } from './constants'\nimport { RadioItem } from './RadioItem'\nimport {\n BaseValueType,\n DisplayType,\n IconPosition,\n ItemWidth,\n JustifyContent,\n} from './types'\nimport { TransientProps } from 'utils/utilTypes'\nimport { Icons } from '../Icon'\n\nexport type RadioGroupProps<Value extends BaseValueType = BaseValueType> = {\n options: Array<{\n visual?: string\n icon?: Icons\n iconPosition?: IconPosition\n iconComponent?: ReactNode\n label: string\n value: Value\n bodyCopy?: string\n disabled?: boolean\n }>\n justifyContent?: JustifyContent\n itemWidth?: ItemWidth\n onChange: (value: Value) => void\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n value: Value\n displayType?: DisplayType\n fallbackStyle?: boolean\n} & CommonFieldProps\n\nexport type RadioGroupElement = {\n focus: VoidFunction\n}\n\nconst RadioGroupComponent = <Value extends BaseValueType>(\n {\n options,\n onChange,\n onBlur,\n value,\n displayType = 'normal',\n renderAsTitle = false,\n error = false,\n fallbackStyle = false,\n justifyContent,\n itemWidth,\n ...fieldProps\n }: RadioGroupProps<Value>,\n ref: ForwardedRef<RadioGroupElement>,\n) => {\n const name = useUniqueId()\n\n const optionRefs = useRef<RefObject<HTMLInputElement | null>[]>([])\n useImperativeHandle(ref, () => {\n return {\n focus: () => {\n const selectedIndex = options.findIndex((item) => item.value === value)\n\n const elementToFocus = selectedIndex === -1 ? 0 : selectedIndex\n optionRefs.current[elementToFocus].current?.focus()\n },\n }\n })\n\n return (\n <Fieldset renderAsTitle={renderAsTitle} error={error} {...fieldProps}>\n <RadioItemList\n $displayType={displayType}\n $justifyContent={justifyContent}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value\n\n return (\n <RadioItem\n ref={(radioOptionRef) => {\n optionRefs.current[index] = {\n current: radioOptionRef,\n }\n }}\n key={`${option.value}`}\n name={name}\n visual={option.visual}\n icon={option.icon}\n iconComponent={option.iconComponent}\n iconPosition={option.iconPosition}\n label={option.label}\n value={option.value}\n checked={isSelected}\n // @ts-expect-error TODO: address this type inconsistency in another PR\n onChange={onChange}\n onBlur={onBlur}\n displayType={displayType}\n isError={error}\n fallbackStyle={fallbackStyle}\n bodyCopy={option.bodyCopy}\n disabled={option.disabled}\n itemWidth={itemWidth}\n />\n )\n })}\n </RadioItemList>\n </Fieldset>\n )\n}\n\nexport const RadioGroup = forwardRef(RadioGroupComponent) as <\n Value extends BaseValueType = BaseValueType,\n>(\n p: RadioGroupProps<Value> & RefAttributes<HTMLInputElement>,\n) => ReactElement | null\n\nconst RadioItemList = styled.div<\n TransientProps<Pick<RadioGroupProps, 'displayType' | 'justifyContent'>>\n>`\n display: flex;\n gap: ${ITEM_GAP}px;\n justify-content: ${({ $justifyContent }) => $justifyContent ?? 'flex-start'};\n\n ${({ $displayType }) => {\n switch ($displayType) {\n case 'horizontal-normal':\n return `\n flex-direction: row;\n align-items: center;\n `\n case 'horizontal-card':\n return `\n flex-direction: row;\n flex-wrap: wrap;\n `\n default:\n return 'flex-direction: column;'\n }\n }}\n`\n"]}
@@ -1,10 +1,11 @@
1
- import { FocusEvent } from 'react';
2
- import { Icons } from '../Icon/iconsList';
1
+ import { FocusEvent, ReactNode } from 'react';
2
+ import { Icons } from '../Icon';
3
3
  import { BaseValueType, DisplayType, IconPosition, ItemWidth } from './types';
4
4
  type RadioItemProps = {
5
5
  name: string;
6
6
  visual?: string;
7
7
  icon?: Icons;
8
+ iconComponent?: ReactNode;
8
9
  iconPosition?: IconPosition;
9
10
  value: BaseValueType;
10
11
  label: string;
@@ -8,9 +8,14 @@ import { Icon } from '../Icon';
8
8
  import { Text } from '../Text';
9
9
  import { RadioElement } from './RadioElement';
10
10
  import { ITEM_GAP } from './constants';
11
- export const RadioItem = forwardRef(function RadioItem({ name, visual, icon, iconPosition = 'center', label, value, checked, onChange, onBlur, displayType, isError, fallbackStyle, bodyCopy, disabled, itemWidth, }, ref) {
11
+ import { IconContainer } from '../sharedStyles/shared.styles';
12
+ export const RadioItem = forwardRef(function RadioItem({ name, visual, icon, iconComponent, iconPosition = 'center', label, value, checked, onChange, onBlur, displayType, isError, fallbackStyle, bodyCopy, disabled, itemWidth, }, ref) {
12
13
  const id = useUniqueId();
13
- return (_jsxs(Wrapper, { htmlFor: id, checked: checked, "$displayType": displayType, "data-testid": value, "$isError": isError, "$fallbackStyle": fallbackStyle, "$disabled": disabled, "$itemWidth": itemWidth, children: [visual && !icon && (_jsx(VisualWrapper, { children: _jsx(Visual, { "$visualUrl": visual }) })), !visual && icon && (_jsx(IconWrapper, { "$iconPosition": iconPosition, children: _jsx(Icon, { render: icon, size: 24 }) })), _jsxs(Box, { flex: true, alignItems: "center", children: [_jsx(RadioElement, { ref: ref, name: name, id: id, value: value, checked: checked, onChange: onChange, onBlur: onBlur, isError: isError, mr: "8px", isDisabled: disabled }), _jsxs(Box, { children: [_jsx(RadioText, { "$isError": isError, children: label }), bodyCopy && (_jsx(Box, { children: _jsx(Text, { typo: "caption", children: bodyCopy }) }))] })] })] }));
14
+ const iconToRender = iconComponent ? (_jsx(IconContainer, { "$size": 24, style: {
15
+ display: 'flex',
16
+ justifyContent: iconPosition === 'center' ? 'center' : 'flex-start',
17
+ }, children: iconComponent })) : icon ? (_jsx(IconWrapper, { "$iconPosition": iconPosition, children: _jsx(Icon, { render: icon, size: 24 }) })) : null;
18
+ return (_jsxs(Wrapper, { htmlFor: id, checked: checked, "$displayType": displayType, "data-testid": value, "$isError": isError, "$fallbackStyle": fallbackStyle, "$disabled": disabled, "$itemWidth": itemWidth, children: [visual && !icon && (_jsx(VisualWrapper, { children: _jsx(Visual, { "$visualUrl": visual }) })), !visual && iconToRender, _jsxs(Box, { flex: true, alignItems: "center", children: [_jsx(RadioElement, { ref: ref, name: name, id: id, value: value, checked: checked, onChange: onChange, onBlur: onBlur, isError: isError, mr: "8px", isDisabled: disabled }), _jsxs(Box, { children: [_jsx(RadioText, { "$isError": isError, children: label }), bodyCopy && (_jsx(Box, { children: _jsx(Text, { typo: "caption", children: bodyCopy }) }))] })] })] }));
14
19
  });
15
20
  const VisualWrapper = styled.div `
16
21
  width: 100%;
@@ -1 +1 @@
1
- {"version":3,"file":"RadioItem.js","sourceRoot":"","sources":["../../src/RadioGroup/RadioItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAc,UA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AAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;;CAExE,CAAA","sourcesContent":["import { FocusEvent, forwardRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { useUniqueId } from '../utils/id'\nimport { theme as oldTheme } from '../theme'\n\nimport { TransientProps } from 'utils/utilTypes'\nimport { Box } from '../Box'\nimport { Icon } from '../Icon'\nimport { Icons } from '../Icon/iconsList'\n\nimport { Text } from '../Text'\nimport { RadioElement } from './RadioElement'\nimport { ITEM_GAP } from './constants'\nimport { BaseValueType, DisplayType, IconPosition, ItemWidth } from './types'\n\ntype RadioItemProps = {\n name: string\n visual?: string\n icon?: Icons\n iconPosition?: IconPosition\n value: BaseValueType\n label: string\n checked: boolean\n onChange: (value: BaseValueType) => void\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n displayType: DisplayType\n isError: boolean\n fallbackStyle?: boolean\n bodyCopy?: string\n disabled?: boolean\n itemWidth?: ItemWidth\n}\n\nexport const RadioItem = forwardRef<HTMLInputElement, RadioItemProps>(\n function RadioItem(\n {\n name,\n visual,\n icon,\n iconPosition = 'center',\n label,\n value,\n checked,\n onChange,\n onBlur,\n displayType,\n isError,\n fallbackStyle,\n bodyCopy,\n disabled,\n itemWidth,\n },\n ref,\n ) {\n const id = useUniqueId()\n\n return (\n <Wrapper\n htmlFor={id}\n checked={checked}\n $displayType={displayType}\n data-testid={value}\n $isError={isError}\n $fallbackStyle={fallbackStyle}\n $disabled={disabled}\n $itemWidth={itemWidth}\n >\n {visual && !icon && (\n <VisualWrapper>\n <Visual $visualUrl={visual} />\n </VisualWrapper>\n )}\n {!visual && icon && (\n <IconWrapper $iconPosition={iconPosition}>\n <Icon render={icon} size={24} />\n </IconWrapper>\n )}\n <Box flex alignItems=\"center\">\n <RadioElement\n ref={ref}\n name={name}\n id={id}\n value={value}\n checked={checked}\n onChange={onChange}\n onBlur={onBlur}\n isError={isError}\n mr=\"8px\"\n isDisabled={disabled}\n />\n <Box>\n <RadioText $isError={isError}>{label}</RadioText>\n {bodyCopy && (\n <Box>\n <Text typo=\"caption\">{bodyCopy}</Text>\n </Box>\n )}\n </Box>\n </Box>\n </Wrapper>\n )\n },\n)\n\nconst VisualWrapper = styled.div`\n width: 100%;\n max-width: 120px;\n margin: 0 auto 8px;\n`\n\nconst IconWrapper = styled.div<{ $iconPosition?: IconPosition }>`\n display: flex;\n padding-bottom: 12px;\n\n ${({ $iconPosition }) =>\n $iconPosition === 'center' &&\n css`\n justify-content: center;\n `}\n\n ${({ $iconPosition }) =>\n $iconPosition === 'start' &&\n css`\n justify-content: flex-start;\n `}\n`\n\nconst Visual = styled.div<{ $visualUrl: string }>`\n width: 100%;\n padding-top: 100%;\n background-image: url('${(p) => p.$visualUrl}');\n background-size: contain;\n background-repeat: no-repeat;\n background-position: center;\n`\n\nconst Wrapper = styled.label<\n TransientProps<\n Pick<RadioItemProps, 'displayType' | 'isError' | 'fallbackStyle'>\n > & { checked: boolean; $disabled?: boolean; $itemWidth?: ItemWidth }\n>`\n display: flex;\n flex-direction: column;\n cursor: ${({ $disabled }) => ($disabled ? 'default' : 'pointer')};\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n ${({\n $displayType,\n checked,\n $isError,\n $fallbackStyle,\n $disabled,\n $itemWidth,\n theme,\n }) => css`\n ${($displayType === 'horizontal-card' ||\n $displayType === 'vertical-card') &&\n css`\n border-radius: 12px;\n background-color: ${$fallbackStyle\n ? theme.color.surface.base['000']\n : theme.color.surface.base[300]};\n padding: ${checked ? '10px' : '12px'};\n border: ${checked &&\n ($isError\n ? `2px solid ${theme.color.feedback.negative[200]}`\n : `2px solid ${theme.color.border.contrast}`)};\n\n &:hover {\n ${!$disabled &&\n css`\n background-color: ${$fallbackStyle\n ? theme.color.surface.base[100]\n : theme.color.surface.base[400]};\n `}\n }\n `}\n ${$displayType === 'horizontal-card' &&\n css`\n justify-content: center;\n ${!$itemWidth &&\n css`\n @media (min-width: 420px) {\n width: calc(50% - ${ITEM_GAP / 2}px);\n }\n\n @media (min-width: 768px) {\n width: 201px;\n }\n `}\n `}\n width: ${$itemWidth ?? '100%'};\n `}\n`\n\nconst RadioText = styled.span<{ $isError: boolean }>`\n line-height: 16px;\n font-size: 16px;\n font-weight: ${oldTheme.font.weight.medium};\n color: ${({ $isError, theme }) =>\n $isError ? theme.color.feedback.negative[200] : theme.color.text.base};\n margin-top: 4px;\n`\n"]}
1
+ {"version":3,"file":"RadioItem.js","sourceRoot":"","sources":["../../src/RadioGroup/RadioItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAc,UAAU,EAAa,MAAM,OAAO,CAAA;AACzD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAG5C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAS,MAAM,SAAS,CAAA;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAqB7D,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CACjC,SAAS,SAAS,CAChB,EACE,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,aAAa,EACb,YAAY,GAAG,QAAQ,EACvB,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,EACD,GAAG;IAEH,MAAM,EAAE,GAAG,WAAW,EAAE,CAAA;IAExB,MAAM,YAAY,GAAG,aAA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CAAC,GAAG,CAAC,EAAE;YACnD,CAAC,CAAC,aAAa,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;;;UAG3C,CAAC,SAAS;QACZ,GAAG,CAAA;8BACmB,cAAc;YAChC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YAC/B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;SAClC;;KAEJ;MACC,YAAY,KAAK,iBAAiB;IACpC,GAAG,CAAA;;QAEC,CAAC,UAAU;QACb,GAAG,CAAA;;8BAEqB,QAAQ,GAAG,CAAC;;;;;;OAMnC;KACF;WACM,UAAU,IAAI,MAAM;GAC5B;CACF,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAuB;;;iBAGnC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;WACjC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAC/B,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;;CAExE,CAAA","sourcesContent":["import { FocusEvent, forwardRef, ReactNode } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { useUniqueId } from '../utils/id'\nimport { theme as oldTheme } from '../theme'\n\nimport { TransientProps } from 'utils/utilTypes'\nimport { Box } from '../Box'\nimport { Icon, Icons } from '../Icon'\n\nimport { Text } from '../Text'\nimport { RadioElement } from './RadioElement'\nimport { ITEM_GAP } from './constants'\nimport { BaseValueType, DisplayType, IconPosition, ItemWidth } from './types'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\ntype RadioItemProps = {\n name: string\n visual?: string\n icon?: Icons\n iconComponent?: ReactNode\n iconPosition?: IconPosition\n value: BaseValueType\n label: string\n checked: boolean\n onChange: (value: BaseValueType) => void\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n displayType: DisplayType\n isError: boolean\n fallbackStyle?: boolean\n bodyCopy?: string\n disabled?: boolean\n itemWidth?: ItemWidth\n}\n\nexport const RadioItem = forwardRef<HTMLInputElement, RadioItemProps>(\n function RadioItem(\n {\n name,\n visual,\n icon,\n iconComponent,\n iconPosition = 'center',\n label,\n value,\n checked,\n onChange,\n onBlur,\n displayType,\n isError,\n fallbackStyle,\n bodyCopy,\n disabled,\n itemWidth,\n },\n ref,\n ) {\n const id = useUniqueId()\n\n const iconToRender = iconComponent ? (\n <IconContainer\n $size={24}\n style={{\n display: 'flex',\n justifyContent: iconPosition === 'center' ? 'center' : 'flex-start',\n }}\n >\n {iconComponent}\n </IconContainer>\n ) : icon ? (\n <IconWrapper $iconPosition={iconPosition}>\n <Icon render={icon} size={24} />\n </IconWrapper>\n ) : null\n\n return (\n <Wrapper\n htmlFor={id}\n checked={checked}\n $displayType={displayType}\n data-testid={value}\n $isError={isError}\n $fallbackStyle={fallbackStyle}\n $disabled={disabled}\n $itemWidth={itemWidth}\n >\n {visual && !icon && (\n <VisualWrapper>\n <Visual $visualUrl={visual} />\n </VisualWrapper>\n )}\n {!visual && iconToRender}\n <Box flex alignItems=\"center\">\n <RadioElement\n ref={ref}\n name={name}\n id={id}\n value={value}\n checked={checked}\n onChange={onChange}\n onBlur={onBlur}\n isError={isError}\n mr=\"8px\"\n isDisabled={disabled}\n />\n <Box>\n <RadioText $isError={isError}>{label}</RadioText>\n {bodyCopy && (\n <Box>\n <Text typo=\"caption\">{bodyCopy}</Text>\n </Box>\n )}\n </Box>\n </Box>\n </Wrapper>\n )\n },\n)\n\nconst VisualWrapper = styled.div`\n width: 100%;\n max-width: 120px;\n margin: 0 auto 8px;\n`\n\nconst IconWrapper = styled.div<{ $iconPosition?: IconPosition }>`\n display: flex;\n padding-bottom: 12px;\n\n ${({ $iconPosition }) =>\n $iconPosition === 'center' &&\n css`\n justify-content: center;\n `}\n\n ${({ $iconPosition }) =>\n $iconPosition === 'start' &&\n css`\n justify-content: flex-start;\n `}\n`\n\nconst Visual = styled.div<{ $visualUrl: string }>`\n width: 100%;\n padding-top: 100%;\n background-image: url('${(p) => p.$visualUrl}');\n background-size: contain;\n background-repeat: no-repeat;\n background-position: center;\n`\n\nconst Wrapper = styled.label<\n TransientProps<\n Pick<RadioItemProps, 'displayType' | 'isError' | 'fallbackStyle'>\n > & { checked: boolean; $disabled?: boolean; $itemWidth?: ItemWidth }\n>`\n display: flex;\n flex-direction: column;\n cursor: ${({ $disabled }) => ($disabled ? 'default' : 'pointer')};\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n ${({\n $displayType,\n checked,\n $isError,\n $fallbackStyle,\n $disabled,\n $itemWidth,\n theme,\n }) => css`\n ${($displayType === 'horizontal-card' ||\n $displayType === 'vertical-card') &&\n css`\n border-radius: 12px;\n background-color: ${$fallbackStyle\n ? theme.color.surface.base['000']\n : theme.color.surface.base[300]};\n padding: ${checked ? '10px' : '12px'};\n border: ${checked &&\n ($isError\n ? `2px solid ${theme.color.feedback.negative[200]}`\n : `2px solid ${theme.color.border.contrast}`)};\n\n &:hover {\n ${!$disabled &&\n css`\n background-color: ${$fallbackStyle\n ? theme.color.surface.base[100]\n : theme.color.surface.base[400]};\n `}\n }\n `}\n ${$displayType === 'horizontal-card' &&\n css`\n justify-content: center;\n ${!$itemWidth &&\n css`\n @media (min-width: 420px) {\n width: calc(50% - ${ITEM_GAP / 2}px);\n }\n\n @media (min-width: 768px) {\n width: 201px;\n }\n `}\n `}\n width: ${$itemWidth ?? '100%'};\n `}\n`\n\nconst RadioText = styled.span<{ $isError: boolean }>`\n line-height: 16px;\n font-size: 16px;\n font-weight: ${oldTheme.font.weight.medium};\n color: ${({ $isError, theme }) =>\n $isError ? theme.color.feedback.negative[200] : theme.color.text.base};\n margin-top: 4px;\n`\n"]}
@@ -3,11 +3,13 @@ import domPurify from 'dompurify';
3
3
  import { forwardRef } from 'react';
4
4
  import styled from 'styled-components';
5
5
  import { Box } from '../Box';
6
- import { Icon } from '../Icon';
6
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
7
+ import { faWarning } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
8
+ import { IconContainer } from '../sharedStyles/shared.styles';
7
9
  export const RichText = forwardRef(function RichText({ htmlString, ...props }, ref) {
8
10
  const sanitisedHtml = domPurify.sanitize(htmlString);
9
11
  if (!domPurify.isSupported) {
10
- return (_jsxs(Box, { ...props, children: [_jsxs(WarningText, { children: [_jsx(Icon, { render: "warning" }), "Your browser is not supported, please upgrade to a newer version"] }), htmlString] }));
12
+ return (_jsxs(Box, { ...props, children: [_jsxs(WarningText, { children: [_jsx(IconContainer, { "$size": 24, children: _jsx(FontAwesomeIcon, { icon: faWarning }) }), "Your browser is not supported, please upgrade to a newer version"] }), htmlString] }));
11
13
  }
12
14
  else {
13
15
  return (_jsx(HtmlBox, { ref: ref, ...props, dangerouslySetInnerHTML: { __html: sanitisedHtml } }));
@@ -1 +1 @@
1
- {"version":3,"file":"RichText.js","sourceRoot":"","sources":["../../src/RichText/RichText.tsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAgB,UAAU,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAO9B,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,QAAQ,CAClD,EAAE,UAAU,EAAE,GAAG,KAAK,EAAiB,EACvC,GAAiC;IAEjC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;IAEpD,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;QAC3B,OAAO,CACL,MAAC,GAAG,OAAK,KAAK,aACZ,MAAC,WAAW,eACV,KAAC,IAAI,IAAC,MAAM,EAAC,SAAS,GAAG,wEAEb,EACb,UAAU,IACP,CACP,CAAA;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CACL,KAAC,OAAO,IACN,GAAG,EAAE,GAAG,KACJ,KAAK,EACT,uBAAuB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,GAClD,CACH,CAAA;IACH,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;sBACT,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;;;;;;;;CAQtE,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;CAI1B,CAAA","sourcesContent":["import domPurify from 'dompurify'\nimport { ForwardedRef, forwardRef } from 'react'\nimport styled from 'styled-components'\nimport { Box } from '../Box'\nimport { Icon } from '../Icon'\nimport { MarginProps } from '../utils/space'\n\nexport interface RichTextProps extends MarginProps {\n htmlString: string\n}\n\nexport const RichText = forwardRef(function RichText(\n { htmlString, ...props }: RichTextProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const sanitisedHtml = domPurify.sanitize(htmlString)\n\n if (!domPurify.isSupported) {\n return (\n <Box {...props}>\n <WarningText>\n <Icon render=\"warning\" />\n Your browser is not supported, please upgrade to a newer version\n </WarningText>\n {htmlString}\n </Box>\n )\n } else {\n return (\n <HtmlBox\n ref={ref}\n {...props}\n dangerouslySetInnerHTML={{ __html: sanitisedHtml }}\n />\n )\n }\n})\n\nconst WarningText = styled(Box)`\n background-color: ${({ theme }) => theme.color.feedback.negative[200]};\n padding: 16px;\n border-radius: 16px;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 16px;\n margin-bottom: 16px;\n`\n\nconst HtmlBox = styled(Box)`\n * {\n all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MAAM,CAAC,GAAG,CAAC,CAAA;;;;CAI1B,CAAA","sourcesContent":["import domPurify from 'dompurify'\nimport { ForwardedRef, forwardRef } from 'react'\nimport styled from 'styled-components'\nimport { Box } from '../Box'\nimport { MarginProps } from '../utils/space'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faWarning } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\nexport interface RichTextProps extends MarginProps {\n htmlString: string\n}\n\nexport const RichText = forwardRef(function RichText(\n { htmlString, ...props }: RichTextProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const sanitisedHtml = domPurify.sanitize(htmlString)\n\n if (!domPurify.isSupported) {\n return (\n <Box {...props}>\n <WarningText>\n <IconContainer $size={24}>\n <FontAwesomeIcon icon={faWarning} />\n </IconContainer>\n Your browser is not supported, please upgrade to a newer version\n </WarningText>\n {htmlString}\n </Box>\n )\n } else {\n return (\n <HtmlBox\n ref={ref}\n {...props}\n dangerouslySetInnerHTML={{ __html: sanitisedHtml }}\n />\n )\n }\n})\n\nconst WarningText = styled(Box)`\n background-color: ${({ theme }) => theme.color.feedback.negative[200]};\n padding: 16px;\n border-radius: 16px;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 16px;\n margin-bottom: 16px;\n`\n\nconst HtmlBox = styled(Box)`\n * {\n all: revert;\n }\n`\n"]}
@@ -9,7 +9,9 @@ import { $getSelection, $isRangeSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, F
9
9
  import { useCallback, useEffect, useRef, useState } from 'react';
10
10
  import styled from 'styled-components';
11
11
  import { Box } from '../../Box';
12
- import { Icon } from '../../Icon';
12
+ import { IconContainer } from '../../sharedStyles/shared.styles';
13
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
14
+ import { faArrowUpRightFromSquare, faLinkSimple, faList, } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
13
15
  const LowPriority = 1;
14
16
  function getSelectedNode(selection) {
15
17
  const anchor = selection.anchor;
@@ -120,11 +122,11 @@ export default function ToolbarPlugin() {
120
122
  editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
121
123
  }, "$active": isBold, children: "B" }), _jsx(Italic, { onClick: () => {
122
124
  editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic');
123
- }, "$active": isItalic, children: "i" }), _jsx(EditorButton, { "$active": blockType === 'ul', onClick: () => formatBulletList(), children: _jsx(Icon, { render: "bullets" }) }), _jsxs(Link, { "$active": isLink, onClick: () => !isLink
125
+ }, "$active": isItalic, children: "i" }), _jsx(EditorButton, { "$active": blockType === 'ul', onClick: () => formatBulletList(), children: _jsx(IconContainer, { "$size": 24, children: _jsx(FontAwesomeIcon, { icon: faList }) }) }), _jsxs(Link, { "$active": isLink, onClick: () => !isLink
124
126
  ? editor.dispatchCommand(TOGGLE_LINK_COMMAND, 'https://')
125
- : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null), children: [_jsx(Box, { ml: { custom: '-4px' }, children: _jsx(Icon, { render: "link" }) }), _jsx(LinkInput, { tabIndex: -1, ref: urlInputRef, placeholder: "Enter url", value: linkURL, onChange: (e) => {
127
+ : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null), children: [_jsx(Box, { ml: { custom: '-4px' }, mt: { custom: '6px' }, children: _jsx(IconContainer, { "$size": 24, children: _jsx(FontAwesomeIcon, { icon: faLinkSimple }) }) }), _jsx(LinkInput, { tabIndex: -1, ref: urlInputRef, placeholder: "Enter url", value: linkURL, onChange: (e) => {
126
128
  editor.dispatchCommand(TOGGLE_LINK_COMMAND, e.target.value);
127
- }, onClick: (e) => e.stopPropagation() }), _jsx(Box, { onClick: openNewWindow, children: _jsx(LinkOpen, { render: "new-window" }) })] })] }));
129
+ }, onClick: (e) => e.stopPropagation() }), _jsx(Box, { onClick: openNewWindow, children: _jsx(LinkOpen, { "$size": 24, children: _jsx(FontAwesomeIcon, { icon: faArrowUpRightFromSquare }) }) })] })] }));
128
130
  }
129
131
  const EditorButton = styled(Box) `
130
132
  height: 40px;
@@ -176,7 +178,7 @@ const Link = styled(EditorButton) `
176
178
  }
177
179
  `}
178
180
  `;
179
- const LinkOpen = styled(Icon) `
181
+ const LinkOpen = styled(IconContainer) `
180
182
  background-color: ${({ theme }) => theme.color.interactive.tertiary.base};
181
183
  height: 32px;
182
184
  width: 32px;