@lynx-js/lynx-ui-switch 3.137.0 → 3.142.0
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,21 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-switch
|
|
2
2
|
|
|
3
|
+
## 3.142.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Accept React 18 and newer types. ReactLynx still defines the compatible versions for each app. ([#383](https://github.com/lynx-family/lynx-ui/pull/383))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`49cb3c5`](https://github.com/lynx-family/lynx-ui/commit/49cb3c5b20d9346ff0f8b314367b4c8e354d195d)]:
|
|
10
|
+
- @lynx-js/lynx-ui-common@3.142.0
|
|
11
|
+
|
|
12
|
+
## 3.139.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`1a4ad19`](https://github.com/lynx-family/lynx-ui/commit/1a4ad190993d57425b4c377a7dd63882cc65a8d2)]:
|
|
17
|
+
- @lynx-js/lynx-ui-common@3.139.0
|
|
18
|
+
|
|
3
19
|
## 3.137.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from '@lynx-js/react';
|
|
2
2
|
import type { ComponentBasicProps } from '@lynx-js/lynx-ui-common';
|
|
3
3
|
import type { ViewProps } from '@lynx-js/types';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Props for the Switch component.
|
|
5
6
|
* @zh Switch 组件的属性
|
|
6
7
|
*/
|
|
7
8
|
export interface SwitchProps extends ComponentBasicProps {
|
|
@@ -54,7 +55,8 @@ export interface SwitchProps extends ComponentBasicProps {
|
|
|
54
55
|
*/
|
|
55
56
|
children?: ReactNode | ((status: SwitchRenderProps) => ReactNode);
|
|
56
57
|
}
|
|
57
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Render state props passed to custom Switch content.
|
|
58
60
|
* @zh Switch 自定义渲染的状态属性
|
|
59
61
|
*/
|
|
60
62
|
export interface SwitchRenderProps {
|
|
@@ -83,9 +85,9 @@ export interface SwitchRenderProps {
|
|
|
83
85
|
/**
|
|
84
86
|
* UI variants applied by Switch based on render state.
|
|
85
87
|
* Use them as CSS selectors to style different states.
|
|
86
|
-
* @zh Switch 根据状态注入的
|
|
88
|
+
* @zh Switch 根据状态注入的 UI variants,可用于 CSS selector 按状态定制样式。
|
|
87
89
|
*/
|
|
88
|
-
export interface
|
|
90
|
+
export interface SwitchUIVariants {
|
|
89
91
|
/**
|
|
90
92
|
* Applied when `status.active` is true.
|
|
91
93
|
* @zh 当 status.active 为 true 时生效,可用于 `.ui-active { ... }`。
|
|
@@ -102,6 +104,22 @@ export interface SwitchUiVariants {
|
|
|
102
104
|
*/
|
|
103
105
|
'ui-disabled'?: boolean;
|
|
104
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* UI variants exposed by SwitchTrack.
|
|
109
|
+
* @zh SwitchTrack 暴露的 UI variants。
|
|
110
|
+
*/
|
|
111
|
+
export interface SwitchTrackUIVariants extends SwitchUIVariants {
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* UI variants exposed by SwitchThumb.
|
|
115
|
+
* @zh SwitchThumb 暴露的 UI variants。
|
|
116
|
+
*/
|
|
117
|
+
export interface SwitchThumbUIVariants extends SwitchUIVariants {
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated Use `SwitchUIVariants` instead.
|
|
121
|
+
*/
|
|
122
|
+
export type SwitchUiVariants = SwitchUIVariants;
|
|
105
123
|
/**
|
|
106
124
|
* The thumb of the Switch.
|
|
107
125
|
* The draggable/clickable handle that toggles the state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],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;IAEtB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;CAAG;AAElE;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;CAAG;AAElE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAA;AAE/C;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAC3D;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAC3D;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-press-tap.d.ts","sourceRoot":"","sources":["../src/use-press-tap.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-press-tap.d.ts","sourceRoot":"","sources":["../src/use-press-tap.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKhD,UAAU,sBAAuB,SAAQ,UAAU,CAAC,OAAO,iBAAiB,CAAC;IAC3E,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAA;CACjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,EAAE,QAAgB,EAAE,KAAK,EAAE,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAA;CAAO,GAC3E,sBAAsB,CA4BxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-press-tap.jsx","sources":["../src/use-press-tap.ts"],"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 { useState } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { TouchEvent } from '@lynx-js/types'\n\nimport { useEffectEvent } from './use-effect-event'\n\ninterface UsePressTapReturnValue extends ReturnType<typeof useTouchEmulation> {\n pressed: boolean\n bindtap: (e: TouchEvent) => void\n}\n\n/**\n * usePressTap\n *\n * Hook that provides press/tap interaction state similar to <button>.\n *\n * - When `disabled` is true:\n * - The element cannot become active.\n * - No tap will fire.\n * - If the element becomes disabled during a press:\n * - The active state is cleared immediately.\n */\nexport function usePressTap(\n { disabled = false, onTap }: { disabled?: boolean, onTap?: () => void } = {},\n): UsePressTapReturnValue {\n const [pressed, setPressed] = useState(false)\n\n const press =
|
|
1
|
+
{"version":3,"file":"use-press-tap.jsx","sources":["../src/use-press-tap.ts"],"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 { useState } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { TouchEvent } from '@lynx-js/types'\n\n// This local helper is a stable callback, not React's restricted Effect Event.\nimport { useEffectEvent as useStableCallback } from './use-effect-event'\n\ninterface UsePressTapReturnValue extends ReturnType<typeof useTouchEmulation> {\n pressed: boolean\n bindtap: (e: TouchEvent) => void\n}\n\n/**\n * usePressTap\n *\n * Hook that provides press/tap interaction state similar to <button>.\n *\n * - When `disabled` is true:\n * - The element cannot become active.\n * - No tap will fire.\n * - If the element becomes disabled during a press:\n * - The active state is cleared immediately.\n */\nexport function usePressTap(\n { disabled = false, onTap }: { disabled?: boolean, onTap?: () => void } = {},\n): UsePressTapReturnValue {\n const [pressed, setPressed] = useState(false)\n\n const press = useStableCallback(() => {\n if (disabled) return\n setPressed(true)\n })\n\n const reset = useStableCallback(() => {\n setPressed(false)\n })\n\n const handleTap = useStableCallback(() => {\n if (disabled) return\n onTap?.()\n })\n\n const touchHandlers = useTouchEmulation({\n onTouchStart: press,\n onTouchEnd: reset,\n onTouchCancel: reset,\n })\n\n return {\n pressed,\n bindtap: handleTap,\n ...touchHandlers,\n }\n}\n"],"names":["usePressTap","disabled","onTap","pressed","setPressed","useState","press","useStableCallback","reset","handleTap","touchHandlers","useTouchEmulation"],"mappings":";;;AA4BO,SAASA,YACd,EAAEC,WAAW,KAAK,EAAEC,KAAK,EAA8C,GAAG,CAAC,CAAC;IAE5E,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAS;IAEvC,MAAMC,QAAQC,eAAkB;QAC9B,IAAIN,UAAU;QACdG,WAAW;IACb;IAEA,MAAMI,QAAQD,eAAkB;QAC9BH,WAAW;IACb;IAEA,MAAMK,YAAYF,eAAkB;QAClC,IAAIN,UAAU;QACdC;IACF;IAEA,MAAMQ,gBAAgBC,kBAAkB;QACtC,cAAcL;QACd,YAAYE;QACZ,eAAeA;IACjB;IAEA,OAAO;QACLL;QACA,SAASM;QACT,GAAGC,aAAa;IAClB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-switch",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.142.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@lynx-js/react-use": "0.2.2",
|
|
29
29
|
"clsx": "^2.1.1",
|
|
30
|
-
"@lynx-js/lynx-ui-common": "3.
|
|
30
|
+
"@lynx-js/lynx-ui-common": "3.142.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@lynx-js/react": "0.123.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@lynx-js/react": ">=0.100.0",
|
|
41
41
|
"@lynx-js/types": "*",
|
|
42
|
-
"@types/react": "
|
|
42
|
+
"@types/react": ">=18"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
package/src/types/index.docs.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type { ReactNode } from '@lynx-js/react'
|
|
|
7
7
|
import type { ComponentBasicProps } from '@lynx-js/lynx-ui-common'
|
|
8
8
|
import type { ViewProps } from '@lynx-js/types'
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Props for the Switch component.
|
|
11
12
|
* @zh Switch 组件的属性
|
|
12
13
|
*/
|
|
13
14
|
export interface SwitchProps extends ComponentBasicProps {
|
|
@@ -69,7 +70,8 @@ export interface SwitchProps extends ComponentBasicProps {
|
|
|
69
70
|
) => ReactNode)
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Render state props passed to custom Switch content.
|
|
73
75
|
* @zh Switch 自定义渲染的状态属性
|
|
74
76
|
*/
|
|
75
77
|
export interface SwitchRenderProps {
|
|
@@ -101,9 +103,9 @@ export interface SwitchRenderProps {
|
|
|
101
103
|
/**
|
|
102
104
|
* UI variants applied by Switch based on render state.
|
|
103
105
|
* Use them as CSS selectors to style different states.
|
|
104
|
-
* @zh Switch 根据状态注入的
|
|
106
|
+
* @zh Switch 根据状态注入的 UI variants,可用于 CSS selector 按状态定制样式。
|
|
105
107
|
*/
|
|
106
|
-
export interface
|
|
108
|
+
export interface SwitchUIVariants {
|
|
107
109
|
/**
|
|
108
110
|
* Applied when `status.active` is true.
|
|
109
111
|
* @zh 当 status.active 为 true 时生效,可用于 `.ui-active { ... }`。
|
|
@@ -123,6 +125,23 @@ export interface SwitchUiVariants {
|
|
|
123
125
|
'ui-disabled'?: boolean
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* UI variants exposed by SwitchTrack.
|
|
130
|
+
* @zh SwitchTrack 暴露的 UI variants。
|
|
131
|
+
*/
|
|
132
|
+
export interface SwitchTrackUIVariants extends SwitchUIVariants {}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* UI variants exposed by SwitchThumb.
|
|
136
|
+
* @zh SwitchThumb 暴露的 UI variants。
|
|
137
|
+
*/
|
|
138
|
+
export interface SwitchThumbUIVariants extends SwitchUIVariants {}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated Use `SwitchUIVariants` instead.
|
|
142
|
+
*/
|
|
143
|
+
export type SwitchUiVariants = SwitchUIVariants
|
|
144
|
+
|
|
126
145
|
/**
|
|
127
146
|
* The thumb of the Switch.
|
|
128
147
|
* The draggable/clickable handle that toggles the state.
|
package/src/use-press-tap.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { useState } from '@lynx-js/react'
|
|
|
7
7
|
import { useTouchEmulation } from '@lynx-js/react-use'
|
|
8
8
|
import type { TouchEvent } from '@lynx-js/types'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// This local helper is a stable callback, not React's restricted Effect Event.
|
|
11
|
+
import { useEffectEvent as useStableCallback } from './use-effect-event'
|
|
11
12
|
|
|
12
13
|
interface UsePressTapReturnValue extends ReturnType<typeof useTouchEmulation> {
|
|
13
14
|
pressed: boolean
|
|
@@ -30,16 +31,16 @@ export function usePressTap(
|
|
|
30
31
|
): UsePressTapReturnValue {
|
|
31
32
|
const [pressed, setPressed] = useState(false)
|
|
32
33
|
|
|
33
|
-
const press =
|
|
34
|
+
const press = useStableCallback(() => {
|
|
34
35
|
if (disabled) return
|
|
35
36
|
setPressed(true)
|
|
36
37
|
})
|
|
37
38
|
|
|
38
|
-
const reset =
|
|
39
|
+
const reset = useStableCallback(() => {
|
|
39
40
|
setPressed(false)
|
|
40
41
|
})
|
|
41
42
|
|
|
42
|
-
const handleTap =
|
|
43
|
+
const handleTap = useStableCallback(() => {
|
|
43
44
|
if (disabled) return
|
|
44
45
|
onTap?.()
|
|
45
46
|
})
|