Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>

              
            
!

CSS

              
                html,
body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
*,
*:after,
*:before {
  box-sizing: inherit;
}

#root {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  background: url('https://images.pexels.com/photos/1421903/pexels-photo-1421903.jpeg') top left no-repeat;
  background-size: cover;
}

.str-chat {
  /* flex: 1; */
  height: auto;
  max-height: 100%;
}

.str-chat-channel .str-chat__container {
  height: auto;
  max-height: 100%;
  border-radius: 10px;
  max-width: 375px;
}

.wrapper {
  display: flex;
  flex-direction: column;
  position: fixed;
  right: 20px;
  top: 60px;
  align-items: flex-end;
  justify-content: flex-end;
  height: 100%;
  height: calc(100% - 40px);
  padding: 30px 0;
  /* margin: 30px 0; */
}

.wrapper--open .str-chat__container {
  height: 100%;
}

.button {
  height: 60px;
  width: 60px;
  margin-top: 16px;
  border-radius: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 60px;

  background: #ffffff;
  background-image: linear-gradient(
    -180deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(0, 0, 0, 0.1) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5),
    inset 0 1px 0 0 rgba(255, 255, 255, 0.24);
  cursor: pointer;
}

.button svg {
  fill: #000;
  opacity: 0.8;
}

.button--closed svg {
  position: relative;
  left: 3px;
  fill: #0043f7;
}
.button:hover svg {
  opacity: 1;
}

.test-state-button {
  height: 50px;
}

@media screen and (max-width: 414px) {
  /* .str-chat-channel .str-chat__container {
    top: 0;
    right: 0;
    max-width: 100%;
    border-radius: 0;
    margin: 0 auto;
  } */
}

              
            
!

JS

              
                const chatClient = new StreamChat('qk4nn7rpcn75');
const userToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYnJva2VuLXdhdGVyZmFsbC01In0.d1xKTlD_D0G-VsBoDBNbaLjO-2XWNA8rlTm4ru4sMHg';

chatClient.setUser(
    {
        id: 'broken-waterfall-5',
        name: 'Broken waterfall',
        image: 'https://getstream.io/random_svg/?id=broken-waterfall-5&amp;name=Broken+waterfall'
    },
    userToken,
);


const channel = chatClient.channel('commerce', 'realestate', {
    image: 'https://cdn.shopifycloud.com/hatchful-web/assets/313d73fa42f04a46213abc6267b4d074.png',
    name: 'Safye Real Estate',
});

channel.on('message.new', event => {
    console.log('received a new message', event.message.text);
});

const Button = ({ open, onClick }) => (
    <div
        onClick={onClick}
        className={`button ${open ? 'button--open' : 'button--closed'}`}
    >
        {open ? (
            <svg width="20" height="20" xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M19.333 2.547l-1.88-1.88L10 8.12 2.547.667l-1.88 1.88L8.12 10 .667 17.453l1.88 1.88L10 11.88l7.453 7.453 1.88-1.88L11.88 10z"
                    fillRule="evenodd"
                />
            </svg>
        ) : (
                <svg width="24" height="20" xmlns="http://www.w3.org/2000/svg">
                    <path
                        d="M.011 20L24 10 .011 0 0 7.778 17.143 10 0 12.222z"
                        fillRule="evenodd"
                    />
                </svg>
            )}
    </div>
);

// original class components without Hooks
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            open: true
        };
    }

    toggleDemo = () => {
        if (this.state.open) {
            this.setState({ open: false });
        } else {
            this.setState({ open: true });
        }
    };

    async componentDidMount() {
        console.log('componentDidMount - rendered!');
        await channel.sendMessage({
          text: 'Welcome to our Stream Chat with React Hooks tutorial! 😄',
        });
    };

    componentWillUnmount() {
        console.log(`You have ${channel.state.messages.length} stored in local state. Goodbye!`);
    };

    render() {
        return (
            <>
                <div className={`wrapper ${this.state.open ? 'wrapper--open' : ''}`}>
                    <Chat client={chatClient} theme={'commerce dark'}>
                        <Channel channel={channel}>
                            <Window>
                                <ChannelHeader />
                                {this.state.open && (
                                    <MessageList
                                        typingIndicator={TypingIndicator}
                                        Message={MessageCommerce}
                                    />
                                )}
                                <MessageInput Input={MessageInputFlat} />
                            </Window>
                        </Channel>
                    </Chat>
                    <Button onClick={this.toggleDemo} open={this.state.open} />
                </div>
            </>
        );
    }
}

ReactDOM.render(<App />, document.getElementById('root'));

              
            
!
999px

Console