Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and razonyang committed Dec 1, 2024
0 parents commit f4bd85f
Show file tree
Hide file tree
Showing 20 changed files with 5,403 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: razonyang
custom:
- https://paypal.me/razonyang
- https://afdian.com/a/razonyang
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: lint

on:
push:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
- run: npm ci
- run: npm run lint
18 changes: 18 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
command: manifest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public/
resources/
.hugo_build.lock
node_modules/
14 changes: 14 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pull_request_rules:
- name: Automatic merge for Renovate pull requests
conditions:
- author=renovate[bot]
actions:
merge:
method: rebase

- name: Automatic merge on approval
conditions:
- "#approved-reviews-by>=1"
actions:
merge:
method: rebase
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.tmpl.scss
9 changes: 9 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "stylelint-config-standard-scss",
"rules": {
"at-rule-no-unknown": null,
"color-function-notation": null,
"scss/at-rule-no-unknown": true,
"scss/at-extend-no-missing-placeholder": null
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 HB Framework Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# HB Toasts Module

[![Used By](https://flat.badgen.net/github/dependents-repo/hbstack/toasts?icon=hugo&label=used+by&color=green)](https://github.com/hbstack/toasts/network/dependents)
![Hugo Requirements](https://img.shields.io/badge/dynamic/json?color=important&label=requirements&query=requirements&logo=hugo&style=flat-square&url=https://api.razonyang.com/v1/hugo/modules/github.com/hbstack/toasts)
[![License](https://flat.badgen.net/github/license/hbstack/toasts)](https://github.com/hbstack/toasts/blob/main/LICENSE)
[![Version](https://flat.badgen.net/github/tag/hbstack/toasts)](https://github.com/hbstack/toasts/tags)
86 changes: 86 additions & 0 deletions assets/hb/modules/toasts/js/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Toast from 'js/bootstrap/src/toast.js'
import { getCookie, deleteCookie } from '@hugomods/cookies'

let container: null | HTMLElement = null

const getContainer = (): HTMLElement => {
if (container === null) {
container = document.createElement('div')
container.className = 'toast-container hb-toast-container position-fixed end-0 bottom-0 mb-3 me-2'
document.body.appendChild(container)
}

return container
}

export interface ToastOptions {
autoHide?: boolean
style?: string
}

export const add = (title: string, content: string, options: ToastOptions = {}): void => {
const container = getContainer()
const toast = document.createElement('div')
toast.className = 'toast hb-toast'
if (options.autoHide === false) {
toast.setAttribute('data-bs-autohide', 'false')
}

const header = document.createElement('div')
header.classList.add('toast-header')
header.innerHTML = `<strong class="me-auto">${title}</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>`

const body = document.createElement('div')
body.classList.add('toast-body')
body.innerHTML = content

if (options.style !== undefined) {
header.classList.add(`text-bg-${options.style}`)
body.classList.add(`bg-${options.style}-subtle`)
}

toast.appendChild(header)
toast.appendChild(body)
container.append(toast)

Toast.getOrCreateInstance(toast).show()
}

export const addStyle = (style, title, content, options: ToastOptions = {}): void => {
add(title, content, { ...options, style })
}

export const addError = (content, options: ToastOptions = {}, title = 'Error'): void => {
addStyle('danger', title, content, options)
}

export const addInfo = (content, options: ToastOptions = {}, title = 'Info'): void => {
addStyle('info', title, content, options)
}

export const addSuccess = (content, options: ToastOptions = {}, title = 'Success'): void => {
addStyle('success', title, content, options)
}

export const addWarning = (content, options: ToastOptions = {}, title = 'Warning'): void => {
addStyle('warning', title, content, options)
}

export const readToastsFromCookie = (name: string): void => {
const toastCookie = getCookie(name)
if (toastCookie !== null) {
// delete the one time toast cookie.
deleteCookie(name, { path: '/' })
const toasts = JSON.parse(atob(decodeURIComponent(toastCookie)))
for (const toast of toasts) {
add(toast.title, toast.content, {
style: toast.style ?? ''
})
}
}
}

(() => {
readToastsFromCookie('hb-toasts')
})()
28 changes: 28 additions & 0 deletions assets/hb/modules/toasts/purgecss.config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classes = [
'toast-container',
'position-fixed',
'end-0',
'bottom-0',
'mb-2',
'me-2',
'toast',
'toast-header',
'toast-body',
'text-bg-primary',
'text-bg-secondary',
'text-bg-info',
'text-bg-warning',
'text-bg-success',
'text-bg-dark',
'text-bg-light',
'text-bg-danger',
'bg-primary-subtle',
'bg-secondary-subtle',
'bg-info-subtle',
'bg-warning-subtle',
'bg-success-subtle',
'bg-dark-subtle',
'bg-light-subtle',
'bg-danger-subtle',
'btn-close',
]
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/hbstack/toasts

go 1.19

require (
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20200 // indirect
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 // indirect
github.com/hbstack/hb v0.16.0 // indirect
github.com/hugomods/base v0.7.2 // indirect
github.com/hugomods/cookies v0.1.0 // indirect
github.com/hugomods/hugopress v0.5.0 // indirect
github.com/twbs/bootstrap v5.3.3+incompatible // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20200 h1:SmpwwN3DNzJWbV+IT8gaFu07ENUFpCvKou5BHYUKuVs=
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20200/go.mod h1:kx8MBj9T7SFR8ZClWvKZPmmUxBaltkoXvnWlZZcSnYA=
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs=
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI=
github.com/hbstack/hb v0.16.0 h1:k5SLF8zmGb8M5UWJwTjWi8/EuiKZ+7gQbP2qRcWYdr0=
github.com/hbstack/hb v0.16.0/go.mod h1:FJilVCHtkVpfXZT+Ii2OFCVeu9wQh/YGgRMuPKX5ycA=
github.com/hugomods/base v0.7.2 h1:SShNl7koN79CEUdGQ65Knbf/c2k+bE+El5ManYWd8Cg=
github.com/hugomods/base v0.7.2/go.mod h1:hnWCPbVxuhXBwdFax3mmbMlWKmIo/7OP36MCLOyHtT4=
github.com/hugomods/cookies v0.1.0 h1:kFhCT8IVcQs+CBOy6imnQu37zQgP/Sx3VKnqBVCVC0Y=
github.com/hugomods/cookies v0.1.0/go.mod h1:VeB+SljM9zsF/yzwolmVy7y7yDFyDlmDRdelE1Aw6Bg=
github.com/hugomods/hugopress v0.5.0 h1:eQHg1aKnc5StGFnV5H0BORhE0UmHYpaWHnX9QNseHrw=
github.com/hugomods/hugopress v0.5.0/go.mod h1:CRYvr60xOkZOf4Atkuj+uEj2EH5pjJ39Ws3aJAkoMkA=
github.com/twbs/bootstrap v5.3.2+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=
github.com/twbs/bootstrap v5.3.3+incompatible h1:goFoqinzdHfkeegpFP7pvhbd0g+A3O2hbU3XCjuNrEQ=
github.com/twbs/bootstrap v5.3.3+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=
10 changes: 10 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [module.hugoVersion]
# min = "0.111.3"

[[module.imports]]
path = "github.com/hbstack/hb"

[[module.imports]]
path = "github.com/hugomods/cookies"

[params.hb.toasts]
Loading

0 comments on commit f4bd85f

Please sign in to comment.