24725216e4
* add watch script * make interactions in Vue and React consistent * re-work focus restoration When we click outside of the Menu or Listbox, we want to restore the focus to the Button, *unless* we clicked on/in an element that is focusable in itself. For example, when the Menu is open and you click in an input field, the input field should stay focused. We should also close the Menu itself at this point. * add examples with multiple elements * bump dependencies
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
export type ExamplesType = {
|
|
name: string
|
|
path: string
|
|
children?: ExamplesType[]
|
|
}
|
|
|
|
export async function resolveAllExamples(...paths: string[]) {
|
|
const base = path.resolve(process.cwd(), ...paths)
|
|
|
|
if (!fs.existsSync(base)) {
|
|
return false
|
|
}
|
|
|
|
const files = await fs.promises.readdir(base, { withFileTypes: true })
|
|
const items: ExamplesType[] = []
|
|
|
|
for (let file of files) {
|
|
// Skip reserved filenames from Next. E.g.: _app.tsx, _error.tsx
|
|
if (file.name.startsWith('_')) {
|
|
continue
|
|
}
|
|
|
|
const bucket: ExamplesType = {
|
|
name: file.name.replace(/-/g, ' ').replace(/\.tsx?/g, ''),
|
|
path: [...paths, file.name]
|
|
.join('/')
|
|
.replace(/^pages/, '')
|
|
.replace(/\.tsx?/g, '')
|
|
.replace(/\/+/g, '/'),
|
|
}
|
|
|
|
if (file.isDirectory()) {
|
|
const children = await resolveAllExamples(...paths, file.name)
|
|
|
|
if (children) {
|
|
bucket.children = children
|
|
}
|
|
}
|
|
|
|
items.push(bucket)
|
|
}
|
|
|
|
return items
|
|
}
|