Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toast): new component #279

Merged
merged 48 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
569a8cc
feat: toast component
Cr0zy07 Aug 13, 2023
f94c407
Merge branch 'main' into feat/toast-24
Cr0zy07 Aug 23, 2023
a1f0772
chore: update package
Cr0zy07 Aug 26, 2023
7858c6e
chore: update package
Cr0zy07 Aug 28, 2023
df6c21e
Merge branch 'main' into pr/279
productdevbook Aug 29, 2023
64c0d2b
chore: `Oku` typo add component name
productdevbook Aug 29, 2023
70def96
chore: refactor `context` name
productdevbook Aug 29, 2023
3f0f8a3
fix: toast-provider
productdevbook Aug 29, 2023
34d4705
chore: fix toast-viewport
productdevbook Aug 29, 2023
ffb1162
chore: fix toast-focus-proxy
productdevbook Aug 29, 2023
fe04b3e
chore: update toast
productdevbook Aug 29, 2023
fe0c7ba
chore: update toast-impl
productdevbook Aug 29, 2023
a10ec1d
fix: lint issues
autofix-ci[bot] Aug 29, 2023
f223999
chore: update toast-announce
productdevbook Aug 29, 2023
4bf211b
chore: update toast-title
productdevbook Aug 29, 2023
58683de
chore: update toast-description
productdevbook Aug 29, 2023
af484ac
chore: update toast close
productdevbook Aug 29, 2023
0509e76
chore: update toast-action
productdevbook Aug 29, 2023
4153b59
fix: children slots
productdevbook Aug 29, 2023
c69f0bd
chore: fix type
productdevbook Aug 29, 2023
92a6c9f
fix: add package packages
productdevbook Aug 29, 2023
8ab2241
chore: fix test
productdevbook Aug 29, 2023
9485986
chore: add stories
Cr0zy07 Aug 31, 2023
c625713
fix: build
Cr0zy07 Aug 31, 2023
16e613b
fix: typo
Cr0zy07 Aug 31, 2023
9edc87e
Merge branch 'main' into pr/279
productdevbook Aug 31, 2023
8f8b5e3
chore: update
productdevbook Aug 31, 2023
a7f769a
Merge branch 'main' into pr/279
productdevbook Sep 2, 2023
af79555
chore: fix merge
productdevbook Sep 2, 2023
2a170d1
chore: update
productdevbook Sep 2, 2023
b7d5221
chore: update
productdevbook Sep 2, 2023
82407fe
chore: fix
Cr0zy07 Sep 4, 2023
3af84cb
refactor: formatting
Cr0zy07 Sep 4, 2023
e58a584
fix: typo
Cr0zy07 Sep 4, 2023
716fd4e
fix: styling
Cr0zy07 Sep 4, 2023
fd96fcd
chore: fix
Cr0zy07 Sep 4, 2023
365a161
refactor: revert a change and formatting
Cr0zy07 Sep 4, 2023
c5a915c
fix: toast initial value
Cr0zy07 Sep 4, 2023
0d0202d
fix: stories style props and emits
Cr0zy07 Sep 5, 2023
fb5c37c
chore: fix
Cr0zy07 Sep 5, 2023
af408a2
fix: teleport and formatting
Cr0zy07 Sep 5, 2023
c3bbf6e
refactor: add Chromatic story
Cr0zy07 Sep 5, 2023
48fd33f
refactor: split into separate files
productdevbook Sep 6, 2023
9419ee1
Merge branch 'main' into pr/279
productdevbook Sep 6, 2023
c58e369
chore: after merge fix errors
productdevbook Sep 6, 2023
ac6b04d
fix: `Styled` and `Chromatic`
productdevbook Sep 6, 2023
4a894d4
fix: empty el
productdevbook Sep 6, 2023
ad1b174
chore: delete empty file
productdevbook Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@oku-ui/slot": "workspace:^",
"@oku-ui/switch": "workspace:^",
"@oku-ui/tabs": "workspace:^",
"@oku-ui/toast": "workspace:^",
"@oku-ui/toggle": "workspace:^",
"@oku-ui/toggle-group": "workspace:^",
"@oku-ui/toolbar": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { defineComponent, h, ref, watchEffect } from 'vue'
import { useComposedRefs, useForwardRef } from '@oku-ui/use-composable'
import { DismissableLayerContext } from './DismissableLayer'

/* -------------------------------------------------------------------------------------------------
* DismissableLayerBranch
* ----------------------------------------------------------------------------------------------- */

const BRANCH_NAME = 'OkuDismissableLayerBranch'
export type DismissableLayerBranchNaviteElement = OkuElement<'div'>
export type DismissableLayerBranchElement = HTMLDivElement
Expand Down
13 changes: 13 additions & 0 deletions packages/components/toast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# `toast`

<span><a href="https://www.npmjs.com/package/@oku-ui/toast "><img src="https://img.shields.io/npm/v/@oku-ui/toast?style=flat&colorA=18181B&colorB=28CF8D" alt="Version"></a> </span> | <span> <a href="https://www.npmjs.com/package/@oku-ui/toast"> <img src="https://img.shields.io/npm/dm/@oku-ui/toast?style=flat&colorA=18181B&colorB=28CF8D" alt="Downloads"> </a> </span> | <span> <a href="https://oku-ui.com/primitives/components/toast"><img src="https://img.shields.io/badge/Open%20Documentation-18181B" alt="Website"></a> </span>

## Installation

```sh
$ pnpm add @oku-ui/toast
```

## Usage

soon docs
7 changes: 7 additions & 0 deletions packages/components/toast/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineBuildConfig } from 'unbuild'

const isClean = (process.env.CLEAN || 'false') === 'true'
export default defineBuildConfig({
declaration: true,
clean: isClean,
})
55 changes: 55 additions & 0 deletions packages/components/toast/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@oku-ui/toast",
"type": "module",
"version": "0.2.3",
"license": "MIT",
"source": "src/index.ts",
"funding": "https://github.com/sponsors/productdevbook",
"homepage": "https://oku-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/oku-ui/primitives.git",
"directory": "packages/components/toast"
},
"bugs": {
"url": "https://github.com/oku-ui/primitives/issues"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=18"
},
"scripts": {
"build": "unbuild",
"dev": "unbuild --watch"
},
"peerDependencies": {
"vue": "^3.3.0"
},
"dependencies": {
"@oku-ui/collection": "latest",
"@oku-ui/dismissable-layer": "latest",
"@oku-ui/portal": "latest",
"@oku-ui/presence": "latest",
"@oku-ui/primitive": "latest",
"@oku-ui/provide": "latest",
"@oku-ui/use-composable": "latest",
"@oku-ui/utils": "latest",
"@oku-ui/visually-hidden": "latest"
},
"devDependencies": {
"tsconfig": "workspace:^"
},
"publishConfig": {
"access": "public"
}
}
80 changes: 80 additions & 0 deletions packages/components/toast/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
export { OkuToast } from './toast'
export { OkuToastAction } from './toast-action'
export { OkuToastAnnounce } from './toast-announce'
export { OkuToastAnnounceExclude } from './toast-announce-exclude'
export { OkuToastClose } from './toast-close'
export { OkuToastDescription } from './toast-description'
export { OkuToastFocusProxy } from './toast-focus-proxy'
export { OkuToastImpl } from './toast-impl'
export { OkuToastProvider } from './toast-provider'
export { createToastScope } from './share'
export { OkuToastTitle } from './toast-title'
export { OkuToastViewport } from './toast-viewport'

export type {
ToastProps,
ToastElement,
ToastNaviteElement,
ToastPropsEmits,
} from './toast'

export type {
ToastActionProps,
ToastActionElement,
ToastActionNaviteElement,
} from './toast-action'

export type {
ToastAnnounceProps,
ToastAnnounceElement,
ToastAnnounceNaviteElement,
} from './toast-announce'

export type {
ToastAnnounceExcludeProps,
ToastAnnounceExcludeElement,
ToastAnnounceExcludeNaviteElement,
} from './toast-announce-exclude'

export type {
ToastCloseProps,
ToastCloseElement,
ToastCloseNaviteElement,
ToastCloseEmits,
} from './toast-close'

export type {
ToastDescriptionProps,
ToastDescriptionElement,
ToastDescriptionNaviteElement,
} from './toast-description'

export type {
FocusProxyProps,
FocusProxyElement,
FocusProxyPropsEmits,
FocusProxyNativeElement,
} from './toast-focus-proxy'

export type {
ToastImplProps,
ToastImplElement,
ToastImplNaviteElement,
ToastImplPrivateEmits,
} from './toast-impl'

export type {
ToastProviderProps,
} from './toast-provider'

export type {
ToastTitleProps,
ToastTitleElement,
ToastTitleNaviteElement,
} from './toast-title'

export type {
ToastViewportProps,
ToastViewportNaviteElement,
ToastViewportElement,
} from './toast-viewport'
35 changes: 35 additions & 0 deletions packages/components/toast/src/share.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createProvideScope } from '@oku-ui/provide'
import { createCollection } from '@oku-ui/collection'
import type { Ref } from 'vue'
import type { ToastImplElement, ToastImplNaviteElement } from './toast-impl'
import type { ToastViewportElement } from './toast-viewport'

export const PROVIDER_NAME = 'OkuToastProvider'
export const TOAST_NAME = 'Toast'
export type ToastElement = ToastImplElement
export type ToastNativeElement = ToastImplNaviteElement

export const { CollectionProvider, CollectionSlot, CollectionItemSlot, useCollection, createCollectionScope } = createCollection<ToastElement>('Toast')

export type SwipeDirection = 'up' | 'down' | 'left' | 'right'
type ToastProviderProvideValue = {
label: Ref<string>
duration: Ref<number>
swipeDirection: Ref<SwipeDirection>
swipeThreshold: Ref<number>
toastCount: Ref<number>
viewport: Ref<ToastViewportElement | null>
onViewportChange(viewport: ToastViewportElement): void
onToastAdd(): void
onToastRemove(): void
isFocusedToastEscapeKeyDownRef: Ref<boolean>
isClosePausedRef: Ref<boolean>
}

export const [createToastProvide, createToastScope] = createProvideScope('Toast', [createCollectionScope])

export const [toastProviderProvider, useToastProviderInject] = createToastProvide<ToastProviderProvideValue>(PROVIDER_NAME)

export const [toastInteractiveProvider, useToastInteractiveInject] = createToastProvide(TOAST_NAME, {
onClose() { },
})
61 changes: 61 additions & 0 deletions packages/components/toast/src/stories/Animated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<script setup lang="ts">
import { OkuToast, OkuToastClose, OkuToastDescription, OkuToastProvider, OkuToastViewport } from '@oku-ui/toast'
import type { ToastProviderProps } from '@oku-ui/toast'
import { ref } from 'vue'

type Direction = ToastProviderProps['swipeDirection']

const swipeDirection = ref<Direction>('right')
const timerRef = ref(0)
const open = ref(false)

function handelAnimatedOpen() {
open.value = false
window.clearTimeout(timerRef.value)
timerRef.value = window.setTimeout(() => open.value = true, 150)
}
</script>

<template>
<OkuToastProvider
:swipe-direction="swipeDirection"
:swipe-threshold="(['up', 'down'] as Direction[]).includes(swipeDirection) ? 25 : undefined"
>
<button
type="button"
class="px-4 py-2 bg-gray-200 hover:bg-gray-300 text-gray-800 text-sm font-medium rounded-md"
@click="handelAnimatedOpen"
>
Open
</button>

<select
:value="swipeDirection"
@change="(event: any) => swipeDirection = (event.currentTarget.value as Direction)"
>
<option value="right">
Slide right
</option>
<option value="left">
Slide left
</option>
<option value="up">
Slide up
</option>
<option value="down">
Slide down
</option>
</select>
<OkuToast v-model="open" class="toast animated-toast">
<OkuToastDescription>Swipe me {{ swipeDirection }}</OkuToastDescription>
<OkuToastClose class="button">
Dismiss
</OkuToastClose>
</OkuToast>
<OkuToastViewport class="viewport" />
</OkuToastProvider>
</template>

<style lang="postcss">
@import './toast.css'
</style>
Loading
Loading