Skip to content

Commit 9c305c4

Browse files
committed
Expose appid to callback in sidebar
1 parent a8820d4 commit 9c305c4

File tree

7 files changed

+40
-17
lines changed

7 files changed

+40
-17
lines changed

dash_mp_components/MatSidebar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ class MatSidebar(Component):
99
1010
Keyword arguments:
1111
- id (string; optional): The ID used to identify this component in Dash callbacks.
12-
- currentApp (string; optional)
13-
- state (string; optional)
14-
- layout (a value equal to: 'vertical', 'horizontal'; optional)"""
12+
- currentApp (string; optional): The ID of the current selected app
13+
- appId (string; optional): This is a read-only prop that dash callback can subscribe to
14+
- layout (a value equal to: 'vertical', 'horizontal'; optional): The layout of the sidebar"""
1515
@_explicitize_args
1616
def __init__(self,
1717
id=Component.UNDEFINED,
1818
currentApp=Component.UNDEFINED,
19-
state=Component.UNDEFINED,
19+
appId=Component.UNDEFINED,
2020
layout=Component.UNDEFINED,
2121
**kwargs):
22-
self._prop_names = ['id', 'currentApp', 'state', 'layout']
22+
self._prop_names = ['id', 'currentApp', 'appId', 'layout']
2323
self._type = 'MatSidebar'
2424
self._namespace = 'dash_mp_components'
2525
self._valid_wildcard_attributes = []
26-
self.available_properties = ['id', 'currentApp', 'state', 'layout']
26+
self.available_properties = ['id', 'currentApp', 'appId', 'layout']
2727
self.available_wildcard_properties = []
2828

2929
_explicit_args = kwargs.pop('_explicit_args')

dash_mp_components/dash_mp_components.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_mp_components/dash_mp_components.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_mp_components/metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@
235235
"name": "string"
236236
},
237237
"required": false,
238-
"description": ""
238+
"description": "The ID of the current selected app"
239239
},
240-
"state": {
240+
"appId": {
241241
"type": {
242242
"name": "string"
243243
},
244244
"required": false,
245-
"description": ""
245+
"description": "This is a read-only prop that dash callback can subscribe to"
246246
},
247247
"layout": {
248248
"type": {
@@ -259,7 +259,7 @@
259259
]
260260
},
261261
"required": false,
262-
"description": ""
262+
"description": "The layout of the sidebar"
263263
}
264264
}
265265
},

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/components/MatSidebar.react.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class MatSidebar extends Component {
1010
currentApp={this.props.currentApp}
1111
onAppSelected={(v) => {
1212
console.log(v);
13-
this.props.setProps({state: v});
13+
this.props.setProps({appId: v});
1414
}}/>
1515
);
1616
}
@@ -25,7 +25,20 @@ MatSidebar.propTypes = {
2525
* to Dash, to make them available for callbacks.
2626
*/
2727
setProps: PropTypes.func,
28+
/**
29+
*
30+
* The ID of the current selected app
31+
*
32+
*/
2833
currentApp: PropTypes.string,
29-
state: PropTypes.string,
34+
/**
35+
* This is a read-only prop that dash callback can subscribe to
36+
*/
37+
appId: PropTypes.string,
38+
/**
39+
*
40+
* The layout of the sidebar
41+
*
42+
*/
3043
layout: PropTypes.oneOf(['vertical', 'horizontal']),
3144
};

usage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,21 @@
592592
hiddenElements=['Fe', 'Dy'],
593593
enabledElements=['H', 'O']),
594594
html.P(id='p'),
595+
html.P(id='p2'),
595596
html.Div(id='component'),
596597
dash_mp_components.MatSidebar(id='bar', layout='horizontal')
597598
])
598599

599600

601+
@app.callback([Output(component_id='p2', component_property='children')],
602+
[Input(component_id='bar', component_property='appId')])
603+
def display_output2(value):
604+
print(value)
605+
if value is None:
606+
return ['']
607+
return [value]
608+
609+
600610
@app.callback([Output(component_id='p', component_property='children')],
601611
[Input(component_id='context', component_property='state')])
602612
def display_output2(value):

0 commit comments

Comments
 (0)