-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
+page.svelte
191 lines (186 loc) · 8.53 KB
/
+page.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<script lang="ts">
import DocsShell from '$lib/layouts/DocsShell/DocsShell.svelte';
import { DocsFeature, type DocsShellSettings } from '$lib/layouts/DocsShell/types';
import DocsPreview from '$lib/components/DocsPreview/DocsPreview.svelte';
import { getImageLink } from '$lib/images';
// Components
import { RadioGroup, RadioItem, CodeBlock } from '@skeletonlabs/skeleton';
// Actions
import { filter } from '@skeletonlabs/skeleton';
// Filter SVGs
import { Apollo, BlueNight, Emerald, GreenFall, Noir, NoirLight, Rustic, Summer84, XPro, TabGroup, Tab } from '@skeletonlabs/skeleton';
// Docs Shell
const settings: DocsShellSettings = {
feature: DocsFeature.Action,
name: 'Filters',
description: 'Apply Instagram-like filter effects to images.',
imports: ['filter'],
source: 'packages/skeleton/src/lib/actions/Filters',
parameters: [['<code class="code">(default)</code>', 'string', '-', '-', 'The name of the filter, such as "Apollo".']]
};
// Local
let activeImg: '8vKVlNIbAc4' | 'YOErFW8AfkI' | 'z_X0PxmBuIQ' = 'YOErFW8AfkI';
$: imgPlaceholder = getImageLink({ id: activeImg, h: 200, w: 200 });
let method = 0;
</script>
<!--
NOTE:
We keep filters localized since we
only utilize theme on this doc page.
-->
<Apollo />
<BlueNight />
<Emerald />
<GreenFall />
<Noir />
<NoirLight />
<Rustic />
<Summer84 />
<XPro />
<DocsShell {settings}>
<!-- Slot: Sandbox -->
<svelte:fragment slot="sandbox">
<DocsPreview>
<svelte:fragment slot="preview">
<section class="p-4 grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4">
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} alt="example" />
<span class="badge variant-soft">Original</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#Emerald'} alt="example" />
<span class="badge variant-soft">Emerald</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#BlueNight'} alt="example" />
<span class="badge variant-soft">BlueNight</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#XPro'} alt="example" />
<span class="badge variant-soft">XPro</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#Summer84'} alt="example" />
<span class="badge variant-soft">Summer84</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#Rustic'} alt="example" />
<span class="badge variant-soft">Rustic</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#Apollo'} alt="example" />
<span class="badge variant-soft">Apollo</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#GreenFall'} alt="example" />
<span class="badge variant-soft">GreenFall</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#Noir'} alt="example" />
<span class="badge variant-soft">Noir</span>
</div>
<div class="flex flex-col items-center space-y-4 overflow-hidden">
<img class="aspect-square w-full rounded-container-token" src={imgPlaceholder} use:filter={'#NoirLight'} alt="example" />
<span class="badge variant-soft">NoirLight</span>
</div>
</section>
</svelte:fragment>
<svelte:fragment slot="footer">
<div class="text-center">
<RadioGroup>
<RadioItem bind:group={activeImg} name="source" value="YOErFW8AfkI">1</RadioItem>
<RadioItem bind:group={activeImg} name="source" value="z_X0PxmBuIQ">2</RadioItem>
<RadioItem bind:group={activeImg} name="source" value="8vKVlNIbAc4">3</RadioItem>
</RadioGroup>
</div>
</svelte:fragment>
<svelte:fragment slot="source">
<p>Import the filter and each filter component you wish to use.</p>
<CodeBlock language="ts" code={`import { filter, Emerald, BlueNight /* ... */ } from '@skeletonlabs/skeleton';`} />
<p>Implement each filter component. For global scope add these to your root layout.</p>
<CodeBlock language="html" code={`<Emerald />\n<BlueNight />`} />
<p>Apply the filter to your desired element.</p>
<CodeBlock language="html" code={`<img ... use:filter={'#Emerald'} />`} />
</svelte:fragment>
</DocsPreview>
</svelte:fragment>
<!-- Slot: Usage -->
<svelte:fragment slot="usage">
<section class="space-y-4">
<p>
Add each filter you plan to use within the scope of your filtered elements. To use globally throughout your application, add this to
your application's root layout. Avoid importing filters you are not using.
</p>
</section>
<section class="space-y-4">
<h2 class="h2">Applying a Filter</h2>
<p>Use either of the two methods below to apply your desired filter. <u>The hash mark is required</u>.</p>
<TabGroup regionPanel="space-y-4">
<Tab bind:group={method} name="method" value={0}>Via Action</Tab>
<Tab bind:group={method} name="method" value={1}>Via Attribute</Tab>
<!-- Tab Panels --->
<svelte:fragment slot="panel">
{#if method === 0}
<p>
Use the following <a class="anchor" href="https://svelte.dev/tutorial/actions" target="_blank" rel="noreferrer"
>Svelte action</a
> to filter any element. Pass the filter name as the only parameter.
</p>
<CodeBlock language="ts" code={`import { filter } from '@skeletonlabs/skeleton';`} />
<CodeBlock language="html" code={`<img src={myImageSrc} use:filter={'#BlueNight'}>`} />
{:else if method === 1}
<p>Alternatively you may apply filters using inline CSS. This is what the action is doing under the hood.</p>
<CodeBlock language="html" code={`<img src={myImageSrc} style="filter: url({'#Emerald'})">`} />
{/if}
</svelte:fragment>
</TabGroup>
</section>
<hr />
<section class="space-y-4">
<h2 class="h2">How It Works</h2>
<!-- prettier-ignore -->
<p>
This feature is enabled by the use of native browser <a class="anchor" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter" target="_blank" rel="noreferrer">SVG filters</a> via <a class="anchor" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix" target="_blank" rel="noreferrer">feColorMatrix</a> transformations.
</p>
</section>
<section class="flex flex-col md:flex-row justify-between items-start md:items-center space-y-4 md:space-y-0 md:space-x-4">
<div class="space-y-2">
<h2 class="h2">Create a Custom Filter</h2>
<!-- prettier-ignore -->
<p>
Use this tool by <a class="anchor" href="https://twitter.com/rikschennink/" target="_blank" rel="noreferrer">Rik Schennink</a> to easily generate your own custom filters.
</p>
</div>
<a class="btn variant-filled-secondary" href="https://fecolormatrix.com/" target="_blank" rel="noreferrer">
<span>Create a Filter</span>
<span><i class="fa-solid fa-up-right-from-square"></i></span>
</a>
</section>
<hr />
<section class="space-y-4">
<h2 class="h2">Browser Support</h2>
<!-- prettier-ignore -->
<p>
Please be aware that <strong>SVG filters</strong> have limited support in Safari.
</p>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-center">
<div class="card p-2 !bg-green-500 text-black">
<h4 class="h4" data-toc-ignore>Chrome</h4>
<span>Full</span>
</div>
<div class="card p-2 !bg-green-500 text-black">
<h4 class="h4" data-toc-ignore>Edge</h4>
<span>Full</span>
</div>
<div class="card p-2 !bg-green-500 text-black">
<h4 class="h4" data-toc-ignore>Firefox</h4>
<span>Full</span>
</div>
<div class="card p-2 !bg-yellow-500 text-black">
<h4 class="h4" data-toc-ignore>Safari</h4>
<span>Partial</span>
</div>
</div>
</section>
</svelte:fragment>
</DocsShell>