feffery_utils_components 0.0.21 → 0.0.22

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.
@@ -884,6 +884,76 @@
884
884
  }
885
885
  }
886
886
  },
887
+ "src/lib/components/FefferyCountDown.react.js": {
888
+ "description": "",
889
+ "displayName": "FefferyCountDown",
890
+ "methods": [],
891
+ "props": {
892
+ "id": {
893
+ "type": {
894
+ "name": "string"
895
+ },
896
+ "required": false,
897
+ "description": ""
898
+ },
899
+ "delay": {
900
+ "type": {
901
+ "name": "number"
902
+ },
903
+ "required": false,
904
+ "description": ""
905
+ },
906
+ "interval": {
907
+ "type": {
908
+ "name": "number"
909
+ },
910
+ "required": false,
911
+ "description": "",
912
+ "defaultValue": {
913
+ "value": "1",
914
+ "computed": false
915
+ }
916
+ },
917
+ "countdown": {
918
+ "type": {
919
+ "name": "number"
920
+ },
921
+ "required": false,
922
+ "description": ""
923
+ },
924
+ "setProps": {
925
+ "type": {
926
+ "name": "func"
927
+ },
928
+ "required": false,
929
+ "description": "Dash-assigned callback that should be called to report property changes\r\nto Dash, to make them available for callbacks."
930
+ },
931
+ "loading_state": {
932
+ "type": {
933
+ "name": "shape",
934
+ "value": {
935
+ "is_loading": {
936
+ "name": "bool",
937
+ "description": "Determines if the component is loading or not",
938
+ "required": false
939
+ },
940
+ "prop_name": {
941
+ "name": "string",
942
+ "description": "Holds which property is loading",
943
+ "required": false
944
+ },
945
+ "component_name": {
946
+ "name": "string",
947
+ "description": "Holds the name of the component that is loading",
948
+ "required": false
949
+ }
950
+ }
951
+ },
952
+ "required": false,
953
+ "description": ""
954
+ }
955
+ }
956
+ },
887
957
  "src/lib/components/FefferyExecuteJs.react.js": {
888
958
  "description": "",
889
959
  "displayName": "FefferyExecuteJs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feffery_utils_components",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
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.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Build more utility components for Plotly Dash.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,7 +3,7 @@ module FefferyUtilsComponents
3
3
  using Dash
4
4
 
5
5
  const resources_path = realpath(joinpath( @__DIR__, "..", "deps"))
6
- const version = "0.0.21"
6
+ const version = "0.0.22"
7
7
 
8
8
  include("jl/''_fefferyblockcolorpicker.jl")
9
9
  include("jl/''_fefferycirclecolorpicker.jl")
@@ -15,6 +15,7 @@ include("jl/''_fefferywheelcolorpicker.jl")
15
15
  include("jl/''_fefferyexternalcss.jl")
16
16
  include("jl/''_fefferysettitle.jl")
17
17
  include("jl/''_fefferycaptcha.jl")
18
+ include("jl/''_fefferycountdown.jl")
18
19
  include("jl/''_fefferyexecutejs.jl")
19
20
  include("jl/''_fefferyextraspinner.jl")
20
21
  include("jl/''_fefferyguide.jl")
@@ -48,14 +49,14 @@ function __init__()
48
49
  [
49
50
  DashBase.Resource(
50
51
  relative_package_path = "feffery_utils_components.min.js",
51
- external_url = "https://unpkg.com/feffery_utils_components@0.0.21/feffery_utils_components/feffery_utils_components.min.js",
52
+ external_url = "https://unpkg.com/feffery_utils_components@0.0.22/feffery_utils_components/feffery_utils_components.min.js",
52
53
  dynamic = nothing,
53
54
  async = nothing,
54
55
  type = :js
55
56
  ),
56
57
  DashBase.Resource(
57
58
  relative_package_path = "feffery_utils_components.min.js.map",
58
- external_url = "https://unpkg.com/feffery_utils_components@0.0.21/feffery_utils_components/feffery_utils_components.min.js.map",
59
+ external_url = "https://unpkg.com/feffery_utils_components@0.0.22/feffery_utils_components/feffery_utils_components.min.js.map",
59
60
  dynamic = true,
60
61
  async = nothing,
61
62
  type = :js
@@ -0,0 +1,26 @@
1
+ # AUTO GENERATED FILE - DO NOT EDIT
2
+
3
+ export ''_fefferycountdown
4
+
5
+ """
6
+ ''_fefferycountdown(;kwargs...)
7
+
8
+ A FefferyCountDown component.
9
+
10
+ Keyword arguments:
11
+ - `id` (String; optional)
12
+ - `countdown` (Real; optional)
13
+ - `delay` (Real; optional)
14
+ - `interval` (Real; optional)
15
+ - `loading_state` (optional): . loading_state has the following type: lists containing elements 'is_loading', 'prop_name', 'component_name'.
16
+ Those elements have the following types:
17
+ - `is_loading` (Bool; optional): Determines if the component is loading or not
18
+ - `prop_name` (String; optional): Holds which property is loading
19
+ - `component_name` (String; optional): Holds the name of the component that is loading
20
+ """
21
+ function ''_fefferycountdown(; kwargs...)
22
+ available_props = Symbol[:id, :countdown, :delay, :interval, :loading_state]
23
+ wild_props = Symbol[]
24
+ return Component("''_fefferycountdown", "FefferyCountDown", "feffery_utils_components", available_props, wild_props; kwargs...)
25
+ end
26
+
@@ -0,0 +1,92 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useCountDown } from 'ahooks';
3
+ import PropTypes from 'prop-types';
4
+
5
+ // 定义倒计时执行组件FefferyCountDown
6
+ const FefferyCountDown = (props) => {
7
+
8
+ const {
9
+ id,
10
+ delay,
11
+ interval,
12
+ setProps,
13
+ loading_state
14
+ } = props;
15
+
16
+ const [targetDate, setTargetDate] = useState(null);
17
+
18
+ useEffect(() => {
19
+ if (delay) {
20
+ setTargetDate(Date.now() + 1000 * delay)
21
+ }
22
+ }, [delay])
23
+
24
+ const [_countdown] = useCountDown({
25
+ targetDate: targetDate,
26
+ interval: interval * 1000,
27
+ onEnd: () => {
28
+ setProps({
29
+ delay: undefined,
30
+ countdown: 0
31
+ })
32
+ }
33
+ });
34
+
35
+ useEffect(() => {
36
+ if (_countdown && delay) {
37
+ setProps({
38
+ countdown: Math.round(_countdown / 1000)
39
+ })
40
+ }
41
+ }, [_countdown])
42
+
43
+ return (<div
44
+ id={id}
45
+ data-dash-is-loading={
46
+ (loading_state && loading_state.is_loading) || undefined
47
+ } />);
48
+ }
49
+
50
+ // 定义参数或属性
51
+ FefferyCountDown.propTypes = {
52
+ // 部件id
53
+ id: PropTypes.string,
54
+
55
+ // 用于设置距离下一次超时事件触发的倒计时间隔(单位:秒)
56
+ // 每次有效的delay对应超时事件结束后都会被重置为undefined
57
+ delay: PropTypes.number,
58
+
59
+ // 设置倒计时时间间隔(单位:秒),默认为1
60
+ interval: PropTypes.number,
61
+
62
+ // 监听当前剩余时间秒数,默认为0
63
+ countdown: PropTypes.number,
64
+
65
+ /**
66
+ * Dash-assigned callback that should be called to report property changes
67
+ * to Dash, to make them available for callbacks.
68
+ */
69
+ setProps: PropTypes.func,
70
+
71
+ loading_state: PropTypes.shape({
72
+ /**
73
+ * Determines if the component is loading or not
74
+ */
75
+ is_loading: PropTypes.bool,
76
+ /**
77
+ * Holds which property is loading
78
+ */
79
+ prop_name: PropTypes.string,
80
+ /**
81
+ * Holds the name of the component that is loading
82
+ */
83
+ component_name: PropTypes.string
84
+ })
85
+ };
86
+
87
+ // 设置默认参数
88
+ FefferyCountDown.defaultProps = {
89
+ interval: 1
90
+ }
91
+
92
+ export default React.memo(FefferyCountDown);
package/src/lib/index.js CHANGED
@@ -32,6 +32,7 @@ import FefferyIdle from "./components/listeners/FefferyIdle.react";
32
32
  import FefferyWindowSize from "./components/listeners/FefferyWindowSize.react";
33
33
  import FefferyKeyPress from "./components/listeners/FefferyKeyPress.react";
34
34
  import FefferyTimeout from "./components/FefferyTimeout.react";
35
+ import FefferyCountDown from "./components/FefferyCountDown.react";
35
36
 
36
37
  /*
37
38
  忽略部分设计React中规范的console警告信息
@@ -88,5 +89,6 @@ export {
88
89
  FefferyIdle,
89
90
  FefferyWindowSize,
90
91
  FefferyKeyPress,
91
- FefferyTimeout
92
+ FefferyTimeout,
93
+ FefferyCountDown
92
94
  };
@@ -0,0 +1,53 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ fuc.FefferyCountDown(
16
+ id='count-down-demo',
17
+ interval=2
18
+ ),
19
+ html.Button(
20
+ '设置10秒倒计时',
21
+ id='set-10s-count-down'
22
+ ),
23
+ html.Div(id='count-down-output')
24
+ ],
25
+ style={
26
+ 'height': '2000px'
27
+ }
28
+ )
29
+
30
+
31
+ @app.callback(
32
+ Output('count-down-demo', 'delay'),
33
+ Input('set-10s-count-down', 'n_clicks')
34
+ )
35
+ def demo1(n_clicks):
36
+
37
+ if n_clicks:
38
+ return 10
39
+
40
+
41
+ @app.callback(
42
+ Output('count-down-output', 'children'),
43
+ Input('count-down-demo', 'countdown')
44
+ )
45
+ def demo2(countdown):
46
+
47
+ print(countdown)
48
+
49
+ return countdown
50
+
51
+
52
+ if __name__ == '__main__':
53
+ app.run(debug=True)