- We've got some components
A,BandCwhich provide different slots.const A = { template: `<div><slot name="a">Default A Content</slot></div>` }
const B = {
x-select is an Alpine.js directive which provides a styled enhancement over a native <select> element.
Its main goal is to be a progressive enhancement adding no actual features to a select dropdown apart from making it more visually appealing to use (especially for select fields with multiple).
Further goals include:
| /** | |
| * Convert between Uint8Array and Base64 strings | |
| * Allows for any encoded JS string to be converted (as opposed to atob()/btoa() which only supports latin1) | |
| * | |
| * Original implementation by madmurphy on MDN | |
| * @see https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_1_–_JavaScript%27s_UTF-16_%3E_base64 | |
| */ | |
| function b64ToUint6(nChr) { | |
| return nChr > 64 && nChr < 91 |
| /** | |
| * Get the number of characters in an element | |
| * | |
| * @param {Element} element | |
| * @return {number} | |
| */ | |
| function getTextLength(element) { | |
| let range = element.ownerDocument.createRange() | |
| range.selectNodeContents(element) |
ATTENTION!
I keep this Gist for archival reasons, however I strongly recommend against using it. As I discovered after several weeks in production usage, these BEM mixins cause unexpected, unfixable and hard-to-debug selectors in some cases (especially when nested in some ways).
This is a utility with three simple Sass mixins for writing BEM as DRY as possible, heavily inspired by Hugo Giraudel's article on CSS Tricks.
It exposes three Sass mixins: block, element and modifier.
| /** | |
| * Export all data from an IndexedDB database | |
| * | |
| * @param {IDBDatabase} idbDatabase The database to export from | |
| * @return {Promise<string>} | |
| */ | |
| export function exportToJson(idbDatabase) { | |
| return new Promise((resolve, reject) => { | |
| const exportObject = {} | |
| if (idbDatabase.objectStoreNames.length === 0) { |
A container component reacting to breakpoints on its own width or height, powered by ResizeObserver and scoped slots.
It is similar to things like vue-resize in that you can use it to observe a component's size. However the ResponsiveContainer will not emit any events, its whole point is to work as declaratively as possible, taking a predefined set of breakpoints you can access in your component.
This is about how to split a GitHub pull request, following a real in-the-wild example.
So it happened that I once wanted to fix a bug (#832) on the shelljs repository.
I forked the repository, cloned it and created a new branch called ln-directory-dest. I fixed the bug, created a pull request, and implemented initial review feedback.
At this point, I had added the commits A, B, C, D, E and [F](https://github.com/Loilo/shelljs/commit/946ab48bf5cf9c8aac03407
| function getLocalISOString(date) { | |
| const offset = date.getTimezoneOffset() | |
| const offsetAbs = Math.abs(offset) | |
| const isoString = new Date(date.getTime() - offset * 60 * 1000).toISOString() | |
| return `${isoString.slice(0, -1)}${offset > 0 ? '-' : '+'}${String(Math.floor(offsetAbs / 60)).padStart(2, '0')}:${String(offsetAbs % 60).padStart(2, '0')}` | |
| } |
This is a Sass mixin to handle a 3-way dark mode. It relies on a data-theme attribute on your <html> element with a value of light or dark. If data-theme is absent (i.e. it's neither light nor dark), the system's preferred mode is used.
body {
// matches data-theme="light" or data-theme="auto" with system instructing light mode
@include light {
background: white;
color: black;