Skip to content

Commit e15d80c

Browse files
authored
Clean props (#1088)
* Make all props after id keyword only * Reorder props and make docstrings consistent * Some typos * Update Table tests
1 parent d9744ea commit e15d80c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3157
-3166
lines changed

justfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@ _move-generated-files:
137137
if file_.name in ("__init__.py", "_table.py", "_version.py", "icons.py", "themes.py"):
138138
continue
139139
filename = "__init__.py" if file_.name == "_imports_.py" else file_.name
140-
file_.rename(file_.parent / "_components" / filename)
140+
new_file = file_.parent / "_components" / filename
141+
file_.rename(new_file)
142+
# enforce keyword arguments only after the id argument
143+
id_pattern = " id: typing.Optional[str] = None,\n"
144+
new_file.write_text(
145+
new_file.read_text().replace(id_pattern, f"{id_pattern}{8 * ' '}*,\n")
146+
)

src/components/accordion/Accordion.js

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import {getLoadingState} from '../../private/util';
1515
function Accordion({
1616
children,
1717
active_item,
18-
key,
19-
class_name,
20-
className,
2118
always_open = false,
2219
start_collapsed = false,
20+
class_name,
21+
className,
22+
key,
2323
setProps,
2424
...otherProps
2525
}) {
@@ -92,76 +92,56 @@ Accordion.dashPersistence = {
9292

9393
Accordion.propTypes = {
9494
/**
95-
* The ID of this component, used to identify dash components
96-
* in callbacks. The ID needs to be unique across all of the
97-
* components in an app.
98-
*/
99-
id: PropTypes.string,
100-
101-
/**
102-
* The children of this component
95+
* The children of the Accordion.
10396
*/
10497
children: PropTypes.node,
10598

10699
/**
107-
* Defines CSS styles which will override styles previously set.
108-
*/
109-
style: PropTypes.object,
110-
111-
/**
112-
* Often used with CSS to style elements with common properties.
100+
* The ID of the Accordion.
113101
*/
114-
class_name: PropTypes.string,
115-
116-
/**
117-
* **DEPRECATED** Use `class_name` instead.
118-
*
119-
* Often used with CSS to style elements with common properties.
120-
*/
121-
className: PropTypes.string,
122-
123-
/**
124-
* A unique identifier for the component, used to improve
125-
* performance by React.js while rendering components
126-
* See https://reactjs.org/docs/lists-and-keys.html for more info
127-
*/
128-
key: PropTypes.string,
129-
130-
/**
131-
* Renders accordion edge-to-edge with its parent container
132-
*/
133-
flush: PropTypes.bool,
102+
id: PropTypes.string,
134103

135104
/**
136105
* The item_id of the currently active item. If item_id has not been specified
137106
* for the active item, this will default to item-i, where i is the index
138107
* (starting from 0) of the item.
139108
*
140-
* If `always_open=True`, this needs to be a list of string IDs.
109+
* If `always_open=True`, then active_item should be a list item_ids of all the
110+
* currently open AccordionItems
141111
*/
142112
active_item: PropTypes.oneOfType([
143113
PropTypes.string,
144114
PropTypes.arrayOf(PropTypes.string)
145115
]),
146116

147117
/**
148-
* You can make accordion items stay open when another item is opened by
149-
* using the always_open prop.
118+
* If True, multiple items can be expanded at once.
150119
*/
151120
always_open: PropTypes.bool,
152121

153122
/**
154-
* Set to True for all items to be collapsed initially.
123+
* If True, all items will start collapsed.
155124
*/
156125
start_collapsed: PropTypes.bool,
157126

158127
/**
159-
* Used to allow user interactions in this component to be persisted when
160-
* the component - or the page - is refreshed. If `persisted` is truthy and
161-
* hasn't changed from its previous value, a `value` that the user has
162-
* changed while using the app will keep that change, as long as
163-
* the new `value` also matches what was given originally.
164-
* Used in conjunction with `persistence_type`.
128+
* If True the Accordion will be rendered edge-to-edge within its parent container.
129+
*/
130+
flush: PropTypes.bool,
131+
132+
/**
133+
* Additional inline styles to apply to the Accordion
134+
*/
135+
style: PropTypes.object,
136+
137+
/**
138+
* Additional CSS class to apply to the Accordion.
139+
*/
140+
class_name: PropTypes.string,
141+
142+
/**
143+
* Used to allow user interactions to be persisted when the page is refreshed.
144+
* See https://dash.plotly.com/persistence for more details
165145
*/
166146
persistence: PropTypes.oneOfType([
167147
PropTypes.bool,
@@ -170,20 +150,34 @@ Accordion.propTypes = {
170150
]),
171151

172152
/**
173-
* Properties whose user interactions will persist after refreshing the
174-
* component or the page. Since only `value` is allowed this prop can
153+
* Properties to persist. Since only `active_item` is supported, this prop can
175154
* normally be ignored.
176155
*/
177156
persisted_props: PropTypes.arrayOf(PropTypes.oneOf(['active_item'])),
178157

179158
/**
180159
* Where persisted user changes will be stored:
181-
* memory: only kept in memory, reset on page refresh.
182-
* local: window.localStorage, data is kept after the browser quit.
183-
* session: window.sessionStorage, data is cleared once the browser quit.
160+
* - memory: only kept in memory, reset on page refresh.
161+
* - local: window.localStorage, data is kept after the browser quit.
162+
* - session: window.sessionStorage, data is cleared once the browser quit.
184163
*/
185164
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
186165

166+
/**
167+
* A unique identifier for the component, used to improve performance by React.js
168+
* while rendering components
169+
*
170+
* See https://react.dev/learn/rendering-lists#why-does-react-need-keys for more info
171+
*/
172+
key: PropTypes.string,
173+
174+
/**
175+
* **DEPRECATED** Use `class_name` instead.
176+
*
177+
* Additional CSS class to apply to the Accordion.
178+
*/
179+
className: PropTypes.string,
180+
187181
/**
188182
* Dash-assigned callback that gets fired when the value changes.
189183
*/

src/components/accordion/AccordionItem.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {getLoadingState, stringifyId} from '../../private/util';
1111
* A component to build up the children of the accordion.
1212
*/
1313
function AccordionItem({
14+
children,
15+
id,
1416
title,
1517
item_id,
1618
class_name,
1719
className,
18-
id,
19-
children,
2020
...otherProps
2121
}) {
2222
const {toggle, idx} = useContext(AccordionContext);
@@ -43,46 +43,49 @@ function AccordionItem({
4343

4444
AccordionItem.propTypes = {
4545
/**
46-
* The ID of this component, used to identify dash components
47-
* in callbacks. The ID needs to be unique across all of the
48-
* components in an app.
46+
* The ID of the AccordionItem.
4947
*/
5048
id: PropTypes.string,
5149

5250
/**
53-
* The children of this component
51+
* The children of the AccordionItem.
5452
*/
5553
children: PropTypes.node,
5654

5755
/**
58-
* Defines CSS styles which will override styles previously set.
56+
* Text to display in the header of the AccordionItem.
57+
*/
58+
title: PropTypes.node,
59+
60+
/**
61+
* Optional identifier for item used for determining which item is visible if not
62+
* specified, and AccordionItem is being used inside Accordion component, the item_id
63+
* will be set to "item-i" where i is (zero indexed) position of item in list items
64+
* passed to Accordion component.
65+
*/
66+
item_id: PropTypes.string,
67+
68+
/**
69+
* Additional inline CSS styles to apply to the AccordionItem.
5970
*/
6071
style: PropTypes.object,
6172

6273
/**
63-
* Often used with CSS to style elements with common properties.
74+
* Additional CSS classes to apply to the AccordionItem.
6475
*/
6576
class_name: PropTypes.string,
6677

6778
/**
6879
* **DEPRECATED** Use `class_name` instead.
6980
*
70-
* Often used with CSS to style elements with common properties.
81+
* Additional CSS classes to apply to the AccordionItem.
7182
*/
7283
className: PropTypes.string,
7384

7485
/**
75-
* The title on display in the collapsed accordion item.
76-
*/
77-
title: PropTypes.node,
78-
79-
/**
80-
* Optional identifier for item used for determining which item is visible
81-
* if not specified, and AccordionItem is being used inside Accordion component, the itemId
82-
* will be set to "item-i" where i is (zero indexed) position of item in list
83-
* items pased to Accordion component.
86+
* Dash-assigned callback that gets fired when the value changes.
8487
*/
85-
item_id: PropTypes.string
88+
setProps: PropTypes.func
8689
};
8790

8891
export default AccordionItem;

0 commit comments

Comments
 (0)