nexa-ui-kit 0.6.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/dist/NBadge.nexa +40 -0
- package/dist/NBottomSheet.nexa +124 -0
- package/dist/NButton.nexa +123 -0
- package/dist/NCard.nexa +74 -0
- package/dist/NInput.nexa +116 -0
- package/dist/NModal.nexa +165 -0
- package/dist/NSelect.nexa +169 -0
- package/dist/NToastContainer.nexa +86 -0
- package/dist/NTooltip.nexa +115 -0
- package/dist/components/NAlert.js +134 -0
- package/dist/components/NAlert.nexa +115 -0
- package/dist/components/NAutocomplete.js +94 -0
- package/dist/components/NAutocomplete.nexa +58 -0
- package/dist/components/NAvatar.js +75 -0
- package/dist/components/NAvatar.nexa +67 -0
- package/dist/components/NBadge.js +74 -0
- package/dist/components/NBadge.nexa +61 -0
- package/dist/components/NBottomSheet.js +149 -0
- package/dist/components/NBottomSheet.nexa +145 -0
- package/dist/components/NButton.js +284 -0
- package/dist/components/NButton.nexa +275 -0
- package/dist/components/NCard.js +117 -0
- package/dist/components/NCard.nexa +100 -0
- package/dist/components/NCheckbox.js +108 -0
- package/dist/components/NCheckbox.nexa +90 -0
- package/dist/components/NChips.js +72 -0
- package/dist/components/NChips.nexa +57 -0
- package/dist/components/NDataTable.js +252 -0
- package/dist/components/NDataTable.nexa +186 -0
- package/dist/components/NDatepicker.js +379 -0
- package/dist/components/NDatepicker.nexa +367 -0
- package/dist/components/NForm.js +132 -0
- package/dist/components/NForm.nexa +133 -0
- package/dist/components/NFormField.js +173 -0
- package/dist/components/NFormField.nexa +171 -0
- package/dist/components/NInput.js +311 -0
- package/dist/components/NInput.nexa +311 -0
- package/dist/components/NInputNumber.js +202 -0
- package/dist/components/NInputNumber.nexa +199 -0
- package/dist/components/NModal.js +221 -0
- package/dist/components/NModal.nexa +221 -0
- package/dist/components/NMultiSelect.js +156 -0
- package/dist/components/NMultiSelect.nexa +77 -0
- package/dist/components/NPaginator.js +117 -0
- package/dist/components/NPaginator.nexa +77 -0
- package/dist/components/NPassword.js +193 -0
- package/dist/components/NPassword.nexa +178 -0
- package/dist/components/NProgressBar.js +127 -0
- package/dist/components/NProgressBar.nexa +111 -0
- package/dist/components/NRadio.js +96 -0
- package/dist/components/NRadio.nexa +81 -0
- package/dist/components/NSelect.js +468 -0
- package/dist/components/NSelect.nexa +452 -0
- package/dist/components/NSkeleton.js +98 -0
- package/dist/components/NSkeleton.nexa +74 -0
- package/dist/components/NSwitch.js +92 -0
- package/dist/components/NSwitch.nexa +76 -0
- package/dist/components/NTabs.js +129 -0
- package/dist/components/NTabs.nexa +113 -0
- package/dist/components/NTag.js +108 -0
- package/dist/components/NTag.nexa +93 -0
- package/dist/components/NToastContainer.js +242 -0
- package/dist/components/NToastContainer.nexa +221 -0
- package/dist/components/NTooltip.js +163 -0
- package/dist/components/NTooltip.nexa +166 -0
- package/dist/components/NTreeMenu.js +151 -0
- package/dist/components/NTreeMenu.nexa +142 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +34 -0
- package/dist/services/FloatingOverlay.d.ts +27 -0
- package/dist/services/FloatingOverlay.js +98 -0
- package/dist/services/FormValidation.d.ts +8 -0
- package/dist/services/FormValidation.js +46 -0
- package/dist/services/ToastService.d.ts +16 -0
- package/dist/services/ToastService.js +26 -0
- package/dist/styles/theme.d.ts +1 -0
- package/dist/styles/theme.js +144 -0
- package/package.json +32 -0
- package/src/components/NAlert.nexa +115 -0
- package/src/components/NAutocomplete.nexa +58 -0
- package/src/components/NAvatar.nexa +67 -0
- package/src/components/NBadge.nexa +61 -0
- package/src/components/NBottomSheet.nexa +145 -0
- package/src/components/NButton.nexa +275 -0
- package/src/components/NCard.nexa +100 -0
- package/src/components/NCheckbox.nexa +90 -0
- package/src/components/NChips.nexa +57 -0
- package/src/components/NDataTable.nexa +186 -0
- package/src/components/NDatepicker.nexa +367 -0
- package/src/components/NForm.nexa +133 -0
- package/src/components/NFormField.nexa +171 -0
- package/src/components/NInput.nexa +311 -0
- package/src/components/NInputNumber.nexa +199 -0
- package/src/components/NModal.nexa +221 -0
- package/src/components/NMultiSelect.nexa +77 -0
- package/src/components/NPaginator.nexa +77 -0
- package/src/components/NPassword.nexa +178 -0
- package/src/components/NProgressBar.nexa +111 -0
- package/src/components/NRadio.nexa +81 -0
- package/src/components/NSelect.nexa +452 -0
- package/src/components/NSkeleton.nexa +74 -0
- package/src/components/NSwitch.nexa +76 -0
- package/src/components/NTabs.nexa +113 -0
- package/src/components/NTag.nexa +93 -0
- package/src/components/NToastContainer.nexa +221 -0
- package/src/components/NTooltip.nexa +166 -0
- package/src/components/NTreeMenu.nexa +142 -0
- package/src/index.ts +36 -0
- package/src/services/FloatingOverlay.ts +133 -0
- package/src/services/FormValidation.ts +44 -0
- package/src/services/ToastService.ts +41 -0
- package/src/shims.d.ts +5 -0
- package/src/styles/theme.ts +146 -0
- package/src/styles/tokens.css +170 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { signal, computed, inject, onBeforeUnmount, effect, batch, h, hText, defineComponent, registerComponent, reloadComponent, injectStyle, Teleport } from 'nexa-framework'
|
|
2
|
+
import { trackFloatingOverlay } from '../services/FloatingOverlay.js'
|
|
3
|
+
|
|
4
|
+
const _sfc_main = defineComponent({
|
|
5
|
+
__scopeId: 'data-v-12b3b8c4',
|
|
6
|
+
__hmrId: 'NMultiSelect_nexa',
|
|
7
|
+
props: { modelValue: { type: Array, default: () => [] }, options: { type: Array, default: () => [] }, placeholder: { type: String, default: 'Select...' }, label: { type: String, default: '' }, disabled: { type: Boolean, default: false }, bindField: { type: Boolean, default: false }, searchable: { type: Boolean, default: false }, clearable: { type: Boolean, default: false }, placement: { type: String, default: 'auto' }, appendTo: { type: String, default: 'self' }, maxChips: { type: Number, default: 3 } },
|
|
8
|
+
emits: ['update:modelValue', 'clear'],
|
|
9
|
+
setup(props, setupContext) {
|
|
10
|
+
const { emit, slots, slots: $slots } = setupContext
|
|
11
|
+
const field = inject('nexa-ui:form-field', undefined)
|
|
12
|
+
const instanceId = `n-ms-${Math.random().toString(16).slice(2)}`
|
|
13
|
+
const isOpen = signal(false)
|
|
14
|
+
const query = signal('')
|
|
15
|
+
const queryDraft = signal('')
|
|
16
|
+
const focusedIndex = signal(-1)
|
|
17
|
+
const popupStyle = signal({})
|
|
18
|
+
const resolvedPlacement = signal('bottom')
|
|
19
|
+
const rootEl = signal(null)
|
|
20
|
+
let stopTracking = null
|
|
21
|
+
let outsideHandler = null
|
|
22
|
+
const normalizeOption = (opt) => { if (opt == null) return { label: '', value: null, disabled: false }; if (typeof opt === 'string' || typeof opt === 'number') return { label: String(opt), value: opt, disabled: false }; if (typeof opt === 'object') { const label = 'label' in opt ? String(opt.label) : String(opt.value ?? ''); const value = 'value' in opt ? opt.value : label; return { label, value, disabled: !!opt.disabled } } return { label: String(opt), value: opt, disabled: false } }
|
|
23
|
+
const normalizedOptions = computed(() => props.options.map(normalizeOption))
|
|
24
|
+
const effectiveModelValue = computed(() => {
|
|
25
|
+
if (props.bindField && field?.value) {
|
|
26
|
+
const v = field.value.value
|
|
27
|
+
return Array.isArray(v) ? v : []
|
|
28
|
+
}
|
|
29
|
+
return props.modelValue
|
|
30
|
+
})
|
|
31
|
+
const effectiveDisabled = computed(() => {
|
|
32
|
+
if (props.disabled) return true
|
|
33
|
+
if (props.bindField && field?.disabled) return !!field.disabled.value
|
|
34
|
+
return false
|
|
35
|
+
})
|
|
36
|
+
const selectedSet = computed(() => new Set(Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []))
|
|
37
|
+
const filteredOptions = computed(() => { const q = props.searchable ? query.value.trim().toLowerCase() : ''; if (!q) return normalizedOptions.value; return normalizedOptions.value.filter(o => o.label.toLowerCase().includes(q)) })
|
|
38
|
+
const selectedLabels = computed(() => { const set = selectedSet.value; const out = []; for (const opt of normalizedOptions.value) { if (set.has(opt.value)) out.push({ label: opt.label, value: opt.value }) } return out })
|
|
39
|
+
const close = () => { if (!isOpen.value) return; isOpen.value = false; focusedIndex.value = -1; query.value = ''; queryDraft.value = ''; if (stopTracking) { stopTracking(); stopTracking = null } if (outsideHandler) { document.removeEventListener('mousedown', outsideHandler); outsideHandler = null } if (props.bindField && field?.onBlur) field.onBlur() }
|
|
40
|
+
const open = (e) => { if (effectiveDisabled.value || isOpen.value) return; isOpen.value = true; focusedIndex.value = filteredOptions.value.length > 0 ? 0 : -1; const t = e?.currentTarget || e?.target; rootEl.value = t?.closest ? t.closest(`[data-ms-root="${instanceId}"]`) : null; if (props.appendTo === 'body') { stopTracking = trackFloatingOverlay({ isOpen: () => isOpen.value, getAnchor: () => { const root = rootEl.value; return root ? root.querySelector('.n-ms-trigger') : null }, getPopup: () => document.querySelector(`[data-ms-popup="${instanceId}"]`), placement: props.placement, align: 'start', matchWidth: true, minWidth: 240, gap: 8, margin: 8, zIndex: 9999, onUpdate: (r) => { popupStyle.value = r.style; resolvedPlacement.value = r.placement }, isEventInside: (ev) => { const el = ev.target; if (!el || typeof el.closest !== 'function') return false; return !!(el.closest(`[data-ms-root="${instanceId}"]`) || el.closest(`[data-ms-popup="${instanceId}"]`)) }, onOutside: () => close() }) } else { if (outsideHandler) document.removeEventListener('mousedown', outsideHandler); outsideHandler = (event) => { const el = event.target; if (!el || typeof el.closest !== 'function') return; if (el.closest(`[data-ms-root="${instanceId}"]`)) return; close() }; document.addEventListener('mousedown', outsideHandler) } requestAnimationFrame(() => { if (!props.searchable) return; const search = props.appendTo === 'body' ? document.querySelector(`[data-ms-popup="${instanceId}"] .n-ms-search-input`) : rootEl.value?.querySelector?.('.n-ms-search-input'); if (search && typeof search.focus === 'function') { try { search.focus() } catch {} } }) }
|
|
41
|
+
const toggleOpen = (e) => { if (effectiveDisabled.value) return; if (isOpen.value) close(); else open(e) }
|
|
42
|
+
const setModel = (next) => { if (props.bindField && field?.setValue) field.setValue(next); else emit('update:modelValue', next) }
|
|
43
|
+
const toggleValue = (value) => { if (effectiveDisabled.value) return; const cur = Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []; const next = cur.includes(value) ? cur.filter(v => v !== value) : [...cur, value]; setModel(next) }
|
|
44
|
+
const clear = () => { if (effectiveDisabled.value) return; setModel([]); emit('clear'); query.value = ''; queryDraft.value = '' }
|
|
45
|
+
const removeChip = (value, e) => { e?.stopPropagation?.(); const cur = Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []; setModel(cur.filter(v => v !== value)) }
|
|
46
|
+
const onKeydown = (e) => { if (!isOpen.value) { if (e.key === 'Enter' || e.key === ' ' || e.key === 'ArrowDown') { e.preventDefault(); open(e) } return } const items = filteredOptions.value; if (e.key === 'ArrowDown') { e.preventDefault(); focusedIndex.value = Math.min(focusedIndex.value + 1, items.length - 1); return } if (e.key === 'ArrowUp') { e.preventDefault(); focusedIndex.value = Math.max(focusedIndex.value - 1, 0); return } if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); const opt = items[focusedIndex.value]; if (!opt || opt.disabled) return; toggleValue(opt.value); return } if (e.key === 'Escape') { e.preventDefault(); close() } }
|
|
47
|
+
effect(() => {
|
|
48
|
+
if (!isOpen.value) return
|
|
49
|
+
if (!props.searchable) return
|
|
50
|
+
if (queryDraft.value === query.value) return
|
|
51
|
+
queryDraft.value = query.value
|
|
52
|
+
})
|
|
53
|
+
const onSearchInput = (e) => {
|
|
54
|
+
const next = e?.target?.value ?? ''
|
|
55
|
+
batch(() => {
|
|
56
|
+
queryDraft.value = next
|
|
57
|
+
query.value = next
|
|
58
|
+
focusedIndex.value = filteredOptions.value.length > 0 ? 0 : -1
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
onBeforeUnmount(() => close())
|
|
62
|
+
return { field, instanceId, isOpen, query, queryDraft, focusedIndex, popupStyle, resolvedPlacement, rootEl, stopTracking, outsideHandler, normalizeOption, normalizedOptions, effectiveModelValue, effectiveDisabled, selectedSet, filteredOptions, selectedLabels, close, open, toggleOpen, setModel, toggleValue, clear, removeChip, onKeydown, onSearchInput, inject, onBeforeUnmount, batch, trackFloatingOverlay, $slots, emit }
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
// Injected render function
|
|
66
|
+
_sfc_main.render = function(ctx) {
|
|
67
|
+
const { field, instanceId, isOpen, query, queryDraft, focusedIndex, popupStyle, resolvedPlacement, rootEl, stopTracking, outsideHandler, normalizeOption, normalizedOptions, effectiveModelValue, effectiveDisabled, selectedSet, filteredOptions, selectedLabels, close, open, toggleOpen, setModel, toggleValue, clear, removeChip, onKeydown, onSearchInput, inject, onBeforeUnmount, batch, trackFloatingOverlay, $slots, emit, modelValue, options, placeholder, label, disabled, bindField, searchable, clearable, placement, appendTo, maxChips, Fragment: _ntc_Fragment, Teleport: _ntc_Teleport } = ctx
|
|
68
|
+
return h('div', { class: ["n-ms", { 'is-open': isOpen.value, 'is-disabled': effectiveDisabled.value }], "data-ms-root": instanceId, "data-v-12b3b8c4": "" }, [
|
|
69
|
+
"\n ",
|
|
70
|
+
(label) ? h('label', { class: "n-ms-label", "data-v-12b3b8c4": "" }, [
|
|
71
|
+
label
|
|
72
|
+
]) : null,
|
|
73
|
+
h('div', { class: "n-ms-trigger", role: "combobox", tabindex: "0", "aria-expanded": isOpen.value, onClick: toggleOpen, onKeydown: onKeydown, "data-v-12b3b8c4": "" }, [
|
|
74
|
+
"\n ",
|
|
75
|
+
(selectedLabels.value.length > 0) ? h('div', { class: "n-ms-chips", "data-v-12b3b8c4": "" }, [
|
|
76
|
+
selectedLabels.value.slice(0, maxChips).map((c, index) =>
|
|
77
|
+
h('div', { class: "n-ms-chip", key: String(c.value), "data-v-12b3b8c4": "" }, [
|
|
78
|
+
h('span', { class: "n-ms-chip-label", "data-v-12b3b8c4": "" }, [
|
|
79
|
+
c.label
|
|
80
|
+
]),
|
|
81
|
+
h('button', { class: "n-ms-chip-remove", type: "button", "aria-label": "Remove", tabindex: "-1", disabled: effectiveDisabled.value, onClick: ($event) => { removeChip(c.value, $event) }, "data-v-12b3b8c4": "" }, [
|
|
82
|
+
"✕"
|
|
83
|
+
])
|
|
84
|
+
])
|
|
85
|
+
),
|
|
86
|
+
(selectedLabels.value.length > maxChips) ? h('span', { class: "n-ms-more", "data-v-12b3b8c4": "" }, [
|
|
87
|
+
"+",
|
|
88
|
+
selectedLabels.value.length - maxChips
|
|
89
|
+
]) : null
|
|
90
|
+
]) : (true) ? h('span', { class: "n-ms-placeholder", "data-v-12b3b8c4": "" }, [
|
|
91
|
+
placeholder
|
|
92
|
+
]) : null,
|
|
93
|
+
"\n ",
|
|
94
|
+
h('div', { class: "n-ms-actions", "data-v-12b3b8c4": "" }, [
|
|
95
|
+
(clearable && selectedLabels.value.length > 0) ? h('button', { class: "n-ms-clear", type: "button", tabindex: "-1", onClick: ($event) => { $event.stopPropagation(); (clear)($event) }, "data-v-12b3b8c4": "" }, [
|
|
96
|
+
"✕"
|
|
97
|
+
]) : null,
|
|
98
|
+
h('span', { class: "n-ms-arrow", "data-v-12b3b8c4": "" }, [
|
|
99
|
+
"▾"
|
|
100
|
+
])
|
|
101
|
+
]),
|
|
102
|
+
"\n "
|
|
103
|
+
]),
|
|
104
|
+
"\n ",
|
|
105
|
+
(isOpen.value && appendTo !== 'body') ? h('div', { class: "n-ms-dropdown", "data-v-12b3b8c4": "" }, [
|
|
106
|
+
(searchable) ? h('div', { class: "n-ms-search", "data-v-12b3b8c4": "" }, [
|
|
107
|
+
h('input', { class: "n-ms-search-input", value: queryDraft.value, placeholder: "Search...", onInput: onSearchInput, onKeydown: ($event) => { $event.stopPropagation(); (onKeydown)($event) }, "data-v-12b3b8c4": "" })
|
|
108
|
+
]) : null,
|
|
109
|
+
h('div', { class: "n-ms-options", "data-v-12b3b8c4": "" }, [
|
|
110
|
+
filteredOptions.value.map((opt, i) =>
|
|
111
|
+
h('button', { class: ["n-ms-option", { 'is-selected': selectedSet.value.has(opt.value), 'is-focused': i === focusedIndex.value, 'is-disabled': opt.disabled }], key: String(opt.value) + ':' + i, type: "button", "data-ms-opt": String(opt.value), disabled: opt.disabled, onMouseenter: ($event) => { focusedIndex.value = i }, onClick: ($event) => { toggleValue(opt.value) }, "data-v-12b3b8c4": "" }, [
|
|
112
|
+
h('span', { class: "n-ms-check", "data-v-12b3b8c4": "" }, [
|
|
113
|
+
selectedSet.value.has(opt.value) ? '✓' : ''
|
|
114
|
+
]),
|
|
115
|
+
h('span', { class: "n-ms-option-label", "data-v-12b3b8c4": "" }, [
|
|
116
|
+
opt.label
|
|
117
|
+
])
|
|
118
|
+
])
|
|
119
|
+
),
|
|
120
|
+
(filteredOptions.value.length === 0) ? h('div', { class: "n-ms-empty", "data-v-12b3b8c4": "" }, [
|
|
121
|
+
"No options"
|
|
122
|
+
]) : null
|
|
123
|
+
])
|
|
124
|
+
]) : null,
|
|
125
|
+
h(_ntc_Teleport, { to: "body", "data-v-12b3b8c4": "" }, [
|
|
126
|
+
(isOpen.value && appendTo === 'body') ? h('div', { class: ["n-ms-dropdown", { 'is-top': resolvedPlacement.value === 'top' }], "data-ms-popup": instanceId, style: popupStyle.value, "data-v-12b3b8c4": "" }, [
|
|
127
|
+
(searchable) ? h('div', { class: "n-ms-search", "data-v-12b3b8c4": "" }, [
|
|
128
|
+
h('input', { class: "n-ms-search-input", value: queryDraft.value, placeholder: "Search...", onInput: onSearchInput, onKeydown: ($event) => { $event.stopPropagation(); (onKeydown)($event) }, "data-v-12b3b8c4": "" })
|
|
129
|
+
]) : null,
|
|
130
|
+
h('div', { class: "n-ms-options", "data-v-12b3b8c4": "" }, [
|
|
131
|
+
filteredOptions.value.map((opt, i) =>
|
|
132
|
+
h('button', { class: ["n-ms-option", { 'is-selected': selectedSet.value.has(opt.value), 'is-focused': i === focusedIndex.value, 'is-disabled': opt.disabled }], key: String(opt.value) + ':' + i, type: "button", "data-ms-opt": String(opt.value), disabled: opt.disabled, onMouseenter: ($event) => { focusedIndex.value = i }, onClick: ($event) => { toggleValue(opt.value) }, "data-v-12b3b8c4": "" }, [
|
|
133
|
+
h('span', { class: "n-ms-check", "data-v-12b3b8c4": "" }, [
|
|
134
|
+
selectedSet.value.has(opt.value) ? '✓' : ''
|
|
135
|
+
]),
|
|
136
|
+
h('span', { class: "n-ms-option-label", "data-v-12b3b8c4": "" }, [
|
|
137
|
+
opt.label
|
|
138
|
+
])
|
|
139
|
+
])
|
|
140
|
+
),
|
|
141
|
+
(filteredOptions.value.length === 0) ? h('div', { class: "n-ms-empty", "data-v-12b3b8c4": "" }, [
|
|
142
|
+
"No options"
|
|
143
|
+
]) : null
|
|
144
|
+
])
|
|
145
|
+
]) : null
|
|
146
|
+
]),
|
|
147
|
+
"\n "
|
|
148
|
+
])
|
|
149
|
+
}
|
|
150
|
+
_sfc_main.__scopeId = 'data-v-12b3b8c4'
|
|
151
|
+
_sfc_main.__hmrId = 'NMultiSelect_nexa'
|
|
152
|
+
|
|
153
|
+
export default _sfc_main
|
|
154
|
+
|
|
155
|
+
const __style = `.n-ms[data-v-12b3b8c4]{position:relative;width:100%;font-family:var(--n-font-sans)}.n-ms-label{display:block;font-size:var(--n-text-sm);font-weight:var(--n-weight-medium);color:var(--n-color-text-secondary);margin-bottom:var(--n-space-2)}.n-ms-trigger{background:var(--n-color-surface);border:1px solid var(--n-color-border);border-radius:var(--n-radius-md);padding:0.5rem 0.75rem;display:flex;justify-content:space-between;align-items:center;cursor:pointer;transition:all var(--n-transition-fast);color:var(--n-color-text);gap:var(--n-space-2);min-height:44px}.n-ms-trigger:focus-visible{border-color:var(--n-color-primary);box-shadow:0 0 0 3px var(--n-color-primary-light)}.n-ms.is-open .n-ms-trigger{border-color:var(--n-color-primary);box-shadow:0 0 0 3px var(--n-color-primary-light)}.n-ms-placeholder{color:var(--n-color-text-muted)}.n-ms-actions{display:flex;align-items:center;gap:0.25rem;flex-shrink:0}.n-ms-clear{background:transparent;border:none;color:var(--n-color-text-muted);cursor:pointer;padding:0.15rem;font-size:var(--n-text-xs);border-radius:var(--n-radius-sm);line-height:1}.n-ms-clear:hover{color:var(--n-color-text)}.n-ms-arrow{color:var(--n-color-text-muted);transition:transform var(--n-transition-fast);font-size:var(--n-text-xs)}.is-open .n-ms-arrow{transform:rotate(180deg)}.n-ms-chips{display:flex;flex-wrap:wrap;gap:var(--n-space-2);align-items:center;min-width:0}.n-ms-chip{display:inline-flex;align-items:center;gap:0.35rem;padding:0.2rem 0.45rem;border-radius:999px;background:var(--n-color-glass);border:1px solid var(--n-color-border);font-size:var(--n-text-xs);line-height:1;max-width:12rem}.n-ms-chip-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:10rem}.n-ms-chip-remove{background:transparent;border:none;color:var(--n-color-text-muted);cursor:pointer;padding:0;line-height:1;display:flex;align-items:center}.n-ms-chip-remove:hover:not(:disabled){color:var(--n-color-text)}.n-ms-chip-remove:disabled{opacity:0.5;cursor:not-allowed}.n-ms-more{font-size:var(--n-text-xs);color:var(--n-color-text-muted)}.n-ms-dropdown{position:absolute;top:calc(100% + 0.5rem);left:0;width:100%;background:var(--n-color-surface);border:1px solid var(--n-color-border);border-radius:var(--n-radius-md);box-shadow:var(--n-shadow-lg);z-index:var(--n-z-dropdown);overflow:hidden;animation:n-ms-in .2s cubic-bezier(0,1,0,1)}@keyframes n-ms-in{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.n-ms-dropdown.is-top{animation:n-ms-in-top .2s cubic-bezier(0,1,0,1)}@keyframes n-ms-in-top{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.n-ms-search{padding:var(--n-space-2);border-bottom:1px solid var(--n-color-border)}.n-ms-search-input{width:100%;background:var(--n-color-bg);border:1px solid var(--n-color-border);border-radius:var(--n-radius-sm);padding:var(--n-space-2) var(--n-space-3);color:var(--n-color-text);font-size:var(--n-text-sm);outline:none;font-family:inherit}.n-ms-search-input:focus{border-color:var(--n-color-primary)}.n-ms-options{max-height:260px;overflow-y:auto}.n-ms-option{width:100%;display:flex;align-items:center;gap:0.5rem;padding:0.7rem 1rem;background:transparent;border:none;color:var(--n-color-text-secondary);cursor:pointer;transition:all var(--n-transition-fast);text-align:left}.n-ms-option:hover:not(:disabled),.n-ms-option.is-focused{background:var(--n-color-glass);color:var(--n-color-text)}.n-ms-option.is-selected{background:var(--n-color-primary-light);color:var(--n-color-primary);font-weight:var(--n-weight-semibold)}.n-ms-option:disabled,.n-ms-option.is-disabled{opacity:0.4;cursor:not-allowed}.n-ms-check{width:1.25rem;display:inline-flex;align-items:center;justify-content:center;font-size:var(--n-text-xs)}.n-ms-empty{padding:var(--n-space-4);color:var(--n-color-text-muted);text-align:center;font-size:var(--n-text-sm)}.is-disabled .n-ms-trigger{opacity:0.5;cursor:not-allowed}`
|
|
156
|
+
injectStyle('data-v-12b3b8c4', __style)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { signal, computed, inject, onBeforeUnmount, effect, batch } from 'nexa-framework'
|
|
3
|
+
import { trackFloatingOverlay } from '../services/FloatingOverlay.js'
|
|
4
|
+
const props = defineProps({ modelValue: { type: Array, default: () => [] }, options: { type: Array, default: () => [] }, placeholder: { type: String, default: 'Select...' }, label: { type: String, default: '' }, disabled: { type: Boolean, default: false }, bindField: { type: Boolean, default: false }, searchable: { type: Boolean, default: false }, clearable: { type: Boolean, default: false }, placement: { type: String, default: 'auto' }, appendTo: { type: String, default: 'self' }, maxChips: { type: Number, default: 3 } })
|
|
5
|
+
const emit = defineEmits(['update:modelValue', 'clear'])
|
|
6
|
+
const field = inject('nexa-ui:form-field', undefined)
|
|
7
|
+
const instanceId = `n-ms-${Math.random().toString(16).slice(2)}`
|
|
8
|
+
const isOpen = signal(false)
|
|
9
|
+
const query = signal('')
|
|
10
|
+
const queryDraft = signal('')
|
|
11
|
+
const focusedIndex = signal(-1)
|
|
12
|
+
const popupStyle = signal({})
|
|
13
|
+
const resolvedPlacement = signal('bottom')
|
|
14
|
+
const rootEl = signal(null)
|
|
15
|
+
let stopTracking = null
|
|
16
|
+
let outsideHandler = null
|
|
17
|
+
const normalizeOption = (opt) => { if (opt == null) return { label: '', value: null, disabled: false }; if (typeof opt === 'string' || typeof opt === 'number') return { label: String(opt), value: opt, disabled: false }; if (typeof opt === 'object') { const label = 'label' in opt ? String(opt.label) : String(opt.value ?? ''); const value = 'value' in opt ? opt.value : label; return { label, value, disabled: !!opt.disabled } } return { label: String(opt), value: opt, disabled: false } }
|
|
18
|
+
const normalizedOptions = computed(() => props.options.map(normalizeOption))
|
|
19
|
+
const effectiveModelValue = computed(() => {
|
|
20
|
+
if (props.bindField && field?.value) {
|
|
21
|
+
const v = field.value.value
|
|
22
|
+
return Array.isArray(v) ? v : []
|
|
23
|
+
}
|
|
24
|
+
return props.modelValue
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const effectiveDisabled = computed(() => {
|
|
28
|
+
if (props.disabled) return true
|
|
29
|
+
if (props.bindField && field?.disabled) return !!field.disabled.value
|
|
30
|
+
return false
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const selectedSet = computed(() => new Set(Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []))
|
|
34
|
+
const filteredOptions = computed(() => { const q = props.searchable ? query.value.trim().toLowerCase() : ''; if (!q) return normalizedOptions.value; return normalizedOptions.value.filter(o => o.label.toLowerCase().includes(q)) })
|
|
35
|
+
const selectedLabels = computed(() => { const set = selectedSet.value; const out = []; for (const opt of normalizedOptions.value) { if (set.has(opt.value)) out.push({ label: opt.label, value: opt.value }) } return out })
|
|
36
|
+
const close = () => { if (!isOpen.value) return; isOpen.value = false; focusedIndex.value = -1; query.value = ''; queryDraft.value = ''; if (stopTracking) { stopTracking(); stopTracking = null } if (outsideHandler) { document.removeEventListener('mousedown', outsideHandler); outsideHandler = null } if (props.bindField && field?.onBlur) field.onBlur() }
|
|
37
|
+
const open = (e) => { if (effectiveDisabled.value || isOpen.value) return; isOpen.value = true; focusedIndex.value = filteredOptions.value.length > 0 ? 0 : -1; const t = e?.currentTarget || e?.target; rootEl.value = t?.closest ? t.closest(`[data-ms-root="${instanceId}"]`) : null; if (props.appendTo === 'body') { stopTracking = trackFloatingOverlay({ isOpen: () => isOpen.value, getAnchor: () => { const root = rootEl.value; return root ? root.querySelector('.n-ms-trigger') : null }, getPopup: () => document.querySelector(`[data-ms-popup="${instanceId}"]`), placement: props.placement, align: 'start', matchWidth: true, minWidth: 240, gap: 8, margin: 8, zIndex: 9999, onUpdate: (r) => { popupStyle.value = r.style; resolvedPlacement.value = r.placement }, isEventInside: (ev) => { const el = ev.target; if (!el || typeof el.closest !== 'function') return false; return !!(el.closest(`[data-ms-root="${instanceId}"]`) || el.closest(`[data-ms-popup="${instanceId}"]`)) }, onOutside: () => close() }) } else { if (outsideHandler) document.removeEventListener('mousedown', outsideHandler); outsideHandler = (event) => { const el = event.target; if (!el || typeof el.closest !== 'function') return; if (el.closest(`[data-ms-root="${instanceId}"]`)) return; close() }; document.addEventListener('mousedown', outsideHandler) } requestAnimationFrame(() => { if (!props.searchable) return; const search = props.appendTo === 'body' ? document.querySelector(`[data-ms-popup="${instanceId}"] .n-ms-search-input`) : rootEl.value?.querySelector?.('.n-ms-search-input'); if (search && typeof search.focus === 'function') { try { search.focus() } catch {} } }) }
|
|
38
|
+
const toggleOpen = (e) => { if (effectiveDisabled.value) return; if (isOpen.value) close(); else open(e) }
|
|
39
|
+
const setModel = (next) => { if (props.bindField && field?.setValue) field.setValue(next); else emit('update:modelValue', next) }
|
|
40
|
+
const toggleValue = (value) => { if (effectiveDisabled.value) return; const cur = Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []; const next = cur.includes(value) ? cur.filter(v => v !== value) : [...cur, value]; setModel(next) }
|
|
41
|
+
const clear = () => { if (effectiveDisabled.value) return; setModel([]); emit('clear'); query.value = ''; queryDraft.value = '' }
|
|
42
|
+
const removeChip = (value, e) => { e?.stopPropagation?.(); const cur = Array.isArray(effectiveModelValue.value) ? effectiveModelValue.value : []; setModel(cur.filter(v => v !== value)) }
|
|
43
|
+
const onKeydown = (e) => { if (!isOpen.value) { if (e.key === 'Enter' || e.key === ' ' || e.key === 'ArrowDown') { e.preventDefault(); open(e) } return } const items = filteredOptions.value; if (e.key === 'ArrowDown') { e.preventDefault(); focusedIndex.value = Math.min(focusedIndex.value + 1, items.length - 1); return } if (e.key === 'ArrowUp') { e.preventDefault(); focusedIndex.value = Math.max(focusedIndex.value - 1, 0); return } if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); const opt = items[focusedIndex.value]; if (!opt || opt.disabled) return; toggleValue(opt.value); return } if (e.key === 'Escape') { e.preventDefault(); close() } }
|
|
44
|
+
effect(() => {
|
|
45
|
+
if (!isOpen.value) return
|
|
46
|
+
if (!props.searchable) return
|
|
47
|
+
if (queryDraft.value === query.value) return
|
|
48
|
+
queryDraft.value = query.value
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const onSearchInput = (e) => {
|
|
52
|
+
const next = e?.target?.value ?? ''
|
|
53
|
+
batch(() => {
|
|
54
|
+
queryDraft.value = next
|
|
55
|
+
query.value = next
|
|
56
|
+
focusedIndex.value = filteredOptions.value.length > 0 ? 0 : -1
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
onBeforeUnmount(() => close())
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<div class="n-ms" :class="{ 'is-open': isOpen.value, 'is-disabled': effectiveDisabled.value }" :data-ms-root="instanceId">
|
|
64
|
+
<label v-if="label" class="n-ms-label">{{ label }}</label>
|
|
65
|
+
<div class="n-ms-trigger" role="combobox" tabindex="0" :aria-expanded="isOpen.value" @click="toggleOpen" @keydown="onKeydown">
|
|
66
|
+
<div v-if="selectedLabels.value.length > 0" class="n-ms-chips"><div v-for="c in selectedLabels.value.slice(0, maxChips)" :key="String(c.value)" class="n-ms-chip"><span class="n-ms-chip-label">{{ c.label }}</span><button type="button" class="n-ms-chip-remove" aria-label="Remove" tabindex="-1" :disabled="effectiveDisabled.value" @click="removeChip(c.value, $event)">✕</button></div><span v-if="selectedLabels.value.length > maxChips" class="n-ms-more">+{{ selectedLabels.value.length - maxChips }}</span></div>
|
|
67
|
+
<span v-else class="n-ms-placeholder">{{ placeholder }}</span>
|
|
68
|
+
<div class="n-ms-actions"><button v-if="clearable && selectedLabels.value.length > 0" type="button" class="n-ms-clear" tabindex="-1" @click.stop="clear">✕</button><span class="n-ms-arrow">▾</span></div>
|
|
69
|
+
</div>
|
|
70
|
+
<div v-if="isOpen.value && appendTo !== 'body'" class="n-ms-dropdown"><div v-if="searchable" class="n-ms-search"><input class="n-ms-search-input" :value="queryDraft.value" placeholder="Search..." @input="onSearchInput" @keydown.stop="onKeydown" /></div><div class="n-ms-options"><button v-for="(opt, i) in filteredOptions.value" :key="String(opt.value) + ':' + i" type="button" class="n-ms-option" :data-ms-opt="String(opt.value)" :class="{ 'is-selected': selectedSet.value.has(opt.value), 'is-focused': i === focusedIndex.value, 'is-disabled': opt.disabled }" :disabled="opt.disabled" @mouseenter="focusedIndex.value = i" @click="toggleValue(opt.value)"><span class="n-ms-check">{{ selectedSet.value.has(opt.value) ? '✓' : '' }}</span><span class="n-ms-option-label">{{ opt.label }}</span></button><div v-if="filteredOptions.value.length === 0" class="n-ms-empty">No options</div></div></div>
|
|
71
|
+
<Teleport to="body"><div v-if="isOpen.value && appendTo === 'body'" class="n-ms-dropdown" :class="{ 'is-top': resolvedPlacement.value === 'top' }" :data-ms-popup="instanceId" :style="popupStyle.value"><div v-if="searchable" class="n-ms-search"><input class="n-ms-search-input" :value="queryDraft.value" placeholder="Search..." @input="onSearchInput" @keydown.stop="onKeydown" /></div><div class="n-ms-options"><button v-for="(opt, i) in filteredOptions.value" :key="String(opt.value) + ':' + i" type="button" class="n-ms-option" :data-ms-opt="String(opt.value)" :class="{ 'is-selected': selectedSet.value.has(opt.value), 'is-focused': i === focusedIndex.value, 'is-disabled': opt.disabled }" :disabled="opt.disabled" @mouseenter="focusedIndex.value = i" @click="toggleValue(opt.value)"><span class="n-ms-check">{{ selectedSet.value.has(opt.value) ? '✓' : '' }}</span><span class="n-ms-option-label">{{ opt.label }}</span></button><div v-if="filteredOptions.value.length === 0" class="n-ms-empty">No options</div></div></div></Teleport>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
74
|
+
|
|
75
|
+
<style scoped>
|
|
76
|
+
.n-ms{position:relative;width:100%;font-family:var(--n-font-sans)}.n-ms-label{display:block;font-size:var(--n-text-sm);font-weight:var(--n-weight-medium);color:var(--n-color-text-secondary);margin-bottom:var(--n-space-2)}.n-ms-trigger{background:var(--n-color-surface);border:1px solid var(--n-color-border);border-radius:var(--n-radius-md);padding:0.5rem 0.75rem;display:flex;justify-content:space-between;align-items:center;cursor:pointer;transition:all var(--n-transition-fast);color:var(--n-color-text);gap:var(--n-space-2);min-height:44px}.n-ms-trigger:focus-visible{border-color:var(--n-color-primary);box-shadow:0 0 0 3px var(--n-color-primary-light)}.n-ms.is-open .n-ms-trigger{border-color:var(--n-color-primary);box-shadow:0 0 0 3px var(--n-color-primary-light)}.n-ms-placeholder{color:var(--n-color-text-muted)}.n-ms-actions{display:flex;align-items:center;gap:0.25rem;flex-shrink:0}.n-ms-clear{background:transparent;border:none;color:var(--n-color-text-muted);cursor:pointer;padding:0.15rem;font-size:var(--n-text-xs);border-radius:var(--n-radius-sm);line-height:1}.n-ms-clear:hover{color:var(--n-color-text)}.n-ms-arrow{color:var(--n-color-text-muted);transition:transform var(--n-transition-fast);font-size:var(--n-text-xs)}.is-open .n-ms-arrow{transform:rotate(180deg)}.n-ms-chips{display:flex;flex-wrap:wrap;gap:var(--n-space-2);align-items:center;min-width:0}.n-ms-chip{display:inline-flex;align-items:center;gap:0.35rem;padding:0.2rem 0.45rem;border-radius:999px;background:var(--n-color-glass);border:1px solid var(--n-color-border);font-size:var(--n-text-xs);line-height:1;max-width:12rem}.n-ms-chip-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:10rem}.n-ms-chip-remove{background:transparent;border:none;color:var(--n-color-text-muted);cursor:pointer;padding:0;line-height:1;display:flex;align-items:center}.n-ms-chip-remove:hover:not(:disabled){color:var(--n-color-text)}.n-ms-chip-remove:disabled{opacity:0.5;cursor:not-allowed}.n-ms-more{font-size:var(--n-text-xs);color:var(--n-color-text-muted)}.n-ms-dropdown{position:absolute;top:calc(100% + 0.5rem);left:0;width:100%;background:var(--n-color-surface);border:1px solid var(--n-color-border);border-radius:var(--n-radius-md);box-shadow:var(--n-shadow-lg);z-index:var(--n-z-dropdown);overflow:hidden;animation:n-ms-in .2s cubic-bezier(0,1,0,1)}@keyframes n-ms-in{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}.n-ms-dropdown.is-top{animation:n-ms-in-top .2s cubic-bezier(0,1,0,1)}@keyframes n-ms-in-top{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.n-ms-search{padding:var(--n-space-2);border-bottom:1px solid var(--n-color-border)}.n-ms-search-input{width:100%;background:var(--n-color-bg);border:1px solid var(--n-color-border);border-radius:var(--n-radius-sm);padding:var(--n-space-2) var(--n-space-3);color:var(--n-color-text);font-size:var(--n-text-sm);outline:none;font-family:inherit}.n-ms-search-input:focus{border-color:var(--n-color-primary)}.n-ms-options{max-height:260px;overflow-y:auto}.n-ms-option{width:100%;display:flex;align-items:center;gap:0.5rem;padding:0.7rem 1rem;background:transparent;border:none;color:var(--n-color-text-secondary);cursor:pointer;transition:all var(--n-transition-fast);text-align:left}.n-ms-option:hover:not(:disabled),.n-ms-option.is-focused{background:var(--n-color-glass);color:var(--n-color-text)}.n-ms-option.is-selected{background:var(--n-color-primary-light);color:var(--n-color-primary);font-weight:var(--n-weight-semibold)}.n-ms-option:disabled,.n-ms-option.is-disabled{opacity:0.4;cursor:not-allowed}.n-ms-check{width:1.25rem;display:inline-flex;align-items:center;justify-content:center;font-size:var(--n-text-xs)}.n-ms-empty{padding:var(--n-space-4);color:var(--n-color-text-muted);text-align:center;font-size:var(--n-text-sm)}.is-disabled .n-ms-trigger{opacity:0.5;cursor:not-allowed}
|
|
77
|
+
</style>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { computed, h, hText, effect, defineComponent, registerComponent, reloadComponent, injectStyle } from 'nexa-framework'
|
|
2
|
+
|
|
3
|
+
const _sfc_main = defineComponent({
|
|
4
|
+
__scopeId: 'data-v-372b30ac',
|
|
5
|
+
__hmrId: 'NPaginator_nexa',
|
|
6
|
+
props: {
|
|
7
|
+
first: { type: Number, default: 0 },
|
|
8
|
+
rows: { type: Number, default: 10 },
|
|
9
|
+
totalRecords: { type: Number, default: 0 },
|
|
10
|
+
rowsPerPageOptions: { type: Array, default: () => [10, 20, 50] },
|
|
11
|
+
},
|
|
12
|
+
emits: ['update:first', 'update:rows', 'updateFirst', 'updateRows', 'page'],
|
|
13
|
+
setup(props, setupContext) {
|
|
14
|
+
const { emit, slots, slots: $slots } = setupContext
|
|
15
|
+
const safeFirst = computed(() => Number.isFinite(props.first) ? props.first : 0)
|
|
16
|
+
const safeRows = computed(() => {
|
|
17
|
+
const r = Number.isFinite(props.rows) ? props.rows : 10
|
|
18
|
+
return r > 0 ? r : 10
|
|
19
|
+
})
|
|
20
|
+
const page = computed(() => Math.floor((safeFirst.value || 0) / (safeRows.value || 1)))
|
|
21
|
+
const pageCount = computed(() => {
|
|
22
|
+
const rows = safeRows.value || 1
|
|
23
|
+
return Math.max(1, Math.ceil((props.totalRecords || 0) / rows))
|
|
24
|
+
})
|
|
25
|
+
const canPrev = computed(() => page.value > 0)
|
|
26
|
+
const canNext = computed(() => page.value < pageCount.value - 1)
|
|
27
|
+
const goToPage = (p) => {
|
|
28
|
+
const clamped = Math.min(Math.max(p, 0), pageCount.value - 1)
|
|
29
|
+
const nextFirst = clamped * (safeRows.value || 1)
|
|
30
|
+
emit('update:first', nextFirst)
|
|
31
|
+
emit('updateFirst', nextFirst)
|
|
32
|
+
emit('page', { page: clamped, first: nextFirst, rows: safeRows.value })
|
|
33
|
+
}
|
|
34
|
+
const prev = () => { if (!canPrev.value) return; goToPage(page.value - 1) }
|
|
35
|
+
const next = () => { if (!canNext.value) return; goToPage(page.value + 1) }
|
|
36
|
+
const firstPage = () => goToPage(0)
|
|
37
|
+
const lastPage = () => goToPage(pageCount.value - 1)
|
|
38
|
+
const changeRows = (e) => {
|
|
39
|
+
const nextRows = Number(e.target.value)
|
|
40
|
+
if (!Number.isFinite(nextRows) || nextRows <= 0) return
|
|
41
|
+
emit('update:rows', nextRows)
|
|
42
|
+
emit('update:first', 0)
|
|
43
|
+
emit('updateRows', nextRows)
|
|
44
|
+
emit('updateFirst', 0)
|
|
45
|
+
emit('page', { page: 0, first: 0, rows: nextRows })
|
|
46
|
+
}
|
|
47
|
+
const start = computed(() => Math.min((safeFirst.value || 0) + 1, props.totalRecords || 0))
|
|
48
|
+
const end = computed(() => Math.min((safeFirst.value || 0) + (safeRows.value || 0), props.totalRecords || 0))
|
|
49
|
+
return { safeFirst, safeRows, page, pageCount, canPrev, canNext, goToPage, prev, next, firstPage, lastPage, changeRows, start, end, $slots, emit }
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
// Injected render function
|
|
53
|
+
_sfc_main.render = function(ctx) {
|
|
54
|
+
const { safeFirst, safeRows, page, pageCount, canPrev, canNext, goToPage, prev, next, firstPage, lastPage, changeRows, start, end, $slots, emit, first, rows, totalRecords, rowsPerPageOptions, Fragment: _ntc_Fragment } = ctx
|
|
55
|
+
return h('div', { class: "n-paginator", "data-v-372b30ac": "" }, [
|
|
56
|
+
"\n ",
|
|
57
|
+
h('div', { class: "n-paginator-left", "data-v-372b30ac": "" }, [
|
|
58
|
+
"\n ",
|
|
59
|
+
h('span', { class: "n-paginator-report", "data-v-372b30ac": "" }, [
|
|
60
|
+
start.value,
|
|
61
|
+
"-",
|
|
62
|
+
end.value,
|
|
63
|
+
" of ",
|
|
64
|
+
totalRecords
|
|
65
|
+
]),
|
|
66
|
+
"\n "
|
|
67
|
+
]),
|
|
68
|
+
"\n ",
|
|
69
|
+
h('div', { class: "n-paginator-center", "data-v-372b30ac": "" }, [
|
|
70
|
+
"\n ",
|
|
71
|
+
h('button', { class: "n-pg-btn", type: "button", disabled: !canPrev.value, onClick: firstPage, "data-v-372b30ac": "" }, [
|
|
72
|
+
"«"
|
|
73
|
+
]),
|
|
74
|
+
"\n ",
|
|
75
|
+
h('button', { class: "n-pg-btn", type: "button", disabled: !canPrev.value, onClick: prev, "data-v-372b30ac": "" }, [
|
|
76
|
+
"‹"
|
|
77
|
+
]),
|
|
78
|
+
"\n ",
|
|
79
|
+
h('span', { class: "n-pg-page", "data-v-372b30ac": "" }, [
|
|
80
|
+
page.value + 1,
|
|
81
|
+
" / ",
|
|
82
|
+
pageCount.value
|
|
83
|
+
]),
|
|
84
|
+
"\n ",
|
|
85
|
+
h('button', { class: "n-pg-btn", type: "button", disabled: !canNext.value, onClick: next, "data-v-372b30ac": "" }, [
|
|
86
|
+
"›"
|
|
87
|
+
]),
|
|
88
|
+
"\n ",
|
|
89
|
+
h('button', { class: "n-pg-btn", type: "button", disabled: !canNext.value, onClick: lastPage, "data-v-372b30ac": "" }, [
|
|
90
|
+
"»"
|
|
91
|
+
]),
|
|
92
|
+
"\n "
|
|
93
|
+
]),
|
|
94
|
+
"\n ",
|
|
95
|
+
h('div', { class: "n-paginator-right", "data-v-372b30ac": "" }, [
|
|
96
|
+
"\n ",
|
|
97
|
+
h('select', { class: "n-pg-select", value: rows, onChange: changeRows, "data-v-372b30ac": "" }, [
|
|
98
|
+
"\n ",
|
|
99
|
+
rowsPerPageOptions.map((n, index) =>
|
|
100
|
+
h('option', { key: n, value: n, "data-v-372b30ac": "" }, [
|
|
101
|
+
n
|
|
102
|
+
])
|
|
103
|
+
),
|
|
104
|
+
"\n "
|
|
105
|
+
]),
|
|
106
|
+
"\n "
|
|
107
|
+
]),
|
|
108
|
+
"\n "
|
|
109
|
+
])
|
|
110
|
+
}
|
|
111
|
+
_sfc_main.__scopeId = 'data-v-372b30ac'
|
|
112
|
+
_sfc_main.__hmrId = 'NPaginator_nexa'
|
|
113
|
+
|
|
114
|
+
export default _sfc_main
|
|
115
|
+
|
|
116
|
+
const __style = `.n-paginator[data-v-372b30ac]{display:flex;align-items:center;justify-content:space-between;gap:var(--n-space-3);padding:var(--n-space-3) var(--n-space-4);border-top:1px solid var(--n-color-border);background:var(--n-color-surface);font-family:var(--n-font-sans)}.n-paginator-report{color:var(--n-color-text-muted);font-size:var(--n-text-xs)}.n-paginator-center{display:flex;align-items:center;gap:0.35rem}.n-pg-btn{background:transparent;border:1px solid var(--n-color-border);color:var(--n-color-text);border-radius:var(--n-radius-sm);padding:0.25rem 0.5rem;cursor:pointer;transition:all var(--n-transition-fast)}.n-pg-btn:hover:not(:disabled){background:var(--n-color-glass)}.n-pg-btn:disabled{opacity:0.5;cursor:not-allowed}.n-pg-page{min-width:5rem;text-align:center;color:var(--n-color-text-secondary);font-size:var(--n-text-xs)}.n-pg-select{background:var(--n-color-bg);border:1px solid var(--n-color-border);color:var(--n-color-text);border-radius:var(--n-radius-sm);padding:0.25rem 0.5rem;font-size:var(--n-text-xs);outline:none}`
|
|
117
|
+
injectStyle('data-v-372b30ac', __style)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from 'nexa-framework'
|
|
3
|
+
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
first: { type: Number, default: 0 },
|
|
6
|
+
rows: { type: Number, default: 10 },
|
|
7
|
+
totalRecords: { type: Number, default: 0 },
|
|
8
|
+
rowsPerPageOptions: { type: Array, default: () => [10, 20, 50] },
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const emit = defineEmits(['update:first', 'update:rows', 'updateFirst', 'updateRows', 'page'])
|
|
12
|
+
|
|
13
|
+
const safeFirst = computed(() => Number.isFinite(props.first) ? props.first : 0)
|
|
14
|
+
const safeRows = computed(() => {
|
|
15
|
+
const r = Number.isFinite(props.rows) ? props.rows : 10
|
|
16
|
+
return r > 0 ? r : 10
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const page = computed(() => Math.floor((safeFirst.value || 0) / (safeRows.value || 1)))
|
|
20
|
+
const pageCount = computed(() => {
|
|
21
|
+
const rows = safeRows.value || 1
|
|
22
|
+
return Math.max(1, Math.ceil((props.totalRecords || 0) / rows))
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const canPrev = computed(() => page.value > 0)
|
|
26
|
+
const canNext = computed(() => page.value < pageCount.value - 1)
|
|
27
|
+
|
|
28
|
+
const goToPage = (p) => {
|
|
29
|
+
const clamped = Math.min(Math.max(p, 0), pageCount.value - 1)
|
|
30
|
+
const nextFirst = clamped * (safeRows.value || 1)
|
|
31
|
+
emit('update:first', nextFirst)
|
|
32
|
+
emit('updateFirst', nextFirst)
|
|
33
|
+
emit('page', { page: clamped, first: nextFirst, rows: safeRows.value })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const prev = () => { if (!canPrev.value) return; goToPage(page.value - 1) }
|
|
37
|
+
const next = () => { if (!canNext.value) return; goToPage(page.value + 1) }
|
|
38
|
+
const firstPage = () => goToPage(0)
|
|
39
|
+
const lastPage = () => goToPage(pageCount.value - 1)
|
|
40
|
+
|
|
41
|
+
const changeRows = (e) => {
|
|
42
|
+
const nextRows = Number(e.target.value)
|
|
43
|
+
if (!Number.isFinite(nextRows) || nextRows <= 0) return
|
|
44
|
+
emit('update:rows', nextRows)
|
|
45
|
+
emit('update:first', 0)
|
|
46
|
+
emit('updateRows', nextRows)
|
|
47
|
+
emit('updateFirst', 0)
|
|
48
|
+
emit('page', { page: 0, first: 0, rows: nextRows })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const start = computed(() => Math.min((safeFirst.value || 0) + 1, props.totalRecords || 0))
|
|
52
|
+
const end = computed(() => Math.min((safeFirst.value || 0) + (safeRows.value || 0), props.totalRecords || 0))
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div class="n-paginator">
|
|
57
|
+
<div class="n-paginator-left">
|
|
58
|
+
<span class="n-paginator-report">{{ start.value }}-{{ end.value }} of {{ totalRecords }}</span>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="n-paginator-center">
|
|
61
|
+
<button type="button" class="n-pg-btn" :disabled="!canPrev.value" @click="firstPage">«</button>
|
|
62
|
+
<button type="button" class="n-pg-btn" :disabled="!canPrev.value" @click="prev">‹</button>
|
|
63
|
+
<span class="n-pg-page">{{ page.value + 1 }} / {{ pageCount.value }}</span>
|
|
64
|
+
<button type="button" class="n-pg-btn" :disabled="!canNext.value" @click="next">›</button>
|
|
65
|
+
<button type="button" class="n-pg-btn" :disabled="!canNext.value" @click="lastPage">»</button>
|
|
66
|
+
</div>
|
|
67
|
+
<div class="n-paginator-right">
|
|
68
|
+
<select class="n-pg-select" :value="rows" @change="changeRows">
|
|
69
|
+
<option v-for="n in rowsPerPageOptions" :key="n" :value="n">{{ n }}</option>
|
|
70
|
+
</select>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
74
|
+
|
|
75
|
+
<style scoped>
|
|
76
|
+
.n-paginator{display:flex;align-items:center;justify-content:space-between;gap:var(--n-space-3);padding:var(--n-space-3) var(--n-space-4);border-top:1px solid var(--n-color-border);background:var(--n-color-surface);font-family:var(--n-font-sans)}.n-paginator-report{color:var(--n-color-text-muted);font-size:var(--n-text-xs)}.n-paginator-center{display:flex;align-items:center;gap:0.35rem}.n-pg-btn{background:transparent;border:1px solid var(--n-color-border);color:var(--n-color-text);border-radius:var(--n-radius-sm);padding:0.25rem 0.5rem;cursor:pointer;transition:all var(--n-transition-fast)}.n-pg-btn:hover:not(:disabled){background:var(--n-color-glass)}.n-pg-btn:disabled{opacity:0.5;cursor:not-allowed}.n-pg-page{min-width:5rem;text-align:center;color:var(--n-color-text-secondary);font-size:var(--n-text-xs)}.n-pg-select{background:var(--n-color-bg);border:1px solid var(--n-color-border);color:var(--n-color-text);border-radius:var(--n-radius-sm);padding:0.25rem 0.5rem;font-size:var(--n-text-xs);outline:none}
|
|
77
|
+
</style>
|