Skip to content

Commit

Permalink
feat: Popconfirm component
Browse files Browse the repository at this point in the history
  • Loading branch information
AntzyMo committed Oct 12, 2024
1 parent f7f68de commit 66da499
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 5 deletions.
16 changes: 16 additions & 0 deletions docs/components/content/Popconfirm/PopconfirmBasic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { Button, Popconfirm } from '@lite-space/ui'
</script>

<template>
<Popconfirm
title="Delete the task"
description="Are you sure to delete this task?"
ok-text="Yes"
cancel-text="No"
>
<Button danger>
Delete
</Button>
</Popconfirm>
</template>
53 changes: 53 additions & 0 deletions docs/components/content/Popconfirm/PopconfirmPlacement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script setup lang="ts">
import { Button, Popconfirm, Space } from '@lite-space/ui'
const [DefineTemplate, ReuseTemplate] = createReusableTemplate()
</script>

<template>
<DefineTemplate v-slot="{ placement, text }">
<Popconfirm
title="Delete the task"
description="Are you sure to delete this task?"
ok-text="Yes"
cancel-text="No"
:placement="placement"
>
<Button class="w-18">
{{ text }}
</Button>
</Popconfirm>
</DefineTemplate>
<div px-6>
<div ml-20>
<Space>
<ReuseTemplate placement="top-start" text="TL" />
<ReuseTemplate placement="top" text="Top" />
<ReuseTemplate placement="top-end" text="TR" />
</Space>
</div>
<div flex="~ items-center justify-between">
<div>
<Space direction="vertical">
<ReuseTemplate placement="left-start" text="LT" />
<ReuseTemplate placement="left" text="Left" />
<ReuseTemplate placement="left-end" text="LB" />
</Space>
</div>
<div>
<Space direction="vertical">
<ReuseTemplate placement="right-start" text="RT" />
<ReuseTemplate placement="right" text="Right" />
<ReuseTemplate placement="right-end" text="RB" />
</Space>
</div>
</div>
<div ml-20>
<Space>
<ReuseTemplate placement="bottom-start" text="BL" />
<ReuseTemplate placement="bottom" text="Bottom" />
<ReuseTemplate placement="bottom-end" text="BR" />
</Space>
</div>
</div>
</template>
90 changes: 90 additions & 0 deletions docs/content/docs/components/popconfirm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: Popconfirm 气泡确认框
description: 点击元素,弹出气泡式的确认框。
---

## Installation

::CodePreview{title="基本用法" src="PopconfirmBasic"}
最简单的用法,支持确认标题和描述。
#code
```vue
<script setup lang="ts">
import { Button, Popconfirm } from '@lite-space/ui'
</script>
<template>
<Popconfirm
title="Delete the task"
description="Are you sure to delete this task?"
ok-text="Yes"
cancel-text="No"
>
<Button danger>
Delete
</Button>
</Popconfirm>
</template>
```
::

::CodePreview{title="位置" src="PopconfirmPlacement"}
位置有 12 个方向。

#code
```vue
<script setup lang="ts">
import { Button, Popconfirm, Space } from '@lite-space/ui'
const [DefineTemplate, ReuseTemplate] = createReusableTemplate()
</script>
<template>
<DefineTemplate v-slot="{ placement, text }">
<Popconfirm
title="Delete the task"
description="Are you sure to delete this task?"
ok-text="Yes"
cancel-text="No"
:placement="placement"
>
<Button class="w-18">
{{ text }}
</Button>
</Popconfirm>
</DefineTemplate>
<div px-6>
<div ml-20>
<Space>
<ReuseTemplate placement="top-start" text="TL" />
<ReuseTemplate placement="top" text="Top" />
<ReuseTemplate placement="top-end" text="TR" />
</Space>
</div>
<div flex="~ items-center justify-between">
<div>
<Space direction="vertical">
<ReuseTemplate placement="left-start" text="LT" />
<ReuseTemplate placement="left" text="Left" />
<ReuseTemplate placement="left-end" text="LB" />
</Space>
</div>
<div>
<Space direction="vertical">
<ReuseTemplate placement="right-start" text="RT" />
<ReuseTemplate placement="right" text="Right" />
<ReuseTemplate placement="right-end" text="RB" />
</Space>
</div>
</div>
<div ml-20>
<Space>
<ReuseTemplate placement="bottom-start" text="BL" />
<ReuseTemplate placement="bottom" text="Bottom" />
<ReuseTemplate placement="bottom-end" text="BR" />
</Space>
</div>
</div>
</template>
```
::
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@antzy/eslint-config": "^3.3.2",
"@iconify-json/carbon": "^1.1.36",
"@iconify-json/heroicons": "^1.2.1",
"@unocss/nuxt": "^0.61.9",
"@unocss/reset": "^0.61.9",
"@vueuse/nuxt": "^10.11.1",
Expand Down
4 changes: 4 additions & 0 deletions docs/utils/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export const toc: Toc[] = [
{
title: 'Popover 气泡卡片',
path: '/docs/components/popover'
},
{
title: 'Popconfirm 气泡确认框',
path: '/docs/components/popconfirm'
}
]
}
Expand Down
38 changes: 38 additions & 0 deletions packages/components/Popconfirm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@lite-space/popconfirm",
"type": "module",
"version": "0.0.0",
"keywords": [
"vue3",
"component",
"unocss",
"popconfirm"
],
"publishConfig": {
"access": "public",
"main": "dist/index.mjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts"
},
"main": "src/index.ts",
"module": "src/index.ts",
"types": "src/index.ts",
"files": [
"README.md",
"dist",
"package.json"
],
"scripts": {
"build": "mkdist -d"
},
"dependencies": {
"@lite-space/button": "workspace:*",
"@lite-space/tooltip": "workspace:*"
},
"devDependencies": {
"@vue/tsconfig": "^0.5.1",
"mkdist": "^1.5.4",
"typescript": "^5.2.2",
"vue": "^3.5.9"
}
}
65 changes: 65 additions & 0 deletions packages/components/Popconfirm/src/Popconfirm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<script setup lang="ts">
import type { PopconfirmProps } from './types'
import { Button } from '@lite-space/button'
import { Tooltip } from '@lite-space/tooltip'
defineOptions({
name: 'LtPopconfirm'
})
withDefaults(defineProps<PopconfirmProps>(), {
showCancel: true
})
defineEmits<{
confirm: []
cancel: []
}>()
defineSlots<{
default: () => any
icon: () => any
title: () => any
description: () => any
}>()
</script>

<template>
<Tooltip trigger="click" :placement="$props.placement" :offset="8">
<slot />
<template #content>
<div class="lt-popconfirm">
<div class="lt-popconfirm-message">
<div class="lt-popconfirm-message-icon">
<slot name="icon">
<span
class="lt-popconfirm-message-icon-inner"
:class="[icon ? icon : 'i-heroicons:exclamation-circle-16-solid text-amber-400']"
/>
</slot>
</div>
<div class="lt-popconfirm-message-text">
<div class="lt-popconfirm-message-text-title">
<slot name="title">
{{ title }}
</slot>
</div>
<div v-if="$slots.description || description" class="mt-1">
<slot name="description">
{{ description }}
</slot>
</div>
</div>
</div>
<div class=" lt-popconfirm-buttons">
<Button v-if="showCancel" size="small" @click="$emit('cancel')">
{{ cancelText }}
</Button>
<Button size="small" type="primary" @click="$emit('confirm')">
{{ okText }}
</Button>
</div>
</div>
</template>
</Tooltip>
</template>
2 changes: 2 additions & 0 deletions packages/components/Popconfirm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Popconfirm } from './Popconfirm.vue'
export type * from './types'
13 changes: 13 additions & 0 deletions packages/components/Popconfirm/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { TooltipProps } from '@lite-space/tooltip'

interface LtPopconfirmProps extends Pick<TooltipProps, 'placement'> {
title: string
description: string
okText: string
cancelText: string
icon: string
showCancel: boolean
}

export type PopconfirmProps = Partial<LtPopconfirmProps>
export type PopconfirmInstance = InstanceType<typeof import('./Popconfirm.vue')['default']>
9 changes: 9 additions & 0 deletions packages/components/Popconfirm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo"
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"],
"exclude": ["node_modules/*", "src/**/__test__/*"]
}
11 changes: 11 additions & 0 deletions packages/lite-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @lite-space/ui

## 0.4.0

### Minor Changes

- @lite-space/popconfirm@0.0.0

### Patch Changes

- Updated dependencies
- @lite-space/theme@0.4.0

## 0.3.0

### Minor Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/lite-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lite-space/ui",
"type": "module",
"version": "0.3.0",
"version": "0.4.0",
"description": "A Vue3 based UnoCSS UI library.",
"author": "AntzyMo <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -41,6 +41,7 @@
"@lite-space/icon": "workspace:*",
"@lite-space/input": "workspace:*",
"@lite-space/menu": "workspace:*",
"@lite-space/popconfirm": "workspace:*",
"@lite-space/popover": "workspace:*",
"@lite-space/radio": "workspace:*",
"@lite-space/space": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/lite-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from '@lite-space/empty'
export * from '@lite-space/icon'
export * from '@lite-space/input'
export * from '@lite-space/menu'
export * from '@lite-space/popconfirm'
export * from '@lite-space/popover'
export * from '@lite-space/radio'
export * from '@lite-space/space'
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @lite-space/theme

## 0.4.0

### Minor Changes

- @lite-space/popconfirm@0.0.0

## 0.3.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lite-space/theme",
"type": "module",
"version": "0.3.0",
"version": "0.4.0",
"description": "unocss preset for lite-ui",
"author": "AntzyMo <[email protected]>",
"license": "MIT",
Expand Down
10 changes: 10 additions & 0 deletions packages/theme/src/shortcuts/Popconfirm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const Popconfirm = {
'lt-popconfirm': 'px-1.5 py-2.5',
'lt-popconfirm-message': 'flex items-start mb-2',
'lt-popconfirm-message-icon': 'w-5.5 h-5.5',
'lt-popconfirm-message-icon-inner': 'inline-block pt-.6 text-base',
'lt-popconfirm-message-text': 'text-sm',
'lt-popconfirm-message-text-title': 'font-600',
'lt-popconfirm-buttons': 'flex justify-end gap-2'

}
Loading

0 comments on commit 66da499

Please sign in to comment.