Skip to content

Commit 42066c6

Browse files
committed
feat(shared): 新增工具栏组件
1 parent 9186095 commit 42066c6

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

src/shared/toolbar/index.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
:where(.kit-toolbar) {
2+
--gap: calc(1em * 0.8);
3+
--title-font-size: calc(1em + 2px);
4+
--title-font-weight: 600;
5+
--divider-color: #a0a0a0;
6+
7+
display: flex;
8+
justify-content: space-between;
9+
align-items: center;
10+
gap: var(--gap);
11+
}
12+
13+
:where(.kit-toolbar),
14+
:where(.kit-toolbar) [class^='kit-toolbar__'] {
15+
box-sizing: border-box;
16+
}
17+
18+
:where(.kit-toolbar) > .kit-toolbar__left {
19+
position: relative;
20+
display: flex;
21+
align-items: center;
22+
}
23+
24+
:where(.kit-toolbar) > .kit-toolbar__left > .kit-toolbar__title {
25+
font-size: var(--title-font-size);
26+
font-weight: var(--title-font-weight);
27+
}
28+
29+
:where(.kit-toolbar) > .kit-toolbar__left > .kit-toolbar__divider {
30+
position: relative;
31+
display: inline-block;
32+
width: 1px;
33+
height: 1em;
34+
border-left: 1px var(--divider-color) solid;
35+
margin: 0 0.6em;
36+
vertical-align: middle;
37+
}
38+
39+
:where(.kit-toolbar)
40+
> .kit-toolbar__left:has(> .kit-toolbar__title:empty, > .kit-toolbar__content:empty)
41+
> .kit-toolbar__divider {
42+
display: none;
43+
}
44+
45+
:where(.kit-toolbar) > .kit-toolbar__left > .kit-toolbar__content,
46+
:where(.kit-toolbar) > .kit-toolbar__extra {
47+
position: relative;
48+
display: flex;
49+
align-items: center;
50+
gap: var(--gap);
51+
}
52+
53+
:where(.kit-toolbar) > .kit-toolbar__left > .kit-toolbar__content > *,
54+
:where(.kit-toolbar) > .kit-toolbar__extra > * {
55+
margin-left: 0 !important;
56+
margin-right: 0 !important;
57+
}

src/shared/toolbar/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Toolbar } from './index.vue'
2+
export type * from './interface'

src/shared/toolbar/index.vue

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script setup lang="ts">
2+
import type { ToolbarProps, ToolbarSlots } from './interface'
3+
import { loadCSS } from '@/internal/load-css'
4+
import css from './index.css?raw'
5+
6+
defineOptions({
7+
__cKitStaticCSS: css,
8+
})
9+
10+
defineProps<ToolbarProps>()
11+
12+
defineSlots<ToolbarSlots>()
13+
14+
loadCSS()
15+
16+
const ns = 'kit-toolbar'
17+
</script>
18+
19+
<template>
20+
<div :class="ns">
21+
<div :class="[`${ns}__left`]">
22+
<div
23+
:style="titleStyle"
24+
:class="[`${ns}__title`, titleClass]"
25+
>
26+
<slot name="title">
27+
{{ title }}
28+
</slot>
29+
</div>
30+
31+
<div :class="[`${ns}__divider`]" />
32+
33+
<div
34+
:class="[`${ns}__content`, contentClass]"
35+
:style="contentStyle"
36+
>
37+
<slot />
38+
</div>
39+
</div>
40+
41+
<div
42+
:class="[`${ns}__extra`, extraClass]"
43+
:style="extraStyle"
44+
>
45+
<slot name="extra" />
46+
</div>
47+
</div>
48+
</template>

src/shared/toolbar/interface.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { StyleValue, VNodeChild } from 'vue'
2+
3+
export interface ToolbarProps {
4+
titleStyle?: StyleValue
5+
titleClass?: any
6+
7+
contentStyle?: StyleValue
8+
contentClass?: any
9+
10+
extraStyle?: StyleValue
11+
extraClass?: any
12+
13+
/**
14+
* 标题,优先级低于 title 插槽
15+
*/
16+
title?: string
17+
}
18+
19+
export interface ToolbarSlots {
20+
title: () => VNodeChild
21+
default: () => VNodeChild
22+
extra: () => VNodeChild
23+
}

0 commit comments

Comments
 (0)