Skip to content

Commit b81b503

Browse files
committed
clean up multi import core components
1 parent 4c2431c commit b81b503

File tree

18 files changed

+68
-67
lines changed

18 files changed

+68
-67
lines changed

packages/react-core/src/components/BackToTop/__tests__/BackToTop.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { RefObject } from 'react';
1+
import { createRef, RefObject } from 'react';
22
import { fireEvent, render, screen } from '@testing-library/react';
33
import { BackToTop } from '../BackToTop';
44
import userEvent from '@testing-library/user-event';
@@ -76,7 +76,7 @@ test('Renders with passed aria-label', () => {
7676
});
7777

7878
test('BackToTop can be accessed via passed innerRef', () => {
79-
const testRef: RefObject<HTMLElement | null> = React.createRef();
79+
const testRef: RefObject<HTMLElement | null> = createRef();
8080
render(<BackToTop innerRef={testRef} isAlwaysVisible />);
8181
global.scrollTo = jest.fn();
8282
testRef.current?.click();

packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, type JSX } from 'react';
1+
import { useEffect, useMemo, useRef, useState, type JSX } from 'react';
22
import { TextInput } from '../TextInput';
33
import { Button } from '../Button';
44
import { Select, SelectList, SelectOption } from '../Select';
@@ -148,7 +148,7 @@ export const CalendarMonth = ({
148148
const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
149149
.map((monthNum) => new Date(1990, monthNum))
150150
.map(monthFormat);
151-
const [isSelectOpen, setIsSelectOpen] = React.useState(false);
151+
const [isSelectOpen, setIsSelectOpen] = useState(false);
152152

153153
const getInitialDate = () => {
154154
if (isValidDate(dateProp)) {
@@ -160,18 +160,18 @@ export const CalendarMonth = ({
160160
return today;
161161
};
162162
const initialDate = getInitialDate();
163-
const [focusedDate, setFocusedDate] = React.useState(initialDate);
163+
const [focusedDate, setFocusedDate] = useState(initialDate);
164164

165165
// Must be numeric given current header design
166166
const yearFormat = (date: Date) => date.getFullYear();
167167
//
168168
const yearFormatted = yearFormat(focusedDate);
169-
const [yearInput, setYearInput] = React.useState(yearFormatted.toString());
169+
const [yearInput, setYearInput] = useState(yearFormatted.toString());
170170

171-
const [hoveredDate, setHoveredDate] = React.useState<Date>(undefined);
172-
const focusRef = React.useRef<HTMLButtonElement>(undefined);
173-
const [hiddenMonthId] = React.useState(getUniqueId('hidden-month-span'));
174-
const [shouldFocus, setShouldFocus] = React.useState(false);
171+
const [hoveredDate, setHoveredDate] = useState<Date>(undefined);
172+
const focusRef = useRef<HTMLButtonElement>(undefined);
173+
const [hiddenMonthId] = useState(getUniqueId('hidden-month-span'));
174+
const [shouldFocus, setShouldFocus] = useState(false);
175175

176176
const isValidated = (date: Date) => validators.every((validator) => validator(date));
177177
const focusedDateValidated = isValidated(focusedDate);
@@ -266,7 +266,7 @@ export const CalendarMonth = ({
266266
const nextMonth = addMonth(1);
267267
const focusedYear = focusedDate.getFullYear();
268268
const focusedMonth = focusedDate.getMonth();
269-
const calendar = React.useMemo(
269+
const calendar = useMemo(
270270
() => buildCalendar(focusedYear, focusedMonth, weekStart, validators),
271271
[focusedYear, focusedMonth, weekStart, validators]
272272
);

packages/react-core/src/components/Card/__tests__/Card.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type JSX } from 'react';
1+
import { type JSX } from 'react';
22

33
import { render, screen } from '@testing-library/react';
44
import '@testing-library/jest-dom';

packages/react-core/src/components/Card/__tests__/CardBody.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type JSX } from 'react';
1+
import { type JSX } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import { CardBody } from '../CardBody';
44

packages/react-core/src/components/Card/__tests__/CardFooter.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type JSX } from 'react';
1+
import { type JSX } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import { CardFooter } from '../CardFooter';
44

packages/react-core/src/components/ExpandableSection/examples/ExpandableSection.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cssPrefix: pf-v6-c-expandable-section
55
propComponents: ['ExpandableSection', 'ExpandableSectionToggle']
66
---
77

8+
import { useState } from 'react';
89
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
910

1011
## Examples

packages/react-core/src/components/ExpandableSection/examples/ExpandableSectionIndented.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { FormEvent } from 'react';
1+
import { FormEvent, useState } from 'react';
22
import { ExpandableSection, Checkbox } from '@patternfly/react-core';
33

44
export const ExpandableSectionIndented: React.FunctionComponent = () => {
5-
const [isExpanded, setIsExpanded] = React.useState(true);
6-
const [isDisplayLgChecked, setIsDisplayLgChecked] = React.useState(false);
5+
const [isExpanded, setIsExpanded] = useState(true);
6+
const [isDisplayLgChecked, setIsDisplayLgChecked] = useState(false);
77

88
const onToggle = (_event: React.MouseEvent, isExpanded: boolean) => {
99
setIsExpanded(isExpanded);

packages/react-core/src/components/Form/FormContext.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Dispatch, SetStateAction } from 'react';
1+
import { createContext, Dispatch, SetStateAction, useContext, useState } from 'react';
22

33
export interface FormContextProps {
44
/** Record of values for all fieldIds */
@@ -35,7 +35,7 @@ export interface FormContextProps {
3535
setValidator(fieldId: string, validate: (value: string) => string | null): void;
3636
}
3737

38-
const FormContext = React.createContext({} as FormContextProps);
38+
const FormContext = createContext({} as FormContextProps);
3939

4040
export const FormContextConsumer = FormContext.Consumer;
4141

@@ -47,10 +47,10 @@ export interface FormContextProviderProps {
4747
}
4848

4949
export const FormContextProvider: React.FC<FormContextProviderProps> = ({ initialValues, children }) => {
50-
const [values, setValues] = React.useState<Record<string, string>>(initialValues || {});
51-
const [errors, setErrors] = React.useState<Record<string, string>>({});
52-
const [validators, setValidators] = React.useState<Record<string, Function>>({});
53-
const [touched, setTouched] = React.useState<Record<string, boolean>>({});
50+
const [values, setValues] = useState<Record<string, string>>(initialValues || {});
51+
const [errors, setErrors] = useState<Record<string, string>>({});
52+
const [validators, setValidators] = useState<Record<string, Function>>({});
53+
const [touched, setTouched] = useState<Record<string, boolean>>({});
5454
const isValid = Object.keys(errors)?.length === 0;
5555

5656
const getValue = (fieldId: string) =>
@@ -127,4 +127,4 @@ export const FormContextProvider: React.FC<FormContextProviderProps> = ({ initia
127127
};
128128
FormContextProvider.displayName = 'FormContextProvider';
129129

130-
export const useFormContext = () => React.useContext(FormContext);
130+
export const useFormContext = () => useContext(FormContext);

packages/react-core/src/components/Menu/examples/MenuWithDrilldownBreadcrumbs.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type JSX } from 'react';
1+
import { type JSX, useState } from 'react';
22
import {
33
Badge,
44
Breadcrumb,
@@ -26,12 +26,12 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico
2626
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
2727

2828
export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
29-
const [menuDrilledIn, setMenuDrilledIn] = React.useState<string[]>([]);
30-
const [drilldownPath, setDrilldownPath] = React.useState<string[]>([]);
31-
const [menuHeights, setMenuHeights] = React.useState<any>({});
32-
const [activeMenu, setActiveMenu] = React.useState<string>('breadcrumbs-rootMenu');
33-
const [breadcrumb, setBreadcrumb] = React.useState<JSX.Element | null>();
34-
const [withMaxMenuHeight, setWithMaxMenuHeight] = React.useState(false);
29+
const [menuDrilledIn, setMenuDrilledIn] = useState<string[]>([]);
30+
const [drilldownPath, setDrilldownPath] = useState<string[]>([]);
31+
const [menuHeights, setMenuHeights] = useState<any>({});
32+
const [activeMenu, setActiveMenu] = useState<string>('breadcrumbs-rootMenu');
33+
const [breadcrumb, setBreadcrumb] = useState<JSX.Element | null>();
34+
const [withMaxMenuHeight, setWithMaxMenuHeight] = useState(false);
3535

3636
const onToggle = (isOpen: boolean, key: string) => {
3737
switch (key) {

packages/react-core/src/components/Nav/examples/NavDrilldown.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type JSX } from 'react';
1+
import { type JSX, useState } from 'react';
22

33
import { Nav, MenuContent, MenuItem, MenuList, DrilldownMenu, Menu } from '@patternfly/react-core';
44

@@ -46,10 +46,10 @@ const subMenuOne: JSX.Element = (
4646
);
4747

4848
export const NavigationDrilldown: React.FunctionComponent = () => {
49-
const [menuDrilledIn, setMenuDrilledIn] = React.useState<string[]>([]);
50-
const [drilldownPath, setDrilldownPath] = React.useState<string[]>([]);
51-
const [menuHeights, setMenuHeights] = React.useState<MenuHeights>({});
52-
const [activeMenu, setActiveMenu] = React.useState('nav-drilldown-rootMenu');
49+
const [menuDrilledIn, setMenuDrilledIn] = useState<string[]>([]);
50+
const [drilldownPath, setDrilldownPath] = useState<string[]>([]);
51+
const [menuHeights, setMenuHeights] = useState<MenuHeights>({});
52+
const [activeMenu, setActiveMenu] = useState('nav-drilldown-rootMenu');
5353

5454
const onDrillIn = (
5555
_event: React.KeyboardEvent | React.MouseEvent,

0 commit comments

Comments
 (0)