@cdx-ui/primitives 0.0.1-alpha.11 → 0.0.1-alpha.13
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/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/link/LinkProvider.js +28 -0
- package/lib/commonjs/link/LinkProvider.js.map +1 -0
- package/lib/commonjs/link/createLink.js +74 -0
- package/lib/commonjs/link/createLink.js.map +1 -0
- package/lib/commonjs/link/index.js +27 -0
- package/lib/commonjs/link/index.js.map +1 -0
- package/lib/commonjs/link/types.js +6 -0
- package/lib/commonjs/link/types.js.map +1 -0
- package/lib/commonjs/link/useLink.js +56 -0
- package/lib/commonjs/link/useLink.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/link/LinkProvider.js +23 -0
- package/lib/module/link/LinkProvider.js.map +1 -0
- package/lib/module/link/createLink.js +68 -0
- package/lib/module/link/createLink.js.map +1 -0
- package/lib/module/link/index.js +6 -0
- package/lib/module/link/index.js.map +1 -0
- package/lib/module/link/types.js +4 -0
- package/lib/module/link/types.js.map +1 -0
- package/lib/module/link/useLink.js +52 -0
- package/lib/module/link/useLink.js.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/link/LinkProvider.d.ts +36 -0
- package/lib/typescript/link/LinkProvider.d.ts.map +1 -0
- package/lib/typescript/link/createLink.d.ts +6 -0
- package/lib/typescript/link/createLink.d.ts.map +1 -0
- package/lib/typescript/link/index.d.ts +6 -0
- package/lib/typescript/link/index.d.ts.map +1 -0
- package/lib/typescript/link/types.d.ts +45 -0
- package/lib/typescript/link/types.d.ts.map +1 -0
- package/lib/typescript/link/useLink.d.ts +9 -0
- package/lib/typescript/link/useLink.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/link/LinkProvider.tsx +50 -0
- package/src/link/createLink.tsx +71 -0
- package/src/link/index.tsx +5 -0
- package/src/link/types.ts +47 -0
- package/src/link/useLink.ts +54 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -48,6 +48,18 @@ Object.keys(_input).forEach(function (key) {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
|
+
var _link = require("./link");
|
|
52
|
+
Object.keys(_link).forEach(function (key) {
|
|
53
|
+
if (key === "default" || key === "__esModule") return;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
+
if (key in exports && exports[key] === _link[key]) return;
|
|
56
|
+
Object.defineProperty(exports, key, {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () {
|
|
59
|
+
return _link[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
51
63
|
var _overlay = require("./overlay");
|
|
52
64
|
var _select = require("./select");
|
|
53
65
|
Object.keys(_select).forEach(function (key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_button","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_checkbox","_input","_overlay","_select","_switch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,SAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,SAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,SAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,SAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,MAAA,GAAAd,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAY,MAAA,EAAAX,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAU,MAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,MAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,
|
|
1
|
+
{"version":3,"names":["_button","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_checkbox","_input","_link","_overlay","_select","_switch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CA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AL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,OAAA,CAAAd,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LinkProvider = LinkProvider;
|
|
7
|
+
exports.useLinkConfig = useLinkConfig;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
const LinkConfigContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
11
|
+
function LinkProvider({
|
|
12
|
+
navigate,
|
|
13
|
+
shouldNavigate,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkConfigContext.Provider, {
|
|
17
|
+
value: {
|
|
18
|
+
navigate,
|
|
19
|
+
shouldNavigate
|
|
20
|
+
},
|
|
21
|
+
children: children
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
LinkProvider.displayName = 'LinkProvider';
|
|
25
|
+
function useLinkConfig() {
|
|
26
|
+
return (0, _react.useContext)(LinkConfigContext);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=LinkProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_jsxRuntime","LinkConfigContext","createContext","undefined","LinkProvider","navigate","shouldNavigate","children","jsx","Provider","value","displayName","useLinkConfig","useContext"],"sourceRoot":"../../../src","sources":["link/LinkProvider.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAkE,IAAAC,WAAA,GAAAD,OAAA;AA+BlE,MAAME,iBAAiB,gBAAG,IAAAC,oBAAa,EAAyBC,SAAS,CAAC;AAEnE,SAASC,YAAYA,CAAC;EAC3BC,QAAQ;EACRC,cAAc;EACdC;AACoC,CAAC,EAAE;EACvC,oBACE,IAAAP,WAAA,CAAAQ,GAAA,EAACP,iBAAiB,CAACQ,QAAQ;IAACC,KAAK,EAAE;MAAEL,QAAQ;MAAEC;IAAe,CAAE;IAAAC,QAAA,EAC7DA;EAAQ,CACiB,CAAC;AAEjC;AAEAH,YAAY,CAACO,WAAW,GAAG,cAAc;AAElC,SAASC,aAAaA,CAAA,EAA2B;EACtD,OAAO,IAAAC,iBAAU,EAACZ,iBAAiB,CAAC;AACtC","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createLink = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _utils = require("@cdx-ui/utils");
|
|
9
|
+
var _focus = require("@react-native-aria/focus");
|
|
10
|
+
var _interactions = require("@react-native-aria/interactions");
|
|
11
|
+
var _dataAttributes = require("../utils/dataAttributes");
|
|
12
|
+
var _useLink = require("./useLink");
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
+
const createLink = ({
|
|
16
|
+
Root
|
|
17
|
+
}) => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
18
|
+
children,
|
|
19
|
+
isHovered: isHoveredProp,
|
|
20
|
+
isPressed: isPressedProp,
|
|
21
|
+
isFocused: isFocusedProp,
|
|
22
|
+
isFocusVisible: isFocusVisibleProp,
|
|
23
|
+
href,
|
|
24
|
+
onPress,
|
|
25
|
+
action,
|
|
26
|
+
webProps,
|
|
27
|
+
...props
|
|
28
|
+
}, ref) => {
|
|
29
|
+
const {
|
|
30
|
+
isFocused,
|
|
31
|
+
focusProps
|
|
32
|
+
} = (0, _focus.useFocus)();
|
|
33
|
+
const {
|
|
34
|
+
isFocusVisible,
|
|
35
|
+
focusProps: focusRingProps
|
|
36
|
+
} = (0, _focus.useFocusRing)();
|
|
37
|
+
const {
|
|
38
|
+
pressProps,
|
|
39
|
+
isPressed
|
|
40
|
+
} = (0, _interactions.usePress)({});
|
|
41
|
+
const {
|
|
42
|
+
isHovered,
|
|
43
|
+
hoverProps
|
|
44
|
+
} = (0, _interactions.useHover)();
|
|
45
|
+
const {
|
|
46
|
+
linkProps
|
|
47
|
+
} = (0, _useLink.useLink)({
|
|
48
|
+
href,
|
|
49
|
+
onPress,
|
|
50
|
+
action,
|
|
51
|
+
webProps
|
|
52
|
+
});
|
|
53
|
+
const interactionAttrs = (0, _dataAttributes.dataAttributes)({
|
|
54
|
+
hover: isHoveredProp || isHovered,
|
|
55
|
+
focus: isFocusedProp || isFocused,
|
|
56
|
+
active: isPressedProp || isPressed,
|
|
57
|
+
focusVisible: isFocusVisibleProp || isFocusVisible
|
|
58
|
+
});
|
|
59
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Root, {
|
|
60
|
+
ref: ref,
|
|
61
|
+
...interactionAttrs,
|
|
62
|
+
...linkProps,
|
|
63
|
+
...props,
|
|
64
|
+
onPressIn: (0, _utils.composeEventHandlers)(props?.onPressIn, pressProps.onPressIn),
|
|
65
|
+
onPressOut: (0, _utils.composeEventHandlers)(props?.onPressOut, pressProps.onPressOut),
|
|
66
|
+
onHoverIn: (0, _utils.composeEventHandlers)(props?.onHoverIn, hoverProps.onHoverIn),
|
|
67
|
+
onHoverOut: (0, _utils.composeEventHandlers)(props?.onHoverOut, hoverProps.onHoverOut),
|
|
68
|
+
onFocus: (0, _utils.composeEventHandlers)((0, _utils.composeEventHandlers)(props?.onFocus, focusProps.onFocus), focusRingProps.onFocus),
|
|
69
|
+
onBlur: (0, _utils.composeEventHandlers)((0, _utils.composeEventHandlers)(props?.onBlur, focusProps.onBlur), focusRingProps.onBlur),
|
|
70
|
+
children: children
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
exports.createLink = createLink;
|
|
74
|
+
//# sourceMappingURL=createLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_utils","_focus","_interactions","_dataAttributes","_useLink","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","createLink","Root","forwardRef","children","isHovered","isHoveredProp","isPressed","isPressedProp","isFocused","isFocusedProp","isFocusVisible","isFocusVisibleProp","href","onPress","action","webProps","props","ref","focusProps","useFocus","focusRingProps","useFocusRing","pressProps","usePress","hoverProps","useHover","linkProps","useLink","interactionAttrs","dataAttributes","hover","focus","active","focusVisible","jsx","onPressIn","composeEventHandlers","onPressOut","onHoverIn","onHoverOut","onFocus","onBlur","exports"],"sourceRoot":"../../../src","sources":["link/createLink.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAAoC,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAD,wBAAAQ,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAA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CAACoB,OACjB,CAAE;IACFC,MAAM,EAAE,IAAAL,2BAAoB,EAC1B,IAAAA,2BAAoB,EAACpB,KAAK,EAAEyB,MAAM,EAAEvB,UAAU,CAACuB,MAAM,CAAC,EACtDrB,cAAc,CAACqB,MACjB,CAAE;IAAAtC,QAAA,EAEDA;EAAQ,CACL,CAAC;AAEX,CACF,CAAC;AAACuC,OAAA,CAAA1C,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "LinkProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _LinkProvider.LinkProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createLink", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _createLink.createLink;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "useLink", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useLink.useLink;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _createLink = require("./createLink");
|
|
25
|
+
var _LinkProvider = require("./LinkProvider");
|
|
26
|
+
var _useLink = require("./useLink");
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_createLink","require","_LinkProvider","_useLink"],"sourceRoot":"../../../src","sources":["link/index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["link/types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLink = useLink;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _LinkProvider = require("./LinkProvider");
|
|
9
|
+
function defaultNavigate(href) {
|
|
10
|
+
_reactNative.Linking.canOpenURL(href).then(supported => {
|
|
11
|
+
if (supported) return _reactNative.Linking.openURL(href);
|
|
12
|
+
console.warn(`Cannot open URL: ${href}`);
|
|
13
|
+
}).catch(err => console.error('Failed to open URL', err));
|
|
14
|
+
}
|
|
15
|
+
function useLink(props) {
|
|
16
|
+
const {
|
|
17
|
+
href,
|
|
18
|
+
onPress,
|
|
19
|
+
action = 'navigate',
|
|
20
|
+
webProps
|
|
21
|
+
} = props;
|
|
22
|
+
const config = (0, _LinkProvider.useLinkConfig)();
|
|
23
|
+
const providerHandles = !!config && !!href && (config.shouldNavigate?.(href) ?? true);
|
|
24
|
+
let platformLinkProps = {};
|
|
25
|
+
if (_reactNative.Platform.OS === 'web') {
|
|
26
|
+
platformLinkProps = {
|
|
27
|
+
href: providerHandles ? undefined : href,
|
|
28
|
+
hrefAttrs: webProps,
|
|
29
|
+
onPress: event => {
|
|
30
|
+
onPress?.(event);
|
|
31
|
+
if (providerHandles) void config.navigate(href, action);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
platformLinkProps = {
|
|
36
|
+
onPress: event => {
|
|
37
|
+
onPress?.(event);
|
|
38
|
+
if (href) {
|
|
39
|
+
if (providerHandles) {
|
|
40
|
+
void config.navigate(href, action);
|
|
41
|
+
} else {
|
|
42
|
+
defaultNavigate(href);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
linkProps: {
|
|
50
|
+
...platformLinkProps,
|
|
51
|
+
role: 'link',
|
|
52
|
+
accessible: true
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=useLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_LinkProvider","defaultNavigate","href","Linking","canOpenURL","then","supported","openURL","console","warn","catch","err","error","useLink","props","onPress","action","webProps","config","useLinkConfig","providerHandles","shouldNavigate","platformLinkProps","Platform","OS","undefined","hrefAttrs","event","navigate","linkProps","role","accessible"],"sourceRoot":"../../../src","sources":["link/useLink.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAGA,SAASE,eAAeA,CAACC,IAAY,EAAQ;EAC3CC,oBAAO,CAACC,UAAU,CAACF,IAAI,CAAC,CACrBG,IAAI,CAAEC,SAAS,IAAK;IACnB,IAAIA,SAAS,EAAE,OAAOH,oBAAO,CAACI,OAAO,CAACL,IAAI,CAAC;IAC3CM,OAAO,CAACC,IAAI,CAAC,oBAAoBP,IAAI,EAAE,CAAC;EAC1C,CAAC,CAAC,CACDQ,KAAK,CAAEC,GAAY,IAAKH,OAAO,CAACI,KAAK,CAAC,oBAAoB,EAAED,GAAG,CAAC,CAAC;AACtE;AAEO,SAASE,OAAOA,CAACC,KAAmB,EAAE;EAC3C,MAAM;IAAEZ,IAAI;IAAEa,OAAO;IAAEC,MAAM,GAAG,UAAU;IAAEC;EAAS,CAAC,GAAGH,KAAK;EAC9D,MAAMI,MAAM,GAAG,IAAAC,2BAAa,EAAC,CAAC;EAE9B,MAAMC,eAAe,GAAG,CAAC,CAACF,MAAM,IAAI,CAAC,CAAChB,IAAI,KAAKgB,MAAM,CAACG,cAAc,GAAGnB,IAAI,CAAC,IAAI,IAAI,CAAC;EAErF,IAAIoB,iBAAiB,GAAG,CAAC,CAAC;EAE1B,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IACzBF,iBAAiB,GAAG;MAClBpB,IAAI,EAAEkB,eAAe,GAAGK,SAAS,GAAGvB,IAAI;MACxCwB,SAAS,EAAET,QAAQ;MACnBF,OAAO,EAAGY,KAA4B,IAAK;QACzCZ,OAAO,GAAGY,KAAK,CAAC;QAChB,IAAIP,eAAe,EAAE,KAAKF,MAAM,CAACU,QAAQ,CAAC1B,IAAI,EAAEc,MAAM,CAAC;MACzD;IACF,CAAC;EACH,CAAC,MAAM;IACLM,iBAAiB,GAAG;MAClBP,OAAO,EAAGY,KAA4B,IAAK;QACzCZ,OAAO,GAAGY,KAAK,CAAC;QAChB,IAAIzB,IAAI,EAAE;UACR,IAAIkB,eAAe,EAAE;YACnB,KAAKF,MAAM,CAACU,QAAQ,CAAC1B,IAAI,EAAEc,MAAM,CAAC;UACpC,CAAC,MAAM;YACLf,eAAe,CAACC,IAAI,CAAC;UACvB;QACF;MACF;IACF,CAAC;EACH;EAEA,OAAO;IACL2B,SAAS,EAAE;MACT,GAAGP,iBAAiB;MACpBQ,IAAI,EAAE,MAA2B;MACjCC,UAAU,EAAE;IACd;EACF,CAAC;AACH","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OverlayInsetsProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,UAAU;AACxB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,SAA0BA,qBAAqB,QAAQ,WAAW;AAClE,cAAc,UAAU;AACxB,cAAc,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["OverlayInsetsProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,UAAU;AACxB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,SAA0BA,qBAAqB,QAAQ,WAAW;AAClE,cAAc,UAAU;AACxB,cAAc,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const LinkConfigContext = /*#__PURE__*/createContext(undefined);
|
|
6
|
+
export function LinkProvider({
|
|
7
|
+
navigate,
|
|
8
|
+
shouldNavigate,
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
return /*#__PURE__*/_jsx(LinkConfigContext.Provider, {
|
|
12
|
+
value: {
|
|
13
|
+
navigate,
|
|
14
|
+
shouldNavigate
|
|
15
|
+
},
|
|
16
|
+
children: children
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
LinkProvider.displayName = 'LinkProvider';
|
|
20
|
+
export function useLinkConfig() {
|
|
21
|
+
return useContext(LinkConfigContext);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=LinkProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","useContext","jsx","_jsx","LinkConfigContext","undefined","LinkProvider","navigate","shouldNavigate","children","Provider","value","displayName","useLinkConfig"],"sourceRoot":"../../../src","sources":["link/LinkProvider.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAwB,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA+BlE,MAAMC,iBAAiB,gBAAGJ,aAAa,CAAyBK,SAAS,CAAC;AAE1E,OAAO,SAASC,YAAYA,CAAC;EAC3BC,QAAQ;EACRC,cAAc;EACdC;AACoC,CAAC,EAAE;EACvC,oBACEN,IAAA,CAACC,iBAAiB,CAACM,QAAQ;IAACC,KAAK,EAAE;MAAEJ,QAAQ;MAAEC;IAAe,CAAE;IAAAC,QAAA,EAC7DA;EAAQ,CACiB,CAAC;AAEjC;AAEAH,YAAY,CAACM,WAAW,GAAG,cAAc;AAEzC,OAAO,SAASC,aAAaA,CAAA,EAA2B;EACtD,OAAOZ,UAAU,CAACG,iBAAiB,CAAC;AACtC","ignoreList":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
5
|
+
import { useFocusRing, useFocus } from '@react-native-aria/focus';
|
|
6
|
+
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
7
|
+
import { dataAttributes } from '../utils/dataAttributes';
|
|
8
|
+
import { useLink } from './useLink';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export const createLink = ({
|
|
11
|
+
Root
|
|
12
|
+
}) => /*#__PURE__*/forwardRef(({
|
|
13
|
+
children,
|
|
14
|
+
isHovered: isHoveredProp,
|
|
15
|
+
isPressed: isPressedProp,
|
|
16
|
+
isFocused: isFocusedProp,
|
|
17
|
+
isFocusVisible: isFocusVisibleProp,
|
|
18
|
+
href,
|
|
19
|
+
onPress,
|
|
20
|
+
action,
|
|
21
|
+
webProps,
|
|
22
|
+
...props
|
|
23
|
+
}, ref) => {
|
|
24
|
+
const {
|
|
25
|
+
isFocused,
|
|
26
|
+
focusProps
|
|
27
|
+
} = useFocus();
|
|
28
|
+
const {
|
|
29
|
+
isFocusVisible,
|
|
30
|
+
focusProps: focusRingProps
|
|
31
|
+
} = useFocusRing();
|
|
32
|
+
const {
|
|
33
|
+
pressProps,
|
|
34
|
+
isPressed
|
|
35
|
+
} = usePress({});
|
|
36
|
+
const {
|
|
37
|
+
isHovered,
|
|
38
|
+
hoverProps
|
|
39
|
+
} = useHover();
|
|
40
|
+
const {
|
|
41
|
+
linkProps
|
|
42
|
+
} = useLink({
|
|
43
|
+
href,
|
|
44
|
+
onPress,
|
|
45
|
+
action,
|
|
46
|
+
webProps
|
|
47
|
+
});
|
|
48
|
+
const interactionAttrs = dataAttributes({
|
|
49
|
+
hover: isHoveredProp || isHovered,
|
|
50
|
+
focus: isFocusedProp || isFocused,
|
|
51
|
+
active: isPressedProp || isPressed,
|
|
52
|
+
focusVisible: isFocusVisibleProp || isFocusVisible
|
|
53
|
+
});
|
|
54
|
+
return /*#__PURE__*/_jsx(Root, {
|
|
55
|
+
ref: ref,
|
|
56
|
+
...interactionAttrs,
|
|
57
|
+
...linkProps,
|
|
58
|
+
...props,
|
|
59
|
+
onPressIn: composeEventHandlers(props?.onPressIn, pressProps.onPressIn),
|
|
60
|
+
onPressOut: composeEventHandlers(props?.onPressOut, pressProps.onPressOut),
|
|
61
|
+
onHoverIn: composeEventHandlers(props?.onHoverIn, hoverProps.onHoverIn),
|
|
62
|
+
onHoverOut: composeEventHandlers(props?.onHoverOut, hoverProps.onHoverOut),
|
|
63
|
+
onFocus: composeEventHandlers(composeEventHandlers(props?.onFocus, focusProps.onFocus), focusRingProps.onFocus),
|
|
64
|
+
onBlur: composeEventHandlers(composeEventHandlers(props?.onBlur, focusProps.onBlur), focusRingProps.onBlur),
|
|
65
|
+
children: children
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=createLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","composeEventHandlers","useFocusRing","useFocus","useHover","usePress","dataAttributes","useLink","jsx","_jsx","createLink","Root","children","isHovered","isHoveredProp","isPressed","isPressedProp","isFocused","isFocusedProp","isFocusVisible","isFocusVisibleProp","href","onPress","action","webProps","props","ref","focusProps","focusRingProps","pressProps","hoverProps","linkProps","interactionAttrs","hover","focus","active","focusVisible","onPressIn","onPressOut","onHoverIn","onHoverOut","onFocus","onBlur"],"sourceRoot":"../../../src","sources":["link/createLink.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,YAAY,EAAEC,QAAQ,QAAQ,0BAA0B;AACjE,SAASC,QAAQ,EAAEC,QAAQ,Q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AAS,EAAER,UAAU,CAACQ,SAAS,CAAE;IACxEC,UAAU,EAAErC,oBAAoB,CAACwB,KAAK,EAAEa,UAAU,EAAET,UAAU,CAACS,UAAU,CAAE;IAC3EC,SAAS,EAAEtC,oBAAoB,CAACwB,KAAK,EAAEc,SAAS,EAAET,UAAU,CAACS,SAAS,CAAE;IACxEC,UAAU,EAAEvC,oBAAoB,CAACwB,KAAK,EAAEe,UAAU,EAAEV,UAAU,CAACU,UAAU,CAAE;IAC3EC,OAAO,EAAExC,oBAAoB,CAC3BA,oBAAoB,CAACwB,KAAK,EAAEgB,OAAO,EAAEd,UAAU,CAACc,OAAO,CAAC,EACxDb,cAAc,CAACa,OACjB,CAAE;IACFC,MAAM,EAAEzC,oBAAoB,CAC1BA,oBAAoB,CAACwB,KAAK,EAAEiB,MAAM,EAAEf,UAAU,CAACe,MAAM,CAAC,EACtDd,cAAc,CAACc,MACjB,CAAE;IAAA9B,QAAA,EAEDA;EAAQ,CACL,CAAC;AAEX,CACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createLink","LinkProvider","useLink"],"sourceRoot":"../../../src","sources":["link/index.tsx"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,OAAO,QAAQ,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["link/types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Linking, Platform } from 'react-native';
|
|
4
|
+
import { useLinkConfig } from './LinkProvider';
|
|
5
|
+
function defaultNavigate(href) {
|
|
6
|
+
Linking.canOpenURL(href).then(supported => {
|
|
7
|
+
if (supported) return Linking.openURL(href);
|
|
8
|
+
console.warn(`Cannot open URL: ${href}`);
|
|
9
|
+
}).catch(err => console.error('Failed to open URL', err));
|
|
10
|
+
}
|
|
11
|
+
export function useLink(props) {
|
|
12
|
+
const {
|
|
13
|
+
href,
|
|
14
|
+
onPress,
|
|
15
|
+
action = 'navigate',
|
|
16
|
+
webProps
|
|
17
|
+
} = props;
|
|
18
|
+
const config = useLinkConfig();
|
|
19
|
+
const providerHandles = !!config && !!href && (config.shouldNavigate?.(href) ?? true);
|
|
20
|
+
let platformLinkProps = {};
|
|
21
|
+
if (Platform.OS === 'web') {
|
|
22
|
+
platformLinkProps = {
|
|
23
|
+
href: providerHandles ? undefined : href,
|
|
24
|
+
hrefAttrs: webProps,
|
|
25
|
+
onPress: event => {
|
|
26
|
+
onPress?.(event);
|
|
27
|
+
if (providerHandles) void config.navigate(href, action);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
} else {
|
|
31
|
+
platformLinkProps = {
|
|
32
|
+
onPress: event => {
|
|
33
|
+
onPress?.(event);
|
|
34
|
+
if (href) {
|
|
35
|
+
if (providerHandles) {
|
|
36
|
+
void config.navigate(href, action);
|
|
37
|
+
} else {
|
|
38
|
+
defaultNavigate(href);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
linkProps: {
|
|
46
|
+
...platformLinkProps,
|
|
47
|
+
role: 'link',
|
|
48
|
+
accessible: true
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=useLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Linking","Platform","useLinkConfig","defaultNavigate","href","canOpenURL","then","supported","openURL","console","warn","catch","err","error","useLink","props","onPress","action","webProps","config","providerHandles","shouldNavigate","platformLinkProps","OS","undefined","hrefAttrs","event","navigate","linkProps","role","accessible"],"sourceRoot":"../../../src","sources":["link/useLink.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,QAAQ,QAAQ,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AAIgB,eAAe,EAAE;YACnB,KAAKD,MAAM,CAACQ,QAAQ,CAACvB,IAAI,EAAEa,MAAM,CAAC;UACpC,CAAC,MAAM;YACLd,eAAe,CAACC,IAAI,CAAC;UACvB;QACF;MACF;IACF,CAAC;EACH;EAEA,OAAO;IACLwB,SAAS,EAAE;MACT,GAAGN,iBAAiB;MACpBO,IAAI,EAAE,MAA2B;MACjCC,UAAU,EAAE;IACd;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { LinkAction } from './types';
|
|
3
|
+
export interface LinkConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Global navigation handler for `<Link>` instances whose `href` passes the
|
|
6
|
+
* `shouldNavigate` check. Called with the `href` and the per-instance `action`.
|
|
7
|
+
*
|
|
8
|
+
* @param href - The URL or path to navigate to.
|
|
9
|
+
* @param action - Navigation intent from the per-instance `action` prop:
|
|
10
|
+
* `'navigate'` (default) — smart navigation, avoids duplicates.
|
|
11
|
+
* `'push'` — always pushes a new entry onto the stack.
|
|
12
|
+
* `'replace'` — replaces the current entry without stacking.
|
|
13
|
+
*/
|
|
14
|
+
navigate: (href: string, action: LinkAction) => void | Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Optional predicate evaluated at **render time** to decide whether the
|
|
17
|
+
* provider should handle a given `href`.
|
|
18
|
+
*
|
|
19
|
+
* - Returns `true` → the provider's `navigate` is called on press;
|
|
20
|
+
* on web the native `<a href>` is **removed** so the browser doesn't
|
|
21
|
+
* follow the link.
|
|
22
|
+
* - Returns `false` → the provider is bypassed; on web the `<a href>` is
|
|
23
|
+
* preserved (cmd-click, SEO, etc.); on native `Linking.openURL` is used.
|
|
24
|
+
*
|
|
25
|
+
* Defaults to `() => true` when omitted (all hrefs go through the provider).
|
|
26
|
+
*/
|
|
27
|
+
shouldNavigate?: (href: string) => boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function LinkProvider({ navigate, shouldNavigate, children, }: LinkConfig & {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export declare namespace LinkProvider {
|
|
33
|
+
var displayName: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function useLinkConfig(): LinkConfig | undefined;
|
|
36
|
+
//# sourceMappingURL=LinkProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkProvider.d.ts","sourceRoot":"","sources":["../../../src/link/LinkProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,UAAU;IACzB;;;;;;;;;OASG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5C;AAID,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,cAAc,EACd,QAAQ,GACT,EAAE,UAAU,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAMtC;yBAVe,YAAY;;;AAc5B,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ILinkProps } from './types';
|
|
3
|
+
export declare const createLink: <RootT, R = unknown>({ Root }: {
|
|
4
|
+
Root: React.ComponentType<RootT>;
|
|
5
|
+
}) => React.ForwardRefExoticComponent<ILinkProps & React.RefAttributes<R>>;
|
|
6
|
+
//# sourceMappingURL=createLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createLink.d.ts","sourceRoot":"","sources":["../../../src/link/createLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAM1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,UAAU,GAAI,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,UAAU;IAAE,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;CAAE,yEA8D1F,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createLink } from './createLink';
|
|
2
|
+
export { LinkProvider } from './LinkProvider';
|
|
3
|
+
export type { LinkConfig } from './LinkProvider';
|
|
4
|
+
export { useLink } from './useLink';
|
|
5
|
+
export type { ILinkProps, IUseLinkProp, LinkAction } from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/link/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { GestureResponderEvent, PressableProps } from 'react-native';
|
|
3
|
+
/**
|
|
4
|
+
* Navigation action forwarded to the `LinkProvider.navigate` callback.
|
|
5
|
+
*
|
|
6
|
+
* - `'navigate'` — (default) Smart navigation. In React Navigation this
|
|
7
|
+
* avoids duplicating a screen that is already in the stack. In expo-router
|
|
8
|
+
* it maps to `router.navigate()`.
|
|
9
|
+
* - `'push'` — Always pushes a new screen onto the navigation stack,
|
|
10
|
+
* even if the destination is already present.
|
|
11
|
+
* - `'replace'` — Replaces the current screen without adding to the stack.
|
|
12
|
+
* Useful for post-login redirects or wizard flows.
|
|
13
|
+
*/
|
|
14
|
+
export type LinkAction = 'navigate' | 'push' | 'replace';
|
|
15
|
+
export interface ILinkProps extends PressableProps {
|
|
16
|
+
/**
|
|
17
|
+
* URL that should be opened on Link press
|
|
18
|
+
*/
|
|
19
|
+
href?: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Callback that will be invoked on Link press
|
|
22
|
+
*/
|
|
23
|
+
onPress?: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Navigation action forwarded to the `LinkProvider`.
|
|
26
|
+
* Defaults to `'navigate'`.
|
|
27
|
+
*/
|
|
28
|
+
action?: LinkAction;
|
|
29
|
+
isPressed?: boolean;
|
|
30
|
+
isHovered?: boolean;
|
|
31
|
+
isFocused?: boolean;
|
|
32
|
+
isFocusVisible?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* HTML anchor attributes applied only on web. Ignored on native platforms.
|
|
35
|
+
* `target`, `rel`, and `download` are forwarded via react-native-web's `hrefAttrs`.
|
|
36
|
+
*/
|
|
37
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
38
|
+
}
|
|
39
|
+
export interface IUseLinkProp {
|
|
40
|
+
href?: string;
|
|
41
|
+
onPress: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
42
|
+
action?: LinkAction;
|
|
43
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/link/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACvE;;;OAGG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACtE,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CAC1D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AccessibilityRole } from 'react-native';
|
|
2
|
+
import type { IUseLinkProp } from './types';
|
|
3
|
+
export declare function useLink(props: IUseLinkProp): {
|
|
4
|
+
linkProps: {
|
|
5
|
+
role: AccessibilityRole;
|
|
6
|
+
accessible: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=useLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLink.d.ts","sourceRoot":"","sources":["../../../src/link/useLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAyB,MAAM,cAAc,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAW5C,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY;;cAmCrB,iBAAiB;;;EAItC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/primitives",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.13",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"module": "lib/module/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@react-native-aria/interactions": "^0.2.16",
|
|
53
53
|
"@react-stately/checkbox": "3.7.4",
|
|
54
54
|
"@react-stately/toggle": "3.9.4",
|
|
55
|
-
"@cdx-ui/utils": "0.0.1-alpha.
|
|
55
|
+
"@cdx-ui/utils": "0.0.1-alpha.13"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/react": "*",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from 'react';
|
|
2
|
+
import type { LinkAction } from './types';
|
|
3
|
+
|
|
4
|
+
export interface LinkConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Global navigation handler for `<Link>` instances whose `href` passes the
|
|
7
|
+
* `shouldNavigate` check. Called with the `href` and the per-instance `action`.
|
|
8
|
+
*
|
|
9
|
+
* @param href - The URL or path to navigate to.
|
|
10
|
+
* @param action - Navigation intent from the per-instance `action` prop:
|
|
11
|
+
* `'navigate'` (default) — smart navigation, avoids duplicates.
|
|
12
|
+
* `'push'` — always pushes a new entry onto the stack.
|
|
13
|
+
* `'replace'` — replaces the current entry without stacking.
|
|
14
|
+
*/
|
|
15
|
+
navigate: (href: string, action: LinkAction) => void | Promise<void>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional predicate evaluated at **render time** to decide whether the
|
|
19
|
+
* provider should handle a given `href`.
|
|
20
|
+
*
|
|
21
|
+
* - Returns `true` → the provider's `navigate` is called on press;
|
|
22
|
+
* on web the native `<a href>` is **removed** so the browser doesn't
|
|
23
|
+
* follow the link.
|
|
24
|
+
* - Returns `false` → the provider is bypassed; on web the `<a href>` is
|
|
25
|
+
* preserved (cmd-click, SEO, etc.); on native `Linking.openURL` is used.
|
|
26
|
+
*
|
|
27
|
+
* Defaults to `() => true` when omitted (all hrefs go through the provider).
|
|
28
|
+
*/
|
|
29
|
+
shouldNavigate?: (href: string) => boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const LinkConfigContext = createContext<LinkConfig | undefined>(undefined);
|
|
33
|
+
|
|
34
|
+
export function LinkProvider({
|
|
35
|
+
navigate,
|
|
36
|
+
shouldNavigate,
|
|
37
|
+
children,
|
|
38
|
+
}: LinkConfig & { children: ReactNode }) {
|
|
39
|
+
return (
|
|
40
|
+
<LinkConfigContext.Provider value={{ navigate, shouldNavigate }}>
|
|
41
|
+
{children}
|
|
42
|
+
</LinkConfigContext.Provider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
LinkProvider.displayName = 'LinkProvider';
|
|
47
|
+
|
|
48
|
+
export function useLinkConfig(): LinkConfig | undefined {
|
|
49
|
+
return useContext(LinkConfigContext);
|
|
50
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
3
|
+
import { useFocusRing, useFocus } from '@react-native-aria/focus';
|
|
4
|
+
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
5
|
+
import { dataAttributes } from '../utils/dataAttributes';
|
|
6
|
+
import { useLink } from './useLink';
|
|
7
|
+
import type { ILinkProps } from './types';
|
|
8
|
+
|
|
9
|
+
export const createLink = <RootT, R = unknown>({ Root }: { Root: React.ComponentType<RootT> }) =>
|
|
10
|
+
forwardRef(
|
|
11
|
+
(
|
|
12
|
+
{
|
|
13
|
+
children,
|
|
14
|
+
isHovered: isHoveredProp,
|
|
15
|
+
isPressed: isPressedProp,
|
|
16
|
+
isFocused: isFocusedProp,
|
|
17
|
+
isFocusVisible: isFocusVisibleProp,
|
|
18
|
+
href,
|
|
19
|
+
onPress,
|
|
20
|
+
action,
|
|
21
|
+
webProps,
|
|
22
|
+
...props
|
|
23
|
+
}: ILinkProps,
|
|
24
|
+
ref: React.ForwardedRef<R>,
|
|
25
|
+
) => {
|
|
26
|
+
const { isFocused, focusProps } = useFocus();
|
|
27
|
+
const { isFocusVisible, focusProps: focusRingProps } = useFocusRing() as {
|
|
28
|
+
isFocusVisible: boolean;
|
|
29
|
+
focusProps: typeof focusProps;
|
|
30
|
+
};
|
|
31
|
+
const { pressProps, isPressed } = usePress({});
|
|
32
|
+
const { isHovered, hoverProps } = useHover();
|
|
33
|
+
|
|
34
|
+
const { linkProps } = useLink({
|
|
35
|
+
href,
|
|
36
|
+
onPress,
|
|
37
|
+
action,
|
|
38
|
+
webProps,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const interactionAttrs = dataAttributes({
|
|
42
|
+
hover: isHoveredProp || isHovered,
|
|
43
|
+
focus: isFocusedProp || isFocused,
|
|
44
|
+
active: isPressedProp || isPressed,
|
|
45
|
+
focusVisible: isFocusVisibleProp || isFocusVisible,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Root
|
|
50
|
+
ref={ref}
|
|
51
|
+
{...interactionAttrs}
|
|
52
|
+
{...linkProps}
|
|
53
|
+
{...(props as RootT)}
|
|
54
|
+
onPressIn={composeEventHandlers(props?.onPressIn, pressProps.onPressIn)}
|
|
55
|
+
onPressOut={composeEventHandlers(props?.onPressOut, pressProps.onPressOut)}
|
|
56
|
+
onHoverIn={composeEventHandlers(props?.onHoverIn, hoverProps.onHoverIn)}
|
|
57
|
+
onHoverOut={composeEventHandlers(props?.onHoverOut, hoverProps.onHoverOut)}
|
|
58
|
+
onFocus={composeEventHandlers(
|
|
59
|
+
composeEventHandlers(props?.onFocus, focusProps.onFocus),
|
|
60
|
+
focusRingProps.onFocus,
|
|
61
|
+
)}
|
|
62
|
+
onBlur={composeEventHandlers(
|
|
63
|
+
composeEventHandlers(props?.onBlur, focusProps.onBlur),
|
|
64
|
+
focusRingProps.onBlur,
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</Root>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { GestureResponderEvent, PressableProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Navigation action forwarded to the `LinkProvider.navigate` callback.
|
|
6
|
+
*
|
|
7
|
+
* - `'navigate'` — (default) Smart navigation. In React Navigation this
|
|
8
|
+
* avoids duplicating a screen that is already in the stack. In expo-router
|
|
9
|
+
* it maps to `router.navigate()`.
|
|
10
|
+
* - `'push'` — Always pushes a new screen onto the navigation stack,
|
|
11
|
+
* even if the destination is already present.
|
|
12
|
+
* - `'replace'` — Replaces the current screen without adding to the stack.
|
|
13
|
+
* Useful for post-login redirects or wizard flows.
|
|
14
|
+
*/
|
|
15
|
+
export type LinkAction = 'navigate' | 'push' | 'replace';
|
|
16
|
+
|
|
17
|
+
export interface ILinkProps extends PressableProps {
|
|
18
|
+
/**
|
|
19
|
+
* URL that should be opened on Link press
|
|
20
|
+
*/
|
|
21
|
+
href?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Callback that will be invoked on Link press
|
|
24
|
+
*/
|
|
25
|
+
onPress?: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Navigation action forwarded to the `LinkProvider`.
|
|
28
|
+
* Defaults to `'navigate'`.
|
|
29
|
+
*/
|
|
30
|
+
action?: LinkAction;
|
|
31
|
+
isPressed?: boolean;
|
|
32
|
+
isHovered?: boolean;
|
|
33
|
+
isFocused?: boolean;
|
|
34
|
+
isFocusVisible?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* HTML anchor attributes applied only on web. Ignored on native platforms.
|
|
37
|
+
* `target`, `rel`, and `download` are forwarded via react-native-web's `hrefAttrs`.
|
|
38
|
+
*/
|
|
39
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IUseLinkProp {
|
|
43
|
+
href?: string;
|
|
44
|
+
onPress: ((event?: GestureResponderEvent) => void) | null | undefined;
|
|
45
|
+
action?: LinkAction;
|
|
46
|
+
webProps?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Linking, Platform } from 'react-native';
|
|
2
|
+
import type { AccessibilityRole, GestureResponderEvent } from 'react-native';
|
|
3
|
+
import { useLinkConfig } from './LinkProvider';
|
|
4
|
+
import type { IUseLinkProp } from './types';
|
|
5
|
+
|
|
6
|
+
function defaultNavigate(href: string): void {
|
|
7
|
+
Linking.canOpenURL(href)
|
|
8
|
+
.then((supported) => {
|
|
9
|
+
if (supported) return Linking.openURL(href);
|
|
10
|
+
console.warn(`Cannot open URL: ${href}`);
|
|
11
|
+
})
|
|
12
|
+
.catch((err: unknown) => console.error('Failed to open URL', err));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useLink(props: IUseLinkProp) {
|
|
16
|
+
const { href, onPress, action = 'navigate', webProps } = props;
|
|
17
|
+
const config = useLinkConfig();
|
|
18
|
+
|
|
19
|
+
const providerHandles = !!config && !!href && (config.shouldNavigate?.(href) ?? true);
|
|
20
|
+
|
|
21
|
+
let platformLinkProps = {};
|
|
22
|
+
|
|
23
|
+
if (Platform.OS === 'web') {
|
|
24
|
+
platformLinkProps = {
|
|
25
|
+
href: providerHandles ? undefined : href,
|
|
26
|
+
hrefAttrs: webProps,
|
|
27
|
+
onPress: (event: GestureResponderEvent) => {
|
|
28
|
+
onPress?.(event);
|
|
29
|
+
if (providerHandles) void config.navigate(href, action);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
platformLinkProps = {
|
|
34
|
+
onPress: (event: GestureResponderEvent) => {
|
|
35
|
+
onPress?.(event);
|
|
36
|
+
if (href) {
|
|
37
|
+
if (providerHandles) {
|
|
38
|
+
void config.navigate(href, action);
|
|
39
|
+
} else {
|
|
40
|
+
defaultNavigate(href);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
linkProps: {
|
|
49
|
+
...platformLinkProps,
|
|
50
|
+
role: 'link' as AccessibilityRole,
|
|
51
|
+
accessible: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|