Show HN: 7GUIs in Vanilla HTML, CSS, JavaScript
7guis.bradwoods.io
7guis.bradwoods.io
https://github.com/bradwoods/7guis-html-css-js/blob/19279899...
This sort of thing in a production app would be littered with global state, it would be difficult to change anything / refactor without serious anxiety, if you have multiple developers good luck getting them to program the same predictable way, importing libraries see previous point, etc, etc.
function calcState() {
// Return field disabled for one-way trips
elems.return.disabled = isOneWay();
let allOk = true;
// All enabled fields are valid?
for (const f of [elems.departure, elems.return]) {
const isInvalid = (
!f.disabled &&
isBadFormat(f.value)
);
setInvalid(f, isInvalid);
if (isInvalid) allOk = false;
}
// Return trip after departure trip?
if (allOk && !isOneWay() && isEarlyReturn()) {
allOk = false;
}
// Enable submit if everything is OK
elems.submit.disabled = !allOk;
}
function setInvalid(elem, invalid) {
elem.setAttribute(ARIA_INVALID, invalid);
}
This follows the problem description quite closely, eg. "The return textfield is enabled if the combobox’s value is return flight" is implemented by one line, and not spread across seven different enable/disable calls.When we arrive at the CRUD widget,a simple <script> dep on petite-vue (6ko: https://github.com/vuejs/petite-vue) would half the implementation by half.
Of course it would still count as more lines of code in total, but not sure that matters.
Anyway, when I teach react/vue, I always start with the vanilla example because just like with ORM, people need to know the benefit and cost of the abstraction.
And then wrote my own version, with code a lot closer to modern react, with undo/redo and other niceties - https://github.com/ivank/vanilla-teuxdeux
And what I leaned is that is astonishingly easy to write code that would be understandable to people coming from the redux crowd. Maybe that’s because redux is just such a simple concept in and off itself - a glorified switch on a big object. And it’s also quite easy to hack a simple version of vdom to make it all work.
What’s missing from all those vanilla js efforts though turned out to be testability. There is a ton of code in the modern js world just to allow you to mock/test your components, and thats for me the real tragedy of vanilla js.
I have no idea why W3C crowd have not invested into standardizing js tests in all these years…
Besides lacking an open source version, spreadsheets and data grids haven't been studied as well as they should be.
It is also difficult to build one using just the DOM. For instance, you can't have a table be horizontally scrollable with the scrollbar fixed at the bottom and also have a fixed header.
Here's something I played around with a while back that has keyboard navigation between cells. Going between pages isn't great. The default focus scrolling in Chrome skips a few rows, and it doesn't respect the fixed header when scrolling up to the top after scrolling down. https://table-edit-20210409.vercel.app/ https://gitlab.com/ResourcesCo/table-edit-20210409 I tried making it with CSS Grid just to see if it could be done, and it turns out, only with Firefox. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_La... I'm thinking of drawing it with JavaScript, perhaps with a combination of canvas and DOM elements.
Back to the 7 GUIs - what's great about it is trying to build stuff from scratch. So much of web development is just putting components together and customizing them, but there is a lot of lower level work to do, and the more developers that attempt it, the more progress will be made.
Edit: found this, pretty interesting: https://github.com/TonyGermaneri/canvas-datagrid
You might actually be able to do that with position:sticky now: https://jsfiddle.net/0ydsve3x/1/
Edit: hmm, it's working in the CodePen here: https://css-tricks.com/a-table-with-both-a-sticky-header-and... I'll have to fully revisit what I was trying to do and see if I can get it working.
Edit 2: Oh, I realized that I wanted the horizontal scrollbar to be sticky when it is an element taking part of the vertical space of a page, but more than a screenful. I found this that solves it but not for a table with a fixed header: https://amphiluke.github.io/handy-scroll/ To see what I'm talking about, go to the top of the demo, horizontally scroll, and note that horizontal scrollbar is shown when scrolling horizontally. Then click disable, and note that it isn't shown when scrolling horizontally, unless you go all the way to the bottom. Or, if you don't have a trackpad, you actually have to go all the way to the bottom to scroll it horizontally.
I assume SlickGrid (https://github.com/6pac/SlickGrid/wiki/Examples) didn't satisfy your requirements?
Anything after the temperature converter example makes it painfully obvious that it would not be a pleasant experience.
Meanwhile all the functionality of vanilla JS is still there, and the language and runtime are arguably much better than they ever were.
It's worth experimenting with these things every now and then on your own, even if you don't have a simple setup at work.
> they make developing even harder
is saying
> These people are stupid and make their jobs more difficult
I'm not saying that majority is always right, but I think these devs might be onto something. I'm also trying to show how idiotic is the logic of tonis2 who throws such a slogan around without giving a single argument WHY these frameworks make development more difficult.
Or in my case seasoned developers who have been away from that front (concentrating on database/infrastructure/security matters) for some time and might like to catch up a bit. I can still do things the vanilla (or jquery/similar) way but that might not be ideal, but beyond that the sea of choice is daunting to think about navigating.
Or maybe I've been away so long I should consider myself to be a newbie in a new environment, instead of just a bit out-of-date in one that has moved forwards rapidly in my absence!
However, the issue is, any moderately complex application will soon develop its own in-house Framework. Its the natural progression, very soon the head Dev will say "lets create a library to handle all our form validation requirements....lets create library separate UI from business logic...etc"
That's the real "slippery slope" from a management perspective.
Do we wind up developing our own in-house Framework which our current developers are very productive in (but new hires don't understand)? Or do we bite the bullet and opt for an already existing Framework that already has a dev community? I'm not suggesting its an easy answer as there are pros/cons to each. In the end for 90% of cases I think starting with an existing Framework (or at least "Framework-lite") is best approach.
I’ve been thinking of something similar, and this is a good list, but is it “exhaustive”? What would such a list look like? Is there an objective way to explore all the various challenges of building UI?
Here’s one example: Very large forms. This is not covered, and can be quite challenging, especially when different parts of the form show up at different times. Even vanilla React fits this poorly (this is where Flux came into being, which ultimately spurred Redux, Recoil etc).
But also a CLI. A flow chart. Notebooks (Jupyter). So many types of UI to cover.
#colHeadings .rowHeading {
z-index: 3;
top: 0;
}
I also believe keyboard navigability is essential for the cells example, although the task specification neglected to mention it. (But then, the spec doesn’t specify anything about the formulas either—though it does include a picture depicting something like =SUM(B1:C4).) Tab and Shift+Tab work to shift cell focus, but that’s all; at the very least, Up/Down/Left/Right should work for cell navigation, and some way of entering edit mode without needing the mouse (start with F2, which is standard across spreadsheet apps that I know; perhaps Enter too, though they don’t).One thing though: add undo/redo to the Cell task as a requirement. After all, "a good paradigm should give you this functionality for free" :)
The CRUD example is just bad for no reason. It looks like a typical master-detail view, but the detail view doesn’t give any feedback when the selection in the list changes.
eta: Bad UX granted, I gather that the task is meant to compare DX. (And it'd be useful for comparing coding approaches by individuals, for evaluating interview candidates. For that purpose, it'd perhaps be useful to be able to test a person's particular design choices, and how they interpret the spec, perhaps to see if they are justified in building something not-quite-to-spec.)
eta2: https://eugenkiss.github.io/7guis/tasks#circle
Man, look how detailed this is. I suppose some people's job as developers is to literally implement specs exactly. Glad that's not my job. But maybe some folks would prefer not to have to deal with ambiguity.
(edit) nevermind, found it: https://garden.bradwoods.io/notes/problem-solving
The only "issue" I see: visually it's hard to see whether a cell is just focused, or is in edit mode.