-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathprops.ts
384 lines (336 loc) · 12.4 KB
/
props.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import type { OkuElement, PrimitiveProps } from '@oku-ui/primitive'
import { ref } from 'vue'
import type { PropType, Ref } from 'vue'
import type { Scope } from '@oku-ui/provide'
import { ScopePropObject, createScope } from '@oku-ui/provide'
import { createCollection } from '@oku-ui/collection'
import type { RovingFocusGroupProps } from '@oku-ui/roving-focus'
import { collapsibleContentProps, collapsibleProps, collapsibleTriggerProps, createCollapsibleScope } from '@oku-ui/collapsible'
import type { CollapsibleContentProps, CollapsibleProps, CollapsibleTriggerEmits, CollapsibleTriggerProps } from '@oku-ui/collapsible'
import { propsOmit } from '@oku-ui/primitive'
export const ACCORDION_NAME = 'OkuAccordion'
export const ITEM_NAME = 'OkuAccordionItem'
export const CONTENT_NAME = 'OkuAccordionContent'
export const HEADER_NAME = 'OkuAccordionHeader'
export const ACCORDION_IMPL_NAME = 'OkuAccordionImpl'
export const ACCORDION_IMPL_MULTIPLE_NAME = 'OkuAccordionImplMultiple'
export const ACCORDION_IMPL_SINGLE_NAME = 'OkuAccordionImplSingle'
export const TRIGGER_NAME = 'OkuAccordionTrigger'
export const ACCORDION_KEYS = ['Home', 'End', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight']
export type Direction = 'ltr' | 'rtl'
export type SelectionType = 'single' | 'multiple'
/* -------------------------------------------------------------------------- */
/* AccordionTrigger - accordionTrigger.ts */
/* -------------------------------------------------------------------------- */
export type AccordionTriggerNativeElement = OkuElement<'button'>
export type AccordionTriggerElement = HTMLButtonElement
export interface AccordionTriggerProps extends CollapsibleTriggerProps {}
export interface AccordionTriggerEmits extends CollapsibleTriggerEmits {}
export const accordionTriggerProps = {
props: {
...collapsibleTriggerProps.props,
},
emits: {
...collapsibleTriggerProps.emits,
},
}
/* -------------------------------------------------------------------------- */
/* **************** */
/* -------------------------------------------------------------------------- */
export const { CollectionItemSlot, CollectionProvider, CollectionSlot, useCollection, createCollectionScope } = createCollection<AccordionTriggerElement>(ACCORDION_NAME)
export type ScopeAccordion<T> = T & { scopeOkuAccordion?: Scope }
export const scopeAccordionProps = {
scopeOkuAccordion: {
...ScopePropObject,
},
}
export const [createAccordionProvider, createAccordionScope] = createScope(ACCORDION_NAME, [
createCollectionScope,
createCollapsibleScope,
])
export const useCollapsibleScope = createCollapsibleScope()
type AccordionValueProviderValue = {
value: Ref<string[]>
onItemOpen: (value: string) => void
onItemClose: (value: string) => void
}
export const [AccordionValueProvider, useAccordionValueInject]
= createAccordionProvider<AccordionValueProviderValue>(ACCORDION_NAME)
export const [AccordionCollapsibleProvider, useAccordionCollapsibleInject] = createAccordionProvider(
ACCORDION_NAME,
{ collapsible: ref(false) },
)
type AccordionImplContextValue = {
disabled?: Ref<boolean | undefined>
direction: Ref<AccordionImplProps['dir']>
orientation: Ref<AccordionImplProps['orientation']>
}
export const [AccordionImplProvider, useAccordionInject] = createAccordionProvider<AccordionImplContextValue>(
ACCORDION_NAME,
)
type AccordionItemContextValue =
{
open?: Ref<boolean>
disabled?: Ref<boolean | undefined>
triggerId: Ref<string>
}
export const [AccordionItemProvider, useAccordionItemInject]
= createAccordionProvider<AccordionItemContextValue>(ITEM_NAME)
/* -------------------------------------------------------------------------- */
/* Accordion - accordion.ts */
/* -------------------------------------------------------------------------- */
export type AccordionNativeElement = OkuElement<'div'>
export type AccordionElement = HTMLDivElement
export interface AccordionSingleProps extends AccordionImplSingleProps {
type: 'single'
}
export interface AccordionSingleEmits extends AccordionImplSingleEmits {
}
export interface AccordionMultipleProps extends AccordionImplMultipleProps {
type: 'multiple'
}
export interface AccordionMultipleEmits extends AccordionImplMultipleEmits {
}
export const accordionProps = {
props: {
value: {
type: [String, Array, undefined] as PropType<string | string[] | undefined>,
default: undefined,
},
type: {
type: String as PropType<SelectionType>,
default: 'single',
},
defaultValue: {
type: [String, Array, undefined] as PropType<string | string[] | undefined>,
default: undefined,
},
/**
* Whether an accordion item can be collapsed after it has been opened.
* @default false
*/
collapsible: {
type: [Boolean, undefined] as PropType<boolean | undefined>,
default: undefined,
},
},
emits: {
/**
* The callback that fires when the state of the accordion changes.
*/
// eslint-disable-next-line unused-imports/no-unused-vars
valueChange: (value: string | string[]) => true,
},
}
/* -------------------------------------------------------------------------- */
/* AccordionContent - accordionContent.ts */
/* -------------------------------------------------------------------------- */
export type AccordionContentNativeElement = OkuElement<'div'>
export type AccordionContentElement = HTMLDivElement
export interface AccordionContentProps extends CollapsibleContentProps {}
export const accordionContentProps = {
props: {
...collapsibleContentProps.props,
},
emits: {
},
}
/* -------------------------------------------------------------------------- */
/* AccordionContent - accordionContent.ts */
/* -------------------------------------------------------------------------- */
export type AccordionHeaderNativeElement = OkuElement<'h3'>
export interface AccordionHeaderProps extends PrimitiveProps {}
export const accordionHeaderProps = {
props: {
},
emits: {
},
}
/* -------------------------------------------------------------------------- */
/* AccordionImpl - accordionImpl.ts */
/* -------------------------------------------------------------------------- */
export type AccordionImplNativeElement = OkuElement<'div'>
export interface AccordionImplProps extends PrimitiveProps {
/**
* Whether or not an accordion is disabled from user interaction.
*
* @defaultValue false
*/
disabled?: boolean
/**
* The layout in which the Accordion operates.
* @default vertical
*/
orientation?: RovingFocusGroupProps['orientation']
/**
* The language read direction.
*/
dir?: RovingFocusGroupProps['dir']
}
export interface AccordionImplEmits {
valueChange: [value: string | string[]]
keydown: [event: KeyboardEvent]
}
export const accordionImplProps = {
props: {
disabled: {
type: [Boolean, undefined] as PropType<boolean | undefined>,
default: undefined,
},
orientation: {
type: String as PropType<RovingFocusGroupProps['orientation']>,
default: 'vertical',
},
dir: {
type: String as PropType<RovingFocusGroupProps['dir']>,
default: undefined,
},
},
emits: {
/**
* The callback that fires when the state of the accordion changes.
*/
// eslint-disable-next-line unused-imports/no-unused-vars
valueChange: (value: string | string[]) => true,
// eslint-disable-next-line unused-imports/no-unused-vars
keydown: (event: KeyboardEvent) => true,
},
}
/* -------------------------------------------------------------------------- */
/* AccordionImplMultiple - accordionImplMultiple.ts */
/* -------------------------------------------------------------------------- */
export type AccordionImplMultipleNativeElement = OkuElement<'div'>
export type AccordionImplMultipleElement = HTMLDivElement
export interface AccordionImplMultipleProps extends AccordionImplProps {
/**
* The controlled stateful value of the accordion item whose content is expanded.
*/
value?: string[]
/**
* The value of the item whose content is expanded when the accordion is initially rendered. Use
* `defaultValue` if you do not need to control the state of an accordion.
*/
defaultValue?: string[]
}
export interface AccordionImplMultipleEmits extends AccordionImplEmits {
/**
* The callback that fires when the state of the accordion changes.
*/
valueChange: [value: string[]]
}
export const accordionImplMultipleProps = {
props: {
...accordionImplProps.props,
modelValue: {
type: [Array, undefined] as PropType<string[] | undefined>,
default: undefined,
},
value: {
type: [Array, undefined] as PropType<string[] | undefined>,
default: undefined,
},
defaultValue: {
type: [Array, undefined] as PropType<string[] | undefined>,
default: undefined,
},
},
emits: {
...accordionImplProps.emits,
/**
* The callback that fires when the state of the accordion changes.
*/
// eslint-disable-next-line unused-imports/no-unused-vars
'valueChange': (value: string[]) => true,
// eslint-disable-next-line unused-imports/no-unused-vars
'update:modelValue': (value: string[]) => true,
},
}
/* -------------------------------------------------------------------------- */
/* AccordionImplSingle - accordionImplSingle.ts */
/* -------------------------------------------------------------------------- */
export type AccordionImplSingleNativeElement = OkuElement<'div'>
export interface AccordionImplSingleProps extends AccordionImplProps {
/**
* The controlled stateful value of the accordion item whose content is expanded.
*/
value?: string
/**
* The value of the item whose content is expanded when the accordion is initially rendered. Use
* `defaultValue` if you do not need to control the state of an accordion.
*/
defaultValue?: string
/**
* Whether an accordion item can be collapsed after it has been opened.
* @default false
*/
collapsible?: boolean
}
export interface AccordionImplSingleEmits extends AccordionImplEmits {
/**
* The callback that fires when the state of the accordion changes.
*/
valueChange: [value: string]
}
export const accordionImplSingleProps = {
props: {
...accordionImplProps.props,
modelValue: {
type: [String, undefined] as PropType<string | undefined>,
default: undefined,
},
value: {
type: [String, undefined] as PropType<string | undefined>,
default: undefined,
},
defaultValue: {
type: [String, undefined] as PropType<string | undefined>,
default: undefined,
},
collapsible: {
type: [Boolean, undefined] as PropType<boolean | undefined>,
default: false,
},
},
emits: {
...accordionImplProps.emits,
/**
* The callback that fires when the state of the accordion changes.
*/
// eslint-disable-next-line unused-imports/no-unused-vars
'valueChange': (value: string) => true,
// eslint-disable-next-line unused-imports/no-unused-vars
'update:modelValue': (value: string) => true,
},
}
/* -------------------------------------------------------------------------- */
/* AccordionItem - accordionItem.ts */
/* -------------------------------------------------------------------------- */
export type AccordionItemNativeElement = OkuElement<'div'>
export interface AccordionItemProps extends Omit<CollapsibleProps, 'open' | 'defaultOpen' | 'openChange'> {
/**
* Whether or not an accordion is disabled from user interaction.
*
* @defaultValue false
*/
disabled?: boolean
/**
* A string value for the accordion item. All items within an accordion should use a unique value.
*/
value: string
}
export interface AccordionItemEmits extends Omit<CollapsibleProps, 'open' | 'defaultOpen' | 'openChange'> {
}
export const accordionItemProps = {
props: {
...propsOmit(collapsibleProps.props, ['open', 'defaultOpen']),
disabled: {
type: [Boolean, undefined] as PropType<boolean | undefined>,
},
value: {
type: String as PropType<string>,
},
},
emits: {
...propsOmit(collapsibleProps.emits, ['openChange']),
},
}