Skip to content

Commit 05a13ea

Browse files
authored
Merge pull request #184 from calibreapp/styling
Add class attribute to the container element
2 parents 4b6e96b + 4fea732 commit 05a13ea

8 files changed

Lines changed: 71 additions & 26 deletions

File tree

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,14 @@ export default class App extends React.Component {
157157
}
158158
```
159159

160-
You can customise the Help Scout beacon by passing the following props to the
160+
You can customise the Help Scout placeholder by passing the following props to the
161161
`HelpScout` component:
162162

163-
- `color`: The background color of the beacon
163+
- `color`: The background color of the placeholder
164164
- `icon`: Choose from `message`, `antenna`, `search`, `question`, `beacon`
165-
- `zIndex`: Changes the CSS index value of how the Beacon relates to other objects
165+
- `zIndex`: Changes the CSS index value of how the placeholder relates to other objects
166166
- `horizontalPosition`: Choose from `left` or `right`
167+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
167168

168169
Currently the Help Scout component only supports the icon button style.
169170

@@ -192,8 +193,10 @@ export default class App extends React.Component {
192193
}
193194
```
194195

195-
You can customise the color of the Intercom widget by passing a `color` prop to
196-
the `Intercom` component.
196+
You can customise the Intercom placeholder icon by passing the following props to the `Intercom` component:
197+
198+
- `color`: The background color of the placeholder widget
199+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
197200

198201
[Messenger Settings](https://developers.intercom.com/installing-intercom/docs/javascript-api-attributes-objects#messenger-attributes), User context and Company context settings can be set using `window.intercomSettings`. See the [official Intercom documentation](https://developers.intercom.com/installing-intercom/docs/javascript-api-attributes-objects#section-data-attributes) for more details.
199202

@@ -241,6 +244,7 @@ You can customise the Messenger widget by passing the following props to the
241244
currently not logged in to Facebook.
242245
- `greetingDialogDisplay`: Sets how the greeting dialog will be displayed.
243246
- `greetingDialogDelay`: Sets the number of seconds of delay before the greeting dialog is shown after the plugin is loaded.
247+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
244248

245249
For a list of options, refer to [Facebook Customer Chat Plugin documentation](https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin#customization).
246250

@@ -267,11 +271,12 @@ export default () => (
267271
)
268272
```
269273

270-
You can customise the Drift Messenger by passing the following props to the
274+
You can customise the Drift placeholder by passing the following props to the
271275
`Drift` component:
272276

273-
- `color`: The background color of the messenger
277+
- `color`: The background color of the placeholder
274278
- `icon`: Choose from `A`, `B`, `C`, `D`; you're presented with these preset icons when signing up for Drift, or in the "Drift Widget > Design > Widget icon" entry under the "App Settings" header on the Drift settings page.
279+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
275280

276281
</details>
277282

@@ -297,7 +302,7 @@ export default () => (
297302
)
298303
```
299304

300-
You can customise the Userlike Widget by passing the following props to the
305+
You can customise the Userlike placeholder by passing the following props to the
301306
`Userlike` component:
302307

303308
- `color`: The contrasting color, can be `black` or `white`.
@@ -306,6 +311,7 @@ You can customise the Userlike Widget by passing the following props to the
306311
- `vOffset`: The amount of vertical margin.
307312
- `hOffset`: The amount of horizontal margin.
308313
- `style`: The shape style, can be `round` or `square`.
314+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
309315

310316
</details>
311317

@@ -333,10 +339,11 @@ export default () => (
333339
)
334340
```
335341

336-
You can customise the Chatwoot Widget by passing the following props to the
342+
You can customise the Chatwoot placeholder by passing the following props to the
337343
`Chatwoot` component:
338344

339345
- `color`: The background color, set to same color value you choose in Chatwoot dashboard.
346+
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
340347

341348
</details>
342349

src/components/Chatwoot/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { CSSProperties } from 'react'
22

33
import useChat from '../../hooks/useChat'
4+
import { ProviderProps, ClassNames } from '../../types'
45

56
const styles: {
67
button: CSSProperties
@@ -34,17 +35,20 @@ const styles: {
3435
}
3536
}
3637

37-
interface Props {
38+
interface Props extends ProviderProps {
3839
color?: string
3940
}
4041

41-
const Provider = ({ color }: Props): JSX.Element | null => {
42+
const Provider = ({
43+
color,
44+
containerClass = ClassNames.container
45+
}: Props): JSX.Element | null => {
4246
const [state, loadChat] = useChat({ loadWhenIdle: true })
4347

4448
if (state === 'complete') return null
4549

4650
return (
47-
<div>
51+
<div className={containerClass}>
4852
<div
4953
role="button"
5054
aria-label="Load Chat"

src/components/Drift/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect, CSSProperties } from 'react'
22

33
import useChat from '../../hooks/useChat'
44
import useWindowWidth from '../../hooks/useWindowWidth'
5+
import { ProviderProps, ClassNames } from '../../types'
56

67
const styles: {
78
container: CSSProperties
@@ -40,14 +41,15 @@ const styles: {
4041
}
4142
}
4243

43-
interface Props {
44+
interface Props extends ProviderProps {
4445
color?: string
4546
icon?: 'A' | 'B' | 'C' | 'D'
4647
}
4748

4849
const Drift = ({
4950
color = '#0176ff',
50-
icon = 'A'
51+
icon = 'A',
52+
containerClass = ClassNames.container
5153
}: Props): JSX.Element | null => {
5254
const [state, loadChat] = useChat({ loadWhenIdle: true })
5355
const windowWidth = useWindowWidth()
@@ -72,7 +74,7 @@ const Drift = ({
7274
}
7375

7476
return (
75-
<div style={positionStyles}>
77+
<div className={containerClass} style={positionStyles}>
7678
<div style={styles.container}>
7779
<div
7880
role="button"

src/components/HelpScout/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { CSSProperties, useEffect, useState } from 'react'
22

33
import useChat from '../../hooks/useChat'
44
import useWindowHeight from '../../hooks/useWindowHeight'
5+
import { ProviderProps, ClassNames } from '../../types'
56

67
const styles: {
78
wrapper: CSSProperties
@@ -157,7 +158,7 @@ const getIcon = (icon: HelpScoutIcon): JSX.Element => {
157158
}
158159
}
159160

160-
interface Props {
161+
interface Props extends ProviderProps {
161162
color?: string
162163
icon?: HelpScoutIcon
163164
zIndex?: string
@@ -168,7 +169,8 @@ const HelpScout = ({
168169
color = '#976ad4',
169170
icon = 'beacon',
170171
zIndex = '1050',
171-
horizontalPosition = 'left'
172+
horizontalPosition = 'left',
173+
containerClass = ClassNames.container
172174
}: Props): JSX.Element | null => {
173175
const [state, loadChat] = useChat({ loadWhenIdle: true })
174176
const windowHeight = useWindowHeight()
@@ -201,6 +203,7 @@ const HelpScout = ({
201203

202204
return (
203205
<div
206+
className={containerClass}
204207
style={{
205208
...styles.wrapper,
206209
...positionStyles,

src/components/Intercom/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { CSSProperties } from 'react'
22

33
import useChat from '../../hooks/useChat'
4+
import { ProviderProps, ClassNames } from '../../types'
45

56
const styles: {
67
wrapper: CSSProperties
@@ -88,11 +89,14 @@ const styles: {
8889
}
8990
}
9091

91-
interface Props {
92+
interface Props extends ProviderProps {
9293
color?: string
9394
}
9495

95-
const Intercom = ({ color }: Props): JSX.Element | null => {
96+
const Intercom = ({
97+
color,
98+
containerClass = ClassNames.container
99+
}: Props): JSX.Element | null => {
96100
const [state, loadChat] = useChat({ loadWhenIdle: true })
97101

98102
if (state === 'complete') {
@@ -101,6 +105,7 @@ const Intercom = ({ color }: Props): JSX.Element | null => {
101105

102106
return (
103107
<div
108+
className={containerClass}
104109
style={{
105110
...styles.wrapper,
106111
background: color

src/components/Messenger/index.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { CSSProperties, memo } from 'react'
22

33
import useProvider from '../../hooks/useProvider'
44
import useChat from '../../hooks/useChat'
5+
import { ProviderProps, ClassNames } from '../../types'
56

67
const styles: CSSProperties = {
78
appearance: 'none',
@@ -24,7 +25,7 @@ const styles: CSSProperties = {
2425
userSelect: 'none'
2526
}
2627

27-
interface Props {
28+
interface Props extends ProviderProps {
2829
themeColor?: string
2930
loggedInGreeting?: string
3031
loggedOutGreeting?: string
@@ -67,7 +68,13 @@ const CustomerChat = memo(
6768
}
6869
)
6970

70-
const Widget = ({ color }: { color: string }): JSX.Element | null => {
71+
const Widget = ({
72+
color,
73+
containerClass
74+
}: {
75+
color: string
76+
containerClass: string
77+
}): JSX.Element | null => {
7178
const [state, loadChat] = useChat({ loadWhenIdle: true })
7279

7380
if (state === 'complete') {
@@ -76,6 +83,7 @@ const Widget = ({ color }: { color: string }): JSX.Element | null => {
7683

7784
return (
7885
<div
86+
className={containerClass}
7987
style={styles}
8088
role="button"
8189
aria-label="Load Chat"
@@ -104,13 +112,17 @@ const Widget = ({ color }: { color: string }): JSX.Element | null => {
104112
)
105113
}
106114

107-
const Messenger = ({ color = '', ...props }: Props): JSX.Element => {
115+
const Messenger = ({
116+
color = '',
117+
containerClass = ClassNames.container,
118+
...props
119+
}: Props): JSX.Element => {
108120
const { providerKey } = useProvider()
109121

110122
return (
111123
<>
112124
<CustomerChat color={color} providerKey={providerKey} {...props} />
113-
<Widget color={color} />
125+
<Widget color={color} containerClass={containerClass} />
114126
</>
115127
)
116128
}

src/components/Userlike/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { CSSProperties } from 'react'
22

33
import useChat from '../../hooks/useChat'
4+
import { ProviderProps, ClassNames } from '../../types'
45

56
const styles: {
67
container: CSSProperties
@@ -34,7 +35,7 @@ const styles: {
3435
}
3536
}
3637

37-
interface Props {
38+
interface Props extends ProviderProps {
3839
color?: string
3940
backgroundColor?: string
4041
position?: string
@@ -49,7 +50,8 @@ const Userlike = ({
4950
position = 'right',
5051
vOffset = '24px',
5152
hOffset = '24px',
52-
style = 'round'
53+
style = 'round',
54+
containerClass = ClassNames.container
5355
}: Props): JSX.Element | null => {
5456
const [state, loadChat] = useChat({ loadWhenIdle: true })
5557
const positionStyles = {
@@ -66,7 +68,10 @@ const Userlike = ({
6668
}
6769

6870
return (
69-
<div style={{ ...styles.container, ...positionStyles, ...shapeStyle }}>
71+
<div
72+
className={containerClass}
73+
style={{ ...styles.container, ...positionStyles, ...shapeStyle }}
74+
>
7075
<button
7176
role="button"
7277
aria-label="Load Chat"

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
export enum ClassNames {
2+
container = 'live-chat-loader-placeholder'
3+
}
4+
export interface ProviderProps {
5+
containerClass?: string
6+
}
7+
18
export type State = 'initial' | 'open' | 'complete'
29

310
export type Provider =

0 commit comments

Comments
 (0)