@mlightcad/ui-components 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/dist/ui-components.es.js +358 -300
- package/dist/ui-components.umd.js +2 -2
- package/lib/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/components/MlToolBar.vue +2 -0
- package/src/components/MlToolPalette.vue +158 -4
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ The following components are included in this package.
|
|
|
9
9
|
- Tool Palette: one dockable, resizable, and floating window, which is quite similar to AutoCAD Tool Palette.
|
|
10
10
|
- Toolbar: one toolbar which can be easily customized by one array of button data.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
[**🌐 Live Demo**](https://mlightcad.gitlab.io/ui-components/).
|
|
13
13
|
|
|
14
14
|
### Tool Palette
|
|
15
15
|
|
|
@@ -32,6 +32,10 @@ interface Props {
|
|
|
32
32
|
* The title of tool palette dialog
|
|
33
33
|
*/
|
|
34
34
|
title?: string
|
|
35
|
+
/**
|
|
36
|
+
* Array of tab definitions. If provided, the tool palette will display tabs.
|
|
37
|
+
*/
|
|
38
|
+
tabs?: MlToolPaletteTab[]
|
|
35
39
|
/**
|
|
36
40
|
* The minimum distance from the left side of the tool palette to the left side of the window
|
|
37
41
|
*/
|
|
@@ -51,8 +55,32 @@ interface Props {
|
|
|
51
55
|
}
|
|
52
56
|
```
|
|
53
57
|
|
|
58
|
+
Tabs in tool palette are described by the following data structure.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
/**
|
|
62
|
+
* Tab definition for tool palette
|
|
63
|
+
*/
|
|
64
|
+
export interface MlToolPaletteTab {
|
|
65
|
+
/**
|
|
66
|
+
* Unique name identifier for the tab
|
|
67
|
+
*/
|
|
68
|
+
name: string
|
|
69
|
+
/**
|
|
70
|
+
* Display label for the tab
|
|
71
|
+
*/
|
|
72
|
+
label: string
|
|
73
|
+
/**
|
|
74
|
+
* Title to display in the title bar when this tab is active
|
|
75
|
+
*/
|
|
76
|
+
title?: string
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
54
80
|
Four `offsetXXX` properties are used to set the minimum distance from the side of the tool palette to the side of the window. It is quite useful if you want the tool palette is shown within certain area. For example, one web page has one title bar at the top of window, one status bar at the bottom of window, and one canvas area between the title bar and the status bar. The height of the title bar is 60px and the height of the status bar is 20px. Then you can set `topOffset` to 60 and `bottomOffset` to 20 to let the tool palette are shown and moved within canvas area only.
|
|
55
81
|
|
|
82
|
+
#### Basic Usage
|
|
83
|
+
|
|
56
84
|
```javascript
|
|
57
85
|
<script lang="ts" setup>
|
|
58
86
|
import { MlToolPalette } from '@mlightcad/ui-components'
|
|
@@ -80,6 +108,119 @@ const toolPaletteVisible = ref<boolean>(false)
|
|
|
80
108
|
</style>
|
|
81
109
|
```
|
|
82
110
|
|
|
111
|
+
#### Using Tabs
|
|
112
|
+
|
|
113
|
+
Tool Palette supports multiple tabs to organize different content. Each tab can have its own content and title. When a tab becomes active, its `title` (if provided) will be displayed in the title bar of the tool palette.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
<script lang="ts" setup>
|
|
117
|
+
import { MlToolPalette, MlToolPaletteTab } from '@mlightcad/ui-components'
|
|
118
|
+
import { ref, reactive } from 'vue'
|
|
119
|
+
|
|
120
|
+
const toolPaletteVisible = ref<boolean>(true)
|
|
121
|
+
const activeTab = ref<string>('blocks')
|
|
122
|
+
|
|
123
|
+
const tabs = reactive<MlToolPaletteTab[]>([
|
|
124
|
+
{
|
|
125
|
+
name: 'blocks',
|
|
126
|
+
label: 'Blocks',
|
|
127
|
+
title: 'Blocks Palette'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'hatches',
|
|
131
|
+
label: 'Hatches',
|
|
132
|
+
title: 'Hatches Palette'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'tools',
|
|
136
|
+
label: 'Tools',
|
|
137
|
+
title: 'Custom Tools'
|
|
138
|
+
}
|
|
139
|
+
])
|
|
140
|
+
|
|
141
|
+
const handleTabChange = (tabName: string) => {
|
|
142
|
+
console.log('Tab changed to:', tabName)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const handleTabClose = (tabName: string) => {
|
|
146
|
+
console.log('Tab closed:', tabName)
|
|
147
|
+
const index = tabs.findIndex(t => t.name === tabName)
|
|
148
|
+
if (index >= 0) {
|
|
149
|
+
tabs.splice(index, 1)
|
|
150
|
+
// If the closed tab was active, switch to another tab
|
|
151
|
+
if (activeTab.value === tabName && tabs.length > 0) {
|
|
152
|
+
activeTab.value = tabs[0].name
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<template>
|
|
159
|
+
<ml-tool-palette
|
|
160
|
+
class="tool-palette"
|
|
161
|
+
v-model="toolPaletteVisible"
|
|
162
|
+
v-model:active-tab="activeTab"
|
|
163
|
+
title="Tool Palette"
|
|
164
|
+
:tabs="tabs"
|
|
165
|
+
:top-offset="60"
|
|
166
|
+
:bottom-offset="20"
|
|
167
|
+
@tab-change="handleTabChange"
|
|
168
|
+
@tab-close="handleTabClose"
|
|
169
|
+
>
|
|
170
|
+
<template #tab-blocks>
|
|
171
|
+
<div class="tab-content">
|
|
172
|
+
<h3>Blocks</h3>
|
|
173
|
+
<p>This is the Blocks tab content.</p>
|
|
174
|
+
<el-button>Block 1</el-button>
|
|
175
|
+
<el-button>Block 2</el-button>
|
|
176
|
+
</div>
|
|
177
|
+
</template>
|
|
178
|
+
<template #tab-hatches>
|
|
179
|
+
<div class="tab-content">
|
|
180
|
+
<h3>Hatches</h3>
|
|
181
|
+
<p>This is the Hatches tab content.</p>
|
|
182
|
+
<el-button>Hatch Pattern 1</el-button>
|
|
183
|
+
<el-button>Hatch Pattern 2</el-button>
|
|
184
|
+
</div>
|
|
185
|
+
</template>
|
|
186
|
+
<template #tab-tools>
|
|
187
|
+
<div class="tab-content">
|
|
188
|
+
<h3>Custom Tools</h3>
|
|
189
|
+
<p>This is the Tools tab content.</p>
|
|
190
|
+
<el-button>Custom Tool 1</el-button>
|
|
191
|
+
<el-button>Custom Tool 2</el-button>
|
|
192
|
+
</div>
|
|
193
|
+
</template>
|
|
194
|
+
</ml-tool-palette>
|
|
195
|
+
</template>
|
|
196
|
+
|
|
197
|
+
<style scoped>
|
|
198
|
+
.tool-palette {
|
|
199
|
+
position: fixed;
|
|
200
|
+
top: 55px;
|
|
201
|
+
width: 400px;
|
|
202
|
+
height: 500px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.tab-content {
|
|
206
|
+
padding: 16px;
|
|
207
|
+
display: flex;
|
|
208
|
+
flex-direction: column;
|
|
209
|
+
gap: 12px;
|
|
210
|
+
}
|
|
211
|
+
</style>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Tab Features:**
|
|
215
|
+
- **Closeable tabs**: Each tab has a close icon that can be clicked to close the tab
|
|
216
|
+
- **Active tab title**: When a tab is active, its `title` property (if provided) is displayed in the title bar
|
|
217
|
+
- **Tab switching**: Use `v-model:active-tab` to control which tab is active
|
|
218
|
+
- **Tab events**:
|
|
219
|
+
- `@tab-change`: Emitted when the active tab changes
|
|
220
|
+
- `@tab-close`: Emitted when a tab is closed
|
|
221
|
+
- **Tab content**: Use named slots `#tab-{name}` to provide content for each tab
|
|
222
|
+
- **Overflow handling**: When there are many tabs, Element Plus automatically handles overflow with a dropdown menu
|
|
223
|
+
|
|
83
224
|
### Toolbar
|
|
84
225
|
|
|
85
226
|
Toolbar component has the followiing features.
|