@bwui/vue 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/cn.d.ts +1 -0
- package/dist/cn.js +3 -0
- package/dist/combobox.d.ts +59 -0
- package/dist/combobox.js +119 -0
- package/dist/date-picker.d.ts +70 -0
- package/dist/date-picker.js +237 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/pages.d.ts +89 -0
- package/dist/pages.js +149 -0
- package/dist/primitives.d.ts +171 -0
- package/dist/primitives.js +173 -0
- package/package.json +42 -3
- package/src/cn.ts +3 -0
- package/src/combobox.ts +147 -0
- package/src/date-picker.ts +283 -0
- package/src/index.ts +37 -0
- package/src/pages.ts +173 -0
- package/src/primitives.ts +256 -0
package/src/combobox.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { computed, defineComponent, h, onMounted, onUnmounted, ref, type PropType } from 'vue'
|
|
2
|
+
import { cn } from './cn'
|
|
3
|
+
|
|
4
|
+
export type ComboboxOption = { value: string; label: string; disabled?: boolean }
|
|
5
|
+
|
|
6
|
+
export const Combobox = defineComponent({
|
|
7
|
+
name: 'BwCombobox',
|
|
8
|
+
props: {
|
|
9
|
+
id: String,
|
|
10
|
+
name: String,
|
|
11
|
+
options: { type: Array as PropType<ComboboxOption[]>, required: true },
|
|
12
|
+
modelValue: { type: String, default: '' },
|
|
13
|
+
placeholder: { type: String, default: 'Search' },
|
|
14
|
+
disabled: Boolean,
|
|
15
|
+
required: Boolean,
|
|
16
|
+
emptyLabel: { type: String, default: 'No matches' },
|
|
17
|
+
},
|
|
18
|
+
emits: ['update:modelValue'],
|
|
19
|
+
setup(props, { emit, attrs }) {
|
|
20
|
+
const open = ref(false)
|
|
21
|
+
const query = ref('')
|
|
22
|
+
const active = ref(0)
|
|
23
|
+
const root = ref<HTMLElement | null>(null)
|
|
24
|
+
|
|
25
|
+
const selected = computed(
|
|
26
|
+
() => props.options.find((o) => o.value === props.modelValue) ?? null,
|
|
27
|
+
)
|
|
28
|
+
const filtered = computed(() => {
|
|
29
|
+
const q = query.value.trim().toLowerCase()
|
|
30
|
+
if (!q) return props.options
|
|
31
|
+
return props.options.filter((o) => o.label.toLowerCase().includes(q))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
function commit(value: string) {
|
|
35
|
+
emit('update:modelValue', value)
|
|
36
|
+
query.value = props.options.find((o) => o.value === value)?.label ?? value
|
|
37
|
+
open.value = false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function onPointer(e: PointerEvent) {
|
|
41
|
+
if (!root.value?.contains(e.target as Node)) open.value = false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onMounted(() => document.addEventListener('pointerdown', onPointer))
|
|
45
|
+
onUnmounted(() => document.removeEventListener('pointerdown', onPointer))
|
|
46
|
+
|
|
47
|
+
return () =>
|
|
48
|
+
h(
|
|
49
|
+
'div',
|
|
50
|
+
{
|
|
51
|
+
ref: root,
|
|
52
|
+
class: cn('bw-combobox', String(attrs.class || '')),
|
|
53
|
+
'data-bw-combobox': '',
|
|
54
|
+
...(open.value ? { 'data-bw-open': '' } : {}),
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
h(
|
|
58
|
+
'select',
|
|
59
|
+
{
|
|
60
|
+
class: 'bw-input bw-combobox__floor',
|
|
61
|
+
id: props.id,
|
|
62
|
+
name: props.name,
|
|
63
|
+
value: props.modelValue,
|
|
64
|
+
required: props.required,
|
|
65
|
+
disabled: props.disabled,
|
|
66
|
+
tabindex: -1,
|
|
67
|
+
'aria-hidden': 'true',
|
|
68
|
+
hidden: true,
|
|
69
|
+
onChange: (e: Event) => commit((e.target as HTMLSelectElement).value),
|
|
70
|
+
},
|
|
71
|
+
[
|
|
72
|
+
h('option', { value: '' }, 'Choose'),
|
|
73
|
+
...props.options.map((opt) =>
|
|
74
|
+
h('option', { value: opt.value, disabled: opt.disabled }, opt.label),
|
|
75
|
+
),
|
|
76
|
+
],
|
|
77
|
+
),
|
|
78
|
+
h('div', { class: 'bw-combobox__field' }, [
|
|
79
|
+
h('input', {
|
|
80
|
+
class: 'bw-input bw-combobox__input',
|
|
81
|
+
role: 'combobox',
|
|
82
|
+
'aria-expanded': open.value,
|
|
83
|
+
autocomplete: 'off',
|
|
84
|
+
disabled: props.disabled,
|
|
85
|
+
placeholder: props.placeholder,
|
|
86
|
+
value: open.value ? query.value : (selected.value?.label ?? query.value),
|
|
87
|
+
onFocus: () => {
|
|
88
|
+
open.value = true
|
|
89
|
+
},
|
|
90
|
+
onInput: (e: Event) => {
|
|
91
|
+
query.value = (e.target as HTMLInputElement).value
|
|
92
|
+
open.value = true
|
|
93
|
+
active.value = 0
|
|
94
|
+
},
|
|
95
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
96
|
+
if (e.key === 'ArrowDown') {
|
|
97
|
+
e.preventDefault()
|
|
98
|
+
open.value = true
|
|
99
|
+
active.value = Math.min(active.value + 1, Math.max(filtered.value.length - 1, 0))
|
|
100
|
+
} else if (e.key === 'ArrowUp') {
|
|
101
|
+
e.preventDefault()
|
|
102
|
+
active.value = Math.max(active.value - 1, 0)
|
|
103
|
+
} else if (e.key === 'Enter') {
|
|
104
|
+
e.preventDefault()
|
|
105
|
+
const opt = filtered.value[active.value]
|
|
106
|
+
if (opt && !opt.disabled) commit(opt.value)
|
|
107
|
+
} else if (e.key === 'Escape') {
|
|
108
|
+
open.value = false
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
h(
|
|
113
|
+
'ul',
|
|
114
|
+
{ class: 'bw-combobox__listbox', role: 'listbox' },
|
|
115
|
+
[
|
|
116
|
+
...filtered.value.map((opt, idx) =>
|
|
117
|
+
h(
|
|
118
|
+
'li',
|
|
119
|
+
{
|
|
120
|
+
class: 'bw-combobox__option',
|
|
121
|
+
role: 'option',
|
|
122
|
+
'data-bw-value': opt.value,
|
|
123
|
+
'aria-selected': opt.value === props.modelValue,
|
|
124
|
+
...(idx === active.value ? { 'data-bw-active': '' } : {}),
|
|
125
|
+
onMousemove: () => {
|
|
126
|
+
active.value = idx
|
|
127
|
+
},
|
|
128
|
+
onMousedown: (e: MouseEvent) => {
|
|
129
|
+
e.preventDefault()
|
|
130
|
+
if (!opt.disabled) commit(opt.value)
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
opt.label,
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
h(
|
|
137
|
+
'li',
|
|
138
|
+
{ class: 'bw-combobox__empty', hidden: filtered.value.length > 0 },
|
|
139
|
+
props.emptyLabel,
|
|
140
|
+
),
|
|
141
|
+
],
|
|
142
|
+
),
|
|
143
|
+
]),
|
|
144
|
+
],
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
})
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { defineComponent, h, onMounted, onUnmounted, ref } from 'vue'
|
|
2
|
+
import { cn } from './cn'
|
|
3
|
+
|
|
4
|
+
const MONTHS = [
|
|
5
|
+
'January',
|
|
6
|
+
'February',
|
|
7
|
+
'March',
|
|
8
|
+
'April',
|
|
9
|
+
'May',
|
|
10
|
+
'June',
|
|
11
|
+
'July',
|
|
12
|
+
'August',
|
|
13
|
+
'September',
|
|
14
|
+
'October',
|
|
15
|
+
'November',
|
|
16
|
+
'December',
|
|
17
|
+
]
|
|
18
|
+
const DOW = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
|
|
19
|
+
|
|
20
|
+
function parseISO(s: string | undefined): Date | null {
|
|
21
|
+
if (!s) return null
|
|
22
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s)
|
|
23
|
+
if (!m) return null
|
|
24
|
+
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function toISO(d: Date): string {
|
|
28
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sameDay(a: Date | null, b: Date | null): boolean {
|
|
32
|
+
return Boolean(
|
|
33
|
+
a &&
|
|
34
|
+
b &&
|
|
35
|
+
a.getFullYear() === b.getFullYear() &&
|
|
36
|
+
a.getMonth() === b.getMonth() &&
|
|
37
|
+
a.getDate() === b.getDate(),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Calendar(opts: {
|
|
42
|
+
view: Date
|
|
43
|
+
selected?: Date | null
|
|
44
|
+
rangeStart?: Date | null
|
|
45
|
+
rangeEnd?: Date | null
|
|
46
|
+
onView: (view: Date) => void
|
|
47
|
+
onSelect: (date: Date) => void
|
|
48
|
+
}) {
|
|
49
|
+
const first = new Date(opts.view.getFullYear(), opts.view.getMonth(), 1)
|
|
50
|
+
const startDow = (first.getDay() + 6) % 7
|
|
51
|
+
const count = new Date(opts.view.getFullYear(), opts.view.getMonth() + 1, 0).getDate()
|
|
52
|
+
const cells: Array<Date | null> = Array.from({ length: startDow }, () => null)
|
|
53
|
+
for (let day = 1; day <= count; day += 1) {
|
|
54
|
+
cells.push(new Date(opts.view.getFullYear(), opts.view.getMonth(), day))
|
|
55
|
+
}
|
|
56
|
+
return h('div', { class: 'bw-calendar' }, [
|
|
57
|
+
h('div', { class: 'bw-calendar__nav' }, [
|
|
58
|
+
h(
|
|
59
|
+
'button',
|
|
60
|
+
{
|
|
61
|
+
type: 'button',
|
|
62
|
+
class: 'bw-btn bw-btn--ghost bw-btn--sm',
|
|
63
|
+
'aria-label': 'Previous month',
|
|
64
|
+
onClick: () =>
|
|
65
|
+
opts.onView(new Date(opts.view.getFullYear(), opts.view.getMonth() - 1, 1)),
|
|
66
|
+
},
|
|
67
|
+
'Prev',
|
|
68
|
+
),
|
|
69
|
+
h('p', { class: 'bw-calendar__title' }, `${MONTHS[opts.view.getMonth()]} ${opts.view.getFullYear()}`),
|
|
70
|
+
h(
|
|
71
|
+
'button',
|
|
72
|
+
{
|
|
73
|
+
type: 'button',
|
|
74
|
+
class: 'bw-btn bw-btn--ghost bw-btn--sm',
|
|
75
|
+
'aria-label': 'Next month',
|
|
76
|
+
onClick: () =>
|
|
77
|
+
opts.onView(new Date(opts.view.getFullYear(), opts.view.getMonth() + 1, 1)),
|
|
78
|
+
},
|
|
79
|
+
'Next',
|
|
80
|
+
),
|
|
81
|
+
]),
|
|
82
|
+
h('div', { class: 'bw-calendar__grid' }, [
|
|
83
|
+
...DOW.map((d) => h('div', { class: 'bw-calendar__dow' }, d)),
|
|
84
|
+
...cells.map((date, i) => {
|
|
85
|
+
if (!date) return h('div', { key: `blank-${i}` })
|
|
86
|
+
const inRange = Boolean(
|
|
87
|
+
opts.rangeStart && opts.rangeEnd && date > opts.rangeStart && date < opts.rangeEnd,
|
|
88
|
+
)
|
|
89
|
+
const isSelected =
|
|
90
|
+
sameDay(date, opts.selected ?? null) ||
|
|
91
|
+
sameDay(date, opts.rangeStart ?? null) ||
|
|
92
|
+
sameDay(date, opts.rangeEnd ?? null)
|
|
93
|
+
return h(
|
|
94
|
+
'button',
|
|
95
|
+
{
|
|
96
|
+
key: toISO(date),
|
|
97
|
+
type: 'button',
|
|
98
|
+
class: 'bw-calendar__day',
|
|
99
|
+
'aria-label': toISO(date),
|
|
100
|
+
'aria-selected': isSelected,
|
|
101
|
+
...(inRange ? { 'data-bw-in-range': '' } : {}),
|
|
102
|
+
onClick: () => opts.onSelect(date),
|
|
103
|
+
},
|
|
104
|
+
String(date.getDate()),
|
|
105
|
+
)
|
|
106
|
+
}),
|
|
107
|
+
]),
|
|
108
|
+
])
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const DatePicker = defineComponent({
|
|
112
|
+
name: 'BwDatePicker',
|
|
113
|
+
props: {
|
|
114
|
+
id: String,
|
|
115
|
+
name: String,
|
|
116
|
+
modelValue: { type: String, default: '' },
|
|
117
|
+
placeholder: { type: String, default: 'YYYY-MM-DD' },
|
|
118
|
+
disabled: Boolean,
|
|
119
|
+
required: Boolean,
|
|
120
|
+
},
|
|
121
|
+
emits: ['update:modelValue'],
|
|
122
|
+
setup(props, { emit, attrs }) {
|
|
123
|
+
const open = ref(false)
|
|
124
|
+
const parsed = parseISO(props.modelValue) || new Date()
|
|
125
|
+
const view = ref(new Date(parsed.getFullYear(), parsed.getMonth(), 1))
|
|
126
|
+
const root = ref<HTMLElement | null>(null)
|
|
127
|
+
|
|
128
|
+
function onPointer(e: PointerEvent) {
|
|
129
|
+
if (!root.value?.contains(e.target as Node)) open.value = false
|
|
130
|
+
}
|
|
131
|
+
onMounted(() => document.addEventListener('pointerdown', onPointer))
|
|
132
|
+
onUnmounted(() => document.removeEventListener('pointerdown', onPointer))
|
|
133
|
+
|
|
134
|
+
return () =>
|
|
135
|
+
h('div', { ref: root, class: cn('bw-date-picker-chrome', String(attrs.class || '')) }, [
|
|
136
|
+
h('div', { class: 'bw-date-picker-chrome__field' }, [
|
|
137
|
+
h('input', {
|
|
138
|
+
id: props.id,
|
|
139
|
+
name: props.name,
|
|
140
|
+
class: 'bw-input',
|
|
141
|
+
value: props.modelValue,
|
|
142
|
+
required: props.required,
|
|
143
|
+
disabled: props.disabled,
|
|
144
|
+
placeholder: props.placeholder,
|
|
145
|
+
autocomplete: 'off',
|
|
146
|
+
onInput: (e: Event) => emit('update:modelValue', (e.target as HTMLInputElement).value),
|
|
147
|
+
onFocus: () => {
|
|
148
|
+
open.value = true
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
h(
|
|
152
|
+
'button',
|
|
153
|
+
{
|
|
154
|
+
type: 'button',
|
|
155
|
+
class: 'bw-date-picker-chrome__trigger',
|
|
156
|
+
'aria-label': 'Open calendar',
|
|
157
|
+
disabled: props.disabled,
|
|
158
|
+
onClick: () => {
|
|
159
|
+
open.value = !open.value
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
'Cal',
|
|
163
|
+
),
|
|
164
|
+
]),
|
|
165
|
+
h('div', { class: 'bw-date-picker-chrome__panel', hidden: !open.value }, [
|
|
166
|
+
Calendar({
|
|
167
|
+
view: view.value,
|
|
168
|
+
selected: parseISO(props.modelValue),
|
|
169
|
+
onView: (next) => {
|
|
170
|
+
view.value = next
|
|
171
|
+
},
|
|
172
|
+
onSelect: (date) => {
|
|
173
|
+
emit('update:modelValue', toISO(date))
|
|
174
|
+
open.value = false
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
]),
|
|
178
|
+
])
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
export const DateRangePicker = defineComponent({
|
|
183
|
+
name: 'BwDateRangePicker',
|
|
184
|
+
props: {
|
|
185
|
+
start: { type: String, default: '' },
|
|
186
|
+
end: { type: String, default: '' },
|
|
187
|
+
startName: String,
|
|
188
|
+
endName: String,
|
|
189
|
+
disabled: Boolean,
|
|
190
|
+
},
|
|
191
|
+
emits: ['update:start', 'update:end'],
|
|
192
|
+
setup(props, { emit, attrs }) {
|
|
193
|
+
const open = ref(false)
|
|
194
|
+
const parsed = parseISO(props.start) || new Date()
|
|
195
|
+
const view = ref(new Date(parsed.getFullYear(), parsed.getMonth(), 1))
|
|
196
|
+
const root = ref<HTMLElement | null>(null)
|
|
197
|
+
|
|
198
|
+
function onPointer(e: PointerEvent) {
|
|
199
|
+
if (!root.value?.contains(e.target as Node)) open.value = false
|
|
200
|
+
}
|
|
201
|
+
onMounted(() => document.addEventListener('pointerdown', onPointer))
|
|
202
|
+
onUnmounted(() => document.removeEventListener('pointerdown', onPointer))
|
|
203
|
+
|
|
204
|
+
return () =>
|
|
205
|
+
h(
|
|
206
|
+
'div',
|
|
207
|
+
{
|
|
208
|
+
ref: root,
|
|
209
|
+
class: cn('bw-date-picker-chrome', String(attrs.class || '')),
|
|
210
|
+
'data-bw-range': 'true',
|
|
211
|
+
},
|
|
212
|
+
[
|
|
213
|
+
h('div', { class: 'bw-date-picker-chrome__range' }, [
|
|
214
|
+
h('input', {
|
|
215
|
+
name: props.startName,
|
|
216
|
+
class: 'bw-input',
|
|
217
|
+
value: props.start,
|
|
218
|
+
disabled: props.disabled,
|
|
219
|
+
placeholder: 'From',
|
|
220
|
+
autocomplete: 'off',
|
|
221
|
+
onInput: (e: Event) => emit('update:start', (e.target as HTMLInputElement).value),
|
|
222
|
+
onFocus: () => {
|
|
223
|
+
open.value = true
|
|
224
|
+
},
|
|
225
|
+
}),
|
|
226
|
+
h('span', { class: 'bw-date-picker-chrome__separator' }, 'to'),
|
|
227
|
+
h('input', {
|
|
228
|
+
name: props.endName,
|
|
229
|
+
class: 'bw-input',
|
|
230
|
+
value: props.end,
|
|
231
|
+
disabled: props.disabled,
|
|
232
|
+
placeholder: 'To',
|
|
233
|
+
autocomplete: 'off',
|
|
234
|
+
onInput: (e: Event) => emit('update:end', (e.target as HTMLInputElement).value),
|
|
235
|
+
onFocus: () => {
|
|
236
|
+
open.value = true
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
h(
|
|
240
|
+
'button',
|
|
241
|
+
{
|
|
242
|
+
type: 'button',
|
|
243
|
+
class: 'bw-date-picker-chrome__trigger',
|
|
244
|
+
'aria-label': 'Open range calendar',
|
|
245
|
+
disabled: props.disabled,
|
|
246
|
+
onClick: () => {
|
|
247
|
+
open.value = !open.value
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
'Cal',
|
|
251
|
+
),
|
|
252
|
+
]),
|
|
253
|
+
h('div', { class: 'bw-date-picker-chrome__panel', hidden: !open.value }, [
|
|
254
|
+
Calendar({
|
|
255
|
+
view: view.value,
|
|
256
|
+
rangeStart: parseISO(props.start),
|
|
257
|
+
rangeEnd: parseISO(props.end),
|
|
258
|
+
onView: (next) => {
|
|
259
|
+
view.value = next
|
|
260
|
+
},
|
|
261
|
+
onSelect: (date) => {
|
|
262
|
+
const currentStart = parseISO(props.start)
|
|
263
|
+
const currentEnd = parseISO(props.end)
|
|
264
|
+
if (!currentStart || currentEnd) {
|
|
265
|
+
emit('update:start', toISO(date))
|
|
266
|
+
emit('update:end', '')
|
|
267
|
+
return
|
|
268
|
+
}
|
|
269
|
+
if (date < currentStart) {
|
|
270
|
+
emit('update:start', toISO(date))
|
|
271
|
+
emit('update:end', toISO(currentStart))
|
|
272
|
+
open.value = false
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
emit('update:end', toISO(date))
|
|
276
|
+
open.value = false
|
|
277
|
+
},
|
|
278
|
+
}),
|
|
279
|
+
]),
|
|
280
|
+
],
|
|
281
|
+
)
|
|
282
|
+
},
|
|
283
|
+
})
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Button,
|
|
3
|
+
ButtonLink,
|
|
4
|
+
Badge,
|
|
5
|
+
Card,
|
|
6
|
+
Alert,
|
|
7
|
+
Stack,
|
|
8
|
+
Cluster,
|
|
9
|
+
Grid,
|
|
10
|
+
Container,
|
|
11
|
+
Field,
|
|
12
|
+
Form,
|
|
13
|
+
FormActions,
|
|
14
|
+
Label,
|
|
15
|
+
Hint,
|
|
16
|
+
FieldError,
|
|
17
|
+
Input,
|
|
18
|
+
Textarea,
|
|
19
|
+
Select,
|
|
20
|
+
Checkbox,
|
|
21
|
+
Radio,
|
|
22
|
+
TimeInput,
|
|
23
|
+
DateTimeInput,
|
|
24
|
+
SkipLink,
|
|
25
|
+
ThemeToggle,
|
|
26
|
+
} from './primitives'
|
|
27
|
+
|
|
28
|
+
export { Combobox } from './combobox'
|
|
29
|
+
export type { ComboboxOption } from './combobox'
|
|
30
|
+
|
|
31
|
+
export { DatePicker, DateRangePicker } from './date-picker'
|
|
32
|
+
|
|
33
|
+
export { Homepage, Landing, ContactForm } from './pages'
|
|
34
|
+
|
|
35
|
+
export { cn } from './cn'
|
|
36
|
+
|
|
37
|
+
export * as tokens from '@bwui/tokens'
|
package/src/pages.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { defineComponent, h, type PropType } from 'vue'
|
|
2
|
+
import { Combobox, type ComboboxOption } from './combobox'
|
|
3
|
+
import { DatePicker, DateRangePicker } from './date-picker'
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
ButtonLink,
|
|
7
|
+
Card,
|
|
8
|
+
Checkbox,
|
|
9
|
+
Cluster,
|
|
10
|
+
Field,
|
|
11
|
+
Form,
|
|
12
|
+
FormActions,
|
|
13
|
+
Hint,
|
|
14
|
+
Input,
|
|
15
|
+
Label,
|
|
16
|
+
SkipLink,
|
|
17
|
+
Stack,
|
|
18
|
+
Textarea,
|
|
19
|
+
ThemeToggle,
|
|
20
|
+
TimeInput,
|
|
21
|
+
} from './primitives'
|
|
22
|
+
|
|
23
|
+
export const Homepage = defineComponent({
|
|
24
|
+
name: 'BwHomepage',
|
|
25
|
+
props: {
|
|
26
|
+
brand: { type: String, default: 'Brickwork' },
|
|
27
|
+
title: { type: String, default: 'Beautiful interfaces, out of the box' },
|
|
28
|
+
description: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: 'Install a Brickwork delivery, copy a gallery template, brand with tokens, ship.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
setup(props) {
|
|
34
|
+
return () => [
|
|
35
|
+
h(SkipLink),
|
|
36
|
+
h('header', { class: 'bw-shell-marketing__header' }, [
|
|
37
|
+
h(Cluster, { style: { justifyContent: 'space-between', padding: 'var(--bw-space-4) var(--bw-space-6)' } }, () => [
|
|
38
|
+
h('strong', { class: 'bw-text-title-md' }, props.brand),
|
|
39
|
+
h('nav', { class: 'bw-cluster', 'aria-label': 'Primary' }, [
|
|
40
|
+
h(ButtonLink, { href: '#features', variant: 'ghost' }, () => 'Features'),
|
|
41
|
+
h(ButtonLink, { href: '/gallery/landing', variant: 'ghost' }, () => 'Landing'),
|
|
42
|
+
h(ButtonLink, { href: '/gallery/forms', variant: 'primary' }, () => 'Contact'),
|
|
43
|
+
h(ThemeToggle),
|
|
44
|
+
]),
|
|
45
|
+
]),
|
|
46
|
+
]),
|
|
47
|
+
h('main', { id: 'main' }, [
|
|
48
|
+
h('section', { class: 'bw-hero', style: { padding: 'var(--bw-space-12) var(--bw-space-6)' } }, [
|
|
49
|
+
h(Stack, { style: { maxWidth: '40rem' } }, () => [
|
|
50
|
+
h('h1', { class: 'bw-text-display-md' }, props.title),
|
|
51
|
+
h('p', { class: 'bw-text-body-lg', style: { color: 'var(--bw-color-fg-muted)' } }, props.description),
|
|
52
|
+
h(Cluster, () => [
|
|
53
|
+
h(ButtonLink, { href: '/gallery/forms', variant: 'primary', size: 'lg' }, () => 'Get started'),
|
|
54
|
+
h(ButtonLink, { href: '/gallery/landing', variant: 'ghost', size: 'lg' }, () => 'See landing'),
|
|
55
|
+
]),
|
|
56
|
+
]),
|
|
57
|
+
]),
|
|
58
|
+
h(
|
|
59
|
+
'section',
|
|
60
|
+
{
|
|
61
|
+
id: 'features',
|
|
62
|
+
style: { padding: 'var(--bw-space-10) var(--bw-space-6)', background: 'var(--bw-color-surface-2)' },
|
|
63
|
+
},
|
|
64
|
+
[
|
|
65
|
+
h('div', { class: 'bw-grid' }, [
|
|
66
|
+
h(Card, () => [h('h2', { class: 'bw-text-title-sm' }, 'Tokens'), h('p', 'One --bw-* source.')]),
|
|
67
|
+
h(Card, () => [h('h2', { class: 'bw-text-title-sm' }, 'Components'), h('p', 'Same chrome on every stack.')]),
|
|
68
|
+
h(Card, () => [h('h2', { class: 'bw-text-title-sm' }, 'Gallery'), h('p', 'Homepage, landing, forms.')]),
|
|
69
|
+
]),
|
|
70
|
+
],
|
|
71
|
+
),
|
|
72
|
+
]),
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export const Landing = defineComponent({
|
|
78
|
+
name: 'BwLanding',
|
|
79
|
+
props: {
|
|
80
|
+
brand: { type: String, default: 'Brickwork' },
|
|
81
|
+
title: { type: String, default: 'Ship your next interface this afternoon' },
|
|
82
|
+
description: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: 'One primary offer. One CTA. Gallery landings stay focused on conversion.',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
setup(props) {
|
|
88
|
+
return () => [
|
|
89
|
+
h(SkipLink),
|
|
90
|
+
h('header', { style: { padding: 'var(--bw-space-4) var(--bw-space-6)' } }, [
|
|
91
|
+
h(Cluster, { style: { justifyContent: 'space-between' } }, () => [
|
|
92
|
+
h('strong', { class: 'bw-text-title-md' }, props.brand),
|
|
93
|
+
h(ThemeToggle),
|
|
94
|
+
]),
|
|
95
|
+
]),
|
|
96
|
+
h('main', { id: 'main', style: { padding: 'var(--bw-space-12) var(--bw-space-6)' } }, [
|
|
97
|
+
h(Stack, { class: 'bw-centre', style: { textAlign: 'center' } }, () => [
|
|
98
|
+
h('h1', { class: 'bw-text-display-sm' }, props.title),
|
|
99
|
+
h('p', { class: 'bw-text-body-lg', style: { color: 'var(--bw-color-fg-muted)' } }, props.description),
|
|
100
|
+
h(Cluster, { style: { justifyContent: 'center' } }, () => [
|
|
101
|
+
h(ButtonLink, { href: '/gallery/forms', variant: 'primary', size: 'lg' }, () => 'Start free'),
|
|
102
|
+
h(ButtonLink, { href: '/gallery/homepage', variant: 'ghost', size: 'lg' }, () => 'Back to homepage'),
|
|
103
|
+
]),
|
|
104
|
+
]),
|
|
105
|
+
]),
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export const ContactForm = defineComponent({
|
|
111
|
+
name: 'BwContactForm',
|
|
112
|
+
props: {
|
|
113
|
+
topics: {
|
|
114
|
+
type: Array as PropType<ComboboxOption[]>,
|
|
115
|
+
default: () => [
|
|
116
|
+
{ value: 'product', label: 'Product question' },
|
|
117
|
+
{ value: 'partnership', label: 'Partnership' },
|
|
118
|
+
{ value: 'support', label: 'Support' },
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
setup(props) {
|
|
123
|
+
return () => [
|
|
124
|
+
h(SkipLink),
|
|
125
|
+
h('main', { id: 'main', style: { padding: 'var(--bw-space-10) var(--bw-space-6)', maxWidth: '32rem', marginInline: 'auto' } }, [
|
|
126
|
+
h(Stack, () => [
|
|
127
|
+
h('h1', { class: 'bw-text-title-lg' }, 'Contact'),
|
|
128
|
+
h(Form, { onSubmit: (e: Event) => e.preventDefault() }, () => [
|
|
129
|
+
h(Field, () => [
|
|
130
|
+
h(Label, { for: 'bw-contact-name' }, () => 'Name'),
|
|
131
|
+
h(Input, { id: 'bw-contact-name', name: 'name', required: true }),
|
|
132
|
+
]),
|
|
133
|
+
h(Field, () => [
|
|
134
|
+
h(Label, { for: 'bw-contact-email' }, () => 'Email'),
|
|
135
|
+
h(Input, { id: 'bw-contact-email', name: 'email', type: 'email', required: true }),
|
|
136
|
+
h(Hint, () => 'We only use this to reply.'),
|
|
137
|
+
]),
|
|
138
|
+
h(Field, () => [
|
|
139
|
+
h(Label, { for: 'bw-contact-topic' }, () => 'Topic'),
|
|
140
|
+
h(Combobox, { id: 'bw-contact-topic', name: 'topic', options: props.topics, placeholder: 'Search topics' }),
|
|
141
|
+
]),
|
|
142
|
+
h(Field, () => [
|
|
143
|
+
h(Label, { for: 'bw-contact-date' }, () => 'Preferred date'),
|
|
144
|
+
h(DatePicker, { id: 'bw-contact-date', name: 'date' }),
|
|
145
|
+
]),
|
|
146
|
+
h(Field, () => [
|
|
147
|
+
h(Label, () => 'Availability'),
|
|
148
|
+
h(DateRangePicker, { startName: 'from', endName: 'to' }),
|
|
149
|
+
]),
|
|
150
|
+
h(Field, () => [
|
|
151
|
+
h(Label, { for: 'bw-contact-time' }, () => 'Call time'),
|
|
152
|
+
h(TimeInput, { id: 'bw-contact-time', name: 'time' }),
|
|
153
|
+
]),
|
|
154
|
+
h(Field, () => [
|
|
155
|
+
h(Label, { for: 'bw-contact-message' }, () => 'Message'),
|
|
156
|
+
h(Textarea, { id: 'bw-contact-message', name: 'message', rows: 5, required: true }),
|
|
157
|
+
]),
|
|
158
|
+
h(Field, () => [
|
|
159
|
+
h(Cluster, () => [
|
|
160
|
+
h(Checkbox, { id: 'bw-contact-copy', name: 'copy' }),
|
|
161
|
+
h(Label, { for: 'bw-contact-copy' }, () => 'Send me a copy'),
|
|
162
|
+
]),
|
|
163
|
+
]),
|
|
164
|
+
h(FormActions, () => [
|
|
165
|
+
h(Button, { type: 'submit', variant: 'primary' }, () => 'Send message'),
|
|
166
|
+
h(ButtonLink, { href: '/gallery/homepage', variant: 'ghost' }, () => 'Cancel'),
|
|
167
|
+
]),
|
|
168
|
+
]),
|
|
169
|
+
]),
|
|
170
|
+
]),
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
})
|