-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36eaeb9
commit 7810ac7
Showing
27 changed files
with
71,165 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.utilities { | ||
padding-bottom: 3rem; | ||
} | ||
|
||
.utilities h3.util { | ||
font-size: 1.1rem; | ||
color: var(--ui-color-accent); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<h3 class="util">alignItem (config)</h3> | ||
<p>Aligns an element to another element, | ||
ensuring that the aligned element remains within the viewport. | ||
</p> | ||
<ul> | ||
<li><em>config</em> - an object with the configuration (see below). | ||
<li>Returns <em>position</em> - whether the aligned item is above (top) or below (bottom) the target. | ||
</ul> | ||
|
||
<API props="{apiProps}" title="Config object schema"/> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { API } from '../../api-table'; | ||
import { CodeExample } from '../../code-example'; | ||
const apiProps = [ | ||
{ name: 'element', type: 'HTMLElement', description: 'main element that will be aligned.' }, | ||
{ name: 'target', type: 'HTMLElement', description: 'target element to align to.' }, | ||
{ name: 'alignH', type: ['left', 'right', 'center'], default: 'left', description: 'Horizontal position' }, | ||
{ name: 'offsetH', type: 'number', default: 0, description: 'horizontal offset of the aligned position (in pixels).' }, | ||
{ name: 'alignV', type: ['top', 'bottom'], default: 'bottom', description: 'Vertical position' }, | ||
{ name: 'offsetV', type: 'number', default: 2, description: 'vertical offset of the aligned position (in pixels).' }, | ||
{ name: 'viewportPadding', type: 'number', default: 10, description: 'padding from the viewport (in pixels).' }, | ||
{ name: 'setMinWidthToTarget', type: 'boolean', default: false, description: 'whether to set the minWidth of the element to the width of the target.' }, | ||
]; | ||
const example = ` | ||
<script> | ||
const button = document.querySelector('.button1'); | ||
const popup = document.querySelector('.popup1'); | ||
const pos = alignItem({ | ||
element: popup, | ||
target: button, | ||
alignH: 'left', | ||
alignV: 'bottom', | ||
}); | ||
// it may happen that there is not enough space to align the popup as requested | ||
// in this case, the popup will be aligned to the opposite side | ||
console.log('position:', pos); // 'top' | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h3 class="util">debounce(fn, timeout = 300)</h3> | ||
<p>The "debounced" function will only be called after it has not been called for <em>timeout</em> milliseconds.</p> | ||
<ul> | ||
<li><em>fn</em> - function to debounce. | ||
<li><em>timeout</em> - milliseconds to wait before calling <em>fn</em>. | ||
</ul> | ||
|
||
<p> | ||
This is a useful e.g. when attaching an event listener to an event that is fired repeatedly & quickly (like scroll or resize).<br> | ||
Attaching a heavy function to such an event can cause performance issues, so debouncing it will ensure | ||
that the function is only called after it has not been called for <em>timeout</em> milliseconds. | ||
</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
function original() { | ||
console.log('resizing has stopped for 300ms'); | ||
} | ||
const debounced = debounce(original); | ||
window.addEventListener('resize', debounced); | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h3 class="util">deepCopy(object)</h3> | ||
<p>This is just an alias for an oddly-named native function: <b>structuredClone</b>.</p> | ||
<ul> | ||
<li><em>object</em> - any object or array to clone. | ||
</ul> | ||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
const original = {a: 1, b: 2, c: 3}; | ||
const clone = deepCopy(original); | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<h3 class="util">empty(value)</h3> | ||
<p>Similar to PHP's <em>empty</em> - returns true if a value is empty.</p> | ||
<ul> | ||
<li><em>value</em> - any data type. | ||
</ul> | ||
|
||
<p>Empty will return true if the <em>value</em> is one of the following:</p> | ||
<ul> | ||
<li><em>undefined</em> | ||
<li><em>null</em> | ||
<li><em>empty string</em> | ||
<li><em>empty array</em> | ||
<li><em>empty object</em> | ||
</ul> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
empty(); // true | ||
empty(null); // true | ||
empty(''); // true | ||
empty([]); // true | ||
empty({}); // true | ||
empty(0); // false | ||
empty(false); // false | ||
empty('0'); // false | ||
empty([0]); // false | ||
empty({a: 0}); // false | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h3 class="util">formatDate (date)</h3> | ||
<p>Converts date to a string in the format: <em>YYYY-MM-DD HH:mm</em>.</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
formatDate(new Date()); // 2020-01-01 12:00 | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h3 class="util">fuzzy (haystack = '', needle = '')</h3> | ||
<p>Fuzzy finds if <em>haystack</em> contains characters from the <em>needle</em> in the same order.</p> | ||
<ul> | ||
<li><em>haystack</em> - a string to be searched in. | ||
<li><em>needle</em> - a string to search for. | ||
</ul> | ||
|
||
<p>It's useful for filtering lists of items by a search string.</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
fuzzy('hello world', 'hell'); // true | ||
fuzzy('hello world', 'helloo'); // true | ||
fuzzy('hello world', 'helll'); // true | ||
fuzzy('hello world', 'hellooo'); // false | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h3 class="util">getMouseX (event)</h3> | ||
<p>Returns the mouse X position. Event is standardised across platforms (touch & pointer)</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
document.addEventListener('mousedown', e => { | ||
const x = getMouseX(e); | ||
console.log(x); | ||
}); | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h3 class="util">getMouseY (event)</h3> | ||
<p>Returns the mouse XY position. Event is standardised across platforms (touch & pointer)</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
document.addEventListener('mousedown', e => { | ||
const [x, y] = getMouseXY(e); | ||
console.log(x, y); | ||
}); | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h3 class="util">getMouseY (event)</h3> | ||
<p>Returns the mouse Y position. Event is standardised across platforms (touch & pointer)</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
document.addEventListener('mousedown', e => { | ||
const y = getMouseY(e); | ||
console.log(y); | ||
}); | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h3 class="util">guid ()</h3> | ||
<p>Generates a globally unique identifier.</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
const id = guid(); | ||
console.log(id); // 9748bb50-0e54-4f4d-b6a2-c0ea0d576cd4 | ||
</script> | ||
`; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h3 class="util">isInScrollable (node)</h3> | ||
<p>Checks whether the given node is inside a scrollable element.</p> | ||
<p>This function is useful when determining whether a swipe event should be allowed | ||
to start on a given element.<br> | ||
If an element is inside a scrollable element, the swipe event will not start, | ||
allowing the browser to trigger the normal scrolling. | ||
</p> | ||
|
||
<CodeExample nohr html="{example}" /> | ||
|
||
|
||
<script> | ||
import { CodeExample } from '../../code-example'; | ||
const example = ` | ||
<script> | ||
const isInScrl = isInScrollable(document.querySelector('.element')); | ||
</script> | ||
`; | ||
</script> |
Oops, something went wrong.