@redsift/popovers 8.0.0 → 8.0.1

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 (185) hide show
  1. package/coverage/clover.xml +738 -0
  2. package/coverage/coverage-final.json +53 -0
  3. package/coverage/lcov-report/Tooltip.tsx.html +235 -0
  4. package/coverage/lcov-report/TooltipContent.tsx.html +235 -0
  5. package/coverage/lcov-report/TooltipTrigger.tsx.html +241 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/block-navigation.js +87 -0
  8. package/coverage/lcov-report/context.ts.html +97 -0
  9. package/coverage/lcov-report/dialog/Dialog.tsx.html +271 -0
  10. package/coverage/lcov-report/dialog/context.ts.html +97 -0
  11. package/coverage/lcov-report/dialog/index.html +191 -0
  12. package/coverage/lcov-report/dialog/index.ts.html +100 -0
  13. package/coverage/lcov-report/dialog/types.ts.html +253 -0
  14. package/coverage/lcov-report/dialog/useDialog.tsx.html +346 -0
  15. package/coverage/lcov-report/dialog/useDialogContext.tsx.html +121 -0
  16. package/coverage/lcov-report/dialog-content/DialogContent.tsx.html +487 -0
  17. package/coverage/lcov-report/dialog-content/index.html +146 -0
  18. package/coverage/lcov-report/dialog-content/index.ts.html +91 -0
  19. package/coverage/lcov-report/dialog-content/intl/index.html +116 -0
  20. package/coverage/lcov-report/dialog-content/intl/index.ts.html +106 -0
  21. package/coverage/lcov-report/dialog-content/styles.ts.html +301 -0
  22. package/coverage/lcov-report/dialog-content-actions/DialogContentActions.tsx.html +205 -0
  23. package/coverage/lcov-report/dialog-content-actions/index.html +146 -0
  24. package/coverage/lcov-report/dialog-content-actions/index.ts.html +91 -0
  25. package/coverage/lcov-report/dialog-content-actions/styles.ts.html +139 -0
  26. package/coverage/lcov-report/dialog-content-body/DialogContentBody.tsx.html +232 -0
  27. package/coverage/lcov-report/dialog-content-body/index.html +146 -0
  28. package/coverage/lcov-report/dialog-content-body/index.ts.html +91 -0
  29. package/coverage/lcov-report/dialog-content-body/styles.ts.html +259 -0
  30. package/coverage/lcov-report/dialog-content-header/DialogContentHeader.tsx.html +328 -0
  31. package/coverage/lcov-report/dialog-content-header/index.html +146 -0
  32. package/coverage/lcov-report/dialog-content-header/index.ts.html +91 -0
  33. package/coverage/lcov-report/dialog-content-header/styles.ts.html +193 -0
  34. package/coverage/lcov-report/dialog-trigger/DialogTrigger.tsx.html +214 -0
  35. package/coverage/lcov-report/dialog-trigger/index.html +131 -0
  36. package/coverage/lcov-report/dialog-trigger/index.ts.html +91 -0
  37. package/coverage/lcov-report/favicon.png +0 -0
  38. package/coverage/lcov-report/index.html +341 -0
  39. package/coverage/lcov-report/index.ts.html +97 -0
  40. package/coverage/lcov-report/popover/Popover.tsx.html +244 -0
  41. package/coverage/lcov-report/popover/context.ts.html +97 -0
  42. package/coverage/lcov-report/popover/index.html +191 -0
  43. package/coverage/lcov-report/popover/index.ts.html +100 -0
  44. package/coverage/lcov-report/popover/types.ts.html +244 -0
  45. package/coverage/lcov-report/popover/usePopover.tsx.html +295 -0
  46. package/coverage/lcov-report/popover/usePopoverContext.tsx.html +121 -0
  47. package/coverage/lcov-report/popover-content/PopoverContent.tsx.html +268 -0
  48. package/coverage/lcov-report/popover-content/index.html +146 -0
  49. package/coverage/lcov-report/popover-content/index.ts.html +91 -0
  50. package/coverage/lcov-report/popover-content/styles.ts.html +166 -0
  51. package/coverage/lcov-report/popover-trigger/PopoverTrigger.tsx.html +214 -0
  52. package/coverage/lcov-report/popover-trigger/index.html +131 -0
  53. package/coverage/lcov-report/popover-trigger/index.ts.html +91 -0
  54. package/coverage/lcov-report/prettify.css +1 -0
  55. package/coverage/lcov-report/prettify.js +2 -0
  56. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  57. package/coverage/lcov-report/sorter.js +196 -0
  58. package/coverage/lcov-report/styles.ts.html +391 -0
  59. package/coverage/lcov-report/toast/Toast.tsx.html +451 -0
  60. package/coverage/lcov-report/toast/index.html +161 -0
  61. package/coverage/lcov-report/toast/index.ts.html +91 -0
  62. package/coverage/lcov-report/toast/intl/index.html +116 -0
  63. package/coverage/lcov-report/toast/intl/index.ts.html +106 -0
  64. package/coverage/lcov-report/toast/styles.ts.html +214 -0
  65. package/coverage/lcov-report/toast/types.ts.html +217 -0
  66. package/coverage/lcov-report/toast-container/ToastContainer.tsx.html +217 -0
  67. package/coverage/lcov-report/toast-container/index.html +161 -0
  68. package/coverage/lcov-report/toast-container/index.ts.html +94 -0
  69. package/coverage/lcov-report/toast-container/styles.ts.html +2323 -0
  70. package/coverage/lcov-report/toast-container/useToast.tsx.html +469 -0
  71. package/coverage/lcov-report/toast-provider/ToastProvider.tsx.html +256 -0
  72. package/coverage/lcov-report/toast-provider/context.ts.html +106 -0
  73. package/coverage/lcov-report/toast-provider/index.html +161 -0
  74. package/coverage/lcov-report/toast-provider/index.ts.html +97 -0
  75. package/coverage/lcov-report/toast-provider/useToast.tsx.html +109 -0
  76. package/coverage/lcov-report/tooltip/Tooltip.tsx.html +250 -0
  77. package/coverage/lcov-report/tooltip/context.ts.html +97 -0
  78. package/coverage/lcov-report/tooltip/index.html +191 -0
  79. package/coverage/lcov-report/tooltip/index.ts.html +100 -0
  80. package/coverage/lcov-report/tooltip/types.ts.html +250 -0
  81. package/coverage/lcov-report/tooltip/useTooltip.tsx.html +352 -0
  82. package/coverage/lcov-report/tooltip/useTooltipContext.tsx.html +121 -0
  83. package/coverage/lcov-report/tooltip-content/TooltipContent.tsx.html +313 -0
  84. package/coverage/lcov-report/tooltip-content/index.html +146 -0
  85. package/coverage/lcov-report/tooltip-content/index.ts.html +91 -0
  86. package/coverage/lcov-report/tooltip-content/styles.ts.html +337 -0
  87. package/coverage/lcov-report/tooltip-trigger/TooltipTrigger.tsx.html +211 -0
  88. package/coverage/lcov-report/tooltip-trigger/index.html +131 -0
  89. package/coverage/lcov-report/tooltip-trigger/index.ts.html +91 -0
  90. package/coverage/lcov-report/types.ts.html +226 -0
  91. package/coverage/lcov-report/useTooltip.tsx.html +277 -0
  92. package/coverage/lcov-report/useTooltipContext.tsx.html +121 -0
  93. package/coverage/lcov-report/useTooltipOpen.tsx.html +559 -0
  94. package/coverage/lcov.info +1330 -0
  95. package/dist/package.json +96 -0
  96. package/index.ts +1 -0
  97. package/jest.config.js +3 -0
  98. package/package.json +2 -3
  99. package/rollup.config.js +13 -0
  100. package/src/components/dialog/Dialog.stories.tsx +201 -0
  101. package/src/components/dialog/Dialog.test.tsx +116 -0
  102. package/src/components/dialog/Dialog.tsx +62 -0
  103. package/src/components/dialog/context.ts +4 -0
  104. package/src/components/dialog/index.ts +5 -0
  105. package/src/components/dialog/types.ts +56 -0
  106. package/src/components/dialog/useDialog.tsx +87 -0
  107. package/src/components/dialog/useDialogContext.tsx +12 -0
  108. package/src/components/dialog-content/DialogContent.stories.tsx +337 -0
  109. package/src/components/dialog-content/DialogContent.tsx +134 -0
  110. package/src/components/dialog-content/index.ts +2 -0
  111. package/src/components/dialog-content/intl/en-US.json +3 -0
  112. package/src/components/dialog-content/intl/fr-FR.json +3 -0
  113. package/src/components/dialog-content/intl/index.ts +7 -0
  114. package/src/components/dialog-content/styles.ts +72 -0
  115. package/src/components/dialog-content/types.ts +11 -0
  116. package/src/components/dialog-content-actions/DialogContentActions.test.tsx +68 -0
  117. package/src/components/dialog-content-actions/DialogContentActions.tsx +40 -0
  118. package/src/components/dialog-content-actions/index.ts +2 -0
  119. package/src/components/dialog-content-actions/styles.ts +18 -0
  120. package/src/components/dialog-content-actions/types.ts +11 -0
  121. package/src/components/dialog-content-body/DialogContentBody.test.tsx +63 -0
  122. package/src/components/dialog-content-body/DialogContentBody.tsx +49 -0
  123. package/src/components/dialog-content-body/index.ts +2 -0
  124. package/src/components/dialog-content-body/styles.ts +58 -0
  125. package/src/components/dialog-content-body/types.ts +14 -0
  126. package/src/components/dialog-content-header/DialogContentHeader.test.tsx +63 -0
  127. package/src/components/dialog-content-header/DialogContentHeader.tsx +81 -0
  128. package/src/components/dialog-content-header/index.ts +2 -0
  129. package/src/components/dialog-content-header/styles.ts +36 -0
  130. package/src/components/dialog-content-header/types.ts +23 -0
  131. package/src/components/dialog-trigger/DialogTrigger.tsx +43 -0
  132. package/src/components/dialog-trigger/index.ts +2 -0
  133. package/src/components/dialog-trigger/types.ts +9 -0
  134. package/src/components/popover/Popover.stories.tsx +158 -0
  135. package/src/components/popover/Popover.test.tsx +102 -0
  136. package/src/components/popover/Popover.tsx +53 -0
  137. package/src/components/popover/context.ts +4 -0
  138. package/src/components/popover/index.ts +5 -0
  139. package/src/components/popover/types.ts +53 -0
  140. package/src/components/popover/usePopover.tsx +70 -0
  141. package/src/components/popover/usePopoverContext.tsx +12 -0
  142. package/src/components/popover-content/PopoverContent.tsx +61 -0
  143. package/src/components/popover-content/index.ts +2 -0
  144. package/src/components/popover-content/styles.ts +27 -0
  145. package/src/components/popover-content/types.ts +11 -0
  146. package/src/components/popover-trigger/PopoverTrigger.tsx +43 -0
  147. package/src/components/popover-trigger/index.ts +2 -0
  148. package/src/components/popover-trigger/types.ts +9 -0
  149. package/src/components/toast/Toast.stories.tsx +75 -0
  150. package/src/components/toast/Toast.test.tsx +63 -0
  151. package/src/components/toast/Toast.tsx +122 -0
  152. package/src/components/toast/index.ts +2 -0
  153. package/src/components/toast/intl/en-US.json +3 -0
  154. package/src/components/toast/intl/fr-FR.json +3 -0
  155. package/src/components/toast/intl/index.ts +7 -0
  156. package/src/components/toast/styles.ts +43 -0
  157. package/src/components/toast/types.ts +44 -0
  158. package/src/components/toast-container/ToastContainer.stories.tsx +349 -0
  159. package/src/components/toast-container/ToastContainer.tsx +44 -0
  160. package/src/components/toast-container/index.ts +3 -0
  161. package/src/components/toast-container/styles.ts +746 -0
  162. package/src/components/toast-container/types.ts +110 -0
  163. package/src/components/toast-container/useToast.test.tsx +111 -0
  164. package/src/components/toast-container/useToast.tsx +128 -0
  165. package/src/components/tooltip/Tooltip.stories.tsx +200 -0
  166. package/src/components/tooltip/Tooltip.test.tsx +119 -0
  167. package/src/components/tooltip/Tooltip.tsx +55 -0
  168. package/src/components/tooltip/context.ts +4 -0
  169. package/src/components/tooltip/index.ts +5 -0
  170. package/src/components/tooltip/types.ts +55 -0
  171. package/src/components/tooltip/useTooltip.tsx +89 -0
  172. package/src/components/tooltip/useTooltipContext.tsx +12 -0
  173. package/src/components/tooltip-content/TooltipContent.tsx +76 -0
  174. package/src/components/tooltip-content/index.ts +2 -0
  175. package/src/components/tooltip-content/styles.ts +84 -0
  176. package/src/components/tooltip-content/types.ts +14 -0
  177. package/src/components/tooltip-trigger/TooltipTrigger.tsx +42 -0
  178. package/src/components/tooltip-trigger/index.ts +2 -0
  179. package/src/components/tooltip-trigger/types.ts +9 -0
  180. package/src/index.ts +14 -0
  181. package/tsconfig.json +3 -0
  182. /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
  183. /package/{index.d.ts → dist/index.d.ts} +0 -0
  184. /package/{index.js → dist/index.js} +0 -0
  185. /package/{index.js.map → dist/index.js.map} +0 -0
@@ -0,0 +1,18 @@
1
+ import styled from 'styled-components';
2
+ import { baseContainer } from '@redsift/design-system';
3
+ import { StyledDialogContentActionsProps } from './types';
4
+
5
+ /**
6
+ * Component style.
7
+ */
8
+ export const StyledDialogContentActions = styled.div<StyledDialogContentActionsProps>`
9
+ display: flex;
10
+ ${baseContainer}
11
+
12
+ margin-top: 8px;
13
+ margin-bottom: 8px;
14
+
15
+ &:focus-visible {
16
+ outline: none;
17
+ }
18
+ `;
@@ -0,0 +1,11 @@
1
+ import { ComponentProps } from 'react';
2
+ import { ContainerProps } from '@redsift/design-system';
3
+
4
+ /**
5
+ * Component props.
6
+ */
7
+ export interface DialogContentActionsProps
8
+ extends ComponentProps<'div'>,
9
+ ContainerProps {}
10
+
11
+ export type StyledDialogContentActionsProps = DialogContentActionsProps;
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import { act, render, waitFor } from '@testing-library/react';
3
+
4
+ import { DialogContentBody } from '.';
5
+ import { Dialog } from '../dialog';
6
+
7
+ const DialogBodyWrapper = ({ children }: { children: React.ReactNode }) => {
8
+ return (
9
+ <Dialog isOpen>
10
+ <Dialog.Content>{children}</Dialog.Content>
11
+ </Dialog>
12
+ );
13
+ };
14
+
15
+ describe('DialogContentBody', () => {
16
+ it('handles default', async () => {
17
+ const { getByText } = render(<DialogContentBody>Body</DialogContentBody>, {
18
+ wrapper: DialogBodyWrapper,
19
+ });
20
+ await act(async () => {});
21
+ await waitFor(() => {
22
+ expect(getByText('Body')).toBeVisible();
23
+ });
24
+ expect(getByText('Body')).toBeVisible();
25
+ });
26
+
27
+ it('supports custom className', async () => {
28
+ const { getByText } = render(
29
+ <DialogContentBody className="test-class">Body</DialogContentBody>,
30
+ { wrapper: DialogBodyWrapper }
31
+ );
32
+
33
+ await act(async () => {});
34
+ await waitFor(() => {
35
+ expect(getByText('Body')).toBeVisible();
36
+ });
37
+
38
+ const component = getByText('Body');
39
+ expect(component).toHaveAttribute(
40
+ 'class',
41
+ expect.stringContaining(DialogContentBody.className!)
42
+ );
43
+ expect(component).toHaveAttribute(
44
+ 'class',
45
+ expect.stringContaining('test-class')
46
+ );
47
+ });
48
+
49
+ it('supports custom data attributes', async () => {
50
+ const { getByText } = render(
51
+ <DialogContentBody data-testid="test">Body</DialogContentBody>,
52
+ { wrapper: DialogBodyWrapper }
53
+ );
54
+
55
+ await act(async () => {});
56
+ await waitFor(() => {
57
+ expect(getByText('Body')).toBeVisible();
58
+ });
59
+
60
+ const component = getByText('Body');
61
+ expect(component).toHaveAttribute('data-testid', 'test');
62
+ });
63
+ });
@@ -0,0 +1,49 @@
1
+ import React, { forwardRef } from 'react';
2
+ import classNames from 'classnames';
3
+ import { useMergeRefs } from '@floating-ui/react';
4
+
5
+ import { Comp, useBoundingClientRect } from '@redsift/design-system';
6
+ import { StyledDialogContentBody } from './styles';
7
+ import { DialogContentBodyProps } from './types';
8
+ import { useDialogContext } from '../dialog';
9
+
10
+ const COMPONENT_NAME = 'DialogContentBody';
11
+ const CLASSNAME = 'redsift-dialog-content-body';
12
+ const DEFAULT_PROPS: Partial<DialogContentBodyProps> = {};
13
+
14
+ /**
15
+ * The DialogContentBody component.
16
+ */
17
+ export const DialogContentBody: Comp<DialogContentBodyProps, HTMLDivElement> =
18
+ forwardRef((props, ref) => {
19
+ const { children, className, ...forwardedProps } = props;
20
+
21
+ const { actionsRef, bodyRef, hasCloseButton, headerRef, initialFocus } =
22
+ useDialogContext();
23
+
24
+ const { height: headerHeight = 0 } = useBoundingClientRect(
25
+ headerRef as any,
26
+ [children, headerRef]
27
+ );
28
+ const { height: actionsHeight = 0 } = useBoundingClientRect(
29
+ actionsRef as any,
30
+ [children, actionsRef]
31
+ );
32
+
33
+ /* istanbul ignore next */
34
+ return (
35
+ <StyledDialogContentBody
36
+ {...forwardedProps}
37
+ className={classNames(DialogContentBody.className, className)}
38
+ ref={useMergeRefs([ref, bodyRef])}
39
+ tabIndex={initialFocus === 'body' ? -1 : undefined}
40
+ $marginTop={Math.max(headerHeight, hasCloseButton ? 40 : 0) + 80}
41
+ $marginBottom={(actionsHeight === 0 ? 0 : actionsHeight + 16) + 80}
42
+ >
43
+ {children}
44
+ </StyledDialogContentBody>
45
+ );
46
+ });
47
+ DialogContentBody.className = CLASSNAME;
48
+ DialogContentBody.defaultProps = DEFAULT_PROPS;
49
+ DialogContentBody.displayName = COMPONENT_NAME;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './DialogContentBody';
@@ -0,0 +1,58 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { baseContainer } from '@redsift/design-system';
3
+ import { StyledDialogContentBodyProps } from './types';
4
+
5
+ /**
6
+ * Component style.
7
+ */
8
+ export const StyledDialogContentBody = styled.div<StyledDialogContentBodyProps>`
9
+ ${baseContainer}
10
+
11
+ overflow-y: auto;
12
+ ${({ $marginTop, $marginBottom }) => css`
13
+ max-height: calc(100vh - ${$marginTop + $marginBottom}px);
14
+ `}
15
+
16
+ color: var(--redsift-color-neutral-darkgrey);
17
+ font-family: var(--redsift-typography-body2-font-family);
18
+ font-size: var(--redsift-typography-body2-font-size);
19
+ font-weight: var(--redsift-typography-body2-font-weight);
20
+ line-height: var(--redsift-typography-body2-line-height);
21
+ padding: 0 24px;
22
+ margin: 16px -24px;
23
+
24
+ &:focus-visible {
25
+ outline: none;
26
+ }
27
+
28
+ scrollbar-color: var(--redsift-color-neutral-midgrey) transparent;
29
+ scrollbar-width: thin;
30
+
31
+ &::-webkit-scrollbar {
32
+ block-size: 9px;
33
+ inline-size: 9px;
34
+ }
35
+
36
+ &::-webkit-scrollbar-thumb {
37
+ background-clip: padding-box;
38
+ background-color: var(--redsift-color-neutral-midgrey);
39
+ border-radius: 0px;
40
+ border-left: 2px solid transparent;
41
+ border-right: 2px solid transparent;
42
+ }
43
+
44
+ &::-webkit-scrollbar-track {
45
+ background-color: transparent;
46
+ }
47
+
48
+ &::-webkit-scrollbar-thumb:horizontal,
49
+ &::-webkit-scrollbar-thumb:vertical {
50
+ &:hover {
51
+ background-color: var(--redsift-color-neutral-darkgrey);
52
+ }
53
+ }
54
+
55
+ &::-webkit-scrollbar-corner {
56
+ visibility: hidden;
57
+ }
58
+ `;
@@ -0,0 +1,14 @@
1
+ import { ComponentProps } from 'react';
2
+ import { ContainerProps } from '@redsift/design-system';
3
+
4
+ /**
5
+ * Component props.
6
+ */
7
+ export interface DialogContentBodyProps
8
+ extends ComponentProps<'div'>,
9
+ ContainerProps {}
10
+
11
+ export type StyledDialogContentBodyProps = DialogContentBodyProps & {
12
+ $marginTop: number;
13
+ $marginBottom: number;
14
+ };
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import { act, render, waitFor } from '@testing-library/react';
3
+
4
+ import { DialogContentHeader } from '.';
5
+ import { Dialog } from '../dialog';
6
+
7
+ const DialogHeaderWrapper = ({ children }: { children: React.ReactNode }) => {
8
+ return (
9
+ <Dialog isOpen>
10
+ <Dialog.Content>{children}</Dialog.Content>
11
+ </Dialog>
12
+ );
13
+ };
14
+
15
+ describe('DialogContentHeader', () => {
16
+ it('handles default', async () => {
17
+ const { getByText } = render(<DialogContentHeader header="Header" />, {
18
+ wrapper: DialogHeaderWrapper,
19
+ });
20
+ await act(async () => {});
21
+ await waitFor(() => {
22
+ expect(getByText('Header')).toBeVisible();
23
+ });
24
+ expect(getByText('Header')).toBeVisible();
25
+ });
26
+
27
+ it('supports custom className', async () => {
28
+ const { getByText } = render(
29
+ <DialogContentHeader className="test-class" header="Header" />,
30
+ { wrapper: DialogHeaderWrapper }
31
+ );
32
+
33
+ await act(async () => {});
34
+ await waitFor(() => {
35
+ expect(getByText('Header')).toBeVisible();
36
+ });
37
+
38
+ const component = getByText('Header').parentElement;
39
+ expect(component).toHaveAttribute(
40
+ 'class',
41
+ expect.stringContaining(DialogContentHeader.className!)
42
+ );
43
+ expect(component).toHaveAttribute(
44
+ 'class',
45
+ expect.stringContaining('test-class')
46
+ );
47
+ });
48
+
49
+ it('supports custom data attributes', async () => {
50
+ const { getByText } = render(
51
+ <DialogContentHeader data-testid="test" header="Header" />,
52
+ { wrapper: DialogHeaderWrapper }
53
+ );
54
+
55
+ await act(async () => {});
56
+ await waitFor(() => {
57
+ expect(getByText('Header')).toBeVisible();
58
+ });
59
+
60
+ const component = getByText('Header').parentElement;
61
+ expect(component).toHaveAttribute('data-testid', 'test');
62
+ });
63
+ });
@@ -0,0 +1,81 @@
1
+ import React, { forwardRef, useId } from 'react';
2
+ import classNames from 'classnames';
3
+ import { useMergeRefs } from '@floating-ui/react';
4
+
5
+ import { Icon, Heading, Comp } from '@redsift/design-system';
6
+ import { StyledDialogContentHeader } from './styles';
7
+ import { DialogContentHeaderProps } from './types';
8
+ import { useDialogContext } from '../dialog';
9
+
10
+ const COMPONENT_NAME = 'DialogContentHeader';
11
+ const CLASSNAME = 'redsift-dialog-content-header';
12
+ const DEFAULT_PROPS: Partial<DialogContentHeaderProps> = {};
13
+
14
+ /**
15
+ * The DialogContentHeader component.
16
+ */
17
+ export const DialogContentHeader: Comp<
18
+ DialogContentHeaderProps,
19
+ HTMLDivElement
20
+ > = forwardRef((props, ref) => {
21
+ const {
22
+ children,
23
+ className,
24
+ header,
25
+ headingProps,
26
+ icon,
27
+ subheader,
28
+ ...forwardedProps
29
+ } = props;
30
+
31
+ const { setLabelId, setDescriptionId, headerRef, initialFocus } =
32
+ useDialogContext();
33
+ const labelId = useId();
34
+ const descriptionId = useId();
35
+
36
+ // Only sets `aria-labelledby` on the Dialog root element
37
+ // if this component is mounted inside it.
38
+ React.useLayoutEffect(() => {
39
+ setLabelId(labelId);
40
+ return () => setLabelId(undefined);
41
+ }, [labelId, setLabelId]);
42
+
43
+ // Only sets `aria-describedby` on the Dialog root element
44
+ // if this component is mounted inside it.
45
+ React.useLayoutEffect(() => {
46
+ setDescriptionId(descriptionId);
47
+ return () => setDescriptionId(undefined);
48
+ }, [descriptionId, setDescriptionId]);
49
+
50
+ return (
51
+ <StyledDialogContentHeader
52
+ {...forwardedProps}
53
+ className={classNames(DialogContentHeader.className, className)}
54
+ ref={useMergeRefs([ref, headerRef])}
55
+ tabIndex={initialFocus === 'header' ? -1 : undefined}
56
+ >
57
+ {subheader ? (
58
+ <div className={`${DialogContentHeader.className}__subheader`}>
59
+ {subheader}
60
+ </div>
61
+ ) : null}
62
+ {header ? (
63
+ <Heading
64
+ as="h2"
65
+ color="black"
66
+ className={`${DialogContentHeader.className}__header`}
67
+ id={labelId}
68
+ variant="h2"
69
+ {...headingProps}
70
+ >
71
+ {icon ? <Icon icon={icon} aria-hidden="true" /> : null}
72
+ {header}
73
+ </Heading>
74
+ ) : null}
75
+ {children ? <div id={descriptionId}>{children}</div> : null}
76
+ </StyledDialogContentHeader>
77
+ );
78
+ });
79
+ DialogContentHeader.className = CLASSNAME;
80
+ DialogContentHeader.defaultProps = DEFAULT_PROPS;
81
+ DialogContentHeader.displayName = COMPONENT_NAME;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './DialogContentHeader';
@@ -0,0 +1,36 @@
1
+ import styled from 'styled-components';
2
+ import { StyledDialogContentHeaderProps } from './types';
3
+
4
+ /**
5
+ * Component style.
6
+ */
7
+ export const StyledDialogContentHeader = styled.div<StyledDialogContentHeaderProps>`
8
+ color: var(--redsift-color-neutral-black);
9
+
10
+ &:focus-visible {
11
+ outline: none;
12
+ }
13
+
14
+ .redsift-dialog-content-header__header {
15
+ align-items: center;
16
+ display: flex;
17
+ gap: 8px;
18
+ padding: 10px 0px;
19
+ margin: 0px;
20
+
21
+ .redsift-icon {
22
+ color: var(--redsift-color-neutral-black);
23
+ padding-right: 8px;
24
+ font-size: 30px;
25
+ line-height: 30px;
26
+ height: 30px;
27
+ }
28
+ }
29
+
30
+ .redsift-dialog-content-header__subheader {
31
+ font-family: var(--redsift-typography-body-font-family);
32
+ font-size: var(--redsift-typography-body-font-size);
33
+ font-weight: var(--redsift-typography-body-font-weight);
34
+ line-height: var(--redsift-typography-body-line-height);
35
+ }
36
+ `;
@@ -0,0 +1,23 @@
1
+ import { ComponentProps } from 'react';
2
+ import { HeadingProps } from '@redsift/design-system';
3
+
4
+ /**
5
+ * Component props.
6
+ */
7
+ export interface DialogContentHeaderProps extends ComponentProps<'div'> {
8
+ /** Header. */
9
+ header?: string;
10
+ /** Heading props allowing to override the component rendered by the heading without changing its style. */
11
+ headingProps?: Pick<HeadingProps, 'as' | 'noWrap'>;
12
+ /** Subheader */
13
+ subheader?: string;
14
+ /**
15
+ * Icon path data (`d` property of the `path` SVG element).<br />
16
+ * See <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths">https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths</a>.<br />
17
+ * Recommended path data come from mdi/js.<br />
18
+ * See <a href="https://www.npmjs.com/package/@mdi/js">https://www.npmjs.com/package/@mdi/js</a>.
19
+ */
20
+ icon?: string;
21
+ }
22
+
23
+ export type StyledDialogContentHeaderProps = DialogContentHeaderProps;
@@ -0,0 +1,43 @@
1
+ import React, { forwardRef, ReactElement } from 'react';
2
+ import { useMergeRefs } from '@floating-ui/react';
3
+
4
+ import { Comp, isComponent } from '@redsift/design-system';
5
+ import { useDialogContext } from '../dialog';
6
+ import { DialogTriggerProps } from './types';
7
+
8
+ const COMPONENT_NAME = 'DialogTrigger';
9
+ const CLASSNAME = 'redsift-dialog-trigger';
10
+ const DEFAULT_PROPS: Partial<DialogTriggerProps> = {};
11
+
12
+ /**
13
+ * The DialogTrigger component.
14
+ */
15
+ export const DialogTrigger: Comp<DialogTriggerProps, HTMLButtonElement> =
16
+ forwardRef((props, ref) => {
17
+ const { children } = props;
18
+
19
+ const { getReferenceProps, isOpen, handleOpen, refs } = useDialogContext();
20
+ const childrenRef = (children as any).ref;
21
+ const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
22
+
23
+ if (
24
+ isComponent('Button')(children) ||
25
+ isComponent('IconButton')(children) ||
26
+ isComponent('LinkButton')(children)
27
+ ) {
28
+ return React.cloneElement(children, {
29
+ ...getReferenceProps({
30
+ ref: triggerRef,
31
+ ...props,
32
+ ...(children as ReactElement).props,
33
+ }),
34
+ onClick: () => handleOpen(!isOpen),
35
+ isActive: isOpen,
36
+ });
37
+ }
38
+
39
+ return <>{children}</>;
40
+ });
41
+ DialogTrigger.className = CLASSNAME;
42
+ DialogTrigger.defaultProps = DEFAULT_PROPS;
43
+ DialogTrigger.displayName = COMPONENT_NAME;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './DialogTrigger';
@@ -0,0 +1,9 @@
1
+ import { ComponentProps } from 'react';
2
+ import { StylingProps } from '@redsift/design-system';
3
+
4
+ /**
5
+ * Component props.
6
+ */
7
+ export interface DialogTriggerProps
8
+ extends Omit<ComponentProps<'button'>, 'onClick'>,
9
+ StylingProps {}
@@ -0,0 +1,158 @@
1
+ import React, { useState } from 'react';
2
+ import { Flexbox, Button, Text } from '@redsift/design-system';
3
+ import { Popover, PopoverPlacement } from '.';
4
+
5
+ export default {
6
+ title: 'Popovers/Popover',
7
+ component: Popover,
8
+ };
9
+
10
+ export const Uncontrolled = () => (
11
+ <Popover>
12
+ <Popover.Trigger>
13
+ <Button variant="secondary">Button</Button>
14
+ </Popover.Trigger>
15
+ <Popover.Content>
16
+ <Text margin="16px">
17
+ Cupcake ipsum dolor sit amet blueie jujubes topping sesame snaps.
18
+ Liquorice marzipan jelly-o carrot cake icing croissant carrot cake. Tart
19
+ soufflé sweet roll halvah croissant wafer cotton candy. Candy halvah
20
+ marzipan bear claw donut.
21
+ </Text>
22
+ </Popover.Content>
23
+ </Popover>
24
+ );
25
+
26
+ export const Controlled = () => {
27
+ const [isOpen, setIsOpen] = useState(false);
28
+ return (
29
+ <>
30
+ <Button variant="secondary" onClick={() => setIsOpen(!isOpen)}>
31
+ External trigger
32
+ </Button>
33
+ <Popover isOpen={isOpen} onOpen={setIsOpen}>
34
+ <Popover.Trigger>
35
+ <Button variant="secondary">Trigger</Button>
36
+ </Popover.Trigger>
37
+ <Popover.Content>
38
+ <Text margin="16px">
39
+ Cupcake ipsum dolor sit amet blueie jujubes topping sesame snaps.
40
+ Liquorice marzipan jelly-o carrot cake icing croissant carrot cake.
41
+ Tart soufflé sweet roll halvah croissant wafer cotton candy. Candy
42
+ halvah marzipan bear claw donut.
43
+ </Text>
44
+ </Popover.Content>
45
+ </Popover>
46
+ </>
47
+ );
48
+ };
49
+
50
+ export const AllPlacements = () => (
51
+ <Flexbox
52
+ flexDirection="column"
53
+ flexWrap="wrap"
54
+ gap="32px"
55
+ padding="64px"
56
+ style={{ backgroundColor: '#EFEFEF' }}
57
+ >
58
+ {['top', 'left', 'right', 'bottom'].map((side) => {
59
+ return (
60
+ <Flexbox
61
+ key={side}
62
+ flexDirection="row"
63
+ flexWrap="wrap"
64
+ justifyContent="space-evenly"
65
+ alignItems="center"
66
+ >
67
+ {['start', '', 'end'].map((alignment) => {
68
+ return (
69
+ <div
70
+ key={`${side}${alignment ? '-' : ''}${alignment}`}
71
+ style={{ margin: '1em' }}
72
+ >
73
+ <Popover
74
+ isOpen
75
+ placement={
76
+ `${side}${
77
+ alignment ? '-' : ''
78
+ }${alignment}` as PopoverPlacement
79
+ }
80
+ >
81
+ <Popover.Trigger>
82
+ <Button variant="secondary">Button</Button>
83
+ </Popover.Trigger>
84
+ <Popover.Content>
85
+ <Text margin="16px">{`Popover [${side}${
86
+ alignment ? '-' : ''
87
+ }${alignment}]`}</Text>
88
+ </Popover.Content>
89
+ </Popover>
90
+ </div>
91
+ );
92
+ })}
93
+ </Flexbox>
94
+ );
95
+ })}
96
+ </Flexbox>
97
+ );
98
+
99
+ export const TriggerIsNotAButton = () => (
100
+ <Popover>
101
+ <Popover.Trigger>
102
+ This text has a popover but this will never be displayed because the
103
+ trigger is not a button.
104
+ </Popover.Trigger>
105
+ <Popover.Content>
106
+ <Text margin="16px">
107
+ Cupcake ipsum dolor sit amet blueie jujubes topping sesame snaps.
108
+ Liquorice marzipan jelly-o carrot cake icing croissant carrot cake. Tart
109
+ soufflé sweet roll halvah croissant wafer cotton candy. Candy halvah
110
+ marzipan bear claw donut.
111
+ </Text>
112
+ </Popover.Content>
113
+ </Popover>
114
+ );
115
+
116
+ export const EmptyPopover = () => (
117
+ <Flexbox
118
+ flexDirection="row"
119
+ flexWrap="wrap"
120
+ justifyContent="center"
121
+ alignItems="center"
122
+ padding="32px"
123
+ style={{ backgroundColor: '#EFEFEF' }}
124
+ >
125
+ <Popover>
126
+ <Popover.Trigger>
127
+ <Button variant="secondary">Button</Button>
128
+ </Popover.Trigger>
129
+ </Popover>
130
+ </Flexbox>
131
+ );
132
+
133
+ export const PopoverOnDisabledButton = () => (
134
+ <Flexbox
135
+ flexDirection="row"
136
+ flexWrap="wrap"
137
+ justifyContent="center"
138
+ alignItems="center"
139
+ padding="32px"
140
+ style={{ backgroundColor: '#EFEFEF' }}
141
+ >
142
+ <Popover>
143
+ <Popover.Trigger>
144
+ <Button variant="secondary" isDisabled>
145
+ Disabled
146
+ </Button>
147
+ </Popover.Trigger>
148
+ <Popover.Content>
149
+ <Text margin="16px">
150
+ Cupcake ipsum dolor sit amet blueie jujubes topping sesame snaps.
151
+ Liquorice marzipan jelly-o carrot cake icing croissant carrot cake.
152
+ Tart soufflé sweet roll halvah croissant wafer cotton candy. Candy
153
+ halvah marzipan bear claw donut.
154
+ </Text>
155
+ </Popover.Content>
156
+ </Popover>
157
+ </Flexbox>
158
+ );