layouts
All repositories: gitoria
5.7 KB
// file-upload.hl — THE FILE UPLOAD (one file), pure Hybriel: a drop zone with a "Choose a file" button. The chosen or dropped file goes// to the app through `emit server saveFile(file)` (the framework carries it over HTTP, in parts, with progress: hybriel#94); the app's// `on server saveFile(file)` decides where it is stored and answers anything but null when it took it (a face that raises an error or// answers null = the upload failed). Name, size and progress show while it goes; a finished file is listed under "Uploaded".// One file at a time: a drop of several takes the first, a file dropped during an upload is ignored. USE ONE PER PAGE (a composed// component's members are the page's state). The page is written by DOM calls in the handlers: the emit blocks its handler, and// `on client uploadProgress` paints the bar meanwhile.String dropText = 'Drop a file here or'String chooseText = 'Choose a file'String uploadedTitle = 'Uploaded'sizeText(n) {if (n < 1024) { return n + ' B' }if (n < 1048576) { return (n / 1024).toFixed(1) + ' KB' }return (n / 1048576).toFixed(1) + ' MB'}View {fileUpload {dropZone { on dragover(e) { emit uploadOver(e) } on dragleave(e) { emit uploadLeave(e) } on drop(e) { emit uploadDrop(e) }p { dropText }label { class = "choose" chooseText input { type = "file" on change(e) { emit uploadChosen(e) } } }uploadStatus { 'aria-live' = "polite"strong { class = "name" }span { class = "size" }progress { max = "100" value = "0" }output { class = "state" }}}uploadedList {h2 { uploadedTitle }ul { class = "uploaded" }}}}rootOf(node) { return node.closest('file-upload') }on uploadOver(e) {e.preventDefault()rootOf(e.target).classList.add('over')}on uploadLeave(e) { rootOf(e.target).classList.remove('over') }on uploadDrop(e) {e.preventDefault()root = rootOf(e.target)root.classList.remove('over')if (e.dataTransfer.files.length > 0) { send(root, e.dataTransfer.files[0]) }}on uploadChosen(e) {root = rootOf(e.target)input = e.targetif (input.files.length > 0) { send(root, input.files[0]) }input.value = ''}on client uploadProgress(p) {for (root of document.querySelectorAll('file-upload.busy')) {let bar = root.querySelector('progress')bar.max = p.size > 0 ? p.size : 1bar.value = p.sent}}send(root, file) {if (root.classList.contains('busy')) { return null }root.classList.add('busy')root.classList.remove('done')root.classList.remove('failed')root.classList.add('shown')root.querySelector('.name').textContent = file.nameroot.querySelector('.size').textContent = sizeText(file.size)bar = root.querySelector('progress')bar.max = 100bar.value = 0state = root.querySelector('.state')state.textContent = 'Uploading…'saved = emit server saveFile(file)root.classList.remove('busy')if (saved == null) {root.classList.add('failed')state.textContent = 'Failed'return null}bar.max = 100bar.value = 100root.classList.add('done')state.textContent = 'Uploaded'li = document.createElement('li')li.textContent = file.name + ' — ' + sizeText(file.size)root.querySelector('ul.uploaded').appendChild(li)}// ---- look: the component's own Style; the base look is black, white and the greys #555 #999 #ddd #f2f2f2 (shared/base.hl names them;// README "Look"); every colour is a semantic token with its base value as fallback, so an app that declares the tokens (layouts.worldapi.org's// theme) restyles it. No frames: the one border is the drop zone's dashed one (it means "drop here")Style {fileUpload {display = 'block'color = 'var(--color-text, #000)'dropZone {display = 'block'padding = '1rem'textAlign = 'center'border = '2px dashed var(--color-border, #999)'borderRadius = '.5rem'p {margin = '0 0 .5rem'color = 'var(--color-text-muted, #555)'}}// Class or attribute assigned by the View or code; no compound-selector form.'label.choose' {display = 'inline-block'padding = '.35rem .8rem'cursor = 'pointer'border = '0'borderRadius = '.35rem'background = 'var(--color-surface, #f2f2f2)'hover { filter = 'brightness(.93)' }input { display = 'none' }}uploadStatus {display = 'none'marginTop = '.8rem'textAlign = 'left'// Class or attribute assigned by the View or code; no compound-selector form.'.name' { overflowWrap = 'anywhere' }// Class or attribute assigned by the View or code; no compound-selector form.'.size' {marginLeft = '.6rem'color = 'var(--color-text-muted, #555)'}// Class or attribute assigned by the View or code; no compound-selector form.'.state' { fontSize = '.9rem' }}progress {display = 'block'width = '100%'margin = '.4rem 0'accentColor = 'var(--color-accent, #000)'}uploadedList {h2 {margin = '1rem 0 .3rem'fontSize = '1rem'}}// Class or attribute assigned by the View or code; no compound-selector form.'ul.uploaded' {margin = '0'paddingLeft = '1.2rem'}}// No language form for class or attribute on the component root.'file-upload.over drop-zone' {borderColor = 'var(--color-accent, #000)'background = 'var(--color-surface, #f2f2f2)'}// No language form for class or attribute on the component root.'file-upload.shown upload-status' { display = 'block' }// No language form for class or attribute on the component root.'file-upload.done .state' { color = 'var(--color-success, #000)' }// No language form for class or attribute on the component root.'file-upload.failed .state' { color = 'var(--color-danger, #000)' }// No language form for pseudo-element.'file-upload ul.uploaded:empty::after' {content = '"Nothing yet."'marginLeft = '-1.2rem'color = 'var(--color-text-muted, #555)'}}
Branches
Latest commits
- ebd00b6cNest caller slot styles in three-panemre
- 009991efNest caller slot styles in list-firstmre
- 494d75d4Nest caller slot styles in app-sidebarmre
- e5571680Align all plugin sources with Hybriel day38bmre
- 5d204c46Re-vendor layouts to Hybriel set day38bmre
- 17e0f03eNest html-prefixed theme component overridesmre
- e54e735eFormat plain theme elements with nested rules and bare mediamre
- 547f834eRecord LY7 deployment and live verificationmre
- fa4600b1Link caller-slot style exceptions to hybriel#270mre
- 413b11e1Record corrected LY7 nesting, exact CSS and Chrome proofmre
- b810453etracker-demo: nest child and compound selectors in Stylemre
- 0b5b1d61notes-demo: nest child and compound selectors in Stylemre
- ab22bdc2mail-demo: nest child and compound selectors in Stylemre
- fe2d8de9home: nest child and compound selectors in Stylemre
- e631791buser-menu: nest child and compound selectors in Stylemre
- 69604944three-pane: nest child and compound selectors in Stylemre
- 3e389b83main-menu: nest child and compound selectors in Stylemre
- 05413975list-first: nest child and compound selectors in Stylemre
- c545b642content-first: nest child and compound selectors in Stylemre
- eae2be7aapp-sidebar: nest child selectors and document caller-slot gapmre