clxx 3.0.0 → 3.0.2

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.
@@ -1,21 +1,34 @@
1
1
  import { showCitySelect } from "@";
2
- import { useEffect } from "react";
3
2
 
4
3
  export default function Index() {
5
4
  return (
6
- <button
7
- onClick={() => {
8
- showCitySelect({
9
- onSelect: (city) => {
10
- console.log("选择了城市:", city);
11
- },
12
- getLocation() {
13
- return "北京";
14
- },
15
- });
16
- }}
17
- >
18
- 选择城市
19
- </button>
5
+ <div style={{ display: "flex", flexDirection: "column", gap: "0.2rem", padding: "0.3rem" }}>
6
+ <button
7
+ onClick={() => {
8
+ showCitySelect({
9
+ onSelect: (city) => {
10
+ console.log("选择了城市:", city);
11
+ },
12
+ getLocation() {
13
+ return "北京";
14
+ },
15
+ });
16
+ }}
17
+ >
18
+ 选择城市(默认:不含港澳台)
19
+ </button>
20
+ <button
21
+ onClick={() => {
22
+ showCitySelect({
23
+ taiwanHKMacau: true,
24
+ onSelect: (city) => {
25
+ console.log("选择了城市:", city);
26
+ },
27
+ });
28
+ }}
29
+ >
30
+ 选择城市(含港澳台)
31
+ </button>
32
+ </div>
20
33
  );
21
34
  }
@@ -1,6 +1,12 @@
1
1
  import { showRegionPicker } from "@";
2
2
  import { useState } from "react";
3
3
 
4
+ // 部分城市无区级,district 可能为 null
5
+ const formatSelection = (sel) =>
6
+ sel.district
7
+ ? `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`
8
+ : `${sel.province.label} / ${sel.city.label}`;
9
+
4
10
  export default function RegionPickerDemo() {
5
11
  const [result, setResult] = useState("");
6
12
  const [initial, setInitial] = useState(null);
@@ -9,9 +15,12 @@ export default function RegionPickerDemo() {
9
15
  showRegionPicker({
10
16
  value: initial || undefined,
11
17
  onConfirm: (sel) => {
12
- const text = `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`;
13
- setResult(text);
14
- setInitial([sel.province.value, sel.city.value, sel.district.value]);
18
+ setResult(formatSelection(sel));
19
+ setInitial([
20
+ sel.province.value,
21
+ sel.city.value,
22
+ sel.district?.value,
23
+ ]);
15
24
  },
16
25
  onCancel: () => {
17
26
  console.log("取消选择");
@@ -25,9 +34,7 @@ export default function RegionPickerDemo() {
25
34
  value: ["440000", "440100", "440106"],
26
35
  title: "带初始值",
27
36
  onConfirm: (sel) => {
28
- setResult(
29
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
30
- );
37
+ setResult(formatSelection(sel));
31
38
  },
32
39
  });
33
40
  };
@@ -37,9 +44,7 @@ export default function RegionPickerDemo() {
37
44
  primary: "#e53935",
38
45
  title: "京东红主题",
39
46
  onConfirm: (sel) => {
40
- setResult(
41
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
42
- );
47
+ setResult(formatSelection(sel));
43
48
  },
44
49
  });
45
50
  };
@@ -49,9 +54,7 @@ export default function RegionPickerDemo() {
49
54
  rounded: false,
50
55
  title: "无圆角",
51
56
  onConfirm: (sel) => {
52
- setResult(
53
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
54
- );
57
+ setResult(formatSelection(sel));
55
58
  },
56
59
  });
57
60
  };
@@ -63,9 +66,7 @@ export default function RegionPickerDemo() {
63
66
  confirmText: "选好了",
64
67
  title: "自定义文案",
65
68
  onConfirm: (sel) => {
66
- setResult(
67
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
68
- );
69
+ setResult(formatSelection(sel));
69
70
  },
70
71
  });
71
72
  };
@@ -75,9 +76,7 @@ export default function RegionPickerDemo() {
75
76
  maskClosable: false,
76
77
  title: "点击遮罩不关闭",
77
78
  onConfirm: (sel) => {
78
- setResult(
79
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
80
- );
79
+ setResult(formatSelection(sel));
81
80
  },
82
81
  });
83
82
  };
@@ -93,9 +92,17 @@ export default function RegionPickerDemo() {
93
92
  cancelText: <span style={{ color: "#ef4444" }}>✕ 关</span>,
94
93
  confirmText: <strong>OK ✓</strong>,
95
94
  onConfirm: (sel) => {
96
- setResult(
97
- `${sel.province.label} / ${sel.city.label} / ${sel.district.label}`,
98
- );
95
+ setResult(formatSelection(sel));
96
+ },
97
+ });
98
+ };
99
+
100
+ const openWithHKMOTW = () => {
101
+ showRegionPicker({
102
+ taiwanHKMacau: true,
103
+ title: "含港澳台",
104
+ onConfirm: (sel) => {
105
+ setResult(formatSelection(sel));
99
106
  },
100
107
  });
101
108
  };
@@ -110,6 +117,7 @@ export default function RegionPickerDemo() {
110
117
  <button onClick={openCustomLabels}>自定义 tab 占位 / 按钮文案</button>
111
118
  <button onClick={openNoMaskClose}>点击遮罩不关闭</button>
112
119
  <button onClick={openReactNodeTitle}>ReactNode 标题/按钮</button>
120
+ <button onClick={openWithHKMOTW}>含港澳台</button>
113
121
  </div>
114
122
  <div style={{ marginTop: "0.4rem", fontSize: "0.3rem" }}>
115
123
  选择结果: