@lynx-js/lynx-ui-button 3.131.0 → 3.133.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @lynx-js/lynx-ui-button
2
2
 
3
+ ## 3.133.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve Web and desktop touch compatibility by routing `onTouchStart`, ([#200](https://github.com/lynx-family/lynx-ui/pull/200))
8
+ `onTouchMove`, `onTouchEnd`, and `onTouchCancel` through shared touch
9
+ emulation.
10
+ - Updated dependencies [[`3932070`](https://github.com/lynx-family/lynx-ui/commit/393207073522e221a79e65c643df2afb329ec931)]:
11
+ - @lynx-js/lynx-ui-common@3.133.1
12
+
13
+ ## 3.133.0
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`85d2e9d`](https://github.com/lynx-family/lynx-ui/commit/85d2e9d12e9aeee3256856f1be0076524ddb7d8a)]:
18
+ - @lynx-js/lynx-ui-common@3.133.0
19
+
3
20
  ## 3.131.0
4
21
 
5
22
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,eAAO,MAAM,aAAa;YAChB,OAAO;cACL,OAAO;EAIjB,CAAA;AAEF,eAAO,MAAM,gBAAgB;YAPnB,OAAO;cACL,OAAO;CAM4C,CAAA;AAE/D,eAAO,MAAM,MAAM,GAAI,MAAM,WAAW,gCAyDvC,CAAA"}
1
+ {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,eAAO,MAAM,aAAa;YAChB,OAAO;cACL,OAAO;EAIjB,CAAA;AAEF,eAAO,MAAM,gBAAgB;YAPnB,OAAO;cACL,OAAO;CAM4C,CAAA;AAE/D,eAAO,MAAM,MAAM,GAAI,MAAM,WAAW,gCA6DvC,CAAA"}
package/dist/Button.jsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createContext, useContext, useMemo, useState } from "@lynx-js/react";
2
2
  import { useMemoizedFn } from "@lynx-js/lynx-ui-common";
3
+ import { useTouchEmulation } from "@lynx-js/react-use";
3
4
  import { clsx } from "clsx";
4
5
  const ButtonContext = createContext({
5
6
  active: false,
@@ -26,6 +27,11 @@ const Button = (prop)=>{
26
27
  if (disabled) return;
27
28
  onClick?.();
28
29
  });
30
+ const touchHandlers = useTouchEmulation({
31
+ onTouchStart: handleTouchStart,
32
+ onTouchEnd: handleTouchEnd,
33
+ onTouchCancel: handleTouchEnd
34
+ });
29
35
  const contextValue = useMemo(()=>({
30
36
  active: isEffectiveActive,
31
37
  disabled
@@ -34,7 +40,7 @@ const Button = (prop)=>{
34
40
  disabled
35
41
  ]);
36
42
  return <ButtonContext.Provider value={contextValue}>
37
- <view bindtap={handleTap} bindtouchstart={handleTouchStart} bindtouchend={handleTouchEnd} bindtouchcancel={handleTouchEnd} event-through={false} style={style} className={clsx(className, {
43
+ <view bindtap={handleTap} {...touchHandlers} event-through={false} style={style} className={clsx(className, {
38
44
  'ui-active': isEffectiveActive,
39
45
  'ui-disabled': disabled
40
46
  })} {...buttonProps}>
@@ -1 +1 @@
1
- {"version":3,"file":"Button.jsx","sources":["webpack://@lynx-js/lynx-ui-button/./src/Button.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useContext, useMemo, useState } from '@lynx-js/react'\n\nimport { useMemoizedFn } from '@lynx-js/lynx-ui-common'\nimport { clsx } from 'clsx'\n\nimport type { ButtonProps } from './types'\n\nexport const ButtonContext = createContext<{\n active: boolean\n disabled: boolean\n}>({\n active: false,\n disabled: false,\n})\n\nexport const useButtonContext = () => useContext(ButtonContext)\n\nexport const Button = (prop: ButtonProps) => {\n const {\n children,\n onClick,\n disabled = false,\n style,\n className,\n buttonProps,\n } = prop\n const [active, setActive] = useState(false)\n\n // Only when the button is active and not disabled, the active style will be applied\n const isEffectiveActive = active && !disabled\n\n const renderedChildren = typeof children === 'function'\n ? children({ active: isEffectiveActive, disabled })\n : children\n\n const handleTouchStart = useMemoizedFn(() => {\n if (disabled) return\n setActive(true)\n })\n\n const handleTouchEnd = useMemoizedFn(() => {\n setActive(false)\n if (disabled) return\n })\n\n const handleTap = useMemoizedFn(() => {\n if (disabled) return\n onClick?.()\n })\n\n const contextValue = useMemo(\n () => ({ active: isEffectiveActive, disabled }),\n [isEffectiveActive, disabled],\n )\n\n return (\n <ButtonContext.Provider value={contextValue}>\n <view\n bindtap={handleTap}\n bindtouchstart={handleTouchStart}\n bindtouchend={handleTouchEnd}\n bindtouchcancel={handleTouchEnd}\n event-through={false}\n style={style}\n className={clsx(className, {\n 'ui-active': isEffectiveActive,\n 'ui-disabled': disabled,\n })}\n {...buttonProps}\n >\n {renderedChildren}\n </view>\n </ButtonContext.Provider>\n )\n}\n"],"names":["ButtonContext","createContext","useButtonContext","useContext","Button","prop","children","onClick","disabled","style","className","buttonProps","active","setActive","useState","isEffectiveActive","renderedChildren","handleTouchStart","useMemoizedFn","handleTouchEnd","handleTap","contextValue","useMemo","view","clsx"],"mappings":";;;AAWO,MAAMA,gBAAgBC,cAG1B;IACD,QAAQ;IACR,UAAU;AACZ;AAEO,MAAMC,mBAAmB,IAAMC,WAAWH;AAE1C,MAAMI,SAAS,CAACC;IACrB,MAAM,EACJC,QAAQ,EACRC,OAAO,EACPC,WAAW,KAAK,EAChBC,KAAK,EACLC,SAAS,EACTC,WAAW,EACZ,GAAGN;IACJ,MAAM,CAACO,QAAQC,UAAU,GAAGC,SAAS;IAGrC,MAAMC,oBAAoBH,UAAU,CAACJ;IAErC,MAAMQ,mBAAmB,AAAoB,cAApB,OAAOV,WAC5BA,SAAS;QAAE,QAAQS;QAAmBP;IAAS,KAC/CF;IAEJ,MAAMW,mBAAmBC,cAAc;QACrC,IAAIV,UAAU;QACdK,UAAU;IACZ;IAEA,MAAMM,iBAAiBD,cAAc;QACnCL,UAAU;QACV,IAAIL,UAAU;IAChB;IAEA,MAAMY,YAAYF,cAAc;QAC9B,IAAIV,UAAU;QACdD;IACF;IAEA,MAAMc,eAAeC,QACnB,IAAO;YAAE,QAAQP;YAAmBP;QAAS,IAC7C;QAACO;QAAmBP;KAAS;IAG/B,QACGR,cAAc,SAAS,OAAOqB,cAAc;MAC3C,CAACE,KACC,SAASH,WACT,gBAAgBH,kBAChB,cAAcE,gBACd,iBAAiBA,gBACjB,eAAe,OACf,OAAOV,OACP,WAAWe,KAAKd,WAAW;QACzB,aAAaK;QACb,eAAeP;IACjB,KACC,GAAGG,WAAW,EAChB;QACC,CAACK,iBAAiB;MACpB,EAAEO,KAAK;IACT,EAAEvB,cAAc;AAEpB"}
1
+ {"version":3,"file":"Button.jsx","sources":["webpack://@lynx-js/lynx-ui-button/./src/Button.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useContext, useMemo, useState } from '@lynx-js/react'\n\nimport { useMemoizedFn } from '@lynx-js/lynx-ui-common'\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport { clsx } from 'clsx'\n\nimport type { ButtonProps } from './types'\n\nexport const ButtonContext = createContext<{\n active: boolean\n disabled: boolean\n}>({\n active: false,\n disabled: false,\n})\n\nexport const useButtonContext = () => useContext(ButtonContext)\n\nexport const Button = (prop: ButtonProps) => {\n const {\n children,\n onClick,\n disabled = false,\n style,\n className,\n buttonProps,\n } = prop\n const [active, setActive] = useState(false)\n\n // Only when the button is active and not disabled, the active style will be applied\n const isEffectiveActive = active && !disabled\n\n const renderedChildren = typeof children === 'function'\n ? children({ active: isEffectiveActive, disabled })\n : children\n\n const handleTouchStart = useMemoizedFn(() => {\n if (disabled) return\n setActive(true)\n })\n\n const handleTouchEnd = useMemoizedFn(() => {\n setActive(false)\n if (disabled) return\n })\n\n const handleTap = useMemoizedFn(() => {\n if (disabled) return\n onClick?.()\n })\n\n const touchHandlers = useTouchEmulation({\n onTouchStart: handleTouchStart,\n onTouchEnd: handleTouchEnd,\n onTouchCancel: handleTouchEnd,\n })\n\n const contextValue = useMemo(\n () => ({ active: isEffectiveActive, disabled }),\n [isEffectiveActive, disabled],\n )\n\n return (\n <ButtonContext.Provider value={contextValue}>\n <view\n bindtap={handleTap}\n {...touchHandlers}\n event-through={false}\n style={style}\n className={clsx(className, {\n 'ui-active': isEffectiveActive,\n 'ui-disabled': disabled,\n })}\n {...buttonProps}\n >\n {renderedChildren}\n </view>\n </ButtonContext.Provider>\n )\n}\n"],"names":["ButtonContext","createContext","useButtonContext","useContext","Button","prop","children","onClick","disabled","style","className","buttonProps","active","setActive","useState","isEffectiveActive","renderedChildren","handleTouchStart","useMemoizedFn","handleTouchEnd","handleTap","touchHandlers","useTouchEmulation","contextValue","useMemo","view","clsx"],"mappings":";;;;AAYO,MAAMA,gBAAgBC,cAG1B;IACD,QAAQ;IACR,UAAU;AACZ;AAEO,MAAMC,mBAAmB,IAAMC,WAAWH;AAE1C,MAAMI,SAAS,CAACC;IACrB,MAAM,EACJC,QAAQ,EACRC,OAAO,EACPC,WAAW,KAAK,EAChBC,KAAK,EACLC,SAAS,EACTC,WAAW,EACZ,GAAGN;IACJ,MAAM,CAACO,QAAQC,UAAU,GAAGC,SAAS;IAGrC,MAAMC,oBAAoBH,UAAU,CAACJ;IAErC,MAAMQ,mBAAmB,AAAoB,cAApB,OAAOV,WAC5BA,SAAS;QAAE,QAAQS;QAAmBP;IAAS,KAC/CF;IAEJ,MAAMW,mBAAmBC,cAAc;QACrC,IAAIV,UAAU;QACdK,UAAU;IACZ;IAEA,MAAMM,iBAAiBD,cAAc;QACnCL,UAAU;QACV,IAAIL,UAAU;IAChB;IAEA,MAAMY,YAAYF,cAAc;QAC9B,IAAIV,UAAU;QACdD;IACF;IAEA,MAAMc,gBAAgBC,kBAAkB;QACtC,cAAcL;QACd,YAAYE;QACZ,eAAeA;IACjB;IAEA,MAAMI,eAAeC,QACnB,IAAO;YAAE,QAAQT;YAAmBP;QAAS,IAC7C;QAACO;QAAmBP;KAAS;IAG/B,QACGR,cAAc,SAAS,OAAOuB,cAAc;MAC3C,CAACE,KACC,SAASL,YACR,GAAGC,aAAa,EACjB,eAAe,OACf,OAAOZ,OACP,WAAWiB,KAAKhB,WAAW;QACzB,aAAaK;QACb,eAAeP;IACjB,KACC,GAAGG,WAAW,EAChB;QACC,CAACK,iBAAiB;MACpB,EAAES,KAAK;IACT,EAAEzB,cAAc;AAEpB"}
@@ -59,4 +59,37 @@ export interface ButtonProps {
59
59
  */
60
60
  onClick?: () => void;
61
61
  }
62
+ /**
63
+ * The interactive status passed to Button's render-prop children.
64
+ * @zh 传入 Button render-prop children 的交互状态。
65
+ */
66
+ export interface ButtonRenderProps {
67
+ /**
68
+ * Whether the button is currently being pressed (and not disabled).
69
+ * @zh 按钮当前是否处于按下态(且未被禁用)。
70
+ */
71
+ active?: boolean;
72
+ /**
73
+ * Whether the button is disabled.
74
+ * @zh 按钮是否处于禁用态。
75
+ */
76
+ disabled?: boolean;
77
+ }
78
+ /**
79
+ * UI variants applied by Button based on its interactive status.
80
+ * Use them as CSS selectors to style different states.
81
+ * @zh Button 根据交互状态注入的 ui-variants,可用于 CSS selector 按状态定制样式。
82
+ */
83
+ export interface ButtonUiVariants {
84
+ /**
85
+ * Applied when `status.active` is true.
86
+ * @zh 当 status.active 为 true 时生效,可用于 `.ui-active { ... }`。
87
+ */
88
+ 'ui-active'?: boolean;
89
+ /**
90
+ * Applied when `status.disabled` is true.
91
+ * @zh 当 status.disabled 为 true 时生效,可用于 `.ui-disabled { ... }`。
92
+ */
93
+ 'ui-disabled'?: boolean;
94
+ }
62
95
  //# sourceMappingURL=index.docs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE9D;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;;OAOG;IACH,QAAQ,CAAC,EACL,SAAS,GACT,CAAC,CACD,KAAK,EAAE;QACL,MAAM,EAAE,OAAO,CAAA;QACf,QAAQ,EAAE,OAAO,CAAA;KAClB,KACE,SAAS,CAAC,CAAA;IACjB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB"}
1
+ {"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE9D;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;;OAOG;IACH,QAAQ,CAAC,EACL,SAAS,GACT,CAAC,CACD,KAAK,EAAE;QACL,MAAM,EAAE,OAAO,CAAA;QACf,QAAQ,EAAE,OAAO,CAAA;KAClB,KACE,SAAS,CAAC,CAAA;IACjB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-button",
3
- "version": "3.131.0",
3
+ "version": "3.133.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -25,11 +25,12 @@
25
25
  "dist/**"
26
26
  ],
27
27
  "dependencies": {
28
+ "@lynx-js/react-use": "0.1.3",
28
29
  "clsx": "^2.1.1",
29
- "@lynx-js/lynx-ui-common": "3.131.0"
30
+ "@lynx-js/lynx-ui-common": "3.133.1"
30
31
  },
31
32
  "devDependencies": {
32
- "@lynx-js/react": "0.113.0",
33
+ "@lynx-js/react": "0.114.0",
33
34
  "@lynx-js/types": "3.6.0",
34
35
  "@rslib/core": "^0.16.0",
35
36
  "@types/react": "^18.3.8",
package/src/Button.tsx CHANGED
@@ -5,6 +5,7 @@
5
5
  import { createContext, useContext, useMemo, useState } from '@lynx-js/react'
6
6
 
7
7
  import { useMemoizedFn } from '@lynx-js/lynx-ui-common'
8
+ import { useTouchEmulation } from '@lynx-js/react-use'
8
9
  import { clsx } from 'clsx'
9
10
 
10
11
  import type { ButtonProps } from './types'
@@ -52,6 +53,12 @@ export const Button = (prop: ButtonProps) => {
52
53
  onClick?.()
53
54
  })
54
55
 
56
+ const touchHandlers = useTouchEmulation({
57
+ onTouchStart: handleTouchStart,
58
+ onTouchEnd: handleTouchEnd,
59
+ onTouchCancel: handleTouchEnd,
60
+ })
61
+
55
62
  const contextValue = useMemo(
56
63
  () => ({ active: isEffectiveActive, disabled }),
57
64
  [isEffectiveActive, disabled],
@@ -61,9 +68,7 @@ export const Button = (prop: ButtonProps) => {
61
68
  <ButtonContext.Provider value={contextValue}>
62
69
  <view
63
70
  bindtap={handleTap}
64
- bindtouchstart={handleTouchStart}
65
- bindtouchend={handleTouchEnd}
66
- bindtouchcancel={handleTouchEnd}
71
+ {...touchHandlers}
67
72
  event-through={false}
68
73
  style={style}
69
74
  className={clsx(className, {
@@ -69,3 +69,40 @@ export interface ButtonProps {
69
69
  */
70
70
  onClick?: () => void
71
71
  }
72
+
73
+ /**
74
+ * The interactive status passed to Button's render-prop children.
75
+ * @zh 传入 Button render-prop children 的交互状态。
76
+ */
77
+ export interface ButtonRenderProps {
78
+ /**
79
+ * Whether the button is currently being pressed (and not disabled).
80
+ * @zh 按钮当前是否处于按下态(且未被禁用)。
81
+ */
82
+ active?: boolean
83
+
84
+ /**
85
+ * Whether the button is disabled.
86
+ * @zh 按钮是否处于禁用态。
87
+ */
88
+ disabled?: boolean
89
+ }
90
+
91
+ /**
92
+ * UI variants applied by Button based on its interactive status.
93
+ * Use them as CSS selectors to style different states.
94
+ * @zh Button 根据交互状态注入的 ui-variants,可用于 CSS selector 按状态定制样式。
95
+ */
96
+ export interface ButtonUiVariants {
97
+ /**
98
+ * Applied when `status.active` is true.
99
+ * @zh 当 status.active 为 true 时生效,可用于 `.ui-active { ... }`。
100
+ */
101
+ 'ui-active'?: boolean
102
+
103
+ /**
104
+ * Applied when `status.disabled` is true.
105
+ * @zh 当 status.disabled 为 true 时生效,可用于 `.ui-disabled { ... }`。
106
+ */
107
+ 'ui-disabled'?: boolean
108
+ }