@okam/next-component 1.0.15 → 1.1.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/index.esm.js CHANGED
@@ -4,6 +4,7 @@ import Image from 'next/image';
4
4
  import NextLink from 'next/link';
5
5
  import { useState, useCallback, useEffect, forwardRef } from 'react';
6
6
  import { usePathname, useSearchParams, useParams } from 'next/navigation';
7
+ import { useLocale } from 'react-aria';
7
8
  import { useEvent } from 'react-use';
8
9
 
9
10
  function _define_property$1(obj, key, value) {
@@ -196,7 +197,7 @@ function scrollToTop(behavior) {
196
197
  });
197
198
  }
198
199
  function getParamsLocale(params) {
199
- var locale = params.locale;
200
+ var locale = (params !== null && params !== void 0 ? params : {}).locale;
200
201
  if (Array.isArray(locale)) return locale[0];
201
202
  return locale;
202
203
  }
@@ -210,16 +211,25 @@ function getParamsLocale(params) {
210
211
  var locale = props.locale;
211
212
  var params = useParams();
212
213
  var paramsLocale = getParamsLocale(params);
213
- if (locale === false) return false;
214
- var _ref;
215
- return (_ref = locale !== null && locale !== void 0 ? locale : paramsLocale) !== null && _ref !== void 0 ? _ref : false;
214
+ var _useLocale = useLocale(), ctxLocale = _useLocale.locale;
215
+ var _ref, _ref1;
216
+ return (_ref1 = (_ref = locale !== null && locale !== void 0 ? locale : ctxLocale) !== null && _ref !== void 0 ? _ref : paramsLocale) !== null && _ref1 !== void 0 ? _ref1 : false;
217
+ }
218
+ function localizeHref(href, locale) {
219
+ var hrefString = href.toString();
220
+ var isExternal = /^[a-z]+:\/\//i.test(hrefString) || hrefString.startsWith('//');
221
+ if (isExternal) return hrefString;
222
+ if (locale) {
223
+ return "/".concat(locale).concat(hrefString);
224
+ }
225
+ return hrefString;
216
226
  }
217
227
  /**
218
228
  * @params {props.locale} - The direct locale prop always gets priority. If no `locale` prop is provided, the prop will try to fall back to react-aria `useLocale` and then next/navigation `useParams`. If a locale is found, it will be automatically prepended to the href. Otherwise, href will be returned as is.
219
229
  */ function useLink(props) {
220
230
  var _props_scroll = props.scroll, scroll = _props_scroll === void 0 ? true : _props_scroll, onMouseEnter = props.onMouseEnter, onTouchStart = props.onTouchStart, onClick = props.onClick, onPathnameChange = props.onPathnameChange, onHashChange = props.onHashChange, onSearchParamsChange = props.onSearchParamsChange, href = props.href, urlDecorator = props.urlDecorator, replace = props.replace, prefetch = props.prefetch, shallow = props.shallow, passHref = props.passHref, legacyBehavior = props.legacyBehavior, _props_behavior = props.behavior, behavior = _props_behavior === void 0 ? 'instant' : _props_behavior;
221
231
  var locale = useLinkLocale(props);
222
- var localizedHref = locale ? "/".concat(locale).concat(href) : href;
232
+ var localizedHref = localizeHref(href, locale);
223
233
  var pathname = usePathname();
224
234
  var searchParams = useSearchParams();
225
235
  var hash = useHash();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/next-component",
3
- "version": "1.0.15",
3
+ "version": "1.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,11 +8,12 @@
8
8
  "url": "https://github.com/OKAMca/stack.git"
9
9
  },
10
10
  "dependencies": {
11
- "@okam/stack-ui": "1.41.1",
11
+ "@okam/stack-ui": "1.41.2",
12
12
  "next": "^14.1.1",
13
13
  "react": "18.3.1",
14
14
  "react-use": "17.5.1",
15
- "tailwind-variants": "^0.3.0"
15
+ "tailwind-variants": "^0.3.0",
16
+ "react-aria": "^3.39.0"
16
17
  },
17
18
  "module": "./index.esm.js",
18
19
  "type": "module",
@@ -1,3 +1,4 @@
1
+ import type { LinkProps } from 'next/link';
1
2
  import type { TLink, TUseLinkReturn } from './interface';
2
3
  /**
3
4
  * Tries to get the locale, in order of priority:
@@ -6,7 +7,8 @@ import type { TLink, TUseLinkReturn } from './interface';
6
7
  * 3. The locale from next/navigation `useParams`
7
8
  * @returns The best matched locale
8
9
  */
9
- export declare function useLinkLocale(props: TLink): any;
10
+ export declare function useLinkLocale(props: TLink): string | false;
11
+ export declare function localizeHref(href: LinkProps['href'], locale: LinkProps['locale']): string;
10
12
  /**
11
13
  * @params {props.locale} - The direct locale prop always gets priority. If no `locale` prop is provided, the prop will try to fall back to react-aria `useLocale` and then next/navigation `useParams`. If a locale is found, it will be automatically prepended to the href. Otherwise, href will be returned as is.
12
14
  */