Giter VIP home page Giter VIP logo

announcekit-react's Introduction

The easiest way to use AnnounceKit widgets in your React App.

Visit https://announcekit.app to get started with AnnounceKit.

CodeSandBox Demo

Documentation

Installation

yarn add announcekit-react

Usage

import React from "react";
import AnnounceKit from "announcekit-react";

class App extends React.Component {
  render() {
    return (
      <div>
        <nav>
          <ul>
            <li>
              <a href="#">Home</a>
            </li>
            <li>
              <AnnounceKit widget="https://announcekit.co/widgets/v2/3xdhio">
                <span>Whats new</span>
              </AnnounceKit>
            </li>
          </ul>
        </nav>
      </div>
    );
  }
}

Props

  • widget - The url of the widget. You can obtain it while creating or editing widget in AnnounceKit Dashboard.
  • widgetStyle - You can apply CSS rules to modify / tune the position of the widget launcher.
  • floatWidget - Set true if the widget is a Float widget.
  • embedWidget - Set true if the widget is a Embed widget.
  • boosters - In case you don't want to boosters appear on the page the widget is placed.
  • lang - Language selector
  • user - User properties (for user tracking)
  • data - Segmentation data
  • labels - In case you want to filter and display posts under a specific label or tag.
  • user_token - JWT setup: https://announcekit.app/docs/jwt
  • onWidgetOpen - Called when the widget is opened.
  • onWidgetClose - Called when the widget is closed.
  • onWidgetResize - Called when the widget is resized.
  • onWidgetUnread - Called when unread post count of widget has been updated.

API

You can use ref property to access the widget instance and call control functions

  • open()
  • close()
  • unread()
  • instance()
function App() {
  const ref = React.createRef<AnnounceKit>();

  React.useEffect(() => {
    ref.current.unread().then(an => console.log("unread", an));
  });

  return (
    <div>
        <button onClick={async() => await ref.current.open()}>
            Click to open widget
        </button>
        <AnnounceKit ref={ref} widget="https://announcekit.co/widgets/v2/3xdhio">
            <span>Whats new</span>
        </AnnounceKit>
    </div>
    )
}

announcekit-react's People

Contributors

bbenoist avatar eknkc avatar hasanayan avatar namirali avatar yigitfindikli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

announcekit-react's Issues

Can't do snapshot testing

Every time I run snapshot testing it creates a container with new classname hashes.
It should be possible to apply snapshotSerializers in jest configuration to keep the classnames the same.

image

AnnounceKit badge doesn't disappear on click when ref is used

The following, when clicking on the element I pass open to (for its onClick handler), the badge is still shown until I refresh the page:

const AnnounceKitBadge = ({ children }) => {
  const announceKitRef = useRef<AnnounceKit>();

  const open = async () => await announceKitRef?.current?.open();

  const AnnounceKitElement = (
    <AnnounceKit
      widget={'myurl'}
      ref={announceKitRef}
    />
  );

  return children({ open, AnnounceKitElement }) ;
};

It will only disappear as expected if I were to click directly on the small circle badge instead of clicking on the element I pass the open function to as an onClick handler. This ref usage is in the example codesandbox so I'd expect it to work.

When I use catchClick and pass a selector instead of the onClick event handler, then clicking on the element I pass the selector to will make the badge disappear upon open as expected..

A related issue is passing children to AnnounceKit isn't well supported since there is no way to override the styles, the display: inline is hardcoded. Passing widgetStyle doesn't help either.

I'm using version 2.1.7.

Component should not inject script tags

When we attempted to integrate this into our project, it broke tests due to the script tag that is being injected.

Having a component directly mutate the DOM in this way is not how React is intended to be used.

The external script that is needed should be provided as part of a template HTML file rather than directly injected by the component itself.

Unfortunately, I don't see a backward-compatible way to make this change.

Adding Youtube video throw error

Hi,

If we add youtube video to Announcekit post we get this error on the client console:

Uncaught DOMException: Failed to construct 'PresentationRequest': The document is sandboxed and lacks the 'allow-presentation' flag.

please add this flag: 'allow-presentation' to the youtube iframe

New feature request: batch delete posts

A batch delete posts function will be convenient. Now I have to manually delete each post since I have some posts I want to keep and can't just delete them all.
image

Z-Index update

The announceKit banner appears way on a static z-index value.

Is there any way to make the zIndex on the component to be configurable?

New widget is added to page on re-render

We use the <AnnounceKit /> component inside of a dropdown, and whenever the dropdown is re-rendered, it re-initializes announcekit.

This means that long running instances of our applications have a lot of their resources consumed by announcekit.

Is there an identifier we can provide?

Add componentWillUnmount()

Any initialized widget object would forever stay in the global window['announcekit'], having a componentWillUnmount() to clean the global object would be very helpful to free up memory usage.

Chrome flashes "Waiting for announceKit.app" every minute or so on left corner

image

See the image above. It's kind of annoying. My first thought is you should do a POST instead of a GET to prevent chrome from doing that. but test it and see if that's true. Post an update soon.

Request URL: https://announcekit.app/widget/3DXfDq/data.json?_=JHVybD1odHRwJTNBJTJGJTJGbG9jYWxob3N0JTNBNDAwMCUyRmRldmVsb3BlciUyRm5ldy1hcHAmJHBhZ2U9T1JFJTIwSUQmJGxhbmd1YWdlPWVuLVVTJiRvcz1NYWMlMjBPUyYkYWdlbnQ9Q2hyb21l
Request Method: GET <=== try making this a POST
Status Code: 200

Doesn't work

I had a bunch of problems getting this to work by the instructions on the widget page. Finally got it to kind of work, but when I cleared my browser cache for that page, it stopped working. Then I tried this announcekit-react package and still can't get it working. I see that it does create the widget div and the window.announcekit is setup. Not sure why it's not working. No errors in console and no network errors.

boosters Prop is missing

Original documentation have a property:

// Optional: In case you don't want to boosters appear on the page the widget is placed.
boosters: false,

and looks like you dont have it :(

Typing issues in 3.0+

Hello, there seems to be some typing issues in versions 3.0 and upwards. When I try to use your component through ref I get this
'AnnounceKit' refers to a value, but is being used as a type here. Did you mean 'typeof AnnounceKit'?

After changing it to const ref = React.createRef<typeof AnnounceKit>(); it seems that all the typing which were available in versions up to version 3 is gone Property 'open' does not exist on type 'ForwardRefExoticComponent<AnnounceKitProps & RefAttributes<unknown>>'.ts(2339).

It seems to me that this part in your declaration file declare const _default: React.ForwardRefExoticComponent<AnnounceKitProps & React.RefAttributes<unknown>>; export default _default; seems to be the problem. Shouldn't React.RefAttributes<unknown> have something else casted other than unknown or am I just using your library wrong? I've followed your readme available in this repo.

Thank you for your help.

Overflow issues

Hi there,

We've been running into a few issues while trying to integrate the AnnounceKit React component into our component library -- the first of which was solved here (thank you for this!) However, we've run into another issue with how overflows are handled when the modal/sidebar opens.

Currently, we're trying to integrate this component into our navigation bar, which is placed at the top of every web app we've got. When the modal/sidebar opens, the scrollbar is removed because of the overflow: hidden styling that is added; however, this has undesired effects to our navigation bar, where the sub-components to the right of our navigation bar move over to the right a little bit because of the extra space/padding.

This is a before screenshot:

Screenshot from 2021-10-25 14-55-33

And this is an after screenshot -- all the elements on the top right (the options + about + log out buttons) move to the right by about 15px because of the custom inline styling that we have no control over.

Screenshot from 2021-10-25 14-55-47

I get that hiding the scrollbar is the most obvious solution to ensuring that users don't scroll under the modal/sidebar (this in fact is what we do for most of our modals as well.) But is there any way for us to control the dimming of the background? My ideal state here would be to make the dimmer a lot darker, so that the slight movement of the nav bar elements is not noticeable. Currently, this is set inline to be rgba(0, 0, 0, 0.3), is it possible for us to control this either via the AnnounceKit UI or via the AnnounceKit-React component?

Thanks!

Announcekit gobbles up click event?

I found this weird behavior when I had a dropdown menu with a 'suggest a featureitem in it. The idea was for the AK widget to pop open when clicked on. Automatically, the dropdown menu recognizes any clicks in the menu to automatically close, but for reason I can't figure out, it seems that AK seems topreventDefaultandstopPropagation` of the click event, leaving the menu open while the widget is showing.

I instead tried to close the dropdown menu automatically when the onWidgetOpen event triggered, but when I did, the AK widget would close as well :|

There's some very odd behaviors at play here...

Dev Widget Visibility

Not necessarily an Announcekit-React specific question, but that is what I am using.

I have an issue where the Banner that is displayed when an Announcement is sent out, affects the way in which my site works. This is due to a bit of scroll jacking, but that is the design required by designers.

The issue, which is a hunch because I don't have an actual banner to work with, is that the css for the banner is adding some margin to the body. It is this extra space that is breaking how the design works.

So my question, is there a way to trigger the display of a banner (or any other widget) so that I can work on this bug without having to have Product team send out an Announcement and all the users see it?

I am hoping that Announcekit adds a class to the body something like <body class="announcekit-banner"> because then I can write a css style that removes the added margin from the bottom when that class is present and leave things alone when NOT present.

If Announcekit is adding margin directly to body, like:

body {
   margin-top: 2.5rem
}

Then that is going to be significantly more effort to deal with.

But without the ability to see an actual banner, then I am not sure I can actually definitively figure this out.

Thanks in advance!

Segment around widget-open

How can I set segment data before/after/around widget-open? I would like may set dynamically segment.

e.g:

<AnnounceKit
  widget="https://announcekit.app/widgets/v2/id-widget"
  user={{ id: 1234 }}
  data={{
    ...segment
  }}
  onWidgetOpen={({ widget }) => {
    const page = `${props.currentPath}${location.hash}`
    setSegment({ page })
  }}
>
  <NotificationsIcon />
</AnnounceKit>

However this dont open component, anybody know about this?

Badge style

Hi,

We are using custom Bell icon in order to open up the widget, however we are still getting the red badge appear next to the bell icon.
see screenshot below:

navber_badge

We want to apply custom style in order to hide the badge (and the cursor too when hovering over it), Iv'e been trying:

      <AnnounceKit
        widget="https://announcekit.app/widgets/v2/34MmKA"
        widgetStyle={{ visibility: 'hidden', cursor: 'default' }}
      >
        <Bell width="20" height="20" />
      </AnnounceKit>

It didn't work. We also have a problem to apply our own css because it has his own inline style which cannot be overridden.
Is there a way to handle to cursor and the visibility of the badge so we can see only our custom Bell icon?

Upgrading to 3.0 breaks widgetStyles

I recently updated to 3.0 and my widgetStyles passed via prop are no longer being applied. I also noticed there is no release history, changelog or documentation on possible breaking changes when upgrading to 3.0.

Is this docmented anywhere? And if not can we get some documentation around the major update?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.