Skip to content

Commit 6339313

Browse files
committed
feat(features): useSize and useIntersection examples
1 parent faa4a16 commit 6339313

File tree

11 files changed

+116
-53
lines changed

11 files changed

+116
-53
lines changed

src/components/ExampleBind.vue

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<section
33
class="
44
mx-auto with-max-w flex flex-col gap-7 p-6 rounded-4 shadow-4
5-
bg-primary-10 text-primary-100 dork:bg-primary-gray-80
5+
bg-primary-10 dork:bg-primary-gray-110
66
"
77
>
88
<section>
9-
<span class="preexisting-class" ref="example">👉 Inspect this <code :class="store.statuses.darkTheme === 'enabled' ? 'bg-primary-gray-70' : 'bg-primary-10'">&lt;span&gt;</code> in devtools 👈</span>
9+
<span class="preexisting-class" ref="example">👉 Inspect this <code>&lt;span&gt;</code> in devtools 👈</span>
1010
</section>
1111
<section class="flex flex-col gap-2">
12-
<label for="bind-example-ariaLabel-input">Edit the <code :class="store.statuses.darkTheme === 'enabled' ? 'bg-primary-gray-70' : 'bg-primary-10'">aria-label</code> dynamically:</label>
12+
<label for="bind-example-ariaLabel-input">Edit the <code>aria-label</code> dynamically:</label>
1313
<input
1414
id="bind-example-ariaLabel-input"
1515
type="text"
@@ -22,33 +22,29 @@
2222
/>
2323
</section>
2424
<section class="flex flex-col gap-2">
25-
<label for="bind-example-class-input">Edit the <code :class="store.statuses.darkTheme === 'enabled' ? 'bg-primary-gray-70' : 'bg-primary-10'">class</code> list dynamically:</label>
25+
<label for="bind-example-class-input">Edit the <code>class</code> list dynamically:</label>
2626
<input
2727
id="bind-example-class-input"
2828
type="text"
2929
v-model="classes"
30-
class="form -shadow-4"
31-
:class="[
32-
store.statuses.darkTheme === 'enabled'
33-
? 'bg-primary-gray-90 ring-primary-gray-80 focus:ring-primary-gray-40'
34-
: 'bg-white ring-primary-20 focus:ring-primary-70'
35-
36-
]"
30+
class="
31+
form -shadow-4
32+
bg-white ring-primary-20 focus:ring-primary-70
33+
dork:bg-primary-gray-90 dork:ring-primary-gray-80 dork:focus:ring-primary-gray-40
34+
"
3735
/>
3836
</section>
3937
<section class="flex flex-col gap-2">
40-
<label for="bind-example-backgroundColor-input">Edit the <code :class="store.statuses.darkTheme === 'enabled' ? 'bg-primary-gray-70' : 'bg-primary-10'">backgroundColor</code> dynamically:</label>
38+
<label for="bind-example-backgroundColor-input">Edit the <code>backgroundColor</code> dynamically:</label>
4139
<input
4240
id="bind-example-backgroundColor-input"
4341
type="text"
4442
v-model="backgroundColor"
45-
class="form -shadow-4"
46-
:class="[
47-
store.statuses.darkTheme === 'enabled'
48-
? 'bg-primary-gray-90 ring-primary-gray-80 focus:ring-primary-gray-40'
49-
: 'bg-white ring-primary-20 focus:ring-primary-70'
50-
51-
]"
43+
class="
44+
form -shadow-4
45+
bg-white ring-primary-20 focus:ring-primary-70
46+
dork:bg-primary-gray-90 dork:ring-primary-gray-80 dork:focus:ring-primary-gray-40
47+
"
5248
/>
5349
</section>
5450
</section>

src/components/ExampleUseFocus.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
2-
<div class="with-mt mx-auto w-full with-max-w flex-col center-all-x">
3-
<p>Status: <code>{{ focus.status.value }}</code></p>
2+
<div class="mx-auto w-full with-max-w flex-col center-all-x">
3+
<p class="text-3">Focus this element:</p>
44
<div
55
:ref="api.ref()"
66
tabindex="0"
@@ -9,6 +9,7 @@
99
focus.is.focused() ? 'bg-primary-40 dork:bg-primary-90' : 'bg-gray-30 dork:bg-primary-gray-100',
1010
]"
1111
/>
12+
<p>Status: <code>{{ focus.status.value }}</code></p>
1213
</div>
1314
</template>
1415

src/components/ExampleUseHover.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<template>
2-
<div class="with-mt mx-auto w-full with-max-w flex-col center-all-x">
3-
<p>Status: <code>{{ hover.status.value }}</code></p>
2+
<div class="mx-auto w-full with-max-w flex-col center-all-x">
3+
<p class="text-3">Hover this element:</p>
44
<div
55
:ref="api.ref()"
66
class="with-mt d-14 rounded-6"
77
:class="[
88
hover.is.hovered() ? 'bg-primary-40 dork:bg-primary-90' : 'bg-gray-30 dork:bg-primary-gray-100',
99
]"
1010
/>
11+
<p>Status: <code>{{ hover.status.value }}</code></p>
1112
</div>
1213
</template>
1314

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div class="mx-auto w-full with-max-w flex-col center-all-x">
3+
<p class="text-3">Scroll to bring the element into view:</p>
4+
<div class="
5+
with-mt w-16 h-20 p-4 scroll-p-4 overflow-y-scroll
6+
ring-sh-2-gray-30 dork:ring-primary-gray-100
7+
rounded-3 scrollbar-hide
8+
">
9+
<div
10+
:ref="api.ref()"
11+
class="my-22 d-14 rounded-6 bg-primary-40 dork:bg-primary-90"
12+
/>
13+
</div>
14+
<p>Status: <code>{{ intersection.status.value }}</code></p>
15+
</div>
16+
</template>
17+
18+
<script setup lang="tsx">
19+
import { useElementApi, useIntersection } from '@baleada/vue-features'
20+
21+
const api = useElementApi()
22+
const intersection = useIntersection(api.element)
23+
</script>

src/components/ExampleUseSize.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div class="mx-auto w-full with-max-w flex-col center-all-x">
3+
<p class="text-3">Resize this element:</p>
4+
<div
5+
:ref="api.ref()"
6+
class="
7+
with-mt
8+
rounded-6 bg-primary-40 dork:bg-primary-90
9+
overflow-scroll resize
10+
"
11+
style="width: 4rem; height: 4rem;"
12+
>
13+
</div>
14+
<p>Height: <code>{{ size.borderBox.value?.height }}</code>, Width: <code>{{ size.borderBox.value?.width }}</code></p>
15+
</div>
16+
</template>
17+
18+
<script setup lang="tsx">
19+
import { useElementApi, useSize } from '@baleada/vue-features'
20+
21+
const api = useElementApi()
22+
const size = useSize(api.element)
23+
</script>

src/components/LayoutArticleLinks.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<span class="flex flex-col gap-2 text-3">
33
<a
44
v-if="source"
5-
class="flex/2 center-all-y text-3"
5+
class="mr-auto flex/2 center-all-y text-3"
66
:href="source"
77
target="_blank"
88
>
@@ -11,7 +11,7 @@
1111
</a>
1212
<a
1313
v-if="tests"
14-
class="flex/2 center-all-y text-3"
14+
class="mr-auto flex/2 center-all-y text-3"
1515
:href="tests"
1616
target="_blank"
1717
>
@@ -20,7 +20,7 @@
2020
</a>
2121
<a
2222
v-if="stub"
23-
class="flex/2 center-all-y text-3"
23+
class="mr-auto flex/2 center-all-y text-3"
2424
:href="stub"
2525
target="_blank"
2626
>

src/components/LayoutExample.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<template>
2-
<p>
2+
<p class="flex">
33
<a
4-
class="flex/2 center-all-y text-3"
4+
class="mr-auto flex/2 center-all-y text-3"
55
:href="`https://github.com/baleada/docs/blob/main/src/components/${component}.vue`"
66
target="_blank"
77
>
88
<SimpleGitHub class="icon icon-btn duration-1" />
99
<span class="duration-1">Example source code</span>
1010
</a>
1111
</p>
12-
<component :is="component" />
12+
<div class="with-mt">
13+
<component :is="component" />
14+
</div>
1315
</template>
1416

1517
<script setup lang="tsx">
1618
import SimpleGitHub from '@simple-icons/github.svg'
17-
const props = defineProps<{ component: any }>()
18-
console.log(props)
19+
defineProps<{ component: any }>()
1920
</script>

src/composition/useStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ type Article = {
1313
summary?: string,
1414
image?: string,
1515
imageAlt?: string,
16+
source?: string | boolean,
1617
},
18+
source?: string,
19+
tests?: string,
20+
stub?: string,
1721
relativePath?: string
1822
}
1923

src/prose/features/04-extensions/intersection.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ publish: true
55
order: 0
66
---
77

8-
::: type="warning"
9-
Under construction 🚧
10-
:::
8+
`useIntersection` is an [extension](/docs/features/extensions-overview) that tracks whether or not an element has entered a viewport.
119

10+
Under the hood, `useIntersection` uses the `IntersectionObserver` API for performant intersection tracking.
1211

13-
`useIntersection` is an [extension](/docs/features/extensions-overview) that allows you to reactively track whether or not an element has entered a viewport.
1412

15-
::: type="info"
16-
Under the hood, `useIntersection` uses the `IntersectionObserver` API for performant intersection tracking.
13+
:::
14+
## Example
1715
:::
1816

17+
<LayoutExample component="ExampleUseIntersection" />
1918

19+
20+
21+
::: type="warning"
22+
Under construction 🚧
2023
:::
24+
25+
<!-- :::
2126
## Create visibility
2227
:::
2328
@@ -45,9 +50,9 @@ Instead of passing the unreliable DOM element to `options.observer.root`, you ca
4550
:::
4651
4752
:::
48-
```html
53+
```html -->
4954
<!-- MyComponent.vue -->
50-
<template>
55+
<!-- <template>
5156
<div ref="viewport">
5257
<div :ref="tablist.root.ref()">...</div>
5358
</div>
@@ -90,4 +95,4 @@ Here's a breakdown of that object:
9095
| `isVisible` | Ref (Boolean) | <p>A reactive reference to a Boolean describing the visibility of your element. `isVisible` is `true` when `status` is `visible`, and `false` when it's `invisible`.</p> |
9196
| `time` | Ref (DOMHighResTimestamp) | A reactive reference to the [time](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry/time) of the most recent change in visibility. |
9297
:::
93-
98+
-->

src/prose/features/04-extensions/size.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ publish: true
55
order: 0
66
---
77

8-
::: type="warning"
9-
Under construction 🚧
10-
:::
8+
`useSize` is an [extension](/docs/features/extensions-overview) that tracks the dimensions of an element, and whether that element's width is currently wider than certain breakpoints.
119

10+
Under the hood, `useSize` uses the `ResizeObserver` API for performant size tracking.
1211

13-
`useSize` is an [extension](/docs/features/extensions-overview) that allows you to reactively track the dimensions of an element, and whether that element's width is currently wider than certain breakpoints.
1412

15-
::: type="info"
16-
Under the hood, `useSize` uses the `ResizeObserver` API for performant dimension tracking.
1713
:::
14+
## Example
15+
:::
16+
17+
<LayoutExample component="ExampleUseSize" />
1818

1919

20+
::: type="warning"
21+
Under construction 🚧
2022
:::
23+
24+
25+
<!-- :::
2126
## Create size
2227
:::
2328
@@ -37,12 +42,12 @@ Here's a breakdown of the `useSize` options:
3742
| --- | --- | --- | --- | --- |
3843
| `breakpoints` | Object | no | See description | <p>An object specifying breakpoints for `useSize` to compare against. Each key should be the name of the breakpoint, and the value should be the width (Number) of that breakpoint, measured in pixels.</p><p>The keys of the default `breakpoints` object are `sm`, `md`, `lg`, `xl`, and `2xl`. The values of those keys are [the default TailwindCSS breakpoints](https://tailwindcss.com/docs/responsive-design).</p> |
3944
| `observe` | Object | no | none | The `options` parameter of the [Resize Observer's `observe` method](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe). |
40-
:::
45+
::: -->
4146

42-
:::
43-
```html
47+
<!-- :::
48+
```html -->
4449
<!-- MyComponent.vue -->
45-
<template>...</template>
50+
<!-- <template>...</template>
4651
4752
<script setup>
4853
import { computed } from 'vue'
@@ -89,9 +94,9 @@ If you stick with the default `breakpoints`, the properties of `breaks` will be
8994
You can use these values to, for example, swap out the `src` of an `img` element based on screen size, so that only the correct image for that screen size is loaded:
9095
9196
:::
92-
```html
97+
```html -->
9398
<!-- MyComponent.vue -->
94-
<style>
99+
<!-- <style>
95100
header {
96101
height: 100vw;
97102
width: 100vw;
@@ -127,4 +132,4 @@ const header = ref(null)
127132
const size = readonly(useSize(header))
128133
</script>
129134
```
130-
:::
135+
::: -->

0 commit comments

Comments
 (0)