Skip to content

Commit

Permalink
utils & utils nav
Browse files Browse the repository at this point in the history
  • Loading branch information
tborychowski committed Sep 8, 2023
1 parent 0fbf4e0 commit adf3eda
Show file tree
Hide file tree
Showing 30 changed files with 1,665 additions and 1,308 deletions.
23 changes: 20 additions & 3 deletions docs-src/components/utils/Utils.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
.utilities {
padding-bottom: 3rem;
}
.utils .dark-mode-switch { right: 260px; }

.utilities { padding-bottom: 3rem; margin-right: 240px; }


.utilities h3.util {
scroll-margin-top: 4.2rem;
font-size: 1.1rem;
color: var(--ui-color-accent);
font-family: Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;
}


.utilities-nav {
position: fixed;
right: 0;
top: 0;
bottom: 0;
z-index: 52;
margin: 0;
padding: 1rem 2rem;
overflow-y: auto;
width: 240px;
border-left: 1px solid var(--ui-color-border-2);
background-color: var(--ui-color-background-input);
}
86 changes: 37 additions & 49 deletions docs-src/components/utils/Utils.svelte
Original file line number Diff line number Diff line change
@@ -1,60 +1,48 @@
<div class="sticky-block utilities">
<h2>Utility properties</h2>
<div class="sticky-block utilities utilities-nav">
<h3>Utility properties</h3>
<ul>
{#each props as item}
<li><a href="#Utils/{item}">{item}</a>
{/each}
</ul>

<FocusableSelector/><hr>
<PrefersDark/>
<h3>Utility Functions</h3>
<ul>
{#each fns as item}
<li><a href="#Utils/{item}">{item}</a>
{/each}
</ul>
</div>

<div class="sticky-block utilities" id="top">
<h2>Utility properties</h2>
{#each props as item}
<div class="utility">
<svelte:component this="{Properties[item]}" /><br>
</div>
{/each}
<p>
<em>*</em> <a href="https://svelte.dev/docs/svelte-components#script-4-prefix-stores-with-$-to-access-their-values">
svelte store variables</a> - when reading the value, add <em>$</em> to the name, e.g.
<em>$FOCUSABLE_SELECTOR</em>.
</p>
</div>

<div class="sticky-block utilities">
<h2>Utility Functions</h2>

<Animate/><hr>
<Blink/><hr>
<DeepCopy/><hr>
<Debounce/><hr>
<Throttle/><hr>
<Empty/><hr>
<Fuzzy/><hr>
<Guid/><hr>
<GetMouseX/><hr>
<GetMouseY/><hr>
<GetMouseXY/><hr>
<IsMobile/><hr>
<Pluck/><hr>
<RoundAmount/><hr>
<FormatDate/><hr>
<TimeAgo/><hr>
<AlignItem/><hr>
<IsInScrollable/>
{#each fns as item}
<div class="utility">
<svelte:component this="{Functions[item]}" /><br>
</div>
{/each}
</div>
docs-src/components/utils/fn-guid.svelte

<p>
<em>*</em> <a href="https://svelte.dev/docs/svelte-components#script-4-prefix-stores-with-$-to-access-their-values">
svelte store variables</a> - when reading the value, add <em>$</em> to the name, e.g.
<em>$FOCUSABLE_SELECTOR</em>.
</p>


<script>
import FocusableSelector from './prop-focusable-selector.svelte';
import PrefersDark from './prop-prefers-dark.svelte';
import Animate from './fn-animate.svelte';
import Blink from './fn-blink.svelte';
import DeepCopy from './fn-deep-copy.svelte';
import Debounce from './fn-debounce.svelte';
import Throttle from './fn-throttle.svelte';
import Empty from './fn-empty.svelte';
import Fuzzy from './fn-fuzzy.svelte';
import Guid from './fn-guid.svelte';
import GetMouseX from './fn-get-mouse-x.svelte';
import GetMouseY from './fn-get-mouse-y.svelte';
import GetMouseXY from './fn-get-mouse-xy.svelte';
import IsMobile from './fn-is-mobile.svelte';
import Pluck from './fn-pluck.svelte';
import RoundAmount from './fn-round-amount.svelte';
import FormatDate from './fn-format-date.svelte';
import TimeAgo from './fn-time-ago.svelte';
import AlignItem from './fn-align-item.svelte';
import IsInScrollable from './fn-is-in-scrollable.svelte';
import * as Functions from './functions';
import * as Properties from './properties';
const props = Object.keys(Properties);
const fns = Object.keys(Functions);
</script>
19 changes: 0 additions & 19 deletions docs-src/components/utils/fn-get-mouse-xy.svelte.svelte

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">alignItem (config)</h3>
<h3 class="util" id="AlignItem">alignItem(config)</h3>
<p>Aligns an element to another element,
ensuring that the aligned element remains within the viewport.
</p>
Expand All @@ -13,8 +13,8 @@


<script>
import { API } from '../../api-table';
import { CodeExample } from '../../code-example';
import { API } from '../../../api-table';
import { CodeExample } from '../../../code-example';
const apiProps = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">animate(element, from, to, options?)</h3>
<h3 class="util" id="Animate">animate(element, from, to, options?)</h3>

<p>Animates an element from one state to another. Shortcut & wrapper for the native javascript animation.</p>

Expand All @@ -10,8 +10,8 @@


<script>
import { API } from '../../api-table';
import { CodeExample } from '../../code-example';
import { API } from '../../../api-table';
import { CodeExample } from '../../../code-example';
const apiProps = [
{ name: 'element', type: 'HTMLElement', description: 'An element that will be animated.' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">blink(element, duration = 160)</h3>
<h3 class="util" id="Blink">blink(element, duration = 160)</h3>
<p>Animates an element by changing its opacity from 0.5 to 1.</p>
<ul>
<li><em>element</em> - HTMLElement to animate
Expand All @@ -9,7 +9,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">debounce(fn, timeout = 300)</h3>
<h3 class="util" id="Debounce">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.
Expand All @@ -15,7 +15,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">deepCopy(object)</h3>
<h3 class="util" id="DeepCopy">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.
Expand All @@ -7,7 +7,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">empty(value)</h3>
<h3 class="util" id="Empty">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.
Expand All @@ -17,7 +17,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h3 class="util">formatDate (date)</h3>
<h3 class="util" id="FormatDate">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';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">fuzzy (haystack = '', needle = '')</h3>
<h3 class="util" id="Fuzzy">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.
Expand All @@ -11,7 +11,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h3 class="util">getMouseX (event)</h3>
<h3 class="util" id="GetMouseX">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';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
19 changes: 19 additions & 0 deletions docs-src/components/utils/functions/get-mouse-xy.svelte.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h3 class="util" id="GetMouseXY">getMouseXY(event)</h3>
<p>Returns the mouse XY position (as an array: [x, y]). 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);
});
&lt;/script>
`;
</script>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h3 class="util">getMouseY (event)</h3>
<h3 class="util" id="GetMouseY">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';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h3 class="util">guid ()</h3>
<h3 class="util" id="Guid">guid()</h3>
<p>Generates a globally unique identifier.</p>

<CodeExample nohr html="{example}" />


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
18 changes: 18 additions & 0 deletions docs-src/components/utils/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export { default as AlignItem } from './align-item.svelte';
export { default as Animate } from './animate.svelte';
export { default as Blink } from './blink.svelte';
export { default as Debounce } from './debounce.svelte';
export { default as DeepCopy } from './deep-copy.svelte';
export { default as Empty } from './empty.svelte';
export { default as FormatDate } from './format-date.svelte';
export { default as Fuzzy } from './fuzzy.svelte';
export { default as GetMouseX } from './get-mouse-x.svelte.svelte';
export { default as GetMouseXY } from './get-mouse-xy.svelte.svelte';
export { default as GetMouseY } from './get-mouse-y.svelte.svelte';
export { default as Guid } from './guid.svelte';
export { default as IsInScrollable } from './is-in-scrollable.svelte';
export { default as IsMobile } from './is-mobile.svelte';
export { default as Pluck } from './pluck.svelte';
export { default as RoundAmount } from './round-amount.svelte';
export { default as Throttle } from './throttle.svelte';
export { default as TimeAgo } from './time-ago.svelte';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 class="util">isInScrollable (node)</h3>
<h3 class="util" id="IsInScrollable">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>
Expand All @@ -10,7 +10,7 @@


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<h3 class="util">isMobile ()</h3>
<h3 class="util" id="IsMobile">isMobile()</h3>
<p>Checks if the current platform is mobile.</p>

<CodeExample nohr html="{example}" />


<script>
import { CodeExample } from '../../code-example';
import { CodeExample } from '../../../code-example';
const example = `
<script>
const mob = isMobile();
console.log(mob);
console.log(mob); // false
&lt;/script>
`;
Expand Down
Loading

0 comments on commit adf3eda

Please sign in to comment.