next-language-selector 0.1.3 → 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;
@@ -8,7 +8,7 @@ interface LocaleConfig {
8
8
  interface LanguageSelectorProps {
9
9
  locales: LocaleConfig[];
10
10
  defaultLocale: string;
11
- isDropdown: boolean;
11
+ isDropdown?: boolean;
12
12
  cookieName?: string;
13
13
  activeColor?: string;
14
14
  className?: string;
@@ -19,8 +19,10 @@ interface LanguageSelectorProps {
19
19
  }) => ReactNode;
20
20
  }
21
21
 
22
- declare const 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;
@@ -8,7 +8,7 @@ interface LocaleConfig {
8
8
  interface LanguageSelectorProps {
9
9
  locales: LocaleConfig[];
10
10
  defaultLocale: string;
11
- isDropdown: boolean;
11
+ isDropdown?: boolean;
12
12
  cookieName?: string;
13
13
  activeColor?: string;
14
14
  className?: string;
@@ -19,8 +19,10 @@ interface LanguageSelectorProps {
19
19
  }) => ReactNode;
20
20
  }
21
21
 
22
- declare const 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 ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ setLocaleCookie: () => setLocaleCookie
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/utils.ts
28
+ var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
29
+ if (typeof document === "undefined") return;
30
+ document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
31
+ window.location.reload();
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ setLocaleCookie
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
- var 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,14 +1,16 @@
1
1
  {
2
2
  "name": "next-language-selector",
3
- "version": "0.1.3",
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",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
12
+ "require": "./dist/index.cjs",
13
+ "default": "./dist/index.mjs"
12
14
  }
13
15
  },
14
16
  "scripts": {
@@ -25,6 +27,7 @@
25
27
  "keywords": [
26
28
  "next.js",
27
29
  "i18n",
30
+ "language",
28
31
  "language-selector",
29
32
  "internationalization",
30
33
  "react",
@@ -46,5 +49,6 @@
46
49
  "tslib": "^2.8.1",
47
50
  "tsup": "^8.5.1",
48
51
  "typescript": "^5.9.3"
49
- }
52
+ },
53
+ "sideEffects": false
50
54
  }
package/dist/index.cjs DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- LanguageSelector: () => LanguageSelector,
24
- setLocaleCookie: () => setLocaleCookie
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/selector.tsx
29
- var import_react = require("react");
30
-
31
- // src/utils.ts
32
- var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
33
- if (typeof document === "undefined") return;
34
- document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
35
- window.location.reload();
36
- };
37
-
38
- // src/selector.tsx
39
- var import_jsx_runtime = require("react/jsx-runtime");
40
- var 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
- // Annotate the CommonJS export names for ESM import in node:
110
- 0 && (module.exports = {
111
- LanguageSelector,
112
- setLocaleCookie
113
- });