mgv-backoffice 1.34.0 → 1.35.0
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 +41 -1
- package/dist/components/BasePillPickerModal.vue.d.ts +43 -0
- package/dist/components/BaseToolbarButton.vue.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/types/pillPicker.d.ts +14 -0
- package/dist/ui-lib.css +1 -1
- package/dist/ui-lib.js +159 -58
- package/dist/ui-lib.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/components/BasePillPickerModal.test.ts +95 -0
- package/src/components/BasePillPickerModal.vue +0 -0
- package/src/components/BaseToolbarButton.test.ts +48 -0
- package/src/components/BaseToolbarButton.vue +21 -6
- package/src/index.ts +2 -0
- package/src/types/pillPicker.ts +14 -0
package/package.json
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import BasePillPickerModal from './BasePillPickerModal.vue'
|
|
4
|
+
import type { PillPickerItem } from '../types/pillPicker'
|
|
5
|
+
|
|
6
|
+
const items: PillPickerItem[] = [
|
|
7
|
+
{ id: 'STOCK:AAPL', label: 'AAPL', group: 'STOCK' },
|
|
8
|
+
{ id: 'STOCK:MSFT', label: 'MSFT', group: 'STOCK', title: 'Microsoft' },
|
|
9
|
+
{ id: 'CRYPTO:BTC/USD', label: 'BTC/USD', group: 'CRYPTO' },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
const groups = [
|
|
13
|
+
{ value: 'STOCK', label: 'Stock' },
|
|
14
|
+
{ value: 'CRYPTO', label: 'Crypto' },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
function mountPicker(props: Record<string, unknown> = {}) {
|
|
18
|
+
return mount(BasePillPickerModal, {
|
|
19
|
+
props: { title: 'Pick one', items, ...props },
|
|
20
|
+
global: { stubs: { teleport: true } },
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Pills are the buttons inside the flex-wrap grid — not the segmented
|
|
25
|
+
// control's buttons and not the footer Close.
|
|
26
|
+
function pillLabels(wrapper: ReturnType<typeof mountPicker>): string[] {
|
|
27
|
+
return wrapper
|
|
28
|
+
.findAll('.flex.flex-wrap.gap-2 > button')
|
|
29
|
+
.map((b) => b.text())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('BasePillPickerModal', () => {
|
|
33
|
+
it('renders one pill per item and emits pick with the clicked item', async () => {
|
|
34
|
+
const wrapper = mountPicker()
|
|
35
|
+
expect(pillLabels(wrapper)).toEqual(['AAPL', 'MSFT', 'BTC/USD'])
|
|
36
|
+
await wrapper.findAll('.flex.flex-wrap.gap-2 > button')[1].trigger('click')
|
|
37
|
+
expect(wrapper.emitted('pick')).toEqual([[items[1]]])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('narrows by free text, case-insensitively, and shows the no-match message', async () => {
|
|
41
|
+
const wrapper = mountPicker({ noMatchMessage: 'nothing here' })
|
|
42
|
+
await wrapper.find('input').setValue('btc')
|
|
43
|
+
expect(pillLabels(wrapper)).toEqual(['BTC/USD'])
|
|
44
|
+
await wrapper.find('input').setValue('zzz')
|
|
45
|
+
expect(wrapper.text()).toContain('nothing here')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('renders the group toggle with All prepended and narrows by group', async () => {
|
|
49
|
+
const wrapper = mountPicker({ groups })
|
|
50
|
+
// Re-query before each click — the grid re-render replaces the buttons,
|
|
51
|
+
// so a wrapper captured before a click goes stale.
|
|
52
|
+
const seg = () => wrapper.findAll('[role="group"] button')
|
|
53
|
+
expect(seg().map((b) => b.text())).toEqual(['All', 'Stock', 'Crypto'])
|
|
54
|
+
await seg()[2].trigger('click')
|
|
55
|
+
expect(pillLabels(wrapper)).toEqual(['BTC/USD'])
|
|
56
|
+
await seg()[0].trigger('click')
|
|
57
|
+
expect(pillLabels(wrapper)).toEqual(['AAPL', 'MSFT', 'BTC/USD'])
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('hides the group toggle when no groups are passed', () => {
|
|
61
|
+
const wrapper = mountPicker()
|
|
62
|
+
expect(wrapper.find('[role="group"]').exists()).toBe(false)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('shows the empty message instead of the filter row when there are no items', () => {
|
|
66
|
+
const wrapper = mountPicker({ items: [], emptyMessage: 'nothing configured' })
|
|
67
|
+
expect(wrapper.text()).toContain('nothing configured')
|
|
68
|
+
expect(wrapper.find('input').exists()).toBe(false)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('applies the mono font to the input and pills only when asked', () => {
|
|
72
|
+
const mono = mountPicker({ mono: true })
|
|
73
|
+
expect(mono.find('input').classes()).toContain('font-mono')
|
|
74
|
+
expect(mono.findAll('.flex.flex-wrap.gap-2 > button')[0].classes()).toContain('font-mono')
|
|
75
|
+
|
|
76
|
+
const plain = mountPicker()
|
|
77
|
+
expect(plain.find('input').classes()).not.toContain('font-mono')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('forwards an item title to the pill tooltip', () => {
|
|
81
|
+
const wrapper = mountPicker()
|
|
82
|
+
expect(
|
|
83
|
+
wrapper.findAll('.flex.flex-wrap.gap-2 > button')[1].attributes('title'),
|
|
84
|
+
).toBe('Microsoft')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('emits close from the footer button', async () => {
|
|
88
|
+
const wrapper = mountPicker({ closeText: 'Dismiss' })
|
|
89
|
+
const buttons = wrapper.findAll('button')
|
|
90
|
+
const closeBtn = buttons[buttons.length - 1]
|
|
91
|
+
expect(closeBtn.text()).toBe('Dismiss')
|
|
92
|
+
await closeBtn.trigger('click')
|
|
93
|
+
expect(wrapper.emitted('close')).toHaveLength(1)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
Binary file
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import BaseToolbarButton from './BaseToolbarButton.vue'
|
|
4
|
+
|
|
5
|
+
describe('BaseToolbarButton', () => {
|
|
6
|
+
it('renders the neutral pill shape by default', () => {
|
|
7
|
+
const wrapper = mount(BaseToolbarButton, { props: { label: 'Refresh' } })
|
|
8
|
+
const cls = wrapper.find('button').classes()
|
|
9
|
+
expect(cls).toContain('rounded-lg')
|
|
10
|
+
expect(cls).toContain('py-2')
|
|
11
|
+
expect(cls).toContain('font-medium')
|
|
12
|
+
expect(cls).toContain('disabled:opacity-50')
|
|
13
|
+
expect(wrapper.text()).toBe('Refresh')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps the danger variant on the pill shape with the red palette', () => {
|
|
17
|
+
const wrapper = mount(BaseToolbarButton, {
|
|
18
|
+
props: { label: 'Delete', variant: 'danger' },
|
|
19
|
+
})
|
|
20
|
+
const cls = wrapper.find('button').classes()
|
|
21
|
+
expect(cls).toContain('rounded-lg')
|
|
22
|
+
expect(cls).toContain('bg-red-600')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('renders the ghost variant as the slate h-9 rounded-md outline button', () => {
|
|
26
|
+
const wrapper = mount(BaseToolbarButton, {
|
|
27
|
+
props: { label: 'Close', variant: 'ghost' },
|
|
28
|
+
})
|
|
29
|
+
const cls = wrapper.find('button').classes()
|
|
30
|
+
expect(cls).toContain('h-9')
|
|
31
|
+
expect(cls).toContain('rounded-md')
|
|
32
|
+
expect(cls).toContain('px-4')
|
|
33
|
+
expect(cls).toContain('font-semibold')
|
|
34
|
+
expect(cls).toContain('border-slate-300')
|
|
35
|
+
expect(cls).toContain('disabled:opacity-40')
|
|
36
|
+
expect(cls).not.toContain('rounded-lg')
|
|
37
|
+
expect(cls).not.toContain('py-2')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('emits click and honours disabled', async () => {
|
|
41
|
+
const wrapper = mount(BaseToolbarButton, { props: { label: 'Go' } })
|
|
42
|
+
await wrapper.find('button').trigger('click')
|
|
43
|
+
expect(wrapper.emitted('click')).toHaveLength(1)
|
|
44
|
+
|
|
45
|
+
const disabled = mount(BaseToolbarButton, { props: { label: 'Go', disabled: true } })
|
|
46
|
+
expect(disabled.find('button').attributes('disabled')).toBeDefined()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
Props:
|
|
12
12
|
• label — button text (rendered in a <span>). Optional so an
|
|
13
13
|
icon-only toolbar button is possible.
|
|
14
|
-
• variant — 'neutral' (default grey)
|
|
14
|
+
• variant — 'neutral' (default grey), 'danger' (solid red) or
|
|
15
|
+
'ghost' (slate outline — TradeAutomation's toolbar/footer idiom).
|
|
15
16
|
• disabled — greys out + blocks the click.
|
|
16
17
|
• title — native tooltip / accessibility text.
|
|
17
18
|
• type — native button type. Defaults to 'button' so the
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
:type="type"
|
|
22
23
|
:disabled="disabled"
|
|
23
24
|
:title="title"
|
|
24
|
-
class="inline-flex shrink-0 items-center gap-2
|
|
25
|
+
class="inline-flex shrink-0 items-center gap-2 text-sm border transition-colors cursor-pointer disabled:cursor-not-allowed whitespace-nowrap focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500"
|
|
25
26
|
:class="variantClass"
|
|
26
27
|
@click="$emit('click', $event)"
|
|
27
28
|
>
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
import { computed } from 'vue'
|
|
35
36
|
import { useTheme } from '../composables/useTheme'
|
|
36
37
|
|
|
37
|
-
type ToolbarVariant = 'neutral' | 'danger'
|
|
38
|
+
type ToolbarVariant = 'neutral' | 'danger' | 'ghost'
|
|
38
39
|
|
|
39
40
|
const props = withDefaults(
|
|
40
41
|
defineProps<{
|
|
@@ -59,9 +60,19 @@ defineEmits<{
|
|
|
59
60
|
|
|
60
61
|
const { isDark } = useTheme()
|
|
61
62
|
|
|
62
|
-
// Resolves the variant + theme into
|
|
63
|
+
// Resolves the variant + theme into shape and colour classes. The danger
|
|
63
64
|
// style is normalised here so every destructive toolbar button reads
|
|
64
|
-
// identically (red-500 hover in dark, red-700 hover in light).
|
|
65
|
+
// identically (red-500 hover in dark, red-700 hover in light). Shape lives
|
|
66
|
+
// per-variant because 'ghost' — the slate outline button extracted from
|
|
67
|
+
// TradeAutomation's toolbars and modal footers — is a fixed-height
|
|
68
|
+
// rounded-md button, not the neutral/danger pill; it themes via dark:
|
|
69
|
+
// utilities so it renders the same markup in both themes.
|
|
70
|
+
const SHAPE: Record<ToolbarVariant, string> = {
|
|
71
|
+
neutral: 'px-3 py-2 rounded-lg font-medium disabled:opacity-50',
|
|
72
|
+
danger: 'px-3 py-2 rounded-lg font-medium disabled:opacity-50',
|
|
73
|
+
ghost: 'h-9 px-4 rounded-md font-semibold disabled:opacity-40 disabled:hover:bg-slate-50 dark:disabled:hover:bg-slate-900',
|
|
74
|
+
}
|
|
75
|
+
|
|
65
76
|
const variantClass = computed(() => {
|
|
66
77
|
const palette: Record<ToolbarVariant, { dark: string; light: string }> = {
|
|
67
78
|
neutral: {
|
|
@@ -72,8 +83,12 @@ const variantClass = computed(() => {
|
|
|
72
83
|
dark: 'bg-red-600 text-white border-red-600 hover:bg-red-500',
|
|
73
84
|
light: 'bg-red-600 text-white border-red-600 hover:bg-red-700',
|
|
74
85
|
},
|
|
86
|
+
ghost: {
|
|
87
|
+
dark: 'border-slate-300 dark:border-slate-600 bg-slate-50 dark:bg-slate-900 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800',
|
|
88
|
+
light: 'border-slate-300 dark:border-slate-600 bg-slate-50 dark:bg-slate-900 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800',
|
|
89
|
+
},
|
|
75
90
|
}
|
|
76
91
|
const entry = palette[props.variant]
|
|
77
|
-
return isDark.value ? entry.dark : entry.light
|
|
92
|
+
return [SHAPE[props.variant], isDark.value ? entry.dark : entry.light]
|
|
78
93
|
})
|
|
79
94
|
</script>
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ export { default as BaseSpecFields } from './components/BaseSpecFields.vue'
|
|
|
49
49
|
export { default as BaseStatBreakdown } from './components/BaseStatBreakdown.vue'
|
|
50
50
|
export { default as BaseFilterChip } from './components/BaseFilterChip.vue'
|
|
51
51
|
export { default as BaseCredentialsForm } from './components/BaseCredentialsForm.vue'
|
|
52
|
+
export { default as BasePillPickerModal } from './components/BasePillPickerModal.vue'
|
|
52
53
|
export type { CredentialsView, CredentialsUpdate } from './components/BaseCredentialsForm.vue'
|
|
53
54
|
|
|
54
55
|
// Composables
|
|
@@ -92,6 +93,7 @@ export type { DropdownOption } from './types/dropdown'
|
|
|
92
93
|
export type { TableColumn } from './types/table'
|
|
93
94
|
export type { SpecField, SpecFieldType, SpecFieldValue } from './types/specField'
|
|
94
95
|
export type { StatBreakdownItem } from './types/statBreakdown'
|
|
96
|
+
export type { PillPickerItem } from './types/pillPicker'
|
|
95
97
|
|
|
96
98
|
// Utils
|
|
97
99
|
export { getBaseColor, getBaseColorOf } from './utils/util'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One clickable pill in a BasePillPickerModal.
|
|
3
|
+
*
|
|
4
|
+
* `id` must be unique (it keys the pill and identifies the pick),
|
|
5
|
+
* `label` is what the pill shows and what the free-text filter matches,
|
|
6
|
+
* `group` assigns the pill to one of the modal's segmented-filter groups,
|
|
7
|
+
* `title` becomes the pill's tooltip.
|
|
8
|
+
*/
|
|
9
|
+
export interface PillPickerItem {
|
|
10
|
+
id: string
|
|
11
|
+
label: string
|
|
12
|
+
group?: string
|
|
13
|
+
title?: string
|
|
14
|
+
}
|