{"id":15007906,"url":"https://github.com/reecem/h-bar","last_synced_at":"2025-10-30T12:31:34.928Z","repository":{"id":42929353,"uuid":"240772191","full_name":"ReeceM/h-bar","owner":"ReeceM","description":"An Announcement Banner that is lightweight and based on tailwindcss for the styling","archived":false,"fork":false,"pushed_at":"2023-03-30T14:09:44.000Z","size":1280,"stargazers_count":4,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T08:21:49.854Z","etag":null,"topics":["announcement-banner","banner","javascript","javascript-library","notification","npm-package","tailwindcss"],"latest_commit_sha":null,"homepage":"https://reecem.github.io/h-bar","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReeceM.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null},"funding":{"github":"reecem","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-02-15T19:03:13.000Z","updated_at":"2024-05-18T07:23:40.000Z","dependencies_parsed_at":"2023-01-31T05:16:21.538Z","dependency_job_id":null,"html_url":"https://github.com/ReeceM/h-bar","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReeceM%2Fh-bar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReeceM%2Fh-bar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReeceM%2Fh-bar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReeceM%2Fh-bar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReeceM","download_url":"https://codeload.github.com/ReeceM/h-bar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219856290,"owners_count":16556085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["announcement-banner","banner","javascript","javascript-library","notification","npm-package","tailwindcss"],"created_at":"2024-09-24T19:14:23.897Z","updated_at":"2025-10-30T12:31:34.529Z","avatar_url":"https://github.com/ReeceM.png","language":"JavaScript","funding_links":["https://github.com/sponsors/reecem","https://www.buymeacoffee.com/ReeceM","https://ko-fi.com/S6S7UQ66"],"categories":[],"sub_categories":[],"readme":"# h-bar lightweight announcement bar\n\nAn Announcement Banner that is lightweight and based on tailwindcss for the styling\n\n[![npm version](https://badge.fury.io/js/%40reecem%2Fh-bar.svg)](https://www.npmjs.com/package/@reecem/h-bar)\n[![Total Downloads](https://img.shields.io/npm/dt/@reecem/h-bar.svg )](https://www.npmjs.com/package/@reecem/h-bar)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/@reecem/h-bar)\n\n\u003ch1 align=\"center\"\u003e\n\u003cbr\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/ReeceM/h-bar/master/docs/h-bar.png\" alt=\"h-bar announcements\"\u003e\n  \u003cbr\u003e\n    \u003cbr\u003e\n    h-bar Announcement banner\n  \u003cbr\u003e\n\u003c/h1\u003e\n\nThe announcement bar uses native methods to make the library lightweight so that it can be loaded quickly, bar the webpack stuff.\n\n**Note**\nThe initial version makes use of the WordPress API to be able to get the latest post.\n\ni.e. it expects a json structure like so:\nFrom a url like `http://blog.example.com/wp-json/wp/v2/posts?per_page=1\u0026_fields=id,title,link`\n```json\n[\n    {\n        \"id\": 175,\n        \"link\": \"https:\\/\\/blog.example.com\\/how-to-hunt-a-vole\\/\",\n        \"title\": {\n            \"rendered\": \"How To Hunt A Vole\"\n        }\n    }\n]\n```\n\nI plan to add more options and a parser callback that can be defined to extract a standard format.\n\n## Installation\n\nYou can install the package via npm:\n\n```bash\nnpm i @reecem/h-bar\n```\n\nOr use jsDelivr:\n```html\n    ...\n    \u003cscript src=\"https://unpkg.com/@reecem/h-bar?umd\"\u003e\u003c/script\u003e\n    ...\n```\n\n\u003e If you are customising the styling and overriding it with your own styling then you will also need an instance of your css or a tailwindcss file installed as only the classes needed are packaged with h-bar\n\n## Usage\n\nYou can import it directly into your javascript app or use it in the html.\n\n### Example\n\n```html\n\u003cscript src=\"../hBar.js\"\u003e\u003c/script\u003e\n\u003c!-- or --\u003e\n\u003cscript src=\"https://unpkg.com/@reecem/h-bar?umd\" defer\u003e\u003c/script\u003e\n\u003cscript\u003e\n    hBar.init({\n        url: \"http://blog.example.com/wp-json/wp/v2/posts?per_page=1\u0026_fields=id,excerpt,title,link\",\n        secondaryLinks: [\n            {\n                title: \"Docs\",\n                link: \"http:://docs.example.com\"\n            },\n            {\n                title: \"Support\",\n                link: \"http://help.example.com\"\n            }\n        ],\n        options: {\n            theme: \"blue\",\n        }\n    });\n\n    hBar.fetchData()\n\u003c/script\u003e\n```\n\n### All config values\n\nThe initialization object currently has this structure and defaults:\n\n```javascript\n{\n    url: \"https://your.blog/api/....\",\n    onCompleted: \"callback function\",\n    link: \"The link url, can be force and no need to fetch from API\",\n    title: \"The link url, can be force and no need to fetch from API\",\n    secondaryLinks: [\n        {\n            title: \"Docs\",\n            link: \"http:://docs.example.com\"\n        }\n    ],\n    parser: (data) =\u003e {/** Parser function */}\n    dismissible: false, // dismissible banner flag\n    dismissFor: new Date('2020-03-30'), // would dismiss it till end of March 30th 2020\n    theme: \"gray\",\n    headers: {\n        \"Authorization\": \"Bearer {TOKEN}\"\n    },\n    customStyles: {\n        wrapper: \"hb-flex hb-w-full hd-flex-col md:hb-flex-row sm:hb-flex-row hb-text-sm hb-py-2 md:hb-px-20 hb-px-1 hb-items-center hb-justify-between\",\n        linkWrapper: \"hb-flex hb-items-center\",\n        badge: \"hb-px-2 hb-mx-2 hb-leading-relaxed hb-tracking-wider hb-uppercase hb-font-semibold hb-rounded-full hb-text-xs\",\n        postTitle: \"hover:hb-underline\",\n        secondaryLink: \"hb-mx-5 hb-cursor-pointer hover:hb-underline\",\n    }\n}\n```\n\n### Themes\n\nTheme colors available: `gray`, `lightGray`, `blue`, `green`, `indigo`, `orange`, `yellow`, `teal`, `red`\n(the below images are in the order they exits)\n\n![gray banner](docs/themes/gray.png)\n![lightGray banner](docs/themes/lightGray.png)\n![blue banner](docs/themes/blue.png)\n![green banner](docs/themes/green.png)\n![indigo banner](docs/themes/indigo.png)\n![orange banner](docs/themes/orange.png)\n![yellow banner](docs/themes/yellow.png)\n![teal banner](docs/themes/teal.png)\n![red banner](docs/themes/red.png)\n\n### Parser function\n\nThere is the availability of adding a custom parser function to override any of the default ones provided by the package.\n\nThis is handy if you have a custom endpoint that say would return also the secondary links or has a different data structure.\n\nThe parser function should always return an object with the structure:\n```javascript\n{\n    title: String,\n    link: String,\n    /** the secondaryLinks is optional.\n     * It will also override the links parsed in the init() arguments.\n     */\n    secondaryLinks: [\n        {\n            title: String,\n            link: String,\n        },\n    ]\n}\n```\n\nYou can define the function inside the `init()` method as follows:\n```javascript\n\nhBar.init({\n    url: \"https://api.github.com/repos/ReeceM/h-bar/releases\",\n    parser: (data) =\u003e {\n        // getting the first release on the list of releases from github.\n        const {name, html_url} = data[0];\n\n        return {\n            title: `Lateset version available ${name}`,\n            link: html_url\n        };\n    }\n})\n```\n\n### Dismissing Notifications\n\n\u003e Available from `v0.3.0`/`v1.0.0`\n\n**Temporary Dismissing**\nTo be able to dismiss a notification, please note it currently removes secondary links. It is therefore useful that you use this feature when just making announcements of a event or brief notification.\n\nThe way to activate session based dismissal is:\n\n```javascript\n{\n    //... rest of config\n    dismissible: true,\n    //... rest of config\n}\n```\n\nThis will just disable the banner for the current page visit, if the user reloads, its back.\n\n**Time based dismissing**\n\nTo dismiss the banner until another time, you can set the `dismissFor` variable, this requires a `Date()` object.\n\nWhen you set this and the banner is dismissed, the UTC milliseconds are stored in the localStorage, this is then read back when loading h-Bar.\n\n```javascript\n{\n    //... rest of config\n    dismissible: true,\n    dismissFor: new Date('2020-03-30'), // would dismiss it till end of march 30th\n}\n```\n\nIf you fail to set the value properly, it won't dismiss and the banner will show by default.\n\n\n## Testing\n\n_to come_ please make a PR if you know how to do it on JS.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email zsh.rce@gmail.com instead of using the issue tracker. You can also use the [SECURITY](SECURITY.md) doc.\n\n## Credits\n\n- [ReeceM](https://github.com/ReeceM)\n- [All Contributors](../../contributors)\n\n## Support\n\n\u003ca href=\"https://www.buymeacoffee.com/ReeceM\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e\n\n[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S7UQ66)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freecem%2Fh-bar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freecem%2Fh-bar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freecem%2Fh-bar/lists"}