forked from buefy/buefy
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TypeScript Rollout Tier 5 - Toast (#349)
* feat(lib): rewrite Toast in TS - Rewrites `Toast` in TypeScript: - Defines a new type `ToastProps` that represents the props type of `Toast`. `ToastOpenParams` extends this (see below). Trivial changes: - Adds `lang="ts"` to the script section - Wraps the entire component definition with `defineComponent` API - Rewrites `component/toast/index.js` in TypeScript: - Defines a new type `ToastOpenParams` that represents the parameters type for `open`. `ToastOpenParams` accepts `VNode`(s) as `message` in addition to `string`(s). - Defines a new type `ToastProgrammaticInstance` that has the minimal interface of a programmatically opened `Toast` instance The following changes might not be trivial: - Renders `VNode` and an array of `VNode`(s) or `string`(s) through the slot. It used to render an array through the slot, but a single `VNode` also had to be rendered in the slot, otherwise `v-html` binding would try to stringify it. - Removes `params.parent` because it no longer has any effect - Replaces the `merge` helper function with spread syntax to provide the default value for `position` Trivial changes: - Replaces the extension: `.js` → `.ts` - Gives minimal types * test(lib): rewrite Toast.spec in TS - Rewrites `Toast.spec.js` in TypeScript: - Replaces `jest` API calls with those of `vi`: `fn`, `uesFakeTimers`, `useRealTimers`, and `advanceTimersByTime` - Replaces the extension: `.js` → `.ts` - Imports necessary functions and object from `vitest` - Gives minimal types Replaces the spec snapshot `Toast.spec.js.snap` with the one generated by `vitest` → `Toast.spec.ts.snap`. * feat(lib): add `toast` to `$buefy` Binds `$buefy.toast` to `ToastProgrammatic`. * chore(lib): bundle Toast as TS `rollup.config.mjs` removes "toast" from `JS_COMPONENTS`. * feat(docs): rewrite Toast examples in TS Rewrites example components in `pages/components/toast` in TypeScript. Most of the changes are straightforward. In `examples/ExSimple.vue`: - Extraction of the type of a programmatically opened toast instance might look tricky (`ToastProgrammaticInstance`) In `Toast.vue`: - Separates the code snippet to an external file `outside-vue-instance.js` because dev build might treat it as the actual code and end up with an unresolved module error Here is a TypeScript migration tip: - Explicitly import and register components so that they are type checked. No type-checking is performed for globally registered components.
- Loading branch information
Showing
12 changed files
with
109 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ const JS_COMPONENTS = [ | |
'tag', | ||
'taginput', | ||
'timepicker', | ||
'toast', | ||
'upload', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
packages/buefy-next/src/components/toast/__snapshots__/Toast.spec.js.snap
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
packages/buefy-next/src/components/toast/__snapshots__/Toast.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`BToast > render correctly 1`] = ` | ||
"<transition-stub enteractiveclass=\\"fadeInDown\\" leaveactiveclass=\\"fadeOut\\" appear=\\"false\\" persisted=\\"true\\" css=\\"true\\"> | ||
<div class=\\"toast is-dark is-top\\" aria-hidden=\\"false\\" role=\\"alert\\" style=\\"\\"> | ||
<!-- eslint-disable-next-line vue/no-v-html --> | ||
<div></div> | ||
</div> | ||
</transition-stub>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/docs/src/pages/components/toast/outside-vue-instance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { ToastProgrammatic as Toast } from 'buefy' | ||
Toast.open('Toasty!') |
File renamed without changes.