@mlightcad/ui-components 0.1.3 → 0.1.5

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 CHANGED
@@ -223,19 +223,21 @@ const handleTabClose = (tabName: string) => {
223
223
 
224
224
  ### Toolbar
225
225
 
226
- Toolbar component has the followiing features.
226
+ Toolbar component has the following features.
227
227
 
228
- - Define button list by one array of `MlButtonData`
229
- - Arrange button vertically or horizontally
230
- - Support three kind of button size
228
+ - Define button list by one array of `MlButtonData`
229
+ - Arrange button vertically or horizontally
230
+ - Support three kinds of button size
231
+ - **Support toggle buttons with two states (on / off)**
232
+ - **Support sub-toolbars (popover buttons)**
231
233
 
232
- <img src="./doc/toolbar.jpg" width="423" height="223" alt="ViewCube Example">
234
+ <img src="./doc/toolbar.jpg" width="423" height="223" alt="Toolbar Example">
233
235
 
234
236
  Features above can be customized by the following properties.
235
237
 
236
- ```javascript
238
+ ```
237
239
  /**
238
- * Properties of MLToolBar components
240
+ * Properties of MLToolBar component
239
241
  */
240
242
  interface Props {
241
243
  /**
@@ -248,45 +250,99 @@ interface Props {
248
250
  * - medium: 50px
249
251
  * - large: 70px
250
252
  */
251
- size?: 'small' | 'medium'| 'large'
253
+ size?: 'small' | 'medium' | 'large'
252
254
  /**
253
255
  * Layout type.
254
256
  * - vertical: arrange button vertically
255
257
  * - horizontal: arrange button horizontally
256
258
  */
257
259
  direction?: 'vertical' | 'horizontal'
260
+ /**
261
+ * Placement of sub toolbar (popover)
262
+ * - vertical toolbar: left / right variants
263
+ * - horizontal toolbar: top / bottom variants
264
+ */
265
+ placement?: VerticalPlacement | HorizontalPlacement
258
266
  }
259
267
  ```
260
268
 
261
- Buttons in toolbar are described by the following data. Property `icon` can be icon provided by Element Plus or icon imported through `vite-svg-loader`.
269
+ #### Button Definition
262
270
 
263
- ```javascript
271
+ Buttons in toolbar are described by the following data structure.
272
+ Property `icon` can be an icon provided by Element Plus or an icon imported through `vite-svg-loader`.
273
+
274
+ ```
264
275
  /**
265
276
  * Data to descibe button appearance
266
277
  */
267
278
  export interface MlButtonData {
268
279
  /**
269
- * Icon represented by one vue component
280
+ * Command string which will be passed to click event as event arguments
270
281
  */
271
- icon: Component
282
+ command: string
272
283
  /**
273
- * Text shown below icon
284
+ * Sub toolbar data. If this property is set, the button will have a sub toolbar.
274
285
  */
275
- text: string
286
+ children?: MlButtonData[]
276
287
  /**
277
- * Command string which will be passed to click event as event arguments
288
+ * Toggle button configuration.
289
+ * If this property is set, the button becomes a toggle button.
278
290
  */
279
- command: string
291
+ toggle?: {
292
+ /**
293
+ * Initial toggle value
294
+ */
295
+ value?: boolean
296
+ /**
297
+ * Appearance when toggle is ON
298
+ */
299
+ on: {
300
+ icon: Component
301
+ text: string
302
+ description: string
303
+ }
304
+ /**
305
+ * Appearance when toggle is OFF
306
+ */
307
+ off: {
308
+ icon: Component
309
+ text: string
310
+ description: string
311
+ }
312
+ }
313
+ /**
314
+ * Icon represented by one vue component
315
+ * ⚠️ Ignored when toggle is defined
316
+ */
317
+ icon?: Component
318
+ /**
319
+ * Text shown below icon
320
+ * ⚠️ Ignored when toggle is defined
321
+ */
322
+ text?: string
280
323
  /**
281
324
  * Tooltips content when hover
325
+ * ⚠️ Ignored when toggle is defined
282
326
  */
283
327
  description?: string
284
328
  }
285
329
  ```
286
330
 
287
- Usage of this component is as follows.
331
+ #### Events
288
332
 
289
- ```javascript
333
+ Toolbar emits the following events:
334
+
335
+ ```
336
+ @click(command: string)
337
+ @toggle(command: string, value: boolean)
338
+ ```
339
+
340
+ - `click`: emitted when a normal button or sub-button is clicked
341
+ - `toggle`: emitted when a toggle button changes state
342
+
343
+ #### Basic Usage
344
+
345
+ ```
290
346
  <script setup lang="ts">
291
347
  import '@mlightcad/ui-components/dist/style.css'
292
348
  import { MlButtonData, MlToolbar } from '@mlightcad/ui-components'
@@ -320,10 +376,56 @@ const handleCommand = (command: string) => {
320
376
  </script>
321
377
 
322
378
  <template>
323
- <div>
324
- <ml-toolbar :items="data" layout="vertical" @click="handleCommand"/>
325
- </div>
379
+ <ml-toolbar
380
+ :items="data"
381
+ direction="vertical"
382
+ @click="handleCommand"
383
+ />
326
384
  </template>
385
+ ```
386
+
387
+ #### Toggle Button Example
388
+
389
+ Toolbar supports **toggle buttons** that have two states and can display different icons and texts for each state.
390
+
391
+ ```
392
+ import { View, Hide } from '@element-plus/icons-vue'
393
+
394
+ const data = reactive<MlButtonData[]>([
395
+ {
396
+ command: 'view.visibility',
397
+ toggle: {
398
+ value: true,
399
+ on: {
400
+ icon: View,
401
+ text: 'Show'
402
+ description: 'Shows entity'
403
+ },
404
+ off: {
405
+ icon: Hide,
406
+ text: 'Hide'
407
+ description: 'Shows entity'
408
+ }
409
+ }
410
+ }
411
+ ])
412
+ ```
413
+
414
+ ```
415
+ <ml-toolbar
416
+ :items="data"
417
+ @toggle="(command, value) => {
418
+ console.log(command, value)
419
+ }"
420
+ />
421
+ ```
422
+
423
+ - Initial state is controlled by `toggle.value`
424
+ - Clicking the button switches between **on / off**
425
+ - Icon and text are updated automatically
426
+ - Current state is emitted via `@toggle`
427
+
428
+ #### Notes
327
429
 
328
- <style></style>
329
- ```
430
+ - Toggle buttons and sub-toolbars can coexist with normal buttons
431
+ - Toggle state is internally managed by the toolbar (uncontrolled by default)