@lynx-js/lynx-ui-switch 3.133.1 → 3.135.4
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 +18 -0
- package/dist/index.jsx +1 -2
- package/dist/render.jsx.map +1 -1
- package/dist/switch.jsx.map +1 -1
- package/dist/types/index.docs.jsx +1 -0
- package/dist/types/index.jsx +1 -0
- package/dist/use-effect-event.jsx.map +1 -1
- package/dist/use-press-tap.jsx.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-switch
|
|
2
2
|
|
|
3
|
+
## 3.135.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Upgrade the Lynx and Rsbuild toolchain dependencies used to build lynx-ui packages. ([#233](https://github.com/lynx-family/lynx-ui/pull/233))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`753556b`](https://github.com/lynx-family/lynx-ui/commit/753556bc1acb77e05567aba3b8b5ab057b9f670b)]:
|
|
10
|
+
- @lynx-js/lynx-ui-common@3.135.4
|
|
11
|
+
|
|
12
|
+
## 3.135.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Update `@lynx-js/react-use` to 0.2.2. ([#228](https://github.com/lynx-family/lynx-ui/pull/228))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`44c1de6`](https://github.com/lynx-family/lynx-ui/commit/44c1de68cf47e03c5136431a9efea7cbee69e752)]:
|
|
19
|
+
- @lynx-js/lynx-ui-common@3.135.3
|
|
20
|
+
|
|
3
21
|
## 3.133.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.jsx
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { Switch, SwitchThumb, SwitchTrack };
|
|
1
|
+
export { Switch, SwitchThumb, SwitchTrack } from "./switch.jsx";
|
package/dist/render.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.jsx","sources":["
|
|
1
|
+
{"version":3,"file":"render.jsx","sources":["../src/render.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 type { ReactNode } from '@lynx-js/react'\n\nfunction render<T>(\n api: T,\n children: ((api: T) => ReactNode) | ReactNode,\n): ReactNode {\n return typeof children === 'function'\n ? (children as (api: T) => ReactNode)(api)\n : children\n}\n\nexport { render }\n"],"names":["render","api","children"],"mappings":"AAMA,SAASA,OACPC,GAAM,EACNC,QAA6C;IAE7C,OAAO,AAAoB,cAApB,OAAOA,WACTA,SAAmCD,OACpCC;AACN"}
|
package/dist/switch.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.jsx","sources":["
|
|
1
|
+
{"version":3,"file":"switch.jsx","sources":["../src/switch.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'\nimport type { ReactNode } from '@lynx-js/react'\n\nimport { clsx } from 'clsx'\n\nimport { render } from './render'\nimport type {\n SwitchProps,\n SwitchRenderProps,\n SwitchThumbProps,\n SwitchTrackProps,\n} from './types'\nimport { usePressTap } from './use-press-tap'\n\nconst SwitchContext = createContext<SwitchRenderProps>({\n checked: false,\n disabled: false,\n active: false,\n})\n\nfunction Switch({\n style,\n className,\n children,\n onChange,\n checked: checkedProp,\n defaultChecked = false,\n disabled = false,\n switchProps,\n}: SwitchProps): ReactNode {\n const isControlled = checkedProp !== undefined\n\n const [uncontrolledChecked, setUncontrolledChecked] = useState<boolean>(\n defaultChecked,\n )\n\n const checked = isControlled ? checkedProp : uncontrolledChecked\n\n const handleChange = () => {\n const next = !checked\n if (!isControlled) {\n setUncontrolledChecked(next)\n }\n onChange?.(next)\n }\n\n const { pressed, bindtap, ...touchHandlers } = usePressTap({\n disabled,\n onTap: handleChange,\n })\n\n const active = useMemo(() => pressed && !disabled, [pressed, disabled])\n\n const switchContextValue: SwitchRenderProps = useMemo(() => ({\n active,\n checked,\n disabled,\n }), [active, checked, disabled])\n\n return (\n <SwitchContext.Provider value={switchContextValue}>\n <view\n bindtap={bindtap}\n {...touchHandlers}\n event-through={false}\n style={style}\n className={clsx(className, {\n 'ui-active': active,\n 'ui-checked': checked,\n 'ui-disabled': disabled,\n })}\n {...switchProps}\n >\n {render<SwitchRenderProps>(switchContextValue, children)}\n </view>\n </SwitchContext.Provider>\n )\n}\n\nfunction SwitchThumb(props: SwitchThumbProps): ReactNode {\n const { children, className, style } = props\n const { active, checked, disabled } = useContext(SwitchContext)\n\n return (\n <view\n style={style}\n className={clsx(className, {\n 'ui-active': active,\n 'ui-checked': checked,\n 'ui-disabled': disabled,\n })}\n >\n {children}\n </view>\n )\n}\n\nfunction SwitchTrack(props: SwitchTrackProps): ReactNode {\n const { children, className, style } = props\n const { active, checked, disabled } = useContext(SwitchContext)\n\n return (\n <view\n style={style}\n className={clsx(className, {\n 'ui-active': active,\n 'ui-checked': checked,\n 'ui-disabled': disabled,\n })}\n >\n {children}\n </view>\n )\n}\n\nexport { Switch, SwitchThumb, SwitchTrack }\n"],"names":["SwitchContext","createContext","Switch","style","className","children","onChange","checkedProp","defaultChecked","disabled","switchProps","isControlled","undefined","uncontrolledChecked","setUncontrolledChecked","useState","checked","handleChange","next","pressed","bindtap","touchHandlers","usePressTap","active","useMemo","switchContextValue","view","clsx","render","SwitchThumb","props","useContext","SwitchTrack"],"mappings":";;;;AAkBA,MAAMA,gBAAgBC,cAAiC;IACrD,SAAS;IACT,UAAU;IACV,QAAQ;AACV;AAEA,SAASC,OAAO,EACdC,KAAK,EACLC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACR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ED,KAAK,EAAE,GAAG2B;IACvC,MAAM,EAAEP,MAAM,EAAEP,OAAO,EAAEP,QAAQ,EAAE,GAAGsB,WAAW/B;IAEjD,QACG0B,KACC,OAAOvB,OACP,WAAWwB,KAAKvB,WAAW;QACzB,aAAamB;QACb,cAAcP;QACd,eAAeP;IACjB,IACD;MACC,CAACJ,SAAS;IACZ,EAAEqB;AAEN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types/index.jsx
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-effect-event.jsx","sources":["
|
|
1
|
+
{"version":3,"file":"use-effect-event.jsx","sources":["../src/use-effect-event.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 { useEffect, useMemo, useRef } from '@lynx-js/react'\n\n/**\n * useEffectEvent\n *\n * - Internally stores the latest `fn` in a ref, updated via useEffect.\n * - Returns a memoized proxy function that delegates calls to `ref.current`.\n * - Useful when extracting a non-reactive function dependency out of the reactive Effect around it.\n *\n * @param fn The callback function to be stabilized.\n * @returns A stable function that always invokes the latest `fn`.\n */\n\nfunction useEffectEvent<TArgs extends unknown[]>(\n fn: ((...args: TArgs) => void) | undefined,\n): (...args: TArgs) => void {\n const ref = useRef(fn)\n\n useEffect(() => {\n ref.current = fn\n }, [fn])\n\n // Stable proxy that delegates to the latest ref.\n // typed as F so calls are type-safe (no \"unsafe call\" rule).\n // useMemo is clearer here: to memoize a proxy function as a value,\n // not define an inline handler as with useCallback.\n return useMemo(() => {\n const proxy = (...args: TArgs) => {\n ref.current?.(...args)\n }\n return proxy\n }, [])\n}\n\nexport { useEffectEvent }\n"],"names":["useEffectEvent","fn","ref","useRef","useEffect","useMemo","proxy","args"],"mappings":";AAiBA,SAASA,eACPC,EAA0C;IAE1C,MAAMC,MAAMC,OAAOF;IAEnBG,UAAU;QACRF,IAAI,OAAO,GAAGD;IAChB,GAAG;QAACA;KAAG;IAMP,OAAOI,QAAQ;QACb,MAAMC,QAAQ,CAAC,GAAGC;YAChBL,IAAI,OAAO,MAAMK;QACnB;QACA,OAAOD;IACT,GAAG,EAAE;AACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-press-tap.jsx","sources":["
|
|
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 = useEffectEvent(() => {\n if (disabled) return\n setPressed(true)\n })\n\n const reset = useEffectEvent(() => {\n setPressed(false)\n })\n\n const handleTap = useEffectEvent(() => {\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","useEffectEvent","reset","handleTap","touchHandlers","useTouchEmulation"],"mappings":";;;AA2BO,SAASA,YACd,EAAEC,WAAW,KAAK,EAAEC,KAAK,EAA8C,GAAG,CAAC,CAAC;IAE5E,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAS;IAEvC,MAAMC,QAAQC,eAAe;QAC3B,IAAIN,UAAU;QACdG,WAAW;IACb;IAEA,MAAMI,QAAQD,eAAe;QAC3BH,WAAW;IACb;IAEA,MAAMK,YAAYF,eAAe;QAC/B,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.135.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"dist/**"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lynx-js/react-use": "0.
|
|
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.135.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@lynx-js/react": "0.
|
|
34
|
-
"@lynx-js/types": "
|
|
35
|
-
"@rslib/core": "
|
|
33
|
+
"@lynx-js/react": "0.123.1",
|
|
34
|
+
"@lynx-js/types": "4.1.0",
|
|
35
|
+
"@rslib/core": "0.23.2",
|
|
36
36
|
"@types/react": "^18.3.8",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.8.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@lynx-js/react": ">=0.100.0",
|