@defra/flood-webchat 0.0.1-beta.26 → 0.0.1-beta.28

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.
@@ -0,0 +1,33 @@
1
+ // Check there is ot already similar functinality in GOV.UK Frontend
2
+
3
+ @mixin defra-visually-hidden() {
4
+ position: absolute;
5
+ width: 1px;
6
+ height: 1px;
7
+ margin: 0;
8
+ padding: 0;
9
+ overflow: hidden;
10
+ clip: rect(0 0 0 0);
11
+ -webkit-clip-path: inset(50%);
12
+ clip-path: inset(50%);
13
+ border: 0;
14
+ white-space: nowrap;
15
+ }
16
+
17
+ // Map specific mixins
18
+ @mixin focus($glow: 8px, $strong: 5px, $background: 2px, $inset: 0) {
19
+ position:absolute;
20
+ content:'';
21
+ left: 5px;
22
+ right: 5px;
23
+ top: 5px;
24
+ bottom: 5px;
25
+ box-shadow:
26
+ 0 0 0 $background #ffffff,
27
+ inset 0 0 0 $inset govuk-colour('black'),
28
+ 0 0 0 $strong govuk-colour('black'),
29
+ 0 0 0 $glow $govuk-focus-colour;
30
+ outline: 3px solid transparent;
31
+ pointer-events: none;
32
+ z-index: 99;
33
+ }
@@ -0,0 +1,25 @@
1
+ .wc-u-html {
2
+ @include mq ($until: tablet) {
3
+ height: 100vh;
4
+ overflow: hidden;
5
+ }
6
+ }
7
+
8
+ .wc-u-body {
9
+ @include mq ($until: tablet) {
10
+ position: fixed;
11
+ overflow: hidden;
12
+ top:0;
13
+ right:0;
14
+ bottom:0;
15
+ left:0;
16
+ }
17
+ }
18
+
19
+ .wc-u-hidden {
20
+ visibility: hidden;
21
+ }
22
+
23
+ .wc-u-scroll-padding {
24
+ scroll-padding-bottom: calc(2rem + 20px);
25
+ }
@@ -51,6 +51,18 @@ export const AppProvider = ({ sdk, availability, options, children }) => {
51
51
  dispatch({ type: 'SET_AGENT_STATUS', payload: e.detail.data.case.status })
52
52
  }
53
53
 
54
+ const onMatchMedia = e => {
55
+ dispatch({ type: 'TOGGLE_IS_MOBILE', payload: e.matches })
56
+ }
57
+
58
+ const onKeydown = () => {
59
+ dispatch({ type: 'TOGGLE_IS_KEYBOARD', payload: true })
60
+ }
61
+
62
+ const onPointerdown = () => {
63
+ dispatch({ type: 'TOGGLE_IS_KEYBOARD', payload: false })
64
+ }
65
+
54
66
  useEffect(() => {
55
67
  sdk.onChatEvent(ChatEvent.LIVECHAT_RECOVERED, onLiveChatRecovered)
56
68
  sdk.onChatEvent(ChatEvent.MESSAGE_CREATED, onMessageCreated)
@@ -58,6 +70,16 @@ export const AppProvider = ({ sdk, availability, options, children }) => {
58
70
  sdk.onChatEvent(ChatEvent.AGENT_TYPING_ENDED, onAgentTypingEnded)
59
71
  sdk.onChatEvent(ChatEvent.ASSIGNED_AGENT_CHANGED, onAssignedAgentChanged)
60
72
  sdk.onChatEvent(ChatEvent.CONTACT_STATUS_CHANGED, onContactStatusChanged)
73
+ // We need to know if it is a mobile and if it is a keyboard interaction
74
+ window.matchMedia('(max-width: 640px)').addEventListener('change', onMatchMedia)
75
+ window.addEventListener('keydown', onKeydown)
76
+ window.addEventListener('pointerdown', onPointerdown)
77
+ // Tidying up
78
+ return () => {
79
+ window.removeEventListener('change', onMatchMedia)
80
+ window.removeEventListener('keydown', onKeydown)
81
+ window.removeEventListener('pointerdown', onPointerdown)
82
+ }
61
83
  }, [sdk])
62
84
 
63
85
  /**
@@ -69,20 +91,33 @@ export const AppProvider = ({ sdk, availability, options, children }) => {
69
91
  setCustomerId(window.localStorage.getItem(CUSTOMER_ID_STORAGE_KEY))
70
92
  setThreadId(window.localStorage.getItem(THREAD_ID_STORAGE_KEY))
71
93
  setSettings(JSON.parse(window.localStorage.getItem(SETTINGS_STORAGE_KEY)) || state.settings)
94
+ }, [])
72
95
 
96
+ /**
97
+ * Set browser history on start chat click
98
+ */
99
+ useEffect(() => {
73
100
  if (window.location.hash === '#webchat') {
74
101
  setChatVisibility(true)
75
102
  }
103
+
104
+ const onBrowserNavigation = window.addEventListener('popstate', () => {
105
+ if (window.location.hash === '#webchat') {
106
+ setChatVisibility(true)
107
+ } else {
108
+ setChatVisibility(false)
109
+ }
110
+ })
111
+
112
+ return () => {
113
+ window.removeEventListener('popstate', onBrowserNavigation)
114
+ }
76
115
  }, [])
77
116
 
78
117
  /**
79
118
  * State update functions
80
119
  */
81
120
  const setChatVisibility = payload => {
82
- if (!payload) {
83
- window.location.hash = ''
84
- }
85
-
86
121
  dispatch({ type: 'SET_CHAT_VISIBILITY', payload })
87
122
  }
88
123
 
@@ -103,6 +103,20 @@ const setUnseenCount = (state, payload) => {
103
103
  }
104
104
  }
105
105
 
106
+ const toggleIsMobile = (state, payload) => {
107
+ return {
108
+ ...state,
109
+ isMobile: payload
110
+ }
111
+ }
112
+
113
+ const toggleIsKeyboard = (state, payload) => {
114
+ return {
115
+ ...state,
116
+ isKeyboard: payload
117
+ }
118
+ }
119
+
106
120
  export const actionsMap = {
107
121
  SET_CHAT_VISIBILITY: setChatVisibility,
108
122
  SET_AVAILABILITY: setAvailability,
@@ -115,5 +129,7 @@ export const actionsMap = {
115
129
  SET_AGENT: setAgent,
116
130
  SET_AGENT_TYPING: setAgentIsTyping,
117
131
  SET_AGENT_STATUS: setAgentStatus,
118
- SET_UNSEEN_COUNT: setUnseenCount
132
+ SET_UNSEEN_COUNT: setUnseenCount,
133
+ TOGGLE_IS_MOBILE: toggleIsMobile,
134
+ TOGGLE_IS_KEYBOARD: toggleIsKeyboard
119
135
  }
@@ -11,6 +11,8 @@ export const initialState = {
11
11
  agentStatus: null,
12
12
  isAgentTyping: false,
13
13
  isChatOpen: false,
14
+ isMobile: window.matchMedia('(max-width: 640px)').matches,
15
+ isKeyboard: false,
14
16
  settings: { audio: true, scroll: true }
15
17
  }
16
18