Skip to content

Commit 3d4c573

Browse files
authored
chore: run prettier on src (react-bootstrap#5829)
1 parent 0f7b39d commit 3d4c573

Some content is hidden

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

43 files changed

+2054
-2113
lines changed

src/AbstractNav.tsx

Lines changed: 116 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -36,123 +36,125 @@ interface AbstractNavProps
3636
parentOnSelect?: SelectCallback;
3737
}
3838

39-
const AbstractNav: BsPrefixRefForwardingComponent<
40-
'ul',
41-
AbstractNavProps
42-
> = React.forwardRef<HTMLElement, AbstractNavProps>(
43-
(
44-
{
45-
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
46-
as: Component = 'ul',
47-
onSelect,
48-
activeKey,
49-
role,
50-
onKeyDown,
51-
...props
52-
},
53-
ref,
54-
) => {
55-
// A ref and forceUpdate for refocus, b/c we only want to trigger when needed
56-
// and don't want to reset the set in the effect
57-
const forceUpdate = useForceUpdate();
58-
const needsRefocusRef = useRef(false);
59-
60-
const parentOnSelect = useContext(SelectableContext);
61-
const tabContext = useContext(TabContext);
62-
63-
let getControlledId, getControllerId;
64-
65-
if (tabContext) {
66-
role = role || 'tablist';
67-
activeKey = tabContext.activeKey;
68-
getControlledId = tabContext.getControlledId;
69-
getControllerId = tabContext.getControllerId;
70-
}
71-
72-
const listNode = useRef<HTMLElement>(null);
73-
74-
const getNextActiveChild = (offset: number) => {
75-
const currentListNode = listNode.current;
76-
if (!currentListNode) return null;
77-
78-
const items = qsa(currentListNode, '[data-rb-event-key]:not(.disabled)');
79-
const activeChild = currentListNode.querySelector<HTMLElement>('.active');
80-
if (!activeChild) return null;
81-
82-
const index = items.indexOf(activeChild);
83-
if (index === -1) return null;
84-
85-
let nextIndex = index + offset;
86-
if (nextIndex >= items.length) nextIndex = 0;
87-
if (nextIndex < 0) nextIndex = items.length - 1;
88-
return items[nextIndex];
89-
};
90-
91-
const handleSelect = (key, event) => {
92-
if (key == null) return;
93-
onSelect?.(key, event);
94-
parentOnSelect?.(key, event);
95-
};
96-
97-
const handleKeyDown = (event) => {
98-
onKeyDown?.(event);
99-
100-
let nextActiveChild;
101-
switch (event.key) {
102-
case 'ArrowLeft':
103-
case 'ArrowUp':
104-
nextActiveChild = getNextActiveChild(-1);
105-
break;
106-
case 'ArrowRight':
107-
case 'ArrowDown':
108-
nextActiveChild = getNextActiveChild(1);
109-
break;
110-
default:
111-
return;
39+
const AbstractNav: BsPrefixRefForwardingComponent<'ul', AbstractNavProps> =
40+
React.forwardRef<HTMLElement, AbstractNavProps>(
41+
(
42+
{
43+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
44+
as: Component = 'ul',
45+
onSelect,
46+
activeKey,
47+
role,
48+
onKeyDown,
49+
...props
50+
},
51+
ref,
52+
) => {
53+
// A ref and forceUpdate for refocus, b/c we only want to trigger when needed
54+
// and don't want to reset the set in the effect
55+
const forceUpdate = useForceUpdate();
56+
const needsRefocusRef = useRef(false);
57+
58+
const parentOnSelect = useContext(SelectableContext);
59+
const tabContext = useContext(TabContext);
60+
61+
let getControlledId, getControllerId;
62+
63+
if (tabContext) {
64+
role = role || 'tablist';
65+
activeKey = tabContext.activeKey;
66+
getControlledId = tabContext.getControlledId;
67+
getControllerId = tabContext.getControllerId;
11268
}
113-
if (!nextActiveChild) return;
114-
115-
event.preventDefault();
116-
handleSelect(nextActiveChild.dataset.rbEventKey, event);
117-
needsRefocusRef.current = true;
118-
forceUpdate();
119-
};
120-
121-
useEffect(() => {
122-
if (listNode.current && needsRefocusRef.current) {
123-
const activeChild = listNode.current.querySelector<HTMLElement>(
124-
'[data-rb-event-key].active',
125-
);
12669

127-
activeChild?.focus();
128-
}
70+
const listNode = useRef<HTMLElement>(null);
12971

130-
needsRefocusRef.current = false;
131-
});
132-
133-
const mergedRef = useMergedRefs(ref, listNode);
134-
135-
return (
136-
<SelectableContext.Provider value={handleSelect}>
137-
<NavContext.Provider
138-
value={{
139-
role, // used by NavLink to determine it's role
140-
activeKey: makeEventKey(activeKey),
141-
getControlledId: getControlledId || noop,
142-
getControllerId: getControllerId || noop,
143-
}}
144-
>
145-
<Component
146-
{...props}
147-
onKeyDown={handleKeyDown}
148-
ref={mergedRef}
149-
role={role}
150-
/>
151-
</NavContext.Provider>
152-
</SelectableContext.Provider>
153-
);
154-
},
155-
);
72+
const getNextActiveChild = (offset: number) => {
73+
const currentListNode = listNode.current;
74+
if (!currentListNode) return null;
75+
76+
const items = qsa(
77+
currentListNode,
78+
'[data-rb-event-key]:not(.disabled)',
79+
);
80+
const activeChild =
81+
currentListNode.querySelector<HTMLElement>('.active');
82+
if (!activeChild) return null;
83+
84+
const index = items.indexOf(activeChild);
85+
if (index === -1) return null;
86+
87+
let nextIndex = index + offset;
88+
if (nextIndex >= items.length) nextIndex = 0;
89+
if (nextIndex < 0) nextIndex = items.length - 1;
90+
return items[nextIndex];
91+
};
92+
93+
const handleSelect = (key, event) => {
94+
if (key == null) return;
95+
onSelect?.(key, event);
96+
parentOnSelect?.(key, event);
97+
};
98+
99+
const handleKeyDown = (event) => {
100+
onKeyDown?.(event);
101+
102+
let nextActiveChild;
103+
switch (event.key) {
104+
case 'ArrowLeft':
105+
case 'ArrowUp':
106+
nextActiveChild = getNextActiveChild(-1);
107+
break;
108+
case 'ArrowRight':
109+
case 'ArrowDown':
110+
nextActiveChild = getNextActiveChild(1);
111+
break;
112+
default:
113+
return;
114+
}
115+
if (!nextActiveChild) return;
116+
117+
event.preventDefault();
118+
handleSelect(nextActiveChild.dataset.rbEventKey, event);
119+
needsRefocusRef.current = true;
120+
forceUpdate();
121+
};
122+
123+
useEffect(() => {
124+
if (listNode.current && needsRefocusRef.current) {
125+
const activeChild = listNode.current.querySelector<HTMLElement>(
126+
'[data-rb-event-key].active',
127+
);
128+
129+
activeChild?.focus();
130+
}
131+
132+
needsRefocusRef.current = false;
133+
});
134+
135+
const mergedRef = useMergedRefs(ref, listNode);
136+
137+
return (
138+
<SelectableContext.Provider value={handleSelect}>
139+
<NavContext.Provider
140+
value={{
141+
role, // used by NavLink to determine it's role
142+
activeKey: makeEventKey(activeKey),
143+
getControlledId: getControlledId || noop,
144+
getControllerId: getControllerId || noop,
145+
}}
146+
>
147+
<Component
148+
{...props}
149+
onKeyDown={handleKeyDown}
150+
ref={mergedRef}
151+
role={role}
152+
/>
153+
</NavContext.Provider>
154+
</SelectableContext.Provider>
155+
);
156+
},
157+
);
156158

157159
AbstractNav.propTypes = propTypes;
158160

src/Accordion.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,40 @@ const propTypes = {
4242
flush: PropTypes.bool,
4343
};
4444

45-
const Accordion: BsPrefixRefForwardingComponent<
46-
'div',
47-
AccordionProps
48-
> = React.forwardRef<HTMLElement, AccordionProps>((props, ref) => {
49-
const {
50-
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
51-
as: Component = 'div',
52-
activeKey,
53-
bsPrefix,
54-
className,
55-
onSelect,
56-
flush,
57-
...controlledProps
58-
} = useUncontrolled(props, {
59-
activeKey: 'onSelect',
60-
});
61-
62-
const prefix = useBootstrapPrefix(bsPrefix, 'accordion');
63-
const contextValue = useMemo(
64-
() => ({
65-
activeEventKey: activeKey,
45+
const Accordion: BsPrefixRefForwardingComponent<'div', AccordionProps> =
46+
React.forwardRef<HTMLElement, AccordionProps>((props, ref) => {
47+
const {
48+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
49+
as: Component = 'div',
50+
activeKey,
51+
bsPrefix,
52+
className,
6653
onSelect,
67-
}),
68-
[activeKey, onSelect],
69-
);
54+
flush,
55+
...controlledProps
56+
} = useUncontrolled(props, {
57+
activeKey: 'onSelect',
58+
});
7059

71-
return (
72-
<AccordionContext.Provider value={contextValue}>
73-
<Component
74-
ref={ref}
75-
{...controlledProps}
76-
className={classNames(className, prefix, flush && `${prefix}-flush`)}
77-
/>
78-
</AccordionContext.Provider>
79-
);
80-
});
60+
const prefix = useBootstrapPrefix(bsPrefix, 'accordion');
61+
const contextValue = useMemo(
62+
() => ({
63+
activeEventKey: activeKey,
64+
onSelect,
65+
}),
66+
[activeKey, onSelect],
67+
);
68+
69+
return (
70+
<AccordionContext.Provider value={contextValue}>
71+
<Component
72+
ref={ref}
73+
{...controlledProps}
74+
className={classNames(className, prefix, flush && `${prefix}-flush`)}
75+
/>
76+
</AccordionContext.Provider>
77+
);
78+
});
8179

8280
Accordion.displayName = 'Accordion';
8381
Accordion.propTypes = propTypes;

src/AccordionBody.tsx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,32 @@ const propTypes = {
1919
bsPrefix: PropTypes.string,
2020
};
2121

22-
const AccordionBody: BsPrefixRefForwardingComponent<
23-
'div',
24-
AccordionBodyProps
25-
> = React.forwardRef<HTMLElement, AccordionBodyProps>(
26-
(
27-
{
28-
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
29-
as: Component = 'div',
30-
bsPrefix,
31-
className,
32-
...props
33-
},
34-
ref,
35-
) => {
36-
bsPrefix = useBootstrapPrefix(bsPrefix, 'accordion-body');
37-
const { eventKey } = useContext(AccordionItemContext);
22+
const AccordionBody: BsPrefixRefForwardingComponent<'div', AccordionBodyProps> =
23+
React.forwardRef<HTMLElement, AccordionBodyProps>(
24+
(
25+
{
26+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
27+
as: Component = 'div',
28+
bsPrefix,
29+
className,
30+
...props
31+
},
32+
ref,
33+
) => {
34+
bsPrefix = useBootstrapPrefix(bsPrefix, 'accordion-body');
35+
const { eventKey } = useContext(AccordionItemContext);
3836

39-
return (
40-
<AccordionCollapse eventKey={eventKey}>
41-
<Component
42-
ref={ref}
43-
{...props}
44-
className={classNames(className, bsPrefix)}
45-
/>
46-
</AccordionCollapse>
47-
);
48-
},
49-
);
37+
return (
38+
<AccordionCollapse eventKey={eventKey}>
39+
<Component
40+
ref={ref}
41+
{...props}
42+
className={classNames(className, bsPrefix)}
43+
/>
44+
</AccordionCollapse>
45+
);
46+
},
47+
);
5048

5149
AccordionBody.propTypes = propTypes;
5250
AccordionBody.displayName = 'AccordionBody';

0 commit comments

Comments
 (0)