@automattic/jetpack-components 3.2.0 → 4.0.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 (58) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/build/components/admin-page/style.module.scss +2 -2
  3. package/build/components/copy-to-clipboard/index.js +1 -1
  4. package/build/components/decorative-card/style.scss +4 -1
  5. package/build/components/diff-viewer/index.d.ts +2 -1
  6. package/build/components/global-notices/global-notices.d.ts +4 -0
  7. package/build/components/global-notices/global-notices.js +4 -0
  8. package/build/components/global-notices/use-global-notices.d.ts +3 -0
  9. package/build/components/global-notices/use-global-notices.js +3 -0
  10. package/build/components/gravatar/index.d.ts +1 -0
  11. package/build/components/icon-tooltip/index.js +37 -15
  12. package/build/components/icon-tooltip/style.scss +0 -8
  13. package/build/components/icon-tooltip/types.d.ts +4 -0
  14. package/build/components/jetpack-footer/style.scss +2 -5
  15. package/build/components/jitm-slot/index.d.ts +15 -0
  16. package/build/components/jitm-slot/index.js +52 -0
  17. package/build/components/jitm-slot/style.scss +16 -0
  18. package/build/components/jitm-slot/types.d.ts +10 -0
  19. package/build/components/text/style.module.scss +4 -4
  20. package/build/components/text/types.d.ts +4 -4
  21. package/build/components/theme-provider/index.js +1 -1
  22. package/build/index.d.ts +1 -2
  23. package/build/index.js +1 -2
  24. package/components/admin-page/style.module.scss +2 -2
  25. package/components/copy-to-clipboard/index.tsx +2 -2
  26. package/components/decorative-card/style.scss +4 -1
  27. package/components/diff-viewer/index.tsx +1 -0
  28. package/components/global-notices/README.md +25 -0
  29. package/components/global-notices/global-notices.tsx +4 -0
  30. package/components/global-notices/use-global-notices.ts +3 -0
  31. package/components/gravatar/index.tsx +1 -0
  32. package/components/icon-tooltip/index.tsx +49 -18
  33. package/components/icon-tooltip/style.scss +0 -8
  34. package/components/icon-tooltip/types.ts +5 -0
  35. package/components/jetpack-footer/style.scss +2 -5
  36. package/components/jitm-slot/index.tsx +67 -0
  37. package/components/jitm-slot/style.scss +16 -0
  38. package/components/jitm-slot/types.ts +10 -0
  39. package/components/text/style.module.scss +4 -4
  40. package/components/text/types.ts +4 -4
  41. package/components/theme-provider/index.tsx +1 -1
  42. package/index.ts +1 -2
  43. package/package.json +12 -7
  44. package/build/components/notice/index.d.ts +0 -29
  45. package/build/components/notice/index.js +0 -35
  46. package/build/components/notice/style.module.scss +0 -120
  47. package/build/components/zendesk-chat/constants.d.ts +0 -1
  48. package/build/components/zendesk-chat/constants.js +0 -2
  49. package/build/components/zendesk-chat/index.d.ts +0 -3
  50. package/build/components/zendesk-chat/index.js +0 -27
  51. package/build/components/zendesk-chat/types.d.ts +0 -11
  52. package/components/notice/index.tsx +0 -93
  53. package/components/notice/style.module.scss +0 -120
  54. package/components/zendesk-chat/README.md +0 -25
  55. package/components/zendesk-chat/constants.ts +0 -2
  56. package/components/zendesk-chat/index.tsx +0 -34
  57. package/components/zendesk-chat/types.ts +0 -14
  58. /package/build/components/{zendesk-chat → jitm-slot}/types.js +0 -0
@@ -1,93 +0,0 @@
1
- import { Icon, cautionFilled as warning, info, check, close } from '@wordpress/icons';
2
- import clsx from 'clsx';
3
- import styles from './style.module.scss';
4
- import type { Component, FC, ReactElement, ReactNode } from 'react';
5
-
6
- type NoticeProps = {
7
- /** The severity of the alert. */
8
- level?: 'error' | 'warning' | 'info' | 'success';
9
-
10
- /** The title of the notice */
11
- title?: string;
12
-
13
- /** A list of action elements to show across the bottom */
14
- actions?: ReactNode[];
15
-
16
- /** Hide close button */
17
- hideCloseButton?: boolean;
18
-
19
- /** Method to call when the close button is clicked */
20
- onClose?: () => void;
21
-
22
- /** Children to be rendered inside the alert. */
23
- children: ReactNode;
24
- };
25
-
26
- const getIconByLevel = ( level: NoticeProps[ 'level' ] ) => {
27
- switch ( level ) {
28
- case 'error':
29
- return warning;
30
- case 'warning':
31
- return warning;
32
- case 'info':
33
- return info;
34
- case 'success':
35
- return check;
36
- default:
37
- return warning;
38
- }
39
- };
40
-
41
- /**
42
- * Notice component
43
- *
44
- * @param {object} props - The component properties.
45
- * @param {string} props.level - The notice level: error, warning, info, success.
46
- * @param {boolean} props.hideCloseButton - Whether to hide the close button.
47
- * @param {Function} props.onClose - The function to call when the close button is clicked.
48
- * @param {string} props.title - The title of the notice.
49
- * @param {ReactNode[]} props.actions - Actions to show across the bottom of the bar.
50
- * @param {Component} props.children - The notice content.
51
- * @return {ReactElement} The `Notice` component.
52
- */
53
- const Notice: FC< NoticeProps > = ( {
54
- level = 'info',
55
- title,
56
- children,
57
- actions,
58
- hideCloseButton = false,
59
- onClose,
60
- } ) => {
61
- const classes = clsx( styles.container, styles[ `is-${ level }` ] );
62
-
63
- return (
64
- <div className={ classes }>
65
- <div className={ styles[ 'icon-wrapper' ] }>
66
- <Icon icon={ getIconByLevel( level ) } className={ styles.icon } />
67
- </div>
68
-
69
- <div className={ styles[ 'main-content' ] }>
70
- { title && <div className={ styles.title }>{ title }</div> }
71
- { children }
72
-
73
- { actions && actions.length > 0 && (
74
- <div className={ styles[ 'action-bar' ] }>
75
- { actions.map( ( action, index ) => (
76
- <div key={ index } className={ styles.action }>
77
- { action }
78
- </div>
79
- ) ) }
80
- </div>
81
- ) }
82
- </div>
83
-
84
- { ! hideCloseButton && (
85
- <button aria-label="close" className={ styles[ 'close-button' ] } onClick={ onClose }>
86
- <Icon icon={ close } />
87
- </button>
88
- ) }
89
- </div>
90
- );
91
- };
92
-
93
- export default Notice;
@@ -1,120 +0,0 @@
1
- .container {
2
- display: flex;
3
- align-items: flex-start;
4
-
5
- font-size: var(--font-body);
6
-
7
- border: 1px solid var(--jp-black);
8
- border-radius: 4px;
9
- border-color: var(--jp-gray-5);
10
- border-left-width: 6px;
11
-
12
- padding: 24px 31px 27px 18px;
13
- }
14
-
15
- .icon-wrapper {
16
- margin-right: 20px;
17
- width: calc(var(--spacing-base) * 3);
18
- height: calc(var(--spacing-base) * 3);
19
- }
20
-
21
- .close-button {
22
- padding: 0;
23
- background-color: transparent;
24
- border: none;
25
- cursor: pointer;
26
- outline: none;
27
-
28
- svg {
29
- display: block;
30
- }
31
- }
32
-
33
- // Mobile layout differences.
34
- @media screen and ( max-width: 600px ) {
35
-
36
- .container {
37
- position: relative;
38
- padding-top: 68px;
39
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.06);
40
- }
41
-
42
- .icon-wrapper {
43
- position: absolute;
44
- top: 24px;
45
- left: 24px;
46
- }
47
-
48
- .close-button {
49
- position: absolute;
50
- top: 24px;
51
- right: 24px;
52
- }
53
- }
54
-
55
- .main-content {
56
- flex-grow: 1;
57
- }
58
-
59
- .title {
60
- font-weight: 600;
61
- margin-bottom: 8px;
62
- }
63
-
64
- .action-bar {
65
- display: flex;
66
- align-items: center;
67
- margin-top: 20px;
68
- row-gap: 20px;
69
- flex-wrap: wrap;
70
-
71
- @media screen and ( max-width: 600px ) {
72
- justify-content: center;
73
- }
74
-
75
- a {
76
-
77
- &,
78
- &:hover,
79
- &:active,
80
- &:focus {
81
- color: var(--jp-black);
82
- }
83
- }
84
-
85
- > * {
86
- margin-right: 24px;
87
- }
88
- }
89
-
90
- .is-error {
91
- border-left-color: var(--jp-red);
92
-
93
- .icon {
94
- color: var(--jp-red);
95
- }
96
- }
97
-
98
- .is-warning {
99
- border-left-color: var(--jp-yellow-20);
100
-
101
- .icon {
102
- color: var(--jp-yellow-20);
103
- }
104
- }
105
-
106
- .is-info {
107
- border-left-color: var(--black);
108
-
109
- .icon {
110
- color: var(--black);
111
- }
112
- }
113
-
114
- .is-success {
115
- border-left-color: var(--jp-green);
116
-
117
- .icon {
118
- color: var(--jp-green);
119
- }
120
- }
@@ -1,25 +0,0 @@
1
- # Summary
2
-
3
- This component adds a Zendesk chat widget via <script> tag to any page the componet is added to
4
-
5
- WARNING: If you add this to a specific site, it will stay on the page until the browser reloads onto a page that does not load this widget. For example, if a section of the plugin is using `react-router`, and the widget is loaded onto one specific route, it will not go away when a new route is taken since the page is not reloaded
6
-
7
- ## Usage
8
-
9
- ```tsx
10
- import { ZendeskChat } from '@automattic/jetpack-components';
11
-
12
- const ExampleComponent = () => (
13
- <ZendeskChat />
14
- );
15
- ```
16
-
17
- ## Props
18
-
19
- None
20
-
21
- Because the chat is conditionally rendered based on Date and Time, no props are needed in order to render correctly.
22
-
23
- ## Note
24
-
25
- There is a wpcom/v2 API endpoint `/presales/chat?group=jp_presales` that returns whether or not chat is available at this time. This should be used when determining whether or not to render this component.
@@ -1,2 +0,0 @@
1
- // This is not a secret, it can easily be found in the DOM
2
- export const chatKey = 'd729d42c-b547-4750-a6f6-8b30534a5f12';
@@ -1,34 +0,0 @@
1
- import { useEffect, useCallback } from 'react';
2
- import { chatKey } from './constants.ts';
3
- import type { ZendeskChatType } from './types.ts';
4
-
5
- export const ZendeskChat: ZendeskChatType = ( { jwt_token } ) => {
6
- const authenticateUser = useCallback( () => {
7
- if ( typeof window !== 'undefined' && typeof window.zE === 'function' ) {
8
- window.zE( 'messenger', 'loginUser', function ( callback ) {
9
- callback( jwt_token );
10
- } );
11
- }
12
- }, [ jwt_token ] );
13
-
14
- useEffect( () => {
15
- const script = document.createElement( 'script' );
16
- const container = document.getElementById( 'zendesk-chat-container' );
17
-
18
- script.src = 'https://static.zdassets.com/ekr/snippet.js?key=' + encodeURIComponent( chatKey );
19
- script.type = 'text/javascript';
20
- script.id = 'ze-snippet';
21
-
22
- script.onload = () => {
23
- authenticateUser();
24
- };
25
-
26
- if ( container ) {
27
- container.appendChild( script );
28
- }
29
- }, [ authenticateUser ] );
30
-
31
- return <div data-testid="zendesk-chat-container" id="zendesk-chat-container" />;
32
- };
33
-
34
- export default ZendeskChat;
@@ -1,14 +0,0 @@
1
- import type { FC } from 'react';
2
-
3
- declare global {
4
- interface Window {
5
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
6
- zE: Function;
7
- }
8
- }
9
-
10
- interface ZendeskChatProps {
11
- jwt_token: string;
12
- }
13
-
14
- export type ZendeskChatType = FC< ZendeskChatProps >;