Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ripple function #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions kitchen-sink/svelte/pages/Ripple.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script>
import {
Page,
Navbar,
NavbarBackLink,
Card,
BlockTitle,
List,
ListItem,
Link,
Button,
touchRipple,
} from 'konsta/svelte';

const isPreview = document.location.href.includes('examplePreview');
</script>

<Page>
<Navbar title="Ripple action">
<svelte:fragment slot="left">
{#if !isPreview}
<NavbarBackLink onClick={() => history.back()} />
{/if}
</svelte:fragment>
</Navbar>

<BlockTitle withBlock={false}>Example on a card</BlockTitle>
<div use:touchRipple class="rounded-lg touch-ripple-primary">
<Card>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam illum
quam incidunt fugit! Voluptatum, harum. Voluptatem dolorem ex debitis
assumenda sed tempore vitae accusantium dolorum, fugit ea earum aliquid
placeat, deleniti eligendi ratione molestiae laudantium corrupti eaque
voluptatum eum iusto cumque obcaecati voluptatibus! Debitis suscipit, ut
alias non, numquam accusamus dignissimos ipsum accusantium aspernatur
dolor nemo esse quae officia quasi nostrum qui rerum ad ab assumenda iure
sed, voluptatibus minima omnis ex. Ex iusto molestiae, error maiores nisi
totam architecto saepe illum, beatae dicta eligendi explicabo magnam porro
temporibus unde numquam earum possimus nobis molestias fugit! Eligendi
dignissimos rerum iste?
</Card>
</div>

<BlockTitle withBlock={false}>With unapplied styles</BlockTitle>
<div use:touchRipple={false} class="rounded-lg touch-ripple-primary">
<Card>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam illum
quam incidunt fugit! Voluptatum, harum. Voluptatem dolorem ex debitis
assumenda sed tempore vitae accusantium dolorum, fugit ea earum aliquid
placeat, deleniti eligendi ratione molestiae laudantium corrupti eaque
voluptatum eum iusto cumque obcaecati voluptatibus! Debitis suscipit, ut
alias non, numquam accusamus dignissimos ipsum accusantium aspernatur
dolor nemo esse quae officia quasi nostrum qui rerum ad ab assumenda iure
sed, voluptatibus minima omnis ex. Ex iusto molestiae, error maiores nisi
totam architecto saepe illum, beatae dicta eligendi explicabo magnam porro
temporibus unde numquam earum possimus nobis molestias fugit! Eligendi
dignissimos rerum iste?
</Card>
</div>
</Page>

<style>
:global(.k-touch-ripple-wave) {
z-index: 10;
}
</style>
3 changes: 3 additions & 0 deletions kitchen-sink/svelte/routes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import ActionSheet from './pages/ActionSheet.svelte';
import Badge from './pages/Badge.svelte';
import Breadcrumbs from './pages/Breadcrumbs.svelte';
Expand All @@ -20,6 +21,7 @@ import Preloader from './pages/Preloader.svelte';
import Progressbar from './pages/Progressbar.svelte';
import Radio from './pages/Radio.svelte';
import RangeSlider from './pages/RangeSlider.svelte';
import Ripple from './pages/Ripple.svelte';
import SegmentedControl from './pages/SegmentedControl.svelte';
import SheetModal from './pages/SheetModal.svelte';
import Stepper from './pages/Stepper.svelte';
Expand Down Expand Up @@ -52,6 +54,7 @@ const pages = {
Progressbar,
Radio,
RangeSlider,
Ripple,
SegmentedControl,
SheetModal,
Stepper,
Expand Down
3 changes: 2 additions & 1 deletion src/svelte/konsta-svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare class KonstaProvider extends SvelteComponentTyped<
declare const useTheme: (
cb?: (newValue: 'material' | 'ios') => void
) => 'material' | 'ios';
declare const touchRipple: (node: HTMLElement, styles: boolean) => void;

// EXPORT_COMPONENTS
export { useTheme, KonstaProvider };
export { useTheme, touchRipple, KonstaProvider };
2 changes: 2 additions & 0 deletions src/svelte/konsta-svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ import Toolbar from './components/Toolbar.svelte';
// eslint-disable-next-line
import KonstaProvider from './shared/KonstaProvider.svelte';
import { useTheme } from './shared/use-theme.js';
import { touchRipple } from './shared/touch-ripple-action.js';

export {
// utils
KonstaProvider,
useTheme,
touchRipple,
// components
App,
Actions,
Expand Down
20 changes: 20 additions & 0 deletions src/svelte/shared/touch-ripple-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useTouchRipple } from './use-touch-ripple.js';

/**
* Svelte action to apply a ripple effect to a component.
* WARNING: Changes the position to relative and overflow to hidden, set styles to false to disable.
*
* @param {HTMLElement} node
* @param {boolean} styles
* @returns void
*/
export function touchRipple(node, styles = true) {
if (!node) return;
if (styles) {
node.style.position = 'relative';
node.style.overflow = 'hidden';
}
const el = { current: node };

useTouchRipple(el, true);
}