Skip to content

Commit

Permalink
Merge pull request #184 from calibreapp/styling
Browse files Browse the repository at this point in the history
Add class attribute to the container element
  • Loading branch information
robmorieson authored Oct 11, 2022
2 parents 4b6e96b + 4fea732 commit 05a13ea
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 26 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ export default class App extends React.Component {
}
```

You can customise the Help Scout beacon by passing the following props to the
You can customise the Help Scout placeholder by passing the following props to the
`HelpScout` component:

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

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

Expand Down Expand Up @@ -192,8 +193,10 @@ export default class App extends React.Component {
}
```

You can customise the color of the Intercom widget by passing a `color` prop to
the `Intercom` component.
You can customise the Intercom placeholder icon by passing the following props to the `Intercom` component:

- `color`: The background color of the placeholder widget
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`

[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.

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

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

Expand All @@ -267,11 +271,12 @@ export default () => (
)
```

You can customise the Drift Messenger by passing the following props to the
You can customise the Drift placeholder by passing the following props to the
`Drift` component:

- `color`: The background color of the messenger
- `color`: The background color of the placeholder
- `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.
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`

</details>

Expand All @@ -297,7 +302,7 @@ export default () => (
)
```

You can customise the Userlike Widget by passing the following props to the
You can customise the Userlike placeholder by passing the following props to the
`Userlike` component:

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

</details>

Expand Down Expand Up @@ -333,10 +339,11 @@ export default () => (
)
```

You can customise the Chatwoot Widget by passing the following props to the
You can customise the Chatwoot placeholder by passing the following props to the
`Chatwoot` component:

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

</details>

Expand Down
10 changes: 7 additions & 3 deletions src/components/Chatwoot/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { CSSProperties } from 'react'

import useChat from '../../hooks/useChat'
import { ProviderProps, ClassNames } from '../../types'

const styles: {
button: CSSProperties
Expand Down Expand Up @@ -34,17 +35,20 @@ const styles: {
}
}

interface Props {
interface Props extends ProviderProps {
color?: string
}

const Provider = ({ color }: Props): JSX.Element | null => {
const Provider = ({
color,
containerClass = ClassNames.container
}: Props): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })

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

return (
<div>
<div className={containerClass}>
<div
role="button"
aria-label="Load Chat"
Expand Down
8 changes: 5 additions & 3 deletions src/components/Drift/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, CSSProperties } from 'react'

import useChat from '../../hooks/useChat'
import useWindowWidth from '../../hooks/useWindowWidth'
import { ProviderProps, ClassNames } from '../../types'

const styles: {
container: CSSProperties
Expand Down Expand Up @@ -40,14 +41,15 @@ const styles: {
}
}

interface Props {
interface Props extends ProviderProps {
color?: string
icon?: 'A' | 'B' | 'C' | 'D'
}

const Drift = ({
color = '#0176ff',
icon = 'A'
icon = 'A',
containerClass = ClassNames.container
}: Props): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })
const windowWidth = useWindowWidth()
Expand All @@ -72,7 +74,7 @@ const Drift = ({
}

return (
<div style={positionStyles}>
<div className={containerClass} style={positionStyles}>
<div style={styles.container}>
<div
role="button"
Expand Down
7 changes: 5 additions & 2 deletions src/components/HelpScout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { CSSProperties, useEffect, useState } from 'react'

import useChat from '../../hooks/useChat'
import useWindowHeight from '../../hooks/useWindowHeight'
import { ProviderProps, ClassNames } from '../../types'

const styles: {
wrapper: CSSProperties
Expand Down Expand Up @@ -157,7 +158,7 @@ const getIcon = (icon: HelpScoutIcon): JSX.Element => {
}
}

interface Props {
interface Props extends ProviderProps {
color?: string
icon?: HelpScoutIcon
zIndex?: string
Expand All @@ -168,7 +169,8 @@ const HelpScout = ({
color = '#976ad4',
icon = 'beacon',
zIndex = '1050',
horizontalPosition = 'left'
horizontalPosition = 'left',
containerClass = ClassNames.container
}: Props): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })
const windowHeight = useWindowHeight()
Expand Down Expand Up @@ -201,6 +203,7 @@ const HelpScout = ({

return (
<div
className={containerClass}
style={{
...styles.wrapper,
...positionStyles,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Intercom/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { CSSProperties } from 'react'

import useChat from '../../hooks/useChat'
import { ProviderProps, ClassNames } from '../../types'

const styles: {
wrapper: CSSProperties
Expand Down Expand Up @@ -88,11 +89,14 @@ const styles: {
}
}

interface Props {
interface Props extends ProviderProps {
color?: string
}

const Intercom = ({ color }: Props): JSX.Element | null => {
const Intercom = ({
color,
containerClass = ClassNames.container
}: Props): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })

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

return (
<div
className={containerClass}
style={{
...styles.wrapper,
background: color
Expand Down
20 changes: 16 additions & 4 deletions src/components/Messenger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { CSSProperties, memo } from 'react'

import useProvider from '../../hooks/useProvider'
import useChat from '../../hooks/useChat'
import { ProviderProps, ClassNames } from '../../types'

const styles: CSSProperties = {
appearance: 'none',
Expand All @@ -24,7 +25,7 @@ const styles: CSSProperties = {
userSelect: 'none'
}

interface Props {
interface Props extends ProviderProps {
themeColor?: string
loggedInGreeting?: string
loggedOutGreeting?: string
Expand Down Expand Up @@ -67,7 +68,13 @@ const CustomerChat = memo(
}
)

const Widget = ({ color }: { color: string }): JSX.Element | null => {
const Widget = ({
color,
containerClass
}: {
color: string
containerClass: string
}): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })

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

return (
<div
className={containerClass}
style={styles}
role="button"
aria-label="Load Chat"
Expand Down Expand Up @@ -104,13 +112,17 @@ const Widget = ({ color }: { color: string }): JSX.Element | null => {
)
}

const Messenger = ({ color = '', ...props }: Props): JSX.Element => {
const Messenger = ({
color = '',
containerClass = ClassNames.container,
...props
}: Props): JSX.Element => {
const { providerKey } = useProvider()

return (
<>
<CustomerChat color={color} providerKey={providerKey} {...props} />
<Widget color={color} />
<Widget color={color} containerClass={containerClass} />
</>
)
}
Expand Down
11 changes: 8 additions & 3 deletions src/components/Userlike/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { CSSProperties } from 'react'

import useChat from '../../hooks/useChat'
import { ProviderProps, ClassNames } from '../../types'

const styles: {
container: CSSProperties
Expand Down Expand Up @@ -34,7 +35,7 @@ const styles: {
}
}

interface Props {
interface Props extends ProviderProps {
color?: string
backgroundColor?: string
position?: string
Expand All @@ -49,7 +50,8 @@ const Userlike = ({
position = 'right',
vOffset = '24px',
hOffset = '24px',
style = 'round'
style = 'round',
containerClass = ClassNames.container
}: Props): JSX.Element | null => {
const [state, loadChat] = useChat({ loadWhenIdle: true })
const positionStyles = {
Expand All @@ -66,7 +68,10 @@ const Userlike = ({
}

return (
<div style={{ ...styles.container, ...positionStyles, ...shapeStyle }}>
<div
className={containerClass}
style={{ ...styles.container, ...positionStyles, ...shapeStyle }}
>
<button
role="button"
aria-label="Load Chat"
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export enum ClassNames {
container = 'live-chat-loader-placeholder'
}
export interface ProviderProps {
containerClass?: string
}

export type State = 'initial' | 'open' | 'complete'

export type Provider =
Expand Down

1 comment on commit 05a13ea

@vercel
Copy link

@vercel vercel bot commented on 05a13ea Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.