next-language-selector 0.1.4 → 0.1.5

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { ReactNode } from 'react';
1
+ import React$1, { ReactNode, ComponentProps } from 'react';
2
2
 
3
3
  interface LocaleConfig {
4
4
  name: string;
@@ -19,8 +19,10 @@ interface LanguageSelectorProps {
19
19
  }) => ReactNode;
20
20
  }
21
21
 
22
- declare function LanguageSelector({ locales, defaultLocale, cookieName, isDropdown, renderCustom, className, activeColor, }: LanguageSelectorProps): React.JSX.Element;
22
+ declare function LanguageSelector$1(props: LanguageSelectorProps): React$1.JSX.Element;
23
23
 
24
24
  declare const setLocaleCookie: (locale: string, cookieName?: string) => void;
25
25
 
26
+ declare const LanguageSelector: (props: ComponentProps<typeof LanguageSelector$1>) => React.JSX.Element;
27
+
26
28
  export { LanguageSelector, type LanguageSelectorProps, type LocaleConfig, setLocaleCookie };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { ReactNode } from 'react';
1
+ import React$1, { ReactNode, ComponentProps } from 'react';
2
2
 
3
3
  interface LocaleConfig {
4
4
  name: string;
@@ -19,8 +19,10 @@ interface LanguageSelectorProps {
19
19
  }) => ReactNode;
20
20
  }
21
21
 
22
- declare function LanguageSelector({ locales, defaultLocale, cookieName, isDropdown, renderCustom, className, activeColor, }: LanguageSelectorProps): React.JSX.Element;
22
+ declare function LanguageSelector$1(props: LanguageSelectorProps): React$1.JSX.Element;
23
23
 
24
24
  declare const setLocaleCookie: (locale: string, cookieName?: string) => void;
25
25
 
26
+ declare const LanguageSelector: (props: ComponentProps<typeof LanguageSelector$1>) => React.JSX.Element;
27
+
26
28
  export { LanguageSelector, type LanguageSelectorProps, type LocaleConfig, setLocaleCookie };
package/dist/index.js CHANGED
@@ -20,94 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- LanguageSelector: () => LanguageSelector,
24
23
  setLocaleCookie: () => setLocaleCookie
25
24
  });
26
25
  module.exports = __toCommonJS(index_exports);
27
26
 
28
- // src/selector.tsx
29
- var import_react = require("react");
30
-
31
27
  // src/utils.ts
32
28
  var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
33
29
  if (typeof document === "undefined") return;
34
30
  document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
35
31
  window.location.reload();
36
32
  };
37
-
38
- // src/selector.tsx
39
- var import_jsx_runtime = require("react/jsx-runtime");
40
- function LanguageSelector({
41
- locales,
42
- defaultLocale,
43
- cookieName = "NEXT_LOCALE",
44
- isDropdown = true,
45
- renderCustom,
46
- className,
47
- activeColor = "red"
48
- }) {
49
- const [current, setCurrent] = (0, import_react.useState)(defaultLocale);
50
- (0, import_react.useEffect)(() => {
51
- const saved = document.cookie.split("; ").find((row) => row.startsWith(`${cookieName}=`))?.split("=")[1];
52
- if (saved) setCurrent(saved);
53
- }, [cookieName]);
54
- const handleSelect = (code) => {
55
- setCurrent(code);
56
- setLocaleCookie(code, cookieName);
57
- };
58
- if (renderCustom) {
59
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderCustom({
60
- locales,
61
- currentLocale: current,
62
- onChange: handleSelect
63
- }) });
64
- }
65
- if (!isDropdown) {
66
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
- "div",
68
- {
69
- style: { display: "flex", gap: "8px", alignItems: "center" },
70
- className,
71
- children: locales.map((l) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
72
- "button",
73
- {
74
- onClick: () => handleSelect(l.code),
75
- style: {
76
- cursor: "pointer",
77
- background: "none",
78
- border: "none",
79
- borderBottom: current === l.code ? `1px solid ${activeColor}` : "1px solid transparent",
80
- color: current === l.code ? "inherit" : "gray",
81
- fontSize: "12px",
82
- padding: "2px 4px"
83
- },
84
- children: [
85
- l.flag,
86
- " ",
87
- l.name
88
- ]
89
- },
90
- l.code
91
- ))
92
- }
93
- );
94
- }
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
96
- "select",
97
- {
98
- value: current,
99
- onChange: (e) => handleSelect(e.target.value),
100
- className,
101
- children: locales.map((l) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: l.code, children: [
102
- l.flag,
103
- " ",
104
- l.name
105
- ] }, l.code))
106
- }
107
- );
108
- }
109
33
  // Annotate the CommonJS export names for ESM import in node:
110
34
  0 && (module.exports = {
111
- LanguageSelector,
112
35
  setLocaleCookie
113
36
  });
package/dist/index.mjs CHANGED
@@ -1,85 +1,9 @@
1
- // src/selector.tsx
2
- import { useEffect, useState } from "react";
3
-
4
1
  // src/utils.ts
5
2
  var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
6
3
  if (typeof document === "undefined") return;
7
4
  document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
8
5
  window.location.reload();
9
6
  };
10
-
11
- // src/selector.tsx
12
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
- function LanguageSelector({
14
- locales,
15
- defaultLocale,
16
- cookieName = "NEXT_LOCALE",
17
- isDropdown = true,
18
- renderCustom,
19
- className,
20
- activeColor = "red"
21
- }) {
22
- const [current, setCurrent] = useState(defaultLocale);
23
- useEffect(() => {
24
- const saved = document.cookie.split("; ").find((row) => row.startsWith(`${cookieName}=`))?.split("=")[1];
25
- if (saved) setCurrent(saved);
26
- }, [cookieName]);
27
- const handleSelect = (code) => {
28
- setCurrent(code);
29
- setLocaleCookie(code, cookieName);
30
- };
31
- if (renderCustom) {
32
- return /* @__PURE__ */ jsx(Fragment, { children: renderCustom({
33
- locales,
34
- currentLocale: current,
35
- onChange: handleSelect
36
- }) });
37
- }
38
- if (!isDropdown) {
39
- return /* @__PURE__ */ jsx(
40
- "div",
41
- {
42
- style: { display: "flex", gap: "8px", alignItems: "center" },
43
- className,
44
- children: locales.map((l) => /* @__PURE__ */ jsxs(
45
- "button",
46
- {
47
- onClick: () => handleSelect(l.code),
48
- style: {
49
- cursor: "pointer",
50
- background: "none",
51
- border: "none",
52
- borderBottom: current === l.code ? `1px solid ${activeColor}` : "1px solid transparent",
53
- color: current === l.code ? "inherit" : "gray",
54
- fontSize: "12px",
55
- padding: "2px 4px"
56
- },
57
- children: [
58
- l.flag,
59
- " ",
60
- l.name
61
- ]
62
- },
63
- l.code
64
- ))
65
- }
66
- );
67
- }
68
- return /* @__PURE__ */ jsx(
69
- "select",
70
- {
71
- value: current,
72
- onChange: (e) => handleSelect(e.target.value),
73
- className,
74
- children: locales.map((l) => /* @__PURE__ */ jsxs("option", { value: l.code, children: [
75
- l.flag,
76
- " ",
77
- l.name
78
- ] }, l.code))
79
- }
80
- );
81
- }
82
7
  export {
83
- LanguageSelector,
84
8
  setLocaleCookie
85
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-language-selector",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Configurable language selector for Next.js",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",