Skip to content

Commit cacfab4

Browse files
authored
Merge pull request #766 from dcapslock/haptic
feat: Use haptic feedback 'light' on expander click
2 parents bfeccea + e232834 commit cacfab4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/ExpanderCard.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import { onMount } from 'svelte';
5757
import type { ExpanderConfig } from './configtype';
5858
import type { AnimationState } from './types';
59+
import { forwardHaptic } from './helpers/forward-haptic';
5960
6061
const {
6162
hass,
@@ -219,6 +220,7 @@
219220
}
220221
return false;
221222
}
223+
forwardHaptic(event.currentTarget as HTMLElement, 'light');
222224
toggleOpen();
223225
};
224226
@@ -250,6 +252,7 @@
250252
251253
const touchEnd = (event: TouchEvent) => {
252254
if (!isScrolling && touchElement === event.target && config['title-card-clickable']) {
255+
forwardHaptic(touchElement, 'light');
253256
toggleOpen();
254257
touchPreventClick = true;
255258
// A touch event may not always be followed by a click event so we set a timeout to reset

src/helpers/forward-haptic.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Allowed types are from iOS HIG.
2+
// https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/feedback/#haptics
3+
// Implementors on platforms other than iOS should attempt to match the patterns (shown in HIG) as closely as possible.
4+
export type HapticType = 'success' | 'warning' | 'failure' | 'light' | 'medium' | 'heavy' | 'selection' | 'none';
5+
6+
declare global {
7+
// for fire event
8+
interface HASSDomEvents {
9+
haptic: HapticType;
10+
}
11+
}
12+
13+
export const forwardHaptic = (node: HTMLElement, hapticType: HapticType) => {
14+
node.dispatchEvent?.(
15+
new CustomEvent('haptic',
16+
{ detail: hapticType, bubbles: true, composed: true }
17+
)
18+
);
19+
};

0 commit comments

Comments
 (0)