bi-sdk-react 0.0.1 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-sdk-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -1,41 +1,130 @@
1
- import React from 'react'
2
- import { Form, Input, Select, Button } from 'antd'
3
- import type { PropEditorProps } from './types'
1
+ import React from "react";
2
+ import { Form, Input, Select, Button, Space, ColorPicker } from "antd";
3
+ import type { PropEditorProps } from "./types";
4
4
 
5
- export type TextModel = { text?: string }
5
+ export type TextModel = { text?: string; customStyle?: React.CSSProperties };
6
6
 
7
- export const TextProps: React.FC<PropEditorProps<TextModel>> = ({ model, customStyle = {}, onChange }) => {
8
- const triggerModel = (key: keyof TextModel, value: any) => onChange && onChange({ ...model, [key]: value })
7
+ export const TextProps: React.FC<PropEditorProps<TextModel>> = ({
8
+ model,
9
+ onChange,
10
+ }) => {
11
+ const triggerModel = (key: keyof TextModel, value: any) =>
12
+ onChange && onChange({ ...model, [key]: value });
9
13
  const setStyle = (key: string, value: any) => {
10
- const next = { ...customStyle, [key]: value }
11
- onChange && onChange({ ...model, customStyle: next } as any)
12
- }
14
+ const next = { ...(model.customStyle || {}), [key]: value };
15
+ onChange && onChange({ ...model, customStyle: next } as any);
16
+ };
13
17
  return (
14
18
  <Form>
15
19
  <Form.Item label="文本内容">
16
- <Input.TextArea size="small" value={model.text} onChange={e => triggerModel('text', e.target.value)} />
20
+ <Input.TextArea
21
+ size="small"
22
+ value={model.text}
23
+ onChange={(e) => triggerModel("text", e.target.value)}
24
+ />
17
25
  </Form.Item>
18
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
19
- <Input.Group compact>
20
- <Select size="small" value={customStyle.fontFamily} style={{ width: 90 }} onChange={v => setStyle('fontFamily', v)}>
21
- <Select.Option value="'黑体', 'SimHei', sans-serif">黑体</Select.Option>
26
+ <div
27
+ style={{
28
+ display: "flex",
29
+ alignItems: "center",
30
+ justifyContent: "space-between",
31
+ }}
32
+ >
33
+ <Space.Compact>
34
+ <Select
35
+ size="small"
36
+ value={model.customStyle?.fontFamily}
37
+ style={{ width: 90 }}
38
+ onChange={(v) => setStyle("fontFamily", v)}
39
+ >
40
+ <Select.Option value="'黑体', 'SimHei', sans-serif">
41
+ 黑体
42
+ </Select.Option>
22
43
  <Select.Option value="'宋体', 'SimSun', serif">宋体</Select.Option>
23
- <Select.Option value="'仿宋', 'FangSong', serif">仿宋</Select.Option>
44
+ <Select.Option value="'仿宋', 'FangSong', serif">
45
+ 仿宋
46
+ </Select.Option>
24
47
  <Select.Option value="'楷体', 'KaiTi', serif">楷体</Select.Option>
25
48
  <Select.Option value="Arial, sans-serif">Arial</Select.Option>
26
49
  </Select>
27
- <Select size="small" value={customStyle.fontSize} style={{ width: 90 }} onChange={v => setStyle('fontSize', v)}>
28
- {['12px','14px','16px','20px','22px','24px','32px','48px'].map(s => <Select.Option key={s} value={s}>{s}</Select.Option>)}
50
+ <Select
51
+ size="small"
52
+ value={model.customStyle?.fontSize}
53
+ style={{ width: 90 }}
54
+ onChange={(v) => setStyle("fontSize", v)}
55
+ >
56
+ {[
57
+ "12px",
58
+ "14px",
59
+ "16px",
60
+ "20px",
61
+ "22px",
62
+ "24px",
63
+ "32px",
64
+ "48px",
65
+ ].map((s) => (
66
+ <Select.Option key={s} value={s}>
67
+ {s}
68
+ </Select.Option>
69
+ ))}
29
70
  </Select>
30
- <Input size="small" type="color" value={customStyle.color} onChange={e => setStyle('color', e.target.value)} style={{ width: 90 }} />
31
- </Input.Group>
32
- <Input.Group compact>
33
- <Button type={customStyle.fontWeight === 'bold' ? 'primary' : undefined} size="small" onClick={() => setStyle('fontWeight', customStyle.fontWeight === 'bold' ? 'normal' : 'bold')}>B</Button>
34
- <Button type={customStyle.fontStyle === 'italic' ? 'primary' : undefined} size="small" onClick={() => setStyle('fontStyle', customStyle.fontStyle === 'italic' ? 'normal' : 'italic')}>I</Button>
35
- <Button type={customStyle.textDecoration === 'underline' ? 'primary' : undefined} size="small" onClick={() => setStyle('textDecoration', customStyle.textDecoration === 'underline' ? 'none' : 'underline')}>U</Button>
36
- </Input.Group>
71
+ <ColorPicker
72
+ size="small"
73
+ value={model.customStyle?.color}
74
+ onChange={(v) => setStyle("color", v.toHexString())}
75
+ style={{ width: 90 }}
76
+ allowClear={true}
77
+ />
78
+ </Space.Compact>
79
+ <Space.Compact>
80
+ <Button
81
+ type={
82
+ model.customStyle?.fontWeight === "bold" ? "primary" : undefined
83
+ }
84
+ size="small"
85
+ onClick={() =>
86
+ setStyle(
87
+ "fontWeight",
88
+ model.customStyle?.fontWeight === "bold" ? "normal" : "bold"
89
+ )
90
+ }
91
+ >
92
+ B
93
+ </Button>
94
+ <Button
95
+ type={
96
+ model.customStyle?.fontStyle === "italic" ? "primary" : undefined
97
+ }
98
+ size="small"
99
+ onClick={() =>
100
+ setStyle(
101
+ "fontStyle",
102
+ model.customStyle?.fontStyle === "italic" ? "normal" : "italic"
103
+ )
104
+ }
105
+ >
106
+ I
107
+ </Button>
108
+ <Button
109
+ type={
110
+ model.customStyle?.textDecoration === "underline"
111
+ ? "primary"
112
+ : undefined
113
+ }
114
+ size="small"
115
+ onClick={() =>
116
+ setStyle(
117
+ "textDecoration",
118
+ model.customStyle?.textDecoration === "underline"
119
+ ? "none"
120
+ : "underline"
121
+ )
122
+ }
123
+ >
124
+ U
125
+ </Button>
126
+ </Space.Compact>
37
127
  </div>
38
128
  </Form>
39
- )
40
- }
41
-
129
+ );
130
+ };
@@ -1,8 +1,9 @@
1
- import React from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { HtmlBaseProps } from "../../../typing";
3
3
 
4
4
  export type TextRenderProps = {
5
5
  text?: string;
6
+ customStyle?: React.CSSProperties;
6
7
  item?: { style?: React.CSSProperties };
7
8
  } & HtmlBaseProps;
8
9
 
@@ -11,14 +12,19 @@ export const TextRender: React.FC<TextRenderProps> = ({
11
12
  text,
12
13
  item,
13
14
  style = {},
15
+ customStyle = {},
14
16
  className,
15
17
  }) => {
18
+ const actualStyle = useMemo(
19
+ () => ({
20
+ ...(item?.style || {}),
21
+ ...(customStyle || {}),
22
+ ...(style || {}),
23
+ }),
24
+ [item, customStyle, style]
25
+ );
16
26
  return (
17
- <span
18
- id={id}
19
- style={{ ...(item?.style || {}), ...style }}
20
- className={className}
21
- >
27
+ <span id={id} style={actualStyle} className={className}>
22
28
  {text}
23
29
  </span>
24
30
  );