Zed A. Shaw, Writer Profile picture
Jul 20, 2021 11 tweets 5 min read Read on X
I'll use this to do a running commentary on a "style checkbox" in CSS. First trick is to put the label *after* the checkbox so you can use + to select it if the checkbox is :checked. Clicking the label activates the hidden input, so the label changes red/green.
Here's a demo of that first part working. Now to make the label look like a checked/unchecked box that's different.
The next trick is to use the :after to add content, *but* if you give an :after that has no content it still creates a block you can style. Here I'm just making a little square.
Then in the main label we set it to display:flex, align-items: center, and give it a bit of padding on the left and right. Now we have a little box that's sitting on the left. We then need it to move to the right when the checkbox is checked.
To do that we just add flex-direction: row-reverse so the contents of the label (aka the :after box) are drawn in reverse order. Put that in the :checked rule and now you have a little box that toggles sides when you click it.
Finally, you change the background to indicate checked/unchecked. This is sort of where I think it falls apart as a UI element. It's hard to make a difference between "unchecked" and "disabled", and I don't think it's that clear you can click on it to change it.
Here's a demo of what that looks like. I think next level is to allow for two blocks of text for checked/unchecked states.
Well that's not too hard. First make two children for the <active> and <inactive> displays. Then, a series of :checked and regular rules that show/hide those depending on the state. Finally, set justify-content to space-between to push them to either side and done.
Here's the demo for that. I wonder if I can throw some Icons in there?
And with a bunch of little minor changes we have this code for what I think is a full feature Switch:

git.learnjsthehardway.com/zedshaw/zedsha…

Even has different sized variants, allows Icons, changes the font size, etc.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Zed A. Shaw, Writer

Zed A. Shaw, Writer Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @lzsthw

Jun 4, 2023
People who write in a pompous "King James" style sound pretentious. This article on teaching completely loses the message because the author is trying to sound "official" by sounding "biblical". It then slides downhill from there as expected:

intellectualmathematics.com/manifesto/
Clearly the author has never been poor, taught or studied in a poor school, never gone hungry, and has probably only taught people who would fit this model of "perfect". Slap all the "therefore" you want, the entire premise is disconnected from reality. Image
This is not supported by any research, and this is typically used to justify excluding people who don't already know a topic by claiming that a student is forever unteachable because they couldn't "handle" the artificial challenge. You mostly find this attitude in gifted kids who… twitter.com/i/web/status/1… Image
Read 7 tweets
Jun 2, 2023
A thread of weird Youtube searches for when you want some soothing noise to code to. Most of these either have no talking, or if there is talking it's low whispers (because some folks like that). All of these are also Safe for Work in most places.

Here's my favorites:
1. "dugout"

It's almost always a Russian man or woman building a little house in the dirt. They don't talk much, usually there's a dog they talk to but otherwise, woods, rain, fires, cooking, and digging.

youtube.com/results?search…
2. "camping rain"

Similar to "dugout" but this is all over the world, with the best ones in Korea and Australia. A little more talking but not a lot of digging sounds and mostly just rain and cooking.

youtube.com/results?search…
Read 7 tweets
Dec 19, 2022
Another thought I had recently was that I would _like_ to actually buy a product from many open source projects. No, I don't want to donate, I want to pay you for a real product, so I'm your customer and you try to make me happy.

But they always screw this up in weird ways:
1. No, I don't want to buy you coffee, or "donate" because that's a dodge to avoid the obligation of treating me like a customer. FLOSS projects do this so they can get money, and then force any changes they want on your without your consent crying "ENTITLED" when you complain.
2. On average I pay say $10-$30 for a video game, and those are way more expensive to produce than most open source projects. That's a reasonable price point for a lot of things like gitea, but what do they do?

Target the ENTERPRISE market with "Call us for pricing!"
Read 9 tweets
Dec 19, 2022
So, Gitea created some kind of corporation to try to make money on Gitea, and apparently that's caused a fork:

blog.codeberg.org/codeberg-launc…

The comments are amazingly hypocritical given that...

Gitea is written in Go, which is famously run with an iron fist by Google.
The hypocrisy is simply amazing. If all of these people are so against corporate open source then why the hell are they also all using Go or anything by Google?

Because, if you're a Trillionaire then people are grateful for your table scraps and ignore their supposed "morals".
Google has:

1. Unilaterally pushed a packaging system they wanted without any community input.
2. Banned people randomly for criticizing the project.
3. Let a single engineer on Chrome decide the entire fate of gRPC on the internet.

Not a peep from the FLOSS tryhards.
Read 4 tweets
Dec 16, 2022
My jsdoc replacement is at a point where I can browse my own documentation:

git.learnjsthehardway.com/learn-javascri…

with a simple viewer at:

git.learnjsthehardway.com/learn-javascri…

Now I need to process the docs comment and either I support the JSDoc format--which irritates me--or simplify it. Image
My problem with the JSDoc format is it's just a copy of the JavaDoc format, and it's far too strict, which is a Java thing. I'd rather have it tone down the format's requirements and handle more looseness, which would make documentation easier.
But, the JSDoc/JavaDoc format does make a ton of sense in many ways. Since I'm actually parsing the file it _could_ eventually make guesses at return values, and at least show the value of default asigned parameters, but not much more without big code work.
Read 4 tweets
Nov 8, 2022
I found it! It was in a Svelte transitions module that comes with Svelete, but...I think Microsoft is adding this copyright to all source that's compiled with TypeScript? I'm pretty damn sure that's not how copyright works, especially for programming languages.
So the exact file is this one:

github.com/sveltejs/svelt…

There's no Copyright notice in that source .ts file, but this is what's in the generated .mjs file:
That confirms it then, Microsoft is plastering their Copyright on _your_ code when you use TypeScript. That's absolutely not correct, both morally and according to the law. Can you imagine if Adobe Premiere inserted a (c) Adobe on all movies you edited?
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(