@emberbox/ui 0.2.0 → 0.3.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/vite.js +2 -0
- package/package.json +1 -1
- package/src/components/CollapsibleSection.vue +75 -0
- package/src/components/ComboboxField.vue +132 -0
- package/src/components/DateTimeField.vue +47 -0
- package/src/components/TextAreaField.vue +14 -0
- package/src/components/TextField.vue +29 -0
- package/src/components/YesNoField.vue +47 -0
- package/src/index.ts +6 -0
- package/src/style.css +9 -0
- package/src/vite.ts +2 -0
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UCard from '@nuxt/ui/components/Card.vue'
|
|
3
|
+
import UIcon from '@nuxt/ui/components/Icon.vue'
|
|
4
|
+
import {onMounted, ref, useId, watch} from 'vue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A section that can be collapsed. With many lists open at once a page is something to scroll
|
|
8
|
+
* through rather than read. The browser remembers what was open, under `name` in the object stored
|
|
9
|
+
* at `storageKey`, so all sections of a tool share one entry. The remembered state is applied after
|
|
10
|
+
* mounting, so prerendered pages hydrate with `defaultOpen` first.
|
|
11
|
+
*/
|
|
12
|
+
const {
|
|
13
|
+
name, title, count, icon, defaultOpen = false, storageKey = 'emberbox_sections', level = 2,
|
|
14
|
+
} = defineProps<{
|
|
15
|
+
/** Key under which the state is remembered. */
|
|
16
|
+
name: string
|
|
17
|
+
/** The browser storage entry that holds the state of all sections. */
|
|
18
|
+
storageKey?: string
|
|
19
|
+
title: string
|
|
20
|
+
/** What the section holds, visible without opening it. */
|
|
21
|
+
count?: number
|
|
22
|
+
/** An icon before the title, where the section is one of several kinds. */
|
|
23
|
+
icon?: string
|
|
24
|
+
/** How it starts while nothing is remembered. */
|
|
25
|
+
defaultOpen?: boolean
|
|
26
|
+
/** The heading level of the title within the page. */
|
|
27
|
+
level?: 2 | 3 | 4
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const bodyId = `${useId()}-body`
|
|
31
|
+
const open = ref(defaultOpen)
|
|
32
|
+
|
|
33
|
+
function remembered(): boolean {
|
|
34
|
+
try {
|
|
35
|
+
const state = JSON.parse(localStorage.getItem(storageKey) ?? '{}')?.[name]
|
|
36
|
+
return state === undefined ? defaultOpen : Boolean(state)
|
|
37
|
+
} catch {
|
|
38
|
+
return defaultOpen
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onMounted(() => {
|
|
43
|
+
open.value = remembered()
|
|
44
|
+
watch(open, value => {
|
|
45
|
+
try {
|
|
46
|
+
const state = JSON.parse(localStorage.getItem(storageKey) ?? '{}') ?? {}
|
|
47
|
+
localStorage.setItem(storageKey, JSON.stringify({...state, [name]: value}))
|
|
48
|
+
} catch {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<UCard :ui="{body: 'p-4 sm:p-4'}">
|
|
57
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
58
|
+
<component :is="`h${level}`" class="section-title m-0 grow">
|
|
59
|
+
<button type="button" class="flex w-full items-center gap-3 text-left" :aria-expanded="open"
|
|
60
|
+
:aria-controls="open ? bodyId : undefined" @click="open = !open">
|
|
61
|
+
<UIcon :name="open ? 'i-lucide-chevron-down' : 'i-lucide-chevron-right'" class="text-muted"/>
|
|
62
|
+
<UIcon v-if="icon" :name="icon" class="text-muted"/>
|
|
63
|
+
<span>{{ title }}</span>
|
|
64
|
+
<span v-if="count !== undefined" class="tabular text-sm font-normal normal-case tracking-normal text-muted">
|
|
65
|
+
{{ count }}
|
|
66
|
+
</span>
|
|
67
|
+
</button>
|
|
68
|
+
</component>
|
|
69
|
+
<slot v-if="open" name="actions"/>
|
|
70
|
+
</div>
|
|
71
|
+
<div v-if="open" :id="bodyId" class="mt-3">
|
|
72
|
+
<slot/>
|
|
73
|
+
</div>
|
|
74
|
+
</UCard>
|
|
75
|
+
</template>
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import UFormField from '@nuxt/ui/components/FormField.vue'
|
|
4
|
+
import UInput from '@nuxt/ui/components/Input.vue'
|
|
5
|
+
import {computed, nextTick, ref, useId, watch} from 'vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A text field that also opens the list it draws on, so an entry can be picked rather than typed,
|
|
9
|
+
* while anything typed stays the value. A bare datalist offers no visible way in.
|
|
10
|
+
*/
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
label: string
|
|
13
|
+
suggestions: string[]
|
|
14
|
+
placeholder?: string
|
|
15
|
+
wide?: boolean
|
|
16
|
+
/** The list already answers the typing; filtering it again here would only cut it down. */
|
|
17
|
+
prefiltered?: boolean
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
}>()
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{ change: [] }>()
|
|
22
|
+
const model = defineModel<string>({default: ''})
|
|
23
|
+
const id = useId()
|
|
24
|
+
const labelId = `${id}-label`
|
|
25
|
+
const input = ref<{ inputRef: HTMLInputElement | null }>()
|
|
26
|
+
const open = ref(false)
|
|
27
|
+
|
|
28
|
+
/** Which entry the arrow keys are on, or -1 while the typing stands on its own. */
|
|
29
|
+
const active = ref(-1)
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Typing narrows the list, but a value taken from the list matches only itself, so a field that
|
|
33
|
+
* already holds an entry would offer that one alone. Showing everything once the text is an exact
|
|
34
|
+
* hit keeps the list usable for changing one's mind.
|
|
35
|
+
*/
|
|
36
|
+
const filtered = computed(() => {
|
|
37
|
+
const search = model.value.trim().toLowerCase()
|
|
38
|
+
if (props.prefiltered || !search) return props.suggestions
|
|
39
|
+
if (props.suggestions.some(value => value.toLowerCase() === search)) return props.suggestions
|
|
40
|
+
return props.suggestions.filter(value => value.toLowerCase().includes(search))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const visible = computed(() => open.value && filtered.value.length > 0)
|
|
44
|
+
const optionId = (index: number) => `${id}-option-${index}`
|
|
45
|
+
|
|
46
|
+
function pick(value: string) {
|
|
47
|
+
model.value = value
|
|
48
|
+
close()
|
|
49
|
+
emit('change')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function close() {
|
|
53
|
+
open.value = false
|
|
54
|
+
active.value = -1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function toggle() {
|
|
58
|
+
open.value = !open.value
|
|
59
|
+
active.value = -1
|
|
60
|
+
if (open.value) input.value?.inputRef?.focus()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Wraps at both ends, so holding one arrow key walks the whole list either way. With nothing
|
|
65
|
+
* highlighted yet, down starts at the top and up at the bottom.
|
|
66
|
+
*/
|
|
67
|
+
async function move(steps: number) {
|
|
68
|
+
const count = filtered.value.length
|
|
69
|
+
if (!count) return
|
|
70
|
+
open.value = true
|
|
71
|
+
active.value = active.value < 0
|
|
72
|
+
? (steps > 0 ? 0 : count - 1)
|
|
73
|
+
: (active.value + steps + count) % count
|
|
74
|
+
await nextTick()
|
|
75
|
+
document.getElementById(optionId(active.value))?.scrollIntoView({block: 'nearest'})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Enter takes the highlighted entry. With nothing highlighted it only closes the list and is
|
|
80
|
+
* otherwise left alone, so the input fires its own change event for what was typed and a
|
|
81
|
+
* surrounding form still submits.
|
|
82
|
+
*/
|
|
83
|
+
function confirm(event: KeyboardEvent) {
|
|
84
|
+
const chosen = visible.value ? filtered.value[active.value] : undefined
|
|
85
|
+
if (chosen === undefined) {
|
|
86
|
+
close()
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
event.preventDefault()
|
|
90
|
+
pick(chosen)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Escape closes an open list without also closing a dialog around the field. */
|
|
94
|
+
function escape(event: KeyboardEvent) {
|
|
95
|
+
if (!visible.value) return
|
|
96
|
+
event.stopPropagation()
|
|
97
|
+
close()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
watch(filtered, () => (active.value = -1))
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<template>
|
|
104
|
+
<UFormField :class="wide ? 'col-span-2' : ''" class="relative">
|
|
105
|
+
<template #label>
|
|
106
|
+
<span :id="labelId">{{ label }}</span>
|
|
107
|
+
</template>
|
|
108
|
+
<UInput ref="input" v-model="model" class="w-full" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
|
|
109
|
+
role="combobox" aria-autocomplete="list" :aria-expanded="visible"
|
|
110
|
+
:aria-controls="visible ? `${id}-list` : undefined"
|
|
111
|
+
:aria-activedescendant="active >= 0 ? optionId(active) : undefined"
|
|
112
|
+
@focus="open = true" @blur="close" @change="emit('change')"
|
|
113
|
+
@keydown.down.prevent="move(1)" @keydown.up.prevent="move(-1)" @keydown.enter="confirm"
|
|
114
|
+
@keydown.tab="close" @keydown.escape="escape">
|
|
115
|
+
<template v-if="suggestions.length" #trailing>
|
|
116
|
+
<UButton color="neutral" variant="link" size="sm" icon="i-lucide-chevron-down" tabindex="-1"
|
|
117
|
+
aria-label="Auswahl öffnen" :aria-expanded="visible" :disabled="disabled"
|
|
118
|
+
@mousedown.prevent @click="toggle"/>
|
|
119
|
+
</template>
|
|
120
|
+
</UInput>
|
|
121
|
+
<ul v-if="visible" :id="`${id}-list`" role="listbox" :aria-labelledby="labelId"
|
|
122
|
+
class="absolute inset-x-0 top-full z-30 mt-1 max-h-64 overflow-auto rounded-sm border border-default bg-default py-1 shadow-lg">
|
|
123
|
+
<li v-for="(value, index) in filtered" :id="optionId(index)" :key="`${index}-${value}`" role="option"
|
|
124
|
+
:aria-selected="index === active"
|
|
125
|
+
class="cursor-pointer px-3 py-1.5 text-sm"
|
|
126
|
+
:class="[index === active ? 'bg-elevated' : '', value === model ? 'font-semibold' : '']"
|
|
127
|
+
@mousedown.prevent="pick(value)" @mousemove="active = index">
|
|
128
|
+
{{ value }}
|
|
129
|
+
</li>
|
|
130
|
+
</ul>
|
|
131
|
+
</UFormField>
|
|
132
|
+
</template>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UFormField from '@nuxt/ui/components/FormField.vue'
|
|
3
|
+
import UInput from '@nuxt/ui/components/Input.vue'
|
|
4
|
+
import {computed} from 'vue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One date-time field for a date and a time kept as two strings in German notation, as a printed
|
|
8
|
+
* form shows them. They are entered with the browser's picker, which brings a calendar and a clock.
|
|
9
|
+
* The field reads `19.9.2026` and `8:00` as well as zero-padded values, and writes zero-padded ones
|
|
10
|
+
* (`19.09.2026`, `08:00`). A date without a time shows as midnight, so the first edit writes
|
|
11
|
+
* `00:00`; a date that does not exist, such as `31.2.2026`, shows as an empty field.
|
|
12
|
+
*/
|
|
13
|
+
const date = defineModel<string>('date', {default: ''})
|
|
14
|
+
const time = defineModel<string>('time', {default: ''})
|
|
15
|
+
const {label, disabled} = defineProps<{ label: string, disabled?: boolean }>()
|
|
16
|
+
/** Fires only once both values are set, so listeners never see half a change. */
|
|
17
|
+
const emit = defineEmits<{ change: [] }>()
|
|
18
|
+
|
|
19
|
+
/** Turns "19.9.2026" and "08:00" into what a `datetime-local` understands, or into nothing. */
|
|
20
|
+
const value = computed(() => {
|
|
21
|
+
const day = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(date.value.trim())
|
|
22
|
+
const clock = /^(\d{1,2}):(\d{2})/.exec(time.value.trim())
|
|
23
|
+
if (!day) return ''
|
|
24
|
+
const isoDay = `${day[3]}-${day[2]!.padStart(2, '0')}-${day[1]!.padStart(2, '0')}`
|
|
25
|
+
return clock ? `${isoDay}T${clock[1]!.padStart(2, '0')}:${clock[2]}` : `${isoDay}T00:00`
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
/** Back to the slip's notation; clearing the field clears both values. */
|
|
29
|
+
function update(input: string) {
|
|
30
|
+
const parts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(input)
|
|
31
|
+
if (!parts) {
|
|
32
|
+
date.value = ''
|
|
33
|
+
time.value = ''
|
|
34
|
+
} else {
|
|
35
|
+
date.value = `${parts[3]}.${parts[2]}.${parts[1]}`
|
|
36
|
+
time.value = `${parts[4]}:${parts[5]}`
|
|
37
|
+
}
|
|
38
|
+
emit('change')
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<UFormField :label="label">
|
|
44
|
+
<UInput :model-value="value" type="datetime-local" step="60" class="w-full" :disabled="disabled"
|
|
45
|
+
@change="update(($event.target as HTMLInputElement).value)"/>
|
|
46
|
+
</UFormField>
|
|
47
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UFormField from '@nuxt/ui/components/FormField.vue'
|
|
3
|
+
import UTextarea from '@nuxt/ui/components/Textarea.vue'
|
|
4
|
+
|
|
5
|
+
/** A labelled multi-line text field. */
|
|
6
|
+
defineProps<{ label: string, placeholder?: string, rows?: number, disabled?: boolean }>()
|
|
7
|
+
const model = defineModel<string>({default: ''})
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<UFormField :label="label">
|
|
12
|
+
<UTextarea v-model="model" class="w-full" :rows="rows ?? 3" :placeholder="placeholder" :disabled="disabled"/>
|
|
13
|
+
</UFormField>
|
|
14
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UFormField from '@nuxt/ui/components/FormField.vue'
|
|
3
|
+
import UInput from '@nuxt/ui/components/Input.vue'
|
|
4
|
+
import {computed, useId} from 'vue'
|
|
5
|
+
|
|
6
|
+
/** A labelled single-line text field, optionally offering suggestions from a list while typing. */
|
|
7
|
+
const props = defineProps<{
|
|
8
|
+
label: string
|
|
9
|
+
suggestions?: string[]
|
|
10
|
+
placeholder?: string
|
|
11
|
+
/** Spans two columns in a grid. */
|
|
12
|
+
wide?: boolean
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
defineEmits<{ change: [] }>()
|
|
17
|
+
const model = defineModel<string>({default: ''})
|
|
18
|
+
const id = useId()
|
|
19
|
+
const listId = computed(() => props.suggestions?.length ? `${id}-list` : undefined)
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<UFormField :label="label" :class="wide ? 'col-span-2' : ''">
|
|
24
|
+
<UInput v-model="model" class="w-full" :list="listId" :placeholder="placeholder" :disabled="disabled" @change="$emit('change')"/>
|
|
25
|
+
<datalist v-if="listId" :id="listId">
|
|
26
|
+
<option v-for="value in suggestions" :key="value" :value="value"/>
|
|
27
|
+
</datalist>
|
|
28
|
+
</UFormField>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import UFieldGroup from '@nuxt/ui/components/FieldGroup.vue'
|
|
4
|
+
import UFormField from '@nuxt/ui/components/FormField.vue'
|
|
5
|
+
import {useId} from 'vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A yes/no choice as two buttons. The stored values and the button labels are configurable, so a
|
|
9
|
+
* tool can store exactly what it prints, such as `J` and `N`; `yesTitle` and `noTitle` spell out
|
|
10
|
+
* labels that are abbreviations.
|
|
11
|
+
*/
|
|
12
|
+
const {
|
|
13
|
+
yesValue = 'ja',
|
|
14
|
+
noValue = 'nein',
|
|
15
|
+
yesLabel = 'Ja',
|
|
16
|
+
noLabel = 'Nein',
|
|
17
|
+
} = defineProps<{
|
|
18
|
+
label: string
|
|
19
|
+
yesValue?: string
|
|
20
|
+
noValue?: string
|
|
21
|
+
yesLabel?: string
|
|
22
|
+
noLabel?: string
|
|
23
|
+
yesTitle?: string
|
|
24
|
+
noTitle?: string
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
}>()
|
|
27
|
+
const model = defineModel<string>({required: true})
|
|
28
|
+
const labelId = `${useId()}-label`
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<UFormField>
|
|
33
|
+
<template #label>
|
|
34
|
+
<span :id="labelId">{{ label }}</span>
|
|
35
|
+
</template>
|
|
36
|
+
<UFieldGroup role="group" :aria-labelledby="labelId">
|
|
37
|
+
<UButton size="sm" :color="model === yesValue ? 'primary' : 'neutral'"
|
|
38
|
+
:variant="model === yesValue ? 'solid' : 'outline'" :label="yesLabel" :title="yesTitle"
|
|
39
|
+
:aria-label="yesTitle" :aria-pressed="model === yesValue" :disabled="disabled"
|
|
40
|
+
@click="model = yesValue"/>
|
|
41
|
+
<UButton size="sm" :color="model === noValue ? 'primary' : 'neutral'"
|
|
42
|
+
:variant="model === noValue ? 'solid' : 'outline'" :label="noLabel" :title="noTitle"
|
|
43
|
+
:aria-label="noTitle" :aria-pressed="model === noValue" :disabled="disabled"
|
|
44
|
+
@click="model = noValue"/>
|
|
45
|
+
</UFieldGroup>
|
|
46
|
+
</UFormField>
|
|
47
|
+
</template>
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,12 @@ export {default as HelpPage} from './components/HelpPage.vue'
|
|
|
20
20
|
export {default as HelpSection} from './components/HelpSection.vue'
|
|
21
21
|
export {default as HelpTopic} from './components/HelpTopic.vue'
|
|
22
22
|
export {default as HelpMockup} from './components/HelpMockup.vue'
|
|
23
|
+
export {default as TextField} from './components/TextField.vue'
|
|
24
|
+
export {default as TextAreaField} from './components/TextAreaField.vue'
|
|
25
|
+
export {default as ComboboxField} from './components/ComboboxField.vue'
|
|
26
|
+
export {default as YesNoField} from './components/YesNoField.vue'
|
|
27
|
+
export {default as DateTimeField} from './components/DateTimeField.vue'
|
|
28
|
+
export {default as CollapsibleSection} from './components/CollapsibleSection.vue'
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Vue plugin that installs Nuxt UI in the Emberbox style. Icons come only from the bundled set; a
|
package/src/style.css
CHANGED
|
@@ -170,3 +170,12 @@ body {
|
|
|
170
170
|
text-transform: uppercase;
|
|
171
171
|
color: var(--ui-text-muted);
|
|
172
172
|
}
|
|
173
|
+
|
|
174
|
+
@utility section-title {
|
|
175
|
+
font-family: var(--font-condensed);
|
|
176
|
+
font-weight: 700;
|
|
177
|
+
font-size: 15px;
|
|
178
|
+
letter-spacing: 0.06em;
|
|
179
|
+
text-transform: uppercase;
|
|
180
|
+
color: var(--ui-text-highlighted);
|
|
181
|
+
}
|