feffery_utils_components 0.2.0-rc11 → 0.2.0-rc12

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.
@@ -13294,8 +13294,60 @@
13294
13294
  }
13295
13295
  }
13296
13296
  },
13297
+ "src/lib/components/FefferySetFavicon.react.js": {
13298
+ "description": "favicon\u8bbe\u7f6e\u7ec4\u4ef6FefferySetFavicon",
13299
+ "displayName": "FefferySetFavicon",
13300
+ "methods": [],
13301
+ "props": {
13302
+ "id": {
13303
+ "type": {
13304
+ "name": "string"
13305
+ },
13306
+ "required": false,
13307
+ "description": "\u7ec4\u4ef6id"
13308
+ },
13309
+ "favicon": {
13310
+ "type": {
13311
+ "name": "string"
13312
+ },
13313
+ "required": false,
13314
+ "description": "\u7528\u4e8e\u8bbe\u7f6e\u8981\u66f4\u65b0\u7684favicon\u56fe\u7247\u6587\u4ef6\u5730\u5740\uff0c\u652f\u6301svg\u3001png\u3001ico\u3001gif\u683c\u5f0f"
13315
+ },
13316
+ "setProps": {
13317
+ "type": {
13318
+ "name": "func"
13319
+ },
13320
+ "required": false,
13321
+ "description": "Dash-assigned callback that should be called to report property changes\r\nto Dash, to make them available for callbacks."
13322
+ },
13323
+ "loading_state": {
13324
+ "type": {
13325
+ "name": "shape",
13326
+ "value": {
13327
+ "is_loading": {
13328
+ "name": "bool",
13329
+ "description": "Determines if the component is loading or not",
13330
+ "required": false
13331
+ },
13332
+ "prop_name": {
13333
+ "name": "string",
13334
+ "description": "Holds which property is loading",
13335
+ "required": false
13336
+ },
13337
+ "component_name": {
13338
+ "name": "string",
13339
+ "description": "Holds the name of the component that is loading",
13340
+ "required": false
13341
+ }
13342
+ }
13343
+ },
13344
+ "required": false,
13345
+ "description": ""
13346
+ }
13347
+ }
13348
+ },
13297
13349
  "src/lib/components/FefferySetTitle.react.js": {
13298
- "description": "",
13350
+ "description": "\u9875\u9762title\u8bbe\u7f6e\u7ec4\u4ef6FefferySetTitle",
13299
13351
  "displayName": "FefferySetTitle",
13300
13352
  "methods": [],
13301
13353
  "props": {
@@ -13313,6 +13365,13 @@
13313
13365
  "required": false,
13314
13366
  "description": "\u7528\u4e8e\u8bbe\u7f6e\u8981\u66f4\u65b0\u7684title\u4fe1\u606f"
13315
13367
  },
13368
+ "originTitle": {
13369
+ "type": {
13370
+ "name": "string"
13371
+ },
13372
+ "required": false,
13373
+ "description": "\u5f53title\u53c2\u6570\u4e3a\u7a7a\uff0c\u6216\u5f53\u524d\u7ec4\u4ef6\u4ece\u9875\u9762\u4e2d\u5378\u8f7d\u540e\u5e94\u5f53\u8fd8\u539f\u7684title"
13374
+ },
13316
13375
  "setProps": {
13317
13376
  "type": {
13318
13377
  "name": "func"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feffery_utils_components",
3
- "version": "0.2.0-rc11",
3
+ "version": "0.2.0-rc12",
4
4
  "description": "Build more utility components for Plotly Dash.",
5
5
  "repository": {
6
6
  "type": "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feffery_utils_components",
3
- "version": "0.2.0-rc11",
3
+ "version": "0.2.0-rc12",
4
4
  "description": "Build more utility components for Plotly Dash.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,58 @@
1
+ import { useFavicon } from 'ahooks';
2
+ import PropTypes from 'prop-types';
3
+
4
+ /**
5
+ * favicon设置组件FefferySetFavicon
6
+ */
7
+ const FefferySetFavicon = (props) => {
8
+
9
+ const {
10
+ favicon,
11
+ setProps,
12
+ loading_state
13
+ } = props;
14
+
15
+ useFavicon(favicon);
16
+
17
+ return <></>;
18
+ }
19
+
20
+ // 定义参数或属性
21
+ FefferySetFavicon.propTypes = {
22
+ /**
23
+ * 组件id
24
+ */
25
+ id: PropTypes.string,
26
+
27
+ /**
28
+ * 用于设置要更新的favicon图片文件地址,支持svg、png、ico、gif格式
29
+ */
30
+ favicon: PropTypes.string,
31
+
32
+ /**
33
+ * Dash-assigned callback that should be called to report property changes
34
+ * to Dash, to make them available for callbacks.
35
+ */
36
+ setProps: PropTypes.func,
37
+
38
+ loading_state: PropTypes.shape({
39
+ /**
40
+ * Determines if the component is loading or not
41
+ */
42
+ is_loading: PropTypes.bool,
43
+ /**
44
+ * Holds which property is loading
45
+ */
46
+ prop_name: PropTypes.string,
47
+ /**
48
+ * Holds the name of the component that is loading
49
+ */
50
+ component_name: PropTypes.string
51
+ })
52
+ };
53
+
54
+ // 设置默认参数
55
+ FefferySetFavicon.defaultProps = {
56
+ }
57
+
58
+ export default FefferySetFavicon;
@@ -1,20 +1,30 @@
1
+ import { useEffect } from 'react';
1
2
  import { useTitle } from 'ahooks';
2
3
  import PropTypes from 'prop-types';
3
4
 
4
- // 定义页面title设置组件FefferySetTitle
5
+ /**
6
+ * 页面title设置组件FefferySetTitle
7
+ */
5
8
  const FefferySetTitle = (props) => {
6
9
 
7
10
  const {
8
- id,
9
11
  title,
12
+ originTitle,
10
13
  setProps,
11
14
  loading_state
12
15
  } = props;
13
16
 
14
- // 随着title更新进而改变页面title
15
- if (title) {
16
- useTitle(title)
17
- }
17
+ // 组件卸载时,还原有效的originTitle
18
+ useEffect(() => {
19
+ return () => {
20
+ if (originTitle) {
21
+ document.title = originTitle;
22
+ }
23
+ }
24
+ }, [])
25
+
26
+ // 处理title变化时的更新
27
+ useTitle(title || originTitle);
18
28
 
19
29
  return <></>;
20
30
  }
@@ -31,6 +41,11 @@ FefferySetTitle.propTypes = {
31
41
  */
32
42
  title: PropTypes.string,
33
43
 
44
+ /**
45
+ * 当title参数为空,或当前组件从页面中卸载后应当还原的title
46
+ */
47
+ originTitle: PropTypes.string,
48
+
34
49
  /**
35
50
  * Dash-assigned callback that should be called to report property changes
36
51
  * to Dash, to make them available for callbacks.
package/src/lib/index.js CHANGED
@@ -103,6 +103,7 @@ import FefferySortable from "./components/sortable/FefferySortable.react";
103
103
  import FefferyAnimatedImage from "./components/FefferyAnimatedImage.react";
104
104
  import FefferyDebugGuardian from "./components/security/FefferyDebugGuardian.react";
105
105
  import FefferyDom2Image from "./components/FefferyDom2Image.react";
106
+ import FefferySetFavicon from "./components/FefferySetFavicon.react";
106
107
  import './components/styles.css';
107
108
 
108
109
  // 自定义sessionStorage事件监听
@@ -230,5 +231,6 @@ export {
230
231
  FefferySortable,
231
232
  FefferyAnimatedImage,
232
233
  FefferyDebugGuardian,
233
- FefferyDom2Image
234
+ FefferyDom2Image,
235
+ FefferySetFavicon
234
236
  };
package/usage.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import dash
2
- import json
3
2
  from dash import html
4
3
  import feffery_utils_components as fuc
5
4
  from dash.dependencies import Input, Output
@@ -8,34 +7,16 @@ app = dash.Dash(__name__)
8
7
 
9
8
  app.layout = html.Div(
10
9
  [
11
- # 测试元素
12
- fuc.FefferyDiv(
13
- '测试内容',
14
- id='demo-target',
15
- shadow='always-shadow-light',
16
- style={
17
- 'width': 300,
18
- 'height': 200,
19
- 'display': 'flex',
20
- 'justifyContent': 'center',
21
- 'alignItems': 'center',
22
- 'fontSize': 18,
23
- 'fontWeight': 'bold',
24
- 'color': 'white',
25
- 'background': 'linear-gradient(135deg,#17ead9,#6078ea)'
26
- }
27
- ),
28
- # 测试激活元素转图片
29
10
  html.Button(
30
- '打印',
31
- id='execute-screenshot'
32
- ),
33
- # 测试元素转图片组件
34
- fuc.FefferyDom2Image(
35
- id='demo-dom2image',
36
- scale=2
11
+ '还原favicon',
12
+ id='clear-demo-output'
37
13
  ),
38
- html.Div(id='demo-dom2image-output')
14
+ html.Div(
15
+ fuc.FefferySetFavicon(
16
+ favicon='https://www.google.com/favicon.ico'
17
+ ),
18
+ id='demo-output'
19
+ )
39
20
  ],
40
21
  style={
41
22
  'padding': '50px 50px 0 50px'
@@ -44,34 +25,15 @@ app.layout = html.Div(
44
25
 
45
26
 
46
27
  @app.callback(
47
- Output('demo-dom2image', 'targetSelector'),
48
- Input('execute-screenshot', 'n_clicks'),
28
+ Output('demo-output', 'children'),
29
+ Input('clear-demo-output', 'n_clicks'),
49
30
  prevent_initial_call=True
50
31
  )
51
32
  def demo(n_clicks):
52
33
 
53
- return '#demo-target'
54
-
55
-
56
- @app.callback(
57
- Output('demo-dom2image-output', 'children'),
58
- Input('demo-dom2image', 'screenshotResult'),
59
- prevent_initial_call=True
60
- )
61
- def update_result(screenshotResult):
62
-
63
- return [
64
- html.Pre(
65
- json.dumps(
66
- screenshotResult,
67
- ensure_ascii=False,
68
- indent=4
69
- )
70
- ),
71
- html.Img(
72
- src=screenshotResult['dataUrl']
73
- )
74
- ]
34
+ return fuc.FefferySetFavicon(
35
+ favicon='/_favicon.ico'
36
+ )
75
37
 
76
38
 
77
39
  if __name__ == '__main__':