@hzblj/kara-components 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +2 -1
  3. package/lib/module/atoms/icon/icon.android.js +1 -1
  4. package/lib/module/atoms/icon/icon.android.js.map +1 -1
  5. package/lib/module/atoms/icon/icon.ios.js +1 -1
  6. package/lib/module/atoms/icon/icon.ios.js.map +1 -1
  7. package/lib/module/atoms/pressable/pressable.js +1 -1
  8. package/lib/module/atoms/pressable/pressable.js.map +1 -1
  9. package/lib/module/atoms/rn-icon/index.js +1 -1
  10. package/lib/module/atoms/rn-icon/index.js.map +1 -1
  11. package/lib/module/atoms/rn-icon/rn-icon.js +26 -0
  12. package/lib/module/atoms/rn-icon/rn-icon.js.map +1 -0
  13. package/lib/module/atoms/segmented-control/segmented-control.android.js +6 -3
  14. package/lib/module/atoms/segmented-control/segmented-control.android.js.map +1 -1
  15. package/lib/module/atoms/slider/slider.android.js +1 -1
  16. package/lib/module/atoms/slider/slider.android.js.map +1 -1
  17. package/lib/module/atoms/switch/switch.android.js +1 -1
  18. package/lib/module/atoms/switch/switch.android.js.map +1 -1
  19. package/lib/module/glyph/rn-glyph.android.js +8 -3
  20. package/lib/module/glyph/rn-glyph.android.js.map +1 -1
  21. package/lib/module/index.js +0 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/molecules/navigation-bar/navigation-bar.android.js +1 -1
  24. package/lib/module/molecules/navigation-bar/navigation-bar.android.js.map +1 -1
  25. package/lib/module/molecules/navigation-bar/navigation-bar.ios.js +1 -1
  26. package/lib/module/molecules/navigation-bar/navigation-bar.ios.js.map +1 -1
  27. package/lib/module/organisms/context-menu/context-menu.android.js +1 -1
  28. package/lib/module/organisms/context-menu/context-menu.android.js.map +1 -1
  29. package/lib/module/organisms/context-menu/context-menu.ios.js +1 -1
  30. package/lib/module/organisms/context-menu/context-menu.ios.js.map +1 -1
  31. package/lib/module/organisms/fab-menu/fab-menu.ios.js +1 -1
  32. package/lib/module/organisms/fab-menu/fab-menu.ios.js.map +1 -1
  33. package/lib/module/organisms/swipe-actions/swipe-actions.ios.js +1 -1
  34. package/lib/module/organisms/swipe-actions/swipe-actions.ios.js.map +1 -1
  35. package/lib/typescript/atoms/icon/icon.types.d.ts +6 -15
  36. package/lib/typescript/atoms/pressable/pressable.types.d.ts +1 -1
  37. package/lib/typescript/atoms/rn-icon/rn-icon.d.ts +6 -1
  38. package/lib/typescript/index.d.ts +0 -1
  39. package/package.json +6 -4
  40. package/src/atoms/icon/icon.android.tsx +1 -1
  41. package/src/atoms/icon/icon.ios.tsx +1 -1
  42. package/src/atoms/icon/icon.types.ts +6 -15
  43. package/src/atoms/pressable/pressable.tsx +1 -1
  44. package/src/atoms/pressable/pressable.types.ts +1 -2
  45. package/src/atoms/rn-icon/rn-icon.tsx +28 -0
  46. package/src/atoms/segmented-control/segmented-control.android.tsx +5 -3
  47. package/src/atoms/slider/slider.android.tsx +1 -1
  48. package/src/atoms/switch/switch.android.tsx +1 -1
  49. package/src/glyph/rn-glyph.android.tsx +14 -3
  50. package/src/index.ts +0 -1
  51. package/src/molecules/navigation-bar/navigation-bar.android.tsx +1 -1
  52. package/src/molecules/navigation-bar/navigation-bar.ios.tsx +1 -1
  53. package/src/organisms/context-menu/context-menu.android.tsx +1 -1
  54. package/src/organisms/context-menu/context-menu.ios.tsx +1 -1
  55. package/src/organisms/fab-menu/fab-menu.ios.tsx +1 -1
  56. package/src/organisms/swipe-actions/swipe-actions.ios.tsx +1 -1
  57. package/lib/module/atoms/rn-icon/rn-icon.android.js +0 -29
  58. package/lib/module/atoms/rn-icon/rn-icon.android.js.map +0 -1
  59. package/lib/module/atoms/rn-icon/rn-icon.ios.js +0 -29
  60. package/lib/module/atoms/rn-icon/rn-icon.ios.js.map +0 -1
  61. package/lib/module/haptics/haptics.js +0 -56
  62. package/lib/module/haptics/haptics.js.map +0 -1
  63. package/lib/module/haptics/index.js +0 -5
  64. package/lib/module/haptics/index.js.map +0 -1
  65. package/lib/module/haptics/use-haptic-feedback.js +0 -33
  66. package/lib/module/haptics/use-haptic-feedback.js.map +0 -1
  67. package/lib/typescript/atoms/rn-icon/rn-icon.ios.d.ts +0 -3
  68. package/lib/typescript/haptics/haptics.d.ts +0 -61
  69. package/lib/typescript/haptics/index.d.ts +0 -2
  70. package/lib/typescript/haptics/use-haptic-feedback.d.ts +0 -15
  71. package/src/atoms/rn-icon/rn-icon.android.tsx +0 -28
  72. package/src/atoms/rn-icon/rn-icon.ios.tsx +0 -28
  73. package/src/haptics/haptics.ts +0 -68
  74. package/src/haptics/index.ts +0 -2
  75. package/src/haptics/use-haptic-feedback.ts +0 -36
@@ -1,68 +0,0 @@
1
- import {HAPTICS, type Haptic, playHaptic, prepareHaptic} from '@hzblj/kara-native'
2
-
3
- export type {Haptic}
4
-
5
- export type HapticOptions = {
6
- /** iOS: scales an impact — `soft`, `light`, `medium`, `rigid`, `heavy` — from 0 to 1. Everything else ignores it. */
7
- intensity?: number
8
- }
9
-
10
- type HapticShorthands = {readonly [K in Haptic]: (options?: HapticOptions) => void}
11
-
12
- let enabled = true
13
-
14
- const play = (haptic: Haptic, options?: HapticOptions): void => {
15
- if (enabled) {
16
- playHaptic(haptic, options?.intensity)
17
- }
18
- }
19
-
20
- const prepare = (haptic: Haptic): void => {
21
- if (enabled) {
22
- prepareHaptic(haptic)
23
- }
24
- }
25
-
26
- const shorthands = Object.fromEntries(
27
- HAPTICS.map(haptic => [haptic, (options?: HapticOptions) => play(haptic, options)])
28
- ) as HapticShorthands
29
-
30
- /**
31
- * The platform's own haptic feedback, named for what happened: UIKit's feedback generators on iOS, the system's
32
- * `HapticFeedbackConstants` on Android — never a raw vibration. Both follow the user's system haptics setting, and
33
- * every call is synchronous, with nothing to await.
34
- *
35
- * ```ts
36
- * haptics.success() // a name you know: one function per haptic
37
- * haptics.play(haptic) // a name that arrives as data
38
- * haptics.light({intensity: 0.6}) // impacts scale on iOS
39
- * haptics.prepare('selection') // iOS: warm the Taptic Engine as a gesture begins
40
- * haptics.setEnabled(userPreference) // silences every kara haptic, the components' own too
41
- * ```
42
- *
43
- * - `selection` — a choice changed: a segment, a chip, a picker row.
44
- * - `tick` — one step of a continuous gesture: a slider detent, a scrubbed value.
45
- * - `toggleOn` / `toggleOff` — a switch flipped.
46
- * - `success` / `warning` / `error` — how a task ended. Android has no warning of its own; it plays a rejection.
47
- * - `longPress` / `dragStart` — a long press was recognised; an item lifted to be dragged.
48
- * - `thresholdActivate` / `thresholdDeactivate` — a gesture crossed its commit point, or went back over it.
49
- * - `keyPress` — a key of the app's own keypad.
50
- * - `soft`, `light`, `medium`, `rigid`, `heavy` — a collision none of the names above describes.
51
- *
52
- * On Android the names that came with Android 14's constants fall back to the nearest older feedback, so every name
53
- * plays on every version. Haptics are silent in a build without kara's native module.
54
- */
55
- export const haptics = {
56
- ...shorthands,
57
- /** Whether kara plays haptics — `true` until `setEnabled(false)`. */
58
- isEnabled: (): boolean => enabled,
59
- play,
60
- prepare,
61
- /**
62
- * Switches every kara haptic on or off, the ones its components play included — for an app's own "Haptics" setting.
63
- * Not persisted: call it at start-up with the stored preference. The system setting applies either way.
64
- */
65
- setEnabled: (value: boolean): void => {
66
- enabled = value
67
- },
68
- }
@@ -1,2 +0,0 @@
1
- export {type Haptic, type HapticOptions, haptics} from './haptics'
2
- export {type HapticResolver, useHapticFeedback} from './use-haptic-feedback'
@@ -1,36 +0,0 @@
1
- import {useEffect, useRef} from 'react'
2
-
3
- import {type Haptic, haptics} from './haptics'
4
-
5
- /** Picks the haptic for one change of a trigger — or none, to stay silent for that change. */
6
- export type HapticResolver<T> = (previous: T, next: T) => Haptic | false | null | undefined
7
-
8
- /**
9
- * Plays a haptic whenever `trigger` changes — never on mount — like SwiftUI's `sensoryFeedback(_:trigger:)`. Give it
10
- * a haptic, or a function of the previous and next value that picks one per change. Changes are compared with
11
- * `Object.is`, so a trigger is a primitive or a stable reference.
12
- *
13
- * ```ts
14
- * useHapticFeedback(tab, 'selection')
15
- * useHapticFeedback(quantity, (before, after) => (after > before ? 'tick' : 'soft'))
16
- * useHapticFeedback(payment.status, (_, status) => status === 'paid' ? 'success' : status === 'failed' && 'error')
17
- * ```
18
- */
19
- export const useHapticFeedback = <T>(trigger: T, feedback: Haptic | HapticResolver<T>): void => {
20
- const previous = useRef(trigger)
21
-
22
- useEffect(() => {
23
- const before = previous.current
24
-
25
- if (Object.is(before, trigger)) {
26
- return
27
- }
28
-
29
- previous.current = trigger
30
- const haptic = typeof feedback === 'function' ? feedback(before, trigger) : feedback
31
-
32
- if (haptic) {
33
- haptics.play(haptic)
34
- }
35
- }, [feedback, trigger])
36
- }