{"id":21181962,"url":"https://github.com/daief/axew-toast","last_synced_at":"2025-03-14T19:29:51.570Z","repository":{"id":35072254,"uuid":"202671600","full_name":"daief/axew-toast","owner":"daief","description":"A light-weight toast component. / 一个轻量、无依赖的 toast 组件。","archived":false,"fork":false,"pushed_at":"2023-07-12T22:59:05.000Z","size":168,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-24T07:39:56.994Z","etag":null,"topics":["toast","typescript"],"latest_commit_sha":null,"homepage":"https://daief.tech/axew-toast/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daief.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-16T06:30:43.000Z","updated_at":"2022-05-19T06:24:35.000Z","dependencies_parsed_at":"2022-08-08T06:15:25.225Z","dependency_job_id":null,"html_url":"https://github.com/daief/axew-toast","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daief%2Faxew-toast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daief%2Faxew-toast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daief%2Faxew-toast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daief%2Faxew-toast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daief","download_url":"https://codeload.github.com/daief/axew-toast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635049,"owners_count":20322874,"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":["toast","typescript"],"created_at":"2024-11-20T17:53:28.409Z","updated_at":"2025-03-14T19:29:51.496Z","avatar_url":"https://github.com/daief.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @axew/toast\n\n`@axew/toast` is a toast component.\n\n- light-weight\n- promise\n- cancelable\n- non-dependence\n\nDemo at \u003chttps://daief.tech/axew-toast/\u003e.\n\n## Usage\n\nInstall.\n\n```bash\n$ yarn add @axew/toast\n# or\n$ npm i @axew/toast\n```\n\n```js\nimport toast, { createToast } from '@axew/toast';\n\ntoast.show('This a message. It will be hidden in 2.5 seconds.');\n\ntoast.show('This a message', 3000);\n\ntoast.success('This a message', 3000);\n\n// preset a common config\ntoast.config({ timeout: 3000 });\n\ntoast.show('This message will be hidden in 3 seconds.');\n\n// loading style\ntoast.loading('Loading...');\n\n// or pass a object option\ntoast.show({\n  icon: 'loading',\n  className: 'my-custom-class',\n  onClick() {\n    console.log('clicked');\n  },\n});\n\n// cancelable\nconst cancel = toast.show(\n  {\n    text: 'This a message',\n    onClose: why =\u003e {\n      console.log(why);\n    },\n  },\n  4000\n);\n\nsetTimeout(() =\u003e {\n  cancel(); // console.log('cancel');\n}, 1000);\n\n// close all toast created by the instance\ntoast.destroyAll();\n\n// create a new toast instance\nconst toast2 = createToast();\n```\n\nAPI.\n\n```ts\nexport declare function createToast(initCfg?: Partial\u003cIObjectOptions\u003e): {\n  show: IToastFunction;\n  success: IToastFunction;\n  error: IToastFunction;\n  warning: IToastFunction;\n  loading: IToastFunction;\n  destroyAll: () =\u003e void;\n  config: (opts: Partial\u003cIObjectOptions\u003e) =\u003e void;\n};\nexport declare const toast: {\n  show: IToastFunction;\n  success: IToastFunction;\n  error: IToastFunction;\n  warning: IToastFunction;\n  loading: IToastFunction;\n  destroyAll: () =\u003e void;\n  config: (opts: Partial\u003cIObjectOptions\u003e) =\u003e void;\n};\nexport default toast;\n```\n\n```ts\nexport interface IEventHandler {\n  (this: HTMLDivElement, ev: MouseEvent): void;\n  options?: boolean | AddEventListenerOptions;\n}\n\nexport interface IObjectOptions {\n  /**\n   * toast message\n   *\n   * 文案\n   */\n  text?: string;\n  /**\n   * render text as html string\n   *\n   * 使用 html 的方式渲染文本\n   *\n   * @default false\n   */\n  asHtml?: boolean;\n  /**\n   * the icon type or custom icon img url\n   *\n   * 定义 icon 类型（或 icon 链接）\n   */\n  icon?: 'success' | 'error' | 'warning' | 'loading' | string;\n  /**\n   * @default 36\n   */\n  iconSize?: number | string;\n  /**\n   * icon spin\n   *\n   * icon 为 loading 时为 true\n   */\n  iconSpin?: boolean;\n  /**\n   * toast display time. always display when true\n   *\n   * 延迟，true 代表一直存在\n   *\n   * @default 2500\n   */\n  timeout?: number | true;\n  /**\n   * show modal div\n   *\n   * 是否模态\n   */\n  isModal?: boolean;\n  /**\n   * css class\n   *\n   * 样式名\n   */\n  className?: string;\n  /**\n   * click hadnler\n   *\n   * 点击事件\n   */\n  onClick?: IEventHandler;\n  /**\n   * toast close event\n   *\n   * 关闭事件\n   */\n  onClose?: (why: 'auto' | 'cancel') =\u003e void;\n}\n\nexport type IOptions = IObjectOptions | string;\n\nexport interface IToastFunction {\n  (argOpts: IOptions, timeout?: number): VoidFunction;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaief%2Faxew-toast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaief%2Faxew-toast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaief%2Faxew-toast/lists"}