테이블 뷰에는 표를 사용하는 데 필요한 제목과 기본 작업, 필터와 정렬, 행 선택, 행별 작업, 페이지 탐색이 들어갑니다. 각각은 별도의 컴포넌트이며, 블록은 이들을 하나의 시트에 배치하는 방법을 보여 줍니다.
테이블 뷰
<section class="sheet container-inline flex flex-col overflow-hidden" data-example="table-view" aria-labelledby="tv-title"> <header class="flex flex-wrap items-center justify-between gap-sm p-md"> <div class="flex flex-col gap-3xs"> <h2 class="heading heading-sm" id="tv-title">Atlas Labs</h2> <p class="m(0) fg-text-muted" id="tv-summary">24 projects</p> </div> <div class="flex flex-wrap items-center gap-xs"> <div class="segmented segmented-sm" role="radiogroup" aria-label="Show"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="tv-set" value="projects" checked>Projects</label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="tv-set" value="people">People</label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="tv-set" value="files">Files</label> </div> <button type="button" class="btn btn-primary btn-sm" id="tv-action"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> <path d="M8 3L8 13" /> </svg> <span>New project</span> </button> </div> </header> <div class="flex flex-wrap items-center gap-xs px-md pb-md"> <label class="input-group input-group-sm grow(1) basis(200) max-w(320)"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /> <path d="M10.182 10.182L14 14" /> </svg> <input class="input-group-field" type="search" id="tv-search" placeholder="Search projects" aria-label="Search projects" autocomplete="off"> </label> <button type="button" class="btn btn-sm" popovertarget="tv-filters" data-filter="open"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg>Filters <span data-filter="count" aria-hidden="true" hidden> <span class="badge badge-sm badge-ink badge-pill">0</span> </span> </button> <select class="select select-raised select-sm ml-auto" id="tv-sort" aria-label="Sort by"></select> <div class="w-full" data-filter="applied" hidden> <div class="flex flex-wrap items-center gap-xs"> <ul class="flex flex-wrap gap-xs m(0) p(0)" aria-label="Applied filters" data-filter="chips"></ul> <button type="button" class="btn btn-quiet btn-sm" data-filter="clear-all">Clear all</button> </div> </div> </div> <div class="popover p(0) w(560)" id="tv-filters" popover role="dialog" aria-labelledby="tv-filters-title" style="--popover-max-width: min(36rem, calc(100vw - 2rem))" data-filter="panel"> <form class="flex flex-col" data-filter="form" novalidate> <header class="flex flex-col gap-3xs px-md pt-md pb-sm"> <h3 class="heading heading-xs" id="tv-filters-title">Filter projects</h3> <p class="m(0) fg-text-muted" id="tv-filters-hint">A project shows when it meets every condition.</p> </header> <ul class="flex flex-col gap-xs m(0) px-md py-xs" data-filter="conditions"></ul> <p class="m(0) px-md py-xs fg-text-muted" data-filter="empty">No conditions yet: every row shows.</p> <p class="m(0) px-md py-xs fg-danger" id="tv-filters-error" role="alert" data-filter="error" hidden></p> <div class="px-md pb-md"> <button type="button" class="btn btn-quiet btn-sm" data-filter="add"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> <path d="M8 3L8 13" /> </svg>Add condition</button> </div> <footer class="flex flex-wrap items-center justify-between gap-xs p-md bt(1) bt-solid b-line-hair"> <button type="button" class="btn btn-quiet btn-sm" data-filter="clear">Clear</button> <div class="flex gap-xs"> <button type="button" class="btn btn-sm" data-filter="cancel">Cancel</button> <button type="submit" class="btn btn-primary btn-sm">Apply</button> </div> </footer> </form> </div> <div class="scroll-area scroll-area-inline bt(1) bt-solid b-line-hair"> <table class="table table-interactive" id="tv-table" aria-labelledby="tv-title"> <thead id="tv-head"></thead> <tbody id="tv-body"></tbody> </table> </div> <footer class="flex flex-wrap items-center justify-between gap-sm p-md bt(1) bt-solid b-line-hair"> <div class="flex flex-wrap items-center gap-xs min-h(32)"> <p class="m(0) fg-text-muted" id="tv-count">No projects selected</p> <div id="tv-selected" hidden> <div class="flex items-center gap-3xs"> <button type="button" class="btn btn-quiet btn-sm btn-danger" id="tv-delete">Delete</button> <button type="button" class="btn btn-quiet btn-sm" id="tv-deselect">Clear selection</button> </div> </div> </div> <div class="flex flex-wrap items-center gap-sm"> <p class="m(0) fg-text-muted whitespace-nowrap" id="tv-range">1–8 of 24</p> <nav aria-label="Pagination"> <ol class="pagination" id="tv-pages"></ol> </nav> </div> </footer> <p class="sr-only" role="status" id="tv-status"></p> <template data-filter="row"> <li class="flex flex-wrap items-center gap-xs"> <span class="w(44) shrink(0) fg-text-muted text-end" data-part="joiner">Where</span> <select class="select select-sm" aria-label="Field" data-part="field"></select> <select class="select select-sm" aria-label="Comparison" data-part="operator"></select> <input class="input input-sm grow(1) basis(128) min-w(0)" aria-label="Value" data-part="value" required> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove condition" data-part="remove"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /> <path d="M4 12L12 4" /> </svg> </button> </li> </template> <template data-filter="choice"> <select class="select select-sm grow(1) basis(128)" aria-label="Value" data-part="value"></select> </template> <template data-filter="chip"> <li> <span class="chip"> <span class="chip-label"></span> <button type="button" class="chip-remove" aria-label="Remove the filter"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /> <path d="M4 12L12 4" /> </svg> </button> </span> </li> </template> <template id="tv-head-projects"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all projects"> </th> <th class="table-heading" scope="col" data-sort="name">Project</th> <th class="table-heading" scope="col">Status</th> <th class="table-heading" scope="col">Region</th> <th class="table-heading table-numeric" scope="col" data-sort="deployments">Deployments</th> <th class="table-heading" scope="col" data-sort="deployed">Last deployed</th> <th class="table-heading" scope="col"> <span class="sr-only">Actions</span> </th> </tr> </thead> </table> </template> <template id="tv-row-projects"> <table class="table"> <tbody> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" data-part="select" aria-label="Select"> </td> <th class="table-cell table-primary" scope="row"> <span data-part="name"></span> <span class="block fg-text-muted font-regular" data-part="domain"></span> </th> <td class="table-cell"> <span class="badge badge-dot" data-part="status"></span> </td> <td class="table-cell" data-part="region"></td> <td class="table-cell table-numeric" data-part="deployments"></td> <td class="table-cell whitespace-nowrap" data-part="deployed"></td> <td class="table-cell text-end" data-part="actions"></td> </tr> </tbody> </table> </template> <template id="tv-head-people"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all people"> </th> <th class="table-heading" scope="col" data-sort="name">Person</th> <th class="table-heading" scope="col">Role</th> <th class="table-heading" scope="col">Status</th> <th class="table-heading table-numeric" scope="col" data-sort="projects">Projects</th> <th class="table-heading" scope="col" data-sort="active">Last active</th> <th class="table-heading" scope="col"> <span class="sr-only">Actions</span> </th> </tr> </thead> </table> </template> <template id="tv-row-people"> <table class="table"> <tbody> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" data-part="select" aria-label="Select"> </td> <th class="table-cell table-primary" scope="row"> <span class="flex items-center gap-sm"> <span class="avatar avatar-sm" aria-hidden="true" data-part="initials"></span> <span class="min-w(0)"> <span class="block" data-part="name"></span> <span class="block fg-text-muted font-regular" data-part="email"></span> </span> </span> </th> <td class="table-cell" data-part="role"></td> <td class="table-cell"> <span class="badge badge-dot" data-part="status"></span> </td> <td class="table-cell table-numeric" data-part="projects"></td> <td class="table-cell whitespace-nowrap" data-part="active"></td> <td class="table-cell text-end" data-part="actions"></td> </tr> </tbody> </table> </template> <template id="tv-head-files"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all files"> </th> <th class="table-heading" scope="col" data-sort="name">File</th> <th class="table-heading" scope="col">Type</th> <th class="table-heading table-numeric" scope="col" data-sort="size">Size</th> <th class="table-heading" scope="col" data-sort="modified">Modified</th> <th class="table-heading" scope="col">Owner</th> <th class="table-heading" scope="col"> <span class="sr-only">Actions</span> </th> </tr> </thead> </table> </template> <template id="tv-row-files"> <table class="table"> <tbody> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" data-part="select" aria-label="Select"> </td> <th class="table-cell table-primary" scope="row"> <span class="flex items-center gap-sm"> <span class="icon-frame icon-frame-xs" aria-hidden="true"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"> <path d="M4.5 2L9.0858 2A1 1 0 0 1 9.7929 2.2929L12.2071 4.7071A1 1 0 0 1 12.5 5.4142L12.5 13A1 1 0 0 1 11.5 14L4.5 14A1 1 0 0 1 3.5 13L3.5 3A1 1 0 0 1 4.5 2Z" /> <path d="M10 2.5V4.4A0.1 0.1 0 0 0 10.1 4.5H12L12.2409 4.7427A0.9993 0.9993 0 0 1 12.5 5.4142V5.5H10.1Q9.6444 5.5 9.3222 5.1778Q9 4.8556 9 4.4V2A1.1002 1.1002 0 0 1 9.3761 2.0431A1.0001 1.0001 0 0 1 9.7929 2.2929L10 2.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /> </svg> </span> <span class="min-w(0) truncate" data-part="name"></span> </span> </th> <td class="table-cell" data-part="type"></td> <td class="table-cell table-numeric" data-part="size"></td> <td class="table-cell whitespace-nowrap" data-part="modified"></td> <td class="table-cell whitespace-nowrap" data-part="owner"></td> <td class="table-cell text-end" data-part="actions"></td> </tr> </tbody> </table> </template> <template id="tv-actions"> <div> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Actions"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.5" cy="8" r="1.05" fill="currentColor" stroke="none" /> <circle cx="8" cy="8" r="1.05" fill="currentColor" stroke="none" /> <circle cx="12.5" cy="8" r="1.05" fill="currentColor" stroke="none" /> </svg> </button> <div class="menu menu-end" popover> <a class="menu-item" href="#" data-part="open">Open</a> <hr class="menu-separator"> <button type="button" class="menu-item menu-item-danger" data-part="delete">Delete</button> </div> </div> </template> <template id="tv-empty"> <table class="table"> <tbody> <tr class="table-row"> <td class="table-cell" colspan="7"> <div class="empty"> <p class="empty-title" data-part="title">No projects match</p> <p class="empty-description">Try another search, or remove a filter.</p> <div class="empty-actions"> <button type="button" class="btn btn-sm" data-part="reset">Clear the search and the filters</button> </div> </div> </td> </tr> </tbody> </table> </template> <template id="tv-page"> <ol class="pagination"> <li> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Page"></button> </li> </ol> </template> <template id="tv-gap"> <ol class="pagination"> <li class="pagination-gap" aria-hidden="true">…</li> </ol> </template> <template id="tv-previous"> <ol class="pagination"> <li> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous page"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" /> </svg> </button> </li> </ol> </template> <template id="tv-next"> <ol class="pagination"> <li> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next page"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" /> </svg> </button> </li> </ol> </template></section>import { filters } from '../filter-bar/filters.js'import { filter, formatDate, paginate, search, sort } from '../filter-bar/query.js'import { sets } from './data.js'const size = 8const tones = { ready: 'badge-success', building: 'badge-info', queued: 'badge-warning', failed: 'badge-danger', active: 'badge-success', invited: 'badge-info', away: '',}const numbers = new Intl.NumberFormat('en-US')const bytes = (megabytes) => megabytes < 1 ? `${numbers.format(Math.round(megabytes * 1000))} KB` : `${numbers.format(megabytes)} MB`/** * The table view on local data. Search, the filter bar, the sort and the page decide which rows show; the * selection is kept to the rows that match, so the count in the footer, the pages and the rows always agree. * Projects, people and files are three sets with their own fields and rows. Returns the function that stops it. */export function mount(root) { const $ = (selector) => root.querySelector(selector) const copy = (id, selector) => $(id).content.querySelector(selector).cloneNode(true) const controller = new AbortController() const { signal } = controller // The rows are the page's to change: deleting one changes the set it is in. const data = Object.fromEntries(Object.entries(sets).map(([name, set]) => [name, { ...set, rows: [...set.rows] }])) const state = { set: 'projects', search: '', page: 1, sort: data.projects.sorts[0], applied: [], selected: new Map(Object.keys(data).map((name) => [name, new Set()])) } const set = () => data[state.set] const plural = (count) => set().noun[count === 1 ? 0 : 1] const say = (words) => { $('#tv-status').textContent = words } /** The rows that match, in order: what every count and every page is read from. */ function matching() { return sort(filter(search(set().rows, state.search, set().search), state.applied, set().fields), state.sort[0], state.sort[1]) } function fill(row, record) { const part = (name) => row.querySelector(`[data-part="${name}"]`) const field = (key) => set().fields.find((each) => each.key === key) const label = (key) => field(key).options.find(([value]) => value === record[key])[1] if (state.set === 'projects') { part('name').textContent = record.name part('domain').textContent = record.domain part('status').classList.add(tones[record.status]) part('status').textContent = label('status') part('region').textContent = label('region') part('deployments').textContent = numbers.format(record.deployments) part('deployed').textContent = formatDate(record.deployed) } else if (state.set === 'people') { part('initials').textContent = record.name.split(' ').map((word) => word[0]).slice(0, 2).join('') part('name').textContent = record.name part('email').textContent = record.email part('role').textContent = label('role') if (tones[record.status]) part('status').classList.add(tones[record.status]) part('status').textContent = label('status') part('projects').textContent = record.projects part('active').textContent = record.status === 'invited' ? 'Not yet' : formatDate(record.active) } else { part('name').textContent = record.name part('type').textContent = label('type') part('size').textContent = bytes(record.size) part('modified').textContent = formatDate(record.modified) part('owner').textContent = record.owner } const select = part('select') select.checked = state.selected.get(state.set).has(record.id) select.value = record.id select.setAttribute('aria-label', `Select ${record.name}`) if (select.checked) row.setAttribute('aria-selected', 'true') // Each row's actions are a menu named for its row, with an id of its own. const actions = copy('#tv-actions', 'div') const menu = actions.querySelector('.menu') menu.id = `tv-menu-${record.id}` const button = actions.querySelector('button') button.setAttribute('popovertarget', menu.id) button.setAttribute('aria-label', `Actions for ${record.name}`) menu.querySelector('[data-part="delete"]').value = record.id part('actions').replaceChildren(...actions.children) } function head() { const row = copy(`#tv-head-${state.set}`, 'tr') for (const heading of row.querySelectorAll('[data-sort]')) { if (heading.dataset.sort === state.sort[0]) heading.setAttribute('aria-sort', state.sort[1]) } $('#tv-head').replaceChildren(row) } function pages(result) { const list = [] const add = (id, setup) => { const item = copy(id, 'li'); setup(item.querySelector('button')); list.push(item) } add('#tv-previous', (button) => { button.value = String(result.page - 1); button.disabled = result.page === 1 }) // Every page when there are few; the first, the last and the neighbors of the current one when there are many. const shown = [...new Set([1, result.page - 1, result.page, result.page + 1, result.pages])].filter((page) => page >= 1 && page <= result.pages).sort((a, b) => a - b) for (const [index, page] of shown.entries()) { if (index && page - shown[index - 1] > 1) list.push(copy('#tv-gap', 'li')) add('#tv-page', (button) => { button.value = String(page) button.textContent = String(page) button.setAttribute('aria-label', `Page ${page}`) if (page === result.page) button.setAttribute('aria-current', 'page') }) } add('#tv-next', (button) => { button.value = String(result.page + 1); button.disabled = result.page === result.pages }) $('#tv-pages').replaceChildren(...list) } /** Write the table, its counts and its pages from the state. */ function draw() { const rows = matching() const selected = state.selected.get(state.set) // A row that no longer matches leaves the selection, so the count never includes what cannot be seen. for (const id of selected) if (!rows.some((row) => row.id === id)) selected.delete(id) const result = paginate(rows, state.page, size) state.page = result.page const many = set().noun[1] $('#tv-summary').textContent = rows.length === set().rows.length ? `${set().rows.length} ${plural(set().rows.length)}` : `${rows.length} of ${set().rows.length} ${many} match` head() const all = $('#tv-head [data-part="all"]') all.checked = rows.length > 0 && selected.size === rows.length all.indeterminate = selected.size > 0 && selected.size < rows.length all.disabled = rows.length === 0 all.setAttribute('aria-label', `Select all ${rows.length} ${plural(rows.length)}`) if (result.rows.length) { $('#tv-body').replaceChildren(...result.rows.map((record) => { const row = copy(`#tv-row-${state.set}`, 'tr') fill(row, record) return row })) } else { const empty = copy('#tv-empty', 'tr') empty.querySelector('[data-part="title"]').textContent = `No ${many} match` $('#tv-body').replaceChildren(empty) } $('#tv-count').textContent = selected.size ? `${selected.size} of ${rows.length} selected` : `No ${many} selected` $('#tv-selected').hidden = selected.size === 0 $('#tv-range').textContent = rows.length ? `${result.from}–${result.to} of ${rows.length}` : `0 of ${set().rows.length}` pages(result) } // The filter bar of whichever set is shown; a new set brings its own fields and starts with none applied. const bar = filters(root, { fields: set().fields, onChange: (applied) => { state.applied = applied; state.page = 1; draw() } }) function show(name) { state.set = name state.search = '' state.page = 1 state.applied = [] state.sort = set().sorts[0] const [one, many] = set().noun $('#tv-search').value = '' $('#tv-search').placeholder = `Search ${many}` $('#tv-search').setAttribute('aria-label', `Search ${many}`) $('#tv-action span').textContent = set().action $('#tv-filters-title').textContent = `Filter ${many}` $('#tv-filters-hint').textContent = `A${/^[aeiou]/.test(one) ? 'n' : ''} ${one} shows when it meets every condition.` $('#tv-sort').replaceChildren(...set().sorts.map(([key, direction, words]) => { const option = new Option(words, `${key} ${direction}`) option.className = 'select-option' return option })) bar.setFields(set().fields) draw() } root.querySelector('[name="tv-set"]').closest('.segmented').addEventListener('change', (event) => show(event.target.value), { signal }) $('#tv-search').addEventListener('input', (event) => { state.search = event.target.value state.page = 1 draw() }, { signal }) $('#tv-sort').addEventListener('change', (event) => { state.sort = event.target.value.split(' ') state.page = 1 draw() }, { signal }) $('#tv-pages').addEventListener('click', (event) => { const button = event.target.closest('button') if (!button || button.disabled) return state.page = Number(button.value) const pressed = button.getAttribute('aria-label') draw() // Focus stays on what was pressed, drawn again; at an end, where Previous or Next is disabled, on the current page. const again = [...$('#tv-pages').querySelectorAll('button:not(:disabled)')].find(each => each.getAttribute('aria-label') === pressed) ;(again ?? $(`#tv-pages [aria-current="page"]`))?.focus() say(`Page ${state.page} of ${Math.max(1, Math.ceil(matching().length / size))}`) }, { signal }) root.addEventListener('change', (event) => { const input = event.target const selected = state.selected.get(state.set) if (input.matches('#tv-body [data-part="select"]')) { if (input.checked) selected.add(input.value) else selected.delete(input.value) draw() $(`#tv-body [data-part="select"][value="${CSS.escape(input.value)}"]`)?.focus() } else if (input.matches('#tv-head [data-part="all"]')) { // All: every row that matches, on every page. None: clear them. if (input.checked) for (const row of matching()) selected.add(row.id) else selected.clear() draw() $('#tv-head [data-part="all"]').focus() } }, { signal }) function remove(ids) { const before = set().rows.length set().rows = set().rows.filter((row) => !ids.includes(row.id)) for (const id of ids) state.selected.get(state.set).delete(id) const removed = before - set().rows.length draw() say(`${removed} ${plural(removed)} deleted`) ;($('#tv-head [data-part="all"]:not(:disabled)') ?? $('#tv-search')).focus() } $('#tv-delete').addEventListener('click', () => remove([...state.selected.get(state.set)]), { signal }) $('#tv-deselect').addEventListener('click', () => { state.selected.get(state.set).clear() draw() $('#tv-head [data-part="all"]').focus() }, { signal }) $('#tv-body').addEventListener('click', (event) => { const target = event.target if (target.closest('[data-part="open"]')) event.preventDefault() const deleting = target.closest('[data-part="delete"]') if (deleting) { deleting.closest('[popover]').hidePopover() remove([deleting.value]) } if (target.closest('[data-part="reset"]')) { state.search = '' $('#tv-search').value = '' bar.setFields(set().fields) state.applied = [] draw() $('#tv-search').focus() } }, { signal }) show('projects') return () => { controller.abort() bar.destroy() }}/** * Atlas Labs' workspace as local data: its projects, its people and its files. Each set says which fields a * reader can filter by, search in and sort by; the table view writes its rows from them. Dates are YYYY-MM-DD * and the data was read on `today`. */export const today = '2026-11-14'export const sets = { projects: { noun: ['project', 'projects'], action: 'New project', search: ['name', 'domain'], sorts: [['deployed', 'descending', 'Last deployed'], ['name', 'ascending', 'Name'], ['deployments', 'descending', 'Most deployments']], fields: [ { key: 'name', label: 'Name', type: 'text' }, { key: 'status', label: 'Status', type: 'enum', options: [['ready', 'Ready'], ['building', 'Building'], ['queued', 'Queued'], ['failed', 'Failed']] }, { key: 'region', label: 'Region', type: 'enum', options: [['tokyo', 'Tokyo'], ['frankfurt', 'Frankfurt'], ['virginia', 'Virginia'], ['sydney', 'Sydney'], ['sao-paulo', 'São Paulo'], ['london', 'London'], ['singapore', 'Singapore'], ['oregon', 'Oregon']] }, { key: 'deployments', label: 'Deployments', type: 'number' }, { key: 'deployed', label: 'Last deployed', type: 'date' }, ], rows: [ { id: 'prj_01', name: 'Atlas', domain: 'atlas.dev', status: 'queued', region: 'oregon', deployments: 234, deployed: '2026-10-10' }, { id: 'prj_02', name: 'Borealis', domain: 'borealis.app', status: 'ready', region: 'oregon', deployments: 325, deployed: '2026-11-03' }, { id: 'prj_03', name: 'Cinder', domain: 'cinder.io', status: 'ready', region: 'oregon', deployments: 158, deployed: '2026-11-08' }, { id: 'prj_04', name: 'Drift', domain: 'drift.so', status: 'ready', region: 'tokyo', deployments: 307, deployed: '2026-11-09' }, { id: 'prj_05', name: 'Ember', domain: 'ember.dev', status: 'failed', region: 'virginia', deployments: 322, deployed: '2026-10-17' }, { id: 'prj_06', name: 'Fathom', domain: 'fathom.app', status: 'ready', region: 'frankfurt', deployments: 33, deployed: '2026-10-12' }, { id: 'prj_07', name: 'Gale', domain: 'gale.dev', status: 'ready', region: 'sydney', deployments: 310, deployed: '2026-11-02' }, { id: 'prj_08', name: 'Harbor', domain: 'harbor.app', status: 'ready', region: 'london', deployments: 228, deployed: '2026-10-16' }, { id: 'prj_09', name: 'Isle', domain: 'isle.io', status: 'ready', region: 'sydney', deployments: 330, deployed: '2026-10-12' }, { id: 'prj_10', name: 'Juniper', domain: 'juniper.so', status: 'ready', region: 'tokyo', deployments: 342, deployed: '2026-10-14' }, { id: 'prj_11', name: 'Kestrel', domain: 'kestrel.dev', status: 'ready', region: 'sao-paulo', deployments: 211, deployed: '2026-10-16' }, { id: 'prj_12', name: 'Lumen', domain: 'lumen.app', status: 'ready', region: 'london', deployments: 391, deployed: '2026-10-29' }, { id: 'prj_13', name: 'Meridian', domain: 'meridian.dev', status: 'ready', region: 'sao-paulo', deployments: 18, deployed: '2026-10-13' }, { id: 'prj_14', name: 'Nimbus', domain: 'nimbus.app', status: 'ready', region: 'frankfurt', deployments: 208, deployed: '2026-10-09' }, { id: 'prj_15', name: 'Orchard', domain: 'orchard.io', status: 'ready', region: 'singapore', deployments: 37, deployed: '2026-10-27' }, { id: 'prj_16', name: 'Pinecone', domain: 'pinecone.so', status: 'ready', region: 'sydney', deployments: 110, deployed: '2026-11-14' }, { id: 'prj_17', name: 'Quarry', domain: 'quarry.dev', status: 'ready', region: 'singapore', deployments: 365, deployed: '2026-10-15' }, { id: 'prj_18', name: 'Ridge', domain: 'ridge.app', status: 'failed', region: 'frankfurt', deployments: 292, deployed: '2026-10-19' }, { id: 'prj_19', name: 'Saltmarsh', domain: 'saltmarsh.dev', status: 'ready', region: 'london', deployments: 47, deployed: '2026-10-28' }, { id: 'prj_20', name: 'Tundra', domain: 'tundra.app', status: 'ready', region: 'tokyo', deployments: 212, deployed: '2026-10-24' }, { id: 'prj_21', name: 'Umbra', domain: 'umbra.io', status: 'ready', region: 'sydney', deployments: 364, deployed: '2026-11-06' }, { id: 'prj_22', name: 'Vale', domain: 'vale.so', status: 'ready', region: 'tokyo', deployments: 241, deployed: '2026-11-14' }, { id: 'prj_23', name: 'Willow', domain: 'willow.dev', status: 'queued', region: 'sydney', deployments: 232, deployed: '2026-11-03' }, { id: 'prj_24', name: 'Zephyr', domain: 'zephyr.app', status: 'ready', region: 'singapore', deployments: 332, deployed: '2026-11-06' }, ], }, people: { noun: ['person', 'people'], action: 'Invite people', search: ['name', 'email'], sorts: [['name', 'ascending', 'Name'], ['active', 'descending', 'Last active'], ['projects', 'descending', 'Most projects']], fields: [ { key: 'name', label: 'Name', type: 'text' }, { key: 'email', label: 'Email', type: 'text' }, { key: 'role', label: 'Role', type: 'enum', options: [['owner', 'Owner'], ['admin', 'Admin'], ['member', 'Member'], ['viewer', 'Viewer']] }, { key: 'status', label: 'Status', type: 'enum', options: [['active', 'Active'], ['away', 'Away'], ['invited', 'Invited']] }, { key: 'projects', label: 'Projects', type: 'number' }, { key: 'active', label: 'Last active', type: 'date' }, ], rows: [ { id: 'usr_01', name: 'Yi-ching Lin', email: 'yiching@atlaslabs.dev', role: 'owner', status: 'active', projects: 2, active: '2026-11-02' }, { id: 'usr_02', name: 'Po-han Chen', email: 'pohan@atlaslabs.dev', role: 'admin', status: 'active', projects: 7, active: '2026-11-02' }, { id: 'usr_03', name: 'Misaki Sato', email: 'misaki@atlaslabs.dev', role: 'admin', status: 'active', projects: 1, active: '2026-11-08' }, { id: 'usr_04', name: 'Seo-yeon Kim', email: 'seoyeon@atlaslabs.dev', role: 'member', status: 'active', projects: 14, active: '2026-11-06' }, { id: 'usr_05', name: 'Kenta Nakamura', email: 'kenta@atlaslabs.dev', role: 'member', status: 'active', projects: 10, active: '2026-10-20' }, { id: 'usr_06', name: 'Ji-hoon Park', email: 'jihoon@atlaslabs.dev', role: 'member', status: 'active', projects: 1, active: '2026-11-05' }, { id: 'usr_07', name: 'Mei-ling Wang', email: 'meiling@atlaslabs.dev', role: 'member', status: 'away', projects: 3, active: '2026-11-08' }, { id: 'usr_08', name: 'Haruto Takahashi', email: 'haruto@atlaslabs.dev', role: 'member', status: 'active', projects: 14, active: '2026-11-02' }, { id: 'usr_09', name: 'Ga-eun Lee', email: 'gaeun@atlaslabs.dev', role: 'viewer', status: 'active', projects: 11, active: '2026-10-26' }, { id: 'usr_10', name: 'Chia-hao Wu', email: 'chiahao@atlaslabs.dev', role: 'member', status: 'invited', projects: 0, active: '' }, { id: 'usr_11', name: 'Yuna Kobayashi', email: 'yuna@atlaslabs.dev', role: 'viewer', status: 'invited', projects: 0, active: '' }, { id: 'usr_12', name: 'Min-jun Choi', email: 'minjun@atlaslabs.dev', role: 'viewer', status: 'away', projects: 3, active: '2026-11-13' }, { id: 'usr_13', name: 'Shu-fen Huang', email: 'shufen@atlaslabs.dev', role: 'member', status: 'active', projects: 8, active: '2026-11-08' }, { id: 'usr_14', name: 'Ren Watanabe', email: 'ren@atlaslabs.dev', role: 'admin', status: 'active', projects: 1, active: '2026-11-06' }, { id: 'usr_15', name: 'Hye-jin Jung', email: 'hyejin@atlaslabs.dev', role: 'viewer', status: 'invited', projects: 0, active: '' }, { id: 'usr_16', name: 'Tzu-yu Tsai', email: 'tzuyu@atlaslabs.dev', role: 'member', status: 'active', projects: 6, active: '2026-10-26' }, ], }, files: { noun: ['file', 'files'], action: 'Upload', search: ['name', 'owner'], sorts: [['modified', 'descending', 'Last modified'], ['name', 'ascending', 'Name'], ['size', 'descending', 'Largest']], fields: [ { key: 'name', label: 'Name', type: 'text' }, { key: 'type', label: 'Type', type: 'enum', options: [['pdf', 'PDF'], ['image', 'Image'], ['sheet', 'Spreadsheet'], ['doc', 'Document'], ['archive', 'Archive']] }, { key: 'size', label: 'Size', type: 'number', unit: 'MB' }, { key: 'modified', label: 'Modified', type: 'date' }, { key: 'owner', label: 'Owner', type: 'text' }, ], rows: [ { id: 'fil_01', name: 'Q3 infrastructure report.pdf', type: 'pdf', size: 2.4, modified: '2026-10-19', owner: 'Kenta Nakamura' }, { id: 'fil_02', name: 'Launch checklist.pdf', type: 'pdf', size: 0.3, modified: '2026-11-02', owner: 'Po-han Chen' }, { id: 'fil_03', name: 'Brand guidelines.pdf', type: 'pdf', size: 18.6, modified: '2026-11-12', owner: 'Po-han Chen' }, { id: 'fil_04', name: 'Hero photograph.jpg', type: 'image', size: 4.1, modified: '2026-11-08', owner: 'Seo-yeon Kim' }, { id: 'fil_05', name: 'Dashboard screenshot.png', type: 'image', size: 1.2, modified: '2026-11-14', owner: 'Ji-hoon Park' }, { id: 'fil_06', name: 'Team offsite.jpg', type: 'image', size: 6.8, modified: '2026-11-03', owner: 'Haruto Takahashi' }, { id: 'fil_07', name: 'Usage by region.csv', type: 'sheet', size: 0.9, modified: '2026-11-10', owner: 'Haruto Takahashi' }, { id: 'fil_08', name: 'Invoices October.xlsx', type: 'sheet', size: 0.4, modified: '2026-10-19', owner: 'Misaki Sato' }, { id: 'fil_09', name: 'Capacity plan.xlsx', type: 'sheet', size: 1.7, modified: '2026-10-18', owner: 'Mei-ling Wang' }, { id: 'fil_10', name: 'Edge logs 2026-11-12.zip', type: 'archive', size: 214.0, modified: '2026-11-12', owner: 'Misaki Sato' }, { id: 'fil_11', name: 'Design tokens.zip', type: 'archive', size: 3.3, modified: '2026-11-05', owner: 'Seo-yeon Kim' }, { id: 'fil_12', name: 'Incident review.docx', type: 'doc', size: 0.2, modified: '2026-10-19', owner: 'Seo-yeon Kim' }, { id: 'fil_13', name: 'Onboarding guide.docx', type: 'doc', size: 1.1, modified: '2026-10-22', owner: 'Seo-yeon Kim' }, { id: 'fil_14', name: 'API reference.md', type: 'doc', size: 0.1, modified: '2026-11-09', owner: 'Ga-eun Lee' }, { id: 'fil_15', name: 'Release notes 0.9.md', type: 'doc', size: 0.05, modified: '2026-11-08', owner: 'Mei-ling Wang' }, { id: 'fil_16', name: 'Atlas logo.svg', type: 'image', size: 0.02, modified: '2026-10-17', owner: 'Haruto Takahashi' }, { id: 'fil_17', name: 'Migration script.zip', type: 'archive', size: 0.6, modified: '2026-10-26', owner: 'Po-han Chen' }, { id: 'fil_18', name: 'Pricing model.xlsx', type: 'sheet', size: 0.8, modified: '2026-11-01', owner: 'Yi-ching Lin' }, ], },}import { condition, describe, operatorsOf, problem } from './query.js'/** * A filter bar: conditions staged in a popover and applied together, then shown as chips that each remove one. * The page writes the bar's elements and marks them with `data-filter`, with a `<template>` for a condition's row, * a value to choose and an applied chip; this copies the templates, fills them in and says the applied conditions * to `onChange`. * * - The popover holds a draft. Opening it copies what is applied; Cancel, Escape or a click outside drop the draft. * - Apply checks every row first. A row that cannot be applied is marked `aria-invalid`, the message says why and * focus goes to it; nothing is applied until every row can be. * - Clear empties the draft, so Apply then shows every row. Clear all, beside the chips, applies at once. * * @param {HTMLElement} root The element that holds the bar, its chips and its popover. * @param {{ fields: object[], applied?: object[], onChange: (applied: object[]) => void }} options * @returns {{ readonly applied: object[], setFields(fields: object[], applied?: object[]): void, destroy(): void }} */export function filters(root, options) { const part = (name) => root.querySelector(`[data-filter="${name}"]`) const open = part('open') const count = part('count') const chips = part('chips') const clearAll = part('clear-all') const shown = part('applied') const panel = part('panel') const form = part('form') const list = part('conditions') const empty = part('empty') const error = part('error') const add = part('add') const controller = new AbortController() const { signal } = controller let fields = options.fields let applied = [...(options.applied ?? [])] let draft = [] const fieldOf = (key) => fields.find((field) => field.key === key) /** A copy of one of the page's templates: the markup is the page's, this only fills it in. */ const clone = (name) => part(name).content.firstElementChild.cloneNode(true) /** @param {[string, string][]} choices @param {string} chosen */ const fill = (select, choices, chosen) => select.replaceChildren(...choices.map(([value, words]) => { const option = new Option(words, value, false, value === chosen) option.className = 'select-option' return option })) /** The control for a condition's value: what its field holds. */ function valueControl(given, field, index) { const label = `Value of condition ${index + 1}` if (field.type === 'enum') { const select = clone('choice') fill(select, field.options, given.value) // Nothing is chosen for a new condition: a first option that cannot be chosen again says so. const prompt = new Option(`Choose a ${field.label.toLowerCase()}`, '', true, !given.value) prompt.disabled = true prompt.className = 'select-option' select.prepend(prompt) select.setAttribute('aria-label', label) return select } const input = clone('row').querySelector('[data-part="value"]') input.type = field.type === 'number' ? 'number' : field.type === 'date' ? 'date' : 'text' if (field.type === 'number') Object.assign(input, { step: 'any', min: '0', inputMode: 'decimal' }) if (field.type === 'text') input.placeholder = 'Value' input.setAttribute('aria-label', field.unit ? `${label}, in ${field.unit}` : label) input.value = given.value return input } /** Write the draft's rows. Focus goes back to the control it was on, by row and part. */ function drawDraft(focus) { list.replaceChildren(...draft.map((given, index) => { const field = fieldOf(given.field) const row = clone('row') row.dataset.index = String(index) row.querySelector('[data-part="joiner"]').textContent = index === 0 ? 'Where' : 'and' const fieldSelect = row.querySelector('[data-part="field"]') fill(fieldSelect, fields.map((each) => [each.key, each.label]), given.field) fieldSelect.setAttribute('aria-label', `Field of condition ${index + 1}`) const operator = row.querySelector('[data-part="operator"]') fill(operator, operatorsOf(field), given.operator) operator.setAttribute('aria-label', `Comparison of condition ${index + 1}`) row.querySelector('[data-part="value"]').replaceWith(valueControl(given, field, index)) row.querySelector('[data-part="remove"]').setAttribute('aria-label', `Remove condition ${index + 1}`) return row })) empty.hidden = draft.length > 0 if (focus) list.querySelector(`[data-index="${focus.index}"] [data-part="${focus.part}"]`)?.focus() } function say(message, control) { error.textContent = message ?? '' error.hidden = !message for (const invalid of list.querySelectorAll('[aria-invalid="true"]')) { invalid.removeAttribute('aria-invalid') invalid.removeAttribute('aria-describedby') } if (control) { control.setAttribute('aria-invalid', 'true') control.setAttribute('aria-describedby', error.id) } } /** Write the applied conditions: a chip each, the count on the button, and Clear all when there is any. */ function drawApplied() { chips.replaceChildren(...applied.map((given, index) => { const words = describe(given, fieldOf(given.field)) const chip = clone('chip') chip.querySelector('.chip-label').textContent = words const remove = chip.querySelector('.chip-remove') remove.setAttribute('aria-label', `Remove the filter ${words}`) remove.dataset.index = String(index) return chip })) // The wrappers have no display of their own, so `hidden` hides them whatever their content's classes say. shown.hidden = applied.length === 0 count.firstElementChild.textContent = String(applied.length) count.hidden = applied.length === 0 open.setAttribute('aria-label', applied.length ? `Filters, ${applied.length} applied` : 'Filters') } function commit(next, focusAfter) { applied = next drawApplied() options.onChange(applied) focusAfter?.focus() } // Opening copies what is applied into the draft; closing without Apply drops it. panel.addEventListener('toggle', (event) => { if (event.newState !== 'open') return draft = applied.map((given) => ({ ...given })) say(null) drawDraft() ;(list.querySelector('[data-part="field"]') ?? add).focus() }, { signal }) add.addEventListener('click', () => { draft.push(condition(fields[0])) say(null) drawDraft({ index: draft.length - 1, part: 'field' }) }, { signal }) list.addEventListener('click', (event) => { const remove = event.target.closest('[data-part="remove"]') if (!remove) return const index = Number(remove.closest('li').dataset.index) draft.splice(index, 1) say(null) if (draft.length) drawDraft({ index: Math.min(index, draft.length - 1), part: 'field' }) else { drawDraft(); add.focus() } }, { signal }) // A new field brings its own comparisons and its own kind of value. list.addEventListener('change', (event) => { const control = event.target.closest('[data-part]') const index = Number(control?.closest('li')?.dataset.index) if (!control || Number.isNaN(index)) return if (control.dataset.part === 'field') { draft[index] = condition(fieldOf(control.value)) // What was said about the condition this row held is no longer true of it. say(null) drawDraft({ index, part: 'field' }) } else if (control.dataset.part === 'operator') { draft[index].operator = control.value } else { draft[index].value = control.value } }, { signal }) list.addEventListener('input', (event) => { const control = event.target.closest('[data-part="value"]') if (!control) return draft[Number(control.closest('li').dataset.index)].value = control.value if (control.getAttribute('aria-invalid') === 'true') say(null) }, { signal }) form.addEventListener('submit', (event) => { event.preventDefault() for (const [index, given] of draft.entries()) { const control = list.querySelector(`[data-index="${index}"] [data-part="value"]`) const message = problem(given, fieldOf(given.field), control?.validity) if (message) { say(draft.length > 1 ? `Condition ${index + 1}: ${message}` : message, control) control?.focus() return } } panel.hidePopover() commit(draft.map((given) => ({ ...given, value: String(given.value).trim() })), open) }, { signal }) part('cancel').addEventListener('click', () => panel.hidePopover(), { signal }) part('clear').addEventListener('click', () => { draft = [] say(null) drawDraft() add.focus() }, { signal }) chips.addEventListener('click', (event) => { const remove = event.target.closest('.chip-remove') if (!remove) return const index = Number(remove.dataset.index) const next = applied.filter((_, at) => at !== index) commit(next) // Focus stays in the row of chips: on the next one, or the one before, or the button that opens the filters. ;(chips.querySelectorAll('.chip-remove')[Math.min(index, next.length - 1)] ?? open).focus() }, { signal }) clearAll.addEventListener('click', () => commit([], open), { signal }) drawApplied() return { get applied() { return applied.map((given) => ({ ...given })) }, setFields(next, start = []) { fields = next applied = start drawApplied() }, destroy() { controller.abort() if (panel.matches(':popover-open')) panel.hidePopover() }, }}/** * The demo's query logic, shared by the filter bar and the table view: conditions on a field, an operator and a * value, all of which a row must meet (one level of AND), plus search, sort and pages. It reads plain rows and * plain fields and touches no element. An application asks its own data source the same questions; this is * not a query engine to publish. * * A field is `{ key, label, type, options? }`: `type` is `text`, `enum`, `number` or `date`, and an enum lists * its `options` as `[value, label]`. A date is `YYYY-MM-DD`, so dates compare as text. *//** The operators each type of field offers, in the order a reader meets them: `[name, words]`. */export const operators = { text: [['contains', 'contains'], ['is', 'is'], ['is-not', 'is not'], ['starts', 'starts with']], enum: [['is', 'is'], ['is-not', 'is not']], number: [['is', 'is'], ['more', 'is more than'], ['less', 'is less than']], date: [['on', 'is on'], ['before', 'is before'], ['after', 'is after']],}/** @param {{ type: keyof typeof operators }} field */export const operatorsOf = (field) => operators[field.type]/** A new condition on a field: its first operator, and a value still to give, even a choice. */export function condition(field) { return { field: field.key, operator: operatorsOf(field)[0][0], value: '' }}/** * What is wrong with a condition, in words, or null when it can be applied. The input's own validity comes first, * so a number field that holds letters is caught as the browser sees it. * @param {{ field: string, operator: string, value: string }} given * @param {{ type: string, label: string, options?: string[][] }} field * @param {ValidityState} [validity] */export function problem(given, field, validity) { if (!field) return 'Choose a field.' if (!operatorsOf(field).some(([name]) => name === given.operator)) return `Choose how ${field.label.toLowerCase()} compares.` const value = String(given.value ?? '').trim() if (validity?.badInput) return field.type === 'date' ? `Enter a whole date for ${field.label.toLowerCase()}.` : `Enter a number for ${field.label.toLowerCase()}.` if (!value) return field.type === 'enum' ? `Choose a ${field.label.toLowerCase()}, or remove the condition.` : `Enter a value for ${field.label.toLowerCase()}, or remove the condition.` if (field.type === 'number' && !Number.isFinite(Number(value))) return `Enter a number for ${field.label.toLowerCase()}.` if (field.type === 'date' && !/^\d{4}-\d{2}-\d{2}$/.test(value)) return `Enter a whole date for ${field.label.toLowerCase()}.` if (field.type === 'enum' && !field.options.some(([option]) => option === value)) return `Choose a ${field.label.toLowerCase()}.` return null}/** Whether a row meets one condition. */function meets(row, given, field) { const have = row[field.key] const want = given.value switch (field.type) { case 'text': { const text = String(have).toLowerCase() const term = String(want).trim().toLowerCase() if (given.operator === 'contains') return text.includes(term) if (given.operator === 'starts') return text.startsWith(term) return given.operator === 'is' ? text === term : text !== term } case 'enum': return given.operator === 'is' ? have === want : have !== want case 'number': { const number = Number(want) if (given.operator === 'more') return have > number if (given.operator === 'less') return have < number return have === number } case 'date': if (given.operator === 'before') return have < want if (given.operator === 'after') return have > want return have === want } return true}/** The rows that meet every condition. */export function filter(rows, conditions, fields) { const keyed = new Map(fields.map((field) => [field.key, field])) return rows.filter((row) => conditions.every((given) => meets(row, given, keyed.get(given.field))))}/** The rows whose given text holds what was typed, without regard to case. */export function search(rows, text, keys) { const term = text.trim().toLowerCase() if (!term) return rows return rows.filter((row) => keys.some((key) => String(row[key]).toLowerCase().includes(term)))}/** The rows in the order of one field, ascending or descending; ties keep the order they had. */export function sort(rows, key, direction = 'ascending') { const sign = direction === 'descending' ? -1 : 1 const compare = (a, b) => typeof a === 'number' ? a - b : String(a).localeCompare(String(b), 'en', { numeric: true }) return [...rows].sort((a, b) => compare(a[key], b[key]) * sign)}/** One page of rows, and where it stands among them. A page past the end is the last one. */export function paginate(rows, page, size) { const pages = Math.max(1, Math.ceil(rows.length / size)) const current = Math.min(Math.max(1, page), pages) const start = (current - 1) * size return { rows: rows.slice(start, start + size), page: current, pages, from: rows.length ? start + 1 : 0, to: Math.min(start + size, rows.length), total: rows.length }}const dates = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', year: 'numeric', timeZone: 'UTC' })/** A date as a reader reads it: `Nov 13, 2026`. */export const formatDate = (value) => dates.format(new Date(`${value}T00:00:00Z`))/** A condition in words, for its chip: `Status is Ready`. */export function describe(given, field) { const words = operatorsOf(field).find(([name]) => name === given.operator)?.[1] ?? given.operator const value = field.type === 'enum' ? field.options.find(([option]) => option === given.value)?.[1] ?? given.value : field.type === 'date' ? formatDate(given.value) : field.type === 'text' ? `“${String(given.value).trim()}”` : given.value return `${field.label} ${words} ${value}${field.unit ? ` ${field.unit}` : ''}`}블록은 복사해 사용하는 마크업입니다. 페이지의 텍스트 색상과 크기를 따르며, 미리보기에서는 body에 fg-text-body text-sm 클래스를 설정합니다. 각 블록은 크기 컨테이너이므로 넓은 페이지, 사이드바 너비의 공간, 대화 상자 어디서든 자체 너비에 맞춰 배치가 바뀝니다.
#구성 요소
- 하나의 시트. 시트 안에 카드를 겹쳐 넣는 대신 얇은 구분선
bt(1) bt-solid b-line-hair로 영역을 나눕니다. - 헤더는 두 부분으로 나뉩니다. 한쪽에는 워크스페이스 이름과 조건에 맞는 행의 개수를, 다른 쪽에는 프로젝트·사람·파일을 전환하는 세그먼트 컨트롤과 기본 작업을 배치합니다.
flex flex-wrap items-center justify-between을 적용하므로 시트가 좁으면 세그먼트 컨트롤과 기본 작업이 제목 아래로 내려갑니다. - 검색, 필터, 정렬은 공간이 부족하면 줄바꿈되는 한 행에 배치합니다. 200px에서 320px까지 늘어나는 검색 입력 그룹, 필터 바의 버튼, 정렬 순서를 고르는 볼록한 셀렉트가 들어가며, 셀렉트는
ml-auto로 행의 끝에 배치합니다. 적용한 필터는 그 아래 별도의 줄에 칩으로 표시되며, 각 칩으로 필터를 하나씩 해제할 수 있습니다. - 정렬 상태는 열 머리글에 표시합니다. 정렬 기준 열의 머리글에
aria-sort를 지정하면 표는 해당 머리글을 진한 글자색과 셰브런으로 표시합니다. 정렬 순서는 셀렉트에서 바꿉니다. - 표는 자체 영역에서 스크롤됩니다.
scroll-area-inline클래스를 적용한 스크롤 영역에 표를 넣습니다. 시트가 좁아지면 페이지가 아니라 표만 스크롤되고, 열이 더 이어지는 가장자리는 흐리게 표시됩니다. - 데이터 종류마다 첫 번째 셀이 다릅니다. 프로젝트는 이름 아래에 도메인을, 사람은 아바타 옆에 이름과 이메일을, 파일은 아이콘 프레임 옆에 이름을 표시합니다. 첫 번째 셀은
<th scope="row">이므로 보조 기술은 같은 행의 데이터 셀을 읽을 때 이 행 머리글도 함께 읽습니다. - 선택은 조건에 맞는 행을 대상으로 합니다. 선택된 행에는
table-row에aria-selected="true"를 지정해 선택 상태의 색상을 표시하고, 해당 행의 체크박스도 체크합니다. 헤더 체크박스는 모든 페이지에서 검색어와 필터에 맞는 행을 모두 선택하며, 일부만 선택되어 있으면indeterminate상태가 됩니다. 조건에 더 이상 맞지 않는 행은 선택에서 빠지므로 “15개 중 3개 선택됨”은 검색과 필터에 맞는 행만 집계합니다. - 푸터는 두 부분으로 나뉩니다. 한쪽에는 선택 상태와, 선택한 행이 있을 때 표시되는 삭제 및 선택 해제 버튼을, 다른 쪽에는 표시 범위와 버튼으로 구성한 페이지네이션을 배치합니다. 첫 페이지에서는 이전 버튼이, 마지막 페이지에서는 다음 버튼이 비활성화됩니다. 페이지가 많으면 첫 페이지, 마지막 페이지, 현재 페이지의 앞뒤 페이지를 남기고 그 사이는 생략 표시로 나타냅니다.
- 행별 작업은 행 끝의 눈에 띄지 않는 버튼으로 여는 메뉴에 들어갑니다. 버튼 이름에는 “Atlas 작업”처럼 해당 행의 이름을 포함합니다.
- 조건에 맞는 항목이 없으면 그 사실을 알립니다. 빈 상태가 본문을 채우고, 검색어와 필터를 지워 돌아갈 방법을 제공합니다.
#스크립트가 필요한 동작
행은 데이터이므로 예제의 main.js가 data.js의 데이터를 마크업에 들어 있는 데이터 종류별 템플릿에 작성합니다. 스타일시트와 유틸리티는 마크업에서, 텍스트는 데이터에서 가져옵니다. 이 예제는 필터 바의 두 모듈을 공유합니다. query.js는 일반 행을 검색, 필터링, 정렬하고 페이지로 나누며, filters.js는 필터 바를 동작시킵니다. 실제 제품에서는 이런 질의를 데이터 소스에 보내며, 블록은 각 결과를 어떻게 표시하는지 보여 줍니다. 스크립트 없이 사용하려면 모든 영역을 하나의 <form method="get">으로 감싸세요. 검색 필드, 셀렉트, 체크박스가 서버에서 처리할 수 있는 쿼리 문자열이 되고, 페이지네이션은 링크가 됩니다.
#선택한 행에 적용할 작업
예제에서는 선택한 행에 적용할 작업이 하나뿐이므로 푸터의 개수 옆에 둡니다. 작업이 여러 개라면 선택한 행의 개수, 작업, 선택 해제 기능을 플로팅 도구 모음에 표시하세요. sticky bottom(16)을 적용해 시트 하단에 배치하거나 뷰포트 하단에 고정하고, 선택한 행이 있는 동안 표시합니다.
선택한 행에 적용할 작업
<div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected"> <span class="px-xs fg-text-strong">2 selected</span> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-sm"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M8 1.3333C4 4.6667 3.6667 8.6667 5.6667 12.3333H10.3333C12.3333 8.6667 12 4.6667 8 1.3333Z" /><circle cx="8" cy="6.6667" r="0.85" fill="currentColor" stroke="none" /><path d="M10.016 12.3333Q10.1079 12.4463 10.2446 12.5147L12.5342 13.6594A0.6999 0.6999 0 0 0 13.5377 13.1484L14.1443 9.5091Q14.1989 9.1824 13.9807 8.9328L11.9808 6.6473A0.7011 0.7011 0 0 0 11.3582 6.4146C11.5022 7.0678 11.5536 7.7269 11.5195 8.3865L11.635 7.7707L13.1346 9.4845L12.6181 12.5833L10.8942 11.7215L11.1203 10.5157C10.924 11.1275 10.6597 11.7349 10.3333 12.3333H10.016ZM4.6418 6.4146A0.6958 0.6958 0 0 0 4.0192 6.6473L2.0193 8.9328Q1.8012 9.1824 1.8557 9.5091L2.4623 13.1484A0.6999 0.6999 0 0 0 3.4658 13.6594L5.7554 12.5147Q5.8921 12.4463 5.984 12.3333H5.6667C5.3403 11.7349 5.076 11.1275 4.8797 10.5157L5.1058 11.7215L3.3819 12.5833L2.8654 9.4845L4.365 7.7707L4.4805 8.3865C4.4464 7.7269 4.4978 7.0678 4.6418 6.4146Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M6.6667 15L9.3333 15" /> </svg>Redeploy </button> <button type="button" class="btn btn-quiet btn-sm"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M8.5 9L8.4994 1.9755A0.5 0.5 0 0 0 7.5054 1.9266L7.5 2L7.5014 9.0379A0.5007 0.5007 0 0 0 7.5892 9.285A0.7044 0.7044 0 0 0 8.4108 9.285A0.4996 0.4996 0 0 0 8.5 9Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M5 6L7.8586 8.8586A0.2 0.2 0 0 0 8.1414 8.8586L11 6" /><path d="M2.5 10.5L2.5 12.5A1 1 0 0 0 3.5 13.5L12.5 13.5A1 1 0 0 0 13.5 12.5L13.5 10.5" /> </svg>Export </button> <button type="button" class="btn btn-quiet btn-sm btn-danger"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M2.5 4.5L13.5 4.5" /><path d="M4 4.5L4.4501 13.0526A1 1 0 0 0 5.4488 14L10.5512 14A1 1 0 0 0 11.5499 13.0526L12 4.5" /><path d="M6 4.5L6 3A1 1 0 0 1 7 2L9 2A1 1 0 0 1 10 3L10 4.5" /><path d="M8 7.5L8 11" /> </svg>Delete </button> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></div>import RocketIcon from '@master/icons-react/native/16/soft/rocket'import DownloadIcon from '@master/icons-react/native/16/soft/download'import TrashIcon from '@master/icons-react/native/16/soft/trash'import XIcon from '@master/icons-react/native/16/soft/x'<div className="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected"> <span className="px-xs fg-text-strong">2 selected</span> <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" className="btn btn-quiet btn-sm"> <RocketIcon className="icon" />Redeploy </button> <button type="button" className="btn btn-quiet btn-sm"> <DownloadIcon className="icon" />Export </button> <button type="button" className="btn btn-quiet btn-sm btn-danger"> <TrashIcon className="icon" />Delete </button> <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection"> <XIcon className="icon" /> </button></div><script> import RocketIcon from '@master/icons-svelte/native/16/soft/rocket' import DownloadIcon from '@master/icons-svelte/native/16/soft/download' import TrashIcon from '@master/icons-svelte/native/16/soft/trash' import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected"> <span class="px-xs fg-text-strong">2 selected</span> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-sm"><RocketIcon class="icon" />Redeploy</button> <button type="button" class="btn btn-quiet btn-sm"><DownloadIcon class="icon" />Export</button> <button type="button" class="btn btn-quiet btn-sm btn-danger"> <TrashIcon class="icon" />Delete </button> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection"> <XIcon class="icon" /> </button></div><script setup>import RocketIcon from '@master/icons-vue/native/16/soft/rocket'import DownloadIcon from '@master/icons-vue/native/16/soft/download'import TrashIcon from '@master/icons-vue/native/16/soft/trash'import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected"> <span class="px-xs fg-text-strong">2 selected</span> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-sm"><RocketIcon class="icon" />Redeploy</button> <button type="button" class="btn btn-quiet btn-sm"><DownloadIcon class="icon" />Export</button> <button type="button" class="btn btn-quiet btn-sm btn-danger"> <TrashIcon class="icon" />Delete </button> <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection"> <XIcon class="icon" /> </button> </div></template>#접근성
- 시트는
<section>이며, 시트의 제목을 접근 가능한 이름으로 사용합니다. 표의 이름도 이 제목으로 지정합니다. - 각 체크박스 이름에는 “Atlas 선택”처럼 해당 행의 이름을 포함합니다. 헤더 체크박스의 이름은 “프로젝트 15개 모두 선택”처럼 무엇을 선택하는지 알려 줍니다.
- 제목 아래의 개수는 일반 텍스트입니다.
sr-only를 지정한 상태 영역이 “3페이지 중 2페이지”, “프로젝트 3개 삭제됨”처럼 작업 결과를 알립니다. 포커스는 누른 요소에 남으며, 그 요소가 있던 행이 사라지면 헤더 체크박스로 이동합니다. - 작업 열의 제목은 화면에서 숨기되 보조 기술에서 읽을 수 있게 합니다.
- 페이지 탐색에는 레이블이 있는
<nav>를 사용합니다. 페이지는 현재 화면을 그 자리에서 바꾸므로 버튼으로 작성하고, 현재 페이지에는aria-current="page"를 지정합니다. - 각 행의 첫 번째 셀은
<th scope="row">입니다. 따라서 스크린 리더는 셀을 읽을 때 해당 프로젝트, 사람 또는 파일의 이름도 함께 읽습니다. - 필터는 “프로젝트 필터”라는 이름의 팝오버에서 열립니다. 행과 메시지를 읽는 방식은 필터 바를 참고하세요.
- 표는 스크롤 영역 안에서 가로로 스크롤됩니다. 표 안의 체크박스와 버튼을 통해 키보드로 스크롤 영역에 접근할 수 있습니다. 표 안에 포커스를 받을 수 있는 요소가 없다면 스크롤 영역에
tabindex="0", 역할, 접근 가능한 이름을 지정해야 합니다.
#관련 항목
- 표면모든 컴포넌트의 바탕이 되는 트레이, 볼록한 표면, 오목한 영역의 높이 체계입니다.
- 제목페이지의 기본 글자색으로 표시하는 제목과 제목 위 안내 문구, 아래 소개 문단입니다.
- 세그먼트 컨트롤하나의 오목한 영역에 몇 가지 옵션을 배치하고, 솟아오른 표면이 현재 옵션으로 부드럽게 이동합니다.
- 버튼표면 위로 살짝 돌출되어 있으며, 포인터를 올리면 떠오르고 누르면 가라앉는 버튼입니다.
- 입력 필드표면을 파낸 듯한 텍스트 입력 필드와 레이블, 힌트, 오류, 입력 그룹.
- 셀렉트인터페이스의 다른 부분과 같은 표면 스타일로 옵션 목록을 표시하는 네이티브 셀렉트입니다.
- 팝오버팝오버를 여는 버튼을 기준으로 배치되는 떠 있는 패널입니다.
- 칩필터나 삭제할 수 있는 값을 나타내는 작은 알약 모양의 컴포넌트입니다.
- 배지상태, 카테고리 또는 개수를 표시하는 작은 칩입니다. 색에 의미가 있을 때만 색을 사용합니다.
- 스크롤 영역콘텐츠가 이어지는 가장자리에 페이드가 적용되는 스크롤 영역입니다.
- 표가는 구분선으로 데이터 행을 나누고, 열 제목에서 정렬 순서를 바꿀 수 있으며, 숫자의 자릿수가 가지런히 맞는 표입니다.
- 체크박스선택하면 잉크 색으로 채워지는 작은 오목한 영역 형태의 네이티브 입력 요소입니다.
- 아바타사람이나 팀을 사진 또는 이니셜로 나타내며, 하나만 표시하거나 여러 개를 겹쳐 표시할 수 있습니다.
- 아이콘 프레임제목 옆에 아이콘을 크기에 맞게 담는 작은 오목한 영역입니다.
- 메뉴버튼에 맞춰 배치되며 작업 목록을 담는 팝오버입니다.
- 빈 상태뷰에 아직 표시할 내용이 없을 때 나타나는 상태입니다.
- 페이지네이션긴 목록의 페이지를 한 줄의 링크로 보여 주며, 현재 페이지는 눌린 상태로 표시합니다.
- 도구 모음눈에 띄지 않는 컨트롤을 한 줄로 담는 작고 살짝 솟은 표면입니다.