x-star-design 0.0.18 → 0.0.20

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/README.md CHANGED
@@ -7,11 +7,156 @@ A react component library developed by turingstar
7
7
 
8
8
  ## Usage
9
9
 
10
- TODO
10
+ ### 基本信息
11
11
 
12
- ## Options
12
+ - github 地址:https://github.com/turingstar-tech/x-star-design
13
+ - npm 地址:https://www.npmjs.com/package/x-star-design
14
+ - 文档地址:https://turingstar-tech.github.io/x-star-design/components/title-with-icon
13
15
 
14
- TODO
16
+ ### 基本开发流程
17
+
18
+ 假设现在要开发一个名为 StatusTag 的组件
19
+
20
+ 1. 首先在 src 文件目录下建立一个名为 status-tag 的组件文件夹
21
+ 2. 在该文件夹中建立组件相关文件
22
+
23
+ ```tsx
24
+ index.tsx, //组件
25
+ index.md, //组件使用文档
26
+ _index.scss, //组件样式
27
+ define.ts; //组件相关类型定义(类型简短可直接定义在index.tsx中)
28
+ ```
29
+
30
+ 3. 编写组件样式时需注类样式的前缀引入,保证组件样式不和项目样式重叠,**同时由于没有引入 module,各个组件间样式也需命名不同,建议每个组件样式前加上该组件的特定标识,如 statusTagContent 而不是 content**
31
+
32
+ ```tsx
33
+ // index.tsx
34
+ import { prefix } from '../utils/global';
35
+ <img
36
+ src={diamondSVG}
37
+ className={classNames(`${prefix}required`, {
38
+ [`${prefix}circleRequired`]: shape === 'circle',
39
+ [`${prefix}rectRequired`]: shape !== 'circle',
40
+ })}
41
+ />
42
+ // _index.scss
43
+ .#{$prefix}required {
44
+ position: absolute;
45
+ width: 0.8rem;
46
+ height: 0.8rem;
47
+ }
48
+
49
+ .#{$prefix}circleRequired {
50
+ top: -3px;
51
+ right: -3px;
52
+ }
53
+
54
+ .#{$prefix}rectRequired {
55
+ top: -5px;
56
+ right: -5px;
57
+ }
58
+ ```
59
+
60
+ 4. 组件编写后需导出样式、组件及其相关类型
61
+
62
+ - 在 styles 中的 index.scss
63
+
64
+ ```tsx
65
+ // src/styles/index.scss
66
+ @import '../StatusTag';
67
+ ```
68
+
69
+ - 在 src 中的 index.ts
70
+
71
+ ```tsx
72
+ // src/index.ts
73
+ export { default as StatusTag } from './StatusTag';
74
+ export type {
75
+ StatusTagProps,
76
+ StatusTagShape,
77
+ StatusTagStyle,
78
+ StatusTagType,
79
+ } from './StatusTag/define';
80
+ ```
81
+
82
+ - 最后编写组件相关使用文档
83
+
84
+ ````tsx
85
+ // define.ts
86
+ export interface StatusTagProps {
87
+ /**
88
+
89
+ * @description 标签形状
90
+ */
91
+ shape: StatusTagShape;
92
+ status: StatusTagType;
93
+ children?: React.ReactNode;
94
+ /**
95
+ * @description 是否为必做题
96
+ * @default false
97
+ */
98
+ required?: boolean;
99
+ hover?: boolean;
100
+ className?: string;
101
+ style?: React.CSSProperties;
102
+ }
103
+
104
+ // index.md
105
+ # StatusTag
106
+
107
+ 这是题目状态组件
108
+
109
+ ```jsx
110
+ import { StatusTag } from 'x-star-design';
111
+
112
+ export default () => (
113
+ <div className="x-star-design-statusTagTest">
114
+ <StatusTag shape={'rect'} status={'unfilled'} />
115
+ <StatusTag shape={'circle'} hover status={'wrong'} required>
116
+ <span>{'1'}</span>
117
+ </StatusTag>
118
+ </div>
119
+ );
120
+ ```
121
+
122
+ ## API
123
+
124
+ <API id="StatusTag"></API>
125
+ ```
126
+ ````
127
+
128
+ ## 写给内部开发人员
129
+
130
+ 在编写组件示例时,建议将额外的样式写成内联样式,方便用户直接复制。如果样式过于复杂,或必须写成类的形式(如伪类或伪元素),建议新建一个\_example.scss 文件,用于编写示例的样式,并在.dumi/global.scss 中引入该文件,这样示例样式不会打包进发布的 npm 包。
131
+
132
+ - 组件库内置翻译
133
+ - 使用 useLocale 函数
134
+ - 分别在 zh_CN 和 en_US 中加入翻译
135
+ - 组件库如果使用以 antd 为基础的二次封装组件,请在外面套上 ConfigProviderWrapper,以保证组件样式的隔离以及颜色的正确性;同时,如果需要修改 antd 组件的默认样式,需要写两套,一套以.ant 开头适配比赛系统,一套以.x-star-design 开头以适配另外两个系统。具体组件可以参考 XTabs
136
+
137
+ ### 发包流程
138
+
139
+ - 手动发包
140
+ - 手动发包需要本地登录 npm 且必须邀请进 npm 组织,建议使用自动发包
141
+ - 使用 `npm version` 命令更新版本号,例如:
142
+
143
+ ```C++
144
+ 发布一个 patch 版本
145
+ $ npm version patch -m "build: release %s"
146
+ $ npm publish
147
+ ```
148
+
149
+ - 自动发包
150
+
151
+ - 在 main 分支上执行该命令,会自动修改 package.json 版本号并自动打 tag,并且会自动 commit,不需要手动写 message 来 commit
152
+ - ```Bash
153
+ npm version patch -m "build: release %s"
154
+ ```
155
+
156
+ - 执行该命令,将版本和 tag 推到 github 上
157
+ - ```Bash
158
+ git push && git push --tag
159
+ ```
15
160
 
16
161
  ## Development
17
162
 
@@ -32,6 +32,9 @@ declare const _default: {
32
32
  readonly SCORE: "Score";
33
33
  readonly BATCH_ADD: "Batch Add";
34
34
  };
35
+ readonly TranslateButton: {
36
+ readonly CURRENT_LANG: "Current Language:";
37
+ };
35
38
  readonly CodeDetailModal: {
36
39
  readonly Problem: "Problem";
37
40
  readonly Language: "Language";
@@ -32,6 +32,9 @@ export default {
32
32
  SCORE: 'Score',
33
33
  BATCH_ADD: 'Batch Add'
34
34
  },
35
+ TranslateButton: {
36
+ CURRENT_LANG: 'Current Language:'
37
+ },
35
38
  CodeDetailModal: {
36
39
  Problem: 'Problem',
37
40
  Language: 'Language',
@@ -7,7 +7,7 @@ interface LocaleProviderProps {
7
7
  }
8
8
  export declare const LocaleProvider: ({ children, locale, }: LocaleProviderProps) => React.JSX.Element;
9
9
  type MessageMap = typeof zh_CN | typeof en_US;
10
- export declare const useLocale: <T extends "VisualDataConfig" | "CodeDetailModal" | "ContactButton">(slice: T) => {
10
+ export declare const useLocale: <T extends "VisualDataConfig" | "TranslateButton" | "CodeDetailModal" | "ContactButton">(slice: T) => {
11
11
  locale: string;
12
12
  format: <U extends keyof MessageMap[T]>(key: U) => ({
13
13
  readonly VisualDataConfig: {
@@ -43,6 +43,9 @@ export declare const useLocale: <T extends "VisualDataConfig" | "CodeDetailModal
43
43
  readonly SCORE: "得分";
44
44
  readonly BATCH_ADD: "批量添加";
45
45
  };
46
+ readonly TranslateButton: {
47
+ readonly CURRENT_LANG: "当前语言:";
48
+ };
46
49
  readonly CodeDetailModal: {
47
50
  readonly Problem: "题目";
48
51
  readonly Language: "语言";
@@ -96,6 +99,9 @@ export declare const useLocale: <T extends "VisualDataConfig" | "CodeDetailModal
96
99
  readonly SCORE: "Score";
97
100
  readonly BATCH_ADD: "Batch Add";
98
101
  };
102
+ readonly TranslateButton: {
103
+ readonly CURRENT_LANG: "Current Language:";
104
+ };
99
105
  readonly CodeDetailModal: {
100
106
  readonly Problem: "Problem";
101
107
  readonly Language: "Language";
@@ -117,7 +123,7 @@ export declare const useLocale: <T extends "VisualDataConfig" | "CodeDetailModal
117
123
  };
118
124
  })[T][U];
119
125
  };
120
- export declare const getFormat: <T extends "VisualDataConfig" | "CodeDetailModal" | "ContactButton">(locale: string | undefined, slice: T) => <U extends keyof MessageMap[T]>(key: U) => ({
126
+ export declare const getFormat: <T extends "VisualDataConfig" | "TranslateButton" | "CodeDetailModal" | "ContactButton">(locale: string | undefined, slice: T) => <U extends keyof MessageMap[T]>(key: U) => ({
121
127
  readonly VisualDataConfig: {
122
128
  readonly Time_MS: "时间限制(MS)";
123
129
  readonly Space_MS: "空间限制(KB)";
@@ -151,6 +157,9 @@ export declare const getFormat: <T extends "VisualDataConfig" | "CodeDetailModal
151
157
  readonly SCORE: "得分";
152
158
  readonly BATCH_ADD: "批量添加";
153
159
  };
160
+ readonly TranslateButton: {
161
+ readonly CURRENT_LANG: "当前语言:";
162
+ };
154
163
  readonly CodeDetailModal: {
155
164
  readonly Problem: "题目";
156
165
  readonly Language: "语言";
@@ -204,6 +213,9 @@ export declare const getFormat: <T extends "VisualDataConfig" | "CodeDetailModal
204
213
  readonly SCORE: "Score";
205
214
  readonly BATCH_ADD: "Batch Add";
206
215
  };
216
+ readonly TranslateButton: {
217
+ readonly CURRENT_LANG: "Current Language:";
218
+ };
207
219
  readonly CodeDetailModal: {
208
220
  readonly Problem: "Problem";
209
221
  readonly Language: "Language";
@@ -1,3 +1,5 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useCookieState } from 'ahooks';
1
3
  import React, { useContext, useRef } from 'react';
2
4
  import en_US from "./en_US";
3
5
  import zh_CN from "./zh_CN";
@@ -12,7 +14,10 @@ export var LocaleProvider = function LocaleProvider(_ref) {
12
14
  };
13
15
  export var useLocale = function useLocale(slice) {
14
16
  var _zh_CN$en_US$locale;
15
- var locale = useContext(LocaleContext);
17
+ var _useCookieState = useCookieState('lang'),
18
+ _useCookieState2 = _slicedToArray(_useCookieState, 1),
19
+ cookieLang = _useCookieState2[0];
20
+ var locale = useContext(LocaleContext) || cookieLang === 'zh' ? 'zh_CN' : 'en_US';
16
21
  var message = ((_zh_CN$en_US$locale = {
17
22
  zh_CN: zh_CN,
18
23
  en_US: en_US
@@ -32,6 +32,9 @@ declare const _default: {
32
32
  readonly SCORE: "得分";
33
33
  readonly BATCH_ADD: "批量添加";
34
34
  };
35
+ readonly TranslateButton: {
36
+ readonly CURRENT_LANG: "当前语言:";
37
+ };
35
38
  readonly CodeDetailModal: {
36
39
  readonly Problem: "题目";
37
40
  readonly Language: "语言";
@@ -32,6 +32,9 @@ export default {
32
32
  SCORE: '得分',
33
33
  BATCH_ADD: '批量添加'
34
34
  },
35
+ TranslateButton: {
36
+ CURRENT_LANG: '当前语言:'
37
+ },
35
38
  CodeDetailModal: {
36
39
  Problem: '题目',
37
40
  Language: '语言',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-design",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "A react component library developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",