@xhsreds/reds-rn-next 0.0.2-beta20240708190837 → 0.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.
Files changed (140) hide show
  1. package/coverage/coverage-final.json +8 -5
  2. package/lib/cjs/_chunks/{Dx-JjEWA.js → CAyGJuk1.js} +27 -1
  3. package/lib/cjs/_chunks/{Dx-JjEWA.js.map → CAyGJuk1.js.map} +1 -1
  4. package/lib/cjs/_chunks/DiJl2cva.js +49 -0
  5. package/lib/cjs/_chunks/DiJl2cva.js.map +1 -0
  6. package/lib/cjs/components/Button/index.js +1 -1
  7. package/lib/cjs/components/Button/index.js.map +1 -1
  8. package/lib/cjs/components/Button/interface/index.js +12 -0
  9. package/lib/cjs/components/Button/interface/index.js.map +1 -1
  10. package/lib/cjs/components/ConfigProvider/ConfigProvider.js +15 -0
  11. package/lib/cjs/components/ConfigProvider/ConfigProvider.js.map +1 -0
  12. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/ConfigCache.js +147 -0
  13. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/ConfigCache.js.map +1 -0
  14. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/index.js +10 -0
  15. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/index.js.map +1 -0
  16. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/interface.js +3 -0
  17. package/lib/cjs/components/ConfigProvider/hooks/ConfigCache/interface.js.map +1 -0
  18. package/lib/cjs/components/ConfigProvider/hooks/ConfigContext/ConfigContext.js +10 -0
  19. package/lib/cjs/components/ConfigProvider/hooks/ConfigContext/ConfigContext.js.map +1 -0
  20. package/lib/cjs/components/ConfigProvider/hooks/themeToken/useThemeToken.js +24 -0
  21. package/lib/cjs/components/ConfigProvider/hooks/themeToken/useThemeToken.js.map +1 -0
  22. package/lib/cjs/components/ConfigProvider/index.js +17 -0
  23. package/lib/cjs/components/ConfigProvider/index.js.map +1 -0
  24. package/lib/cjs/components/ConfigProvider/interface/index.js +3 -0
  25. package/lib/cjs/components/ConfigProvider/interface/index.js.map +1 -0
  26. package/lib/cjs/components/Popover/component.js +1 -1
  27. package/lib/cjs/components/Popover/hook.js +1 -1
  28. package/lib/cjs/components/Popover/index.js +4 -4
  29. package/lib/cjs/components/Popover/index.js.map +1 -1
  30. package/lib/cjs/components/Switch/index.js +8 -6
  31. package/lib/cjs/components/Switch/index.js.map +1 -1
  32. package/lib/cjs/components/Switch/interface/index.js +2 -2
  33. package/lib/cjs/components/Switch/interface/index.js.map +1 -1
  34. package/lib/cjs/index.js +7 -1
  35. package/lib/cjs/index.js.map +1 -1
  36. package/lib/esm/_chunks/{Bm4Re-8r.js → BHmvJnIm.js} +25 -2
  37. package/lib/esm/_chunks/{Bm4Re-8r.js.map → BHmvJnIm.js.map} +1 -1
  38. package/lib/esm/_chunks/Br6Ked0G.js +46 -0
  39. package/lib/esm/_chunks/Br6Ked0G.js.map +1 -0
  40. package/lib/esm/components/Button/index.js +1 -1
  41. package/lib/esm/components/Button/index.js.map +1 -1
  42. package/lib/esm/components/Button/interface/index.js +11 -0
  43. package/lib/esm/components/Button/interface/index.js.map +1 -1
  44. package/lib/esm/components/ConfigProvider/ConfigProvider.js +7 -0
  45. package/lib/esm/components/ConfigProvider/ConfigProvider.js.map +1 -0
  46. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/ConfigCache.js +145 -0
  47. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/ConfigCache.js.map +1 -0
  48. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/index.js +4 -0
  49. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/index.js.map +1 -0
  50. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/interface.js +2 -0
  51. package/lib/esm/components/ConfigProvider/hooks/ConfigCache/interface.js.map +1 -0
  52. package/lib/esm/components/ConfigProvider/hooks/ConfigContext/ConfigContext.js +8 -0
  53. package/lib/esm/components/ConfigProvider/hooks/ConfigContext/ConfigContext.js.map +1 -0
  54. package/lib/esm/components/ConfigProvider/hooks/themeToken/useThemeToken.js +22 -0
  55. package/lib/esm/components/ConfigProvider/hooks/themeToken/useThemeToken.js.map +1 -0
  56. package/lib/esm/components/ConfigProvider/index.js +12 -0
  57. package/lib/esm/components/ConfigProvider/index.js.map +1 -0
  58. package/lib/esm/components/ConfigProvider/interface/index.js +2 -0
  59. package/lib/esm/components/ConfigProvider/interface/index.js.map +1 -0
  60. package/lib/esm/components/Popover/component.js +1 -1
  61. package/lib/esm/components/Popover/hook.js +1 -1
  62. package/lib/esm/components/Popover/index.js +4 -4
  63. package/lib/esm/components/Popover/index.js.map +1 -1
  64. package/lib/esm/components/Switch/index.js +9 -7
  65. package/lib/esm/components/Switch/index.js.map +1 -1
  66. package/lib/esm/components/Switch/interface/index.js +3 -3
  67. package/lib/esm/components/Switch/interface/index.js.map +1 -1
  68. package/lib/esm/index.js +5 -1
  69. package/lib/esm/index.js.map +1 -1
  70. package/lib/types/src/components/Button/index.d.ts +4 -0
  71. package/lib/types/src/components/Button/interface/index.d.ts +11 -0
  72. package/lib/types/src/components/ConfigProvider/ConfigProvider.d.ts +4 -0
  73. package/lib/types/src/components/ConfigProvider/hooks/ConfigCache/ConfigCache.d.ts +22 -0
  74. package/lib/types/src/components/ConfigProvider/hooks/ConfigCache/index.d.ts +1 -0
  75. package/lib/types/src/components/ConfigProvider/hooks/ConfigCache/interface.d.ts +36 -0
  76. package/lib/types/src/components/ConfigProvider/hooks/ConfigContext/ConfigContext.d.ts +5 -0
  77. package/lib/types/src/components/ConfigProvider/hooks/themeToken/useThemeToken.d.ts +8 -0
  78. package/lib/types/src/components/ConfigProvider/index.d.ts +3 -0
  79. package/lib/types/src/components/ConfigProvider/interface/index.d.ts +27 -0
  80. package/lib/types/src/components/Popover/component.d.ts +13 -0
  81. package/lib/types/src/components/Popover/hook.d.ts +66 -0
  82. package/lib/types/src/components/Popover/index.d.ts +4 -0
  83. package/lib/types/src/components/Popover/interface/index.d.ts +13 -0
  84. package/lib/types/src/components/Popover/manifest.d.ts +3 -0
  85. package/lib/types/src/components/Switch/index.d.ts +7 -0
  86. package/lib/types/src/components/Switch/interface/index.d.ts +11 -0
  87. package/lib/types/src/index.d.ts +5 -0
  88. package/package.json +8 -4
  89. package/rollup.config.js +25 -25
  90. package/src/components/Button/demo/index.jsx +50 -0
  91. package/src/components/Button/demo/index.tsx +50 -0
  92. package/src/components/Button/doc/index.mdx +18 -0
  93. package/src/components/Button/index.tsx +0 -1
  94. package/src/components/Button/interface/index.ts +17 -29
  95. package/src/components/Button/test/index.bench.tsx +18 -0
  96. package/src/components/Button/test/index.test.tsx +9 -0
  97. package/src/components/ConfigProvider/ConfigProvider.tsx +48 -0
  98. package/src/components/ConfigProvider/demo/base.jsx +114 -0
  99. package/src/components/ConfigProvider/demo/index.jsx +50 -0
  100. package/src/components/ConfigProvider/demo/index.tsx +50 -0
  101. package/src/components/ConfigProvider/demo/token.jsx +8 -0
  102. package/src/components/ConfigProvider/doc/index.mdx +22 -0
  103. package/src/components/ConfigProvider/doc/token.mdx +7 -0
  104. package/src/components/ConfigProvider/hooks/ConfigCache/ConfigCache.ts +115 -0
  105. package/src/components/ConfigProvider/hooks/ConfigCache/index.ts +1 -0
  106. package/src/components/ConfigProvider/hooks/ConfigCache/interface.ts +38 -0
  107. package/src/components/ConfigProvider/hooks/ConfigContext/ConfigContext.ts +9 -0
  108. package/src/components/ConfigProvider/hooks/themeToken/useThemeToken.ts +33 -0
  109. package/src/components/ConfigProvider/index.ts +4 -0
  110. package/src/components/ConfigProvider/interface/index.ts +28 -0
  111. package/src/components/ConfigProvider/test/index.bench.tsx +18 -0
  112. package/src/components/ConfigProvider/test/index.test.tsx +9 -0
  113. package/src/components/Popover/demo/{base.jsx → index.tsx} +2 -2
  114. package/src/components/Popover/doc/index.mdx +21 -15
  115. package/src/components/Popover/index.tsx +3 -3
  116. package/src/components/Switch/demo/{base.jsx → index.tsx} +9 -6
  117. package/src/components/Switch/doc/index.mdx +14 -12
  118. package/src/components/Switch/index.tsx +9 -6
  119. package/src/components/Switch/interface/index.ts +3 -3
  120. package/src/components/Switch/test/index.bench.tsx +2 -5
  121. package/src/components/Switch/test/index.test.tsx +11 -23
  122. package/src/index.ts +2 -1
  123. package/tsconfig.json +2 -2
  124. package/lib/cjs/components/Button/common/index.js +0 -11
  125. package/lib/cjs/components/Button/common/index.js.map +0 -1
  126. package/lib/cjs/components/Button/rn/index.js +0 -25
  127. package/lib/cjs/components/Button/rn/index.js.map +0 -1
  128. package/lib/cjs/index.d.ts +0 -37
  129. package/lib/cjs/index.d.ts.map +0 -1
  130. package/lib/cjs/utils/hook.js +0 -3
  131. package/lib/cjs/utils/hook.js.map +0 -1
  132. package/lib/esm/components/Button/common/index.js +0 -9
  133. package/lib/esm/components/Button/common/index.js.map +0 -1
  134. package/lib/esm/components/Button/rn/index.js +0 -21
  135. package/lib/esm/components/Button/rn/index.js.map +0 -1
  136. package/lib/esm/utils/hook.js +0 -2
  137. package/lib/esm/utils/hook.js.map +0 -1
  138. package/src/components/Button/common/index.ts +0 -6
  139. package/src/components/Button/rn/index.tsx +0 -20
  140. package/src/utils/hook.ts +0 -0
package/rollup.config.js CHANGED
@@ -49,29 +49,29 @@ module.exports = [
49
49
  ],
50
50
  external: [...externalDeps, ...externalPeerDeps],
51
51
  },
52
- {
53
- input: "src/index.ts",
54
- output: [
55
- {
56
- dir: "./lib/cjs",
57
- format: "cjs",
58
- sourcemap: true,
59
- chunkFileNames: "_chunks/[hash].js",
60
- exports: "named",
61
- },
62
- ],
63
- plugins: [
64
- multiInput({ relative: "src/" }),
65
- esbuild({}),
66
- babel({
67
- presets: ["@babel/preset-env", "@babel/preset-react"],
68
- extensions: [".js", ".jsx", ".es6", ".es", ".mjs", ".vue", ".ts", ".tsx"],
69
- }),
70
- commonjs({}),
71
- resolve({}),
72
- json(),
73
- dts(),
74
- ],
75
- external: [...externalDeps, ...externalPeerDeps],
76
- },
52
+ // {
53
+ // input: "src/index.ts",
54
+ // output: [
55
+ // {
56
+ // dir: "./lib/cjs",
57
+ // format: "cjs",
58
+ // sourcemap: true,
59
+ // chunkFileNames: "_chunks/[hash].js",
60
+ // exports: "named",
61
+ // },
62
+ // ],
63
+ // plugins: [
64
+ // multiInput({ relative: "src/" }),
65
+ // esbuild({}),
66
+ // babel({
67
+ // presets: ["@babel/preset-env", "@babel/preset-react"],
68
+ // extensions: [".js", ".jsx", ".es6", ".es", ".mjs", ".vue", ".ts", ".tsx"],
69
+ // }),
70
+ // commonjs({}),
71
+ // resolve({}),
72
+ // json(),
73
+ // dts(),
74
+ // ],
75
+ // external: [...externalDeps, ...externalPeerDeps],
76
+ // },
77
77
  ];
@@ -0,0 +1,50 @@
1
+ import React, { useRef, useEffect, useState } from "react";
2
+ import { View, Text, StyleSheet, FlatList, ScrollView } from "react-native";
3
+ import { Button } from "@xhs/reds-rn-next";
4
+
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1,
8
+ justifyContent: "center",
9
+ paddingTop: 100,
10
+ paddingBottom: 100,
11
+ },
12
+ scrollView: {
13
+ backgroundColor: "pink",
14
+ },
15
+ root: {
16
+ flex: 1,
17
+ backgroundColor: "blue",
18
+ },
19
+ });
20
+ const Desc = ({ children = "" }) => {
21
+ return <Text>{children}</Text>;
22
+ };
23
+ const Br = (props) => <View style={{ height: props.height || 20 }}></View>;
24
+
25
+ export default function App() {
26
+ const [value, setValue] = useState(false);
27
+ const [valueStr, setValueStr] = useState(value.toString());
28
+ const onClick = (e) => setValue((v) => !v);
29
+ const onChange = (v) => setValueStr(v.toString());
30
+ return (
31
+ <View style={styles.container}>
32
+ <Desc>默认用法</Desc>
33
+ <Button></Button>
34
+ <Br />
35
+
36
+ <Desc>设置默认值</Desc>
37
+ <Button defaultValue={true}></Button>
38
+ <Br />
39
+
40
+ <Desc>修改开关颜色</Desc>
41
+ <Button trackOnColor={"#1b8bcd"} trackOffColor={"#da36c9"}></Button>
42
+ <Br />
43
+
44
+ <Desc>受控用法</Desc>
45
+ <Text>当前值:{valueStr}</Text>
46
+ <Button value={value} onClick={onClick} onChange={onChange}></Button>
47
+ <Br />
48
+ </View>
49
+ );
50
+ }
@@ -0,0 +1,50 @@
1
+ import React, { useRef, useEffect, useState } from "react";
2
+ import { View, Text, StyleSheet, FlatList, ScrollView } from "react-native";
3
+ import { Button } from "@xhs/reds-rn-next";
4
+
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1,
8
+ justifyContent: "center",
9
+ paddingTop: 100,
10
+ paddingBottom: 100,
11
+ },
12
+ scrollView: {
13
+ backgroundColor: "pink",
14
+ },
15
+ root: {
16
+ flex: 1,
17
+ backgroundColor: "blue",
18
+ },
19
+ });
20
+ const Desc = ({ children = "" }) => {
21
+ return <Text>{children}</Text>;
22
+ };
23
+ const Br = (props) => <View style={{ height: props.height || 20 }}></View>;
24
+
25
+ export default function App() {
26
+ const [value, setValue] = useState(false);
27
+ const [valueStr, setValueStr] = useState(value.toString());
28
+ const onClick = (e) => setValue((v) => !v);
29
+ const onChange = (v) => setValueStr(v.toString());
30
+ return (
31
+ <View style={styles.container}>
32
+ <Desc>默认用法</Desc>
33
+ <Button></Button>
34
+ <Br />
35
+
36
+ <Desc>设置默认值</Desc>
37
+ <Button defaultValue={true}></Button>
38
+ <Br />
39
+
40
+ <Desc>修改开关颜色</Desc>
41
+ <Button trackOnColor={"#1b8bcd"} trackOffColor={"#da36c9"}></Button>
42
+ <Br />
43
+
44
+ <Desc>受控用法</Desc>
45
+ <Text>当前值:{valueStr}</Text>
46
+ <Button value={value} onClick={onClick} onChange={onChange}></Button>
47
+ <Br />
48
+ </View>
49
+ );
50
+ }
@@ -0,0 +1,18 @@
1
+ ## API
2
+
3
+ ### Props
4
+
5
+ | 属性 | 描述 | 类型 | 默认值 |
6
+ | --------------- | ---------------- | ------- | --------------------- |
7
+ | value | 当前的状态 | boolean | |
8
+ | default-value | 默认状态 | boolean | false |
9
+ | disabled | 是否显示气泡 | boolean | false |
10
+ | track-on-color | 开关开启时的颜色 | string | rgba(255, 36, 66, 1) |
11
+ | track-off-color | 开关关闭时的颜色 | string | rgba(48, 48, 52, 0.1) |
12
+
13
+ ### Events
14
+
15
+ | 事件 | 描述 | 类型 | 默认值 |
16
+ | ------ | ------------------ | ------------------------ | ------ |
17
+ | change | 当值发生变化时触发 | (value: boolean) => void | |
18
+ | click | 被点击时触发 | (value: Event) => void | |
@@ -4,7 +4,6 @@ import { Text, View } from "react-native";
4
4
  export default forwardRef<View>((props: any, ref) => {
5
5
  return (
6
6
  <View
7
- // onPress={(e) => props?.onPress?.(e)}
8
7
  ref={ref}
9
8
  style={{
10
9
  paddingLeft: 24,
@@ -1,33 +1,21 @@
1
- /**
2
- * 按钮大小
3
- */
4
- export type ButtonSize = "mini" | "small" | "medium" | "large" | "extraLarge";
1
+ import { GestureResponderEvent } from "react-native";
2
+ import { lightColor } from "@xhs/reds-token-next";
5
3
 
6
- /**
7
- * 按钮类型
8
- */
9
- export type ButtonType = "primary" | "outlined" | "text" | "dark" | "filledGray" | "outlinedGray";
10
-
11
- /**
12
- * button
13
- */
14
4
  export interface RedsButton {
15
- name?: string;
16
- size?: ButtonSize;
17
- /**
18
- * 图标
19
- */
20
- icon?: string;
21
- /**
22
- * 按钮失效状态
23
- */
5
+ value?: boolean;
6
+ defaultValue?: boolean;
24
7
  disabled?: boolean;
25
- type?: ButtonType;
26
- /**
27
- * 将按钮宽度调整为其父宽度的选项
28
- */
29
- block?: boolean;
30
- active?: boolean;
31
- fixedWidth?: string;
32
- loading?: boolean;
8
+ onClick?: (event: GestureResponderEvent) => void;
9
+ onChange?: (value: boolean) => void;
10
+ trackOnColor?: string;
11
+ trackOffColor?: string;
33
12
  }
13
+
14
+ export const defaultProps: RedsButton = {
15
+ defaultValue: false,
16
+ disabled: false,
17
+ onClick: (event: GestureResponderEvent) => {},
18
+ onChange: (value: boolean) => {},
19
+ trackOnColor: lightColor.Primary,
20
+ trackOffColor: lightColor.Fill2,
21
+ };
@@ -0,0 +1,18 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { render, fireEvent, userEvent } from "@testing-library/react-native";
3
+ import "@testing-library/react-native/extend-expect";
4
+ import { Pressable, Text, View } from "react-native";
5
+ import Button from "../index";
6
+
7
+ describe("Button", () => {
8
+ it(":base", async () => {
9
+ let isOn = false;
10
+ const wrapper = render(<Button onChange={(v) => (isOn = v)}></Button>);
11
+ expect(wrapper.UNSAFE_root.props.defaultValue).toBe(false);
12
+ await fireEvent(wrapper.UNSAFE_root.children[0], "press");
13
+ expect(isOn).toBe(true);
14
+
15
+ await fireEvent(wrapper.UNSAFE_root.children[0], "press");
16
+ expect(isOn).toBe(false);
17
+ });
18
+ });
@@ -0,0 +1,9 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { render, fireEvent, userEvent } from "@testing-library/react-native";
3
+ import "@testing-library/react-native/extend-expect";
4
+ import { Pressable, Text, View } from "react-native";
5
+ import Button from "../index";
6
+
7
+ describe("Button", () => {
8
+ it(":base", async () => {});
9
+ });
@@ -0,0 +1,48 @@
1
+ import { ConfigProviderProps } from "./interface";
2
+ import { configCache } from "./hooks/ConfigCache/ConfigCache";
3
+ import { ConfigProviderContext, IConfigProviderContext } from "./hooks/ConfigContext/ConfigContext";
4
+
5
+ const ConfigProvider = (props: ConfigProviderProps) => {
6
+ const {
7
+ id = "root",
8
+ theme = {
9
+ colorMode: "light",
10
+ inherit: true,
11
+ },
12
+ parentId = "root",
13
+ children,
14
+ } = props;
15
+
16
+ const themeCache = {
17
+ colorMode: theme.colorMode || "light",
18
+ token: {
19
+ lightColor: {
20
+ ...theme.token?.lightColor,
21
+ },
22
+ darkColor: {
23
+ ...theme.token?.darkColor,
24
+ },
25
+ alwaysColor: {
26
+ ...theme.token?.alwaysColor,
27
+ },
28
+ components: {
29
+ ...theme.token?.components,
30
+ },
31
+ },
32
+ inherit: theme.inherit,
33
+ };
34
+
35
+ configCache.addNewConfigCache({
36
+ id,
37
+ themeCache,
38
+ parentId,
39
+ });
40
+
41
+ const configProviderContextValue: IConfigProviderContext = {
42
+ id: id,
43
+ };
44
+
45
+ return <ConfigProviderContext.Provider value={configProviderContextValue}>{children}</ConfigProviderContext.Provider>;
46
+ };
47
+
48
+ export default ConfigProvider;
@@ -0,0 +1,114 @@
1
+ import { useState } from "react";
2
+ import { Text, TouchableOpacity } from "react-native";
3
+ import { ConfigProvider, useThemeColor } from "@xhs/reds-rn-next";
4
+
5
+ const App = () => {
6
+ const themeColor = useThemeColor();
7
+ return (
8
+ <View style={{ height: 200, backgroundColor: themeColor.Bg }}>
9
+ <Text style={{ color: themeColor.Info }}>切换主题文字展示</Text>
10
+ </View>
11
+ );
12
+ };
13
+
14
+ const App2 = () => {
15
+ const themeColor = useThemeColor();
16
+ return (
17
+ <View style={{ height: 200, backgroundColor: themeColor.Bg }}>
18
+ <Text style={{ color: themeColor.Info }}>主题定制文字展示</Text>
19
+ </View>
20
+ );
21
+ };
22
+
23
+ export default () => {
24
+ // 切换主题
25
+ const [colorMode, setColorMode] = useState < ColorMode > "light";
26
+ const changeColorMode = () => {
27
+ setColorMode((preColorMode) => (preColorMode === "light" ? "dark" : "light"));
28
+ };
29
+
30
+ // 主题定制
31
+ const [colorMode2, setColorMode2] = useState < ColorMode > "light";
32
+ const [infoLightColor, setInfoLightColor] = useState < string > "red";
33
+ const [infoDarkColor, setInfoDarkColor] = useState < string > "black";
34
+ const changeInfoToken = () => {
35
+ setInfoLightColor((preInfoLightColor) => (preInfoLightColor === "red" ? "blue" : "red"));
36
+ setInfoDarkColor((preInfoDarkColor) => (preInfoDarkColor === "black" ? "white" : "black"));
37
+ };
38
+ const changeColorMode2 = () => {
39
+ setColorMode2((preColorMode) => (preColorMode === "light" ? "dark" : "light"));
40
+ };
41
+
42
+ // 组件级主题定制
43
+ const [colorMode3, setColorMode3] = useState < ColorMode > "light";
44
+ const [infoLightColor3, setInfoLightColor3] = useState < string > "red";
45
+ const [infoDarkColor3, setInfoDarkColor3] = useState < string > "black";
46
+ const changeInfoToken3 = () => {
47
+ setInfoLightColor3((preInfoLightColor) => (preInfoLightColor === "red" ? "blue" : "red"));
48
+ setInfoDarkColor3((preInfoDarkColor) => (preInfoDarkColor === "black" ? "white" : "black"));
49
+ };
50
+ const changeColorMode3 = () => {
51
+ setColorMode3((preColorMode) => (preColorMode === "light" ? "dark" : "light"));
52
+ };
53
+
54
+ return (
55
+ <>
56
+ <TouchableOpacity onPress={changeColorMode}>
57
+ <Text>切换主题</Text>
58
+ </TouchableOpacity>
59
+ <ConfigProvider
60
+ theme={{
61
+ colorMode: colorMode,
62
+ }}
63
+ >
64
+ <App />
65
+ </ConfigProvider>
66
+ <TouchableOpacity onPress={changeColorMode2}>
67
+ <Text>切换主题</Text>
68
+ </TouchableOpacity>
69
+ <TouchableOpacity onPress={changeInfoToken}>
70
+ <Text>主题定制</Text>
71
+ </TouchableOpacity>
72
+ <ConfigProvider
73
+ theme={{
74
+ colorMode: colorMode2,
75
+ token: {
76
+ lightColor: {
77
+ Info: infoLightColor,
78
+ },
79
+ darkColor: {
80
+ Info: infoDarkColor,
81
+ },
82
+ },
83
+ }}
84
+ >
85
+ <App2 />
86
+ </ConfigProvider>
87
+ <TouchableOpacity onPress={changeColorMode3}>
88
+ <Text>切换主题</Text>
89
+ </TouchableOpacity>
90
+ <TouchableOpacity onPress={changeInfoToken3}>
91
+ <Text>组件级主题切换</Text>
92
+ </TouchableOpacity>
93
+ <ConfigProvider
94
+ theme={{
95
+ colorMode: colorMode3,
96
+ token: {
97
+ components: {
98
+ Button: {
99
+ lightColor: {
100
+ Info: infoLightColor3,
101
+ },
102
+ darkColor: {
103
+ Info: infoDarkColor3,
104
+ },
105
+ },
106
+ },
107
+ },
108
+ }}
109
+ >
110
+ <App />
111
+ </ConfigProvider>
112
+ </>
113
+ );
114
+ };
@@ -0,0 +1,50 @@
1
+ import React, { useRef, useEffect, useState } from "react";
2
+ import { View, Text, StyleSheet, FlatList, ScrollView } from "react-native";
3
+ import { ConfigProvider, Button } from "@xhs/reds-rn-next";
4
+
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1,
8
+ justifyContent: "center",
9
+ paddingTop: 100,
10
+ paddingBottom: 100,
11
+ },
12
+ scrollView: {
13
+ backgroundColor: "pink",
14
+ },
15
+ root: {
16
+ flex: 1,
17
+ backgroundColor: "blue",
18
+ },
19
+ });
20
+ const Desc = ({ children = "" }) => {
21
+ return <Text>{children}</Text>;
22
+ };
23
+ const Br = (props) => <View style={{ height: props.height || 20 }}></View>;
24
+
25
+ export default function App() {
26
+ const [value, setValue] = useState(false);
27
+ const [valueStr, setValueStr] = useState(value.toString());
28
+ const onClick = (e) => setValue((v) => !v);
29
+ const onChange = (v) => setValueStr(v.toString());
30
+ return (
31
+ <View style={styles.container}>
32
+ <Desc>默认用法</Desc>
33
+ <ConfigProvider></ConfigProvider>
34
+ <Br />
35
+
36
+ <Desc>设置默认值</Desc>
37
+ <ConfigProvider defaultValue={true}></ConfigProvider>
38
+ <Br />
39
+
40
+ <Desc>修改开关颜色</Desc>
41
+ <ConfigProvider trackOnColor={"#1b8bcd"} trackOffColor={"#da36c9"}></ConfigProvider>
42
+ <Br />
43
+
44
+ <Desc>受控用法</Desc>
45
+ <Text>当前值:{valueStr}</Text>
46
+ <ConfigProvider value={value} onClick={onClick} onChange={onChange}></ConfigProvider>
47
+ <Br />
48
+ </View>
49
+ );
50
+ }
@@ -0,0 +1,50 @@
1
+ import React, { useRef, useEffect, useState } from "react";
2
+ import { View, Text, StyleSheet, FlatList, ScrollView } from "react-native";
3
+ import { ConfigProvider } from "@xhs/reds-rn-next";
4
+
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1,
8
+ justifyContent: "center",
9
+ paddingTop: 100,
10
+ paddingBottom: 100,
11
+ },
12
+ scrollView: {
13
+ backgroundColor: "pink",
14
+ },
15
+ root: {
16
+ flex: 1,
17
+ backgroundColor: "blue",
18
+ },
19
+ });
20
+ const Desc = ({ children = "" }) => {
21
+ return <Text>{children}</Text>;
22
+ };
23
+ const Br = (props) => <View style={{ height: props.height || 20 }}></View>;
24
+
25
+ export default function App() {
26
+ const [value, setValue] = useState(false);
27
+ const [valueStr, setValueStr] = useState(value.toString());
28
+ const onClick = (e) => setValue((v) => !v);
29
+ const onChange = (v) => setValueStr(v.toString());
30
+ return (
31
+ <View style={styles.container}>
32
+ <Desc>默认用法</Desc>
33
+ <ConfigProvider></ConfigProvider>
34
+ <Br />
35
+
36
+ <Desc>设置默认值</Desc>
37
+ <ConfigProvider defaultValue={true}></ConfigProvider>
38
+ <Br />
39
+
40
+ <Desc>修改开关颜色</Desc>
41
+ <ConfigProvider trackOnColor={"#1b8bcd"} trackOffColor={"#da36c9"}></ConfigProvider>
42
+ <Br />
43
+
44
+ <Desc>受控用法</Desc>
45
+ <Text>当前值:{valueStr}</Text>
46
+ <ConfigProvider value={value} onClick={onClick} onChange={onChange}></ConfigProvider>
47
+ <Br />
48
+ </View>
49
+ );
50
+ }
@@ -0,0 +1,8 @@
1
+ import { Text } from "react-native";
2
+ import { useThemeColor } from "@xhs/reds-rn-next";
3
+
4
+ export default () => {
5
+ const themeColor = useThemeColor();
6
+
7
+ return <Text style={{ color: themeColor.Info }}>使用 Token </Text>;
8
+ };
@@ -0,0 +1,22 @@
1
+ import BaseDemo from "!!raw-loader!../demo/base.jsx";
2
+
3
+ ## 演示
4
+
5
+ ### 基础用法
6
+
7
+ ::BaseDemo::
8
+
9
+ ## API
10
+
11
+ ### Props
12
+
13
+ | 属性 | 描述 | 类型 | 默认值 |
14
+ | ---------- | ------------------------------- | ------------ | ------------------------------------------------------------------------------------------------ |
15
+ | id | 主题 ID | string | root |
16
+ | parent-id | 父级主题 ID | string | root |
17
+ | theme | 主题定制 | IThemeConfig | `{"colorMode":"light","inherit":true,"token":{"lightToken":{},"darkToken":{},"alwaysToken":{}}}` |
18
+ | color-mode | IThemeConfig colorMode 主题模式 | string | light |
19
+ | inherit | IThemeConfig inherit Token 继承 | boolean | true |
20
+ | token | IThemeConfig token Token 定制 | Object | `{}` |
21
+
22
+ ### Events
@@ -0,0 +1,7 @@
1
+ import BaseDemo from "!!raw-loader!../demo/token.jsx";
2
+
3
+ ## 演示
4
+
5
+ ### 基础用法
6
+
7
+ ::BaseDemo::